<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99191>99191</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `RayTMin` HLSL Function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
metabug,
backend:DirectX,
HLSL,
backend:SPIR-V,
bot:HLSL
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
farzonl
</td>
</tr>
</table>
<pre>
- [ ] Implement `RayTMin` clang builtin,
- [ ] Link `RayTMin` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `RayTMin` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `RayTMin` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/RayTMin.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/RayTMin-errors.hlsl`
- [ ] Create the `int_dx_RayTMin` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_RayTMin` to `153` in `DXIL.td`
- [ ] Create the `RayTMin.ll` and `RayTMin_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_RayTMin` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `RayTMin` lowering and map it to `int_spv_RayTMin` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/RayTMin.ll`
## DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 153 | RayTMin | 6.3 | ('library', 'intersection', 'anyhit', 'closesthit', 'miss') |
## SPIR-V
<div id="header">
# [RayTminKHR](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/RayTminKHR.html)
## Short Description
<div class="sectionbody">
RayTminKHR - Minimum T value of a ray
</div>
</div>
<div id="content" class="loadable">
<div class="sect1">
## <a href="#_description" class="anchor"></a> Description
<div class="sectionbody">
<div class="dlist">
` RayTminKHR `
A variable decorated with the ` RayTminKHR ` decoration will contain the
parametric <span class="eq"> t <sub>min</sub> </span> value of the ray
being processed. The value is independent of the space in which the ray
origin and direction exist. The value is the parameter passed into the
<a
href="https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#glossary-pipeline-trace-ray"
rel="noopener" target="_blank">pipeline trace ray</a> instruction.
<div class="paragraph">
The <span class="eq"> t <sub>min</sub> </span> value remains constant
for the duration of the ray query.
</div>
</div>
<div class="sidebarblock">
<div class="content">
<div class="title">
Valid Usage
</div>
<div class="ulist">
- <a href="#VUID-RayTminKHR-RayTminKHR-04351"
id="VUID-RayTminKHR-RayTminKHR-04351"></a> <span class="vuid">
VUID-RayTminKHR-RayTminKHR-04351 </span>
The ` RayTminKHR ` decoration **must** be used only within the
` IntersectionKHR ` , ` AnyHitKHR ` , ` ClosestHitKHR ` , or
` MissKHR ` ` Execution ` ` Model `
- <a href="#VUID-RayTminKHR-RayTminKHR-04352"
id="VUID-RayTminKHR-RayTminKHR-04352"></a> <span class="vuid">
VUID-RayTminKHR-RayTminKHR-04352 </span>
The variable decorated with ` RayTminKHR ` **must** be declared using
the ` Input ` ` Storage ` ` Class `
- <a href="#VUID-RayTminKHR-RayTminKHR-04353"
id="VUID-RayTminKHR-RayTminKHR-04353"></a> <span class="vuid">
VUID-RayTminKHR-RayTminKHR-04353 </span>
The variable decorated with ` RayTminKHR ` **must** be declared as a
scalar 32-bit floating-point value
</div>
</div>
</div>
</div>
</div>
</div>
## Test Case(s)
### Example 1
```hlsl
//dxc RayTMin_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export float fn() {
return RayTMin();
}
```
### SPIRV Example(s):
### Example 2
```hlsl
//dxc RayTMin_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 = RayTMin();
}
```
## HLSL:
A float representing the current parametric starting point for the ray.
## Syntax
```
float RayTMin();
```
## Remarks
**RayTMin** defines the starting point of the ray according to the following formula: Origin + (Direction * RayTMin). *Origin* and *Direction* may be in either world or object space, which results in either a world or an object space starting point.
**RayTMin** is specified in the call to [**TraceRay**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/traceray-function.md), and is constant for the duration of that call.
This function can be called from the following raytracing shader types:
* [**Any Hit Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/any-hit-shader.md)
* [**Closest Hit Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/closest-hit-shader.md)
* [**Intersection Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/intersection-shader.md)
* [**Miss Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/miss-shader.md)
## See also
<dl> <dt>
[Direct3D 12 Raytracing HLSL Reference](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/direct3d-12-raytracing-hlsl-reference.md)
</dt> </dl>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEWV9z4jgS_zTKi8ouIwMZHnggEHZSN7m5SrJT-5aS7QbrIkteSSbhPv1VS8Y2hCQzt3M7FA-o1Wp1__qPWoJbK7YKYE4mV2SyuuCNK7WZb7j5j1byItPFfh5RMrmiZLKiN1UtoQLlKJkmd3z_cCsUmSY0l1xtadYI6YQibEmSRb_oi1BP7_HTZ-FKZCillY9COSOUFbmNSzJNjiQtioJaqDjNS8ifLN1ocyLYaSQscfrzl_svV2GHdaNyJ7RacimRSyjkuoeKe06htnFe1-d2y3UBW1Bv7nRdCTfY6PqlNv0Gy99a8kfSHVhnW4keGsLWSCNsvdQF_AYK9yBs3SJmCVu3qsQI2ps4vSMYrW-lei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