Skip to content

Commit 8038643

Browse files
Merge pull request #590 from Devsh-Graphics-Programming/member_test
member tester macros
2 parents 44dd63c + 160aae5 commit 8038643

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (C) 2022 - DevSH Graphics Programming Sp. z O.O.
2+
// This file is part of the "Nabla Engine".
3+
// For conditions of distribution and use, see copyright notice in nabla.h
4+
#ifndef _NBL_BUILTIN_HLSL_MEMBER_TEST_MACROS_INCLUDED_
5+
#define _NBL_BUILTIN_HLSL_MEMBER_TEST_MACROS_INCLUDED_
6+
7+
#include <nbl/builtin/hlsl/type_traits.hlsl>
8+
9+
#ifdef __HLSL_VERSION
10+
11+
namespace nbl
12+
{
13+
namespace hlsl
14+
{
15+
16+
namespace impl
17+
{
18+
19+
template<class T, bool C>
20+
struct is_const_helper : bool_constant<C>
21+
{
22+
NBL_CONSTEXPR_STATIC_INLINE bool is_constant = is_const<T>::value;
23+
};
24+
25+
enum e_member_presence
26+
{
27+
absent = 0,
28+
non_static = 1,
29+
as_static = 2,
30+
static_constexpr = 3,
31+
};
32+
33+
template<class T>
34+
T declval(){}
35+
36+
}
37+
38+
typedef impl::e_member_presence e_member_presence;
39+
}
40+
41+
}
42+
43+
44+
#define NBL_GENERATE_MEMBER_TESTER(a) \
45+
namespace nbl \
46+
{ \
47+
namespace hlsl \
48+
{ \
49+
namespace impl { \
50+
template<class T, class=void> \
51+
struct is_static_member_##a: false_type {NBL_CONSTEXPR_STATIC_INLINE bool is_constant = false; }; \
52+
template<class T> \
53+
struct is_static_member_##a<T,typename enable_if<!is_same<decltype(T::a),void>::value,void>::type>: is_const_helper<decltype(T::a), true> {}; \
54+
template<class T, class=void> \
55+
struct is_member_##a: false_type {NBL_CONSTEXPR_STATIC_INLINE bool is_constant = false;}; \
56+
template<class T> \
57+
struct is_member_##a<T,typename enable_if<!is_same<decltype(declval<T>().a),void>::value,void>::type> : is_const_helper<decltype(declval<T>().a), true>{}; \
58+
} \
59+
template<class T> \
60+
struct has_member_##a { NBL_CONSTEXPR_STATIC_INLINE e_member_presence value = (e_member_presence)(impl::is_member_##a<T>::value + impl::is_static_member_##a<T>::value + impl::is_static_member_##a<T>::is_constant); }; \
61+
} \
62+
}
63+
64+
65+
NBL_GENERATE_MEMBER_TESTER(x)
66+
NBL_GENERATE_MEMBER_TESTER(y)
67+
NBL_GENERATE_MEMBER_TESTER(z)
68+
NBL_GENERATE_MEMBER_TESTER(w)
69+
70+
#endif
71+
#endif

include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ void memoryBarrier(uint32_t memoryScope, uint32_t memorySemantics);
114114

115115
// Add specializations if you need to emit a `ext_capability` (this means that the instruction needs to forward through an `impl::` struct and so on)
116116
template<class T, class U>
117-
// [[vk::ext_extension("SPV_KHR_physical_storage_buffer")]]
118-
// [[vk::ext_capability(spv::CapabilityPhysicalStorageBufferAddresses)]]
119-
// [[vk::ext_capability(spv::CapabilityAddresses)]]
120-
// [[vk::ext_capability(spv::CapabilityFloat64)]]
121117
[[vk::ext_instruction(spv::OpBitcast)]]
122118
T bitcast(U);
123119

include/nbl/builtin/hlsl/type_traits.hlsl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ using integral_constant = std::integral_constant<T, val>;
480480
template<bool val>
481481
using bool_constant = std::bool_constant<val>;
482482

483+
using true_type = std::true_type;
484+
using false_type = std::false_type;
485+
483486
template <bool C, class T, class F>
484487
using conditional = std::conditional<C, T, F>;
485488

src/nbl/builtin/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/limits.hlsl")
249249
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/type_traits.hlsl")
250250
#metaprogramming
251251
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/mpl.hlsl")
252+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/member_test_macros.hlsl")
252253
#extra math
253254
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/math/quadrature/gauss_legendre/gauss_legendre.hlsl")
254255
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/math/quadrature/gauss_legendre/impl.hlsl")

0 commit comments

Comments
 (0)