<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99189>99189</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `ObjectRayOrigin` 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 `ObjectRayOrigin` clang builtin,
- [ ] Link `ObjectRayOrigin` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `ObjectRayOrigin` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `ObjectRayOrigin` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/ObjectRayOrigin.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/ObjectRayOrigin-errors.hlsl`
- [ ] Create the `int_dx_ObjectRayOrigin` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_ObjectRayOrigin` to `149` in `DXIL.td`
- [ ] Create the `ObjectRayOrigin.ll` and `ObjectRayOrigin_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_ObjectRayOrigin` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `ObjectRayOrigin` lowering and map it to `int_spv_ObjectRayOrigin` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/ObjectRayOrigin.ll`
## DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 149 | ObjectRayOrigin | 6.3 | ('library', 'intersection', 'anyhit', 'closesthit') |
## SPIR-V
<div id="header">
# [ObjectRayOriginKHR](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/ObjectRayOriginKHR.html)
## Short Description
<div class="sectionbody">
ObjectRayOriginKHR - Ray origin 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">
` ObjectRayOriginKHR `
A variable decorated with the ` ObjectRayOriginKHR ` decoration will
specify the origin 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-ObjectRayOriginKHR-ObjectRayOriginKHR-04302"
id="VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04302"></a>
<span class="vuid"> VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04302
</span>
The ` ObjectRayOriginKHR ` decoration **must** be used only within the
` IntersectionKHR ` , ` AnyHitKHR ` , or ` ClosestHitKHR `
` Execution ` ` Model `
- <a href="#VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04303"
id="VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04303"></a>
<span class="vuid"> VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04303
</span>
The variable decorated with ` ObjectRayOriginKHR ` **must** be
declared using the ` Input ` ` Storage ` ` Class `
- <a href="#VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04304"
id="VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04304"></a>
<span class="vuid"> VUID-ObjectRayOriginKHR-ObjectRayOriginKHR-04304
</span>
The variable decorated with ` ObjectRayOriginKHR ` **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 ObjectRayOrigin_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export float3 fn() {
return ObjectRayOrigin();
}
```
### SPIRV Example(s):
### Example 2
```hlsl
//dxc ObjectRayOrigin_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 = ObjectRayOrigin();
}
```
## HLSL:
The object-space origin for the current ray. Object-space refers to the space of the current bottom-level acceleration structure.
## Syntax
```
float3 ObjectRayOrigin();
```
## 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/eJzEWF9z4jgS_zTiRWXKyEDCAw8Ewoba2ctVMju1bylZbmNdhOSSZCbcp79qWYBDCNnczO5OpWqw1Oo_v1-r1RJ3Tq41wJSMbsho0eONr4ydltz-12jVy02xmyaUjG4oGS3oalMr2ID2lIzT-_w_IPwD391buZaajFMqFNdrmjdSeakJm5N0dlz8RernP7OOfpe-QsFKOfUktbdSOylcvyLj9JXGWVFQBxtORQXi2dHS2HcMeIMTcxS7-_L45aa1tGy08NLoOVcKpaRGqUfY8CAp9bov6vqcVWEKWIP-0OLtRvqOwduX2h4NzX-Jwx9Z8eC8ixoDVIQtcYyw5dwU8AtotEHYMiLoCFueuNRHMN_F74IBRCNqD96uzmlPwFpj3VkjcwvcA_UVoHap_VPx8nQGsAPREZ3VgfiFtCD8H31fXNa9-GP15b7-jde11GtUacrLJr2hKDAYTo6koJLLls4Q3m_zh-vizORTBKeVaaFubSm13byhkrBlDJiw5cdgunr7OTQf_716-HYmwpWmYWqlnbdN2BePoEB4YzE_qX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