Skip to content

Implement the degrees HLSL Function #99104

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

Closed
9 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 2 comments · Fixed by #111209
Closed
9 tasks
Tracked by #99235

Implement the degrees HLSL Function #99104

farzonl opened this issue Jul 16, 2024 · 2 comments · Fixed by #111209
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 degrees clang builtin,
  • Link degrees clang builtin with hlsl_intrinsics.h
  • Add sema checks for degrees to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for degrees to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/degrees.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/degrees-errors.hlsl
  • Create the int_spv_degrees intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the degrees lowering and map it to int_spv_degrees in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/degrees.ll

DirectX

There were no DXIL opcodes found for degrees.

SPIR-V

Degrees:

Description:

Degrees

Converts radians to degrees, i.e., radians * 180 / π.

The operand radians must be a scalar or vector whose component type is
16-bit or 32-bit floating-point.

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

Number Operand 1 Operand 2 Operand 3 Operand 4

12

<id>
radians

Test Case(s)

Example 1

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

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

HLSL:

Converts the specified value from radians to degrees.

ret degrees(x)

Parameters

Item Description
x
[in] The specified value.

Return Value

The result of converting the x parameter from radians to degrees.

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

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
@inbelic inbelic self-assigned this Sep 27, 2024
@damyanp damyanp moved this to Active in HLSL Support Oct 9, 2024
@damyanp damyanp moved this from Active to Reviewing in HLSL Support Oct 10, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:codegen IR generation bugs: mangling, exceptions, etc. backend:DirectX labels Oct 10, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2024

@llvm/issue-subscribers-clang-codegen

Author: Farzon Lotfi (farzonl)

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

DirectX

There were no DXIL opcodes found for degrees.

SPIR-V

Degrees:

Description:

Degrees

Converts radians to degrees, i.e., radians * 180 / π.

The operand radians must be a scalar or vector whose component type is
16-bit or 32-bit floating-point.

Result Type and the type of radians 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>12</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>radians</em></p></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

Test Case(s)

Example 1

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

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

HLSL:

Converts the specified value from radians to degrees.

ret degrees(x)

Parameters

Item Description
<span id="x"></span><span id="X"></span>x<br/> [in] The specified value.<br/>

Return Value

The result of converting the x parameter from radians to degrees.

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

See also

<dl> <dt>

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

@llvmbot
Copy link
Member

llvmbot commented Oct 10, 2024

@llvm/issue-subscribers-clang-frontend

Author: Farzon Lotfi (farzonl)

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

DirectX

There were no DXIL opcodes found for degrees.

SPIR-V

Degrees:

Description:

Degrees

Converts radians to degrees, i.e., radians * 180 / π.

The operand radians must be a scalar or vector whose component type is
16-bit or 32-bit floating-point.

Result Type and the type of radians 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>12</p></td>
<td
class="tableblock halign-left valign-top"><p><em>&lt;id&gt;</em><br />
<em>radians</em></p></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>

Test Case(s)

Example 1

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

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

HLSL:

Converts the specified value from radians to degrees.

ret degrees(x)

Parameters

Item Description
<span id="x"></span><span id="X"></span>x<br/> [in] The specified value.<br/>

Return Value

The result of converting the x parameter from radians to degrees.

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

See also

<dl> <dt>

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

DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this issue Oct 16, 2024
- add degrees builtin
    - link degrees api in hlsl_intrinsics.h
    - add degrees intrinsic to IntrinsicsDirectX.td
    - add degrees intrinsic to IntrinsicsSPIRV.td
- add lowering from clang builtin to dx/spv intrinsics in CGBuiltin.cpp
    - add semantic checks to SemaHLSL.cpp
- add expansion of directx intrinsic to llvm fmul for DirectX in
DXILIntrinsicExpansion.cpp
    - add mapping to spir-v intrinsic in SPIRVInstructionSelector.cpp

    - add test coverage:
- degrees.hlsl -> check hlsl lowering to dx/spv degrees intrinsics
- degrees-errors.hlsl/half-float-only-errors -> check semantic warnings
- hlsl-intrinsics/degrees.ll -> check lowering of spir-v degrees
intrinsic to SPIR-V backend
- DirectX/degrees.ll -> check expansion and scalarization of directx
degrees intrinsic to fmul
      
Resolves llvm#99104
@damyanp damyanp removed the status in HLSL Support Oct 22, 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 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