diff options
| author | 2021-05-26 21:18:17 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:36 -0400 | |
| commit | d171083d53e106c8c5131522fdc81d51360c562d (patch) | |
| tree | 282cbd1306616e969166e9ddc926bc51c1c15803 /src/shader_recompiler/backend/glsl/emit_context.cpp | |
| parent | glsl: Implement some attribute getters and setters (diff) | |
| download | yuzu-d171083d53e106c8c5131522fdc81d51360c562d.tar.gz yuzu-d171083d53e106c8c5131522fdc81d51360c562d.tar.xz yuzu-d171083d53e106c8c5131522fdc81d51360c562d.zip | |
glsl: textures wip
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_context.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_context.cpp | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_context.cpp b/src/shader_recompiler/backend/glsl/emit_context.cpp index 8e5983909..de19e0fba 100644 --- a/src/shader_recompiler/backend/glsl/emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/emit_context.cpp | |||
| @@ -8,9 +8,21 @@ | |||
| 8 | #include "shader_recompiler/profile.h" | 8 | #include "shader_recompiler/profile.h" |
| 9 | 9 | ||
| 10 | namespace Shader::Backend::GLSL { | 10 | namespace Shader::Backend::GLSL { |
| 11 | namespace { | ||
| 12 | std::string_view InterpDecorator(Interpolation interp) { | ||
| 13 | switch (interp) { | ||
| 14 | case Interpolation::Smooth: | ||
| 15 | return ""; | ||
| 16 | case Interpolation::Flat: | ||
| 17 | return "flat"; | ||
| 18 | case Interpolation::NoPerspective: | ||
| 19 | return "noperspective"; | ||
| 20 | } | ||
| 21 | throw InvalidArgument("Invalid interpolation {}", interp); | ||
| 22 | } | ||
| 23 | } // namespace | ||
| 11 | 24 | ||
| 12 | EmitContext::EmitContext(IR::Program& program, [[maybe_unused]] Bindings& bindings, | 25 | EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile& profile_) |
| 13 | const Profile& profile_) | ||
| 14 | : info{program.info}, profile{profile_} { | 26 | : info{program.info}, profile{profile_} { |
| 15 | std::string header = "#version 450\n"; | 27 | std::string header = "#version 450\n"; |
| 16 | SetupExtensions(header); | 28 | SetupExtensions(header); |
| @@ -49,7 +61,8 @@ EmitContext::EmitContext(IR::Program& program, [[maybe_unused]] Bindings& bindin | |||
| 49 | for (size_t index = 0; index < info.input_generics.size(); ++index) { | 61 | for (size_t index = 0; index < info.input_generics.size(); ++index) { |
| 50 | const auto& generic{info.input_generics[index]}; | 62 | const auto& generic{info.input_generics[index]}; |
| 51 | if (generic.used) { | 63 | if (generic.used) { |
| 52 | Add("layout(location={})in vec4 in_attr{};", index, index); | 64 | Add("layout(location={}) {} in vec4 in_attr{};", index, |
| 65 | InterpDecorator(generic.interpolation), index); | ||
| 53 | } | 66 | } |
| 54 | } | 67 | } |
| 55 | for (size_t index = 0; index < info.stores_frag_color.size(); ++index) { | 68 | for (size_t index = 0; index < info.stores_frag_color.size(); ++index) { |
| @@ -66,6 +79,7 @@ EmitContext::EmitContext(IR::Program& program, [[maybe_unused]] Bindings& bindin | |||
| 66 | DefineConstantBuffers(); | 79 | DefineConstantBuffers(); |
| 67 | DefineStorageBuffers(); | 80 | DefineStorageBuffers(); |
| 68 | DefineHelperFunctions(); | 81 | DefineHelperFunctions(); |
| 82 | SetupImages(bindings); | ||
| 69 | Add("void main(){{"); | 83 | Add("void main(){{"); |
| 70 | 84 | ||
| 71 | if (stage == Stage::VertexA || stage == Stage::VertexB) { | 85 | if (stage == Stage::VertexA || stage == Stage::VertexB) { |
| @@ -102,7 +116,7 @@ void EmitContext::DefineConstantBuffers() { | |||
| 102 | } | 116 | } |
| 103 | u32 binding{}; | 117 | u32 binding{}; |
| 104 | for (const auto& desc : info.constant_buffer_descriptors) { | 118 | for (const auto& desc : info.constant_buffer_descriptors) { |
| 105 | Add("layout(std140,binding={}) uniform cbuf_{}{{vec4 cbuf{}[{}];}};", binding, binding, | 119 | Add("layout(std140,binding={}) uniform cbuf_{}{{vec4 cbuf{}[{}];}};", binding, desc.index, |
| 106 | desc.index, 4 * 1024); | 120 | desc.index, 4 * 1024); |
| 107 | ++binding; | 121 | ++binding; |
| 108 | } | 122 | } |
| @@ -164,4 +178,36 @@ void EmitContext::DefineHelperFunctions() { | |||
| 164 | } | 178 | } |
| 165 | } | 179 | } |
| 166 | 180 | ||
| 181 | void EmitContext::SetupImages(Bindings& bindings) { | ||
| 182 | image_buffer_bindings.reserve(info.image_buffer_descriptors.size()); | ||
| 183 | for (const auto& desc : info.image_buffer_descriptors) { | ||
| 184 | throw NotImplementedException("image_buffer_descriptors"); | ||
| 185 | image_buffer_bindings.push_back(bindings.image); | ||
| 186 | bindings.image += desc.count; | ||
| 187 | } | ||
| 188 | image_bindings.reserve(info.image_descriptors.size()); | ||
| 189 | for (const auto& desc : info.image_descriptors) { | ||
| 190 | throw NotImplementedException("image_bindings"); | ||
| 191 | |||
| 192 | image_bindings.push_back(bindings.image); | ||
| 193 | bindings.image += desc.count; | ||
| 194 | } | ||
| 195 | texture_buffer_bindings.reserve(info.texture_buffer_descriptors.size()); | ||
| 196 | for (const auto& desc : info.texture_buffer_descriptors) { | ||
| 197 | throw NotImplementedException("TextureType::Buffer"); | ||
| 198 | |||
| 199 | texture_buffer_bindings.push_back(bindings.texture); | ||
| 200 | bindings.texture += desc.count; | ||
| 201 | } | ||
| 202 | texture_bindings.reserve(info.texture_descriptors.size()); | ||
| 203 | for (const auto& desc : info.texture_descriptors) { | ||
| 204 | texture_bindings.push_back(bindings.texture); | ||
| 205 | const auto indices{bindings.texture + desc.count}; | ||
| 206 | for (u32 index = bindings.texture; index < indices; ++index) { | ||
| 207 | Add("layout(binding={}) uniform sampler2D tex{};", bindings.texture, index); | ||
| 208 | } | ||
| 209 | bindings.texture += desc.count; | ||
| 210 | } | ||
| 211 | } | ||
| 212 | |||
| 167 | } // namespace Shader::Backend::GLSL | 213 | } // namespace Shader::Backend::GLSL |