summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl
diff options
context:
space:
mode:
authorGravatar ameerj2021-06-18 00:54:16 -0400
committerGravatar ameerj2021-07-22 21:51:38 -0400
commit9e066dcb15b46a1b71068c4865f4a035aa0a43d4 (patch)
tree14efef9dcf2b2f033b5fb979d62ab0e501523403 /src/shader_recompiler/backend/glsl
parentshaders: Allow shader notify when async shaders is disabled (diff)
downloadyuzu-9e066dcb15b46a1b71068c4865f4a035aa0a43d4.tar.gz
yuzu-9e066dcb15b46a1b71068c4865f4a035aa0a43d4.tar.xz
yuzu-9e066dcb15b46a1b71068c4865f4a035aa0a43d4.zip
glsl: Fix output varying initialization when transform feedback is used
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_special.cpp40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
index 1a2d3dcea..2a15fc29a 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_special.cpp
@@ -12,13 +12,47 @@
12 12
13namespace Shader::Backend::GLSL { 13namespace Shader::Backend::GLSL {
14namespace { 14namespace {
15std::string_view OutputVertexIndex(EmitContext& ctx) {
16 return ctx.stage == Stage::TessellationControl ? "[gl_InvocationID]" : "";
17}
18
15void InitializeOutputVaryings(EmitContext& ctx) { 19void InitializeOutputVaryings(EmitContext& ctx) {
16 if (ctx.stage == Stage::VertexB || ctx.stage == Stage::Geometry) { 20 if (ctx.stage == Stage::VertexB || ctx.stage == Stage::Geometry) {
17 ctx.Add("gl_Position=vec4(0,0,0,1);"); 21 ctx.Add("gl_Position=vec4(0,0,0,1);");
18 } 22 }
19 for (size_t index = 0; index < 16; ++index) { 23 for (size_t index = 0; index < ctx.info.stores_generics.size(); ++index) {
20 if (ctx.info.stores_generics[index]) { 24 if (!ctx.info.stores_generics[index]) {
21 ctx.Add("out_attr{}=vec4(0,0,0,1);", index); 25 continue;
26 }
27 const auto& info_array{ctx.output_generics.at(index)};
28 const auto output_decorator{OutputVertexIndex(ctx)};
29 size_t element{};
30 while (element < info_array.size()) {
31 const auto& info{info_array.at(element)};
32 const auto varying_name{fmt::format("{}{}", info.name, output_decorator)};
33 switch (info.num_components) {
34 case 1: {
35 const char value{element == 3 ? '1' : '0'};
36 ctx.Add("{}={}.f;", varying_name, value);
37 break;
38 }
39 case 2:
40 case 3:
41 if (element + info.num_components < 4) {
42 ctx.Add("{}=vec{}(0);", varying_name, info.num_components);
43 } else {
44 // last element is the w component, must be initialized to 1
45 const auto zeros{info.num_components == 3 ? "0,0," : "0,"};
46 ctx.Add("{}=vec{}({}1);", varying_name, info.num_components, zeros);
47 }
48 break;
49 case 4:
50 ctx.Add("{}=vec4(0,0,0,1);", varying_name);
51 break;
52 default:
53 break;
54 }
55 element += info.num_components;
22 } 56 }
23 } 57 }
24} 58}