From: Mikko Rasa Date: Tue, 9 Mar 2021 20:27:04 +0000 (+0200) Subject: Avoid removing outputs which are referenced but not assigned X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=5b33d00373c6f4953d684f8cc75c9353df469735 Avoid removing outputs which are referenced but not assigned The values from such reads are undefined but the variables should be kept nevertheless. --- diff --git a/source/glsl/optimize.cpp b/source/glsl/optimize.cpp index 7f60e67c..500c8417 100644 --- a/source/glsl/optimize.cpp +++ b/source/glsl/optimize.cpp @@ -661,7 +661,7 @@ bool UnusedVariableRemover::apply(Stage &s) } if(output) { - if(!i->second.assignments.empty() && i->second.interface_block) + if((i->second.referenced || !i->second.assignments.empty()) && i->second.interface_block) used_interface_blocks.insert(i->second.interface_block); continue; } diff --git a/tests/glsl/referenced_but_unassigned_output.glsl b/tests/glsl/referenced_but_unassigned_output.glsl new file mode 100644 index 00000000..aabff089 --- /dev/null +++ b/tests/glsl/referenced_but_unassigned_output.glsl @@ -0,0 +1,50 @@ +uniform mat4 projection; + +#pragma MSP stage(vertex) +layout(location=0) in vec4 position; +layout(location=1) in vec3 normal; +out vec4 eye_vertex; +out VertexOut +{ + vec4 color; +}; +void main() +{ + gl_Position = projection*eye_vertex; + out float alpha = color.a; +} + +#pragma MSP stage(fragment) +layout(location=0) out vec4 frag_color; +void main() +{ + frag_color = vec4(color.rgb, alpha); +} + +/* Expected output: vertex +uniform mat4 projection; +out vec4 eye_vertex; +out VertexOut +{ + vec4 color; +}; +out float alpha; +void main() +{ + gl_Position = projection*eye_vertex; + alpha = color.a; +} +*/ + +/* Expected output: fragment +layout(location=0) out vec4 frag_color; +in VertexOut +{ + vec4 color; +}; +in float alpha; +void main() +{ + frag_color = vec4(color.rgb, alpha); +} +*/