<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99098>99098</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `ddx_fine` 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 `ddx_fine` clang builtin,
- [ ] Link `ddx_fine` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `ddx_fine` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `ddx_fine` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/ddx_fine.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/ddx_fine-errors.hlsl`
- [ ] Create the `int_dx_ddx_fine` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_ddx_fine` to `85` in `DXIL.td`
- [ ] Create the `ddx_fine.ll` and `ddx_fine_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_ddx_fine` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `ddx_fine` lowering and map it to `int_spv_ddx_fine` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/ddx_fine.ll`
## DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 85 | DerivFineX | 6.0 | ('library', 'pixel', 'compute', 'amplification', 'mesh', 'node') |
## SPIR-V
# [OpDPdxFine](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpDPdxFine):
## Description:
Result is the partial derivative of *P* with respect to the window *x*
coordinate.Uses local differencing based on the value of *P* for the
current fragment and its immediate neighbor(s).
*Result Type* must be a scalar or vector of [*floating-point
type*](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Floating) using the IEEE 754 encoding. The component width must
be 32 bits.
The type of *P* must be the same as *Result Type*. *P* is the value to
take the derivative of.
This instruction is only valid in the **Fragment** [Execution
Model](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Execution_Model).
[Capability](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Capability):
**DerivativeControl**
<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>210</p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>Result Type</em></p></td>
<td class="tableblock halign-left valign-top"><p><a
href="#ResultId"><em>Result <id></em></a></p></td>
<td
class="tableblock halign-left valign-top"><p><em><id></em><br />
<em>P</em></p></td>
</tr>
</tbody>
</table>
## Test Case(s)
### Example 1
```hlsl
//dxc ddx_fine_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export float4 fn(float4 p1) {
return ddx_fine(p1);
}
```
## HLSL:
Computes a high precision partial derivative with respect to the screen-space x-coordinate.
## Syntax
``` syntax
float ddx_fine(
in float value
);
```
## Parameters
<dl> <dt>
*value* \[in\]
</dt> <dd>
Type: **float**
The input value.
</dd> </dl>
## Return value
Type: **float**
The high precision partial derivative of *value*.
## Remarks
The following overloaded versions are also available:
``` syntax
float2 ddx_fine(float2 value);
float3 ddx_fine(float3 value);
float4 ddx_fine(float4 value);
```
### 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/eJzUWVtz4yry_zTkhZJLRvHtwQ-OHZ-Tqpn_pE7mPztvKSTaFhsEKkCJs59-q0GWpbGTzO6e2YsrFYum-fWVppG5c3KvAZZkckMmmyve-NLY5Y7bvxmtrnIjXpcJJZMbSiYbelfVCirQnpJpKsThcSc1kGlKC8X1nuaNVF5qwtYkXZ1WfZL66d0F9EX6EjlK5dSj1N5K7WThRiWZpgOolRDUQcVpUULx5OjO2B-RvUHKGud___Tw6SaK2Da68NLoNVcKuaRGrgeoeOCUej8q6vqSuMII2IN-W9RtJX1P0u2hticJ699a8kfwHpx3LWJwDmFbpBG2XRsBv4FGGYRtW585wrZHXUbotzdd9Q4y2t_CBjXvBrAJWGusu4i-tsA9UF8CwkrtH8Xhse-bLoqtI-66qG6khcJ_H3nxPujm-92nL_VnXtdS7xHS7N6Q5Q3Fmfnk5Hdc_L6EfjBHMSm4Fn3qY2t_nIxujOhKPVdn8SFs25pG2PZjf7n6-Scd9nB_98e3C8bcaRqm7rTztgnp_QAKCm8sZhstBjL7spR5ASv1Plhc8ZpS6dsMuaxa2CxvyCLZimQrF0ad0mSaji45AEGSbzTnxRNoEZxKC-7gA8cG2YRtMRWTU4Ho7wHV5ij-sYywjB6jEWmzNcWkoF9q3HK0N_4_X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