<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/99100>99100</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Implement the `ddy_coarse` 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 `ddy_coarse` clang builtin,
- [ ] Link `ddy_coarse` clang builtin with `hlsl_intrinsics.h`
- [ ] Add sema checks for `ddy_coarse` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [ ] Add codegen for `ddy_coarse` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp`
- [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/ddy_coarse.hlsl`
- [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/ddy_coarse-errors.hlsl`
- [ ] Create the `int_dx_ddy_coarse` intrinsic in `IntrinsicsDirectX.td`
- [ ] Create the `DXILOpMapping` of `int_dx_ddy_coarse` to `84` in `DXIL.td`
- [ ] Create the `ddy_coarse.ll` and `ddy_coarse_errors.ll` tests in `llvm/test/CodeGen/DirectX/`
- [ ] Create the `int_spv_ddy_coarse` intrinsic in `IntrinsicsSPIRV.td`
- [ ] In SPIRVInstructionSelector.cpp create the `ddy_coarse` lowering and map it to `int_spv_ddy_coarse` in `SPIRVInstructionSelector::selectIntrinsic`.
- [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/ddy_coarse.ll`
## DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
| ----------- | ----------- | ------------ | ------------- |
| 84 | DerivCoarseY | 6.0 | ('library', 'pixel', 'compute', 'amplification', 'mesh', 'node') |
## SPIR-V
# [OpDPdyCoarse](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpDPdyCoarse):
## Description:
Result is the partial derivative of *P* with respect to the window *y*
coordinate. Uses local differencing based on the value of *P* for the
current fragment’s neighbors, and possibly, but not necessarily,
includes the value of *P* for the current fragment. That is, over a
given area, the implementation can compute *y* derivatives in fewer
unique locations than would be allowed for
[**OpDPdyFine**](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpDPdyFine).
*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>214</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 ddy_coarse_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export float4 fn(float4 p1) {
return ddy_coarse(p1);
}
```
## HLSL:
Computes a low precision partial derivative with respect to the screen-space y-coordinate.
## Syntax
``` syntax
float ddy_coarse(
in float value
);
```
## Parameters
<dl> <dt>
*value* \[in\]
</dt> <dd>
Type: **float**
The input value.
</dd> </dl>
## Return value
Type: **float**
The low precision partial derivative of *value*.
## Remarks
The following overloaded versions are also available:
``` syntax
float2 ddy_coarse(float2 value);
float3 ddy_coarse(float3 value);
float4 ddy_coarse(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/eJzUWV1z4jrS_jXKjcqUkYHABRcEwpxUzbyTmsw7e_YqJVsNaCNLXkkmsL9-qyVj7IQks7tn9iM1NbFarf54utVqKdw5udUAczK-IePVFa_9ztj5htu_Ga2uciOO84SS8Q0l4xW9KysFJWhPySQV4vhYGG4dkElKC8X1lua1VF5qwpYkXZzXfZb66YMl9Fn6HfLslFOPUnsrtZOFG-zIJO0JWwhBHZScFjsonhzdGPtatjdIWyLHb58fPt9EJetaF14aveRKIZfUyPUAJQ-cUm8HRVVdUlgYAVvQ7ym7LaXv6Lo9VPasY_mpIX-kwIPzrpEYACJsjTTC1ksj4BNo1EHYusHNEbY-WzNA9N4E7B3ZiEEjOBh690JwAtYa6y7KX1rgHqjfAQqW2j-Kw2MfoTaeDRx3bXxX0kLhfx948b7Y1e93n79WX3hVSb1FkWbzpjZvKM5NR2f8cfn7OvphHcQE4Vr06Y8NDnE6Aho1KLUvX8WKsHXjIGHrj3Fz1f6ngXu4v_v244JL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