Skip to content

Implement the saturate HLSL Function #99154

Closed
Listed in 2 issues
Closed
@farzonl

Description

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

DirectX

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

SPIR-V

FClamp:

Description:

FClamp

Result is min(max(x, minVal), maxVal). Result is undefined if
minVal > maxVal.The semantics used by min() and max() are those of
FMin and FMax.

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

43

<id>
x

<id>
minVal

<id>
maxVal

Test Case(s)

Example 1

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

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

HLSL:

Clamps the specified value within the range of 0 to 1.

ret saturate(x)

Parameters

Item Description
x
[in] The specified value.

Return Value

The x parameter, clamped within the range of 0 to 1.

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 1 (DirectX HLSL) and higher shader models yes

See also

Intrinsic Functions (DirectX HLSL)

Metadata

Metadata

Assignees

Labels

HLSLHLSL Language Supportbackend:DirectXbackend:SPIR-Vbot:HLSLclang:codegenIR generation bugs: mangling, exceptions, etc.clang:frontendLanguage frontend issues, e.g. anything involving "Sema"metaissueIssue to collect references to a group of similar or related issues.

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @farzonl@EugeneZelenko@bharadwajy@llvmbot

    Issue actions

      Implement the `saturate` HLSL Function · Issue #99154 · llvm/llvm-project