Skip to content

Implement the asfloat HLSL Function #70098

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
3 tasks
Tracked by #99235 ...
llvm-beanz opened this issue Oct 24, 2023 · 3 comments · Fixed by #108686
Closed
3 tasks
Tracked by #99235 ...

Implement the asfloat HLSL Function #70098

llvm-beanz opened this issue Oct 24, 2023 · 3 comments · Fixed by #108686
Assignees
Labels

Comments

@llvm-beanz
Copy link
Collaborator

llvm-beanz commented Oct 24, 2023

  • Link asfloat clang builtin (__builtin_bit_cast) with `hlsl_intrinsics.h``
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/asfloat.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/asfloat-errors.hlsl

DirectX

There were no DXIL opcodes found for asfloat.

SPIR-V

Description:

Test Case(s)

Example 1

//dxc asfloat_test.hlsl -T lib_6_8  -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0

export float4 fn(float p1) {
    return asfloat(p1);
}

Example 2

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

export float4 fn(uint p1) {
    return asfloat(p1);
}

Example 3

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

export float4 fn(int p1) {
    return asfloat(p1);
}

HLSL:

Interprets the bit pattern of x as a floating-point number.

ret asfloat(x)

Parameters

Item Description
x
[in] The input value.

Return Value

The input interpreted as a floating-point number.

Type Description

Name Template Type Component Type Size
x scalar, vector, or matrix float, int, uint any
ret same as input x float same dimension(s) as input x

Function Overloads

`float<x> asfloat(float<x> value);` `float<x> asfloat(int<x> value);` `float<x> asfloat(uint<x> value);`

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 4 and higher shader models yes
Shader Model 3 (DirectX HLSL) no
Shader Model 2 (DirectX HLSL) no
Shader Model 1 (DirectX HLSL) no

Remarks

Older compilers incorrectly allowed asfloat(bool), but note that bool inputs are not supported.

See also

Intrinsic Functions (DirectX HLSL)

@llvm-beanz llvm-beanz converted this from a draft issue Oct 24, 2023
@llvm-beanz llvm-beanz added the HLSL HLSL Language Support label Oct 24, 2023
@farzonl farzonl changed the title [HLSL] implement asfloat intrinsic Implement the asfloat HLSL Function Jul 16, 2024
@farzonl
Copy link
Member

farzonl commented Jul 30, 2024

@damyanp This one is already refined, but we should prioritize getting it assigned out. This is used in DirectML shader PixelPacking_Velocity.hlsli:28 and PixelPacking_Velocity.hlsli:41

@joaosaffran
Copy link
Contributor

I can work on this

@joaosaffran
Copy link
Contributor

This is currently awaiting changes on #107292 to be merged, such is introducing bit_cast implementation for HLSL, which is required for this changes.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

3 participants