Skip to content

VK_EXT_ray_tracing_invocation_reorder: Fix swapped HLSL instance mapping - #2833

Merged
oddhack merged 1 commit into
mainfrom
inverted-docs
Oct 22, 2026
Merged

oddhack merged 1 commit into
mainfrom
inverted-docs

Conversation

@MarijnS95

Copy link
Copy Markdown
Contributor

Re-created #2831 to actually be reviewed, this time without accidental insta-merge.


The HLSL mapping paired HitObject::GetInstanceID with OpHitObjectGetInstanceIdEXT and HitObject::GetInstanceIndex with OpHitObjectGetInstanceCustomIndexEXT by name, which is backwards. HLSL's InstanceID() is the application specified 24-bit value (InstanceCustomIndexKHR, gl_InstanceCustomIndexEXT) while InstanceIndex() is the index of the instance in the TLAS (the InstanceId BuiltIn, gl_InstanceID), which is what OpHitObjectGetInstanceIdEXT returns per GLSL_EXT_shader_invocation_reorder.

The HLSL mapping paired HitObject::GetInstanceID with
OpHitObjectGetInstanceIdEXT and HitObject::GetInstanceIndex with
OpHitObjectGetInstanceCustomIndexEXT by name, which is backwards.
HLSL's InstanceID() is the application specified 24-bit value
(InstanceCustomIndexKHR, gl_InstanceCustomIndexEXT) while
InstanceIndex() is the index of the instance in the TLAS (the InstanceId
BuiltIn, gl_InstanceID), which is what OpHitObjectGetInstanceIdEXT
returns per GLSL_EXT_shader_invocation_reorder.
@dgkoch

dgkoch commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

I checked the new mapping against independent sources and it holds up:

  • DXR functional spec (InstanceIndex, InstanceID): InstanceIndex() is "the autogenerated index of the current instance in the top-level structure", and InstanceID() is "the user-provided InstanceID on the bottom-level acceleration structure instance".
  • Vulkan spec, InstanceId and InstanceCustomIndexKHR BuiltIns: InstanceId is the index of the instance that intersects the ray, and InstanceCustomIndexKHR is VkAccelerationStructureInstanceKHR::instanceCustomIndex (lower 24 bits).
  • GLSL_EXT_ray_tracing: gl_InstanceID maps to InstanceId, and gl_InstanceCustomIndexEXT maps to InstanceCustomIndexKHR.
  • GLSL_EXT_shader_invocation_reorder: hitObjectGetInstanceIdEXT returns "the index of the instance", and hitObjectGetInstanceCustomIndexEXT returns "the custom index".
  • DXC's SPIR-V backend already lowers InstanceIndex() to BuiltIn::InstanceId and InstanceID() to InstanceCustomIndexNV/KHR. The ray query intrinsics split the same way (CandidateInstanceIndex to ...InstanceIdKHR, CandidateInstanceID to ...InstanceCustomIndexKHR).

So GetInstanceIndex maps to OpHitObjectGetInstanceIdEXT and GetInstanceID maps to OpHitObjectGetInstanceCustomIndexEXT, as this PR now has it. The old text was swapped.

I also built the proposal with asciidoctor with the patch applied. There are no warnings, and both {spirvextensions} links and the refpage link render as anchors. LGTM.

▎ GenAI disclosure: Analysis assisted by Claude (claude-sonnet-5-5, Anthropic, commercial SaaS — Claude Code CLI).

@dgkoch dgkoch added this to the Signed-off to Merge milestone Oct 22, 2026
@dgkoch
dgkoch requested a review from oddhack October 22, 2026 15:11

@dgkoch dgkoch 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.

LGTM.

Signed off by the Ray TSG 10/22

@oddhack
oddhack merged commit 6984aa0 into main Oct 22, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants