Skip to content

Commit 6be8aec

Browse files
author
devsh
committed
Merge branch 'master' into nahim_complex_fft_workgroup
Also further imporve the memory_accessor.hlsl
2 parents 46f0e81 + 2dc2bfb commit 6be8aec

18 files changed

+312
-366
lines changed

include/nbl/builtin/hlsl/bit.hlsl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#define _NBL_BUILTIN_HLSL_BIT_INCLUDED_
33

44

5-
#include <nbl/builtin/hlsl/cpp_compat.hlsl>
5+
#include <nbl/builtin/hlsl/macros.h>
66

77

88
#ifndef __HLSL_VERSION
9-
109
#include <bit>
1110

1211
namespace nbl::hlsl
@@ -25,7 +24,6 @@ NBL_ALIAS_TEMPLATE_FUNCTION(std::countl_zero, countl_zero);
2524

2625
}
2726
#else
28-
2927
#include <nbl/builtin/hlsl/spirv_intrinsics/core.hlsl>
3028

3129
namespace nbl
@@ -34,9 +32,9 @@ namespace hlsl
3432
{
3533

3634
template<class T, class U>
37-
enable_if_t<sizeof(T) <= sizeof(U), T> bit_cast(U val)
35+
enable_if_t<sizeof(T)==sizeof(U),T> bit_cast(U val)
3836
{
39-
return spirv::bitcast<T, U>(val);
37+
return spirv::bitcast<T,U>(val);
4038
}
4139

4240
template<typename T, typename S>
Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,9 @@
11
#ifndef _NBL_BUILTIN_HLSL_CPP_COMPAT_INCLUDED_
22
#define _NBL_BUILTIN_HLSL_CPP_COMPAT_INCLUDED_
33

4-
#include <nbl/builtin/hlsl/macros.h>
5-
6-
#ifndef __HLSL_VERSION
7-
#include <type_traits>
8-
#include <bit>
9-
10-
#define ARROW ->
11-
#define NBL_CONSTEXPR constexpr
12-
#define NBL_CONSTEXPR_STATIC constexpr static
13-
#define NBL_CONSTEXPR_STATIC_INLINE constexpr static inline
14-
#define NBL_CONST_MEMBER_FUNC const
15-
16-
#define NBL_ALIAS_TEMPLATE_FUNCTION(origFunctionName, functionAlias) \
17-
template<typename... Args> \
18-
inline auto functionAlias(Args&&... args) -> decltype(origFunctionName(std::forward<Args>(args)...)) \
19-
{ \
20-
return origFunctionName(std::forward<Args>(args)...); \
21-
}
22-
23-
namespace nbl::hlsl
24-
{
25-
26-
template<typename T>
27-
using add_reference = std::add_lvalue_reference<T>;
28-
29-
template<typename T>
30-
using add_pointer = std::add_pointer<T>;
31-
32-
}
33-
34-
// We need variadic macro in order to handle multi parameter templates because the
35-
// preprocessor parses the template parameters as different macro parameters.
36-
#define NBL_REF_ARG(...) typename nbl::hlsl::add_reference<__VA_ARGS__ >::type
37-
#define NBL_CONST_REF_ARG(...) typename nbl::hlsl::add_reference<std::add_const_t<__VA_ARGS__ >>::type
38-
39-
#else
40-
41-
#define ARROW .arrow().
42-
#define NBL_CONSTEXPR const static
43-
#define NBL_CONSTEXPR_STATIC_INLINE const static
44-
#define NBL_CONST_MEMBER_FUNC
45-
46-
namespace nbl
47-
{
48-
namespace hlsl
49-
{
50-
51-
#if 0 // TODO: for later
52-
template<typename T>
53-
struct add_reference
54-
{
55-
using type = ref<T>;
56-
};
57-
template<typename T>
58-
struct add_pointer
59-
{
60-
using type = ptr<T>;
61-
};
62-
#endif
63-
64-
}
65-
}
66-
67-
#define NBL_REF_ARG(...) inout __VA_ARGS__
68-
#define NBL_CONST_REF_ARG(...) const in __VA_ARGS__
69-
70-
#endif
71-
4+
#include <nbl/builtin/hlsl/cpp_compat/basic.h>
725
// it includes vector and matrix
736
#include <nbl/builtin/hlsl/cpp_compat/intrinsics.h>
7+
#include <nbl/builtin/hlsl/cpp_compat/promote.hlsl>
748

759
#endif
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#ifndef _NBL_BUILTIN_HLSL_CPP_COMPAT_BASIC_INCLUDED_
2+
#define _NBL_BUILTIN_HLSL_CPP_COMPAT_BASIC_INCLUDED_
3+
4+
#include <nbl/builtin/hlsl/macros.h>
5+
6+
#ifndef __HLSL_VERSION
7+
#include <type_traits>
8+
9+
#define ARROW ->
10+
#define NBL_CONSTEXPR constexpr // TODO: rename to NBL_CONSTEXPR_VAR
11+
#define NBL_CONSTEXPR_FUNC constexpr
12+
#define NBL_CONSTEXPR_STATIC constexpr static
13+
#define NBL_CONSTEXPR_STATIC_INLINE constexpr static inline
14+
#define NBL_CONST_MEMBER_FUNC const
15+
16+
namespace nbl::hlsl
17+
{
18+
template<typename T, typename U>
19+
T _static_cast(U v)
20+
{
21+
return static_cast<T>(v);
22+
}
23+
24+
template<typename T>
25+
using add_reference = std::add_lvalue_reference<T>;
26+
27+
template<typename T>
28+
using add_pointer = std::add_pointer<T>;
29+
30+
}
31+
32+
// We need variadic macro in order to handle multi parameter templates because the
33+
// preprocessor parses the template parameters as different macro parameters.
34+
#define NBL_REF_ARG(...) typename nbl::hlsl::add_reference<__VA_ARGS__ >::type
35+
#define NBL_CONST_REF_ARG(...) typename nbl::hlsl::add_reference<std::add_const_t<__VA_ARGS__ >>::type
36+
37+
#else
38+
39+
#define ARROW .arrow().
40+
#define NBL_CONSTEXPR const static // TODO: rename to NBL_CONSTEXPR_VAR
41+
#define NBL_CONSTEXPR_FUNC
42+
#define NBL_CONSTEXPR_STATIC const static
43+
#define NBL_CONSTEXPR_STATIC_INLINE const static
44+
#define NBL_CONST_MEMBER_FUNC
45+
46+
namespace nbl
47+
{
48+
namespace hlsl
49+
{
50+
template<typename T, typename U>
51+
T _static_cast(U v)
52+
{
53+
return (T)v;
54+
}
55+
56+
#if 0 // TODO: for later
57+
template<typename T>
58+
struct add_reference
59+
{
60+
using type = ref<T>;
61+
};
62+
template<typename T>
63+
struct add_pointer
64+
{
65+
using type = ptr<T>;
66+
};
67+
#endif
68+
69+
}
70+
}
71+
72+
#define NBL_REF_ARG(...) inout __VA_ARGS__
73+
#define NBL_CONST_REF_ARG(...) const in __VA_ARGS__
74+
75+
#endif
76+
77+
#endif

include/nbl/builtin/hlsl/macros.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414
[branch] if (!con) \
1515
vk::RawBufferStore<uint32_t>(0xdeadbeefBADC0FFbull,0x45u,4u); \
1616
} while(!con); \
17-
}
17+
}
18+
#else
19+
20+
#define NBL_ALIAS_TEMPLATE_FUNCTION(origFunctionName, functionAlias) \
21+
template<typename... Args> \
22+
inline auto functionAlias(Args&&... args) -> decltype(origFunctionName(std::forward<Args>(args)...)) \
23+
{ \
24+
return origFunctionName(std::forward<Args>(args)...); \
25+
}
26+
1827
#endif
1928

2029
#ifdef __HLSL_VERSION // cause DXC is insane

include/nbl/builtin/hlsl/member_test_macros.hlsl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct has_method_##x<T BOOST_PP_REPEAT(n, NBL_TYPE_FWD, n), typename make_void<
108108
due to how we check function signatures at the moment
109109
*/
110110

111+
// TODO: these should probably generate without a namespace and be expected to be put inside a namespace
111112
#define GENERATE_METHOD_TESTER(x) \
112113
namespace nbl { \
113114
namespace hlsl { \
@@ -118,8 +119,10 @@ BOOST_PP_REPEAT(4, GENERATE_METHOD_TESTER_SPEC, x) \
118119
}}
119120

120121

121-
GENERATE_METHOD_TESTER(a)
122-
GENERATE_METHOD_TESTER(b)
122+
GENERATE_METHOD_TESTER(a) // TODO: remove
123+
GENERATE_METHOD_TESTER(b) // TODO: remove
124+
GENERATE_METHOD_TESTER(get)
125+
GENERATE_METHOD_TESTER(set)
123126

124127

125128
#endif

0 commit comments

Comments
 (0)