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

    <tr>
        <th>Summary</th>
        <td>
            [HLSL] Implement derivative intrinsics
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:DirectX,
            HLSL
      </td>
    </tr>

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

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

<pre>
    Implement HLSL derivative intrinsics `ddx`, `ddx_fine`, `ddx_coarse`, `ddy` , `ddy_fine` and `ddy_coarse`.

https://godbolt.org/z/1Ej8514MY

The `ddx` and `ddy` intrinsic were initially introduced in Shader Model 2.1 for pixel shaders:
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-ddx
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-ddy

Shader Model 5.0 added `ddx_fine`, `ddx_coarse`, `ddy_fine` and `ddy_coarse`, also just for pixel shaders:
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/ddx-fine
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/ddx-coarse
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/ddy-fine
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/ddy-coarse

In DirectX the `ddx` and `ddy` functions default to coarse behavior - `ddx` is the same as `ddx_coarse` and `ddy` is the same as `ddy_coarse`.

In Shader model 6.6 the derivative intrinsics support was extended to compute, mesh and amplification shaders:
https://microsoft.github.io/DirectX-Specs/d3d/HLSL_SM_6_6_Derivatives.html


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8VU1zwyYQ_TXowkiDkKzYBx3SuJpmJjm5h_bkQbCySBBoAPmjv74DdvyRuun0kFxk78I-3ttdFuac3GiAGs1-QbNlwibfG1v38G48S1ojDvXzMCoYQHv828vqBQuwcsu83AKW2lupneQOo4oIsUcVQfTpZKw7qeHWww2z7sZ3QBXBF-sjBjMtPlznoAyRJSKPx2_v_ehQ8Yhog2izMaI1ymfGbhBt_kK0yX99m8_y8vXP66Dfe7gwvTojWGcxeAc2aJNeMqUOccGIiYPAUuNVzwRY_GoEKEyzHHfG4lHuQWEXlyKpOxQVMKuzQXJrnOl8xs2AaAM6nRyizU5qYXanfwVFtBHSAveF6JVTwdynG8vGXnKXBlcaRPzIMYfrDN7In2UEMyFA_K-Kf1njsI0pZ_Db5PyP5Vbs00jqe6BP4r4D_PB9vA83vI_fZ42Xcd8f2H9xlbpJcy-NdlhAxyblsTf4iIZb6NlWGovTq3DpIp5jA2Dm_tE7n2_qnd3_Niaezzd2iC1bZVUMvj_F3DSOxnq8Yw7D3oMOvR25D-PkITTnAK6PfNgwKtlJzoLS_-jPSxk20vdTm0mDaHNKZboagYdSiEIg2oQhu169rqt1tV6eWbqs94O6VpaIuhCLYsESqPOHvKC0qiqS9HUOHXRlWzJBO9q1vCCLKuddNWO0okWeJ7KmhJakzCtC8oeSZF3LFlVXtGxOeJ63gEoCA5MqU2o7hJmaSOcmqOfzOSWJYi0oFx8MSlvG30ELVDye1CBKEX1ClAYdwZgtE1sHoLSdNg6VREnn3QXaS6_i8xMDZkt8eW_uFimZrKo_Tf9jUo8tHoBPP-lozRtwj2gTBYQkRw1_BwAA__841D9J">