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 f16tof32 HLSL Function #99112

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

Implement the f16tof32 HLSL Function #99112

farzonl opened this issue Jul 16, 2024 · 0 comments
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 f16tof32 clang builtin,
  • Link f16tof32 clang builtin with hlsl_intrinsics.h
  • Add sema checks for f16tof32 to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for f16tof32 to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/f16tof32.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/f16tof32-errors.hlsl
  • Create the int_dx_f16tof32 intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_f16tof32 to 131 in DXIL.td
  • Create the f16tof32.ll and f16tof32_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_f16tof32 intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the f16tof32 lowering and map it to int_spv_f16tof32 in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/f16tof32.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
131 LegacyF16ToF32 6.0 ()

SPIR-V

UnpackHalf2x16:

Description:

UnpackHalf2x16

Result is the two-component floating-point vector with components
obtained by unpacking a 32-bit unsigned integer into a pair of 16-bit
values, interpreting those values as 16-bit floating-point numbers
according to the OpenGL Specification, and converting them to 32-bit
floating-point values. Subnormal numbers are either preserved or flushed
to zero, consistently within an implemenation.

The first component of the vector is obtained from the 16
least-significant bits of v; the second component is obtained from the
16 most-significant bits of v.

The v operand must be a scalar with 32-bit integer type.

Result Type must be a vector of 2 components whose type is 32-bit
floating point.

Number Operand 1 Operand 2 Operand 3 Operand 4

62

<id>
v

Test Case(s)

Example 1

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

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

HLSL:

Converts the float16 stored in the low-half of the uint to a float.

Syntax

float f16tof32(
  in uint value
);

Parameters

value [in]

Type: uint

The input value.

Return value

Type: float

The converted value.

Remarks

The following overloaded versions are also available:

float2 f16tof32(uint2 value);
float3 f16tof32(uint3 value);
float4 f16tof32(uint4 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
@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
@davidcook-msft davidcook-msft moved this from Planning to Ready in HLSL Support Nov 12, 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 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