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 saturate HLSL Function #99154

Closed
12 tasks
Tracked by #99235 ...
farzonl opened this issue Jul 16, 2024 · 2 comments · Fixed by #104619
Closed
12 tasks
Tracked by #99235 ...

Implement the saturate HLSL Function #99154

farzonl opened this issue Jul 16, 2024 · 2 comments · Fixed by #104619
Assignees
Labels
backend:DirectX backend:SPIR-V bot:HLSL clang:codegen clang:frontend Language frontend issues, e.g. anything involving "Sema" 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 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)

@llvmbot
Copy link
Member

llvmbot commented Aug 20, 2024

@llvm/issue-subscribers-clang-frontend

Author: Farzon Lotfi (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 &gt; 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.

<table>
<colgroup>
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
</colgroup>
<thead>
<tr>
<th>Number</th>
<th>Operand 1</th>
<th>Operand 2</th>
<th>Operand 3</th>
<th>Operand 4</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>43</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>x</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>minVal</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>maxVal</em></p></td>
<td></td>
</tr>
</tbody>
</table>

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
<span id="x"></span><span id="X"></span>x<br/> [in] The specified value.<br/>

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

<dl> <dt>

Intrinsic Functions (DirectX HLSL)
</dt> </dl>

@llvmbot
Copy link
Member

llvmbot commented Aug 20, 2024

@llvm/issue-subscribers-clang-codegen

Author: Farzon Lotfi (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 &gt; 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.

<table>
<colgroup>
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
<col style="width: 20%" />
</colgroup>
<thead>
<tr>
<th>Number</th>
<th>Operand 1</th>
<th>Operand 2</th>
<th>Operand 3</th>
<th>Operand 4</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p>43</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>x</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>minVal</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>maxVal</em></p></td>
<td></td>
</tr>
</tbody>
</table>

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
<span id="x"></span><span id="X"></span>x<br/> [in] The specified value.<br/>

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

<dl> <dt>

Intrinsic Functions (DirectX HLSL)
</dt> </dl>

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 clang:codegen clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants