Skip to content

Implement the f32tof16 HLSL Function #99113

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

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

Implement the f32tof16 HLSL Function #99113

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 f32tof16 clang builtin,
  • Link f32tof16 clang builtin with hlsl_intrinsics.h
  • Add sema checks for f32tof16 to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for f32tof16 to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/f32tof16.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/f32tof16-errors.hlsl
  • Create the int_dx_f32tof16 intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_f32tof16 to 130 in DXIL.td
  • Create the f32tof16.ll and f32tof16_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_f32tof16 intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the f32tof16 lowering and map it to int_spv_f32tof16 in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/f32tof16.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
130 LegacyF32ToF16 6.0 ()

SPIR-V

PackHalf2x16:

Description:

PackHalf2x16

Result is the unsigned integer obtained by converting the components of
a two-component floating-point vector to the 16-bit OpTypeFloat, and
then packing these two 16-bit integers into a 32-bit unsigned integer.
The first vector component specifies the 16 least-significant bits of
the result; the second component specifies the 16 most-significant
bits.

The v operand must be a vector of 2 components whose type is a 32-bit
floating-point.

Result Type must be a 32-bit integer type.

Number Operand 1 Operand 2 Operand 3 Operand 4

58

<id>
v

Test Case(s)

Example 1

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

export uint4 fn(float4 p1) {
    return f32tof16(p1);
}

HLSL:

Converts an input into a float16 type.

Syntax

uint f32tof16(
  in float value
);

Parameters

value [in]

Type: float

The input value.

Return value

Type: uint

The converted value, stored in the low-half of the uint.

Remarks

The following overloaded versions are also available:

uint2 f32tof16(float2 value);
uint3 f32tof16(float3 value);
uint4 f32tof16(float4 value);

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 4 and higher shader models yes

 

Although this function is available in Shader Model 4 and higher shader models, because it is emulated in 4.0 and 4.1, it is less perfomant on these shader models than it is on Shader Model 5.

This function is supported in the following types of shaders:

Vertex Hull Domain Geometry Pixel Compute
x x x x x x

 

See also

Intrinsic Functions

Shader Model 5

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

farzonl commented Jul 30, 2024

@damyanp Adding refinment priority. This is used in DirectML shaders PixelPacking_Velocity.hlsli

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

No branches or pull requests

1 participant