<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99223>99223</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `unpack_u8u16` 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 `unpack_u8u16` clang builtin,
- [ ] Link `unpack_u8u16` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `unpack_u8u16` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `unpack_u8u16` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/unpack_u8u16.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/unpack_u8u16-errors.hlsl`
- [ ] Create the `int_dx_unpack_u8u16` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_unpack_u8u16` to `219` in `DXIL.td`
- [ ] Create the `unpack_u8u16.ll` and `unpack_u8u16_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_unpack_u8u16` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `unpack_u8u16` lowering and map it to `int_spv_unpack_u8u16` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/unpack_u8u16.ll`
## DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 219 | Unpack4x8 | 6.6 | () |
## SPIR-V
# [OpUConvert](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpUConvert):
## Description:
Convert unsigned width. This is either a truncate or a zero extend.
*Result Type* must be a scalar or vector of [*integer type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Integer),
whose *Signedness* operand is 0.
*Unsigned Value* must be a scalar or vector of [*integer
type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Integer). It must have the same number of components as *Result
Type*. The component width must not equal the component width in *Result
Type*.
Results are computed per component.
<table>
<colgroup>
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
</colgroup>
<thead>
<tr>
<th>Word Count</th>
<th>Opcode</th>
<th>Results</th>
<th>Operands</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>4</p></td>
<td class="tableblock halign-left valign-top"><p>113</p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>Result Type</em></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#ResultId"><em>Result <id></em></a></p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>Unsigned Value</em></p></td>
</tr>
</tbody>
</table>
## Test Case(s)
### Example 1
```hlsl
//dxc unpack_u8u16_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export uint16_t4 fn(uint8_t4_packed p1) {
return unpack_u8u16(p1);
}
```
## HLSL:
## Syntax
```syntax
uint16_t<4> unpack_u8u16(p32u8 pk);
```
## Type Description
| Name | [**Template Type**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-data-types.md)| [**Component Type**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-data-types.md) | Size |
|-------|--------------------------------------------------------------------|----------------------------------------------------------------------|------|
| *ret* | [**vector**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-vector.md) | [**uint16_t**](https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types) | 4 |
| *pk* | [**scalar**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-scalar.md) | [**uint8_t4_packed**](../WinProg/windows-data-types) | 1 |
## Minimum Shader Model
This function is supported in the following shader models.
|Shader Model | Supported|
|-------------|----------|
|[Shader Model 6.6](https://microsoft.github.io/DirectX-Specs/d3d/HLSL_ShaderModel6_6) and higher shader models | yes |
## Shader Stages
## See also
- [**Intrinsic Functions (DirectX HLSL)**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)
- **See [Unpack Intrinsics](https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_Pack_Unpack_Intrinsics#unpack-intrinsics)**
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWd9z4jjy_2vEi8ouI4MDDzwQEvZL1eQ7U0tmdt8oYQtbF1nySXJC5q-_asn4B5Bk9272bjZFDUhq9Y9Pt9TdGmoMzyVjCzS9RdO7Ea1tofTiQPV3JcVor7LXRYDR9Baj6R3elJVgJZMWoySqZUXTp109q8cJSiKcCipzvK-5sFwiskLRstv5icunDzfhF24LoCqEETsurebS8NSEBUqiAbtllmHDSorTgqVPBh-UvsbdKphdAc3_fdp-uvVi1rVMLVdyRYUAKi6BastK6ii5zMO0qq6JTFXGcibfF3dfctuTdn-sdCdl9Usz_ZEIy4w1DUcHEiJrmENkvVIZ-4VJkIHIusHOILLu6xMChm_C9g53wKFh7VTdXLAOmNZKm6sSVppRy7AtGLDm0u6y4-4cp9azDSib1tN3XLPU_h7a7H3Gd79vPn2uHmhVcZkDS3V4R55VGFbJeN45Aji8L-bcw6GPFiqz85VdA4gn8Nh6KUI8lxeOQ2Td2InI-mMATfX8JxDcftn8-u2KYRuJ3dJGGqtrF_9bJlhqlYZQxOlA7rk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