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

    <tr>
        <th>Summary</th>
        <td>
            [HLSL] Introduce builtins to index into HLSLResource types
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            HLSL
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          bogner
      </td>
    </tr>
</table>

<pre>
    We need a builtin in clang that can operate on HLSLResource builtin types to index into them. There are two approaches to this:

1. Have `__builtin_hlsl_resource_index(resource_t x)` return a pointer to the underlying type, which we then load and store directly
2. Have `__builtin_hlsl_resource_index(resource_t x)` return another `resource_t`, and introduce `__builtin_hlsl_resource_load` and `__builtin_hlsl_resource_store` as well.

Option (1) is probably sufficient and simpler for the `dx.RawBuffer` types (StructuredBuffers and ByteAddressBuffers), but it may be harder to form the right operations for `dx.TypedBuffer` and `dx.CBuffer` types. Option (2) is more complex and should be used if option (1) is found to be untenable.

AC:
- These builtins are available and lower to DXIL intrinsics during clang codegen
- Array subscript operators for HLSL resource types can be implemented using these builtins
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVEuL4zgQ_jXypRhjK7E7PvjQD8IMNCzMDOzegmSVYy2yZKRSJ_73i-R0enoX5rSXBKyq-h71ECHos0XsWfPEmpdCRJqc76U7W_SFdGrt_0SwiAoEyKgNaQvawmCEPQNNgmAQFtyCXhCCs_D19cfrdwwu-gHvGbQuGIAcaKvwCtqSA5pwLuHnhB5BeAS6OBDL4p0Ypi2YJh3Y7pFVL6y6_dYlfBVvCKytTqdb9dNkgjn5G-YpQzB-uH8guDLesbYCjxS9BQGL05bQbyAI0Sr0ZtVJ0rog489wmfQwwQXTuwXjhAJhFQRyHkFpjwOZdePE_xdO1tGEPhX5CGJtlbgkYG3JOxWH38IkmqlmSvhNWBaR4wJc0JjyV4f_WEg7C4wfasY70AEW76SQZoUQx1EPGi1tXuh5MehhdD67yNpKXcvv4vIUxxF9Atj6zvjhB_k4UPSotseQKzythI9KeQzh9jmZwp9BRgJNMIsVJMIkvNqaNTo_ZyyvzxPdxk47GzKJjcDPdXlH-cULdS2f_8WrhA-t_KZ1Tu0dXBJ23UROLhqVWMSACvQI7j8GjS5aleilKEtohTT4ydTH5_scf0kjH-6rEfLsizehTcrKmMZdNrkvf317zZ3XNughgIo-zei2fINTeEb7XvXRe5FaJMPg9fLujfObNWkr4X0Abm1JiysRchdntIQKYsg78Ilgofqd6nadKLCvH-rDA-8e9nUx9ZLvuKgqOdSjqrAaxb7h40G2TSUHzltV6J5XfF-19aFum2Zfl-JBtOOuqttD23S8k2xf4Sy0KY15m0vnz4UOIWLfNV3TFkZINCFfJs6TAMZ5ulG-T-FfZDwHtq-MDhQ-CpAmk69ZTmhe4Nt9ce6Of75Dnw5WdqaI3vQT0ZKvDz8yfjxrmqIsBzczfkxgt78vi3d_40CMHzP1wPhxY__W838CAAD__ypl0jc">