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

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

## DirectX

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

## SPIR-V

<div id="header">

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

## Short Description

<div class="sectionbody">

WorldRayOriginKHR - Ray origin in world space

</div>

</div>

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

<div class="sect1">

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

<div class="sectionbody">

<div class="dlist">

` WorldRayOriginKHR `  
A variable decorated with the ` WorldRayOriginKHR ` decoration will
specify the origin of the ray being processed, in world space. The value
is the parameter passed into the <a
href="https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#glossary-pipeline-trace-ray"
rel="noopener" target="_blank">pipeline trace ray</a> instruction.

</div>

<div class="sidebarblock">

<div class="content">

<div class="title">

Valid Usage

</div>

<div class="ulist">

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

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

- <a href="#VUID-WorldRayOriginKHR-WorldRayOriginKHR-04433"
 id="VUID-WorldRayOriginKHR-WorldRayOriginKHR-04433"></a>
  <span class="vuid"> VUID-WorldRayOriginKHR-WorldRayOriginKHR-04433
  </span>  
 The variable decorated with ` WorldRayOriginKHR ` **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 WorldRayOrigin_test.hlsl -T lib_6_8 -enable-16bit-types -O0

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

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

The world-space origin of the current ray.

## Syntax

```
float3 WorldRayOrigin();

```

## 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/eJzEWV9z4jgS_zTiRWXKyMHAAw8EwobamZurZHZu31Ky1WAdsuSSZCbcp79q2fwnZFMzuzNF1VitVv_5dbfUUrhzcqUBxqR_T_qzDq99Yex4ye3_jFadzIjtOKKkf09Jf0YXZaWgBO0pSeP_GKvEE99-sXIlNUljmiuuVzSrpfJSEzYl8eSw9pPU67-wjH6XvkC-Qjn1IrW3UjuZu25B0vhE4EQI6qDkNC8gXzu6NPa6fG-QPkWux0_Pn-4bRfNa514aPeVKIZfUyPUMJQ-cUq-6eVVdU5obASvQ7yl8KKU_0vfwWtmDnulvLfk9JR6cd63EABRhc6QRNp8aAb-BRh2EzVv8HGHzU4u6iOS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