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

    <tr>
        <th>Summary</th>
        <td>
            Implement the `CheckAccessFullyMapped` 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 `CheckAccessFullyMapped` clang builtin,
- [ ] Link `CheckAccessFullyMapped` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `CheckAccessFullyMapped` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `CheckAccessFullyMapped` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/CheckAccessFullyMapped.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/CheckAccessFullyMapped-errors.hlsl`
- [ ] Create the `int_dx_CheckAccessFullyMapped` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_CheckAccessFullyMapped` to  `71` in `DXIL.td`
- [ ] Create the  `CheckAccessFullyMapped.ll` and `CheckAccessFullyMapped_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_CheckAccessFullyMapped` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `CheckAccessFullyMapped` lowering and map  it to `int_spv_CheckAccessFullyMapped` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/CheckAccessFullyMapped.ll`

## DirectX

| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 71 | CheckAccessFullyMapped | 6.0 | () |

## SPIR-V

# [OpImageSparseTexelsResident](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpImageSparseTexelsResident):

## Description:
  
Translates a *Resident Code* into a Boolean. Result is **false** if any
of the texels were in uncommitted texture memory, and **true**
otherwise.  
  
*Result Type* must be a [*Boolean type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Boolean) scalar.  
  
*Resident Code* is a value from an **OpImageSparse…​** instruction that
results in a resident code.

[Capability](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Capability):  
**SparseResidency**

<table>
<colgroup>
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
</colgroup>
<thead>
<tr>
<th>Word Count</th>
<th>Opcode</th>
<th>Results</th>
<th>Operands</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>4</p></td>
<td class="tableblock halign-left valign-top"><p>316</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Result Type</em></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#ResultId"><em>Result &lt;id&gt;</em></a></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>Resident Code</em></p></td>
</tr>
</tbody>
</table>



## Test Case(s)

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

RWBuffer<float4> g_buffer;

[numthreads(1, 1, 1)]
[shader("pixel")]
bool fn( ) : SV_Target {
        uint p1;
        float4 data = g_buffer.Load(0, p1);
        return CheckAccessFullyMapped(p1);
}
```
## HLSL:

Determines whether all values from a **Sample**, **Gather**, or **Load** operation accessed mapped tiles in a [tiled resource](/windows/desktop/direct3d11/direct3d-11-2-features).

## Syntax

``` syntax
bool CheckAccessFullyMapped(
  in uint_only status
);
```

## Parameters

<dl> <dt>

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

Type: **uint\_only**

The status value that is returned from a **Sample**, **Gather**, or **Load** operation. Because you can't access this status value directly, you need to pass it to **CheckAccessFullyMapped**.

</dd> </dl>

## Return value

Type: **bool**

Returns a **Boolean** value that indicates whether all values from a **Sample**, **Gather**, or **Load** operation accessed mapped tiles in a [tiled resource](/windows/desktop/direct3d11/direct3d-11-2-features). Returns **TRUE** if all values from the operation accessed mapped tiles; otherwise, returns **FALSE** if any values were taken from an unmapped tile.

## Remarks

### 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     | x       |



 

## See also

<dl> <dt>

[Intrinsic Functions](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/eJzcWVFz4ygS_jXkhbJKRpFjP_hBtuPZVGVutpLc7L6lsNS2uCBQAZrE9-uvGiRZmsTJ7N7OXd25XDE00N183dDdhFsrDgpgSdIVSTcXvHGlNss9N__USl7sdHFcTihJV5SkG3pT1RIqUI6SWbwuIX_K8hys3TZSHj_zuoaCzGKaS64OdNcI6YQibE3i7MTjVqinP7CcPgtX4vxSWvkolDNCWZHbqCSzeMQ4KwpqoeI0R86W7rV5X47T_fgvt_e3qyBw26jcCa3WXEqcJRTOuoeK-5lCHaK8rt8SnusCDqB-VPB1JdxA7vVLbU7y1p9a8kfCHFhnW44eOMK2SCNsu9YFfAKFMgjbtnhaHHhTswgRPgvqO3IQm1aIV_rmHSETMEYb-6astQHugLoSUIhQ7rF4eTyPYu8LL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