Repository navigation
VK_EXT_ray_tracing_invocation_reorder: Fix swapped HLSL HitObject instance ID/index mapping - #2831
Conversation
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. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4ad394d to
2b0e4bc
Compare
|
Whoa, this should not have been insta-merged at all 😳 - I'm surprised I even have merge rights. @oddhack should I just revert this so that interesting parties can take a look? |
Bad Claude! |
|
Yes, please revert it. I'll take another look at the repo permissions. |
|
I attempted setting up branch protection rules on main so that only Admins and Maintainers should be able to push. If you are not able to revert the PR that would be good evidence that the rule is working :-) |
|
@oddhack and preferably branch protection rules require at least one review approval (with a maintainer override available)? Indeed I'm unable to push the revert to |
The HLSL mapping in the
VK_EXT_ray_tracing_invocation_reorderproposal pairs the instance getters by name, which swaps them:In HLSL,
InstanceID()/HitObject::GetInstanceID()return the application-specified 24-bit value, which SPIR-V callsInstanceCustomIndexKHR(gl_InstanceCustomIndexEXT).InstanceIndex()/HitObject::GetInstanceIndex()return the index of the instance in the TLAS, which SPIR-V calls theInstanceIdBuiltIn(gl_InstanceID). DXC already maps the non-SER intrinsics this way.GLSL_EXT_shader_invocation_reorderdocumentshitObjectGetInstanceIdEXT()as returning "the index of the instance", soOpHitObjectGetInstanceIdEXTcorresponds toGetInstanceIndex, notGetInstanceID.We hit this in practice: our SER wrapper, built on SPIR-V intrinsics until microsoft/DirectXShaderCompiler#8226 lands, followed this table and read the TLAS index on Vulkan where D3D12 returns the custom index. The table is also the obvious reference for the eventual DXC implementation, so it should be right before that lands.
The two corrected rows also link to the SPIR-V ops.
GetInstanceIDadditionally links toVkAccelerationStructureInstanceKHR::instanceCustomIndex, the field it reads back.KhronosGroup/SPIRV-Registry#459 clarifies the ambiguous
OpHitObjectGetInstanceIdEXTdescription in the SPIR-V extension.🤖 Generated with Claude Code