Skip to content

Implement the HitKind HLSL Function #99195

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 16, 2024 · 0 comments
Open
12 tasks
Tracked by #99235

Implement the HitKind HLSL Function #99195

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

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
143 HitKind 6.3 ('library', 'intersection', 'anyhit', 'closesthit')

SPIR-V

HitKindKHR

Short Description

HitKindKHR - Kind of hit that triggered an any-hit or closest hit ray
shader

Description

HitKindKHR
A variable decorated with the HitKindKHR decoration will describe
the intersection that triggered the execution of the current shader. The
values are determined by the intersection shader. For user-defined
intersection shaders this is the value that was passed to the “Hit Kind”
operand of OpReportIntersectionKHR . For triangle intersection
candidates, this will be one of HitKindFrontFacingTriangleKHR or
HitKindBackFacingTriangleKHR .

Valid Usage


  • VUID-HitKindKHR-HitKindKHR-04242

    The HitKindKHR decoration must be used only within the
    AnyHitKHR or ClosestHitKHR Execution Model


  • VUID-HitKindKHR-HitKindKHR-04243

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


  • VUID-HitKindKHR-HitKindKHR-04244

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

Test Case(s)

Example 1

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

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

SPIRV Example(s):

Example 2

//dxc HitKind_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 = HitKind();
}

HLSL:

Returns the value passed as the HitKind parameter to ReportHit.

Syntax

uint HitKind();

Remarks

If the intersection was reported by fixed-function triangle intersection, HitKind will be one of HIT_KIND_TRIANGLE_FRONT_FACE (254) or HIT_KIND_TRIANGLE_BACK_FACE (255).

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

See also

Direct3D 12 Raytracing HLSL Reference

@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
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: No status
Development

No branches or pull requests

1 participant