<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99182>99182</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `AcceptHitAndEndSearch` 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 `AcceptHitAndEndSearch` clang builtin,
- [ ] Link `AcceptHitAndEndSearch` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `AcceptHitAndEndSearch` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `AcceptHitAndEndSearch` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/AcceptHitAndEndSearch.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/AcceptHitAndEndSearch-errors.hlsl`
- [ ] Create the `int_dx_AcceptHitAndEndSearch` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_AcceptHitAndEndSearch` to `156` in `DXIL.td`
- [ ] Create the `AcceptHitAndEndSearch.ll` and `AcceptHitAndEndSearch_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_AcceptHitAndEndSearch` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `AcceptHitAndEndSearch` lowering and map it to `int_spv_AcceptHitAndEndSearch` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/AcceptHitAndEndSearch.ll`
## DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 156 | AcceptHitAndEndSearch | 6.3 | ('anyhit',) |
## SPIR-V
# [OpTerminateRayKHR](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpTerminateRayKHR):
## Description:
Reserved.
[Capability](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Capability):
**RayTracingKHR**
[Reserved](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Unified).
| Word Count | Opcode | Results | Operands |
|------------|--------|---------|----------|
| 1 | 4449 | | |
## Test Case(s)
### Example 1
```hlsl
//dxc AcceptHitAndEndSearch_test.hlsl -T lib_6_8 -enable-16bit-types -O0
struct [raypayload] RayPayload
{
float4 color : write(caller) : read(anyhit);
float distance : write(caller) : read(anyhit);
};
struct Attributes {
float3 barycentrics;
uint primitiveIndex;
};
[shader("anyhit")]
export void fn(inout RayPayload payload, in Attributes attributes) {
return AcceptHitAndEndSearch();
}
```
### SPIRV Example(s):
### Example 2
```hlsl
//dxc AcceptHitAndEndSearch_spirv_test.hlsl -T lib_6_8 -E fn -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0
struct [raypayload] RayPayload
{
float4 color : write(caller) : read(anyhit);
float distance : write(caller) : read(anyhit);
};
struct Attributes {
float3 barycentrics;
uint primitiveIndex;
};
[shader("anyhit")]
void fn(inout RayPayload payload, in Attributes attributes) {
return AcceptHitAndEndSearch();
}
```
## HLSL:
Used in an [any hit shader](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/any-hit-shader.md) to commit the current hit and then stop searching for more hits for the ray. If there is an intersection shader running, it's execution stops. Execution passes to the [closest hit shader](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/closest-hit-shader.md), if enabled, with the closest hit recorded so far.
## Syntax
```
void AcceptHitAndEndSearch();
```
## Return Value
**void**
## Remarks
This function can be called from the following raytracing shader types:
* [**Callable Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/callable-shader.md)
* [**Closest Hit Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/closest-hit-shader.md)
* [**Miss Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/miss-shader.md)
* [**Ray Generation Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/ray-generation-shader.md)
## See also
* [Direct3D 12 raytracing HLSL reference](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/direct3d-12-raytracing-hlsl-reference.md)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWEFz27oR_jXQBUOOBIqSddBBlqzE06R5Y-el7-YBwaWIGgQ4ACib_fWdBUmZjmU7fZ2X9FCPMiGAJfbDtx-AXXLn5EEDrEl6SdLdhDe-NHZdcPsvo9UkM3m7jihJLylJd_S6qhVUoD0li-lGCKj9R-k3Or_S-S1wK0qymFKhuD7QrJHKS03Ylkw3T1N8kvr-x9-mD9KXaF4qp-6k9lZqJ4WL0fTZvJs8pw4qTkUJ4t7Rwtg33XiDw1s0_vjp9tNl52_faOGl0VuuFFpJjVa3UPFgKfUhFnV9zrcwORxA_6Dfq0r6kdurx9o-udt-6Lvf8-XBedfPGGgjbI99hO23JocPoNEHYfueTUfY_iywGOl9ldE33CAzvY-A-fp1HxFYa6w762prgXugvgT0IbW_yx_vXqXwJIOer-uTLHbSgvB_xD5_28Puj-tPX-rPvK6lPuCUpvgRx95QNJuli6dg4VTv-jtPeicxrvNXTe56zjrLLg6dW6WO1YtoE7bvGSBs_z7Hrj7-GZJvf7u--XZmydeahqFr7bxtwja6BQXCG4tCpuJ9StCxMg9gpT4EYipeUyp9L74fAB226ysoSLIhycaF1mk5ZDGNz_GEk0TfaMbFPeg8cE8Fd_AO_8E3YXtUefR0Xr268VS_F_DHEsISOkSw61tuKSqMfqlx09NR---86tq3Jc_B0s8mBzXuuPX8AA57-omipz_6TvtlRzSaaJYuwvjZJYWRRZyE_wm7IG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