microsoft / microsoft/DirectXShaderCompiler

[SPIR-V] Conversion from `CommittedRayT` to `OpRayQueryGetIntersectionTKHR` can introduce UB

Open
#7,860 2 comments 0 reactions 1 assignee View on GitHub

@s-perron is already working on this.

Since Oct 31, 2025.

bug spirv
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description
query.CommittedRayT() is defined to be initialized to RayDesc::TMax, however, DXC converts this call directly to OpRayQueryGetIntersectionTKHR with an intersection type of RayQueryCommittedIntersectionKHR about which the extension specification states

If Intersection is RayQueryCommittedIntersectionKHR, behavior is undefined if there is no current committed intersection

In a case such as

RaytracingAccelerationStructure g_AS;
[numthreads(1, 1, 1)]
void CSMain()
{
    RayQuery<RAY_FLAG_NONE> query;
    RayDesc desc = (RayDesc)0;
    query.TraceRayInline(g_AS, 0, 0, desc);
    float unused = query.CommittedRayT();
}

this will always be undefined behavior in spirv, when what is returned should be TMax (zero in this case).

This could be a problem in the spirv specification, because the Vulkan spec in one case assumes that this is defined too. Alternatively, I could have missed something somewhere that makes this defined (but I can't find any in the Vulkan environment for spirv or in the extension spec itself).

Steps to Reproduce
See https://godbolt.org/z/xGxb8GPf8

Actual Behavior

               OpRayQueryInitializeKHR %18 %19 %uint_0 %uint_0 %15 %16 %15 %16
         %20 = OpRayQueryGetIntersectionTKHR %float %18 %uint_1

is outputted, which according to the spirv specification has undefined behavior if hit.

Environment

  • DXC version libdxcompiler.so: 1.9(dev;1-9efbb6c3); libdxil.so: 1.9 (version from godbolt)
  • Host Operating System N/A

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.