Implement the `fwidth` HLSL Function
- [ ] Implement
fwidthclang builtin, - [ ] Link
fwidthclang builtin withhlsl_intrinsics.h - [ ] Add sema checks for
fwidthtoCheckHLSLBuiltinFunctionCallinSemaChecking.cpp - [ ] Add codegen for
fwidthtoEmitHLSLBuiltinExprinCGBuiltin.cpp - [ ] Add codegen tests to
clang/test/CodeGenHLSL/builtins/fwidth.hlsl - [ ] Add sema tests to
clang/test/SemaHLSL/BuiltIns/fwidth-errors.hlsl - [ ] Create the
int_dx_fwidthintrinsic inIntrinsicsDirectX.td - [ ] Create the
DXILOpMappingofint_dx_fwidthto83inDXIL.td - [ ] Create the
fwidth.llandfwidth_errors.lltests inllvm/test/CodeGen/DirectX/ - [ ] Create the
int_spv_fwidthintrinsic inIntrinsicsSPIRV.td - [ ] In SPIRVInstructionSelector.cpp create the
fwidthlowering and map it toint_spv_fwidthinSPIRVInstructionSelector::selectIntrinsic. - [ ] Create SPIR-V backend test case in
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fwidth.ll
DirectX
| DXIL Opcode | DXIL OpName | Shader Model | Shader Stages |
|---|---|---|---|
| 83 | DerivCoarseX | 6.0 | ('library', 'pixel', 'compute', 'amplification', 'mesh', 'node') |
SPIR-V
OpFwidth:
Description:
Result is the same as computing the sum of the absolute values of OpDPdx and OpDPdy on P.
Result Type must be a scalar or vector of floating-point type 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.
Capability:
Shader
| Word Count | Opcode | Results | Operands | |
|---|---|---|---|---|
4 |
209 |
<id> |
Result <id> |
<id> |
Test Case(s)
Example 1
//dxc fwidth_test.hlsl -T lib_6_8 -enable-16bit-types -O0
export float4 fn(float4 p1) {
return fwidth(p1);
}
HLSL:
Returns the absolute value of the partial derivatives of the specified value.
| ret fwidth(x) |
|---|
This function computes the following: abs(ddx(x)) + abs(ddy(x)).
This function is only supported in pixel shaders.
Parameters
| Item | Description |
|---|---|
| x |
[in] The specified value. |
Return Value
The absolute value of the partial derivatives of the x parameter.
Type Description
| Name | Template Type | Component Type | Size |
|---|---|---|---|
| x | scalar, vector, or matrix | float | any |
| ret | same as input x | float | same dimension(s) as input x |
Minimum Shader Model
This function is supported in the following shader models.
| Shader Model | Supported |
|---|---|
| Shader Model 3 (DirectX HLSL) and higher shader models | yes |
| Shader Model 2 (DirectX HLSL) | yes (ps_2_x only) |
| Shader Model 1 (DirectX HLSL) | no |
See also
I can pick this up. I don't have permissions to assign myself.