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

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

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 89 | EvalCentroid | 6.0 | ('pixel',) |

## SPIR-V

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

## Test Case(s)

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

[numthreads(1, 1, 1)]
[shader("pixel")]
float4 fn(float4 p1 : COLOR ) : SV_Target {

        return EvaluateAttributeCentroid(p1);
}
```
## HLSL:

Evaluates at the pixel centroid.

## Syntax

``` syntax
numeric EvaluateAttributeCentroid(
  in attrib numeric value
);
```

## Parameters

<dl> <dt>

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

Type: **attrib numeric**

The input value.

</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/eJzMV19v6joS_zTmxQpKnAbCAw8QyrmV2u3RaffoviEnGYi3jh3ZTkv306_G-QOoLece7Wp1UQvO2J7f-Dd_POHWioMCWJJkTZLNhLeu0ma55-bfWslJrsv3ZUBJsqYk2dC7upFQg3KUzMLbVy5b7mDlnBF56yAD5YwWJZmFtJBcHWjeCumEIiwj4eqk5l6ol9_TQN-Eq3BLJa3cCeWMUFYUdlqRWXihe1WW1ELNaVFB8WLpXptfQjmNSzLc8Mf90_26w9y2qnBCq4xLiauEwlVPUHO_UqjDtGiaz_ALXcIB1G9g39bCnUHfHhtzgsy-9eJf4TmwzvYaPX2EbVFG2DbTJXwDhRiEbXtWLWHbL42bItVf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