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

    <tr>
        <th>Summary</th>
        <td>
            Implement the `EvaluateAttributeAtSample` 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 `EvaluateAttributeAtSample` clang builtin,
- [ ] Link `EvaluateAttributeAtSample` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `EvaluateAttributeAtSample` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `EvaluateAttributeAtSample` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/EvaluateAttributeAtSample.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/EvaluateAttributeAtSample-errors.hlsl`
- [ ] Create the `int_dx_EvaluateAttributeAtSample` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_EvaluateAttributeAtSample` to  `88` in `DXIL.td`
- [ ] Create the  `EvaluateAttributeAtSample.ll` and `EvaluateAttributeAtSample_errors.ll` tests in `llvm/test/CodeGen/DirectX/`

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 88 | EvalSampleIndex | 6.0 | ('pixel',) |

## SPIR-V

There is no support for `EvaluateAttributeAtSample` when targeting SPIR-V.

## Test Case(s)

 
 ### Example 1
```hlsl
//dxc EvaluateAttributeAtSample_test.hlsl -T lib_6_8 -enable-16bit-types -O0

[numthreads(1, 1, 1)]
[shader("pixel")]
float4 fn(float4 p1 : COLOR ) : SV_Target {
        uint p2;
        return EvaluateAttributeAtSample(p1, p2);
}
```
## HLSL:

Evaluates at the indexed sample location.

## Syntax

``` syntax
numeric EvaluateAttributeAtSample(
  in attrib numeric value,
  in uint sampleindex
);
```

## Parameters

<dl> <dt>

*value* \[in\]
</dt> <dd>

Type: **attrib numeric**

The input value.

</dd> <dt>

*sampleindex* \[in\]
</dt> <dd>

Type: **uint**

The sample location.

</dd> </dl>

## Remarks

Interpolation mode can be **linear** or **linear\_no\_perspective** on the variable. Use of **centroid** or **sample** is ignored. Attributes with constant interpolation are also allowed, in which case the sample index is ignored.

### 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/eJzMV0Fv4zoO_jXKRXDgyHViH3JInWZegc52MO0O3q1QbCbWVpYMSW7T_fULSraTvLaZN5jFYoM2kWmKH_WRIiVurdgrgCVJr0m6nvDO1dosd9z8Wys52erqbRlRkl5Tkq7pbdNKaEA5SubxzQuXHXewcs6IbYeDB44KZB7TUnK1p9tOSCcUYQWJV0czd0I9_5oF-ipcjVNqaeWTUM4IZUVppzWZx2e2V1VFLTScljWUz5butPkplNOoUuCEP-4e7q4D5qZTpRNaFVxK1BIKtR6g4V5TqP20bNuP8EtdwR7UL2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