Skip to content

Implement the D3DCOLORtoUBYTE4 HLSL Function #99092

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
3 tasks
Tracked by #99235
farzonl opened this issue Jul 16, 2024 · 2 comments · Fixed by #122202
Closed
3 tasks
Tracked by #99235

Implement the D3DCOLORtoUBYTE4 HLSL Function #99092

farzonl opened this issue Jul 16, 2024 · 2 comments · Fixed by #122202
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 D3DCOLORtoUBYTE4 in thehlsl_intrinsics.h header
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl

DirectX

There were no DXIL opcodes found for D3DCOLORtoUBYTE4. That should make it easy to do entirely in the frontend.
In DXC it was done via emitting llvmir. We do not want to do that in upstream.

SPIRV

There is no SPIRV opcode, but SPIRV has a custom implementation. We should try to consolidate behavior between backends. If you need to pick between implementations treat the implementation targeting the DirectX backend as the working spec.

Test Case(s)

Example 1

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

export int4 fn(float4 p1) {
    return D3DCOLORtoUBYTE4(p1);
}

HLSL:

Converts a floating-point, 4D vector set by a D3DCOLOR to a UBYTE4.

ret D3DCOLORtoUBYTE4(x)

This function swizzles and scales components of the x parameter. Use this function to compensate for the lack of UBYTE4 support in some hardware.

Parameters

Item Description
x
[in] The floating-point vector4 to convert.

Return Value

The UBYTE4 representation of the x parameter.

Type Description

Name Template Type Component Type Size
x vector float 4
ret vector integer 4

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) vs_1_1

See also

Intrinsic Functions (DirectX HLSL)

@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 Designing in HLSL Support Nov 12, 2024
@davidcook-msft
Copy link

@farzonl to review and update the item

@farzonl farzonl moved this from Designing to Ready in HLSL Support Jan 8, 2025
@farzonl farzonl moved this from Ready to Planning in HLSL Support Jan 8, 2025
@farzonl farzonl removed their assignment Jan 8, 2025
@Icohedron
Copy link
Contributor

I am currently working on this issue.

inbelic pushed a commit that referenced this issue Jan 14, 2025
Fixes #99092.

1. Defines the function `D3DCOLORtoUBYTE4` in
`clang/lib/Headers/hlsl/hlsl_intrinsics.h`.
2. Implements the function `D3DCOLORtoUBYTE4` as `d3d_color_to_ubyte4`
in `clang/lib/Headers/hlsl/hlsl_detail.h`
3. Adds a HLSL codegen test to
`clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl`
4. Adds sema tests to
`clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl`
@github-project-automation github-project-automation bot moved this from Planning to Closed in HLSL Support Jan 14, 2025
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
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants