Skip to content

Implement the fwidth HLSL Function #99120

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
12 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 0 comments
Open
12 tasks
Tracked by #99235

Implement the fwidth HLSL Function #99120

farzonl opened this issue Jul 16, 2024 · 0 comments
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

  • Implement fwidth clang builtin,
  • Link fwidth clang builtin with hlsl_intrinsics.h
  • Add sema checks for fwidth to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for fwidth to EmitHLSLBuiltinExpr in CGBuiltin.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_fwidth intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_fwidth to 83 in DXIL.td
  • Create the fwidth.ll and fwidth_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_fwidth intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the fwidth lowering and map it to int_spv_fwidth in SPIRVInstructionSelector::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 Type

Result <id>

<id>
P

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

Intrinsic Functions (DirectX HLSL)

@farzonl farzonl added backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues. labels Jul 16, 2024
@damyanp damyanp moved this to Ready in HLSL Support Oct 30, 2024
@damyanp damyanp moved this from Ready to Planning in HLSL Support Oct 30, 2024
@pow2clk pow2clk moved this from Planning to Designing in HLSL Support Nov 19, 2024
@damyanp damyanp removed the status in HLSL Support Apr 25, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
backend:DirectX backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: No status
Development

No branches or pull requests

1 participant