[HLSL] fix D3DCOLORtoUBYTE4 return type to be int (#151353)
fixes #150673 fixes #150678 The issue was we were using the wrong return type.
This commit is contained in:
parent
69751196a9
commit
b59cb281c1
@ -12,7 +12,7 @@
|
||||
namespace hlsl {
|
||||
namespace __detail {
|
||||
|
||||
constexpr vector<uint, 4> d3d_color_to_ubyte4_impl(vector<float, 4> V) {
|
||||
constexpr int4 d3d_color_to_ubyte4_impl(float4 V) {
|
||||
// Use the same scaling factor used by FXC, and DXC for DXIL
|
||||
// (i.e., 255.001953)
|
||||
// https://github.com/microsoft/DirectXShaderCompiler/blob/070d0d5a2beacef9eeb51037a9b04665716fd6f3/lib/HLSL/HLOperationLower.cpp#L666C1-L697C2
|
||||
|
@ -418,7 +418,7 @@ const inline float4 lit(float NDotL, float NDotH, float M) {
|
||||
/// This function swizzles and scales components of the \a x parameter. Use this
|
||||
/// function to compensate for the lack of UBYTE4 support in some hardware.
|
||||
|
||||
constexpr vector<uint, 4> D3DCOLORtoUBYTE4(vector<float, 4> V) {
|
||||
constexpr int4 D3DCOLORtoUBYTE4(float4 V) {
|
||||
return __detail::d3d_color_to_ubyte4_impl(V);
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,16 @@
|
||||
// CHECK-LABEL: D3DCOLORtoUBYTE4
|
||||
int4 test_D3DCOLORtoUBYTE4(float4 p1) {
|
||||
// CHECK: %[[SCALED:.*]] = fmul [[FMFLAGS:.*]][[FLOAT_TYPE:<4 x float>]] %{{.*}}, splat (float 0x406FE01000000000)
|
||||
// CHECK: %[[CONVERTED:.*]] = fptoui [[FLOAT_TYPE]] %[[SCALED]] to [[INT_TYPE:<4 x i32>]]
|
||||
// CHECK: %[[CONVERTED:.*]] = fptosi [[FLOAT_TYPE]] %[[SCALED]] to [[INT_TYPE:<4 x i32>]]
|
||||
// CHECK: %[[SHUFFLED:.*]] = shufflevector [[INT_TYPE]] %[[CONVERTED]], [[INT_TYPE]] poison, <4 x i32> <i32 2, i32 1, i32 0, i32 3>
|
||||
// CHECK: ret [[INT_TYPE]] %[[SHUFFLED]]
|
||||
return D3DCOLORtoUBYTE4(p1);
|
||||
}
|
||||
|
||||
// Note this test confirms issue 150673 is fixed
|
||||
// by confirming the negative does not become a poison
|
||||
// CHECK-LABEL: test_constant_inputs
|
||||
int4 test_constant_inputs() {
|
||||
// CHECK: ret <4 x i32> <i32 -12877, i32 2833, i32 0, i32 25500>
|
||||
return D3DCOLORtoUBYTE4(float4(0, 11.11, -50.5, 100));
|
||||
}
|
||||
|
@ -25,5 +25,5 @@ struct S {
|
||||
int4 struct_arg(S v) {
|
||||
return D3DCOLORtoUBYTE4(v);
|
||||
// expected-error@-1 {{no matching function for call to 'D3DCOLORtoUBYTE4'}}
|
||||
// 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}}
|
||||
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function not viable: no known conversion from 'S' to 'float4' (aka 'vector<float, 4>') for 1st argument}}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user