Skip to content

Implement the GeometryIndex HLSL Function #99216

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
12 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 0 comments
Open
12 tasks
Tracked by #99235

Implement the GeometryIndex HLSL Function #99216

farzonl opened this issue Jul 16, 2024 · 0 comments
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

  • Implement GeometryIndex clang builtin,
  • Link GeometryIndex clang builtin with hlsl_intrinsics.h
  • Add sema checks for GeometryIndex to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for GeometryIndex to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/GeometryIndex.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/GeometryIndex-errors.hlsl
  • Create the int_dx_GeometryIndex intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_GeometryIndex to 213 in DXIL.td
  • Create the GeometryIndex.ll and GeometryIndex_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_GeometryIndex intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the GeometryIndex lowering and map it to int_spv_GeometryIndex in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/GeometryIndex.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
213 GeometryIndex 6.5 ('library', 'intersection', 'anyhit', 'closesthit')

SPIR-V

RayGeometryIndexKHR

Short Description

RayGeometryIndexKHR - Geometry index in a ray shader

Description

RayGeometryIndexKHR
A variable decorated with the RayGeometryIndexKHR decoration will
contain the geometry index for the acceleration
structure geometry currently being shaded.

Valid Usage


  • VUID-RayGeometryIndexKHR-RayGeometryIndexKHR-04345

    The RayGeometryIndexKHR decoration must be used only within
    the IntersectionKHR , AnyHitKHR , or ClosestHitKHR
    Execution Model


  • VUID-RayGeometryIndexKHR-RayGeometryIndexKHR-04346

    The variable decorated with RayGeometryIndexKHR must be
    declared using the Input Storage Class


  • VUID-RayGeometryIndexKHR-RayGeometryIndexKHR-04347

    The variable decorated with RayGeometryIndexKHR must be
    declared as a scalar 32-bit integer value

Test Case(s)

Example 1

//dxc GeometryIndex_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export uint fn() {
    return GeometryIndex();
}

SPIRV Example(s):

Example 2

//dxc GeometryIndex_spirv_test.hlsl -T lib_6_8 -E fn -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0

[shader("intersection")]
void fn() {
uint 	ret = GeometryIndex();
}

HLSL:

The autogenerated index of the current geometry in the bottom-level acceleration structure.

Syntax

uint GeometryIndex();

Remarks

This method is only available on Tier 1.1 implementations.

The MultiplierForGeometryContributionToHitGroupIndex parameter to TraceRay() can be set to 0 to stop the geometry index from contributing to shader table indexing if the shader just wants to rely on GeometryIndex() to distinguish geometries.

@farzonl farzonl added backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues. labels Jul 16, 2024
@damyanp damyanp moved this to Ready in HLSL Support Oct 30, 2024
@damyanp damyanp moved this from Ready to Planning in HLSL Support Oct 30, 2024
@damyanp damyanp moved this from Planning to Designing in HLSL Support Nov 26, 2024
@damyanp damyanp removed the status in HLSL Support Apr 25, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: No status
Development

No branches or pull requests

1 participant