<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99111>99111</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `EvaluateAttributeSnapped` HLSL Function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
metabug,
backend:DirectX,
HLSL,
bot:HLSL
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
farzonl
</td>
</tr>
</table>
<pre>
- [ ] Implement `EvaluateAttributeSnapped` clang builtin,
- [ ] Link `EvaluateAttributeSnapped` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `EvaluateAttributeSnapped` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `EvaluateAttributeSnapped` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/EvaluateAttributeSnapped.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/EvaluateAttributeSnapped-errors.hlsl`
- [ ] Create the `int_dx_EvaluateAttributeSnapped` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_EvaluateAttributeSnapped` to `87` in `DXIL.td`
- [ ] Create the `EvaluateAttributeSnapped.ll` and `EvaluateAttributeSnapped_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
## DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 87 | EvalSnapped | 6.0 | ('pixel',) |
## SPIR-V
There is no support for `EvaluateAttributeSnapped` when targeting SPIR-V.
## Test Case(s)
### Example 1
```hlsl
//dxc EvaluateAttributeSnapped_test.hlsl -T lib_6_8 -enable-16bit-types -O0
[numthreads(1, 1, 1)]
[shader("pixel")]
float4 fn(float4 p1 : COLOR ) : SV_Target {
int2 p2;
return EvaluateAttributeSnapped(p1, p2);
}
```
## HLSL:
Evaluates at the pixel centroid with an offset.
## Syntax
``` syntax
numeric EvaluateAttributeSnapped(
in attrib numeric value,
in
int2 offset
);
```
## Parameters
<dl> <dt>
*value* \[in\]
</dt> <dd>
Type: **attrib numeric**
The input value.
</dd> <dt>
*offset* \[in\]
</dt> <dd>
Type: **int2**
A 2D offset from the pixel center using a 16x16 grid.
</dd> </dl>
## Remarks
The range for the *offset* parameter must be defined by the following byte code.
Only the least significant 4 bits of the first two components (U, V) of the pixel offset are used. The conversion from the 4-bit fixed point to float is as follows (MSB...LSB), where the MSB is both a part of the fraction and determines the sign:
- 1000 = -0.5f (-8 / 16)
- 1001 = -0.4375f (-7 / 16)
- 1010 = -0.375f (-6 / 16)
- 1011 = -0.3125f (-5 / 16)
- 1100 = -0.25f (-4 / 16)
- 1101 = -0.1875f (-3 / 16)
- 1110 = -0.125f (-2 / 16)
- 1111 = -0.0625f (-1 / 16)
- 0000 = 0.0f ( 0 / 16)
- 0001 = 0.0625f ( 1 / 16)
- 0010 = 0.125f ( 2 / 16)
- 0011 = 0.1875f ( 3 / 16)
- 0100 = 0.25f ( 4 / 16)
- 0101 = 0.3125f ( 5 / 16)
- 0110 = 0.375f ( 6 / 16)
- 0111 = 0.4375f ( 7 / 16)
> [!Note]
> The left and top edges of a pixel are included in the offset; however, the bottom and right edges are not included. All other bits in the 32-bit integer U and V offset values are ignored.
An implementation can take the offset provided by the shader and obtain a full 32-bit fixed point value (28.4), which spans the valid range, by performing the following calculation:
```
iU = (iU<<28)>>28 // keep lowest 4 bits and sign extend, which yields [-8..7]
```
If an implementation must map the offset to a floating-point offset, it performs the following calculation:
```
fU = ((float)iU)/16
```
### Minimum Shader Model
This function is supported in the following shader models.
| Shader Model | Supported |
|-----------------------------------------------------------------------------|-----------|
| [Shader Model 5](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/d3d11-graphics-reference-sm5.md) and higher shader models | yes |
This function is supported in the following types of shaders:
| Vertex | Hull | Domain | Geometry | Pixel | Compute |
|--------|------|--------|----------|-------|---------|
| | | | | x | |
## See also
<dl> <dt>
[Intrinsic Functions](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)
</dt> <dt>
[Shader Model 5](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/d3d11-graphics-reference-sm5.md)
</dt> </dl>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWEtv4zgS_jXMpSBBovw8-GA78UyAZDKYpBtzCyipZHMjkQJJJc7--kVRD9uxk-7GLBYruDsSWazHVw8WKayVW4W4YOMVG19ficbttFkUwvxbq_Iq1fn7IgA2XgEbX8NtVZdYoXLAJtHNqygb4XDpnJFp4_BRibrGnE0iyEqhtpA2snRSMb5m0fLA5U6ql19iAG_S7WjFrrTls1TOSGVlZsMdm0QnrJd5DhYrAdkOsxcLhTY_kuQ0UayJ_ve7x7tVK3LTqMxJrdaiLIlKKqJ6xEp4Sqm2YVbXl8RnOsctqp8XfVNJdyT5Zl-bg8T1b93wj8Q5tM52HD14jG9ojPHNWuf4GyqSwfimw9QyvvlMt5Bw_hTaLyQRPp0Yr_btl2ICNEYbe1Ha2qBwCG6HJEYq95zvn7_CcoiKDrjbIUqupcHM_R26_Gsh13_f3j3U96KupdoSS138pGyngShn04PfiNnXEr8KjrANOqHyr6ieO_xa4tYtrfSyfK3O_M_4poOC8U2rGP14wngC_Uw7Nl0DGQAPNYUXHH3_Iar2-3EncjRwr3MsjwcendiipZGOUXB44Aff5wPBEaPZ1E8TGh0A_nsSRv4v4zPGp7XcY8n4lGoOn_erBzMf_7z9K_jeDj3t0CBIC0qDbepaG_czSfu2o2wTZotOqm3HMTyR8oTWwVpYZHxmGZ-3k-D_eQoiutkLqqYQ0-wkan8-FYjPhvFNvs_gU9-Tb33mQPAEpUyfJ88zCFCJtMQgnqTSBe69RgvBQ-_p8Uo1ldsZFLllfBYzvob-vzkbX7c01vvRo8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