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_coarse HLSL Function #99097

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

Implement the ddx_coarse HLSL Function #99097

farzonl opened this issue Jul 16, 2024 · 1 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.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

  • Implement ddx_coarse clang builtin,
  • Link ddx_coarse clang builtin with hlsl_intrinsics.h
  • Add sema checks for ddx_coarse to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for ddx_coarse to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/ddx_coarse.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/ddx_coarse-errors.hlsl
  • Create the int_dx_ddx_coarse intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_ddx_coarse to 83 in DXIL.td
  • Create the ddx_coarse.ll and ddx_coarse_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_ddx_coarse intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the ddx_coarse lowering and map it to int_spv_ddx_coarse in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/ddx_coarse.ll

DirectX

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

SPIR-V

OpDPdxCoarse:

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’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 x derivatives in fewer
unique locations than would be allowed for
OpDPdxFine.

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:
DerivativeControl

Word Count Opcode Results Operands

4

213

<id>
Result Type

Result <id>

<id>
P

Test Case(s)

Example 1

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

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

HLSL:

Computes a low precision partial derivative with respect to the screen-space x-coordinate.

Syntax

float ddx_coarse(
  in float value
);

Parameters

value [in]

Type: float

The input value.

Return value

Type: float

The low precision partial derivative of value.

Remarks

The following overloaded versions are also available:

float2 ddx_coarse(float2 value);
float3 ddx_coarse(float3 value);
float4 ddx_coarse(float4 value);

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 5 and higher shader models yes

 

This function is supported in the following types of shaders:

Vertex Hull Domain Geometry Pixel Compute
x

 

See also

Intrinsic Functions

Shader Model 5

@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
Copy link
Contributor

damyanp commented Oct 22, 2024

We should consider when implementing this microsoft/DirectXShaderCompiler#5744

@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
@davidcook-msft davidcook-msft moved this from Planning to Ready in HLSL Support Nov 12, 2024
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: Ready
Development

No branches or pull requests

2 participants