Skip to content

Implement the D3DCOLORtoUBYTE4 HLSL Function #99092

@farzonl

Description

@farzonl
  • 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)

Metadata

Metadata

Assignees

Labels

HLSLHLSL Language Supportbackend:SPIR-Vbot:HLSLmetaissueIssue to collect references to a group of similar or related issues.

Type

No type

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions