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 ] NonSemantic.Shader.DebugInfo.100 DebugDeclare: expected operand Variable must be a result id of OpVariable or OpFunctionParameter #5191

Open
danginsburg opened this issue May 8, 2023 · 12 comments · Fixed by #7127
Assignees
Labels
bug Bug, regression, crash spirv Work related to SPIR-V

Comments

@danginsburg
Copy link
Contributor

We encountered the following error with one of our shaders when using -fspv-debug=vulkan-with-source to debug the shader in RenderDoc:

fatal error: generated SPIR-V is invalid: NonSemantic.Shader.DebugInfo.100 DebugDeclare: expected operand Variable must be a result id of OpVariable or OpFunctionParameter
  %94 = OpExtInst %void %1 DebugDeclare %36 %92 %20

@jeremy-lunarg helped strip it down to a test case we could share (attached). You can reproduce the error with this shader and the following command-line:

dxc.exe -spirv -T vs_6_0 -E MainVs -fspv-debug=vulkan-with-source shaderdebug_simple.hlsl
fatal error: generated SPIR-V is invalid: NonSemantic.Shader.DebugInfo.100 DebugDeclare: expected operand Variable must be a result id of OpVariable or OpFunctionParameter
  %94 = OpExtInst %void %1 DebugDeclare %36 %92 %20

note: please file a bug report on https://github.com/Microsoft/DirectXShaderCompiler/issues with source code if possible

shaderdebug_simple.zip

@s-perron s-perron added bug Bug, regression, crash spirv Work related to SPIR-V labels May 9, 2023
@jeremy-lunarg
Copy link
Contributor

I've done some investigating and it appears to be coming from the exhaustive inlining pass.

@Sphag
Copy link

Sphag commented May 23, 2023

I've stumbled upon this problem myself recently, after investigation it appears to be a problem in EmitVisitor::visit functions for some SpirvDebug types such as SpirvDebugEntryPoint, SpirvDebugFunctionDefinition, SpirvDebugScope, SpirvDebugDeclare. The problem is that the finalizeInstruction call in these functions should be called with &richDebugInfo instead of &mainBinary. I changed it to &richDebugInfo locally and it fixed the issue for me. I don't know if it's the right way to fix this, but I can roll out a pull request with the fix.

@jeremy-lunarg
Copy link
Contributor

I'm working on fix to the optimizer to convert access chain function call arguments to temporary OpVariables so the inlining pass can handle DebubDeclare correctly.

@jeremy-lunarg
Copy link
Contributor

After discussing with @s-perron and @greg-lunarg, I believe the work that @llvm-beanz is doing will completely avoid this problem and it is the ideal way to fix this issue.

@s-perron
Copy link
Collaborator

It will avoid it until we add reference to the language. We can wait until references are implemented to fix it. Otherwise we won't be able to test the fix.

@ChristianReinbold
Copy link
Contributor

As far as I see it, this problem still persists. I stumbled over it recently as well. In case you need a simple reproducer, see here: https://godbolt.org/z/nYeW4KrbE

Compile

void fn(inout int x) { x = 2; }

// Define some dummy entry point
[shader("raygeneration")]
void main() {
    int2 v;
    fn(v.x);
}

with options -T lib_6_4 -spirv -fspv-target-env=vulkan1.2 -enable-16bit-types -HV 2021 -fspv-debug=vulkan-with-source.

Actual Behavior
DXC crashes with

fatal error: generated SPIR-V is invalid: NonSemantic.Shader.DebugInfo.100 DebugDeclare: expected operand Variable must be a result id of OpVariable or OpFunctionParameter
  %63 = OpExtInst %void %1 DebugDeclare %29 %61 %15

@neversleeping
Copy link

Issue is still there. I got it in MANY different places, but this is my easiest reproduce:
https://godbolt.org/z/zosPGqjWv

@s-perron s-perron modified the milestones: Backlog, Next+1 Release Feb 5, 2025
@s-perron s-perron assigned s-perron and unassigned jeremy-lunarg Feb 5, 2025
s-perron added a commit to s-perron/DirectXShaderCompiler that referenced this issue Feb 6, 2025
DXC tries to avoid the copy-in-copy-out for some parameters when it
thinks it is possible. However, the SPIR-V spec says that if a parameter
is a pointer, it must point to a memory object declarion or a pointer to
an element in a sampler or image array.

This PR enforces this. If the pointer for the parameter is not an
OpVariable (a memory object declaration), then we do not elide the
copy-in copy-out.

Fixes microsoft#7095
Fixes microsoft#5191
@s-perron
Copy link
Collaborator

s-perron commented Feb 6, 2025

I have a PR that should fix some of the cases. Let me know if there are other.

@s-perron s-perron moved this from New to In review in HLSL Roadmap Feb 6, 2025
@github-project-automation github-project-automation bot moved this from In review to Done in HLSL Roadmap Feb 19, 2025
@kp-eagle
Copy link

kp-eagle commented Feb 19, 2025

@s-perron #7127 Fixed some cases, but, for example, this will still fail:
https://godbolt.org/z/E8vWded94

struct SomeStruct
{
    float a;
    float getA(){ return a; }
};

cbuffer ConstBuffer {
    SomeStruct str;
}

[numthreads(1, 1, 1)]
void computeMain()
{
	float a = str.getA();
}

-E computeMain -T cs_6_6 -spirv -fspv-debug=vulkan-with-source

@s-perron s-perron reopened this Feb 19, 2025
@devshgraphicsprogramming

@s-perron #7127 Fixed some cases, but, for example, this will still fail: https://godbolt.org/z/E8vWded94

struct SomeStruct
{
float a;
float getA(){ return a; }
};

cbuffer ConstBuffer {
SomeStruct str;
}

[numthreads(1, 1, 1)]
void computeMain()
{
float a = str.getA();
}

-E computeMain -T cs_6_6 -spirv -fspv-debug=vulkan-with-source

@kp-eagle btw the Godbolt instance still says fcbd2a18 when asked for --version

@kp-eagle
Copy link

@s-perron #7127 Fixed some cases, but, for example, this will still fail: https://godbolt.org/z/E8vWded94
struct SomeStruct
{
float a;
float getA(){ return a; }
};
cbuffer ConstBuffer {
SomeStruct str;
}
[numthreads(1, 1, 1)]
void computeMain()
{
float a = str.getA();
}
-E computeMain -T cs_6_6 -spirv -fspv-debug=vulkan-with-source

@kp-eagle btw the Godbolt instance still says fcbd2a18 when asked for --version

I didn't test it in Godbolt. Link is just for convenience. I built it locally with merged commit. So, if you think that it actually works after it - no, it doesn't =)

@devshgraphicsprogramming

@s-perron #7127 Fixed some cases, but, for example, this will still fail: https://godbolt.org/z/E8vWded94
struct SomeStruct
{
float a;
float getA(){ return a; }
};
cbuffer ConstBuffer {
SomeStruct str;
}
[numthreads(1, 1, 1)]
void computeMain()
{
float a = str.getA();
}
-E computeMain -T cs_6_6 -spirv -fspv-debug=vulkan-with-source

@kp-eagle btw the Godbolt instance still says fcbd2a18 when asked for --version

I didn't test it in Godbolt. Link is just for convenience. I built it locally with merged commit. So, if you think that it actually works after it - no, it doesn't =)

I see, I'm still waiting on Godbolt to see if my other stuff breaks because of inout being copy-in copy-out now

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: Done
Status: Triaged
8 participants