Skip to content

Implement the InstanceID HLSL Function #97624

Open
@farzonl

Description

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

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
141 InstanceID 6.3 ('library', 'intersection', 'anyhit', 'closesthit')

SPIR-V

InstanceCustomIndexKHR

Short Description

InstanceCustomIndexKHR - Custom index associated with an intersected
instance

Description

InstanceCustomIndexKHR
A variable decorated with the InstanceCustomIndexKHR decoration will
contain the application-defined value of the instance that intersects
the current ray. This variable contains the value that was specified in
VkAccelerationStructureInstanceKHR
:: instanceCustomIndex for the current acceleration structure
instance in the lower 24 bits and the upper 8 bits will be zero.

Valid Usage



  • VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04251

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



  • VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04252

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



  • VUID-InstanceCustomIndexKHR-InstanceCustomIndexKHR-04253

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

Test Case(s)

Example 1

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

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

SPIRV Example(s):

Example 2

//dxc InstanceID_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 = InstanceID();
}

HLSL:

The user-provided identifier for the instance on the bottom-level acceleration structure instance within the top-level structure.

Syntax

uint InstanceID();

Remarks

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

See also

Direct3D 12 Raytracing HLSL Reference

Activity

added
metabugIssue to collect references to a group of similar or related issues.
on Jul 3, 2024
farzonl

farzonl commented on Jul 3, 2024

@farzonl
MemberAuthor

@EugeneZelenko These bugs were created via automation. There are going to be about 160+ of these coming in. This first run was just a test. Would you like me to add the metabug label to all the issues created by the bot?

EugeneZelenko

EugeneZelenko commented on Jul 3, 2024

@EugeneZelenko
Contributor

@farzonl: metabug label should be used for issues that are used for tracking multiple issues, so bot could apply the label to such issues.

farzonl

farzonl commented on Jul 12, 2024

@farzonl
MemberAuthor

@EugeneZelenko This is the list of bugs we are going to be adding to llvm-project next week: please let me know if you see something glaring that would be painful for you: farzonl/test_repo#157

EugeneZelenko

EugeneZelenko commented on Jul 12, 2024

@EugeneZelenko
Contributor

@farzonl: This is good example of metabug :-) But I did not look on each issue. Some of them may be of metabug kind.

moved this to Ready in HLSL Supporton Oct 30, 2024
moved this from Ready to Planning in HLSL Supporton Oct 30, 2024
moved this from Planning to Ready in HLSL Supporton Nov 5, 2024
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

    Ready

    Milestone

    No milestone

    Development

    No branches or pull requests

      Participants

      @farzonl@EugeneZelenko

      Issue actions

        Implement the `InstanceID` HLSL Function · Issue #97624 · llvm/llvm-project