summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
diff options
context:
space:
mode:
authorGravatar ameerj2021-05-30 20:02:44 -0400
committerGravatar ameerj2021-07-22 21:51:37 -0400
commit4b5a4ea72e471eaf7d3fae34746e49aa9a6aaf08 (patch)
treefccc88e162423b9523a529caa55ed4193cb73f46 /src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
parentglsl: implement set clip distance (diff)
downloadyuzu-4b5a4ea72e471eaf7d3fae34746e49aa9a6aaf08.tar.gz
yuzu-4b5a4ea72e471eaf7d3fae34746e49aa9a6aaf08.tar.xz
yuzu-4b5a4ea72e471eaf7d3fae34746e49aa9a6aaf08.zip
glsl: Fix ssbo indexing and name shadowing between shader stages
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp106
1 files changed, 62 insertions, 44 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
index db4c60002..d3301054c 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
@@ -27,14 +27,16 @@ void SharedCasFunction(EmitContext& ctx, IR::Inst& inst, std::string_view offset
27void SsboCasFunction(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 27void SsboCasFunction(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
28 const IR::Value& offset, std::string_view value, std::string_view function) { 28 const IR::Value& offset, std::string_view value, std::string_view function) {
29 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; 29 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)};
30 const std::string ssbo{fmt::format("ssbo{}[{}]", binding.U32(), offset.U32())}; 30 const std::string ssbo{
31 fmt::format("{}_ssbo{}[{}]", ctx.stage_name, binding.U32(), offset.U32())};
31 ctx.Add(cas_loop.data(), ssbo, ret, ssbo, function, ssbo, value, ret); 32 ctx.Add(cas_loop.data(), ssbo, ret, ssbo, function, ssbo, value, ret);
32} 33}
33 34
34void SsboCasFunctionF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 35void SsboCasFunctionF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
35 const IR::Value& offset, std::string_view value, 36 const IR::Value& offset, std::string_view value,
36 std::string_view function) { 37 std::string_view function) {
37 const std::string ssbo{fmt::format("ssbo{}[{}]", binding.U32(), offset.U32())}; 38 const std::string ssbo{
39 fmt::format("{}_ssbo{}[{}]", ctx.stage_name, binding.U32(), offset.U32())};
38 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)}; 40 const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U32)};
39 ctx.Add(cas_loop.data(), ssbo, ret, ssbo, function, ssbo, value, ret); 41 ctx.Add(cas_loop.data(), ssbo, ret, ssbo, function, ssbo, value, ret);
40 ctx.AddF32("{}=uintBitsToFloat({});", inst, ret); 42 ctx.AddF32("{}=uintBitsToFloat({});", inst, ret);
@@ -109,7 +111,8 @@ void EmitSharedAtomicExchange64(EmitContext& ctx, IR::Inst& inst, std::string_vi
109 111
110void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 112void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
111 const IR::Value& offset, std::string_view value) { 113 const IR::Value& offset, std::string_view value) {
112 ctx.AddU32("{}=atomicAdd(ssbo{}[{}],{});", inst, binding.U32(), offset.U32(), value); 114 ctx.AddU32("{}=atomicAdd({}_ssbo{}[{}],{});", inst, ctx.stage_name, binding.U32(), offset.U32(),
115 value);
113} 116}
114 117
115void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 118void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
@@ -120,7 +123,8 @@ void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value&
120 123
121void EmitStorageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 124void EmitStorageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
122 const IR::Value& offset, std::string_view value) { 125 const IR::Value& offset, std::string_view value) {
123 ctx.AddU32("{}=atomicMin(ssbo{}[{}],{});", inst, binding.U32(), offset.U32(), value); 126 ctx.AddU32("{}=atomicMin({}_ssbo{}[{}],{});", inst, ctx.stage_name, binding.U32(), offset.U32(),
127 value);
124} 128}
125 129
126void EmitStorageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 130void EmitStorageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
@@ -131,7 +135,8 @@ void EmitStorageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value&
131 135
132void EmitStorageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 136void EmitStorageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
133 const IR::Value& offset, std::string_view value) { 137 const IR::Value& offset, std::string_view value) {
134 ctx.AddU32("{}=atomicMax(ssbo{}[{}],{});", inst, binding.U32(), offset.U32(), value); 138 ctx.AddU32("{}=atomicMax({}_ssbo{}[{}],{});", inst, ctx.stage_name, binding.U32(), offset.U32(),
139 value);
135} 140}
136 141
137void EmitStorageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 142void EmitStorageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
@@ -146,103 +151,116 @@ void EmitStorageAtomicDec32(EmitContext& ctx, IR::Inst& inst, const IR::Value& b
146 151
147void EmitStorageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 152void EmitStorageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
148 const IR::Value& offset, std::string_view value) { 153 const IR::Value& offset, std::string_view value) {
149 ctx.AddU32("{}=atomicAnd(ssbo{}[{}],{});", inst, binding.U32(), offset.U32(), value); 154 ctx.AddU32("{}=atomicAnd({}_ssbo{}[{}],{});", inst, ctx.stage_name, binding.U32(), offset.U32(),
155 value);
150} 156}
151 157
152void EmitStorageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 158void EmitStorageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
153 const IR::Value& offset, std::string_view value) { 159 const IR::Value& offset, std::string_view value) {
154 ctx.AddU32("{}=atomicOr(ssbo{}[{}],{});", inst, binding.U32(), offset.U32(), value); 160 ctx.AddU32("{}=atomicOr({}_ssbo{}[{}],{});", inst, ctx.stage_name, binding.U32(), offset.U32(),
161 value);
155} 162}
156 163
157void EmitStorageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 164void EmitStorageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
158 const IR::Value& offset, std::string_view value) { 165 const IR::Value& offset, std::string_view value) {
159 ctx.AddU32("{}=atomicXor(ssbo{}[{}],{});", inst, binding.U32(), offset.U32(), value); 166 ctx.AddU32("{}=atomicXor({}_ssbo{}[{}],{});", inst, ctx.stage_name, binding.U32(), offset.U32(),
167 value);
160} 168}
161 169
162void EmitStorageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 170void EmitStorageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
163 const IR::Value& offset, std::string_view value) { 171 const IR::Value& offset, std::string_view value) {
164 ctx.AddU32("{}=atomicExchange(ssbo{}[{}],{});", inst, binding.U32(), offset.U32(), value); 172 ctx.AddU32("{}=atomicExchange({}_ssbo{}[{}],{});", inst, ctx.stage_name, binding.U32(),
173 offset.U32(), value);
165} 174}
166 175
167void EmitStorageAtomicIAdd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 176void EmitStorageAtomicIAdd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
168 const IR::Value& offset, std::string_view value) { 177 const IR::Value& offset, std::string_view value) {
169 // LOG_WARNING(..., "Op falling to non-atomic"); 178 // LOG_WARNING(..., "Op falling to non-atomic");
170 ctx.AddU64("{}=packUint2x32(uvec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(), 179 ctx.AddU64("{}=packUint2x32(uvec2({}_ssbo{}[{}],{}_ssbo{}[{}]));", inst, ctx.stage_name,
171 binding.U32(), offset.U32() + 1); 180 binding.U32(), offset.U32(), ctx.stage_name, binding.U32(), offset.U32() + 1);
172 ctx.Add("ssbo{}[{}]+=unpackUint2x32({}).x;ssbo{}[{}]+=unpackUint2x32({}).y;", binding.U32(), 181 ctx.Add("{}_ssbo{}[{}]+=unpackUint2x32({}).x;{}_ssbo{}[{}]+=unpackUint2x32({}).y;",
173 offset.U32(), value, binding.U32(), offset.U32() + 1, value); 182 ctx.stage_name, binding.U32(), offset.U32(), value, ctx.stage_name, binding.U32(),
183 offset.U32() + 1, value);
174} 184}
175 185
176void EmitStorageAtomicSMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 186void EmitStorageAtomicSMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
177 const IR::Value& offset, std::string_view value) { 187 const IR::Value& offset, std::string_view value) {
178 // LOG_WARNING(..., "Op falling to non-atomic"); 188 // LOG_WARNING(..., "Op falling to non-atomic");
179 ctx.AddS64("{}=packInt2x32(ivec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(), 189 ctx.AddS64("{}=packInt2x32(ivec2({}_ssbo{}[{}],{}_ssbo{}[{}]));", inst, ctx.stage_name,
180 binding.U32(), offset.U32() + 1); 190 binding.U32(), offset.U32(), ctx.stage_name, binding.U32(), offset.U32() + 1);
181 ctx.Add("for(int i=0;i<2;++i){{ " 191 ctx.Add("for(int i=0;i<2;++i){{ "
182 "ssbo{}[{}+i]=uint(min(int(ssbo{}[{}+i]),unpackInt2x32(int64_t({}))[i]));}}", 192 "{}_ssbo{}[{}+i]=uint(min(int({}_ssbo{}[{}+i]),unpackInt2x32(int64_t({}))[i]));}}",
183 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value); 193 ctx.stage_name, binding.U32(), offset.U32(), ctx.stage_name, binding.U32(),
194 offset.U32(), value);
184} 195}
185 196
186void EmitStorageAtomicUMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 197void EmitStorageAtomicUMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
187 const IR::Value& offset, std::string_view value) { 198 const IR::Value& offset, std::string_view value) {
188 // LOG_WARNING(..., "Op falling to non-atomic"); 199 // LOG_WARNING(..., "Op falling to non-atomic");
189 ctx.AddU64("{}=packUint2x32(uvec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(), 200 ctx.AddU64("{}=packUint2x32(uvec2({}_ssbo{}[{}],{}_ssbo{}[{}]));", inst, ctx.stage_name,
190 binding.U32(), offset.U32() + 1); 201 binding.U32(), offset.U32(), ctx.stage_name, binding.U32(), offset.U32() + 1);
191 ctx.Add( 202 ctx.Add("for(int i=0;i<2;++i){{ "
192 "for(int i=0;i<2;++i){{ ssbo{}[{}+i]=min(ssbo{}[{}+i],unpackUint2x32(uint64_t({}))[i]);}}", 203 "{}_ssbo{}[{}+i]=min({}_ssbo{}[{}+i],unpackUint2x32(uint64_t({}))[i]);}}",
193 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value); 204 ctx.stage_name, binding.U32(), offset.U32(), ctx.stage_name, binding.U32(),
205 offset.U32(), value);
194} 206}
195 207
196void EmitStorageAtomicSMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 208void EmitStorageAtomicSMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
197 const IR::Value& offset, std::string_view value) { 209 const IR::Value& offset, std::string_view value) {
198 // LOG_WARNING(..., "Op falling to non-atomic"); 210 // LOG_WARNING(..., "Op falling to non-atomic");
199 ctx.AddS64("{}=packInt2x32(ivec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(), 211 ctx.AddS64("{}=packInt2x32(ivec2({}_ssbo{}[{}],{}_ssbo{}[{}]));", inst, ctx.stage_name,
200 binding.U32(), offset.U32() + 1); 212 binding.U32(), offset.U32(), ctx.stage_name, binding.U32(), offset.U32() + 1);
201 ctx.Add("for(int i=0;i<2;++i){{ " 213 ctx.Add("for(int i=0;i<2;++i){{ "
202 "ssbo{}[{}+i]=uint(max(int(ssbo{}[{}+i]),unpackInt2x32(int64_t({}))[i]));}}", 214 "{}_ssbo{}[{}+i]=uint(max(int({}_ssbo{}[{}+i]),unpackInt2x32(int64_t({}))[i]));}}",
203 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value); 215 ctx.stage_name, binding.U32(), offset.U32(), ctx.stage_name, binding.U32(),
216 offset.U32(), value);
204} 217}
205 218
206void EmitStorageAtomicUMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 219void EmitStorageAtomicUMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
207 const IR::Value& offset, std::string_view value) { 220 const IR::Value& offset, std::string_view value) {
208 // LOG_WARNING(..., "Op falling to non-atomic"); 221 // LOG_WARNING(..., "Op falling to non-atomic");
209 ctx.AddU64("{}=packUint2x32(uvec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(), 222 ctx.AddU64("{}=packUint2x32(uvec2({}_ssbo{}[{}],{}_ssbo{}[{}]));", inst, ctx.stage_name,
210 binding.U32(), offset.U32() + 1); 223 binding.U32(), offset.U32(), ctx.stage_name, binding.U32(), offset.U32() + 1);
211 ctx.Add( 224 ctx.Add("for(int "
212 "for(int i=0;i<2;++i){{ssbo{}[{}+i]=max(ssbo{}[{}+i],unpackUint2x32(uint64_t({}))[i]);}}", 225 "i=0;i<2;++i){{{}_ssbo{}[{}+i]=max({}_ssbo{}[{}+i],unpackUint2x32(uint64_t({}))[i]);}}",
213 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value); 226 ctx.stage_name, binding.U32(), offset.U32(), ctx.stage_name, binding.U32(),
227 offset.U32(), value);
214} 228}
215 229
216void EmitStorageAtomicAnd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 230void EmitStorageAtomicAnd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
217 const IR::Value& offset, std::string_view value) { 231 const IR::Value& offset, std::string_view value) {
218 ctx.AddU64( 232 ctx.AddU64("{}=packUint2x32(uvec2(atomicAnd({}_ssbo{}[{}],unpackUint2x32({}).x),atomicAnd({}_"
219 "{}=packUint2x32(uvec2(atomicAnd(ssbo{}[{}],unpackUint2x32({}).x),atomicAnd(ssbo{}[{}]," 233 "ssbo{}[{}],"
220 "unpackUint2x32({}).y)));", 234 "unpackUint2x32({}).y)));",
221 inst, binding.U32(), offset.U32(), value, binding.U32(), offset.U32() + 1, value); 235 inst, ctx.stage_name, binding.U32(), offset.U32(), value, ctx.stage_name,
236 binding.U32(), offset.U32() + 1, value);
222} 237}
223 238
224void EmitStorageAtomicOr64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 239void EmitStorageAtomicOr64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
225 const IR::Value& offset, std::string_view value) { 240 const IR::Value& offset, std::string_view value) {
226 ctx.AddU64( 241 ctx.AddU64(
227 "{}=packUint2x32(uvec2(atomicOr(ssbo{}[{}],unpackUint2x32({}).x),atomicOr(ssbo{}[{}]," 242 "{}=packUint2x32(uvec2(atomicOr({}_ssbo{}[{}],unpackUint2x32({}).x),atomicOr({}_ssbo{}[{}],"
228 "unpackUint2x32({}).y)));", 243 "unpackUint2x32({}).y)));",
229 inst, binding.U32(), offset.U32(), value, binding.U32(), offset.U32() + 1, value); 244 inst, ctx.stage_name, binding.U32(), offset.U32(), value, ctx.stage_name, binding.U32(),
245 offset.U32() + 1, value);
230} 246}
231 247
232void EmitStorageAtomicXor64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 248void EmitStorageAtomicXor64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
233 const IR::Value& offset, std::string_view value) { 249 const IR::Value& offset, std::string_view value) {
234 ctx.AddU64( 250 ctx.AddU64("{}=packUint2x32(uvec2(atomicXor({}_ssbo{}[{}],unpackUint2x32({}).x),atomicXor({}_"
235 "{}=packUint2x32(uvec2(atomicXor(ssbo{}[{}],unpackUint2x32({}).x),atomicXor(ssbo{}[{}]," 251 "ssbo{}[{}],"
236 "unpackUint2x32({}).y)));", 252 "unpackUint2x32({}).y)));",
237 inst, binding.U32(), offset.U32(), value, binding.U32(), offset.U32() + 1, value); 253 inst, ctx.stage_name, binding.U32(), offset.U32(), value, ctx.stage_name,
254 binding.U32(), offset.U32() + 1, value);
238} 255}
239 256
240void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 257void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
241 const IR::Value& offset, std::string_view value) { 258 const IR::Value& offset, std::string_view value) {
242 ctx.AddU64( 259 ctx.AddU64(
243 "{}=packUint2x32(uvec2(atomicExchange(ssbo{}[{}],unpackUint2x32({}).x),atomicExchange(" 260 "{}=packUint2x32(uvec2(atomicExchange({}_ssbo{}[{}],unpackUint2x32({}).x),atomicExchange("
244 "ssbo{}[{}],unpackUint2x32({}).y)));", 261 "{}_ssbo{}[{}],unpackUint2x32({}).y)));",
245 inst, binding.U32(), offset.U32(), value, binding.U32(), offset.U32() + 1, value); 262 inst, ctx.stage_name, binding.U32(), offset.U32(), value, ctx.stage_name, binding.U32(),
263 offset.U32() + 1, value);
246} 264}
247 265
248void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 266void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,