Fix name aliasing for temporary variables.

This commit is contained in:
Hans-Kristian Arntzen 2018-03-24 01:53:08 +01:00
parent 5161d5ed3b
commit 35f64d03bb
4 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,6 @@
#version 450
void main()
{
}

View File

@ -0,0 +1,10 @@
#version 450
void main()
{
float constituent = float(0);
mat3 _mat3 = mat3(vec3(constituent), vec3(constituent), vec3(constituent));
float constituent_1 = float(1);
_mat3 = mat3(vec3(constituent_1), vec3(constituent_1), vec3(constituent_1));
}

View File

@ -0,0 +1,48 @@
; SPIR-V
; Version: 1.2
; Generator: Khronos; 0
; Bound: 51
; Schema: 0
OpCapability Linkage
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %EntryPoint_Main "main"
OpExecutionMode %EntryPoint_Main OriginUpperLeft
OpSource Unknown 100
OpName %mat3 "mat3"
OpName %constituent "constituent"
OpName %constituent_0 "constituent"
OpName %constituent_1 "constituent"
OpName %constituent_2 "constituent"
OpName %constituent_3 "constituent"
OpName %constituent_4 "constituent"
OpName %constituent_5 "constituent"
OpName %constituent_6 "constituent"
OpName %EntryPoint_Main "EntryPoint_Main"
%void = OpTypeVoid
%_ptr_Function_void = OpTypePointer Function %void
%float = OpTypeFloat 32
%int = OpTypeInt 32 1
%v3float = OpTypeVector %float 3
%mat3v3float = OpTypeMatrix %v3float 3
%_ptr_Function_mat3v3float = OpTypePointer Function %mat3v3float
%14 = OpTypeFunction %void
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%EntryPoint_Main = OpFunction %void None %14
%45 = OpLabel
%mat3 = OpVariable %_ptr_Function_mat3v3float Function
%constituent = OpConvertSToF %float %int_0
%constituent_0 = OpCompositeConstruct %v3float %constituent %constituent %constituent
%constituent_1 = OpCompositeConstruct %v3float %constituent %constituent %constituent
%constituent_2 = OpCompositeConstruct %v3float %constituent %constituent %constituent
%25 = OpCompositeConstruct %mat3v3float %constituent_0 %constituent_1 %constituent_2
OpStore %mat3 %25
%constituent_3 = OpConvertSToF %float %int_1
%constituent_4 = OpCompositeConstruct %v3float %constituent_3 %constituent_3 %constituent_3
%constituent_5 = OpCompositeConstruct %v3float %constituent_3 %constituent_3 %constituent_3
%constituent_6 = OpCompositeConstruct %v3float %constituent_3 %constituent_3 %constituent_3
%30 = OpCompositeConstruct %mat3v3float %constituent_4 %constituent_5 %constituent_6
OpStore %mat3 %30
OpReturn
OpFunctionEnd

View File

@ -3091,6 +3091,7 @@ string CompilerGLSL::declare_temporary(uint32_t result_type, uint32_t result_id)
else
{
// The result_id has not been made into an expression yet, so use flags interface.
add_local_variable_name(result_id);
return join(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, to_name(result_id)), " = ");
}
}
@ -8889,6 +8890,7 @@ void CompilerGLSL::emit_block_chain(SPIRBlock &block)
for (auto &tmp : block.declare_temporary)
{
add_local_variable_name(tmp.second);
auto flags = meta[tmp.second].decoration.decoration_flags;
auto &type = get<SPIRType>(tmp.first);
statement(flags_to_precision_qualifiers_glsl(type, flags), variable_decl(type, to_name(tmp.second)), ";");