From: Mikko Rasa Date: Sun, 7 Nov 2021 14:01:06 +0000 (+0200) Subject: Don't try to access parameters with a pointer access instructior X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e8369afbde298a3011a341cd2d4dfed76ecd8d3b;p=libs%2Fgl.git Don't try to access parameters with a pointer access instructior --- diff --git a/source/glsl/spirv.cpp b/source/glsl/spirv.cpp index d8f24d20..91182a65 100644 --- a/source/glsl/spirv.cpp +++ b/source/glsl/spirv.cpp @@ -518,8 +518,15 @@ void SpirVGenerator::visit(VariableReference &var) r_constant_result = false; if(composite_access) { - r_composite_base = var.declaration; r_expression_result_id = 0; + if(!assignment_source_id) + { + auto i = variable_load_ids.find(var.declaration); + if(i!=variable_load_ids.end()) + r_expression_result_id = i->second; + } + if(!r_expression_result_id) + r_composite_base = var.declaration; } else if(assignment_source_id) { diff --git a/tests/glsl/parameter_composite_access.glsl b/tests/glsl/parameter_composite_access.glsl new file mode 100644 index 00000000..718fffd3 --- /dev/null +++ b/tests/glsl/parameter_composite_access.glsl @@ -0,0 +1,60 @@ +uniform Colors +{ + vec4 top_color; + vec4 bottom_color; +}; + +#pragma MSP stage(vertex) +layout(location=0) in vec4 position; +layout(location=1) in vec3 normal; +void main() +{ + gl_Position = position; + passthrough; +} + +#pragma MSP stage(fragment) +layout(location=0) out vec4 frag_color; +vec4 get_color(vec3 n) +{ + if(n.z>=0) + return top_color; + else + return bottom_color; +} +void main() +{ + frag_color = get_color(normal); +} + +/* Expected output: vertex +layout(location=0) in vec4 position; +layout(location=1) in vec3 normal; +layout(location=0) out vec3 _vs_out_normal; +void main() +{ + gl_Position = position; + _vs_out_normal = normal; +} +*/ + +/* Expected output: fragment +layout(binding=23) uniform Colors +{ + vec4 top_color; + vec4 bottom_color; +}; +layout(location=0) out vec4 frag_color; +vec4 get_color(vec3 n) +{ + if(n.z>=0.0) + return top_color; + else + return bottom_color; +} +layout(location=0) in vec3 _vs_out_normal; +void main() +{ + frag_color = get_color(_vs_out_normal); +} +*/