Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Implement the ddx HLSL Function #99096

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

Implement the ddx HLSL Function #99096

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 ddx clang builtin,
  • Link ddx clang builtin with hlsl_intrinsics.h
  • Add sema checks for ddx to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for ddx to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/ddx.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/ddx-errors.hlsl
  • Create the int_dx_ddx intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_ddx to 83 in DXIL.td
  • Create the ddx.ll and ddx_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_ddx intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the ddx lowering and map it to int_spv_ddx in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/ddx.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
83 DerivCoarseX 6.0 ('library', 'pixel', 'compute', 'amplification', 'mesh', 'node')

SPIR-V

OpDPdx:

Description:

Same result as either OpDPdxFine or
OpDPdxCoarse on P. Selection of which one is
based on external factors.

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

207

<id>
Result Type

Result <id>

<id>
P

Test Case(s)

Example 1

//dxc ddx_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export float4 fn(float4 p1) {
    return ddx(p1);
}

HLSL:

Returns the partial derivative of the specified value with respect to the screen-space x-coordinate.

ret ddx(x)

This function computes the partial derivative with respect to the screen-space x-coordinate. To compute the partial derivative with respect to the screen-space y-coordinate, use the ddy function.

This function is only supported in pixel shaders.

Parameters

Item Description
x
[in] The specified value.

Return Value

The partial derivative 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 5 and higher shader models yes
Shader Model 4 yes
Shader Model 3 (DirectX HLSL) yes
Shader Model 2 (DirectX HLSL) yes in ps_2_x; unsupported in ps_2_0.
Shader Model 1 (DirectX HLSL) no

This function is supported in the following types of shaders:

Vertex Hull Domain Geometry Pixel Compute
x

See also

Intrinsic Functions (DirectX HLSL)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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