Skip to content

Use uint64 AS descriptor heap stride#11494

Open
jkwak-work wants to merge 7 commits into
shader-slang:masterfrom
jkwak-work:issue-11231
Open

Use uint64 AS descriptor heap stride#11494
jkwak-work wants to merge 7 commits into
shader-slang:masterfrom
jkwak-work:issue-11231

Conversation

@jkwak-work
Copy link
Copy Markdown
Collaborator

@jkwak-work jkwak-work commented Jun 6, 2026

Fixes #11231

Summary of the problem from the end user perspective

DescriptorHandle<RaytracingAccelerationStructure> heap loads could use a runtime-array stride based on the opaque acceleration structure type while loading a 64-bit device address. Nonzero heap indices could therefore address the wrong heap entry unless users pinned -spirv-resource-heap-stride.

Minimal repro shader; if applicable

DescriptorHandle<RaytracingAccelerationStructure> accelerationStructure;
RaytracingAccelerationStructure scene =
    RaytracingAccelerationStructure(accelerationStructure);

Root cause

The descriptor heap base type for acceleration structures was OpTypeAccelerationStructureKHR, but the descriptor heap load materializes the value by loading uint64 and converting it with OpConvertUToAccelerationStructureKHR. That made the access-chain stride and load width disagree.

Solution in this PR

Use a uint64_t runtime-array element for acceleration-structure heap entries and give it a default ArrayStride 8, while still honoring an explicit -spirv-resource-heap-stride override. The regression tests now cover the unpinned default path for both RayQueryKHR and RayTracingKHR, plus explicit override precedence for acceleration-structure heap entries.

Notes to the reviewers; where to focus on

The main behavior change is in getDescriptorHeapBaseType and getAccelerationStructureDescriptorRuntimeArrayType: AS heap entries take the literal 8-byte default stride because ArrayStrideIdEXT is only valid for descriptor-typed arrays. Existing texture, sampler, texel-pointer, and buffer descriptor heap paths keep their prior stride behavior.

Related PRs in the past

@jkwak-work jkwak-work added pr: non-breaking PRs without breaking changes CoPilot labels Jun 6, 2026
@jkwak-work jkwak-work self-assigned this Jun 6, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 6, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e21ac0dd-e3ec-42d7-9baa-9b79f982fc99

📥 Commits

Reviewing files that changed from the base of the PR and between 1d53571 and e964d4b.

📒 Files selected for processing (4)
  • docs/command-line-slangc-reference.md
  • docs/user-guide/08-compiling.md
  • source/slang/slang-options.cpp
  • tests/spirv/descriptor-heap-acceleration-structure-raygen.slang

📝 Walkthrough

Walkthrough

Type RaytracingAccelerationStructure descriptor-heap entries as uint64 and emit an 8-byte ArrayStride for that heap case; update SPIR-V emission, tests, and documentation to reflect the stride exception while preserving prior stride derivation for other resource types.

Changes

RAS descriptor heap stride and uint64 element type

Layer / File(s) Summary
SPIR-V emission: acceleration-structure runtime-array type
source/slang/slang-emit-spirv.cpp
Add cached m_descriptorHeapAccelerationStructureRuntimeArrayType, add getAccelerationStructureDescriptorRuntimeArrayType(), assert generic runtime-array path isn't used for RAS, and emit OpTypeRuntimeArray with U64 element and ArrayStride = option if non-zero else 8. getDescriptorHeapBaseType routes RAS to the new helper and marks it non-buffer-resource.
Tests: adjust FileCheck and invocations for 8-byte RAS stride
tests/spirv/descriptor-heap-acceleration-structure-raygen.slang, tests/spirv/descriptor-heap-acceleration-structure.slang
Remove explicit -spirv-resource-heap-stride 32 from test invocations and update FileCheck expectations to capture OpTypeRuntimeArray element U64 and expect OpDecorate ... ArrayStride 8 for acceleration-structure descriptor heaps; OVERRIDE patterns referencing ArrayStride 32 remain in overrides where intended.
Documentation of RAS heap stride behavior
docs/command-line-slangc-reference.md, docs/user-guide/03-convenience-features.md, docs/user-guide/08-compiling.md, source/slang/slang-options.cpp
Document that the -spirv-resource-heap-stride default (0) uses OpConstantSizeOfEXT(ResourceType) for most resource types, and that RaytracingAccelerationStructure entries instead use a uint64 element type with an explicit 8-byte ArrayStride literal (unless the option is non-zero).

Suggested reviewers

  • bmillsNV
  • csyonghe
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Use uint64 AS descriptor heap stride' accurately reflects the main change: switching the descriptor heap element type for RaytracingAccelerationStructure to uint64 with a default 8-byte stride instead of using the opaque AccelerationStructureKHR type.
Description check ✅ Passed The description comprehensively explains the problem (stride/load-width coupling), root cause (type mismatch), solution (uint64 elements with 8-byte default), and testing coverage, all directly related to the changeset.
Linked Issues check ✅ Passed The PR fully addresses issue #11231 by implementing candidate fix #1: typing heap entries as uint64 to align OpUntypedAccessChainKHR stride with OpLoad width, eliminating the user-must-pin-stride requirement while honoring explicit overrides.
Out of Scope Changes check ✅ Passed All changes (code, documentation, and tests) are directly in scope: the core fix in slang-emit-spirv.cpp, supporting documentation updates, option help text clarification, and regression test adjustments for the unpinned default behavior.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@jkwak-work
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 6, 2026

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: ad8ec485-f247-4c35-8a9e-6c0f130a5b3c

📥 Commits

Reviewing files that changed from the base of the PR and between 5230a81 and 21ebd9b.

📒 Files selected for processing (7)
  • docs/command-line-slangc-reference.md
  • docs/user-guide/03-convenience-features.md
  • docs/user-guide/08-compiling.md
  • source/slang/slang-emit-spirv.cpp
  • source/slang/slang-options.cpp
  • tests/spirv/descriptor-heap-acceleration-structure-raygen.slang
  • tests/spirv/descriptor-heap-acceleration-structure.slang

Comment thread docs/command-line-slangc-reference.md Outdated
Comment thread tests/spirv/descriptor-heap-acceleration-structure.slang
@jkwak-work jkwak-work marked this pull request as ready for review June 6, 2026 03:34
@jkwak-work jkwak-work requested a review from a team as a code owner June 6, 2026 03:34
@jkwak-work
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 6, 2026

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

github-actions[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Collaborator Author

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

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

Looks good to me

Comment thread source/slang/slang-emit-spirv.cpp Outdated
@jkwak-work
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 6, 2026

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

github-actions[bot]

This comment was marked as outdated.

@jkwak-work
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 6, 2026

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Verdict: ✅ Clean — no significant issues found

The PR fixes a stride/load type mismatch in the SPIR-V DescriptorHandle<RaytracingAccelerationStructure> heap path: the runtime-array element switches from OpTypeAccelerationStructureKHR to uint64, the default ArrayStride becomes a literal 8 (matching the OpLoad %u64 materialization), and -spirv-resource-heap-stride continues to override. The new getAccelerationStructureDescriptorRuntimeArrayType() helper, the getDescriptorRuntimeArrayType guarding SLANG_ASSERT, the outIsBufferResource = false write on the AS early-return, and the per-pass test split into default-stride CHECK and override-stride OVERRIDE runs are all internally consistent.

Changes Overview

SPIR-V emitter — AS descriptor heap stride fix (source/slang/slang-emit-spirv.cpp)

  • New getAccelerationStructureDescriptorRuntimeArrayType() builds an OpTypeRuntimeArray of uint64 with literal ArrayStride 8 by default; honors -spirv-resource-heap-stride override (cached in new m_descriptorHeapAccelerationStructureRuntimeArrayType field).
  • getDescriptorHeapBaseType reroutes kIROp_RaytracingAccelerationStructureType to the new helper and writes *outIsBufferResource = false.
  • getDescriptorRuntimeArrayType adds SLANG_ASSERT that AS opcode never reaches the legacy path.

CLI option help text (source/slang/slang-options.cpp)

  • -spirv-resource-heap-stride description extended to document the AS-specific literal-8 default.

Documentation (docs/command-line-slangc-reference.md, docs/user-guide/03-convenience-features.md, docs/user-guide/08-compiling.md)

  • Default-stride wording updated; RaytracingAccelerationStructure note now states that the heap entry type is uint64_t and the default stride reflects the address width rather than the opaque AS type.

Tests (tests/spirv/descriptor-heap-acceleration-structure.slang, tests/spirv/descriptor-heap-acceleration-structure-raygen.slang)

  • Each file now runs twice: a default-stride CHECK run pinning OpTypeRuntimeArray %[[U64]] + ArrayStride 8, and an OVERRIDE run with -spirv-resource-heap-stride 32 pinning ArrayStride 32. RayQuery and RayTracingKHR capability paths are both exercised.

Copy link
Copy Markdown
Collaborator Author

@jkwak-work jkwak-work left a comment

Choose a reason for hiding this comment

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

Looks good to me

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

Labels

CoPilot pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[spirv] spvDescriptorHeapEXT: heap-stride / load-width coupling for AS heap entries — index ≥ 1 mis-indexed without -spirv-resource-heap-stride

1 participant