Skip to content

Implement the InstanceIndex HLSL Function #99194

Open
Listed in
@farzonl

Description

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

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
142 InstanceIndex 6.3 ('library', 'intersection', 'anyhit', 'closesthit')

SPIR-V

InstanceId

Short Description

InstanceId - Id associated with an intersected instance

Description

InstanceId
Decorating a variable in an intersection, any-hit, or closest hit shader
with the InstanceId decoration will make that variable contain the
index of the instance that intersects the current ray.

Valid Usage


  • VUID-InstanceId-InstanceId-04254

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


  • VUID-InstanceId-InstanceId-04255

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


  • VUID-InstanceId-InstanceId-04256

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

Test Case(s)

Example 1

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

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

SPIRV Example(s):

Example 2

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


uint fn( ) : SV_Target {

	return InstanceIndex();
}

HLSL:

The autogenerated index of the current instance in the top-level raytracing acceleration structure.

Syntax

uint InstanceIndex();

Remarks

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

See also

Direct3D 12 Raytracing HLSL Reference

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @farzonl

        Issue actions

          Implement the `InstanceIndex` HLSL Function · Issue #99194 · llvm/llvm-project