Skip to content

Implement the DispatchRaysIndex HLSL Function #99183

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 DispatchRaysIndex HLSL Function #99183

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 DispatchRaysIndex clang builtin,
  • Link DispatchRaysIndex clang builtin with hlsl_intrinsics.h
  • Add sema checks for DispatchRaysIndex to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for DispatchRaysIndex to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/DispatchRaysIndex.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/DispatchRaysIndex-errors.hlsl
  • Create the int_dx_DispatchRaysIndex intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_DispatchRaysIndex to 145 in DXIL.td
  • Create the DispatchRaysIndex.ll and DispatchRaysIndex_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_DispatchRaysIndex intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the DispatchRaysIndex lowering and map it to int_spv_DispatchRaysIndex in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/DispatchRaysIndex.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
145 DispatchRaysIndex 6.3 ('library', 'raygeneration', 'intersection', 'anyhit', 'closesthit', 'miss', 'callable')

SPIR-V

LaunchIdKHR

Short Description

LaunchIdKHR - Launch Id for ray shaders

Description

LaunchIdKHR
A variable decorated with the LaunchIdKHR decoration will specify
the index of the work item being processed. One work item is generated
for each of the width × height × depth items dispatched by
a vkCmdTraceRaysKHR command. All shader
invocations inherit the same value for variables decorated with
LaunchIdKHR .

Valid Usage


  • VUID-LaunchIdKHR-LaunchIdKHR-04266

    The LaunchIdKHR decoration must be used only within the
    RayGenerationKHR , IntersectionKHR , AnyHitKHR ,
    ClosestHitKHR , MissKHR , or CallableKHR Execution
    Model


  • VUID-LaunchIdKHR-LaunchIdKHR-04267

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


  • VUID-LaunchIdKHR-LaunchIdKHR-04268

    The variable decorated with LaunchIdKHR must be declared as a
    three-component vector of 32-bit integer values

Test Case(s)

Example 1

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

export uint3 fn() {
    return DispatchRaysIndex();
}

SPIRV Example(s):

Example 2

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

[shader("intersection")]
void fn() {
uint3 	ret = DispatchRaysIndex();
}

HLSL:

Gets the current location within the width, height, and depth obtained with the DispatchRaysDimensions system value intrinsic.

Syntax

uint3 DispatchRaysIndex();

Remarks

This function can be called from the following raytracing shader types.

See also

@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