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

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

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 158 | ReportHit | 6.3 | ('library', 'intersection') |

## SPIR-V

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

## Description:
(OpReportIntersectionNV)**  
 
Reserved.

[Capability](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Capability): 
**RayTracingNV**, **RayTracingKHR**  
 
[Reserved](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Unified).

<table style="width:100%;">
<colgroup>
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
</colgroup>
<thead>
<tr>
<th>Word Count</th>
<th>Opcode</th>
<th>Results</th>
<th>Operands</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>5</p></td>
<td class="tableblock halign-left valign-top"><p>5334</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Result Type</em></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#ResultId"><em>Result &lt;id&gt;</em></a></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Hit</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>HitKind</em></p></td>
</tr>
</tbody>
</table>



## Test Case(s)

 
 ### Example 1
```hlsl
//dxc ReportHit_test.hlsl -T lib_6_8 -enable-16bit-types -O0

struct RayPayload
{
        float4 color;
        float distance;
};
export bool fn(float p1, uint p2, RayPayload p3) {
    return ReportHit(p1, p2, p3);
}
```
## HLSL:

Called by an [intersection shader](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/intersection-shader.md) to report a ray intersection.

## Syntax
This intrinsic function definition is equivalent to the following function template:

```
template<attr_t>
bool ReportHit(float THit, uint HitKind, attr_t Attributes);
```



## Parameters

`THit`

A float value specifying the parametric distance of the intersection..

`HitKind`

An unsigned integer that identifies the type of hit that occurred.  This is a user-specified value in the range of 0-127.  The value can be read by [any hit](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/any-hit-shader.md) or [closest hit](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/closest-hit-shader.md) shaders with the **HitKind** intrinsic.

`Attributes`

The user-defined [**Intersection Attribute Structure**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/intersection-attributes.md) structure specifying the intersection attributes.  

## Return Value

**bool** True if the hit was accepted.  A hit is rejected if *THit* is outside the current ray interval, or the any hit shader calls [**IgnoreHit**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/ignorehit-function.md). The current ray interval is defined by **RayTMin** and **RayTCurrent**.

## Remarks

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

* [**Intersection Shader**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/intersection-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/eJzkOc1y2zjSTwNfUGRRYPR30EGWrIlrkknK9pdvbi6QaElYQwAXAG1rn36rAVIkY9lObW2Sw05pKkQ3-r8b6Ia5c3KnARZkfEnG6wte-72xiy23_zJaXRRGHBcJJeNLSsZren2oFBxAe0om2Q1UxvqP0pNJRkvF9Y4WtVReasJWJFt2ZJ-kfnibgj5Jv8cte-XUvdTeSu1k6dI9mWQDXkshqIMDp-UeygdHt8a-YO0Ngla44eOn20-XUcam1qWXRq-4UrhLatx1Cwcedkq9S8uqOievNAJ2oN-QdXWQvifq6rmynYjVHw34Pf4enHcNx-AewjYII2yzMgL-AI0yCNs0XnOEbU7KpOi6V731Bmv0QMM36Hk95JuAtca6s-xXFrgH6veAfKX29-L5fuCeUygbX1yfQruWFkr_d-rF21zXf19_-lJ95lUl9Q5Zmu1rwryhiBqNZ53zkfxtGYOQpjE3uBYD8H3jhIiNzoz8lXo8vAgTYZvGPM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