diff options
| author | 2021-05-27 22:28:33 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:36 -0400 | |
| commit | 2a713337165df4d5c4228458999a680e9ab65369 (patch) | |
| tree | 0e820cbfcedaaffafc34b334bd04107a51e2a24d /src/shader_recompiler/backend/glsl/emit_context.cpp | |
| parent | glsl: remove unused headers (diff) | |
| download | yuzu-2a713337165df4d5c4228458999a680e9ab65369.tar.gz yuzu-2a713337165df4d5c4228458999a680e9ab65369.tar.xz yuzu-2a713337165df4d5c4228458999a680e9ab65369.zip | |
glsl: Fix bindings, add some CC ops
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_context.cpp | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp index 0ddc0443b..7bd6b3605 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/emit_context.cpp | |||
| @@ -20,6 +20,20 @@ std::string_view InterpDecorator(Interpolation interp) { | |||
| 20 | } | 20 | } |
| 21 | throw InvalidArgument("Invalid interpolation {}", interp); | 21 | throw InvalidArgument("Invalid interpolation {}", interp); |
| 22 | } | 22 | } |
| 23 | |||
| 24 | std::string_view SamplerType(TextureType type) { | ||
| 25 | switch (type) { | ||
| 26 | case TextureType::Color2D: | ||
| 27 | return "sampler2D"; | ||
| 28 | case TextureType::ColorArray2D: | ||
| 29 | return "sampler2DArray"; | ||
| 30 | case TextureType::Color3D: | ||
| 31 | return "sampler3D"; | ||
| 32 | default: | ||
| 33 | throw NotImplementedException("Texture type: {}", type); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 23 | } // namespace | 37 | } // namespace |
| 24 | 38 | ||
| 25 | EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_, | 39 | EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_, |
| @@ -31,27 +45,23 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 31 | switch (program.stage) { | 45 | switch (program.stage) { |
| 32 | case Stage::VertexA: | 46 | case Stage::VertexA: |
| 33 | case Stage::VertexB: | 47 | case Stage::VertexB: |
| 34 | stage_name = "vertex"; | 48 | stage_name = "vs"; |
| 35 | attrib_name = "vertex"; | ||
| 36 | // TODO: add only what's used by the shader | 49 | // TODO: add only what's used by the shader |
| 37 | header += | 50 | header += |
| 38 | "out gl_PerVertex {vec4 gl_Position;float gl_PointSize;float gl_ClipDistance[];};"; | 51 | "out gl_PerVertex {vec4 gl_Position;float gl_PointSize;float gl_ClipDistance[];};"; |
| 39 | break; | 52 | break; |
| 40 | case Stage::TessellationControl: | 53 | case Stage::TessellationControl: |
| 41 | case Stage::TessellationEval: | 54 | case Stage::TessellationEval: |
| 42 | stage_name = "primitive"; | 55 | stage_name = "ts"; |
| 43 | attrib_name = "primitive"; | ||
| 44 | break; | 56 | break; |
| 45 | case Stage::Geometry: | 57 | case Stage::Geometry: |
| 46 | stage_name = "primitive"; | 58 | stage_name = "gs"; |
| 47 | attrib_name = "vertex"; | ||
| 48 | break; | 59 | break; |
| 49 | case Stage::Fragment: | 60 | case Stage::Fragment: |
| 50 | stage_name = "fragment"; | 61 | stage_name = "fs"; |
| 51 | attrib_name = "fragment"; | ||
| 52 | break; | 62 | break; |
| 53 | case Stage::Compute: | 63 | case Stage::Compute: |
| 54 | stage_name = "invocation"; | 64 | stage_name = "cs"; |
| 55 | header += fmt::format("layout(local_size_x={},local_size_y={},local_size_z={}) in;\n", | 65 | header += fmt::format("layout(local_size_x={},local_size_y={},local_size_z={}) in;\n", |
| 56 | program.workgroup_size[0], program.workgroup_size[1], | 66 | program.workgroup_size[0], program.workgroup_size[1], |
| 57 | program.workgroup_size[2]); | 67 | program.workgroup_size[2]); |
| @@ -77,12 +87,12 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile | |||
| 77 | Add("layout(location={}) out vec4 out_attr{};", index, index); | 87 | Add("layout(location={}) out vec4 out_attr{};", index, index); |
| 78 | } | 88 | } |
| 79 | } | 89 | } |
| 80 | DefineConstantBuffers(); | 90 | DefineConstantBuffers(bindings); |
| 81 | DefineStorageBuffers(); | 91 | DefineStorageBuffers(bindings); |
| 82 | DefineHelperFunctions(); | ||
| 83 | SetupImages(bindings); | 92 | SetupImages(bindings); |
| 84 | Add("void main(){{"); | 93 | DefineHelperFunctions(); |
| 85 | 94 | ||
| 95 | Add("void main(){{"); | ||
| 86 | if (stage == Stage::VertexA || stage == Stage::VertexB) { | 96 | if (stage == Stage::VertexA || stage == Stage::VertexB) { |
| 87 | Add("gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);"); | 97 | Add("gl_Position = vec4(0.0f, 0.0f, 0.0f, 1.0f);"); |
| 88 | } | 98 | } |
| @@ -112,27 +122,25 @@ void EmitContext::SetupExtensions(std::string& header) { | |||
| 112 | } | 122 | } |
| 113 | } | 123 | } |
| 114 | 124 | ||
| 115 | void EmitContext::DefineConstantBuffers() { | 125 | void EmitContext::DefineConstantBuffers(Bindings& bindings) { |
| 116 | if (info.constant_buffer_descriptors.empty()) { | 126 | if (info.constant_buffer_descriptors.empty()) { |
| 117 | return; | 127 | return; |
| 118 | } | 128 | } |
| 119 | u32 binding{}; | ||
| 120 | for (const auto& desc : info.constant_buffer_descriptors) { | 129 | for (const auto& desc : info.constant_buffer_descriptors) { |
| 121 | Add("layout(std140,binding={}) uniform cbuf_{}{{vec4 cbuf{}[{}];}};", binding, desc.index, | 130 | Add("layout(std140,binding={}) uniform {}_cbuf_{}{{vec4 {}_cbuf{}[{}];}};", |
| 122 | desc.index, 4 * 1024); | 131 | bindings.uniform_buffer, stage_name, desc.index, stage_name, desc.index, 4 * 1024); |
| 123 | ++binding; | 132 | bindings.uniform_buffer += desc.count; |
| 124 | } | 133 | } |
| 125 | } | 134 | } |
| 126 | 135 | ||
| 127 | void EmitContext::DefineStorageBuffers() { | 136 | void EmitContext::DefineStorageBuffers(Bindings& bindings) { |
| 128 | if (info.storage_buffers_descriptors.empty()) { | 137 | if (info.storage_buffers_descriptors.empty()) { |
| 129 | return; | 138 | return; |
| 130 | } | 139 | } |
| 131 | u32 binding{}; | ||
| 132 | for (const auto& desc : info.storage_buffers_descriptors) { | 140 | for (const auto& desc : info.storage_buffers_descriptors) { |
| 133 | Add("layout(std430,binding={}) buffer ssbo_{}{{uint ssbo{}[];}};", binding, binding, | 141 | Add("layout(std430,binding={}) buffer ssbo_{}{{uint ssbo{}[];}};", bindings.storage_buffer, |
| 134 | desc.cbuf_index, desc.count); | 142 | bindings.storage_buffer, desc.cbuf_index); |
| 135 | ++binding; | 143 | bindings.storage_buffer += desc.count; |
| 136 | } | 144 | } |
| 137 | } | 145 | } |
| 138 | 146 | ||
| @@ -203,10 +211,11 @@ void EmitContext::SetupImages(Bindings& bindings) { | |||
| 203 | } | 211 | } |
| 204 | texture_bindings.reserve(info.texture_descriptors.size()); | 212 | texture_bindings.reserve(info.texture_descriptors.size()); |
| 205 | for (const auto& desc : info.texture_descriptors) { | 213 | for (const auto& desc : info.texture_descriptors) { |
| 214 | const auto sampler_type{SamplerType(desc.type)}; | ||
| 206 | texture_bindings.push_back(bindings.texture); | 215 | texture_bindings.push_back(bindings.texture); |
| 207 | const auto indices{bindings.texture + desc.count}; | 216 | const auto indices{bindings.texture + desc.count}; |
| 208 | for (u32 index = bindings.texture; index < indices; ++index) { | 217 | for (u32 index = bindings.texture; index < indices; ++index) { |
| 209 | Add("layout(binding={}) uniform sampler2D tex{};", bindings.texture, index); | 218 | Add("layout(binding={}) uniform {} tex{};", bindings.texture, sampler_type, index); |
| 210 | } | 219 | } |
| 211 | bindings.texture += desc.count; | 220 | bindings.texture += desc.count; |
| 212 | } | 221 | } |