Skip to content

Implement the InstanceID HLSL Function #97624

New issue

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

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

Already on GitHub? Sign in to your account

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

Implement the InstanceID HLSL Function #97624

farzonl opened this issue Jul 3, 2024 · 4 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 3, 2024

  • 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

@EugeneZelenko EugeneZelenko added the metabug Issue to collect references to a group of similar or related issues. label Jul 3, 2024
@farzonl
Copy link
Member Author

farzonl commented Jul 3, 2024

@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
Copy link
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
Copy link
Member Author

farzonl commented Jul 12, 2024

@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
Copy link
Contributor

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

@farzonl farzonl mentioned this issue Jul 16, 2024
Closed
@farzonl farzonl added bot:HLSL and removed HLSL_Bot 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
@davidcook-msft davidcook-msft moved this from Planning to Ready in HLSL Support Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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: Ready
Development

No branches or pull requests

2 participants