KhronosGroup / KhronosGroup/SPIRV-Tools

OpUndef in output of spirv-opt -Os on shader with non-semantic debug info seems unexpected

Open
#6,718 7 comments 0 reactions 1 assignee Claimed by @SteveUrquhart View on GitHub
component:optimization
Dominant language
C++
Stars
1.4k
Forks
709
Avg merge
1d 22h
Merged PRs (30d)
28

Description

This may be a case of "this is what happens when you optimize a shader with non-semantic debug info" (in which case, feel free to close the bug), but I thought it would be worth someone taking a look at to make sure this is expected behavior out of spirv-opt. We had a shader with non semantic debug info which when run through `spirv-opt -Os` and then debugged in RenderDoc would end up showing variables as having undefined value. I tried to strip it down to a simple reproducer case. Here is the slang input shader, the important variable here is the o.vNormalWs:

```
struct VsOut
{
float4 vPositionWs : TEXCOORD0;
float3 vNormalWs : TEXCOORD1; // <-- the member that goes OpUndef
float4 vColor : TEXCOORD2;
float4 pos : SV_Position;
};

cbuffer C
{
float3x3 g_xform;
float g_thickness;
}

VsOut Fill(float3 n, float4 p, float4 c)
{
VsOut o;
o.vNormalWs = normalize(mul(n, g_xform));
o.vPositionWs = p;
o.vColor = c;
o.pos = p;
return o;
}

VsOut MainVs(float3 n : NORMAL, float4 p : POSITION, float4 c : COLOR)
{
VsOut o = Fill(n, p, c);

float s = g_thickness * c.x;
o.vPositionWs.xyz += s * o.vNormalWs;
return o;
}
```

The shader compiled with slang using `slangc min_repro.slang -target spirv -stage vertex -entry MainVs -g2 -O0 -emit-spirv-directly -o full_debug_info.spv` yields the following with non semantic debug info.:

```
; SPIR-V
; Version: 1.5
; Generator: Khronos Slang Compiler; 0
; Bound: 249
; Schema: 0
OpCapability Shader
OpExtension "SPV_KHR_non_semantic_info"
%2 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
%165 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %MainVs "main" %C %entryPointParam_MainVs_vPositionWs %entryPointParam_MainVs_vNormalWs %entryPointParam_MainVs_vColor %gl_Position %n_0 %p_0 %c_0
%1 = OpString "struct VsOut
{
float4 vPositionWs : TEXCOORD0;
float3 vNormalWs : TEXCOORD1; // <-- the member that goes OpUndef
float4 vColor : TEXCOORD2;
float4 pos : SV_Position;
};

cbuffer C
{
float3x3 g_xform;
float g_thickness;
}

VsOut Fill(float3 n, float4 p, float4 c)
{
VsOut o;
o.vNormalWs = normalize(mul(n, g_xform)); // becomes the live `Normalize` SSA value
o.vPositionWs = p;
o.vColor = c;
o.pos = p;
return o;
}

VsOut MainVs(float3 n : NORMAL, float4 p : POSITION, float4 c : COLOR)
{
VsOut o = Fill(n, p, c);

float s = g_thickness * c.x;
o.vPositionWs.xyz += s * o.vNormalWs; // reads vNormalWs (live) to update vPositionWs
return o;
}
"
%5 = OpString "C:\\Users\\Dan\\Downloads\\min_repro.slang"
OpSource Slang 1
%29 = OpString "float"
%36 = OpString "vPositionWs"
%42 = OpString "vNormalWs"
%45 = OpString "vColor"
%48 = OpString "pos"
%52 = OpString "VsOut"
%61 = OpString "MainVs"
%66 = OpString "slangc"
%67 = OpString "-target spirv -I \"C:\\VulkanSDK\\1.4.341.1\\Bin\" -matrix-layout-column-major -O0 -stage vertex -entry MainVs -g2"
%69 = OpString "c"
%78 = OpString "p"
%86 = OpString "n"
%101 = OpString "o"
%117 = OpString "Fill"
%149 = OpString "g_xform"
%152 = OpString "g_thickness"
%154 = OpString "SLANG_ParameterGroup_C_std140"
%157 = OpString "C"
%198 = OpString "s"
%232 = OpString "entryPointParam_MainVs.vPositionWs"
%238 = OpString "entryPointParam_MainVs.vNormalWs"
%243 = OpString "entryPointParam_MainVs.vColor"
OpName %_dbgvar_c "_dbgvar_c"
OpName %_dbgvar_p "_dbgvar_p"
OpName %_dbgvar_n "_dbgvar_n"
OpName %VsOut "VsOut"
OpMemberName %VsOut 0 "vPositionWs"
OpMemberName %VsOut 1 "vNormalWs"
OpMemberName %VsOut 2 "vColor"
OpMemberName %VsOut 3 "pos"
OpName %_dbgvar_o "_dbgvar_o"
OpName %o "o"
OpName %o "o"
OpName %_dbgvar_s "_dbgvar_s"
OpName %c "c"
OpName %c_0 "c"
OpName %p "p"
OpName %p_0 "p"
OpName %n "n"
OpName %n_0 "n"
OpName %o_0 "o"
OpName %n_1 "n"
OpName %p_1 "p"
OpName %c_1 "c"
OpName %_dbgvar_c_0 "_dbgvar_c"
OpName %_dbgvar_p_0 "_dbgvar_p"
OpName %_dbgvar_n_0 "_dbgvar_n"
OpName %_dbgvar_o_0 "_dbgvar_o"
OpName %o_1 "o"
OpName %o_1 "o"
OpName %c_2 "c"
OpName %p_2 "p"
OpName %n_2 "n"
OpName %o_2 "o"
OpName %SLANG_ParameterGroup_C_std140 "SLANG_ParameterGroup_C_std140"
OpMemberName %SLANG_ParameterGroup_C_std140 0 "g_xform"
OpMemberName %SLANG_ParameterGroup_C_std140 1 "g_thickness"
OpName %C "C"
OpName %Fill "Fill"
OpName %s "s"
OpName %s_0 "s"
OpName %entryPointParam_MainVs_vPositionWs "entryPointParam_MainVs.vPositionWs"
OpName %entryPointParam_MainVs_vNormalWs "entryPointParam_MainVs.vNormalWs"
OpName %entryPointParam_MainVs_vColor "entryPointParam_MainVs.vColor"
OpName %MainVs "MainVs"
OpDecorate %c_0 Location 2
OpDecorate %p_0 Location 1
OpDecorate %n_0 Location 0
OpDecorate %SLANG_ParameterGroup_C_std140 Block
OpMemberDecorate %SLANG_ParameterGroup_C_std140 0 Offset 0
OpMemberDecorate %SLANG_ParameterGroup_C_std140 0 RowMajor
OpMemberDecorate %SLANG_ParameterGroup_C_std140 0 MatrixStride 16
OpMemberDecorate %SLANG_ParameterGroup_C_std140 1 Offset 48
OpDecorate %C Binding 0
OpDecorate %C DescriptorSet 0
OpDecorate %entryPointParam_MainVs_vPositionWs Location 0
OpDecorate %entryPointParam_MainVs_vNormalWs Location 1
OpDecorate %entryPointParam_MainVs_vColor Location 2
OpDecorate %gl_Position BuiltIn Position
%void = OpTypeVoid
%4 = OpExtInst %void %2 DebugSource %5 %1
%uint = OpTypeInt 32 0
%uint_11 = OpConstant %uint 11
%uint_5 = OpConstant %uint 5
%uint_100 = OpConstant %uint 100
%10 = OpExtInst %void %2 DebugCompilationUnit %uint_100 %uint_5 %4 %uint_11
%12 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Function_v4float = OpTypePointer Function %v4float
%v3float = OpTypeVector %float 3
%_ptr_Function_v3float = OpTypePointer Function %v3float
%VsOut = OpTypeStruct %v4float %v3float %v4float %v4float
%_ptr_Function_VsOut = OpTypePointer Function %VsOut
%_ptr_Function_float = OpTypePointer Function %float
%uint_32 = OpConstant %uint 32
%uint_3 = OpConstant %uint 3
%uint_131072 = OpConstant %uint 131072
%28 = OpExtInst %void %2 DebugTypeBasic %29 %uint_32 %uint_3 %uint_131072
%uint_4 = OpConstant %uint 4
%33 = OpExtInst %void %2 DebugTypeVector %28 %uint_4
%uint_12 = OpConstant %uint 12
%uint_0 = OpConstant %uint 0
%uint_128 = OpConstant %uint 128
%35 = OpExtInst %void %2 DebugTypeMember %36 %33 %4 %uint_3 %uint_12 %uint_0 %uint_128 %uint_0
%40 = OpExtInst %void %2 DebugTypeVector %28 %uint_3
%uint_96 = OpConstant %uint 96
%41 = OpExtInst %void %2 DebugTypeMember %42 %40 %4 %uint_4 %uint_12 %uint_128 %uint_96 %uint_0
%uint_224 = OpConstant %uint 224
%44 = OpExtInst %void %2 DebugTypeMember %45 %33 %4 %uint_5 %uint_12 %uint_224 %uint_128 %uint_0
%uint_6 = OpConstant %uint 6
%uint_352 = OpConstant %uint 352
%47 = OpExtInst %void %2 DebugTypeMember %48 %33 %4 %uint_6 %uint_12 %uint_352 %uint_128 %uint_0
%uint_1 = OpConstant %uint 1
%uint_8 = OpConstant %uint 8
%uint_480 = OpConstant %uint 480
%51 = OpExtInst %void %2 DebugTypeComposite %52 %uint_1 %4 %uint_1 %uint_8 %10 %52 %uint_480 %uint_131072 %35 %41 %44 %47
%uint_7 = OpConstant %uint 7
%56 = OpExtInst %void %2 DebugTypePointer %40 %uint_7 %uint_131072
%58 = OpExtInst %void %2 DebugTypePointer %33 %uint_7 %uint_131072
%59 = OpExtInst %void %2 DebugTypeFunction %uint_0 %51 %56 %58 %58
%uint_25 = OpConstant %uint 25
%60 = OpExtInst %void %2 DebugFunction %61 %59 %4 %uint_25 %uint_7 %10 %61 %uint_0 %uint_25
%65 = OpExtInst %void %2 DebugEntryPoint %60 %10 %66 %67
%c = OpExtInst %void %2 DebugLocalVariable %69 %33 %4 %uint_25 %uint_7 %60 %uint_0 %uint_3
%70 = OpExtInst %void %2 DebugExpression
%_ptr_Input_v4float = OpTypePointer Input %v4float
%uint_2 = OpConstant %uint 2
%p = OpExtInst %void %2 DebugLocalVariable %78 %33 %4 %uint_25 %uint_7 %60 %uint_0 %uint_2
%n = OpExtInst %void %2 DebugLocalVariable %86 %40 %4 %uint_25 %uint_7 %60 %uint_0 %uint_1
%_ptr_Input_v3float = OpTypePointer Input %v3float
%uint_27 = OpConstant %uint 27
%o_0 = OpExtInst %void %2 DebugLocalVariable %101 %51 %4 %uint_27 %uint_11 %60 %uint_0
%105 = OpTypeFunction %VsOut %v3float %v4float %v4float
%115 = OpExtInst %void %2 DebugTypeFunction %uint_0 %51 %40 %33 %33
%uint_15 = OpConstant %uint 15
%116 = OpExtInst %void %2 DebugFunction %117 %115 %4 %uint_15 %uint_7 %10 %117 %uint_0 %uint_15
%c_2 = OpExtInst %void %2 DebugLocalVariable %69 %33 %4 %uint_15 %uint_7 %116 %uint_0 %uint_3
%p_2 = OpExtInst %void %2 DebugLocalVariable %78 %33 %4 %uint_15 %uint_7 %116 %uint_0 %uint_2
%n_2 = OpExtInst %void %2 DebugLocalVariable %86 %40 %4 %uint_15 %uint_7 %116 %uint_0 %uint_1
%uint_17 = OpConstant %uint 17
%o_2 = OpExtInst %void %2 DebugLocalVariable %101 %51 %4 %uint_17 %uint_11 %116 %uint_0
%uint_18 = OpConstant %uint 18
%int = OpTypeInt 32 1
%int_1 = OpConstant %int 1
%mat3v3float = OpTypeMatrix %v3float 3
%SLANG_ParameterGroup_C_std140 = OpTypeStruct %mat3v3float %float
%_ptr_Uniform_SLANG_ParameterGroup_C_std140 = OpTypePointer Uniform %SLANG_ParameterGroup_C_std140
%bool = OpTypeBool
%true = OpConstantTrue %bool
%145 = OpExtInst %void %2 DebugTypeMatrix %40 %uint_3 %true
%uint_288 = OpConstant %uint 288
%148 = OpExtInst %void %2 DebugTypeMember %149 %145 %4 %uint_11 %uint_11 %uint_0 %uint_288 %uint_0
%151 = OpExtInst %void %2 DebugTypeMember %152 %28 %4 %uint_12 %uint_8 %uint_288 %uint_32 %uint_0
%uint_320 = OpConstant %uint 320
%153 = OpExtInst %void %2 DebugTypeComposite %154 %uint_1 %4 %uint_0 %uint_0 %10 %154 %uint_320 %uint_131072 %148 %151
%uint_9 = OpConstant %uint 9
%int_0 = OpConstant %int 0
%_ptr_Uniform_mat3v3float = OpTypePointer Uniform %mat3v3float
%uint_19 = OpConstant %uint 19
%uint_20 = OpConstant %uint 20
%int_2 = OpConstant %int 2
%uint_21 = OpConstant %uint 21
%int_3 = OpConstant %int 3
%uint_22 = OpConstant %uint 22
%uint_29 = OpConstant %uint 29
%s = OpExtInst %void %2 DebugLocalVariable %198 %28 %4 %uint_29 %uint_11 %60 %uint_0
%_ptr_Uniform_float = OpTypePointer Uniform %float
%uint_30 = OpConstant %uint 30
%uint_31 = OpConstant %uint 31
%_ptr_Output_v4float = OpTypePointer Output %v4float
%_ptr_Output_v3float = OpTypePointer Output %v3float
%c_0 = OpVariable %_ptr_Input_v4float Input
%75 = OpExtInst %void %2 DebugGlobalVariable %69 %33 %4 %uint_0 %uint_0 %10 %69 %c_0 %uint_0
%p_0 = OpVariable %_ptr_Input_v4float Input
%83 = OpExtInst %void %2 DebugGlobalVariable %78 %33 %4 %uint_0 %uint_0 %10 %78 %p_0 %uint_0
%n_0 = OpVariable %_ptr_Input_v3float Input
%91 = OpExtInst %void %2 DebugGlobalVariable %86 %40 %4 %uint_0 %uint_0 %10 %86 %n_0 %uint_0
%C = OpVariable %_ptr_Uniform_SLANG_ParameterGroup_C_std140 Uniform
%156 = OpExtInst %void %2 DebugGlobalVariable %157 %153 %4 %uint_9 %uint_9 %10 %157 %C %uint_0
%entryPointParam_MainVs_vPositionWs = OpVariable %_ptr_Output_v4float Output
%231 = OpExtInst %void %2 DebugGlobalVariable %232 %33 %4 %uint_0 %uint_0 %10 %232 %entryPointParam_MainVs_vPositionWs %uint_0
%entryPointParam_MainVs_vNormalWs = OpVariable %_ptr_Output_v3float Output
%237 = OpExtInst %void %2 DebugGlobalVariable %238 %40 %4 %uint_0 %uint_0 %10 %238 %entryPointParam_MainVs_vNormalWs %uint_0
%entryPointParam_MainVs_vColor = OpVariable %_ptr_Output_v4float Output
%242 = OpExtInst %void %2 DebugGlobalVariable %243 %33 %4 %uint_0 %uint_0 %10 %243 %entryPointParam_MainVs_vColor %uint_0
%gl_Position = OpVariable %_ptr_Output_v4float Output
%MainVs = OpFunction %void None %12
%13 = OpLabel
%_dbgvar_c = OpVariable %_ptr_Function_v4float Function
%_dbgvar_p = OpVariable %_ptr_Function_v4float Function
%_dbgvar_n = OpVariable %_ptr_Function_v3float Function
%_dbgvar_o = OpVariable %_ptr_Function_VsOut Function
%o = OpVariable %_ptr_Function_VsOut Function
%_dbgvar_s = OpVariable %_ptr_Function_float Function
%63 = OpExtInst %void %2 DebugFunctionDefinition %60 %MainVs
%64 = OpExtInst %void %2 DebugScope %60
%71 = OpExtInst %void %2 DebugDeclare %c %_dbgvar_c %70
%72 = OpLoad %v4float %c_0
OpStore %_dbgvar_c %72
%80 = OpExtInst %void %2 DebugDeclare %p %_dbgvar_p %70
%81 = OpLoad %v4float %p_0
OpStore %_dbgvar_p %81
%87 = OpExtInst %void %2 DebugDeclare %n %_dbgvar_n %70
%88 = OpLoad %v3float %n_0
OpStore %_dbgvar_n %88
%93 = OpLoad %v3float %n_0
%94 = OpLoad %v4float %p_0
%95 = OpLoad %v4float %c_0
%96 = OpExtInst %void %2 DebugLine %4 %uint_27 %uint_27 %uint_5 %uint_6
%98 = OpExtInst %void %2 DebugLine %4 %uint_27 %uint_27 %uint_5 %uint_6
%99 = OpExtInst %void %2 DebugLine %4 %uint_27 %uint_27 %uint_5 %uint_6
%102 = OpExtInst %void %2 DebugDeclare %o_0 %_dbgvar_o %70
%103 = OpFunctionCall %VsOut %Fill %93 %94 %95
OpStore %o %103
OpStore %_dbgvar_o %103
%195 = OpExtInst %void %2 DebugLine %4 %uint_29 %uint_29 %uint_5 %uint_6
%199 = OpExtInst %void %2 DebugDeclare %s %_dbgvar_s %70
%201 = OpAccessChain %_ptr_Uniform_float %C %int_1
%202 = OpLoad %float %201
%203 = OpCompositeExtract %float %95 0
%s_0 = OpFMul %float %202 %203
OpStore %_dbgvar_s %s_0
%206 = OpExtInst %void %2 DebugLine %4 %uint_30 %uint_30 %uint_5 %uint_6
%208 = OpAccessChain %_ptr_Function_v4float %o %int_0
%209 = OpLoad %v4float %208
%210 = OpVectorShuffle %v3float %209 %209 0 1 2
%211 = OpAccessChain %_ptr_Function_v3float %o %int_1
%212 = OpLoad %v3float %211
%213 = OpVectorTimesScalar %v3float %212 %s_0
%214 = OpFAdd %v3float %210 %213
%215 = OpAccessChain %_ptr_Function_float %208 %int_0
%216 = OpCompositeExtract %float %214 0
OpStore %215 %216
%217 = OpAccessChain %_ptr_Function_float %208 %int_1
%218 = OpCompositeExtract %float %214 1
OpStore %217 %218
%219 = OpAccessChain %_ptr_Function_float %208 %int_2
%220 = OpCompositeExtract %float %214 2
OpStore %219 %220
%222 = OpLoad %v4float %208
%223 = OpAccessChain %_ptr_Function_v4float %_dbgvar_o %int_0
OpStore %223 %222
%225 = OpExtInst %void %2 DebugLine %4 %uint_31 %uint_31 %uint_5 %uint_6
%227 = OpLoad %VsOut %o
%228 = OpCompositeExtract %v4float %227 0
OpStore %entryPointParam_MainVs_vPositionWs %228
%234 = OpCompositeExtract %v3float %227 1
OpStore %entryPointParam_MainVs_vNormalWs %234
%240 = OpCompositeExtract %v4float %227 2
OpStore %entryPointParam_MainVs_vColor %240
%245 = OpCompositeExtract %v4float %227 3
OpStore %gl_Position %245
OpReturn
OpFunctionEnd
%Fill = OpFunction %VsOut None %105
%n_1 = OpFunctionParameter %v3float
%p_1 = OpFunctionParameter %v4float
%c_1 = OpFunctionParameter %v4float
%109 = OpLabel
%_dbgvar_c_0 = OpVariable %_ptr_Function_v4float Function
%_dbgvar_p_0 = OpVariable %_ptr_Function_v4float Function
%_dbgvar_n_0 = OpVariable %_ptr_Function_v3float Function
%_dbgvar_o_0 = OpVariable %_ptr_Function_VsOut Function
%o_1 = OpVariable %_ptr_Function_VsOut Function
%119 = OpExtInst %void %2 DebugFunctionDefinition %116 %Fill
%120 = OpExtInst %void %2 DebugScope %116
%122 = OpExtInst %void %2 DebugDeclare %c_2 %_dbgvar_c_0 %70
%124 = OpExtInst %void %2 DebugDeclare %p_2 %_dbgvar_p_0 %70
%126 = OpExtInst %void %2 DebugDeclare %n_2 %_dbgvar_n_0 %70
OpStore %_dbgvar_n_0 %n_1
OpStore %_dbgvar_p_0 %p_1
OpStore %_dbgvar_c_0 %c_1
%130 = OpExtInst %void %2 DebugLine %4 %uint_17 %uint_17 %uint_5 %uint_6
%132 = OpExtInst %void %2 DebugLine %4 %uint_17 %uint_17 %uint_5 %uint_6
%133 = OpExtInst %void %2 DebugLine %4 %uint_17 %uint_17 %uint_5 %uint_6
%135 = OpExtInst %void %2 DebugDeclare %o_2 %_dbgvar_o_0 %70
%136 = OpExtInst %void %2 DebugLine %4 %uint_18 %uint_18 %uint_5 %uint_6
%140 = OpAccessChain %_ptr_Function_v3float %o_1 %int_1
%161 = OpAccessChain %_ptr_Uniform_mat3v3float %C %int_0
%162 = OpLoad %mat3v3float %161
%163 = OpMatrixTimesVector %v3float %162 %n_1
%164 = OpExtInst %v3float %165 Normalize %163
OpStore %140 %164
%167 = OpAccessChain %_ptr_Function_v3float %_dbgvar_o_0 %int_1
OpStore %167 %164
%169 = OpExtInst %void %2 DebugLine %4 %uint_19 %uint_19 %uint_5 %uint_6
%171 = OpAccessChain %_ptr_Function_v4float %o_1 %int_0
OpStore %171 %p_1
%173 = OpAccessChain %_ptr_Function_v4float %_dbgvar_o_0 %int_0
OpStore %173 %p_1
%175 = OpExtInst %void %2 DebugLine %4 %uint_20 %uint_20 %uint_5 %uint_6
%178 = OpAccessChain %_ptr_Function_v4float %o_1 %int_2
OpStore %178 %c_1
%180 = OpAccessChain %_ptr_Function_v4float %_dbgvar_o_0 %int_2
OpStore %180 %c_1
%182 = OpExtInst %void %2 DebugLine %4 %uint_21 %uint_21 %uint_5 %uint_6
%185 = OpAccessChain %_ptr_Function_v4float %o_1 %int_3
OpStore %185 %p_1
%187 = OpAccessChain %_ptr_Function_v4float %_dbgvar_o_0 %int_3
OpStore %187 %p_1
%189 = OpExtInst %void %2 DebugLine %4 %uint_22 %uint_22 %uint_5 %uint_6
%191 = OpLoad %VsOut %o_1
OpReturnValue %191
OpFunctionEnd

```

Here is the optimized version

```
; SPIR-V
; Version: 1.5
; Generator: Khronos Slang Compiler; 0
; Bound: 554
; Schema: 0
OpCapability Shader
OpExtension "SPV_KHR_non_semantic_info"
%2 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
%165 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Vertex %MainVs "main" %C %entryPointParam_MainVs_vPositionWs %entryPointParam_MainVs_vNormalWs %entryPointParam_MainVs_vColor %gl_Position %n_0 %p_0 %c_0
%1 = OpString "struct VsOut
{
float4 vPositionWs : TEXCOORD0;
float3 vNormalWs : TEXCOORD1; // <-- the member that goes OpUndef
float4 vColor : TEXCOORD2;
float4 pos : SV_Position;
};

cbuffer C
{
float3x3 g_xform;
float g_thickness;
}

VsOut Fill(float3 n, float4 p, float4 c)
{
VsOut o;
o.vNormalWs = normalize(mul(n, g_xform)); // becomes the live `Normalize` SSA value
o.vPositionWs = p;
o.vColor = c;
o.pos = p;
return o;
}

VsOut MainVs(float3 n : NORMAL, float4 p : POSITION, float4 c : COLOR)
{
VsOut o = Fill(n, p, c);

float s = g_thickness * c.x;
o.vPositionWs.xyz += s * o.vNormalWs; // reads vNormalWs (live) to update vPositionWs
return o;
}
"
%5 = OpString "C:\\Users\\Dan\\Downloads\\min_repro.slang"
OpSource Slang 1
%29 = OpString "float"
%36 = OpString "vPositionWs"
%42 = OpString "vNormalWs"
%45 = OpString "vColor"
%48 = OpString "pos"
%52 = OpString "VsOut"
%61 = OpString "MainVs"
%66 = OpString "slangc"
%67 = OpString "-target spirv -I \"C:\\VulkanSDK\\1.4.341.1\\Bin\" -matrix-layout-column-major -O0 -stage vertex -entry MainVs -g2"
%69 = OpString "c"
%78 = OpString "p"
%86 = OpString "n"
%101 = OpString "o"
%117 = OpString "Fill"
%149 = OpString "g_xform"
%152 = OpString "g_thickness"
%154 = OpString "SLANG_ParameterGroup_C_std140"
%157 = OpString "C"
%198 = OpString "s"
%232 = OpString "entryPointParam_MainVs.vPositionWs"
%238 = OpString "entryPointParam_MainVs.vNormalWs"
%243 = OpString "entryPointParam_MainVs.vColor"
OpName %c "c"
OpName %c_0 "c"
OpName %p "p"
OpName %p_0 "p"
OpName %n "n"
OpName %n_0 "n"
OpName %o "o"
OpName %c_1 "c"
OpName %p_1 "p"
OpName %n_1 "n"
OpName %o_0 "o"
OpName %SLANG_ParameterGroup_C_std140 "SLANG_ParameterGroup_C_std140"
OpMemberName %SLANG_ParameterGroup_C_std140 0 "g_xform"
OpMemberName %SLANG_ParameterGroup_C_std140 1 "g_thickness"
OpName %C "C"
OpName %s "s"
OpName %s_0 "s"
OpName %entryPointParam_MainVs_vPositionWs "entryPointParam_MainVs.vPositionWs"
OpName %entryPointParam_MainVs_vNormalWs "entryPointParam_MainVs.vNormalWs"
OpName %entryPointParam_MainVs_vColor "entryPointParam_MainVs.vColor"
OpName %MainVs "MainVs"
OpDecorate %c_0 Location 2
OpDecorate %p_0 Location 1
OpDecorate %n_0 Location 0
OpDecorate %SLANG_ParameterGroup_C_std140 Block
OpMemberDecorate %SLANG_ParameterGroup_C_std140 0 Offset 0
OpMemberDecorate %SLANG_ParameterGroup_C_std140 0 RowMajor
OpMemberDecorate %SLANG_ParameterGroup_C_std140 0 MatrixStride 16
OpMemberDecorate %SLANG_ParameterGroup_C_std140 1 Offset 48
OpDecorate %C Binding 0
OpDecorate %C DescriptorSet 0
OpDecorate %entryPointParam_MainVs_vPositionWs Location 0
OpDecorate %entryPointParam_MainVs_vNormalWs Location 1
OpDecorate %entryPointParam_MainVs_vColor Location 2
OpDecorate %gl_Position BuiltIn Position
%void = OpTypeVoid
%uint = OpTypeInt 32 0
%uint_11 = OpConstant %uint 11
%uint_5 = OpConstant %uint 5
%uint_100 = OpConstant %uint 100
%12 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%v3float = OpTypeVector %float 3
%uint_32 = OpConstant %uint 32
%uint_3 = OpConstant %uint 3
%uint_131072 = OpConstant %uint 131072
%uint_4 = OpConstant %uint 4
%uint_12 = OpConstant %uint 12
%uint_0 = OpConstant %uint 0
%uint_128 = OpConstant %uint 128
%uint_96 = OpConstant %uint 96
%uint_224 = OpConstant %uint 224
%uint_6 = OpConstant %uint 6
%uint_352 = OpConstant %uint 352
%uint_1 = OpConstant %uint 1
%uint_8 = OpConstant %uint 8
%uint_480 = OpConstant %uint 480
%uint_7 = OpConstant %uint 7
%uint_25 = OpConstant %uint 25
%_ptr_Input_v4float = OpTypePointer Input %v4float
%uint_2 = OpConstant %uint 2
%_ptr_Input_v3float = OpTypePointer Input %v3float
%uint_27 = OpConstant %uint 27
%uint_15 = OpConstant %uint 15
%uint_17 = OpConstant %uint 17
%uint_18 = OpConstant %uint 18
%int = OpTypeInt 32 1
%int_1 = OpConstant %int 1
%mat3v3float = OpTypeMatrix %v3float 3
%SLANG_ParameterGroup_C_std140 = OpTypeStruct %mat3v3float %float
%_ptr_Uniform_SLANG_ParameterGroup_C_std140 = OpTypePointer Uniform %SLANG_ParameterGroup_C_std140
%bool = OpTypeBool
%true = OpConstantTrue %bool
%uint_288 = OpConstant %uint 288
%uint_320 = OpConstant %uint 320
%uint_9 = OpConstant %uint 9
%int_0 = OpConstant %int 0
%_ptr_Uniform_mat3v3float = OpTypePointer Uniform %mat3v3float
%uint_19 = OpConstant %uint 19
%uint_20 = OpConstant %uint 20
%int_2 = OpConstant %int 2
%uint_21 = OpConstant %uint 21
%int_3 = OpConstant %int 3
%uint_29 = OpConstant %uint 29
%_ptr_Uniform_float = OpTypePointer Uniform %float
%uint_30 = OpConstant %uint 30
%uint_31 = OpConstant %uint 31
%_ptr_Output_v4float = OpTypePointer Output %v4float
%_ptr_Output_v3float = OpTypePointer Output %v3float
%c_0 = OpVariable %_ptr_Input_v4float Input
%p_0 = OpVariable %_ptr_Input_v4float Input
%n_0 = OpVariable %_ptr_Input_v3float Input
%C = OpVariable %_ptr_Uniform_SLANG_ParameterGroup_C_std140 Uniform
%entryPointParam_MainVs_vPositionWs = OpVariable %_ptr_Output_v4float Output
%entryPointParam_MainVs_vNormalWs = OpVariable %_ptr_Output_v3float Output
%entryPointParam_MainVs_vColor = OpVariable %_ptr_Output_v4float Output
%gl_Position = OpVariable %_ptr_Output_v4float Output
%548 = OpUndef %v4float
%549 = OpUndef %v3float
%528 = OpExtInst %void %2 DebugInfoNone
%70 = OpExtInst %void %2 DebugExpression
%368 = OpExtInst %void %2 DebugOperation %uint_0
%4 = OpExtInst %void %2 DebugSource %5 %1
%10 = OpExtInst %void %2 DebugCompilationUnit %uint_100 %uint_5 %4 %uint_11
%28 = OpExtInst %void %2 DebugTypeBasic %29 %uint_32 %uint_3 %uint_131072
%33 = OpExtInst %void %2 DebugTypeVector %28 %uint_4
%35 = OpExtInst %void %2 DebugTypeMember %36 %33 %4 %uint_3 %uint_12 %uint_0 %uint_128 %uint_0
%40 = OpExtInst %void %2 DebugTypeVector %28 %uint_3
%41 = OpExtInst %void %2 DebugTypeMember %42 %40 %4 %uint_4 %uint_12 %uint_128 %uint_96 %uint_0
%44 = OpExtInst %void %2 DebugTypeMember %45 %33 %4 %uint_5 %uint_12 %uint_224 %uint_128 %uint_0
%47 = OpExtInst %void %2 DebugTypeMember %48 %33 %4 %uint_6 %uint_12 %uint_352 %uint_128 %uint_0
%51 = OpExtInst %void %2 DebugTypeComposite %52 %uint_1 %4 %uint_1 %uint_8 %10 %52 %uint_480 %uint_131072 %35 %41 %44 %47
%56 = OpExtInst %void %2 DebugTypePointer %40 %uint_7 %uint_131072
%58 = OpExtInst %void %2 DebugTypePointer %33 %uint_7 %uint_131072
%59 = OpExtInst %void %2 DebugTypeFunction %uint_0 %51 %56 %58 %58
%60 = OpExtInst %void %2 DebugFunction %61 %59 %4 %uint_25 %uint_7 %10 %61 %uint_0 %uint_25
%65 = OpExtInst %void %2 DebugEntryPoint %60 %10 %66 %67
%c = OpExtInst %void %2 DebugLocalVariable %69 %33 %4 %uint_25 %uint_7 %60 %uint_0 %uint_3
%p = OpExtInst %void %2 DebugLocalVariable %78 %33 %4 %uint_25 %uint_7 %60 %uint_0 %uint_2
%n = OpExtInst %void %2 DebugLocalVariable %86 %40 %4 %uint_25 %uint_7 %60 %uint_0 %uint_1
%o = OpExtInst %void %2 DebugLocalVariable %101 %51 %4 %uint_27 %uint_11 %60 %uint_0
%115 = OpExtInst %void %2 DebugTypeFunction %uint_0 %51 %40 %33 %33
%116 = OpExtInst %void %2 DebugFunction %117 %115 %4 %uint_15 %uint_7 %10 %117 %uint_0 %uint_15
%c_1 = OpExtInst %void %2 DebugLocalVariable %69 %33 %4 %uint_15 %uint_7 %116 %uint_0 %uint_3
%p_1 = OpExtInst %void %2 DebugLocalVariable %78 %33 %4 %uint_15 %uint_7 %116 %uint_0 %uint_2
%n_1 = OpExtInst %void %2 DebugLocalVariable %86 %40 %4 %uint_15 %uint_7 %116 %uint_0 %uint_1
%o_0 = OpExtInst %void %2 DebugLocalVariable %101 %51 %4 %uint_17 %uint_11 %116 %uint_0
%145 = OpExtInst %void %2 DebugTypeMatrix %40 %uint_3 %true
%148 = OpExtInst %void %2 DebugTypeMember %149 %145 %4 %uint_11 %uint_11 %uint_0 %uint_288 %uint_0
%151 = OpExtInst %void %2 DebugTypeMember %152 %28 %4 %uint_12 %uint_8 %uint_288 %uint_32 %uint_0
%153 = OpExtInst %void %2 DebugTypeComposite %154 %uint_1 %4 %uint_0 %uint_0 %10 %154 %uint_320 %uint_131072 %148 %151
%s = OpExtInst %void %2 DebugLocalVariable %198 %28 %4 %uint_29 %uint_11 %60 %uint_0
%75 = OpExtInst %void %2 DebugGlobalVariable %69 %33 %4 %uint_0 %uint_0 %10 %69 %c_0 %uint_0
%83 = OpExtInst %void %2 DebugGlobalVariable %78 %33 %4 %uint_0 %uint_0 %10 %78 %p_0 %uint_0
%91 = OpExtInst %void %2 DebugGlobalVariable %86 %40 %4 %uint_0 %uint_0 %10 %86 %n_0 %uint_0
%156 = OpExtInst %void %2 DebugGlobalVariable %157 %153 %4 %uint_9 %uint_9 %10 %157 %C %uint_0
%231 = OpExtInst %void %2 DebugGlobalVariable %232 %33 %4 %uint_0 %uint_0 %10 %232 %entryPointParam_MainVs_vPositionWs %uint_0
%237 = OpExtInst %void %2 DebugGlobalVariable %238 %40 %4 %uint_0 %uint_0 %10 %238 %entryPointParam_MainVs_vNormalWs %uint_0
%242 = OpExtInst %void %2 DebugGlobalVariable %243 %33 %4 %uint_0 %uint_0 %10 %243 %entryPointParam_MainVs_vColor %uint_0
%312 = OpExtInst %void %2 DebugInlinedAt %uint_27 %60
%367 = OpExtInst %void %2 DebugExpression %368
%433 = OpExtInst %void %2 DebugExpression %368
%MainVs = OpFunction %void None %12
%13 = OpLabel
%63 = OpExtInst %void %2 DebugFunctionDefinition %60 %MainVs
%550 = OpExtInst %void %2 DebugScope %60
%492 = OpExtInst %void %2 DebugValue %c %548 %70
%493 = OpExtInst %void %2 DebugValue %p %548 %70
%494 = OpExtInst %void %2 DebugValue %n %549 %70
%93 = OpLoad %v3float %n_0
%94 = OpLoad %v4float %p_0
%95 = OpLoad %v4float %c_0
%551 = OpExtInst %void %2 DebugScope %116 %312
%495 = OpExtInst %void %2 DebugValue %n_1 %93 %70
%496 = OpExtInst %void %2 DebugValue %p_1 %94 %70
%497 = OpExtInst %void %2 DebugValue %c_1 %95 %70
%341 = OpExtInst %void %2 DebugLine %4 %uint_18 %uint_18 %uint_5 %uint_6
%325 = OpAccessChain %_ptr_Uniform_mat3v3float %C %int_0
%326 = OpLoad %mat3v3float %325
%327 = OpMatrixTimesVector %v3float %326 %93
%328 = OpExtInst %v3float %165 Normalize %327
%499 = OpExtInst %void %2 DebugValue %o_0 %328 %70 %int_1
%503 = OpExtInst %void %2 DebugLine %4 %uint_19 %uint_19 %uint_5 %uint_6
%502 = OpExtInst %void %2 DebugValue %o_0 %94 %70 %int_0
%506 = OpExtInst %void %2 DebugLine %4 %uint_20 %uint_20 %uint_5 %uint_6
%505 = OpExtInst %void %2 DebugValue %o_0 %95 %70 %int_2
%509 = OpExtInst %void %2 DebugLine %4 %uint_21 %uint_21 %uint_5 %uint_6
%508 = OpExtInst %void %2 DebugValue %o_0 %94 %70 %int_3
%552 = OpExtInst %void %2 DebugScope %60
%512 = OpExtInst %void %2 DebugLine %4 %uint_27 %uint_27 %uint_5 %uint_6
%511 = OpExtInst %void %2 DebugValue %o %94 %70 %int_0
%514 = OpExtInst %void %2 DebugValue %o %328 %70 %int_1
%517 = OpExtInst %void %2 DebugValue %o %95 %70 %int_2
%520 = OpExtInst %void %2 DebugValue %o %94 %70 %int_3
%253 = OpExtInst %void %2 DebugLine %4 %uint_29 %uint_29 %uint_5 %uint_6
%201 = OpAccessChain %_ptr_Uniform_float %C %int_1
%202 = OpLoad %float %201
%203 = OpCompositeExtract %float %95 0
%s_0 = OpFMul %float %202 %203
%523 = OpExtInst %void %2 DebugValue %s %s_0 %70
%260 = OpExtInst %void %2 DebugLine %4 %uint_30 %uint_30 %uint_5 %uint_6
%210 = OpVectorShuffle %v3float %94 %94 0 1 2
%213 = OpVectorTimesScalar %v3float %328 %s_0
%214 = OpFAdd %v3float %210 %213
%216 = OpCompositeExtract %float %214 0
%532 = OpCompositeInsert %v4float %216 %94 0
%218 = OpCompositeExtract %float %214 1
%537 = OpCompositeInsert %v4float %218 %532 1
%220 = OpCompositeExtract %float %214 2
%542 = OpCompositeInsert %v4float %220 %537 2
%526 = OpExtInst %void %2 DebugValue %o %548 %70 %int_0
%279 = OpExtInst %void %2 DebugLine %4 %uint_31 %uint_31 %uint_5 %uint_6
OpStore %entryPointParam_MainVs_vPositionWs %542
OpStore %entryPointParam_MainVs_vNormalWs %328
OpStore %entryPointParam_MainVs_vColor %95
OpStore %gl_Position %94
OpReturn
%553 = OpExtInst %void %2 DebugNoScope
OpFunctionEnd
```

You will note that in the optimized shader it references:

```
%542 = OpCompositeInsert %v4float %220 %537 2
%526 = OpExtInst %void %2 DebugValue %o %548 %70 %int_0
````
where %540 is

```
%548 = OpUndef %v4float
```

I don't believe this is correct, I think it should reference %542?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.