Skip to content

Commit 4bd1ab8

Browse files
committed
WIP double/int overloads
1 parent 02306a6 commit 4bd1ab8

File tree

3 files changed

+56
-27
lines changed

3 files changed

+56
-27
lines changed

clang/lib/Headers/hlsl/hlsl_compat_overloads.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#ifndef _HLSL_COMPAT_OVERLOADS_H_
1010
#define _HLSl_COMPAT_OVERLOADS_H_
1111

12+
#include "hlsl/hlsl_intrinsic_helpers.h"
13+
1214
namespace hlsl {
1315

1416
// Note: Functions in this file are sorted alphabetically, then grouped by base
@@ -283,11 +285,23 @@ _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
283285
//===----------------------------------------------------------------------===//
284286
// lit builtins overloads
285287
//===----------------------------------------------------------------------===//
286-
constexpr float4 lit(double V1, double V2, double V3) { return lit((float)V1, (float)V2, (float)V3); }
287-
constexpr float4 lit(int V1, int V2, int V3) { return lit((float)V1, (float)V2, (float)V3); }
288-
constexpr float4 lit(uint V1, uint V2, uint V3) { return lit((float)V1, (float)V2, (float)V3); }
289-
constexpr float4 lit(int64_t V1, int64_t V2, int64_t V3) { return lit((float)V1, (float)V2, (float)V3); }
290-
constexpr float4 lit(uint64_t V1, uint64_t V2, uint64_t V3) { return lit((float)V1, (float)V2, (float)V3); }
288+
289+
// Note: calling lit_impl because calling lit directly causes infinite recursion
290+
constexpr float4 lit(double V1, double V2, double V3) {
291+
return __detail::lit_impl((float)V1, (float)V2, (float)V3);
292+
}
293+
constexpr float4 lit(int V1, int V2, int V3) {
294+
return __detail::lit_impl((float)V1, (float)V2, (float)V3);
295+
}
296+
constexpr float4 lit(uint V1, uint V2, uint V3) {
297+
return __detail::lit_impl((float)V1, (float)V2, (float)V3);
298+
}
299+
constexpr float4 lit(int64_t V1, int64_t V2, int64_t V3) {
300+
return __detail::lit_impl((float)V1, (float)V2, (float)V3);
301+
}
302+
constexpr float4 lit(uint64_t V1, uint64_t V2, uint64_t V3) {
303+
return __detail::lit_impl((float)V1, (float)V2, (float)V3);
304+
}
291305

292306
//===----------------------------------------------------------------------===//
293307
// log builtins overloads

clang/test/CodeGenHLSL/builtins/lit-overloads.hlsl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
// RUN: -emit-llvm -disable-llvm-passes -o - | \
33
// RUN: FileCheck %s --check-prefixes=CHECK
44

5-
// CHECK-LABEL: define noundef nofpclass(nan inf) float {{.*}}test_floor_double
6-
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
5+
// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl3litEddd(
6+
// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
77
float4 test_lit_double(double NDotL, double NDotH, double M) { return lit(NDotL, NDotH, M); }
88

9-
// CHECK-LABEL: define noundef nofpclass(nan inf) float {{.*}}test_floor_int
10-
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
9+
// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl3litEiii(
10+
// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
1111
float4 test_lit_int(int NDotL, int NDotH, int M) { return lit(NDotL, NDotH, M); }
1212

13-
// CHECK-LABEL: define noundef nofpclass(nan inf) float {{.*}}test_floor_uint
14-
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
13+
// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl3litEjjj(
14+
// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
1515
float4 test_lit_uint(uint NDotL, uint NDotH, uint M) { return lit(NDotL, NDotH, M); }
1616

17-
// CHECK-LABEL: define noundef nofpclass(nan inf) float {{.*}}test_floor_int64_t
18-
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
17+
// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl3litElll(
18+
// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
1919
float4 test_lit_int64_t(int64_t NDotL, int64_t NDotH, int64_t M) { return lit(NDotL, NDotH, M); }
2020

21-
// CHECK-LABEL: define noundef nofpclass(nan inf) float {{.*}}test_floor_uint64_t
22-
// CHECK: call reassoc nnan ninf nsz arcp afn float @llvm.floor.f32(
21+
// CHECK-LABEL: define linkonce_odr noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl3litEmmm(
22+
// CHECK: call reassoc nnan ninf nsz arcp afn noundef nofpclass(nan inf) <4 x float> @_ZN4hlsl8__detail8lit_implIfEEDv4_T_S2_S2_S2_(
2323
float4 test_lit_uint64_t(uint64_t NDotL, uint64_t NDotH, uint64_t M) { return lit(NDotL, NDotH, M); }

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

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,49 @@
33
float4 test_no_second_arg(float p0) {
44
return lit(p0);
55
// expected-error@-1 {{no matching function for call to 'lit'}}
6+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 1 was provided}}
7+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 1 was provided}}
8+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 1 was provided}}
9+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 1 was provided}}
10+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 1 was provided}}
611
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
712
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
813
}
914

1015
float4 test_no_third_arg(float p0) {
1116
return lit(p0, p0);
1217
// expected-error@-1 {{no matching function for call to 'lit'}}
18+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 2 were provided}}
19+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 2 were provided}}
20+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 2 were provided}}
21+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 2 were provided}}
22+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 2 were provided}}
1323
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
1424
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
1525
}
1626

1727
float4 test_too_many_arg(float p0) {
1828
return lit(p0, p0, p0, p0);
1929
// expected-error@-1 {{no matching function for call to 'lit'}}
30+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 4 were provided}}
31+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 4 were provided}}
32+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 4 were provided}}
33+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 4 were provided}}
34+
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function not viable: requires 3 arguments, but 4 were provided}}
2035
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
2136
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
2237
}
2338

24-
float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
25-
return lit(p0, p1, p2);
26-
// expected-error@-1 {{no matching function for call to 'lit'}}
27-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float2]: invalid vector element type 'vector<float, 2>' (vector of 2 'float' values)}}
28-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float2]: invalid vector element type 'vector<float, 2>' (vector of 2 'float' values)}}
29-
}
39+
// float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
40+
// return lit(p0, p1, p2);
41+
// // expected-error@-1 {{no matching function for call to 'lit'}}
42+
// // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float2]: invalid vector element type 'vector<float, 2>' (vector of 2 'float' values)}}
43+
// // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float2]: invalid vector element type 'vector<float, 2>' (vector of 2 'float' values)}}
44+
// }
3045

31-
float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
32-
return lit(p0, p1, p2);
33-
// expected-error@-1 {{no matching function for call to 'lit'}}
34-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: invalid vector element type 'vector<float, 1>' (vector of 1 'float' value)}}
35-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: invalid vector element type 'vector<float, 1>' (vector of 1 'float' value)}}
36-
}
46+
// float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
47+
// return lit(p0, p1, p2);
48+
// // expected-error@-1 {{no matching function for call to 'lit'}}
49+
// // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: invalid vector element type 'vector<float, 1>' (vector of 1 'float' value)}}
50+
// // expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = float1]: invalid vector element type 'vector<float, 1>' (vector of 1 'float' value)}}
51+
// }

0 commit comments

Comments
 (0)