Skip to content

Commit 135b1cd

Browse files
committed
Alother slight suffling of hlsl includes
This fixes issues that were causing the new select overloads to fail to compile.
1 parent c93ecf3 commit 135b1cd

File tree

5 files changed

+77
-58
lines changed

5 files changed

+77
-58
lines changed

clang/lib/Headers/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ set(hlsl_h
8787
set(hlsl_subdir_files
8888
hlsl/hlsl_basic_types.h
8989
hlsl/hlsl_alias_intrinsics.h
90+
hlsl/hlsl_intrinsic_helpers.h
9091
hlsl/hlsl_intrinsics.h
9192
hlsl/hlsl_detail.h
9293
)

clang/lib/Headers/hlsl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
#pragma clang diagnostic ignored "-Whlsl-dxc-compatability"
1717
#endif
1818

19+
20+
#include "hlsl/hlsl_detail.h"
1921
#include "hlsl/hlsl_basic_types.h"
22+
#include "hlsl/hlsl_alias_intrinsics.h"
2023
#include "hlsl/hlsl_intrinsics.h"
2124

2225
#if defined(__clang__)

clang/lib/Headers/hlsl/hlsl_detail.h

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===----- detail.h - HLSL definitions for intrinsics ----------===//
1+
//===----- hlsl_detail.h - HLSL definitions for intrinsics ----------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,8 +9,6 @@
99
#ifndef _HLSL_HLSL_DETAILS_H_
1010
#define _HLSL_HLSL_DETAILS_H_
1111

12-
#include "hlsl_alias_intrinsics.h"
13-
1412
namespace hlsl {
1513

1614
namespace __detail {
@@ -43,60 +41,6 @@ constexpr enable_if_t<sizeof(U) == sizeof(T), U> bit_cast(T F) {
4341
return __builtin_bit_cast(U, F);
4442
}
4543

46-
constexpr vector<uint, 4> d3d_color_to_ubyte4_impl(vector<float, 4> V) {
47-
// Use the same scaling factor used by FXC, and DXC for DXIL
48-
// (i.e., 255.001953)
49-
// https://github.com/microsoft/DirectXShaderCompiler/blob/070d0d5a2beacef9eeb51037a9b04665716fd6f3/lib/HLSL/HLOperationLower.cpp#L666C1-L697C2
50-
// The DXC implementation refers to a comment on the following stackoverflow
51-
// discussion to justify the scaling factor: "Built-in rounding, necessary
52-
// because of truncation. 0.001953 * 256 = 0.5"
53-
// https://stackoverflow.com/questions/52103720/why-does-d3dcolortoubyte4-multiplies-components-by-255-001953f
54-
return V.zyxw * 255.001953f;
55-
}
56-
57-
template <typename T>
58-
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
59-
length_impl(T X) {
60-
return abs(X);
61-
}
62-
63-
template <typename T, int N>
64-
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
65-
length_vec_impl(vector<T, N> X) {
66-
#if (__has_builtin(__builtin_spirv_length))
67-
return __builtin_spirv_length(X);
68-
#else
69-
return sqrt(dot(X, X));
70-
#endif
71-
}
72-
73-
template <typename T>
74-
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
75-
distance_impl(T X, T Y) {
76-
return length_impl(X - Y);
77-
}
78-
79-
template <typename T, int N>
80-
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
81-
distance_vec_impl(vector<T, N> X, vector<T, N> Y) {
82-
return length_vec_impl(X - Y);
83-
}
84-
85-
template <typename T>
86-
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
87-
reflect_impl(T I, T N) {
88-
return I - 2 * N * I * N;
89-
}
90-
91-
template <typename T, int L>
92-
constexpr vector<T, L> reflect_vec_impl(vector<T, L> I, vector<T, L> N) {
93-
#if (__has_builtin(__builtin_spirv_reflect))
94-
return __builtin_spirv_reflect(I, N);
95-
#else
96-
return I - 2 * N * dot(I, N);
97-
#endif
98-
}
99-
10044
template <typename T> struct is_arithmetic {
10145
static const bool Value = __is_arithmetic(T);
10246
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===----- hlsl_intrinsic_helpers.h - HLSL helpers intrinsics -------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef _HLSL_HLSL_INTRINSIC_HELPERS_H_
10+
#define _HLSL_HLSL_INTRINSIC_HELPERS_H_
11+
12+
namespace hlsl {
13+
namespace __detail {
14+
15+
constexpr vector<uint, 4> d3d_color_to_ubyte4_impl(vector<float, 4> V) {
16+
// Use the same scaling factor used by FXC, and DXC for DXIL
17+
// (i.e., 255.001953)
18+
// https://github.com/microsoft/DirectXShaderCompiler/blob/070d0d5a2beacef9eeb51037a9b04665716fd6f3/lib/HLSL/HLOperationLower.cpp#L666C1-L697C2
19+
// The DXC implementation refers to a comment on the following stackoverflow
20+
// discussion to justify the scaling factor: "Built-in rounding, necessary
21+
// because of truncation. 0.001953 * 256 = 0.5"
22+
// https://stackoverflow.com/questions/52103720/why-does-d3dcolortoubyte4-multiplies-components-by-255-001953f
23+
return V.zyxw * 255.001953f;
24+
}
25+
26+
template <typename T>
27+
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
28+
length_impl(T X) {
29+
return abs(X);
30+
}
31+
32+
template <typename T, int N>
33+
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
34+
length_vec_impl(vector<T, N> X) {
35+
#if (__has_builtin(__builtin_spirv_length))
36+
return __builtin_spirv_length(X);
37+
#else
38+
return sqrt(dot(X, X));
39+
#endif
40+
}
41+
42+
template <typename T>
43+
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
44+
distance_impl(T X, T Y) {
45+
return length_impl(X - Y);
46+
}
47+
48+
template <typename T, int N>
49+
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
50+
distance_vec_impl(vector<T, N> X, vector<T, N> Y) {
51+
return length_vec_impl(X - Y);
52+
}
53+
54+
template <typename T>
55+
constexpr enable_if_t<is_same<float, T>::value || is_same<half, T>::value, T>
56+
reflect_impl(T I, T N) {
57+
return I - 2 * N * I * N;
58+
}
59+
60+
template <typename T, int L>
61+
constexpr vector<T, L> reflect_vec_impl(vector<T, L> I, vector<T, L> N) {
62+
#if (__has_builtin(__builtin_spirv_reflect))
63+
return __builtin_spirv_reflect(I, N);
64+
#else
65+
return I - 2 * N * dot(I, N);
66+
#endif
67+
}
68+
} // namespace __detail
69+
} // namespace hlsl
70+
71+
#endif // _HLSL_HLSL_INTRINSIC_HELPERS_H_

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef _HLSL_HLSL_INTRINSICS_H_
1010
#define _HLSL_HLSL_INTRINSICS_H_
1111

12-
#include "hlsl_detail.h"
12+
#include "hlsl/hlsl_intrinsic_helpers.h"
1313

1414
namespace hlsl {
1515

0 commit comments

Comments
 (0)