Skip to content

[SPIR-V] Add descriptor heap RaytracingAccelerationStructure support - #8518

Merged
Gregory Roth (pow2clk) merged 13 commits into
microsoft:mainfrom
jzakharovnv:pr2-raytracing-accel-struct
Nov 3, 2026
Merged

Gregory Roth (pow2clk) merged 13 commits into
microsoft:mainfrom
jzakharovnv:pr2-raytracing-accel-struct

Conversation

@jzakharovnv

Copy link
Copy Markdown
Collaborator

Building off of #8517, this PR extends the SPV_EXT_descriptor_heap native heap lowering to cover RaytracingAccelerationStructure resources loaded from ResourceDescriptorHeap. It is part 2/4 in a series.

Acceleration structure descriptors are accessed via OpUntypedAccessChainKHR into a runtime array of OpTypeAccelerationStructureKHR, consistent with the image and sampler paths added in the previous commit.

Assisted by an AI agent

Diego Novillo (@dnovillo)

@github-actions

github-actions Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

✅ With the latest revision this PR passed the C/C++ code formatter.

@jzakharovnv
Jonathan Zakharov (jzakharovnv) force-pushed the pr2-raytracing-accel-struct branch 3 times, most recently from d899b05 to b12b9ea Compare June 4, 2026 22:59
@jzakharovnv

Copy link
Copy Markdown
Collaborator Author

@microsoft-github-policy-service agree company="NVIDIA"

Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Resolved
@github-project-automation github-project-automation Bot moved this from New to In progress in HLSL Roadmap Jul 17, 2026
@dnovillo Diego Novillo (dnovillo) added the spirv Work related to SPIR-V label Jul 17, 2026
@jzakharovnv
Jonathan Zakharov (jzakharovnv) force-pushed the pr2-raytracing-accel-struct branch 2 times, most recently from 23aff82 to 02f3581 Compare July 23, 2026 19:39

@dnovillo Diego Novillo (dnovillo) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a question left on detecting RT usage of the heap.

Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Extends native SPIR-V descriptor-heap lowering to acceleration structures and broader resource operations.

Changes:

  • Adds descriptor-size-based heap strides, including acceleration structures.
  • Adds native buffer, image, sampler, atomic, and alias lowering.
  • Expands SPIR-V tests and documentation.

Reviewed changes

Copilot reviewed 51 out of 51 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
tools/clang/unittests/SPIRV/SpirvContextTest.cpp Extends runtime-array uniqueness tests.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.typed-formats.hlsl Tests typed image formats.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.texturecube.hlsl Tests cube textures and samplers.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.texture.hlsl Tests texel buffers.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.texture-sampler-assignment.hlsl Tests resource reassignment.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.texture-ms.hlsl Tests multisampled textures.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.texture-dims.hlsl Tests sampled-texture dimensions.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.structured-buffer-atomic.hlsl Tests structured-buffer atomics.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.static-global.hlsl Tests static global resources.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.sampler-comparison.hlsl Tests comparison samplers.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.sample-grad-bias.hlsl Tests gradient and bias sampling.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.rwtexture-dims.hlsl Tests storage-texture dimensions.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.rwtexture-atomics.hlsl Tests untyped image atomics.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.rwbyteaddressbuffer.hlsl Tests writable byte buffers.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.nonuniform.hlsl Tests nonuniform-index handling.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.mixed-bound.hlsl Tests bound and heap resources together.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.load-offset.hlsl Tests texture-load offsets.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.groupshared.hlsl Tests groupshared interoperability.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.gather.hlsl Tests texture gather operations.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.function-params.hlsl Tests resource function parameters.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.discarded.error.hlsl Tests discarded-access diagnostics.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.counter-ops.error.hlsl Tests unsupported counter diagnostics.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.constant-texture-buffer.hlsl Tests constant and texture buffers.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.constant-buffer-assignment.hlsl Tests constant-buffer reassignment.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.buffer.hlsl Tests native buffer lowering.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.array-stride.hlsl Tests shared heap strides.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.array-stride.accelstruct.hlsl Tests acceleration-structure stride inclusion.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.append-consume.error.hlsl Tests append/consume diagnostics.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.acceleration-structure.stride.error.hlsl Tests missing acceleration stride diagnostics.
tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.acceleration-structure.hlsl Tests acceleration-structure heap loads.
tools/clang/test/CodeGenSPIRV/resource-heap-ext-texture.hlsl Removes the superseded aggregate test.
tools/clang/lib/SPIRV/SpirvType.cpp Includes stride IDs in type equality.
tools/clang/lib/SPIRV/SpirvInstruction.cpp Implements new SPIR-V instructions.
tools/clang/lib/SPIRV/SpirvEmitter.h Declares heap-lowering and alias state.
tools/clang/lib/SPIRV/SpirvEmitter.cpp Implements native heap lowering and acceleration support.
tools/clang/lib/SPIRV/SpirvContext.cpp Canonicalizes buffer and runtime-array types.
tools/clang/lib/SPIRV/SpirvBuilder.cpp Builds descriptor-size constants and strides.
tools/clang/lib/SPIRV/LowerTypeVisitor.cpp Lowers untyped image pointers.
tools/clang/lib/SPIRV/EmitVisitor.h Declares new emission handlers.
tools/clang/lib/SPIRV/EmitVisitor.cpp Emits new instructions and decorations.
tools/clang/lib/SPIRV/DeclResultIdMapper.h Declares function-variable aliases.
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp Registers function-variable aliases.
tools/clang/lib/SPIRV/CapabilityVisitor.cpp Enforces Vulkan 1.3 for native heaps.
tools/clang/lib/SPIRV/AstTypeProbe.cpp Recognizes acceleration-structure types.
tools/clang/include/clang/SPIRV/SpirvVisitor.h Adds visitor methods.
tools/clang/include/clang/SPIRV/SpirvType.h Stores runtime-array stride IDs.
tools/clang/include/clang/SPIRV/SpirvInstruction.h Defines new instruction classes.
tools/clang/include/clang/SPIRV/SpirvContext.h Extends type-context APIs.
tools/clang/include/clang/SPIRV/SpirvBuilder.h Exposes descriptor-stride builders.
tools/clang/include/clang/SPIRV/AstTypeProbe.h Declares acceleration-type probing.
docs/SPIR-V.rst Documents native descriptor heaps.
Comments suppressed due to low confidence (1)

tools/clang/lib/SPIRV/SpirvEmitter.cpp:7072

  • Only casts are stripped here, so a syntactically valid parenthesized heap base such as (ResourceDescriptorHeap)[i] is diagnosed as unsupported even though it still refers directly to the builtin variable. Use IgnoreParenCasts() consistently when resolving the base declaration.
      const auto *declRefExpr = dyn_cast<DeclRefExpr>(baseExpr->IgnoreCasts());
      const auto *decl =
          declRefExpr ? dyn_cast<VarDecl>(declRefExpr->getDecl()) : nullptr;
      if (!decl) {
        emitError("unsupported ResourceDescriptorHeap/SamplerDescriptorHeap "
                  "expression",
                  baseExpr->getExprLoc());
        return nullptr;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Resolved
Comment thread docs/SPIR-V.rst Resolved
Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Resolved
Comment thread docs/SPIR-V.rst Resolved
Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Resolved
Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Resolved
@damyanp

Copy link
Copy Markdown
Member

[Auto-generated note from Damyan Pepper (@damyanp)]

This looks like a user-visible bug fix/feature change. Please add (or point to) the corresponding entry in docs/ReleaseNotes.md.

If release-note coverage is planned in a related PR (including one that hasn’t been submitted yet), please mention that plan/link so we can avoid duplicate notes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 52 out of 52 changed files in this pull request and generated 1 comment.

Suppressed comments (3)

tools/clang/lib/SPIRV/SpirvEmitter.cpp:5315

  • A heap-to-heap reassignment of RaytracingAccelerationStructure also reaches this branch because mixingDetected includes (isASType && wasHeap) regardless of srcIsHeap. That assignment does not mix bound and heap resources, so this diagnostic is misleading; report the unsupported AS reassignment separately.
    emitError("mixing bound and descriptor heap resources in the same variable "
              "is not supported with SPV_EXT_descriptor_heap",
              loc);

tools/clang/test/CodeGenSPIRV/sm6_6.descriptorheap.ext.array-stride.hlsl:62

  • Use the possessive “its” rather than “it's” (“it is”).
// The sampler array just uses the sampler size as it's stride.

docs/SPIR-V.rst:2089

  • This is a significant user-visible compiler feature, but docs/ReleaseNotes.md has no native descriptor-heap entry. Please add release-note coverage, or point to the shared release note planned for this four-PR series.
When ``-fspv-use-descriptor-heap`` is specified, DXC lowers
``ResourceDescriptorHeap`` and ``SamplerDescriptorHeap`` through
``SPV_EXT_descriptor_heap`` instead of the default emulated heap path. This
also requires ``SPV_KHR_untyped_pointers`` and ``-fspv-target-env=vulkan1.3``

Comment thread tools/clang/lib/SPIRV/SpirvEmitter.cpp Resolved
@dnovillo

Copy link
Copy Markdown
Collaborator

Added an analysis on this series: #8517 (comment)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Writable function parameters can bypass alias reassignment diagnostics and silently leave subsequent accesses using the original descriptor.

6 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Reject writable arguments referencing heap-initialized aliases

tools/​clang/​lib/​SPIRV/​SpirvEmitter.cpp:2091

Passing a heap-initialized acceleration structure to an out or inout parameter bypasses the reassignment diagnostic. processCall creates a temporary but does not copy resource parameters back, so later uses of the alias still read the original heap handle after the helper assigns a different resource. Reject writable arguments that refer to these aliases until their updated values can be represented correctly.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 28, 2026 03:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI balanced review requested due to automatic review settings October 29, 2026 22:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Heap stride varies by shader stage, so separately compiled shaders sharing a heap can read different descriptors at the same index.

1 open issue
3 resolved since last review

Review effort: Balanced

@pow2clk Gregory Roth (pow2clk) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why copilot is not acknowledging the change to sm6_6.descriptorheap.ext.array-stride.accelstruct-ext.hlsl, but it all looks good to me!

@pow2clk

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@pow2clk
Gregory Roth (pow2clk) enabled auto-merge (squash) October 29, 2026 22:57
@jzakharovnv

Copy link
Copy Markdown
Collaborator Author

Looks like one of the tests I added is failing on Azure. Investigating

Copilot AI balanced review requested due to automatic review settings October 30, 2026 18:34
auto-merge was automatically disabled October 30, 2026 18:34

Head branch was pushed to by a user without write access

@jzakharovnv

Copy link
Copy Markdown
Collaborator Author

Seems the issue was that a test was hitting an unexpected assert in debug builds, should be fixed now

@jzakharovnv

Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 8518 in repo microsoft/DirectXShaderCompiler

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Heap stride varies by shader stage and extension settings, potentially causing shaders sharing a heap to read different descriptors for the same index.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@jzakharovnv

Copy link
Copy Markdown
Collaborator Author

🔵 Needs a closer look

Heap stride varies by shader stage and extension settings, potentially causing shaders sharing a heap to read different descriptors for the same index.

No open issues 🎉

Thank you Copilot lol

@pow2clk

Copy link
Copy Markdown
Collaborator

/azp run

1 similar comment
@pow2clk

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Heap stride varies by shader stage and extension list, so shaders sharing a heap can address different descriptors at the same index.

No open issues 🎉

Review effort: Balanced

@pow2clk

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spirv Work related to SPIR-V

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants