diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_context.cpp | 42 |
1 files changed, 37 insertions, 5 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp index 67772c46d..3c610a08a 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/emit_context.cpp | |||
| @@ -19,8 +19,10 @@ EmitContext::EmitContext(IR::Program& program, [[maybe_unused]] Bindings& bindin | |||
| 19 | program.workgroup_size[2]); | 19 | program.workgroup_size[2]); |
| 20 | } | 20 | } |
| 21 | code += header; | 21 | code += header; |
| 22 | |||
| 22 | DefineConstantBuffers(); | 23 | DefineConstantBuffers(); |
| 23 | DefineStorageBuffers(); | 24 | DefineStorageBuffers(); |
| 25 | DefineHelperFunctions(); | ||
| 24 | code += "void main(){\n"; | 26 | code += "void main(){\n"; |
| 25 | } | 27 | } |
| 26 | 28 | ||
| @@ -28,6 +30,15 @@ void EmitContext::SetupExtensions(std::string& header) { | |||
| 28 | if (info.uses_int64) { | 30 | if (info.uses_int64) { |
| 29 | header += "#extension GL_ARB_gpu_shader_int64 : enable\n"; | 31 | header += "#extension GL_ARB_gpu_shader_int64 : enable\n"; |
| 30 | } | 32 | } |
| 33 | if (info.uses_int64_bit_atomics) { | ||
| 34 | header += "#extension GL_NV_shader_atomic_int64 : enable\n"; | ||
| 35 | } | ||
| 36 | if (info.uses_atomic_f32_add) { | ||
| 37 | header += "#extension GL_NV_shader_atomic_float : enable\n"; | ||
| 38 | } | ||
| 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"; | ||
| 41 | } | ||
| 31 | } | 42 | } |
| 32 | 43 | ||
| 33 | void EmitContext::DefineConstantBuffers() { | 44 | void EmitContext::DefineConstantBuffers() { |
| @@ -48,18 +59,39 @@ void EmitContext::DefineStorageBuffers() { | |||
| 48 | } | 59 | } |
| 49 | u32 binding{}; | 60 | u32 binding{}; |
| 50 | for (const auto& desc : info.storage_buffers_descriptors) { | 61 | for (const auto& desc : info.storage_buffers_descriptors) { |
| 51 | if (True(info.used_storage_buffer_types & IR::Type::U32) || | 62 | if (info.uses_s32_atomics) { |
| 52 | True(info.used_storage_buffer_types & IR::Type::F32)) { | 63 | Add("layout(std430,binding={}) buffer ssbo_{}_s32{{int ssbo{}_s32[];}};", binding, |
| 64 | binding, desc.cbuf_index, desc.count); | ||
| 65 | } | ||
| 66 | if (True(info.used_storage_buffer_types & IR::Type::U32)) { | ||
| 53 | Add("layout(std430,binding={}) buffer ssbo_{}_u32{{uint ssbo{}_u32[];}};", binding, | 67 | Add("layout(std430,binding={}) buffer ssbo_{}_u32{{uint ssbo{}_u32[];}};", binding, |
| 54 | binding, desc.cbuf_index, desc.count); | 68 | binding, desc.cbuf_index, desc.count); |
| 55 | } | 69 | } |
| 56 | if (True(info.used_storage_buffer_types & IR::Type::U32x2) || | 70 | if (True(info.used_storage_buffer_types & IR::Type::F32)) { |
| 57 | True(info.used_storage_buffer_types & IR::Type::F32x2)) { | 71 | Add("layout(std430,binding={}) buffer ssbo_{}_f32{{float ssbo{}_f32[];}};", binding, |
| 58 | Add("layout(std430,binding={}) buffer ssbo_{}_u64{{uvec2 ssbo{}_u64[];}};", binding, | 72 | binding, desc.cbuf_index, desc.count); |
| 73 | } | ||
| 74 | if (True(info.used_storage_buffer_types & IR::Type::U32x2)) { | ||
| 75 | Add("layout(std430,binding={}) buffer ssbo_{}_u32x2{{uvec2 ssbo{}_u32x2[];}};", binding, | ||
| 76 | binding, desc.cbuf_index, desc.count); | ||
| 77 | } | ||
| 78 | if (True(info.used_storage_buffer_types & IR::Type::U64) || | ||
| 79 | True(info.used_storage_buffer_types & IR::Type::F64)) { | ||
| 80 | Add("layout(std430,binding={}) buffer ssbo_{}_u64{{uint64_t ssbo{}_u64[];}};", binding, | ||
| 59 | binding, desc.cbuf_index, desc.count); | 81 | binding, desc.cbuf_index, desc.count); |
| 60 | } | 82 | } |
| 61 | ++binding; | 83 | ++binding; |
| 62 | } | 84 | } |
| 63 | } | 85 | } |
| 64 | 86 | ||
| 87 | void EmitContext::DefineHelperFunctions() { | ||
| 88 | if (info.uses_global_increment) { | ||
| 89 | code += "uint CasIncrement(uint op_a,uint op_b){return(op_a>=op_b)?0u:(op_a+1u);}\n"; | ||
| 90 | } | ||
| 91 | if (info.uses_global_decrement) { | ||
| 92 | code += | ||
| 93 | "uint CasDecrement(uint op_a,uint op_b){return(op_a==0||op_a>op_b)?op_b:(op_a-1u);}\n"; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 65 | } // namespace Shader::Backend::GLSL | 97 | } // namespace Shader::Backend::GLSL |