Skip to content
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

[SPIR-V] generated SPIR-V is invalid: ID 'XXX[%XXX]' has not been defined #7025

Open
fnuecke opened this issue Dec 4, 2024 · 1 comment
Open
Labels
bug Bug, regression, crash spirv Work related to SPIR-V

Comments

@fnuecke
Copy link

fnuecke commented Dec 4, 2024

Description
I ran into an unexpected fatal error when compiling a mesh shader with debug symbols. Compilation passes successfully without debug symbols enabled (i.e. without the -fspv-debug=vulkan-with-source flag).

Steps to Reproduce
Repro on godbolt: https://godbolt.org/z/oh8fjYcb8

Given this shader code:

// test.hlsl

#define MAX_VERTICES 64
#define MAX_PRIMITIVES 124

struct MeshPayload {
  uint data[32];
};

struct VertexAttributes {
    float3 position : SV_Position;
};

[outputtopology("triangle")]
[numthreads(1, 1, 1)]
void main(
  in payload MeshPayload payload,
  uint gid : SV_GroupID,
  out indices uint3 triangles[MAX_PRIMITIVES],
  out vertices VertexAttributes vertices[MAX_VERTICES]
) {
  uint data = payload.data[gid];
}

Run DXC with the following command:

dxc -T ms_6_5 -spirv -fspv-target-env=vulkan1.1spirv1.4 -fspv-debug=vulkan-with-source test.hlsl

Actual Behavior

Output:

fatal error: generated SPIR-V is invalid: ID '356[%356]' has not been defined
  %355 = OpExtInst %void %1 DebugValue %71 %356 %75 %int_0

Expected: no error, debug information embedded in SPIR-V output.

Environment

  • DXC version:
    • July 2024: libdxcompiler.so: 1.8(dev;4662-416fab6b); libdxil.so: 1.8
    • Trunk: libdxcompiler.so: 1.8(dev;4773-eb1223e0); libdxil.so: 1.8
  • Host Operating System
    • Manjaro Linux
    • uname -a: Linux guybrush 6.11.10-2-MANJARO #1 SMP PREEMPT_DYNAMIC Mon, 25 Nov 2024 05:29:44 +0000 x86_64 GNU/Linux

I'm aware that resources are limited and debug-related issues are not a priority. If you can provide me with some pointers on where to start, I might have a look if I can figure out some more details. Thank you!

@fnuecke fnuecke added bug Bug, regression, crash needs-triage Awaiting triage spirv Work related to SPIR-V labels Dec 4, 2024
@damyanp damyanp moved this to For Google in HLSL Triage Dec 17, 2024
@Keenuts
Copy link
Collaborator

Keenuts commented Jan 2, 2025

Thanks!

This looks to be caused by the copy-propagate-arrays pass during the legalization step.
The DebugValue was previously generated because a local variable was modified.
The pass created a new OpAccessChain directly accessing the array without going through the local variable (and will let DCE remove this dead code), and patched the DebugValue instruction.

Issue is the OpAccessChain is added after the patched DebugValue instruction, causing an invalid forward reference.

@Keenuts Keenuts removed the needs-triage Awaiting triage label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, regression, crash spirv Work related to SPIR-V
Projects
Status: For Google
Development

No branches or pull requests

2 participants