Skip to content

[WIP] Debug info entry as local #8069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jkwak-work
Copy link
Collaborator

@jkwak-work jkwak-work commented Aug 5, 2025

DO NOT REVIEW
WIP

The intention

This commit is to reconstruct the entry-point parameters as local variables.
And then, we will be able to provide the debug information to the shader debuggers easily.

Consider the pre-existing test, tests/spirv/debug-variable-scope.slang,

struct PSIn
{
   float4 pos      : SV_Position;
};

float4 main(PSIn input) : SV_TARGET
{ ... }

Currently the following command removes the entry point variable and each member is inlined to where they are used.

$ build/Debug/bin/slangc.exe -target glsl tests/spirv/debug-variable-scope.slang -stage fragment -entry main -line-directive-mode none

void main()
{
    entryPointParam_main_0 = vec4((texture(sampler2D(testTex_0,testSampler_0), (vec2(uvec4(gl_FragCoord).xy) / 32.0), (-1.0))).xyz, 1.0);
    return;
}

This commit is to reconstruct the entry-point parameter as a local variable so that we can provide Debug info for the entry point parameter,

void main()
{
    /////// ENTRY POINT PARAMETER IS RECONSTRUCTED AS LOCAL VARIABLE
    PSIn input;
    input.pos = gl_FragCoord;
    /////// ENTRY POINT PARAMETER IS RECONSTRUCTED AS LOCAL VARIABLE

    entryPointParam_main_0 = vec4((texture(sampler2D(testTex_0,testSampler_0), (vec2(uvec4(input.pos).xy) / 32.0), (-1.0))).xyz, 1.0);
    return;
}

When the entry-point parameter is an array of struct

One thing to note is that when the entry point is an array of struct, tests/cross-compile/geometry-shader.slang,

struct CoarseVertex
{
    float4 position     : POSITION;
    float3 color        : COLOR;
    uint   id           : ID;
}

void main(
    triangle CoarseVertex coarseVertices[3],
    inout TriangleStream<RasterVertex> outputStream,
    uint primitiveID : SV_PrimitiveID)
{ ... }

Currently it generates the following,

$ build/Debug/bin/slangc.exe -target glsl -stage geometry -entry main tests/cross-compile/geometry-shader.slang -line-directive-mode none

void main()
{
    CoarseVertex_0 _S1 = { coarseVertices_position_0[0], coarseVertices_color_0[0], coarseVertices_id_0[0] };
    CoarseVertex_0 _S2 = { coarseVertices_position_0[1], coarseVertices_color_0[1], coarseVertices_id_0[1] };
    CoarseVertex_0 _S3 = { coarseVertices_position_0[2], coarseVertices_color_0[2], coarseVertices_id_0[2] };
    CoarseVertex_0  _S4[3] = { _S1, _S2, _S3 };

This commit will change it to the following,

void main()
{
    /////// ENTRY POINT PARAMETER IS RECONSTRUCTED AS LOCAL VARIABLE
    CoarseVertex_0 coarseVertices[3];
    coarseVertices[0] = { coarseVertices_position_0[0], coarseVertices_color_0[0], coarseVertices_id_0[0] };
    coarseVertices[1] = { coarseVertices_position_0[1], coarseVertices_color_0[1], coarseVertices_id_0[1] };
    coarseVertices[2] = { coarseVertices_position_0[2], coarseVertices_color_0[2], coarseVertices_id_0[2] };
    /////// ENTRY POINT PARAMETER IS RECONSTRUCTED AS LOCAL VARIABLE

    CoarseVertex_0 _S1 = coarseVertices[0];
    CoarseVertex_0 _S2 = coarseVertices[1];
    CoarseVertex_0 _S3 = coarseVertices[2];

The tricky part is that the system build-in variables are in a form of array for each semantic.
And the user expect to get the debug information in a form of "array-of-struct".
The implementation maps each member variable to its corresponding global variable with DebugValue.

@jkwak-work jkwak-work self-assigned this Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant