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

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

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 150 | ObjectRayDirection | 6.3 | ('library', 'intersection', 'anyhit', 'closesthit') |

## SPIR-V

<div id="header">

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

## Short Description

<div class="sectionbody">

ObjectRayDirectionKHR - Ray direction in object space

</div>

</div>

<div id="content" class="loadable">

<div class="sect1">

## <a href="#_description" class="anchor"></a> Description

<div class="sectionbody">

<div class="dlist">

` ObjectRayDirectionKHR `  
A variable decorated with the ` ObjectRayDirectionKHR ` decoration will
specify the direction of the ray being processed, in object space.

</div>

<div class="sidebarblock">

<div class="content">

<div class="title">

Valid Usage

</div>

<div class="ulist">

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

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

- <a href="#VUID-ObjectRayDirectionKHR-ObjectRayDirectionKHR-04301"
 id="VUID-ObjectRayDirectionKHR-ObjectRayDirectionKHR-04301"></a>
  <span class="vuid">
  VUID-ObjectRayDirectionKHR-ObjectRayDirectionKHR-04301 </span>  
  The variable decorated with ` ObjectRayDirectionKHR ` **must** be
  declared as a three-component vector of 32-bit floating-point values

</div>

</div>

</div>

</div>

</div>

</div>


## Test Case(s)

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

export float3 fn() {
    return ObjectRayDirection();
}
```
 ### SPIRV Example(s):

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

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

The object-space direction for the current ray. Object-space refers to the space of the current bottom-level acceleration structure.

## Syntax

```
float3 ObjectRayDirection();

```



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





## 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/eJzEWF9v2zgS_zTMCyFDomwnfvCDY8fbYLvXQ9It9i2gxJHFC0UKJOXG9-kPQ8mykijOZrfXLQLUGg7nz-83JIfkzsmdBliS2TWZbS5440tjlwW3_zVaXWRGHJYRJbNrSmYbelvVCirQnpJ5_CX7D-T-jh820kLupdFkHtNccb2jWSOVl5qwNYlXp_mfpX78k1Ppd-lL1C2VUw9Seyu1k7mblGQePzO6EoI6qDjNS8gfHS2MfduHNzi2Rs1Pn-8_X7fOto0OGmuuFGpJjVr3UPGgKfVuktf1mOPcCNiB_jNObyrpBz5vnmp78rX-pRO_58iD866zGAAjbIsywrZrI-AX0OiDsG2HoyNs-zqqCaL6JpBnfCAmnYMQ8O0bDiKw1lg36mdtgXugvgR0ILV_EE8P48j1vHcw3fZ10Kr9MfHivPnNH7efv9S_8bqWeocmTfGuV28o6iSz-EQQ2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