From ed9f42361e2f07a79fde39ded9e57473d5fac39f Mon Sep 17 00:00:00 2001 From: Lujin Wang <143145775+lujinwangnv@users.noreply.github.com> Date: Thu, 18 Sep 2025 10:37:14 -0700 Subject: Fix DebugCompilationUnit to reference main shader file instead of header files (#7957) This PR implements the requested fix for issue #7923 where DebugCompilationUnit incorrectly referenced header files instead of the main shader file. ## Summary - Modified IRDebugSource to include isIncludedFile flag as third operand - Updated emitDebugSource function to accept and pass the included file flag - Updated call sites to use source->isIncludedFile() from SourceFile class - Modified SPIR-V emission to only create DebugCompilationUnit for non-included files ## Test Results The fix has been verified with the provided reproducer code. The SPIR-V output now correctly shows DebugCompilationUnit referencing the main shader file instead of header files. Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Lujin Wang Co-authored-by: Claude Code Co-authored-by: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- tests/spirv/debug-compilation-unit-main-file.slang | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/spirv/debug-compilation-unit-main-file.slang (limited to 'tests/spirv/debug-compilation-unit-main-file.slang') diff --git a/tests/spirv/debug-compilation-unit-main-file.slang b/tests/spirv/debug-compilation-unit-main-file.slang new file mode 100644 index 000000000..c8e89ae93 --- /dev/null +++ b/tests/spirv/debug-compilation-unit-main-file.slang @@ -0,0 +1,37 @@ +//TEST:SIMPLE(filecheck=CHECK):-target spirv -entry main -stage fragment -g2 -emit-spirv-directly + +#include "shader-utils.slang" + +struct VertexOutput +{ + float4 position : SV_Position; + float2 texCoord : TEXCOORD0; +} + +[shader("fragment")] +float4 main(VertexOutput input) : SV_Target +{ + // Create a simple gradient pattern based on texture coordinates + float2 uv = input.texCoord; + + // Call function from the included header file + float distanceFromCenter = calculateDistanceFromCenter(uv); + + // Use another function from the header for a radial fade effect + float radialFade = createRadialFade(uv, 0.7); + + // Create color pattern with both distance effects + float4 color = float4( + uv.x * (1.0 - distanceFromCenter * 0.5), // Red with subtle distance fade + uv.y * radialFade, // Green with smooth radial fade + uv.x * uv.y, // Blue as product of coordinates + 1.0 // Full opacity + ); + + return color; +} + +// Verify that DebugCompilationUnit references this main shader file +// CHECK: [[MAIN_FILE:%[0-9]+]] = OpString "{{.*}}debug-compilation-unit-main-file.slang" +// CHECK: [[SOURCE_ID:%[0-9]+]] = OpExtInst %void %{{[0-9]+}} DebugSource [[MAIN_FILE]] %{{[0-9]+}} +// CHECK: OpExtInst %void %{{[0-9]+}} DebugCompilationUnit %uint_{{[0-9]+}} %uint_{{[0-9]+}} [[SOURCE_ID]] %uint_{{[0-9]+}} -- cgit v1.2.3