diff --git a/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp b/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp index d21552433f..14fbf14c4b 100644 --- a/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp +++ b/tools/clang/lib/SPIRV/DeclResultIdMapper.cpp @@ -1186,6 +1186,7 @@ SpirvVariable *DeclResultIdMapper::createExternVar(const VarDecl *var) { SpirvVariable *DeclResultIdMapper::createExternVar(const VarDecl *var, QualType type) { + const auto name = var->getName(); const bool isGroupShared = var->hasAttr(); const bool hasInlineSpirvSC = var->hasAttr(); const bool isACSBuffer = @@ -1217,7 +1218,12 @@ SpirvVariable *DeclResultIdMapper::createExternVar(const VarDecl *var, createGlobalsCBuffer(var); auto *varInstr = astDecls[var].instr; - return varInstr ? cast(varInstr) : nullptr; + if (varInstr) { + createDebugGlobalVariable(cast(varInstr), type, loc, name); + return cast(varInstr); + } + + return nullptr; } if (isResourceOnlyStructure(type)) { @@ -1245,7 +1251,6 @@ SpirvVariable *DeclResultIdMapper::createExternVar(const VarDecl *var, needsFlatteningCompositeResources = true; } - const auto name = var->getName(); SpirvVariable *varInstr = spvBuilder.addModuleVar( type, storageClass, var->hasAttr(), var->hasAttr(), name, llvm::None, loc); diff --git a/tools/clang/test/CodeGenSPIRV/shader.debug.debuglexicalblock.hlsl b/tools/clang/test/CodeGenSPIRV/shader.debug.debuglexicalblock.hlsl index 429aa061d4..a08faa43d1 100644 --- a/tools/clang/test/CodeGenSPIRV/shader.debug.debuglexicalblock.hlsl +++ b/tools/clang/test/CodeGenSPIRV/shader.debug.debuglexicalblock.hlsl @@ -1,13 +1,17 @@ // RUN: %dxc -T ps_6_0 -E main -fspv-debug=vulkan -fcgl %s -spirv | FileCheck %s -// CHECK: [[debugSet:%[0-9]+]] = OpExtInstImport "NonSemantic.Shader.DebugInfo.100" -// CHECK: [[debugSource:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugSource -// CHECK: [[main:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugFunction -// CHECK: [[mainFnLexBlock:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugLexicalBlock [[debugSource]] %uint_13 %uint_1 [[main]] -// CHECK: [[whileLoopLexBlock:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugLexicalBlock [[debugSource]] %uint_21 %uint_3 [[mainFnLexBlock]] -// CHECK: [[ifStmtLexBlock:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugLexicalBlock [[debugSource]] %uint_26 %uint_20 [[whileLoopLexBlock]] -// CHECK: [[tempLexBlock:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugLexicalBlock [[debugSource]] %uint_28 %uint_7 [[ifStmtLexBlock]] -// CHECK: [[forLoopLexBlock:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugLexicalBlock [[debugSource]] %uint_15 %uint_12 [[mainFnLexBlock]] +// CHECK: [[debugSet:%[0-9]+]] = OpExtInstImport "NonSemantic.Shader.DebugInfo.100" +// CHECK: [[foo:%[0-9]+]] = OpString "foo" +// CHECK: [[debugSource:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugSource +// CHECK: [[main:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugFunction +// CHECK: [[mainFnLexBlock:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugLexicalBlock [[debugSource]] %uint_17 %uint_1 [[main]] +// CHECK: [[whileLoopLexBlock:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugLexicalBlock [[debugSource]] %uint_25 %uint_3 [[mainFnLexBlock]] +// CHECK: [[ifStmtLexBlock:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugLexicalBlock [[debugSource]] %uint_30 %uint_20 [[whileLoopLexBlock]] +// CHECK: [[tempLexBlock:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugLexicalBlock [[debugSource]] %uint_32 %uint_7 [[ifStmtLexBlock]] +// CHECK: [[forLoopLexBlock:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugLexicalBlock [[debugSource]] %uint_19 %uint_12 [[mainFnLexBlock]] +// CHECK: [[globalVar:%[0-9]+]] = OpExtInst %void [[debugSet]] DebugGlobalVariable [[foo]] %25 [[debugSource]] %uint_14 %uint_15 + +uniform float foo; float4 main(float4 color : COLOR) : SV_TARGET { @@ -31,6 +35,6 @@ float4 main(float4 color : COLOR) : SV_TARGET } } - return color + c; + return color + c * foo; }