<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99201>99201</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `GetAttributeAtVertex` 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 `GetAttributeAtVertex` clang builtin,
- [ ] Link `GetAttributeAtVertex` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `GetAttributeAtVertex` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `GetAttributeAtVertex` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/GetAttributeAtVertex.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/GetAttributeAtVertex-errors.hlsl`
- [ ] Create the `int_dx_GetAttributeAtVertex` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_GetAttributeAtVertex` to `137` in `DXIL.td`
- [ ] Create the `GetAttributeAtVertex.ll` and `GetAttributeAtVertex_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_GetAttributeAtVertex` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `GetAttributeAtVertex` lowering and map it to `int_spv_GetAttributeAtVertex` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/GetAttributeAtVertex.ll`
## DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 137 | AttributeAtVertex | 6.1 | ('pixel',) |
## SPIR-V
# [OpAccessChain](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpAccessChain):
## Description:
Create a pointer into a [*composite*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#CompositeType) object.
*Result Type* must be an [**OpTypePointer**](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpTypePointer). Its *Type*
operand must be the type reached by walking the *Base’s* type hierarchy
down to the last provided index in *Indexes*, and its *Storage Class*
operand must be the same as the Storage Class of *Base*.
*Base* must be a pointer, pointing to the base of a composite object.
*Indexes* walk the type hierarchy to the desired depth, potentially down
to scalar granularity. The first index in *Indexes* selects the
top-level member/element/component/element of the base composite. All
composite constituents use zero-based numbering, as described by their
**OpType…** instruction. The second index applies similarly to that
result, and so on. Once any non-composite type is reached, there must be
no remaining (unused) indexes.
Each index in *Indexes*
- must have a scalar [integer type](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Integer)
- is treated as signed
- if indexing into a structure, must be an [**OpConstant**](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpConstant)
whose value is in bounds for selecting a member
- if indexing into a vector, array, or matrix, with the result type
being a [logical pointer type](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#LogicalPointerType), causes undefined
behavior if not in bounds.
<table style="width:100%;">
<colgroup>
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
<col style="width: 16%" />
</colgroup>
<thead>
<tr>
<th>Word Count</th>
<th>Opcode</th>
<th>Results</th>
<th>Operands</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>4 + variable</p></td>
<td class="tableblock halign-left valign-top"><p>65</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>Base</em></p></td>
<td class="tableblock halign-left valign-top"><p><em><id>,
<id>, …</em><br />
<em>Indexes</em></p></td>
</tr>
</tbody>
</table>
## Test Case(s)
### Example 1
```hlsl
//dxc GetAttributeAtVertex_test.hlsl -T lib_6_8 -enable-16bit-types -O0
[numthreads(1, 1, 1)]
[shader("pixel")]
float4 fn(nointerpolation float4 p1 : COLOR ) : SV_Target {
uint p2 = 1;
return GetAttributeAtVertex(p1, p2);
}
```
### Example 2
```hlsl
//dxc GetAttributeAtVertex_1_test.hlsl -T lib_6_8 -enable-16bit-types -O0
[numthreads(1, 1, 1)]
[shader("pixel")]
uint4 fn(nointerpolation float4 p1 : COLOR ) : SV_Target {
uint p2 = 1;
return GetAttributeAtVertex(p1, p2);
}
```
### Example 3
```hlsl
//dxc GetAttributeAtVertex_2_test.hlsl -T lib_6_8 -enable-16bit-types -O0
[numthreads(1, 1, 1)]
[shader("pixel")]
int4 fn(nointerpolation float4 p1 : COLOR ) : SV_Target {
uint p2 = 1;
return GetAttributeAtVertex(p1, p2);
}
```
## HLSL:
## Syntax
```syntax
numeric<> GetAttributeAtVertex(numeric<> value, uint VertexID);
```
## 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* | [**scalar**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-scalar.md), [**vector**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-vector.md), or [**matrix**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-matrix.md) | [**float**](../WinProg/windows-data-types) or [**int**](../WinProg/windows-data-types) | any |
| *value* | [**scalar**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-scalar.md), [**vector**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-vector.md), or [**matrix**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-matrix.md) | [**float**](../WinProg/windows-data-types) or [**int**](../WinProg/windows-data-types) | any |
| *VertexID* | [**scalar**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-scalar.md) | [**uint**](../WinProg/windows-data-types) | 1 |
## Minimum Shader Model
This function is supported in the following shader models.
|Shader Model | Supported|
|-------------|----------|
|[Shader Model 6.1](https://github.com/microsoft/DirectXShaderCompiler/wiki/Shader-Model-6.1) and higher shader models | yes |
## Shader Stages
* [**Pixel Shader**](../direct3dhlsl/dx-graphics-hlsl-writing-shaders-9.md#pixel-shader-basics)
## See also
- [**Intrinsic Functions (DirectX HLSL)**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/../direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)
- **See [GetAttributeAtVertex MeshShader Usage](https://microsoft.github.io/DirectX-Specs/d3d/MeshShader#:~:text=Attributes%20used%20with,have%20any%20effect.).**
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWs1y2zgSfhr4giKLBC3ZOvhAy9asq5J1auzNzM0Fki0SYxBgAaBtzWGffasBUpRiKc7MTjZJ7aQcm8RP99dfN34aILdW1ArggswuyezqhPeu0eZizc3vWsmTQlebi4iS2SUlsyt603YSWlCOknnyE7jcOSOK3kHuPoJx8ELmCS0lVzUteiGdUIQtSZJPEt4J9fjFnemzcA22bqSVD0I5I5QVpY0bMk_2xOZ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