Skip to content

Implement the modf HLSL Function #99136

@farzonl

Description

@farzonl
  • 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)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions