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

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

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 76 | RenderTargetGetSamplePosition | 6.0 | ('pixel',) |

## SPIR-V

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

## Test Case(s)

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

[numthreads(1, 1, 1)]
[shader("pixel")]
float2 fn( ) : SV_Target {
        int p1;
        return GetRenderTargetSamplePosition(p1);
}
```
## HLSL:

Gets the sampling position (x,y) for a given sample index.

float<2> GetRenderTargetSamplePosition( in int<1> Index<br/>);



 

## Parameters



| Item | Description |
|--------------------------------------------------------------------------------------------|----------------------------------------------|
| <span id="Index"></span><span id="index"></span><span id="INDEX"></span>*Index*<br/> | \[in\] A zero-based sample index.<br/> |



 

## Return Value

The (x,y) position of the given sample.

## Remarks

Use this function and [**GetRenderTargetSampleCount**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-getrendertargetsamplecount.md) to find out the number and position of the sampling locations for a render target.

## Minimum Shader Model

This function is supported in the following shader models.



| Shader Model | Supported |
|---------------------------------------------------------------------|-----------|
| [Shader Model 4](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm4.md) and higher shader models | yes       |
| [Shader Model 3 (DirectX HLSL)](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm3.md) | no        |
| [Shader Model 2 (DirectX HLSL)](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm2.md) | no        |
| [Shader Model 1 (DirectX HLSL)](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-sm1.md) | no        |



 

## See also

<dl> <dt>

[**Intrinsic Functions (DirectX HLSL)**](https://github.com/MicrosoftDocs/win32/blob/docs/desktop-src//direct3dhlsl/dx-graphics-hlsl-intrinsic-functions.md)
</dt> </dl>
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWEtv2zgQ_jX0hZBhUZEtH3yw5ThrIGmLOlv0FlDSWOJGIgWSapL--sWQ8itN7QbYRWuodTQznMc3D5LmxohSAsxIvCDxcsA7Wyk923L9Xcl6kKniZRZQEi8oiZd03bQ1NCAtJePRDdjPIAvQ91y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