Skip to content

Commit 5302b2e

Browse files
committed
Merge branch 'master' of github.com:Devsh-Graphics-Programming/Nabla into docker
2 parents c057808 + 9aa4665 commit 5302b2e

File tree

5 files changed

+137
-28
lines changed

5 files changed

+137
-28
lines changed

cmake/common.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,8 +1390,10 @@ execute_process(COMMAND "${GIT_EXECUTABLE}" ${NBL_CONFIG_SETUP_CMD} submodule up
13901390
# NBL_WRAPPER_COMMAND_EXCLUSIVE("" ./ci TRUE "") TODO: enable it once we merge Ditt, etc
13911391

13921392
# examples and their media
1393-
NBL_WRAPPER_COMMAND_EXCLUSIVE("" ./examples_tests FALSE "")
1394-
NBL_WRAPPER_COMMAND_EXCLUSIVE(examples_tests ./media FALSE "")
1393+
if(NBL_BUILD_EXAMPLES)
1394+
NBL_WRAPPER_COMMAND_EXCLUSIVE("" ./examples_tests FALSE "")
1395+
NBL_WRAPPER_COMMAND_EXCLUSIVE(examples_tests ./media FALSE "")
1396+
endif()
13951397
endif()
13961398

13971399
file(WRITE "${_NBL_UPDATE_SUBMODULES_CMD_FILE_}" "${_NBL_UPDATE_SUBMODULES_COMMANDS_}")

include/nbl/builtin/hlsl/member_test_macros.hlsl

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace impl
1919
template<class T, bool C>
2020
struct is_const_helper : bool_constant<C>
2121
{
22+
using type = T;
2223
NBL_CONSTEXPR_STATIC_INLINE bool is_constant = is_const<T>::value;
2324
};
2425

@@ -33,6 +34,11 @@ enum e_member_presence
3334
template<class T>
3435
T declval(){}
3536

37+
template<bool=false>
38+
struct if_2_else_1 : integral_constant<uint32_t,1> {};
39+
template<>
40+
struct if_2_else_1<true> : integral_constant<uint32_t,2> {};
41+
3642
}
3743

3844
typedef impl::e_member_presence e_member_presence;
@@ -67,5 +73,94 @@ NBL_GENERATE_MEMBER_TESTER(y)
6773
NBL_GENERATE_MEMBER_TESTER(z)
6874
NBL_GENERATE_MEMBER_TESTER(w)
6975

76+
77+
// Even though it should work for some reason tests fail
78+
// proof it works : https://godbolt.org/z/EzPWGnTPb
79+
80+
#define CAT(x, y) x##y
81+
#define TYPE_DECLARE(n) typename Arg##n
82+
#define TYPE_DECLARE_DEFAULT(n) TYPE_DECLARE(n)=void
83+
#define TYPE_FWD(n) Arg##n
84+
#define DECLVAL_DECLARE(n) impl::declval<Arg##n>()
85+
86+
#define FOR_EACH0(fn)
87+
#define FOR_EACH1(fn) fn(1)
88+
#define FOR_EACH2(fn) fn(2), FOR_EACH1(fn)
89+
#define FOR_EACH3(fn) fn(3), FOR_EACH2(fn)
90+
#define FOR_EACH4(fn) fn(4), FOR_EACH3(fn)
91+
#define FOR_EACH(fn, n) CAT(FOR_EACH, n)(fn)
92+
93+
#define GENERATE_STATIC_METHOD_TESTER_SPEC0(x) \
94+
template<class T> \
95+
struct has_static_method_##x<T, typename make_void<decltype(T::x())>::type> : true_type \
96+
{ \
97+
using return_type = decltype(T::x()); \
98+
NBL_CONSTEXPR_STATIC_INLINE uint arg_count = 0; \
99+
};
100+
101+
#define GENERATE_STATIC_METHOD_TESTER_SPEC(x, n) \
102+
template<class T, FOR_EACH(TYPE_DECLARE, n)> \
103+
struct has_static_method_##x<T, FOR_EACH(TYPE_FWD, n), typename make_void<decltype(T::x(FOR_EACH(DECLVAL_DECLARE, n)))>::type> : true_type \
104+
{ \
105+
using return_type = decltype(T::x(FOR_EACH(DECLVAL_DECLARE, n))); \
106+
NBL_CONSTEXPR_STATIC_INLINE uint arg_count = n; \
107+
};
108+
109+
#define GENERATE_STATIC_METHOD_TESTER(x) \
110+
template<typename T, FOR_EACH(TYPE_DECLARE_DEFAULT, 4), class=void> \
111+
struct has_static_method_##x : false_type {}; \
112+
GENERATE_STATIC_METHOD_TESTER_SPEC0(x) \
113+
GENERATE_STATIC_METHOD_TESTER_SPEC(x, 1) \
114+
GENERATE_STATIC_METHOD_TESTER_SPEC(x, 2) \
115+
GENERATE_STATIC_METHOD_TESTER_SPEC(x, 3) \
116+
GENERATE_STATIC_METHOD_TESTER_SPEC(x, 4)
117+
118+
#define GENERATE_METHOD_TESTER_SPEC0(x) \
119+
template<class T> \
120+
struct has_method_##x<T, typename make_void<decltype(impl::declval<T>().x())>::type> : impl::if_2_else_1<impl::has_static_method_##x<T>::value> \
121+
{ \
122+
using return_type = decltype(impl::declval<T>().x()); \
123+
NBL_CONSTEXPR_STATIC_INLINE uint arg_count = 0; \
124+
};
125+
126+
#define GENERATE_METHOD_TESTER_SPEC(x, n) \
127+
template<class T, FOR_EACH(TYPE_DECLARE, n)> \
128+
struct has_method_##x<T, FOR_EACH(TYPE_FWD, n), typename make_void<decltype(impl::declval<T>().x(FOR_EACH(DECLVAL_DECLARE, n)))>::type> : impl::if_2_else_1<impl::has_static_method_##x<T,FOR_EACH(TYPE_FWD, n)>::value> \
129+
{ \
130+
using return_type = decltype(impl::declval<T>().x(FOR_EACH(DECLVAL_DECLARE, n))); \
131+
NBL_CONSTEXPR_STATIC_INLINE uint arg_count = n; \
132+
};
133+
134+
/*
135+
types that are impilicitly convertible to each other mess this check up
136+
137+
struct S
138+
{
139+
void a(int) { return 0;}
140+
};
141+
142+
has_method_a<S, float>::value will be true
143+
since float is implicitly convertible to int and
144+
due to how we check function signatures at the moment
145+
*/
146+
147+
#define GENERATE_METHOD_TESTER(x) \
148+
namespace nbl { \
149+
namespace hlsl { \
150+
namespace impl { GENERATE_STATIC_METHOD_TESTER(x) } \
151+
template<typename T, FOR_EACH(TYPE_DECLARE_DEFAULT, 4), class=void> \
152+
struct has_method_##x : false_type {}; \
153+
GENERATE_METHOD_TESTER_SPEC0(x) \
154+
GENERATE_METHOD_TESTER_SPEC(x, 1) \
155+
GENERATE_METHOD_TESTER_SPEC(x, 2) \
156+
GENERATE_METHOD_TESTER_SPEC(x, 3) \
157+
GENERATE_METHOD_TESTER_SPEC(x, 4) \
158+
}}
159+
160+
161+
GENERATE_METHOD_TESTER(a)
162+
GENERATE_METHOD_TESTER(b)
163+
164+
70165
#endif
71166
#endif

include/nbl/builtin/hlsl/subgroup/arithmetic_portability.hlsl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "nbl/builtin/hlsl/subgroup/basic.hlsl"
99

1010
#include "nbl/builtin/hlsl/subgroup/arithmetic_portability_impl.hlsl"
11+
#include "nbl/builtin/hlsl/jit/device_capabilities.hlsl"
1112

1213

1314
namespace nbl
@@ -17,20 +18,16 @@ namespace hlsl
1718
namespace subgroup
1819
{
1920

20-
#ifdef NBL_GLSL_LIMIT_SHADER_SUBGROUP_ARITHMETIC
21-
#define IMPL native
22-
#else
23-
#define IMPL portability
24-
#endif
21+
// TODO: change to alias using template when DXC finally fixes SPIR-V codegen impartity
22+
//template<class Binop, class device_capability_traits/*=TODO: Atil give us the traits so we can default with `void`!*/>
23+
//struct reduction : impl::reduction<Binop,device_capability_traits::subgroupArithmetic> {};
2524

2625
template<class Binop>
27-
struct reduction : IMPL::reduction<Binop> {};
26+
struct reduction : impl::reduction<Binop,nbl::hlsl::jit::device_capabilities::subgroupArithmetic> {};
2827
template<class Binop>
29-
struct inclusive_scan : IMPL::inclusive_scan<Binop> {};
28+
struct inclusive_scan : impl::inclusive_scan<Binop,nbl::hlsl::jit::device_capabilities::subgroupArithmetic> {};
3029
template<class Binop>
31-
struct exclusive_scan : IMPL::exclusive_scan<Binop> {};
32-
33-
#undef IMPL
30+
struct exclusive_scan : impl::exclusive_scan<Binop,nbl::hlsl::jit::device_capabilities::subgroupArithmetic> {};
3431

3532
}
3633
}

include/nbl/builtin/hlsl/subgroup/arithmetic_portability_impl.hlsl

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,34 @@ namespace hlsl
2222
namespace subgroup
2323
{
2424

25-
namespace native
25+
namespace impl
2626
{
27-
28-
template<class Binop, typename T=typename Binop::type_t>
27+
template<class Binop, bool native> // might need a 3rd default param `typename T=typename Binop::type_t`
2928
struct reduction;
30-
template<class Binop, typename T=typename Binop::type_t>
29+
template<class Binop, bool native>
3130
struct inclusive_scan;
32-
template<class Binop, typename T=typename Binop::type_t>
31+
template<class Binop, bool native>
3332
struct exclusive_scan;
3433

35-
#define SPECIALIZE(NAME,BINOP,SUBGROUP_OP) template<typename T> struct NAME<BINOP<T>,T> \
34+
// native
35+
template<class Binop>
36+
struct reduction<Binop, true>;
37+
template<class Binop>
38+
struct inclusive_scan<Binop, true>;
39+
template<class Binop>
40+
struct exclusive_scan<Binop, true>;
41+
42+
// portability
43+
template<class Binop>
44+
struct reduction<Binop, false>;
45+
template<class Binop>
46+
struct inclusive_scan<Binop, false>;
47+
template<class Binop>
48+
struct exclusive_scan<Binop, false>;
49+
50+
// specialize native
51+
52+
#define SPECIALIZE(NAME,BINOP,SUBGROUP_OP) template<typename T> struct NAME<BINOP<T>,true> \
3653
{ \
3754
using type_t = T; \
3855
\
@@ -56,19 +73,16 @@ SPECIALIZE_ALL(maximum,Max);
5673
#undef SPECIALIZE_ALL
5774
#undef SPECIALIZE
5875

59-
}
76+
// specialize portability
6077

61-
namespace portability
62-
{
63-
6478
// WARNING
6579
// THIS PORTABILITY IMPLEMENTATION USES SHUFFLE OPS
6680
// Shuffles where you attempt to read an invactive lane, return garbage,
6781
// which means that our portability reductions and prefix sums will also return garbage/UB/UV
6882
// Always use the native subgroup_arithmetic extensions if supported
6983

7084
template<class Binop>
71-
struct inclusive_scan
85+
struct inclusive_scan<Binop, false>
7286
{
7387
using type_t = typename Binop::type_t;
7488

@@ -97,13 +111,13 @@ struct inclusive_scan
97111
};
98112

99113
template<class Binop>
100-
struct exclusive_scan
114+
struct exclusive_scan<Binop, false>
101115
{
102116
using type_t = typename Binop::type_t;
103117

104118
type_t operator()(type_t value)
105119
{
106-
value = inclusive_scan<Binop>::__call(value);
120+
value = inclusive_scan<Binop,false>::__call(value);
107121
// can't risk getting short-circuited, need to store to a var
108122
type_t left = glsl::subgroupShuffleUp<type_t>(value,1);
109123
// the first invocation doesn't have anything in its left so we set to the binop's identity value for exlusive scan
@@ -112,16 +126,17 @@ struct exclusive_scan
112126
};
113127

114128
template<class Binop>
115-
struct reduction
129+
struct reduction<Binop, false>
116130
{
117131
using type_t = typename Binop::type_t;
118132

119133
type_t operator()(NBL_CONST_REF_ARG(type_t) value)
120134
{
121135
// take the last subgroup invocation's value for the reduction
122-
return BroadcastLast<type_t>(inclusive_scan<Binop>::__call(value));
136+
return BroadcastLast<type_t>(inclusive_scan<Binop,false>::__call(value));
123137
}
124138
};
139+
125140
}
126141

127142
}

include/nbl/builtin/hlsl/type_traits.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ template<bool val>
212212
struct bool_constant : integral_constant<bool, val> {};
213213

214214
struct true_type : bool_constant<true> {};
215-
struct false_type : bool_constant<true> {};
215+
struct false_type : bool_constant<false> {};
216216

217217
template<bool C, class T, class F>
218218
struct conditional : type_identity<T> {};

0 commit comments

Comments
 (0)