Skip to content

Commit 02306a6

Browse files
committed
WIP accept double/int inputs and downcast to floats
1 parent f133aec commit 02306a6

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

clang/lib/Headers/hlsl/hlsl_compat_overloads.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,15 @@ constexpr bool4 isinf(double4 V) { return isinf((float4)V); }
280280
_DXC_COMPAT_TERNARY_DOUBLE_OVERLOADS(lerp)
281281
_DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
282282

283+
//===----------------------------------------------------------------------===//
284+
// lit builtins overloads
285+
//===----------------------------------------------------------------------===//
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); }
291+
283292
//===----------------------------------------------------------------------===//
284293
// log builtins overloads
285294
//===----------------------------------------------------------------------===//
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s \
2+
// RUN: -emit-llvm -disable-llvm-passes -o - | \
3+
// RUN: FileCheck %s --check-prefixes=CHECK
4+
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(
7+
float4 test_lit_double(double NDotL, double NDotH, double M) { return lit(NDotL, NDotH, M); }
8+
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(
11+
float4 test_lit_int(int NDotL, int NDotH, int M) { return lit(NDotL, NDotH, M); }
12+
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(
15+
float4 test_lit_uint(uint NDotL, uint NDotH, uint M) { return lit(NDotL, NDotH, M); }
16+
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(
19+
float4 test_lit_int64_t(int64_t NDotL, int64_t NDotH, int64_t M) { return lit(NDotL, NDotH, M); }
20+
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(
23+
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: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ float4 test_too_many_arg(float p0) {
2121
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
2222
}
2323

24-
float4 test_double_inputs(double p0, double p1, double 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 = double]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<double, 4>>'}}
28-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = double]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<double, 4>>'}}
29-
}
30-
31-
float4 test_int_inputs(int p0, int p1, int 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 = int]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<int, 4>>'}}
35-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate template ignored: substitution failure [with T = int]: no type named 'Type' in 'hlsl::__detail::enable_if<false, vector<int, 4>>'}}
36-
}
37-
3824
float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
3925
return lit(p0, p1, p2);
4026
// expected-error@-1 {{no matching function for call to 'lit'}}

0 commit comments

Comments
 (0)