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

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

## DirectX

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

## SPIR-V

<div id="header">

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

## Short Description

<div class="sectionbody">

ObjectToWorldKHR - Transformation matrix from object to 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">

` ObjectToWorldKHR `  
A variable decorated with the ` ObjectToWorldKHR ` decoration will
contain the current object-to-world transformation matrix, which is
determined by the instance of the current intersection.

</div>

<div class="sidebarblock">

<div class="content">

<div class="title">

Valid Usage

</div>

<div class="ulist">

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

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

- <a href="#VUID-ObjectToWorldKHR-ObjectToWorldKHR-04307"
 id="VUID-ObjectToWorldKHR-ObjectToWorldKHR-04307"></a>
  <span class="vuid"> VUID-ObjectToWorldKHR-ObjectToWorldKHR-04307
  </span>  
 The variable decorated with ` ObjectToWorldKHR ` **must** be declared
  as a matrix with four columns of three-component vectors of 32-bit
 floating-point values

</div>

</div>

</div>

</div>

</div>

</div>


## Test Case(s)

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

export float3x4 fn() {
    return ObjectToWorld3x4();
}
```
 ### SPIRV Example(s):

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

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

A matrix for transforming from object-space to world-space. Object-space refers to the space of the current bottom-level acceleration structure.

## Syntax

```
float3x4 ObjectToWorld3x4();

```




## Remarks

The matrix is a transposition of **ObjectToWorld4x3** matrix.

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_zTKi8ouIwcTHnggEHZSO3NzNZmd27eUbDdYF1lySTKB-_RXLRljEkI2-3cqVYOlVv_5_Vqtlri1YqMAZmR8S8bLK966SpvZmpv_aSWvcl3uZxEl41tKxkt6XzcSalCOkiz5mv8XCvdd_0cbWaa7a5IltJBcbWjeCumEImxBkvlx9Wehnn7TQvosXIWSlbTyUShnhLKisHFFsuRE5bwsqYWa06KC4snStTZvWXAaZxYo9-nzw-fbYGrVqsIJrRZcSpQSCqUeoOZeUqhNXDTNObOFLmED6n2Td7VwA4t3u8YcLS1-6obfM-PAOttp9GARtsIxwlYLXcJPoNAGYasOQ0vY6qVPMeL5JoQXLCAenXrv7v1Z9REYo409a2VhgDugrgJUL5R7LHeP5zD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