Skip to content

Commit b5f34ee

Browse files
committed
[HLSL] fix D3DCOLORtoUBYTE4 return type to be int
fixes #150673 fixes #150678 The issue was we were using the wrong return type.
1 parent a719091 commit b5f34ee

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
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 vector<int, 4> d3d_color_to_ubyte4_impl(vector<float, 4> 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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ int4 test_D3DCOLORtoUBYTE4(float4 p1) {
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+
}

0 commit comments

Comments
 (0)