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 step HLSL Function #99157

Closed
9 tasks
Tracked by #99235 ...
farzonl opened this issue Jul 16, 2024 · 3 comments · Fixed by #106471
Closed
9 tasks
Tracked by #99235 ...

Implement the step HLSL Function #99157

farzonl opened this issue Jul 16, 2024 · 3 comments · Fixed by #106471
Assignees
Labels
backend:DirectX backend:SPIR-V bot:HLSL clang:codegen IR generation bugs: mangling, exceptions, etc. 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 step clang builtin,
  • Link step clang builtin with hlsl_intrinsics.h
  • Add sema checks for step to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for step to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/step.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/step-errors.hlsl
  • Create the int_spv_step intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the step lowering and map it to int_spv_step in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/step.ll

DirectX

There were no DXIL opcodes found for step.

SPIR-V

Step:

Description:

Step

Result is 0.0 if x < edge; otherwise result is 1.0.

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

48

<id>
edge

<id>
x

Test Case(s)

Example 1

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

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

HLSL:

Compares two values, returning 0 or 1 based on which value is greater.

ret step(y, x)

Parameters

Item Description
y
[in] The first floating-point value to compare.
x
[in] The second floating-point value to compare.

Return Value

1 if the x parameter is greater than or equal to the y parameter; otherwise, 0.

Remarks

This function uses the following formula: (x >= y) ? 1 : 0. The function returns either 0 or 1 depending on whether the x parameter is greater than the y parameter. To compute a smooth interpolation between 0 and 1, use the smoothstep HLSL intrinsic function.

Type Description

Name Template Type Component Type Size
y scalar, vector, or matrix float any
x same as input y float same dimension(s) as input y
ret same as input y float same dimension(s) as input y

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 and ps_1_4)

See also

Intrinsic Functions (DirectX HLSL)

@farzonl farzonl added 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
@farzonl
Copy link
Member Author

farzonl commented Jul 30, 2024

@damyanp Adding refinment priority. This is used in DirectML shader Lighting.fxh

@bob80905 bob80905 self-assigned this Aug 28, 2024
bob80905 added a commit that referenced this issue Sep 12, 2024
#106471)

This PR adds the step intrinsic and an HLSL function that uses it.
The SPIRV backend is also implemented.

Used #102683 as a reference.
Fixes #99157
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:codegen IR generation bugs: mangling, exceptions, etc. backend:DirectX labels Sep 12, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 12, 2024

@llvm/issue-subscribers-clang-codegen

Author: Farzon Lotfi (farzonl)

- [ ] Implement `step` clang builtin, - [ ] Link `step` clang builtin with `hlsl_intrinsics.h` - [ ] Add sema checks for `step` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp` - [ ] Add codegen for `step` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp` - [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/step.hlsl` - [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/step-errors.hlsl` - [ ] Create the `int_spv_step` intrinsic in `IntrinsicsSPIRV.td` - [ ] In SPIRVInstructionSelector.cpp create the `step` lowering and map it to `int_spv_step` in `SPIRVInstructionSelector::selectIntrinsic`. - [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/step.ll`

DirectX

There were no DXIL opcodes found for step.

SPIR-V

Step:

Description:

Step

Result is 0.0 if x &lt; edge; otherwise result is 1.0.

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>48</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>edge</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>x</em></p></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

Test Case(s)

Example 1

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

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

HLSL:

Compares two values, returning 0 or 1 based on which value is greater.

ret step(y, x)

Parameters

Item Description
<span id="y"></span><span id="Y"></span>y<br/> [in] The first floating-point value to compare.<br/>
<span id="x"></span><span id="X"></span>x<br/> [in] The second floating-point value to compare.<br/>

Return Value

1 if the x parameter is greater than or equal to the y parameter; otherwise, 0.

Remarks

This function uses the following formula: (x >= y) ? 1 : 0. The function returns either 0 or 1 depending on whether the x parameter is greater than the y parameter. To compute a smooth interpolation between 0 and 1, use the smoothstep HLSL intrinsic function.

Type Description

Name Template Type Component Type Size
y scalar, vector, or matrix float any
x same as input y float same dimension(s) as input y
ret same as input y float same dimension(s) as input y

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 and ps_1_4)

See also

<dl> <dt>

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

@llvmbot
Copy link
Member

llvmbot commented Sep 12, 2024

@llvm/issue-subscribers-clang-frontend

Author: Farzon Lotfi (farzonl)

- [ ] Implement `step` clang builtin, - [ ] Link `step` clang builtin with `hlsl_intrinsics.h` - [ ] Add sema checks for `step` to `CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp` - [ ] Add codegen for `step` to `EmitHLSLBuiltinExpr` in `CGBuiltin.cpp` - [ ] Add codegen tests to `clang/test/CodeGenHLSL/builtins/step.hlsl` - [ ] Add sema tests to `clang/test/SemaHLSL/BuiltIns/step-errors.hlsl` - [ ] Create the `int_spv_step` intrinsic in `IntrinsicsSPIRV.td` - [ ] In SPIRVInstructionSelector.cpp create the `step` lowering and map it to `int_spv_step` in `SPIRVInstructionSelector::selectIntrinsic`. - [ ] Create SPIR-V backend test case in `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/step.ll`

DirectX

There were no DXIL opcodes found for step.

SPIR-V

Step:

Description:

Step

Result is 0.0 if x &lt; edge; otherwise result is 1.0.

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>48</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>edge</em></p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>x</em></p></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

Test Case(s)

Example 1

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

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

HLSL:

Compares two values, returning 0 or 1 based on which value is greater.

ret step(y, x)

Parameters

Item Description
<span id="y"></span><span id="Y"></span>y<br/> [in] The first floating-point value to compare.<br/>
<span id="x"></span><span id="X"></span>x<br/> [in] The second floating-point value to compare.<br/>

Return Value

1 if the x parameter is greater than or equal to the y parameter; otherwise, 0.

Remarks

This function uses the following formula: (x >= y) ? 1 : 0. The function returns either 0 or 1 depending on whether the x parameter is greater than the y parameter. To compute a smooth interpolation between 0 and 1, use the smoothstep HLSL intrinsic function.

Type Description

Name Template Type Component Type Size
y scalar, vector, or matrix float any
x same as input y float same dimension(s) as input y
ret same as input y float same dimension(s) as input y

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 and ps_1_4)

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 IR generation bugs: mangling, exceptions, etc. 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