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 smoothstep HLSL Function #99156

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

Implement the smoothstep HLSL Function #99156

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

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
7 Saturate 6.0 ()

SPIR-V

SmoothStep:

Description:

SmoothStep

Result is 0.0 if xedge0 and 1.0 if xedge1 and performs
smooth Hermite interpolation between 0 and 1 when edge0 < x <
edge1. This is equivalent to:

t * t * (3 - 2 * t), where t = clamp ((x - edge0) /
(edge1 - edge0), 0, 1)

Result is undefined if edge0edge1.

The operands must all be a scalar or vector whose component type is
floating-point.

Result Type and the type of all operands must be the same type.
Results are computed per component.

Number Operand 1 Operand 2 Operand 3 Operand 4

49

<id>
edge0

<id>
edge1

<id>
x

Test Case(s)

Example 1

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

export float4 fn(float4 p1, float4 p2, float4 p3) {
    return smoothstep(p1, p2, p3);
}

HLSL:

Returns a smooth Hermite interpolation between 0 and 1, if x is in the range [min, max].

ret smoothstep(min, max, x)

Parameters

Item Description
min
[in] The minimum range of the x parameter.
max
[in] The maximum range of the x parameter.
x
[in] The specified value to be interpolated.

Return Value

Returns 0 if x is less than min; 1 if x is greater than max; otherwise, a value between 0 and 1 if x is in the range [min, max].

Remarks

Use the smoothstep HLSL intrinsic function to create a smooth transition between two values. For example, you can use this function to blend two colors smoothly.

Type Description

Name Template Type Component Type Size
x scalar, vector, or matrix float any
min same as input x float same dimension(s) as input x
max same as input x float same dimension(s) as input x
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 2 (DirectX HLSL) and higher shader models yes
Shader Model 1 (DirectX HLSL) yes (vs_1_1 only)

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