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

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

## DirectX

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

## SPIR-V

<div id="header">

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

## Short Description

<div class="sectionbody">

WorldToObjectKHR - Transformation matrix from world to 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">

` WorldToObjectKHR `  
A variable decorated with the ` WorldToObjectKHR ` decoration will
contain the current world-to-object 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-WorldToObjectKHR-WorldToObjectKHR-04434"
 id="VUID-WorldToObjectKHR-WorldToObjectKHR-04434"></a>
  <span class="vuid"> VUID-WorldToObjectKHR-WorldToObjectKHR-04434
  </span>  
 The ` WorldToObjectKHR ` decoration **must** be used only within the
  ` IntersectionKHR ` , ` AnyHitKHR ` , or ` ClosestHitKHR `
  ` Execution ` ` Model `

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

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

export float4x3 fn() {
    return WorldToObject4x3();
}
```
 ### SPIRV Example(s):

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

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

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

## Syntax

```
float4x3 WorldToObject4x3();

```




## Remarks

The matrix is a transposition of **WorldToObject3x4** 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/eJzEWF9z4ygS_zTkhZJKRraSPPjBseOd1M7cXCXZuX1LIaltcUGgAuTY9-mvGmRLThxns3-nUjUWNP3n92uaBm6tWCuAKZnckMnigreu0ma64uZ_WsmLXJe7aUTJ5IaSyYLe1Y2EGpSjJEv-o40sH_X3_L9QuPE2JVlCC8nVmuatkE4owuYkmfWrvwr1_JsW0hfhKpSspJVPQjkjlBWFjSuSJUcqZ2VJLdScFhUUz5autHnPgtM4M0e5L18fvt4EU8tWFU5oNedSopRQKPUANfeSQq3jomlOmS10CWtQH5u8rYUbWLzdNqa3NP-pG_7IjAPrbKfRg0XYEscIW851CT-BQhuELTsMLWHL1z7FiOe7EJ6xgHh06r27dyfVR2CMNvaklbkB7oC6ClC9UO6p3D6dwuzAdgfQ3YH9hTBQuF9jV55Xvvj17uv35htvGqHWqFKvPrDpNEWJ0YT1xKCW86ZOsR6HLOKqP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