summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp301
1 files changed, 301 insertions, 0 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
index e69de29bb..f3ef37873 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
@@ -0,0 +1,301 @@
1
2// Copyright 2021 yuzu Emulator Project
3// Licensed under GPLv2 or any later version
4// Refer to the license.txt file included.
5
6#include <string_view>
7
8#include "shader_recompiler/backend/glsl/emit_context.h"
9#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
10#include "shader_recompiler/frontend/ir/value.h"
11#include "shader_recompiler/profile.h"
12
13namespace Shader::Backend::GLSL {
14namespace {
15static constexpr std::string_view cas_loop{R"(
16{} {};
17for (;;){{
18 {} old_value={};
19 {} = atomicCompSwap({},old_value,{}({},{}));
20 if ({}==old_value){{break;}}
21}})"};
22
23void CasFunction(EmitContext& ctx, IR::Inst& inst, std::string_view ssbo, std::string_view value,
24 std::string_view type, std::string_view function) {
25 const auto ret{ctx.reg_alloc.Define(inst)};
26 ctx.Add(cas_loop.data(), type, ret, type, ssbo, ret, ssbo, function, ssbo, value, ret);
27}
28} // namespace
29
30void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
31 const IR::Value& offset, std::string_view value) {
32 ctx.AddU32("{}=atomicAdd(ssbo{}_u32[{}],{});", inst, binding.U32(), offset.U32(), value);
33}
34
35void EmitStorageAtomicSMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
36 const IR::Value& offset, std::string_view value) {
37 ctx.AddS32("{}=atomicMin(ssbo{}_s32[{}],int({}));", inst, binding.U32(), offset.U32(), value);
38}
39
40void EmitStorageAtomicUMin32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
41 const IR::Value& offset, std::string_view value) {
42 ctx.AddU32("{}=atomicMin(ssbo{}_u32[{}],{});", inst, binding.U32(), offset.U32(), value);
43}
44
45void EmitStorageAtomicSMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
46 const IR::Value& offset, std::string_view value) {
47 ctx.AddS32("{}=atomicMax(ssbo{}_s32[{}],int({}));", inst, binding.U32(), offset.U32(), value);
48}
49
50void EmitStorageAtomicUMax32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
51 const IR::Value& offset, std::string_view value) {
52 ctx.AddU32("{}=atomicMax(ssbo{}_u32[{}],{});", inst, binding.U32(), offset.U32(), value);
53}
54
55void EmitStorageAtomicInc32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
56 [[maybe_unused]] const IR::Value& offset, std::string_view value) {
57 // const auto ret{ctx.reg_alloc.Define(inst)};
58 // const auto type{"uint"};
59 // ctx.Add(cas_loop.data(), type, ret, type, ssbo, ret, ssbo, "CasIncrement", ssbo, value, ret);
60 const std::string ssbo{fmt::format("ssbo{}_u32[{}]", binding.U32(), offset.U32())};
61 CasFunction(ctx, inst, ssbo, value, "uint", "CasIncrement");
62}
63
64void EmitStorageAtomicDec32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
65 const IR::Value& offset, std::string_view value) {
66 const std::string ssbo{fmt::format("ssbo{}_u32[{}]", binding.U32(), offset.U32())};
67 CasFunction(ctx, inst, ssbo, value, "uint", "CasDecrement");
68}
69
70void EmitStorageAtomicAnd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
71 const IR::Value& offset, std::string_view value) {
72 ctx.AddU32("{}=atomicAnd(ssbo{}_u32[{}],{});", inst, binding.U32(), offset.U32(), value);
73}
74
75void EmitStorageAtomicOr32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
76 const IR::Value& offset, std::string_view value) {
77 ctx.AddU32("{}=atomicOr(ssbo{}_u32[{}],{});", inst, binding.U32(), offset.U32(), value);
78}
79
80void EmitStorageAtomicXor32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
81 const IR::Value& offset, std::string_view value) {
82 ctx.AddU32("{}=atomicXor(ssbo{}_u32[{}],{});", inst, binding.U32(), offset.U32(), value);
83}
84
85void EmitStorageAtomicExchange32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
86 const IR::Value& offset, std::string_view value) {
87 ctx.AddU32("{}=atomicExchange(ssbo{}_u32[{}],{});", inst, binding.U32(), offset.U32(), value);
88}
89
90void EmitStorageAtomicIAdd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
91 const IR::Value& offset, std::string_view value) {
92 // ctx.AddU64("{}=atomicAdd(ssbo{}_u64[{}],{});", inst, binding.U32(), offset.U32(), value);
93 ctx.AddU64("{}=ssbo{}_u64[{}];", inst, binding.U32(), offset.U32());
94 ctx.Add("ssbo{}_u64[{}]+={};", binding.U32(), offset.U32(), value);
95}
96
97void EmitStorageAtomicSMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
98 const IR::Value& offset, std::string_view value) {
99 ctx.AddS64("{}=atomicMin(int64_t(ssbo{}_u64[{}]),int64_t({}));", inst, binding.U32(),
100 offset.U32(), value);
101}
102
103void EmitStorageAtomicUMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
104 const IR::Value& offset, std::string_view value) {
105 ctx.AddU64("{}=atomicMin(ssbo{}_u64[{}],{});", inst, binding.U32(), offset.U32(), value);
106}
107
108void EmitStorageAtomicSMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
109 const IR::Value& offset, std::string_view value) {
110 ctx.AddS64("{}=atomicMax(int64_t(ssbo{}_u64[{}]),int64_t({}));", inst, binding.U32(),
111 offset.U32(), value);
112}
113
114void EmitStorageAtomicUMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
115 const IR::Value& offset, std::string_view value) {
116 ctx.AddU64("{}=atomicMax(ssbo{}_u64[{}],{});", inst, binding.U32(), offset.U32(), value);
117}
118
119void EmitStorageAtomicAnd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
120 const IR::Value& offset, std::string_view value) {
121 ctx.AddU64("{}=atomicAnd(ssbo{}_u64[{}],{});", inst, binding.U32(), offset.U32(), value);
122}
123
124void EmitStorageAtomicOr64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
125 const IR::Value& offset, std::string_view value) {
126 ctx.AddU64("{}=atomicOr(ssbo{}_u64[{}],{});", inst, binding.U32(), offset.U32(), value);
127}
128
129void EmitStorageAtomicXor64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
130 const IR::Value& offset, std::string_view value) {
131 ctx.AddU64("{}=atomicXor(ssbo{}_u64[{}],{});", inst, binding.U32(), offset.U32(), value);
132}
133
134void EmitStorageAtomicExchange64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
135 const IR::Value& offset, std::string_view value) {
136 ctx.AddU64("{}=atomicExchange(ssbo{}_u64[{}],{});", inst, binding.U32(), offset.U32(), value);
137}
138
139void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
140 const IR::Value& offset, std::string_view value) {
141 ctx.AddF32("{}=atomicAdd(ssbo{}_u32[{}],{});", inst, binding.U32(), offset.U32(), value);
142}
143
144void EmitStorageAtomicAddF16x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
145 [[maybe_unused]] const IR::Value& binding,
146 [[maybe_unused]] const IR::Value& offset,
147 [[maybe_unused]] std::string_view value) {
148 throw NotImplementedException("GLSL Instrucion");
149}
150
151void EmitStorageAtomicAddF32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
152 [[maybe_unused]] const IR::Value& binding,
153 [[maybe_unused]] const IR::Value& offset,
154 [[maybe_unused]] std::string_view value) {
155 throw NotImplementedException("GLSL Instrucion");
156}
157
158void EmitStorageAtomicMinF16x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
159 [[maybe_unused]] const IR::Value& binding,
160 [[maybe_unused]] const IR::Value& offset,
161 [[maybe_unused]] std::string_view value) {
162 throw NotImplementedException("GLSL Instrucion");
163}
164
165void EmitStorageAtomicMinF32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
166 [[maybe_unused]] const IR::Value& binding,
167 [[maybe_unused]] const IR::Value& offset,
168 [[maybe_unused]] std::string_view value) {
169 throw NotImplementedException("GLSL Instrucion");
170}
171
172void EmitStorageAtomicMaxF16x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
173 [[maybe_unused]] const IR::Value& binding,
174 [[maybe_unused]] const IR::Value& offset,
175 [[maybe_unused]] std::string_view value) {
176 throw NotImplementedException("GLSL Instrucion");
177}
178
179void EmitStorageAtomicMaxF32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
180 [[maybe_unused]] const IR::Value& binding,
181 [[maybe_unused]] const IR::Value& offset,
182 [[maybe_unused]] std::string_view value) {
183 throw NotImplementedException("GLSL Instrucion");
184}
185
186void EmitGlobalAtomicIAdd32(EmitContext&) {
187 throw NotImplementedException("GLSL Instrucion");
188}
189
190void EmitGlobalAtomicSMin32(EmitContext&) {
191 throw NotImplementedException("GLSL Instrucion");
192}
193
194void EmitGlobalAtomicUMin32(EmitContext&) {
195 throw NotImplementedException("GLSL Instrucion");
196}
197
198void EmitGlobalAtomicSMax32(EmitContext&) {
199 throw NotImplementedException("GLSL Instrucion");
200}
201
202void EmitGlobalAtomicUMax32(EmitContext&) {
203 throw NotImplementedException("GLSL Instrucion");
204}
205
206void EmitGlobalAtomicInc32(EmitContext&) {
207 throw NotImplementedException("GLSL Instrucion");
208}
209
210void EmitGlobalAtomicDec32(EmitContext&) {
211 throw NotImplementedException("GLSL Instrucion");
212}
213
214void EmitGlobalAtomicAnd32(EmitContext&) {
215 throw NotImplementedException("GLSL Instrucion");
216}
217
218void EmitGlobalAtomicOr32(EmitContext&) {
219 throw NotImplementedException("GLSL Instrucion");
220}
221
222void EmitGlobalAtomicXor32(EmitContext&) {
223 throw NotImplementedException("GLSL Instrucion");
224}
225
226void EmitGlobalAtomicExchange32(EmitContext&) {
227 throw NotImplementedException("GLSL Instrucion");
228}
229
230void EmitGlobalAtomicIAdd64(EmitContext&) {
231 throw NotImplementedException("GLSL Instrucion");
232}
233
234void EmitGlobalAtomicSMin64(EmitContext&) {
235 throw NotImplementedException("GLSL Instrucion");
236}
237
238void EmitGlobalAtomicUMin64(EmitContext&) {
239 throw NotImplementedException("GLSL Instrucion");
240}
241
242void EmitGlobalAtomicSMax64(EmitContext&) {
243 throw NotImplementedException("GLSL Instrucion");
244}
245
246void EmitGlobalAtomicUMax64(EmitContext&) {
247 throw NotImplementedException("GLSL Instrucion");
248}
249
250void EmitGlobalAtomicInc64(EmitContext&) {
251 throw NotImplementedException("GLSL Instrucion");
252}
253
254void EmitGlobalAtomicDec64(EmitContext&) {
255 throw NotImplementedException("GLSL Instrucion");
256}
257
258void EmitGlobalAtomicAnd64(EmitContext&) {
259 throw NotImplementedException("GLSL Instrucion");
260}
261
262void EmitGlobalAtomicOr64(EmitContext&) {
263 throw NotImplementedException("GLSL Instrucion");
264}
265
266void EmitGlobalAtomicXor64(EmitContext&) {
267 throw NotImplementedException("GLSL Instrucion");
268}
269
270void EmitGlobalAtomicExchange64(EmitContext&) {
271 throw NotImplementedException("GLSL Instrucion");
272}
273
274void EmitGlobalAtomicAddF32(EmitContext&) {
275 throw NotImplementedException("GLSL Instrucion");
276}
277
278void EmitGlobalAtomicAddF16x2(EmitContext&) {
279 throw NotImplementedException("GLSL Instrucion");
280}
281
282void EmitGlobalAtomicAddF32x2(EmitContext&) {
283 throw NotImplementedException("GLSL Instrucion");
284}
285
286void EmitGlobalAtomicMinF16x2(EmitContext&) {
287 throw NotImplementedException("GLSL Instrucion");
288}
289
290void EmitGlobalAtomicMinF32x2(EmitContext&) {
291 throw NotImplementedException("GLSL Instrucion");
292}
293
294void EmitGlobalAtomicMaxF16x2(EmitContext&) {
295 throw NotImplementedException("GLSL Instrucion");
296}
297
298void EmitGlobalAtomicMaxF32x2(EmitContext&) {
299 throw NotImplementedException("GLSL Instrucion");
300}
301} // namespace Shader::Backend::GLSL