Skip to content

Commit 394656d

Browse files
Make the foundational types available in nbl::hlsl namespace for HLSL too
New DXC bug: microsoft/DirectXShaderCompiler#6005
1 parent 1e9c170 commit 394656d

File tree

3 files changed

+50
-50
lines changed

3 files changed

+50
-50
lines changed

include/nbl/builtin/hlsl/cpp_compat.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ using add_pointer = std::add_pointer<T>;
3333
#define NBL_REF_ARG(T) typename nbl::hlsl::add_reference<T>::type
3434
#define NBL_CONST_REF_ARG(T) typename nbl::hlsl::add_reference<std::add_const_t<T>>::type
3535

36-
// it includes vector and matrix
37-
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.h>
38-
3936
#else
4037

4138
#define ARROW .arrow().
@@ -68,4 +65,7 @@ struct add_pointer
6865

6966
#endif
7067

68+
// it includes vector and matrix
69+
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.h>
70+
7171
#endif

include/nbl/builtin/hlsl/cpp_compat/matrix.hlsl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
#include <nbl/builtin/hlsl/cpp_compat/vector.hlsl>
55

6-
#ifndef __HLSL_VERSION
7-
namespace nbl::hlsl
6+
namespace nbl
87
{
9-
8+
namespace hlsl
9+
{
10+
#ifndef __HLSL_VERSION
1011
template<typename T, uint16_t N, uint16_t M>
1112
struct matrix final : private glm::mat<N,M,T>
1213
{
@@ -55,12 +56,13 @@ struct matrix final : private glm::mat<N,M,T>
5556
return glm::transpose(reinterpret_cast<Base const&>(m));
5657
}
5758
};
59+
#endif
5860

5961

6062
#define NBL_TYPEDEF_MATRICES_FOR_ROW(T, R) \
61-
using T ## R ## x4 = matrix<T, R, 4>; \
62-
using T ## R ## x3 = matrix<T, R, 3>; \
63-
using T ## R ## x2 = matrix<T, R, 2>;
63+
typedef matrix<T, R, 4> T ## R ## x4; \
64+
typedef matrix<T, R, 3> T ## R ## x3; \
65+
typedef matrix<T, R, 2> T ## R ## x2;
6466

6567
#define NBL_TYPEDEF_MATRICES_FOR_SCALAR(T) \
6668
NBL_TYPEDEF_MATRICES_FOR_ROW(T, 4) \
@@ -80,8 +82,7 @@ NBL_TYPEDEF_MATRICES_FOR_SCALAR(float64_t);
8082

8183
#undef NBL_TYPEDEF_MATRICES_FOR_ROW
8284
#undef NBL_TYPEDEF_MATRICES_FOR_SCALAR
83-
8485
}
85-
#endif
86+
}
8687

8788
#endif
Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,21 @@
11
#ifndef _NBL_BUILTIN_HLSL_CPP_COMPAT_VECTOR_INCLUDED_
22
#define _NBL_BUILTIN_HLSL_CPP_COMPAT_VECTOR_INCLUDED_
33

4+
// stuff for C++
45
#ifndef __HLSL_VERSION
6+
#include <stdint.h>
7+
8+
#include <half.h>
59

610
#define GLM_FORCE_SWIZZLE
711
#include <glm/glm.hpp>
812
#include <glm/detail/_swizzle.hpp>
9-
#include <stdint.h>
10-
#include <half.h>
1113

1214
namespace nbl::hlsl
1315
{
14-
1516
template<typename T, uint16_t N>
1617
using vector = glm::vec<N, T>;
1718

18-
// ideally we should have sized bools, but no idea what they'd be
19-
using bool4 = vector<bool, 4>;
20-
using bool3 = vector<bool, 3>;
21-
using bool2 = vector<bool, 2>;
22-
using bool1 = vector<bool, 1>;
23-
24-
using int32_t4 = vector<int32_t, 4>;
25-
using int32_t3 = vector<int32_t, 3>;
26-
using int32_t2 = vector<int32_t, 2>;
27-
using int32_t1 = vector<int32_t, 1>;
28-
29-
using uint32_t4 = vector<uint32_t, 4>;
30-
using uint32_t3 = vector<uint32_t, 3>;
31-
using uint32_t2 = vector<uint32_t, 2>;
32-
using uint32_t1 = vector<uint32_t, 1>;
33-
34-
// TODO: halfN -> needs class implementation or C++23 std:float16_t
35-
36-
using float16_t = half;
37-
using float16_t4 = vector<float16_t, 4>;
38-
using float16_t3 = vector<float16_t, 3>;
39-
using float16_t2 = vector<float16_t, 2>;
40-
using float16_t1 = vector<float16_t, 1>;
41-
42-
using float32_t = float;
43-
using float32_t4 = vector<float32_t, 4>;
44-
using float32_t3 = vector<float32_t, 3>;
45-
using float32_t2 = vector<float32_t, 2>;
46-
using float32_t1 = vector<float32_t, 1>;
47-
48-
using float64_t = double;
49-
using float64_t4 = vector<float64_t, 4>;
50-
using float64_t3 = vector<float64_t, 3>;
51-
using float64_t2 = vector<float64_t, 2>;
52-
using float64_t1 = vector<float64_t, 1>;
53-
5419
template<typename T, uint16_t N>
5520
glm::vec<N, bool> operator<(const glm::vec<N, T>& lhs, const glm::vec<N, T>& rhs)
5621
{
@@ -77,4 +42,38 @@ glm::vec<N, bool> operator>=(const glm::vec<N, T>& lhs, const glm::vec<N, T>& rh
7742
}
7843
#endif
7944

45+
// general typedefs for both langs
46+
namespace nbl
47+
{
48+
namespace hlsl
49+
{
50+
typedef half float16_t;
51+
typedef float float32_t;
52+
typedef double float64_t;
53+
54+
#define NBL_TYPEDEF_VECTORS(T) \
55+
typedef vector<T,4> T ## 4; \
56+
typedef vector<T,3> T ## 3; \
57+
typedef vector<T,2> T ## 2; \
58+
typedef vector<T,1> T ## 1
59+
60+
// ideally we should have sized bools, but no idea what they'd be
61+
NBL_TYPEDEF_VECTORS(bool);
62+
63+
NBL_TYPEDEF_VECTORS(int16_t);
64+
NBL_TYPEDEF_VECTORS(int32_t);
65+
NBL_TYPEDEF_VECTORS(int64_t);
66+
67+
NBL_TYPEDEF_VECTORS(uint16_t);
68+
NBL_TYPEDEF_VECTORS(uint32_t);
69+
NBL_TYPEDEF_VECTORS(uint64_t);
70+
71+
NBL_TYPEDEF_VECTORS(float16_t);
72+
NBL_TYPEDEF_VECTORS(float32_t);
73+
NBL_TYPEDEF_VECTORS(float64_t);
74+
75+
#undef NBL_TYPEDEF_VECTORS
76+
}
77+
}
78+
8079
#endif

0 commit comments

Comments
 (0)