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

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

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 144 | RayFlags | 6.3 | ('library', 'intersection', 'anyhit', 'closesthit', 'miss') |

## SPIR-V

<div id="header">

# [IncomingRayFlagsKHR](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/IncomingRayFlagsKHR.html)

## Short Description

<div class="sectionbody">

IncomingRayFlagsKHR - Flags used to trace 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">

` IncomingRayFlagsKHR `  
A variable with the ` IncomingRayFlagsKHR ` decoration will contain the
ray flags passed in to the trace call that invoked this particular
shader. Setting pipeline flags on the ray tracing pipeline **must** not
cause any corresponding flags to be set in variables with this
decoration.

</div>

<div class="sidebarblock">

<div class="content">

<div class="title">

Valid Usage

</div>

<div class="ulist">

- <a href="#VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04248"
 id="VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04248"></a>
  <span class="vuid"> VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04248
  </span> 
  The ` IncomingRayFlagsKHR ` decoration **must** be used only within
 the ` IntersectionKHR ` , ` AnyHitKHR ` , ` ClosestHitKHR ` , or
  ` MissKHR ` ` Execution ` ` Model `

- <a href="#VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04249"
 id="VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04249"></a>
  <span class="vuid"> VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04249
  </span> 
  The variable decorated with ` IncomingRayFlagsKHR ` **must** be
 declared using the ` Input ` ` Storage ` ` Class `

- <a href="#VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04250"
 id="VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04250"></a>
  <span class="vuid"> VUID-IncomingRayFlagsKHR-IncomingRayFlagsKHR-04250
  </span> 
  The variable decorated with ` IncomingRayFlagsKHR ` **must** be
 declared as a scalar 32-bit integer value

</div>

</div>

</div>

</div>

</div>

</div>


## Test Case(s)

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

export uint fn() {
    return RayFlags();
}
```
 ### SPIRV Example(s):

 ### Example 2
```hlsl
//dxc RayFlags_spirv_test.hlsl -T lib_6_8 -E fn -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0

[shader("intersection")]
void fn() {
uint    ret = RayFlags();
}
```
## HLSL:

An unsigned integer containing the current [**ray_flag**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/ray_flag.md) flags. 

## Syntax

```
uint RayFlags();

```

## 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)
* [**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/eJzEWVtzGykW_jXohWpVi9b1QQ-yZE1cm-xsxZnUvLkQHKlZ09AFtGLtr9869EUtW7ZTk5nEJZfFAc7l-w5wwNx7dTAASzK5IZPNgFcht2655-5_1ujBzsrTMqFkckPJZEPvilJDASZQMk0_89NW84Mn05QKzc2B7iqlgzKErUm6Os_6qMzjmxPoNxVyHJFrrx-UCU4Zr4Qf5mSaXqhaSUk9FJyKHMSjp3vrnmsOFiVr7P_w8f7jTW1iWxkRlDVrrjWOUgZH3UPB40hlDkNRltfMCSvhAOZ1U7eFCj1Lt0-lO1tY_9aI31MfwAffaIzgELZFGWHbtZXwGxi0Qdi2wcwTtm19GSJur0L1hmaMv1Eb3by7UJuAc9Zd1752w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