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 modf HLSL Function #99136

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

Implement the modf HLSL Function #99136

farzonl opened this issue Jul 16, 2024 · 1 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.

Comments

@farzonl
Copy link
Member

farzonl commented Jul 16, 2024

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

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
29 Round_z 6.0 ()

SPIR-V

ModfStruct:

Description:

ModfStruct

Same semantics as in Modf, except that the entire result is in the
instruction’s result; there is not a pointer operand to write through.

Result Type must be an OpTypeStruct with two members. Member 0
holds the fractional part. Member 1 holds the whole number part. These
two members, and the Result Type must all have the same type. This
structure type must be explicitly declared by the module.

Number Operand 1 Operand 2 Operand 3 Operand 4

36

<id>
x

Test Case(s)

Example 1

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

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

HLSL:

Splits the value x into fractional and integer parts, each of which has the same sign as x.

ret modf(x, out ip)

Parameters

Item Description
x
[in] The x input value.
ip
[out] The integer portion of x.

Return Value

The signed-fractional portion of x.

Type Description

Name In/Out Template Type Component Type Size
x in scalar, vector, or matrix float, int any
ip out same as input x float, int same dimension(s) as input x
ret out same as input x float, int 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)

Requirements

Requirement Value
Header
Corecrt_math.h

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
@damyanp damyanp moved this to Ready in HLSL Support Oct 30, 2024
@damyanp damyanp moved this from Ready to Planning in HLSL Support Oct 30, 2024
@pow2clk pow2clk moved this from Planning to Designing in HLSL Support Nov 19, 2024
@pow2clk
Copy link
Contributor

pow2clk commented Nov 19, 2024

Expanded on DXIL. Op on SPIRV

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: Designing
Development

No branches or pull requests

2 participants