<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/99181>99181</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Implement the `IgnoreHit` 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 `IgnoreHit` clang builtin,
- [ ] Link `IgnoreHit` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `IgnoreHit` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `IgnoreHit` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/IgnoreHit.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/IgnoreHit-errors.hlsl`
- [ ] Create the `int_dx_IgnoreHit` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_IgnoreHit` to  `155` in `DXIL.td`
- [ ] Create the  `IgnoreHit.ll` and `IgnoreHit_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_IgnoreHit` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `IgnoreHit` lowering and map  it to `int_spv_IgnoreHit` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/IgnoreHit.ll`

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 155 | IgnoreHit | 6.3 | ('anyhit',) |

## SPIR-V

# [OpIgnoreIntersectionKHR](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpIgnoreIntersectionKHR):

## 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          | 4448   | |          |



## Test Case(s)

 
 ### Example 1
```hlsl
//dxc IgnoreHit_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 IgnoreHit();
}
```
 ### SPIRV Example(s):

 ### Example 2
```hlsl
//dxc IgnoreHit_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 IgnoreHit();
}
```
## HLSL:

Called from an [any hit shader](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/any-hit-shader.md) to reject the hit and end the shader. The hit search continues on without committing the distance and attributes for the current hit.  The [**ReportHit**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/reporthit-function.md) call in the [intersection shader](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/intersection-shader.md), if there is one, will return false.  Any modifications made to the ray payload up to this point in the any hit shader are preserved.

## Syntax

```
void IgnoreHit();

```


## Return Value

**void**

## Remarks

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)




## 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/eJzsWM1u4zgSfhr6Qkiwqcg_Bx8cO542tnt7kGR75xZQUsnihiIFknLiffpFUZQtT5z0LBaTvUzgRltFqn6--qpYNLdW7BXAkqS3JN2MeOsqbZYlN__WSo4yXRyXESXpLSXphu7qRkINylEyHe_2Shv4IhyZjmkuudrTrBXSCUXYmoxX59e-CvX88Rv0RbgKt1TSyiehnBHKitzGFZmOL3StioJaqDnNK8ifLS21eaPaaRStccOXrw9fbzsb21blTmi15lLiLqFw1wPU3O8Uah_nTXPNXq4L2IP6wNZdLdzA1N1rY84m1r8E8c_0O7DOBo0eHsK2KCNsu9YF_AIKbRC2DahZwrYnZ2KE7l20PlCNCAS93s_dpd4IjNHGXlW_NsAdUFcB6hXKPRWvTxfwnFIZsNidUrsRBnL3W-yKj7Vuftt9_d58400j1B5V6vI9Y05TXJqk6Rl8fP1jGxcpjTtucFVciJ8CCN1qB2anX8pD_SZNhG1DeIRtfw6abQ5_FLWHX3f3P67Es1PUL-2Udab1PH8ACbnTBllH8wujF8akfgEj1N4HXfOGUuECU95xztfNO9ZIsiLJyvqnk9tkOo6vYYBKoh804_kzqMLjSnNu4SfYetuEbZGS0blZXFSDDGTFD0sIS2ifkU42W1OkBv3eYPXRwfPfed09P1S8AEO_6QLkUPDg-B4sSoKi6PxHf_L8VhANFE3S1K-fwvBP0zjx_xM2J2zG1bESjrAZdlm26N8-hdlhehIh5N-bTuFOOTAWfL7-9uWepBvC5pVzjcWssS1hWwN7YZ05xs-V0UrbWJt9QDxCyG0DHuhWiVJAMemzEVeuloQl75liCzRxkQ6wuRENbuiWKBmv7sGCOUARh63p7Zo3PBNSuOOf4e5Au_eQev_wc8-Pj4bnQu29-yiiNHh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