<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99174>99174</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `QuadReadLaneAt` 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 `QuadReadLaneAt` clang builtin,
- [ ] Link `QuadReadLaneAt` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `QuadReadLaneAt` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `QuadReadLaneAt` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/QuadReadLaneAt.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/QuadReadLaneAt-errors.hlsl`
- [ ] Create the `int_dx_QuadReadLaneAt` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_QuadReadLaneAt` to `122` in `DXIL.td`
- [ ] Create the `QuadReadLaneAt.ll` and `QuadReadLaneAt_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_QuadReadLaneAt` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `QuadReadLaneAt` lowering and map it to `int_spv_QuadReadLaneAt` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/QuadReadLaneAt.ll`
## DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 122 | QuadReadLaneAt | 6.0 | ('library', 'compute', 'amplification', 'mesh', 'pixel', 'node') |
## SPIR-V
# [OpGroupNonUniformQuadBroadcast](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpGroupNonUniformQuadBroadcast):
## Description:
Result is the *Value* of the [invocation](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Invocation) within the
[quad](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Quad) with a [quad index](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#QuadIndex) equal to *Index*.
*Result Type* must be a scalar or vector of [*floating-point
type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Floating), [*integer type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Integer), or [*Boolean
type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Boolean).
*Execution* is a [*Scope*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Scope_-id-), but has no effect on the
behavior of this instruction. It must be **Subgroup**.
The type of *Value* must be the same as *Result Type*.
*Index* must be a scalar of [*integer type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Integer), whose
*Signedness* operand is 0.
Before **version 1.5**, *Index* must come from a [*constant
instruction*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#ConstantInstruction). Starting with **version 1.5**,
*Index* must be [dynamically uniform](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#DynamicallyUniform).
If the value of *Index* is greater than or equal to 4, or refers to an
inactive invocation, the resulting value is undefined.
[Capability](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Capability):
**GroupNonUniformQuad**
[Missing before](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Unified) **version 1.3**.
<table style="width:100%;">
<colgroup>
<col style="width: 14%" />
<col style="width: 14%" />
<col style="width: 14%" />
<col style="width: 14%" />
<col style="width: 14%" />
<col style="width: 14%" />
<col style="width: 14%" />
</colgroup>
<thead>
<tr>
<th>Word Count</th>
<th>Opcode</th>
<th>Results</th>
<th>Operands</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>6</p></td>
<td class="tableblock halign-left valign-top"><p>365</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><a
href="#Scope_-id-"><em>Scope <id></em></a><br />
<em>Execution</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>Value</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>Index</em></p></td>
</tr>
</tbody>
</table>
## Test Case(s)
### Example 1
```hlsl
//dxc QuadReadLaneAt_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export float4 fn(float4 p1, uint p2) {
return QuadReadLaneAt(p1, p2);
}
```
### Example 2
```hlsl
//dxc QuadReadLaneAt_1_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export uint4 fn(uint4 p1, uint p2) {
return QuadReadLaneAt(p1, p2);
}
```
### Example 3
```hlsl
//dxc QuadReadLaneAt_2_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export int4 fn(int4 p1, uint p2) {
return QuadReadLaneAt(p1, p2);
}
```
## HLSL:
Returns the specified source value from the lane identified by the lane ID within the current quad.
## Syntax
``` syntax
<type> QuadReadLaneAt(
<type> sourceValue,
uint quadLaneID
);
```
## Parameters
<dl> <dt>
*sourceValue*
</dt> <dd>
The requested type.
</dd> <dt>
*quadLaneID*
</dt> <dd>
The lane ID; this will be a value from 0 to 3.
</dd> </dl>
## Return value
The specified source value. The result of this function is uniform across the quad. If the source lane is inactive, the results are undefined.
## Remarks
For more information on quads, refer to [Overview of Shader Model 6](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/hlsl-shader-model-6-0-features-for-direct3d-12.md).
This function is supported from shader model 6.0 only in pixel and compute shaders.
## See also
<dl> <dt>
[Shader Model 6](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/shader-model-6-0.md)
</dt> </dl>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWUtz47gR_jXwBUUVBephHXTQw9qoamZnM_Zu9uYCyaaIGAQ4AChb-fUpPChSlmzPbKLdHOJy2WSj2V-_0EADVGu2EwBzNF6i8fqGNqaUal5Q9S8p-E0q88M8wmi8xGi8xtuq5lCBMBhN4r83NP8KNP9EBSwMmsQ441TscNowbphAZIXiRfftJyaevuMz_MxMaflKrvkjE0YxoVmmByWaxCcCF3mONVQUZyVkTxoXUl2Wb6SlryzX3z7df1p6oE0jMsOkWFHOLRcTluseKuo4mdgNsrq-BJrJHHYgPgK8q5jp4d291KrDWf0UyB-BGNBGB4nOUYhsLA2RzUrm8BMIi4HIJvhPI7I51WhgPfmm896Rb30RhDtltxeER6CUVPoixkoBNYBNCVY4E-Yxf3k899YxxsE122PM10xBZn4fmPx90evft5--1J9pXTOxsyJl8S6ikdiODwnpAmJlvA90HuuBzxwq8vOxx-AYz-K97JE431dnQURkE6xFZPOxI3W9_yFP3v-y_frbBfO2AruhrdBGNW4-3AOHzEhlExNnJ8jniFw-g2Ji53xQ0RpjZkIyvaemm2lv4KJkgZKFdm9HA9AkHlxyiRUS_YZTmj2ByJ2bcUY1fOBqh43IxmZt1NWY86nDQ1LbX5IgkuA2Sp42XWGbOPhLbecr7r3_TCv_fl_SHBT-LHPgfcK9oTvQlhIERd0P_uD9nBD1BA0JceOntjjSZBC7_4jcIjLlLFVUHRCZImJp00xWdWOgI9Cq5qxgGbUR6sgV6LJ7q9kL8O5VyNxLmLU6HZ3nw3Uk2Wh-qX9Ssql_luJXwQqpKqv1UkmaZ1QbNF4jclsaU2ubF2SDyEbBjmmjDoOnUkkh9UCqXYhpZIOqa3ChbAQrGOTDNt6D0lQckeQDRDKzSCchB50pVjsXuCGMUbz4CrrhBjPtZwdZ_EZ5A4gsbPVxpPGSib0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