Skip to content

Commit b59cb28

Browse files
authored
[HLSL] fix D3DCOLORtoUBYTE4 return type to be int (#151353)
fixes #150673 fixes #150678 The issue was we were using the wrong return type.
1 parent 6975119 commit b59cb28

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

clang/lib/Headers/hlsl/hlsl_intrinsic_helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace hlsl {
1313
namespace __detail {
1414

15-
constexpr vector<uint, 4> d3d_color_to_ubyte4_impl(vector<float, 4> V) {
15+
constexpr int4 d3d_color_to_ubyte4_impl(float4 V) {
1616
// Use the same scaling factor used by FXC, and DXC for DXIL
1717
// (i.e., 255.001953)
1818
// https://github.com/microsoft/DirectXShaderCompiler/blob/070d0d5a2beacef9eeb51037a9b04665716fd6f3/lib/HLSL/HLOperationLower.cpp#L666C1-L697C2

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ const inline float4 lit(float NDotL, float NDotH, float M) {
418418
/// This function swizzles and scales components of the \a x parameter. Use this
419419
/// function to compensate for the lack of UBYTE4 support in some hardware.
420420

421-
constexpr vector<uint, 4> D3DCOLORtoUBYTE4(vector<float, 4> V) {
421+
constexpr int4 D3DCOLORtoUBYTE4(float4 V) {
422422
return __detail::d3d_color_to_ubyte4_impl(V);
423423
}
424424

clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55
// CHECK-LABEL: D3DCOLORtoUBYTE4
66
int4 test_D3DCOLORtoUBYTE4(float4 p1) {
77
// CHECK: %[[SCALED:.*]] = fmul [[FMFLAGS:.*]][[FLOAT_TYPE:<4 x float>]] %{{.*}}, splat (float 0x406FE01000000000)
8-
// CHECK: %[[CONVERTED:.*]] = fptoui [[FLOAT_TYPE]] %[[SCALED]] to [[INT_TYPE:<4 x i32>]]
8+
// CHECK: %[[CONVERTED:.*]] = fptosi [[FLOAT_TYPE]] %[[SCALED]] to [[INT_TYPE:<4 x i32>]]
99
// CHECK: %[[SHUFFLED:.*]] = shufflevector [[INT_TYPE]] %[[CONVERTED]], [[INT_TYPE]] poison, <4 x i32> <i32 2, i32 1, i32 0, i32 3>
1010
// CHECK: ret [[INT_TYPE]] %[[SHUFFLED]]
1111
return D3DCOLORtoUBYTE4(p1);
1212
}
13+
14+
// Note this test confirms issue 150673 is fixed
15+
// by confirming the negative does not become a poison
16+
// CHECK-LABEL: test_constant_inputs
17+
int4 test_constant_inputs() {
18+
// CHECK: ret <4 x i32> <i32 -12877, i32 2833, i32 0, i32 25500>
19+
return D3DCOLORtoUBYTE4(float4(0, 11.11, -50.5, 100));
20+
}

clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ struct S {
2525
int4 struct_arg(S v) {
2626
return D3DCOLORtoUBYTE4(v);
2727
// expected-error@-1 {{no matching function for call to 'D3DCOLORtoUBYTE4'}}
28-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: no known conversion from 'S' to 'vector<float, 4>' (vector of 4 'float' values) for 1st argument}}
28+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: no known conversion from 'S' to 'float4' (aka 'vector<float, 4>') for 1st argument}}
2929
}

0 commit comments

Comments
 (0)