summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2021-07-25 11:39:04 -0700
committerGravatar GitHub2021-07-25 11:39:04 -0700
commit98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f (patch)
tree816faa96c2c4d291825063433331a8ea4b3d08f1 /src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
parentMerge pull request #6699 from lat9nq/common-threads (diff)
parentshader: Support out of bound local memory reads and immediate writes (diff)
downloadyuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar.gz
yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar.xz
yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.zip
Merge pull request #6585 from ameerj/hades
Shader Decompiler Rewrite
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp219
1 files changed, 219 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
new file mode 100644
index 000000000..49a66e3ec
--- /dev/null
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_composite.cpp
@@ -0,0 +1,219 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <string_view>
6
7#include "shader_recompiler/backend/glsl/emit_context.h"
8#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
9#include "shader_recompiler/frontend/ir/value.h"
10
11namespace Shader::Backend::GLSL {
12namespace {
13constexpr std::string_view SWIZZLE{"xyzw"};
14void CompositeInsert(EmitContext& ctx, std::string_view result, std::string_view composite,
15 std::string_view object, u32 index) {
16 if (result == composite) {
17 // The result is aliased with the composite
18 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
19 } else {
20 ctx.Add("{}={};{}.{}={};", result, composite, result, SWIZZLE[index], object);
21 }
22}
23} // Anonymous namespace
24
25void EmitCompositeConstructU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
26 std::string_view e2) {
27 ctx.AddU32x2("{}=uvec2({},{});", inst, e1, e2);
28}
29
30void EmitCompositeConstructU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
31 std::string_view e2, std::string_view e3) {
32 ctx.AddU32x3("{}=uvec3({},{},{});", inst, e1, e2, e3);
33}
34
35void EmitCompositeConstructU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
36 std::string_view e2, std::string_view e3, std::string_view e4) {
37 ctx.AddU32x4("{}=uvec4({},{},{},{});", inst, e1, e2, e3, e4);
38}
39
40void EmitCompositeExtractU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
41 u32 index) {
42 ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
43}
44
45void EmitCompositeExtractU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
46 u32 index) {
47 ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
48}
49
50void EmitCompositeExtractU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
51 u32 index) {
52 ctx.AddU32("{}={}.{};", inst, composite, SWIZZLE[index]);
53}
54
55void EmitCompositeInsertU32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
56 std::string_view object, u32 index) {
57 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x2)};
58 CompositeInsert(ctx, ret, composite, object, index);
59}
60
61void EmitCompositeInsertU32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
62 std::string_view object, u32 index) {
63 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x3)};
64 CompositeInsert(ctx, ret, composite, object, index);
65}
66
67void EmitCompositeInsertU32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
68 std::string_view object, u32 index) {
69 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32x4)};
70 CompositeInsert(ctx, ret, composite, object, index);
71}
72
73void EmitCompositeConstructF16x2([[maybe_unused]] EmitContext& ctx,
74 [[maybe_unused]] std::string_view e1,
75 [[maybe_unused]] std::string_view e2) {
76 NotImplemented();
77}
78
79void EmitCompositeConstructF16x3([[maybe_unused]] EmitContext& ctx,
80 [[maybe_unused]] std::string_view e1,
81 [[maybe_unused]] std::string_view e2,
82 [[maybe_unused]] std::string_view e3) {
83 NotImplemented();
84}
85
86void EmitCompositeConstructF16x4([[maybe_unused]] EmitContext& ctx,
87 [[maybe_unused]] std::string_view e1,
88 [[maybe_unused]] std::string_view e2,
89 [[maybe_unused]] std::string_view e3,
90 [[maybe_unused]] std::string_view e4) {
91 NotImplemented();
92}
93
94void EmitCompositeExtractF16x2([[maybe_unused]] EmitContext& ctx,
95 [[maybe_unused]] std::string_view composite,
96 [[maybe_unused]] u32 index) {
97 NotImplemented();
98}
99
100void EmitCompositeExtractF16x3([[maybe_unused]] EmitContext& ctx,
101 [[maybe_unused]] std::string_view composite,
102 [[maybe_unused]] u32 index) {
103 NotImplemented();
104}
105
106void EmitCompositeExtractF16x4([[maybe_unused]] EmitContext& ctx,
107 [[maybe_unused]] std::string_view composite,
108 [[maybe_unused]] u32 index) {
109 NotImplemented();
110}
111
112void EmitCompositeInsertF16x2([[maybe_unused]] EmitContext& ctx,
113 [[maybe_unused]] std::string_view composite,
114 [[maybe_unused]] std::string_view object,
115 [[maybe_unused]] u32 index) {
116 NotImplemented();
117}
118
119void EmitCompositeInsertF16x3([[maybe_unused]] EmitContext& ctx,
120 [[maybe_unused]] std::string_view composite,
121 [[maybe_unused]] std::string_view object,
122 [[maybe_unused]] u32 index) {
123 NotImplemented();
124}
125
126void EmitCompositeInsertF16x4([[maybe_unused]] EmitContext& ctx,
127 [[maybe_unused]] std::string_view composite,
128 [[maybe_unused]] std::string_view object,
129 [[maybe_unused]] u32 index) {
130 NotImplemented();
131}
132
133void EmitCompositeConstructF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
134 std::string_view e2) {
135 ctx.AddF32x2("{}=vec2({},{});", inst, e1, e2);
136}
137
138void EmitCompositeConstructF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
139 std::string_view e2, std::string_view e3) {
140 ctx.AddF32x3("{}=vec3({},{},{});", inst, e1, e2, e3);
141}
142
143void EmitCompositeConstructF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view e1,
144 std::string_view e2, std::string_view e3, std::string_view e4) {
145 ctx.AddF32x4("{}=vec4({},{},{},{});", inst, e1, e2, e3, e4);
146}
147
148void EmitCompositeExtractF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
149 u32 index) {
150 ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
151}
152
153void EmitCompositeExtractF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
154 u32 index) {
155 ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
156}
157
158void EmitCompositeExtractF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
159 u32 index) {
160 ctx.AddF32("{}={}.{};", inst, composite, SWIZZLE[index]);
161}
162
163void EmitCompositeInsertF32x2(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
164 std::string_view object, u32 index) {
165 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x2)};
166 CompositeInsert(ctx, ret, composite, object, index);
167}
168
169void EmitCompositeInsertF32x3(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
170 std::string_view object, u32 index) {
171 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x3)};
172 CompositeInsert(ctx, ret, composite, object, index);
173}
174
175void EmitCompositeInsertF32x4(EmitContext& ctx, IR::Inst& inst, std::string_view composite,
176 std::string_view object, u32 index) {
177 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::F32x4)};
178 CompositeInsert(ctx, ret, composite, object, index);
179}
180
181void EmitCompositeConstructF64x2([[maybe_unused]] EmitContext& ctx) {
182 NotImplemented();
183}
184
185void EmitCompositeConstructF64x3([[maybe_unused]] EmitContext& ctx) {
186 NotImplemented();
187}
188
189void EmitCompositeConstructF64x4([[maybe_unused]] EmitContext& ctx) {
190 NotImplemented();
191}
192
193void EmitCompositeExtractF64x2([[maybe_unused]] EmitContext& ctx) {
194 NotImplemented();
195}
196
197void EmitCompositeExtractF64x3([[maybe_unused]] EmitContext& ctx) {
198 NotImplemented();
199}
200
201void EmitCompositeExtractF64x4([[maybe_unused]] EmitContext& ctx) {
202 NotImplemented();
203}
204
205void EmitCompositeInsertF64x2(EmitContext& ctx, std::string_view composite, std::string_view object,
206 u32 index) {
207 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
208}
209
210void EmitCompositeInsertF64x3(EmitContext& ctx, std::string_view composite, std::string_view object,
211 u32 index) {
212 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
213}
214
215void EmitCompositeInsertF64x4(EmitContext& ctx, std::string_view composite, std::string_view object,
216 u32 index) {
217 ctx.Add("{}.{}={};", composite, SWIZZLE[index], object);
218}
219} // namespace Shader::Backend::GLSL