Skip to content

[SPIR-V] generated SPIR-V is invalid: [VUID-StandaloneSpirv-OpTypeImage-06924] Cannot store to OpTypeImage, OpTypeSampler, OpTypeSampledImage, or OpTypeAccelerationStructureKHR objects #7181

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

Closed
gjaegy opened this issue Mar 6, 2025 · 26 comments · Fixed by #7303
Assignees
Labels
bug Bug, regression, crash spirv Work related to SPIR-V

Comments

@gjaegy
Copy link

gjaegy commented Mar 6, 2025

Description
Invalid SPIR-V is generated with the latest release and with head, when compiling with debug

Steps to Reproduce
Compile with the following command:
dxc.exe mipmap_gen_envmap.hlsl -E maincomp -T cs_6_0 -spirv -fspv-target-env=vulkan1.1 -Wall -Wno-unused-const-variable -D imBINDLESS=0 -fspv-extension=SPV_KHR_non_semantic_info -fspv-debug=vulkan-with-source -fspv-extension=SPV_EXT_descriptor_indexing

Actual Behavior
fatal error: generated SPIR-V is invalid: [VUID-StandaloneSpirv-OpTypeImage-06924] Cannot store to OpTypeImage, OpTypeSampler, OpTypeSampledImage, or OpTypeAccelerationStructureKHR objects
OpStore %927 %3239

Problem doesn't occur without the "-fspv-debug=vulkan-with-source" option

Environment

  • DXC version February 2025
  • Host Operating System Windows 11

Please contact me and I will send you a repro case per email.

@gjaegy gjaegy added bug Bug, regression, crash needs-triage Awaiting triage spirv Work related to SPIR-V labels Mar 6, 2025
@sd20134
Copy link

sd20134 commented Mar 24, 2025

I get the same error on code

@s-perron
Copy link
Collaborator

Can you provide a shader that reproduces this issue? This type of error typically happens because the optimizer failed to copy propagate the temporaries that stored the opaque types like the images and samplers. Without a specific example, I cannot tell why it did not optimize. Considering that the debug info makes a difference, it could be that an extension is added that turns off optimization.

If you can't provide a specific example, please compile with -Vd and add a comment with the OpExtension instruction at the top of the SPIR-V.

@gjaegy
Copy link
Author

gjaegy commented Mar 25, 2025

Yes I can. How can I send it to you (I am not allowed to make the shader public) ?

@s-perron
Copy link
Collaborator

s-perron commented Mar 25, 2025

If you can't make the shader public, then I probably can't accept it privately unless you have NDA in place with Google. I cannot accept your secrets. Can you make the extensions public? That is most likely the problem.

EDIT changed to "can't accept it"

@gjaegy
Copy link
Author

gjaegy commented Mar 25, 2025

Yes I simply don't want to publish it here, but can send it to you per email?

@gjaegy
Copy link
Author

gjaegy commented Mar 26, 2025

I can also upload it on our server, and send you the link. Let me know when you are available to download...

@s-perron
Copy link
Collaborator

Could you try running:

dxc.exe mipmap_gen_envmap.hlsl -E maincomp -T cs_6_0 -spirv -fspv-target-env=vulkan1.1 -Wall -Wno-unused-const-variable -D imBINDLESS=0 -fspv-extension=SPV_KHR_non_semantic_info -fspv-debug=vulkan-with-source -fspv-extension=SPV_EXT_descriptor_indexing -Vd

I added -Vd, and then past the OpExtension instructions that are output? I'll try other ways to reproduce the problem.

@gjaegy
Copy link
Author

gjaegy commented Mar 26, 2025

please download the repro case here:

http://www.imagine3d.fr/_temp/dxc_bugs.rar

and let me know as soon as you've downloaded it !

@gjaegy
Copy link
Author

gjaegy commented Mar 26, 2025

I've removed the link, let me know once you are ready to download (or drop me an email [email protected])

@s-perron
Copy link
Collaborator

I won't download from the link. The IP issues are too vague for me to be able to do that. You'll have to find something you can make truly public, or try to narrow down the problem yourself. The first thing to try is my suggestion above.

@gjaegy
Copy link
Author

gjaegy commented Mar 26, 2025

I'm the founder and CEO of the company.

By not allowed, I meant I don't want the code to be available to everyone. There is nothing fancy in the code, but it's not an open source software either.

I'm happy for you to get your hands on it in order to fix the issue.

Just drop me an email and I'll send it to you

@s-perron
Copy link
Collaborator

I'll have to see what our legal team says about it.

@gjaegy
Copy link
Author

gjaegy commented Mar 27, 2025

Dear, why so much complexity...

@gjaegy
Copy link
Author

gjaegy commented Mar 27, 2025

output.txt

attached the output when compiling the shader with the additional -Vd parameter

@gjaegy
Copy link
Author

gjaegy commented Mar 27, 2025

That's the output without the -Vd parameter:

dxc.exe mipmap_gen_previousframecolor.hlsl -E maincomp -T cs_6_0 -spirv -fspv-target-env=vulkan1.1 -Wall -Wno-unused-const-variable -D imBINDLESS=0 -fspv-extension=SPV_KHR_non_semantic_info -fspv-debug=vulkan-with-source -fspv-extension=SPV_EXT_descriptor_indexing >> output_novd.txt
fatal error: generated SPIR-V is invalid: [VUID-StandaloneSpirv-OpTypeImage-06924] Cannot store to OpTypeImage, OpTypeSampler, OpTypeSampledImage, or OpTypeAccelerationStructureKHR objects
OpStore %927 %3239

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

@TheMostDiligent
Copy link

Hello,
I am getting the same issue starting with the Vulkan SDK 1.4.304.0. Before that SDK, the same shader was compiling successfully.
Here is the shader source code:

RayTracing.txt

It is a compute shader with inline ray tracing.
Here are the command line args: -spirv -fspv-reflect -Od -fspv-target-env=vulkan1.2 -Zpc
Here is the error log that I get:

fatal error: generated SPIR-V is invalid: [VUID-StandaloneSpirv-OpTypeImage-06924] Cannot store to OpTypeImage, OpTypeSampler, OpTypeSampledImage, or OpTypeAccelerationStructureKHR objects
  OpStore %140 %236

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

@s-perron
Copy link
Collaborator

I'll try to take a look next week. Possibly not the same issue as @gjaegy's. Hopefully it is.

s-perron added a commit to s-perron/SPIRV-Tools that referenced this issue Mar 31, 2025
The SPV_GOOGLE_user_type extension was not added to one of the allow
list. Adding it now.

Part of microsoft/DirectXShaderCompiler#7181.
@s-perron
Copy link
Collaborator

I have a fix for @TheMostDiligent's issue. The missing extension was inserted because of -fspv-reflect, so it will not likely fix @gjaegy's problem.

@s-perron
Copy link
Collaborator

The part of the code that I fixed had not changed, so does not show me why it regressed. I'll try to track down the change that caused the regression. That might point to something else.

@s-perron
Copy link
Collaborator

s-perron commented Mar 31, 2025

The "regression" was caused by KhronosGroup/SPIRV-Tools#5368. The code DXC was generating was always invalid. The difference is that the validator now recognizes that it is invalid.

As a workaround you can compile with -Vd. This turns off validation, and will generate the same code that was generated before. As long as the validation layers are turned off, you should see the same results as before when running a pipeline with the shader.

To fix the issue more or different optimizations are needed to properly legalize the code. Without seeing the code, I cannot determine what is needed.

@gjaegy Since this is an optimization problem, we could also try getting a reduced SPIR-V test case that will not give away any trade secrets. Here are the steps you can follow:

  1. Dump the SPIR-V before optimizations are run by adding -Vd -fcgl to the dxc command line. Call it t.spv.
  2. Write a small script that return 0 if and only if a spir-v binary has the same problem. On Linux this could be called b.sh:
spirv-opt $1 -o o.spv --legalize-hlsl -O --skip-validation && spirv-val --target-env vulkan1.2 o.spv 2>&1 | grep "VUID-StandaloneSpirv-OpTypeImage-06924"
  1. Check that you can reproduce the problem on the command line using spirv-opt:
./b.sh t.spv; echo $?
  1. use spirv-reduce to reduce the spir-v binary:
spirv-reduce --before-hlsl-legalization t.spv -o r.spv -- ./b.sh

Hopefully you can post the disassembly of r.spv publicly. spirv-reduce is part of SPIR-V Tools and is available in the Vulkan SDK.

@TheMostDiligent
Copy link

I have a fix for @TheMostDiligent's issue.
The "regression" was caused by KhronosGroup/SPIRV-Tools#5368. The code DXC was generating was always invalid.

So is the fix on DXC or SPIRV-Tools side? If the code DXC produces is valid, then the issue should be fixed on SPIRV-Tools side?
Or did you find a workaround on DXC side?

@s-perron
Copy link
Collaborator

@TheMostDiligent For your test case, the fix is an improvement to the optimizer: KhronosGroup/SPIRV-Tools#6075. After that, the validator will no longer complain.

s-perron added a commit to KhronosGroup/SPIRV-Tools that referenced this issue Mar 31, 2025
The SPV_GOOGLE_user_type extension was not added to one of the allow
list. Adding it now.

Part of microsoft/DirectXShaderCompiler#7181.
@gjaegy
Copy link
Author

gjaegy commented Mar 31, 2025

Again, I'm happy to share the HLSL, there is nothing fancy about it. Simply drop me an email and I'll send it to you.

Otherwise I'll try to follow the steps you've mentioned above.

@gjaegy
Copy link
Author

gjaegy commented Apr 2, 2025

Actually I have no linux system available in the office. And running the "spirv-opt" command leads to an error (error: line 0: Invalid SPIR-V magic number '5053203b').

Attached the source shader files. Rename the file to 7181.rar and extract the files.

The command line used is the following one:

dxc.exe mipmap_gen_previousframecolor.hlsl -E maincomp -T cs_6_0 -spirv -fspv-target-env=vulkan1.1 -Wall -Wno-unused-const-variable -D imBINDLESS=0 -fspv-extension=SPV_KHR_non_semantic_info -fspv-debug=vulkan-with-source -fspv-extension=SPV_EXT_descriptor_indexing

@s-perron
Copy link
Collaborator

s-perron commented Apr 2, 2025

Thanks for that. Here is a small reproducer: https://godbolt.org/z/shcsf4E8r. If the -fspv-debug=vulkan-with-source option is removed, then the problem goes away.

The issue seems in the spirv-opt pass copy-propagate-arrays. That pass will try to replace the image operand in the OpImageTexelPointer instruction another if on is a copy of the other. In this case is fails because the operand in the OpImageTexelPointer is also used in a debug instruction. The pass does not know what to do with that.

I should be able to update the pass to not consider debug instructions as bad uses.

@gjaegy
Copy link
Author

gjaegy commented Apr 2, 2025

Great news !
Do you think that could be related to issue #7182 ?

s-perron added a commit to s-perron/SPIRV-Tools that referenced this issue Apr 2, 2025
When checking if a variable is possibly stored to, debug instructions
fall into the default case, which assumes it could be a store. We add a
specific check for debug instruction, which are not stores.

See microsoft/DirectXShaderCompiler#7181
s-perron added a commit to s-perron/SPIRV-Tools that referenced this issue Apr 3, 2025
When checking if a variable is possibly stored to, debug instructions
fall into the default case, which assumes it could be a store. We add a
specific check for debug instruction, which are not stores.

See microsoft/DirectXShaderCompiler#7181
@s-perron s-perron moved this from New to In progress in HLSL Roadmap Apr 3, 2025
@s-perron s-perron moved this to Triaged in HLSL Triage Apr 3, 2025
@s-perron s-perron removed the needs-triage Awaiting triage label Apr 3, 2025
s-perron added a commit to KhronosGroup/SPIRV-Tools that referenced this issue Apr 3, 2025
…6078)

When checking if a variable is possibly stored to, debug instructions
fall into the default case, which assumes it could be a store. We add a
specific check for debug instruction, which are not stores.

See microsoft/DirectXShaderCompiler#7181
s-perron added a commit to s-perron/DirectXShaderCompiler that referenced this issue Apr 3, 2025
@github-project-automation github-project-automation bot moved this from In progress to Done in HLSL Roadmap Apr 3, 2025
@s-perron s-perron self-assigned this Apr 7, 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: Done
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants