summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend
diff options
context:
space:
mode:
authorGravatar ameerj2021-05-25 01:52:02 -0400
committerGravatar ameerj2021-07-22 21:51:36 -0400
commit9cc1b8a873196dac5a97368df125816b5b195777 (patch)
tree18e640848aa6e01707bc58479e3c776df0200440 /src/shader_recompiler/backend
parentglsl: Revert ssbo aliasing. Storage Atomics impl (diff)
downloadyuzu-9cc1b8a873196dac5a97368df125816b5b195777.tar.gz
yuzu-9cc1b8a873196dac5a97368df125816b5b195777.tar.xz
yuzu-9cc1b8a873196dac5a97368df125816b5b195777.zip
glsl: F16x2 storage atomics
Diffstat (limited to 'src/shader_recompiler/backend')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.cpp16
-rw-r--r--src/shader_recompiler/backend/glsl/emit_context.h5
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp85
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp9
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_instructions.h4
-rw-r--r--src/shader_recompiler/backend/glsl/reg_alloc.cpp2
-rw-r--r--src/shader_recompiler/backend/glsl/reg_alloc.h1
7 files changed, 64 insertions, 58 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp
index 7986bf78f..a413219e3 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_context.cpp
@@ -39,6 +39,10 @@ void EmitContext::SetupExtensions(std::string& header) {
39 if (info.uses_atomic_f16x2_add || info.uses_atomic_f16x2_min || info.uses_atomic_f16x2_max) { 39 if (info.uses_atomic_f16x2_add || info.uses_atomic_f16x2_min || info.uses_atomic_f16x2_max) {
40 header += "#extension NV_shader_atomic_fp16_vector : enable\n"; 40 header += "#extension NV_shader_atomic_fp16_vector : enable\n";
41 } 41 }
42 if (info.uses_fp16) {
43 // TODO: AMD
44 header += "#extension GL_NV_gpu_shader5 : enable\n";
45 }
42} 46}
43 47
44void EmitContext::DefineConstantBuffers() { 48void EmitContext::DefineConstantBuffers() {
@@ -89,6 +93,18 @@ void EmitContext::DefineHelperFunctions() {
89 code += "uint CasFloatMax32x2(uint op_a,uint op_b){return " 93 code += "uint CasFloatMax32x2(uint op_a,uint op_b){return "
90 "packHalf2x16(max(unpackHalf2x16(op_a),unpackHalf2x16(op_b)));}\n"; 94 "packHalf2x16(max(unpackHalf2x16(op_a),unpackHalf2x16(op_b)));}\n";
91 } 95 }
96 if (info.uses_atomic_f16x2_add) {
97 code += "uint CasFloatAdd16x2(uint op_a,uint op_b){return "
98 "packFloat2x16(unpackFloat2x16(op_a)+unpackFloat2x16(op_b));}\n";
99 }
100 if (info.uses_atomic_f16x2_min) {
101 code += "uint CasFloatMin16x2(uint op_a,uint op_b){return "
102 "packFloat2x16(min(unpackFloat2x16(op_a),unpackFloat2x16(op_b)));}\n";
103 }
104 if (info.uses_atomic_f16x2_max) {
105 code += "uint CasFloatMax16x2(uint op_a,uint op_b){return "
106 "packFloat2x16(max(unpackFloat2x16(op_a),unpackFloat2x16(op_b)));}\n";
107 }
92 // TODO: Track this usage 108 // TODO: Track this usage
93 code += "uint CasMinS32(uint op_a,uint op_b){return uint(min(int(op_a),int(op_b)));}"; 109 code += "uint CasMinS32(uint op_a,uint op_b){return uint(min(int(op_a),int(op_b)));}";
94 code += "uint CasMaxS32(uint op_a,uint op_b){return uint(max(int(op_a),int(op_b)));}"; 110 code += "uint CasMaxS32(uint op_a,uint op_b){return uint(max(int(op_a),int(op_b)));}";
diff --git a/src/shader_recompiler/backend/glsl/emit_context.h b/src/shader_recompiler/backend/glsl/emit_context.h
index ca5657fe7..7f8857fa7 100644
--- a/src/shader_recompiler/backend/glsl/emit_context.h
+++ b/src/shader_recompiler/backend/glsl/emit_context.h
@@ -44,6 +44,11 @@ public:
44 } 44 }
45 45
46 template <typename... Args> 46 template <typename... Args>
47 void AddF16x2(const char* format_str, IR::Inst& inst, Args&&... args) {
48 Add<Type::F16x2>(format_str, inst, args...);
49 }
50
51 template <typename... Args>
47 void AddU32(const char* format_str, IR::Inst& inst, Args&&... args) { 52 void AddU32(const char* format_str, IR::Inst& inst, Args&&... args) {
48 Add<Type::U32>(format_str, inst, args...); 53 Add<Type::U32>(format_str, inst, args...);
49 } 54 }
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
index 0b29c213b..b6b326762 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_atomic.cpp
@@ -12,8 +12,7 @@
12 12
13namespace Shader::Backend::GLSL { 13namespace Shader::Backend::GLSL {
14namespace { 14namespace {
15static constexpr std::string_view cas_loop{R"( 15static constexpr std::string_view cas_loop{R"(uint {};
16uint {};
17for (;;){{ 16for (;;){{
18 uint old_value={}; 17 uint old_value={};
19 {}=atomicCompSwap({},old_value,{}({},{})); 18 {}=atomicCompSwap({},old_value,{}({},{}));
@@ -49,6 +48,14 @@ void CasFunctionF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding
49 const auto ret{ctx.reg_alloc.Define(inst)}; 48 const auto ret{ctx.reg_alloc.Define(inst)};
50 CasFunction(ctx, ret, ssbo, u32_value, function); 49 CasFunction(ctx, ret, ssbo, u32_value, function);
51} 50}
51
52void CasFunctionF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
53 const IR::Value& offset, std::string_view value, std::string_view function) {
54 const std::string ssbo{fmt::format("ssbo{}[{}]", binding.U32(), offset.U32())};
55 const std::string u32_value{fmt::format("packFloat2x16({})", value)};
56 const auto ret{ctx.reg_alloc.Define(inst)};
57 CasFunction(ctx, ret, ssbo, u32_value, function);
58}
52} // namespace 59} // namespace
53 60
54void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 61void EmitStorageAtomicIAdd32(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
@@ -122,11 +129,8 @@ void EmitStorageAtomicSMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value&
122 // LOG_WARNING(..., "Op falling to non-atomic"); 129 // LOG_WARNING(..., "Op falling to non-atomic");
123 ctx.AddS64("{}=int64_t(ivec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(), 130 ctx.AddS64("{}=int64_t(ivec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(),
124 binding.U32(), offset.U32() + 1); 131 binding.U32(), offset.U32() + 1);
125 ctx.Add(R"( 132 ctx.Add("for(int i=0;i<2;++i){{ "
126for(int i=0;i<2;++i){{ 133 "ssbo{}[{}+i]=uint(min(int(ssbo{}[{}+i]),unpackInt2x32(int64_t({}))[i]));}}",
127ssbo{}[{}+i]=uint(min(int(ssbo{}[{}+i]),unpackInt2x32(int64_t({}))[i]));
128}}
129)",
130 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value); 134 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value);
131} 135}
132 136
@@ -135,12 +139,9 @@ void EmitStorageAtomicUMin64(EmitContext& ctx, IR::Inst& inst, const IR::Value&
135 // LOG_WARNING(..., "Op falling to non-atomic"); 139 // LOG_WARNING(..., "Op falling to non-atomic");
136 ctx.AddU64("{}=uint64_t(uvec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(), 140 ctx.AddU64("{}=uint64_t(uvec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(),
137 binding.U32(), offset.U32() + 1); 141 binding.U32(), offset.U32() + 1);
138 ctx.Add(R"( 142 ctx.Add(
139for(int i=0;i<2;++i){{ 143 "for(int i=0;i<2;++i){{ ssbo{}[{}+i]=min(ssbo{}[{}+i],unpackUint2x32(uint64_t({}))[i]);}}",
140ssbo{}[{}+i]=min(ssbo{}[{}+i],unpackUint2x32(uint64_t({}))[i]); 144 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value);
141}}
142)",
143 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value);
144} 145}
145 146
146void EmitStorageAtomicSMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 147void EmitStorageAtomicSMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
@@ -148,11 +149,8 @@ void EmitStorageAtomicSMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value&
148 // LOG_WARNING(..., "Op falling to non-atomic"); 149 // LOG_WARNING(..., "Op falling to non-atomic");
149 ctx.AddS64("{}=int64_t(ivec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(), 150 ctx.AddS64("{}=int64_t(ivec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(),
150 binding.U32(), offset.U32() + 1); 151 binding.U32(), offset.U32() + 1);
151 ctx.Add(R"( 152 ctx.Add("for(int i=0;i<2;++i){{ "
152for(int i=0;i<2;++i){{ 153 "ssbo{}[{}+i]=uint(max(int(ssbo{}[{}+i]),unpackInt2x32(int64_t({}))[i]));}}",
153ssbo{}[{}+i]=uint(max(int(ssbo{}[{}+i]),unpackInt2x32(int64_t({}))[i]));
154}}
155)",
156 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value); 154 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value);
157} 155}
158 156
@@ -161,12 +159,9 @@ void EmitStorageAtomicUMax64(EmitContext& ctx, IR::Inst& inst, const IR::Value&
161 // LOG_WARNING(..., "Op falling to non-atomic"); 159 // LOG_WARNING(..., "Op falling to non-atomic");
162 ctx.AddU64("{}=uint64_t(uvec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(), 160 ctx.AddU64("{}=uint64_t(uvec2(ssbo{}[{}],ssbo{}[{}]));", inst, binding.U32(), offset.U32(),
163 binding.U32(), offset.U32() + 1); 161 binding.U32(), offset.U32() + 1);
164 ctx.Add(R"( 162 ctx.Add(
165for(int i=0;i<2;++i){{ 163 "for(int i=0;i<2;++i){{ssbo{}[{}+i]=max(ssbo{}[{}+i],unpackUint2x32(uint64_t({}))[i]);}}",
166ssbo{}[{}+i]=max(ssbo{}[{}+i],unpackUint2x32(uint64_t({}))[i]); 164 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value);
167}}
168)",
169 binding.U32(), offset.U32(), binding.U32(), offset.U32(), value);
170} 165}
171 166
172void EmitStorageAtomicAnd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding, 167void EmitStorageAtomicAnd64(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
@@ -202,45 +197,33 @@ void EmitStorageAtomicAddF32(EmitContext& ctx, IR::Inst& inst, const IR::Value&
202 CasFunctionF32(ctx, inst, binding, offset, value, "CasFloatAdd"); 197 CasFunctionF32(ctx, inst, binding, offset, value, "CasFloatAdd");
203} 198}
204 199
205void EmitStorageAtomicAddF16x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 200void EmitStorageAtomicAddF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
206 [[maybe_unused]] const IR::Value& binding, 201 const IR::Value& offset, std::string_view value) {
207 [[maybe_unused]] const IR::Value& offset, 202 CasFunctionF16x2(ctx, inst, binding, offset, value, "CasFloatAdd16x2");
208 [[maybe_unused]] std::string_view value) {
209 throw NotImplementedException("GLSL Instrucion");
210} 203}
211 204
212void EmitStorageAtomicAddF32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 205void EmitStorageAtomicAddF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
213 [[maybe_unused]] const IR::Value& binding, 206 const IR::Value& offset, std::string_view value) {
214 [[maybe_unused]] const IR::Value& offset,
215 [[maybe_unused]] std::string_view value) {
216 CasFunctionF32x2(ctx, inst, binding, offset, value, "CasFloatAdd32x2"); 207 CasFunctionF32x2(ctx, inst, binding, offset, value, "CasFloatAdd32x2");
217} 208}
218 209
219void EmitStorageAtomicMinF16x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 210void EmitStorageAtomicMinF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
220 [[maybe_unused]] const IR::Value& binding, 211 const IR::Value& offset, std::string_view value) {
221 [[maybe_unused]] const IR::Value& offset, 212 CasFunctionF16x2(ctx, inst, binding, offset, value, "CasFloatMin16x2");
222 [[maybe_unused]] std::string_view value) {
223 throw NotImplementedException("GLSL Instrucion");
224} 213}
225 214
226void EmitStorageAtomicMinF32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 215void EmitStorageAtomicMinF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
227 [[maybe_unused]] const IR::Value& binding, 216 const IR::Value& offset, std::string_view value) {
228 [[maybe_unused]] const IR::Value& offset,
229 [[maybe_unused]] std::string_view value) {
230 CasFunctionF32x2(ctx, inst, binding, offset, value, "CasFloatMin32x2"); 217 CasFunctionF32x2(ctx, inst, binding, offset, value, "CasFloatMin32x2");
231} 218}
232 219
233void EmitStorageAtomicMaxF16x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 220void EmitStorageAtomicMaxF16x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
234 [[maybe_unused]] const IR::Value& binding, 221 const IR::Value& offset, std::string_view value) {
235 [[maybe_unused]] const IR::Value& offset, 222 CasFunctionF16x2(ctx, inst, binding, offset, value, "CasFloatMax16x2");
236 [[maybe_unused]] std::string_view value) {
237 throw NotImplementedException("GLSL Instrucion");
238} 223}
239 224
240void EmitStorageAtomicMaxF32x2([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, 225void EmitStorageAtomicMaxF32x2(EmitContext& ctx, IR::Inst& inst, const IR::Value& binding,
241 [[maybe_unused]] const IR::Value& binding, 226 const IR::Value& offset, std::string_view value) {
242 [[maybe_unused]] const IR::Value& offset,
243 [[maybe_unused]] std::string_view value) {
244 CasFunctionF32x2(ctx, inst, binding, offset, value, "CasFloatMax32x2"); 227 CasFunctionF32x2(ctx, inst, binding, offset, value, "CasFloatMax32x2");
245} 228}
246 229
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp
index a1e97b4cb..742f394d4 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp
@@ -62,13 +62,12 @@ void EmitUnpackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value
62 ctx.AddU32x2("{}=unpackUint2x32({});", inst, value); 62 ctx.AddU32x2("{}=unpackUint2x32({});", inst, value);
63} 63}
64 64
65void EmitPackFloat2x16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] std::string_view value) { 65void EmitPackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
66 throw NotImplementedException("GLSL Instruction"); 66 ctx.AddU32("{}=packFloat2x16({});", inst, value);
67} 67}
68 68
69void EmitUnpackFloat2x16([[maybe_unused]] EmitContext& ctx, 69void EmitUnpackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
70 [[maybe_unused]] std::string_view value) { 70 ctx.AddF16x2("{}=unpackFloat2x16({});", inst, value);
71 throw NotImplementedException("GLSL Instruction");
72} 71}
73 72
74void EmitPackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) { 73void EmitPackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value) {
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
index 56b812d84..9f32070b0 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h
@@ -224,8 +224,8 @@ void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value)
224void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value); 224void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value);
225void EmitPackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value); 225void EmitPackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
226void EmitUnpackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value); 226void EmitUnpackUint2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
227void EmitPackFloat2x16(EmitContext& ctx, std::string_view value); 227void EmitPackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
228void EmitUnpackFloat2x16(EmitContext& ctx, std::string_view value); 228void EmitUnpackFloat2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
229void EmitPackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value); 229void EmitPackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
230void EmitUnpackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value); 230void EmitUnpackHalf2x16(EmitContext& ctx, IR::Inst& inst, std::string_view value);
231void EmitPackDouble2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value); 231void EmitPackDouble2x32(EmitContext& ctx, IR::Inst& inst, std::string_view value);
diff --git a/src/shader_recompiler/backend/glsl/reg_alloc.cpp b/src/shader_recompiler/backend/glsl/reg_alloc.cpp
index 58c2c408e..3de4c1172 100644
--- a/src/shader_recompiler/backend/glsl/reg_alloc.cpp
+++ b/src/shader_recompiler/backend/glsl/reg_alloc.cpp
@@ -113,6 +113,8 @@ std::string RegAlloc::GetType(Type type, u32 index) {
113 switch (type) { 113 switch (type) {
114 case Type::U1: 114 case Type::U1:
115 return "bool "; 115 return "bool ";
116 case Type::F16x2:
117 return "f16vec2 ";
116 case Type::U32: 118 case Type::U32:
117 return "uint "; 119 return "uint ";
118 case Type::S32: 120 case Type::S32:
diff --git a/src/shader_recompiler/backend/glsl/reg_alloc.h b/src/shader_recompiler/backend/glsl/reg_alloc.h
index 581954e44..9f2ff8718 100644
--- a/src/shader_recompiler/backend/glsl/reg_alloc.h
+++ b/src/shader_recompiler/backend/glsl/reg_alloc.h
@@ -18,6 +18,7 @@ enum class Type;
18namespace Shader::Backend::GLSL { 18namespace Shader::Backend::GLSL {
19enum class Type : u32 { 19enum class Type : u32 {
20 U1, 20 U1,
21 F16x2,
21 S32, 22 S32,
22 U32, 23 U32,
23 F32, 24 F32,