Skip to content

Commit 0a1b37e

Browse files
committed
template specialization
1 parent c3ce717 commit 0a1b37e

File tree

4 files changed

+8
-25
lines changed

4 files changed

+8
-25
lines changed

clang/lib/Headers/hlsl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
// HLSL standard library function declarations/definitions.
2424
#include "hlsl/hlsl_alias_intrinsics.h"
25-
#include "hlsl/hlsl_intrinsics.h"
2625
#if __HLSL_VERSION <= __HLSL_202x
2726
#include "hlsl/hlsl_compat_overloads.h"
2827
#endif
28+
#include "hlsl/hlsl_intrinsics.h"
2929

3030
#if defined(__clang__)
3131
#pragma clang diagnostic pop

clang/lib/Headers/hlsl/hlsl_compat_overloads.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,10 @@ _DXC_COMPAT_TERNARY_INTEGER_OVERLOADS(lerp)
285285
//===----------------------------------------------------------------------===//
286286

287287
template <typename T>
288-
constexpr __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
289-
!__detail::is_same<half, T>::value &&
290-
!__detail::is_same<float, T>::value,
291-
vector<T, 4>>
288+
const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value,
289+
vector<T, 4>>
292290
lit(T NDotL, T NDotH, T M) {
293-
return lit((float)NDotL, (float)NDotH, (float)M);
291+
return lit<float>((float)NDotL, (float)NDotH, (float)M);
294292
}
295293

296294
//===----------------------------------------------------------------------===//

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,19 +268,14 @@ const inline float length(__detail::HLSL_FIXED_VECTOR<float, N> X) {
268268
/// This function returns a lighting coefficient vector (ambient, diffuse,
269269
/// specular, 1).
270270

271-
template <typename T>
271+
template <>
272272
_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
273-
const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
274-
__detail::is_same<half, T>::value,
275-
vector<T, 4>> lit(T NDotL, T NDotH, T M) {
273+
const inline vector<half, 4> lit<half>(half NDotL, half NDotH, half M) {
276274
return __detail::lit_impl(NDotL, NDotH, M);
277275
}
278276

279-
template <typename T>
280-
const inline __detail::enable_if_t<__detail::is_arithmetic<T>::Value &&
281-
__detail::is_same<float, T>::value,
282-
vector<T, 4>>
283-
lit(T NDotL, T NDotH, T M) {
277+
template <>
278+
const inline vector<float, 4> lit<float>(float NDotL, float NDotH, float M) {
284279
return __detail::lit_impl(NDotL, NDotH, M);
285280
}
286281

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,29 @@
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_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
7-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
86
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function template not viable: requires 3 arguments, but 1 was provided}}
97
}
108

119
float4 test_no_third_arg(float p0) {
1210
return lit(p0, p0);
1311
// expected-error@-1 {{no matching function for call to 'lit'}}
14-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
15-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
1612
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function template not viable: requires 3 arguments, but 2 were provided}}
1713
}
1814

1915
float4 test_too_many_arg(float p0) {
2016
return lit(p0, p0, p0, p0);
2117
// expected-error@-1 {{no matching function for call to 'lit'}}
22-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
23-
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
2418
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate function template not viable: requires 3 arguments, but 4 were provided}}
2519
}
2620

2721
float4 test_vec_inputs(float2 p0, float2 p1, float2 p2) {
2822
return lit(p0, p1, p2);
2923
// expected-error@-1 {{no matching function for call to 'lit'}}
30-
// 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)}}
31-
// 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)}}
3224
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate template ignored: substitution failure [with T = float2]: invalid vector element type 'vector<float, 2>' (vector of 2 'float' values)}}
3325
}
3426

3527
float4 test_vec1_inputs(float1 p0, float1 p1, float1 p2) {
3628
return lit(p0, p1, p2);
3729
// expected-error@-1 {{no matching function for call to 'lit'}}
38-
// 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)}}
39-
// 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)}}
4030
// expected-note@hlsl/hlsl_compat_overloads.h:* {{candidate template ignored: substitution failure [with T = float1]: invalid vector element type 'vector<float, 1>' (vector of 1 'float' value)}}
4131
}

0 commit comments

Comments
 (0)