Skip to content

Implement the asuint16 HLSL Function #99185

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

Closed
4 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 1 comment · Fixed by #132315
Closed
4 tasks
Tracked by #99235

Implement the asuint16 HLSL Function #99185

farzonl opened this issue Jul 16, 2024 · 1 comment · Fixed by #132315
Assignees
Labels
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 a uint16 bit cast using __detail::bit_cast in clang/lib/Headers/hlsl/hlsl_intrinsics.h use asuint as template.
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/asuint16.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/asuint16-errors.hlsl
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/asuint16.ll confirm using OpBitcast

DirectX

There were no DXIL opcodes found for asuint16.

SPIR-V

OpBitcast:

Description:

Bit pattern-preserving type conversion.

Result Type must be an OpTypePointer, or a
scalar or vector of numerical-type.

Operand must have a type of OpTypePointer, or a
scalar or vector of numerical-type. It must be a
different type than Result Type.

Before version 1.5: If either Result Type or Operand is a
pointer, the other must be a pointer or an integer scalar.
Starting with version 1.5: If either Result Type or Operand is a
pointer, the other must be a pointer, an integer scalar, or an integer
vector.

If both Result Type and the type of Operand are pointers, they both
must point into same storage class.

Behavior is undefined if the storage class of Result
Type
does not match the one used by the operation that produced the
value of Operand.

If Result Type has the same number of components as Operand, they
must also have the same component width, and results are computed per
component.

If Result Type has a different number of components than Operand,
the total number of bits in Result Type must equal the total number of
bits in Operand. Let L be the type, either Result Type or
Operand’s type, that has the larger number of components. Let S be
the other type, with the smaller number of components. The number of
components in L must be an integer multiple of the number of
components in S. The first component (that is, the only or
lowest-numbered component) of S maps to the first components of L,
and so on, up to the last component of S mapping to the last
components of L. Within this mapping, any single component of S
(mapping to multiple components of L) maps its lower-ordered bits to
the lower-numbered components of L.

Word Count Opcode Results Operands

4

124

<id>
Result Type

Result <id>

<id>
Operand

Test Case(s)

Example 1

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

export uint16_t4 fn(half4 p1) {
    return asuint16(p1);
}

HLSL:

Syntax

uint16_t<> asuint16(numeric16_only<> x);

Type Description

Name Template Type Component Type Size
ret scalar, vector, or matrix uint16_t any
x scalar, vector, or matrix half, int16_t, or uint16_t any

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 6.2 and higher shader models yes

Shader Stages

See also

@farzonl farzonl added 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 Dec 3, 2024
@metkarpoonam
Copy link
Contributor

I will start working on this.

@damyanp damyanp moved this from Ready to Active in HLSL Support Mar 19, 2025
@github-project-automation github-project-automation bot moved this from Active to Closed in HLSL Support Mar 21, 2025
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this issue Mar 21, 2025
Implemented the asuint16 function and added test cases for codegen,
Sema, and SPIR-V backend.
fixes llvm/llvm-project#99185
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:SPIR-V bot:HLSL HLSL HLSL Language Support metabug Issue to collect references to a group of similar or related issues.
Projects
Status: Closed
Development

Successfully merging a pull request may close this issue.

2 participants