Skip to content

[SPIR-V]Raytracing shader no longer compiles with latest releast compiler #7164

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
Clothoid1 opened this issue Feb 27, 2025 · 8 comments
Closed
Assignees
Labels
bug Bug, regression, crash spirv Work related to SPIR-V
Milestone

Comments

@Clothoid1
Copy link

Description
When installing the latest DXC compiler release for February 2025, we noticed that our raytracing shaders no longer compile. Below you find a simpl,e reprocuder for this issue.
The rootcause seems to be that in a raytracing shader it is no longer possible to pass a RaytracingAccelerationStructure to a method and then use this structure in a TraceRay() call.
Interestingly passing such a structure is not a problem at all when using it in a compute shader, it only ssems to be problematic in a raytracing shader.

Steps to Reproduce

RaytracingAccelerationStructure myAccelerationStructure_BlockStructure : register(t0);

// payload
struct Payload
{
    float t;
};

static void test(const RaytracingAccelerationStructure aAccelerationStructure_in)
{
    RayDesc aRayDesc;
    Payload payload;
    TraceRay(aAccelerationStructure_in, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, aRayDesc, payload);
}

[shader("raygeneration")]
void main()
{
    // this works fine
    RayDesc aRayDesc;
    Payload payload;
    TraceRay(myAccelerationStructure_BlockStructure, RAY_FLAG_FORCE_OPAQUE, 0xff, 0, 0, 0, aRayDesc, payload);

    // but this does no longer compile
    test(myAccelerationStructure_BlockStructure);
}

Actual Behavior
when compiling the reproducer with
dxc.exe -HV 2021 -O0 -Zi -spirv -T lib_6_4 -fvk-use-scalar-layout -enable-16bit-types -fspv-target-env=vulkan1.2
the compiler reports an error message that the generated spir-v code is invalid and asks for a reproducer.

Environment

  • DXC version: DX Compiler release for February 2025
  • Host Operating System: Windows 10
@Clothoid1 Clothoid1 added bug Bug, regression, crash needs-triage Awaiting triage spirv Work related to SPIR-V labels Feb 27, 2025
@Clothoid1
Copy link
Author

Here the reported error message:

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

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

@s-perron s-perron added this to the Next+1 Release milestone Feb 28, 2025
@s-perron s-perron self-assigned this Feb 28, 2025
@s-perron s-perron removed the needs-triage Awaiting triage label Feb 28, 2025
@s-perron
Copy link
Collaborator

@Clothoid1 I am unable to reproduce the problem. The latest works: https://godbolt.org/z/5djK138dM. Compiler explorer does not have v1.8.2502 yet, but I built it myself on Linux. I cannot reproduce the problem. I'll try reproducing on Windows.

@s-perron
Copy link
Collaborator

I can reproduce the issue if I use the prebuilt dxc.exe from the release page.

@s-perron
Copy link
Collaborator

@pow2clk Can you help out with this? If I

  1. clone the dxc source from GitHub,
  2. checkout the v1.8.2502 tag,
  3. update the submodules,
  4. and build it,

I am not able to reproduce the problem.

However, if I download the prebuilt binaries from https://github.com/microsoft/DirectXShaderCompiler/releases/tag/v1.8.2502, I can.

Looking at the code produced by the two, it seems to me that some spirv-opt optimizations are not running. I'm guessing this is because an older version of spirv-tools was used to build the prebuilt one. That version may not know about some extensions that DXC started using.

How can we check which commit was used for the prebuilt version?

@s-perron s-perron moved this to For MSFT in HLSL Triage Feb 28, 2025
@s-perron s-perron removed their assignment Feb 28, 2025
@damyanp damyanp moved this to Active in HLSL Support Apr 21, 2025
@bob80905
Copy link
Collaborator

@pow2clk Can you help out with this? If I

  1. clone the dxc source from GitHub,
  2. checkout the v1.8.2502 tag,
  3. update the submodules,
  4. and build it,

I am not able to reproduce the problem.

However, if I download the prebuilt binaries from https://github.com/microsoft/DirectXShaderCompiler/releases/tag/v1.8.2502, I can.

Looking at the code produced by the two, it seems to me that some spirv-opt optimizations are not running. I'm guessing this is because an older version of spirv-tools was used to build the prebuilt one. That version may not know about some extensions that DXC started using.

How can we check which commit was used for the prebuilt version?

I was able to repro on a Windows machine by running the below:

  1. clone the dxc source from github
  2. checkout release-1.8.2502
  3. git pull
  4. update the submodules from DXC\external\
  5. hctbuild -spirv, and run the test

The release branch, at this point, has the SPIRV-Tools submodule checked out on 4d2f0b40bfe290dea6c6904dafdf7fd8328ba346.
I was able to check this by cd'ing into SPIRV-Tools and running git log to see the latest commit.
I was able to reproduce the error without running from the github release exe.
I checked out the source, on the release branch, pulled, ran git submodule update --init,
built with hctbuild -spirv, and ran into the same error.

@s-perron , would you be able to double check the commit that the SPIRV-Tools submodule is "HEAD DETACHED" on, and describe how exactly you checked out the v1.8.2502 tag?
The SPIRV-Tools submodule was checked out on the above hash on release, so if you have the submodule checked out on that hash and are not reproducing that is strange.

@s-perron
Copy link
Collaborator

I must have had something that case stopping the submodule from getting updated properly last time. I can reproduce the problem. This is a duplicate of #7063. The solution would be to update SPIRV-Tools in the release branch.

A work around is to add -Vd to the command line.

The cause of the problem is the validator is now checking for stores of these opaque types. The SPIR-V generated with previous release was also invalid.

s-perron added a commit to s-perron/DirectXShaderCompiler that referenced this issue Apr 22, 2025
@s-perron
Copy link
Collaborator

I opened a draft pr with a minimal fix. I update spirv-tools to just the commits needed to fix this issue. Note that this will not fix all of the issues related to this new validation check. See #7181.

The lit tests will fail because new validation check were added. This could lead to other issues like this.

I think we should close this issue for these reasons:

  1. There is a workaround. Use -Vd.
  2. It is not a regression in the compiler. We were generating invalid code with previous releases. If you were to use the spir-v generated by DXC with the latest validation layers enabled, you will see the same error. This behaviour gives you an advanced warning.
  3. This issues cannot be easily fixed in isolation because DXC uses SPIRV-Tools as a submodule and there is no SPIRV-Tools branch where we can cherry pick the fix. It will have to include other commit that will have larger sideeffects.

If you need a release of DXC for SPIR-V, you can also try to Vulkan SDK. It is released more often, and the latest one will include a fix for this issue.

@damyanp @bob80905 Thoughts?

@damyanp damyanp assigned s-perron and unassigned bob80905 Apr 24, 2025
@damyanp
Copy link
Member

damyanp commented Apr 25, 2025

Agree with @s-perron.

@damyanp damyanp closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2025
@github-project-automation github-project-automation bot moved this from New to Done in HLSL Roadmap Apr 25, 2025
@github-project-automation github-project-automation bot moved this from Active to Closed in HLSL Support Apr 25, 2025
@github-project-automation github-project-automation bot moved this from For MSFT to Triaged in HLSL Triage Apr 25, 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

No branches or pull requests

4 participants