Skip to content
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

Implement the RayTCurrent HLSL Function #99192

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

Implement the RayTCurrent HLSL Function #99192

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

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
154 RayTCurrent 6.3 ('library', 'intersection', 'anyhit', 'closesthit', 'miss')

SPIR-V

RayTmaxKHR

Short Description

RayTmaxKHR - Maximum T value of a ray

Description

RayTmaxKHR
A variable decorated with the RayTmaxKHR decoration will contain the
parametric t max value of the ray
being processed. The value is independent of the space in which the ray
origin and direction exist. The value is initialized to the parameter
passed into the pipeline trace ray instruction.

The t max value changes throughout
the lifetime of the ray that produced the intersection. In the closest
hit shader, the value reflects the closest distance to the intersected
primitive. In the any-hit shader, it reflects the distance to the
primitive currently being intersected. In the intersection shader, it
reflects the distance to the closest primitive intersected so far or the
initial value. The value can change in the intersection shader after
calling OpReportIntersectionKHR if the corresponding any-hit shader
does not ignore the intersection. In a miss shader, the value is
identical to the parameter passed into the pipeline trace ray instruction.

Valid Usage


  • VUID-RayTmaxKHR-RayTmaxKHR-04348

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


  • VUID-RayTmaxKHR-RayTmaxKHR-04349

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


  • VUID-RayTmaxKHR-RayTmaxKHR-04350

    The variable decorated with RayTmaxKHR must be declared as a
    scalar 32-bit floating-point value

Test Case(s)

Example 1

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

export float fn() {
    return RayTCurrent();
}

SPIRV Example(s):

Example 2

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

[shader("intersection")]
void fn() {
float 	ret = RayTCurrent();
}

HLSL:

A float representing the current parametric ending point for the ray.

Syntax

float RayTCurrent();

Remarks

RayTCurrent defines the current ending point of the ray according to the following formula: Origin + (Direction * RayTCurrent). Origin and Direction may be in either world or object space, which results in either a world or an object space ending point.

RayTCurrent is initialized in the call TraceRay call with the RayDesc::TMax value and then is updated during the trace query as intersections are reported (in the any hit), and accepted.

In the intersection shader, it represents the distance to the closest intersection found so far. It will be updated after () to the THit value provided if the hit was accepted.

In the any hit shader, it represents the distance to the current intersection being reported.

In the closest hit shader, it represents the distance to the closest intersection accepted.

In the miss shader, it is equal to TMax passed to the TraceRay call.

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
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: Designing
Development

No branches or pull requests

1 participant