diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_context.cpp | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp index e2a9885f0..b0e46cc07 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/emit_context.cpp | |||
| @@ -11,19 +11,39 @@ namespace Shader::Backend::GLSL { | |||
| 11 | EmitContext::EmitContext(IR::Program& program, [[maybe_unused]] Bindings& bindings, | 11 | EmitContext::EmitContext(IR::Program& program, [[maybe_unused]] Bindings& bindings, |
| 12 | const Profile& profile_) | 12 | const Profile& profile_) |
| 13 | : info{program.info}, profile{profile_} { | 13 | : info{program.info}, profile{profile_} { |
| 14 | std::string header = "#version 450 core\n"; | 14 | std::string header = "#version 450\n"; |
| 15 | header += "layout(local_size_x=1, local_size_y=1, local_size_z=1) in;"; | 15 | if (program.stage == Stage::Compute) { |
| 16 | header += fmt::format("layout(local_size_x={},local_size_y={},local_size_z={}) in;\n", | ||
| 17 | program.workgroup_size[0], program.workgroup_size[1], | ||
| 18 | program.workgroup_size[2]); | ||
| 19 | } | ||
| 16 | code += header; | 20 | code += header; |
| 17 | DefineConstantBuffers(); | 21 | DefineConstantBuffers(); |
| 18 | code += "void main(){"; | 22 | DefineStorageBuffers(); |
| 23 | code += "void main(){\n"; | ||
| 19 | } | 24 | } |
| 20 | 25 | ||
| 21 | void EmitContext::DefineConstantBuffers() { | 26 | void EmitContext::DefineConstantBuffers() { |
| 22 | if (info.constant_buffer_descriptors.empty()) { | 27 | if (info.constant_buffer_descriptors.empty()) { |
| 23 | return; | 28 | return; |
| 24 | } | 29 | } |
| 30 | u32 binding{}; | ||
| 25 | for (const auto& desc : info.constant_buffer_descriptors) { | 31 | for (const auto& desc : info.constant_buffer_descriptors) { |
| 26 | Add("uniform uint c{}[{}];", desc.index, desc.count); | 32 | Add("layout(std140,binding={}) uniform cbuf_{}{{uint cbuf{}[];}};", binding, binding, |
| 33 | desc.index, desc.count); | ||
| 34 | ++binding; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | void EmitContext::DefineStorageBuffers() { | ||
| 39 | if (info.storage_buffers_descriptors.empty()) { | ||
| 40 | return; | ||
| 41 | } | ||
| 42 | u32 binding{}; | ||
| 43 | for (const auto& desc : info.storage_buffers_descriptors) { | ||
| 44 | Add("layout(std430,binding={}) buffer buff_{}{{uint buff{}[];}};", binding, binding, | ||
| 45 | desc.cbuf_index, desc.count); | ||
| 46 | ++binding; | ||
| 27 | } | 47 | } |
| 28 | } | 48 | } |
| 29 | 49 | ||