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

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

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

 ### Example 2
```hlsl
//dxc WorldToObject3x4_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 = WorldToObject3x4();
}
```
## 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

```
float3x4 WorldToObject3x4();

```




## Remarks

The matrix is a transposition of **WorldToObject4x3** 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_zTKi8ouI4MJDzwQCDupnbm5SrJz-5aS7QbrIksuSSZwn_6qZWObhJDN_p1K1WCp1X9-v1arJW6t2CqAOZnckMnqiteu0Ga-4eZ_WsmrVOeHeUDJ5IaSyYrelZWEEpSjJIn-o43MH_X39L-QuXg_JklEM8nVlqa1kE4owpYkWvSrvwr1_JsW0hfhCpQspJVPQjkjlBWZDQuSRCcqF3lOLZScZgVkz5ZutHnPgtM4s0S5L18fvt40pta1ypzQasmlRCmhUOoBSu4lhdqGWVWdM5vpHLagPjZ5Wwo3sHi7r0xvaflTO_yRGQfW2VajB4uwNY4Rtl7qHH4ChTYIW7cYWsLWr30KEc93IbxgAfFo1Xt3786qD8AYbexZK0sD3AF1BaB6odxTvn86h1nHdgvQXcf-ShjI3K-hyy8rX_169_V79Y1XlVBbVKk3H9h0mqLEaMJ6YlDLZVPnWA-b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