Skip to content

Commit a8ff88f

Browse files
author
devsh
committed
fix up NBL_HLSL_DEFINE_STRUCT to allow for methods, make some notes about what structs we can't currently service
1 parent 79a40be commit a8ff88f

File tree

3 files changed

+49
-32
lines changed

3 files changed

+49
-32
lines changed

include/nbl/builtin/hlsl/bda/struct_declare.hlsl

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,37 +123,51 @@ BOOST_PP_SEQ_FOR_EACH_I(NBL_HLSL_IMPL_DEFINE_STRUCT_MEMBER,IDENTIFIER,MEMBER_SEQ
123123
}
124124
#endif
125125

126-
#include <boost/preprocessor/seq/for_each_i.hpp>
127-
#include <boost/preprocessor/seq/size.hpp>
128-
// MEMBER_SEQ is to be a sequence of variable name and type (identifier0,Type0)...(identifierN,TypeN) @see NBL_HLSL_IMPL_DEFINE_STRUCT_GET_MEMBER_TYPE
129-
// the VA_ARGS is the struct alignment for alignas, usage example
130-
// ```
131-
// NBL_HLSL_DEFINE_STRUCT((MyStruct2),
132-
// ((a, float32_t))
133-
// ((b, int32_t))
134-
// ((c, int32_t2))
135-
// );
136-
// ```
137-
#define NBL_HLSL_DEFINE_STRUCT(IDENTIFIER,MEMBER_SEQ, ...) template<> \
126+
// some weird stuff to handle alignment
127+
#define NBL_HLSL_IMPL_DEFINE_STRUCT_BEGIN(IDENTIFIER,MEMBER_SEQ) template<> \
138128
struct ::nbl::hlsl::bda::member_count<NBL_EVAL IDENTIFIER > \
139129
{ \
140130
NBL_CONSTEXPR_STATIC_INLINE uint32_t value = BOOST_PP_SEQ_SIZE(MEMBER_SEQ); \
141131
}; \
142132
BOOST_PP_SEQ_FOR_EACH_I(NBL_HLSL_IMPL_DEFINE_STRUCT_MEMBER_TYPE,IDENTIFIER,MEMBER_SEQ) \
143133
template <> \
144134
struct ::nbl::hlsl::alignment_of<NBL_EVAL IDENTIFIER > \
145-
{ \
146-
NBL_CONSTEXPR_STATIC_INLINE uint32_t value = nbl::hlsl::conditional_value<true __VA_OPT__(&&false),uint32_t,::nbl::hlsl::bda::impl::default_alignment_v<NBL_EVAL IDENTIFIER >,__VA_OPT__((__VA_ARGS__)-)0>::value; \
147-
}; \
135+
{
136+
#define NBL_HLSL_IMPL_DEFINE_STRUCT_END(IDENTIFIER,MEMBER_SEQ,...) }; \
148137
template<> \
149138
struct ::nbl::hlsl::size_of<NBL_EVAL IDENTIFIER > \
150139
{ \
151140
using type = NBL_EVAL IDENTIFIER; \
152141
NBL_CONSTEXPR_STATIC_INLINE uint32_t __last_member_ix_v = ::nbl::hlsl::bda::member_count_v<type>-1; \
153-
NBL_CONSTEXPR_STATIC_INLINE uint64_t __last_member_offset_v = ::nbl::hlsl::bda::member_offset_v<type,__last_member_ix_v>; \
154-
NBL_CONSTEXPR_STATIC_INLINE uint64_t __last_member_size_v = ::nbl::hlsl::size_of_v<::nbl::hlsl::bda::member_type_t<type,__last_member_ix_v> >; \
155-
NBL_CONSTEXPR_STATIC_INLINE uint32_t value = ::nbl::hlsl::mpl::align_up_v<__last_member_offset_v+__last_member_size_v,alignment_of_v<type > >; \
142+
NBL_CONSTEXPR_STATIC_INLINE uint64_t __last_member_offset_v = ::nbl::hlsl::bda::member_offset_v<type, __last_member_ix_v>; \
143+
NBL_CONSTEXPR_STATIC_INLINE uint64_t __last_member_size_v = ::nbl::hlsl::size_of_v<::nbl::hlsl::bda::member_type_t<type, __last_member_ix_v> >; \
144+
NBL_CONSTEXPR_STATIC_INLINE uint32_t value = ::nbl::hlsl::mpl::align_up_v<__last_member_offset_v + __last_member_size_v, alignment_of_v<type > >; \
145+
\
146+
__VA_ARGS__ \
147+
\
156148
}; \
157149
struct NBL_HLSL_IMPL_DEFINE_STRUCT(IDENTIFIER,MEMBER_SEQ)
158150

151+
#include <boost/preprocessor/seq/for_each_i.hpp>
152+
#include <boost/preprocessor/seq/size.hpp>
153+
// MEMBER_SEQ is to be a sequence of variable name and type (identifier0,Type0)...(identifierN,TypeN) @see NBL_HLSL_IMPL_DEFINE_STRUCT_GET_MEMBER_TYPE
154+
// the VA_ARGS is the struct alignment for alignas, usage example
155+
// ```
156+
// NBL_HLSL_DEFINE_STRUCT((MyStruct2),
157+
// ((a, float32_t))
158+
// ((b, int32_t))
159+
// ((c, int32_t2)),
160+
//
161+
// ... block of code for the methods ...
162+
//
163+
// );
164+
// ```
165+
#define NBL_HLSL_DEFINE_STRUCT(IDENTIFIER,MEMBER_SEQ,...) NBL_HLSL_IMPL_DEFINE_STRUCT_BEGIN(IDENTIFIER,MEMBER_SEQ) \
166+
NBL_CONSTEXPR_STATIC_INLINE uint32_t value = ::nbl::hlsl::bda::impl::default_alignment_v<NBL_EVAL IDENTIFIER >; \
167+
NBL_HLSL_IMPL_DEFINE_STRUCT_END(IDENTIFIER,MEMBER_SEQ,__VA_ARGS__)
168+
// version allowing custom alignment on whole struct
169+
#define NBL_HLSL_DEFINE_ALIGNAS_STRUCT(IDENTIFIER,ALIGNMENT,MEMBER_SEQ,...) NBL_HLSL_IMPL_DEFINE_STRUCT_BEGIN(IDENTIFIER,MEMBER_SEQ) \
170+
NBL_CONSTEXPR_STATIC_INLINE uint32_t value = ALIGNMENT; \
171+
NBL_HLSL_IMPL_DEFINE_STRUCT_END(IDENTIFIER,MEMBER_SEQ,__VA_ARGS__)
172+
159173
#endif

include/nbl/builtin/hlsl/complex.hlsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace nbl
5252
namespace hlsl
5353
{
5454

55+
// TODO: make this BDA compatible (no unspecialized templates yet)
5556
template<typename Scalar>
5657
struct complex_t
5758
{

include/nbl/ext/ImGui/builtin/hlsl/common.hlsl

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,30 @@
22
#define _NBL_IMGUI_EXT_COMMON_HLSL_
33

44
#include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
5+
#include "nbl/builtin/hlsl/bda/struct_declare.hlsl"
56

67
namespace nbl
78
{
89
namespace ext
910
{
1011
namespace imgui
1112
{
12-
struct PushConstants
13-
{
14-
uint64_t elementBDA;
15-
uint64_t elementCount;
16-
nbl::hlsl::float32_t2 scale;
17-
nbl::hlsl::float32_t2 translate;
18-
nbl::hlsl::float32_t4 viewport;
19-
};
13+
struct PushConstants
14+
{
15+
uint64_t elementBDA;
16+
uint64_t elementCount;
17+
nbl::hlsl::float32_t2 scale;
18+
nbl::hlsl::float32_t2 translate;
19+
nbl::hlsl::float32_t4 viewport;
20+
};
2021

21-
struct PerObjectData
22-
{
23-
uint32_t aabbMin, aabbMax; //! snorm16_t2 packed as [uint16_t, uint16_t]
24-
uint32_t texId : 26;
25-
uint32_t samplerIx : 6;
26-
};
22+
// would like to replace with our own BDA, but can't do bitfields right now (would need a different wrapper for those)
23+
struct PerObjectData
24+
{
25+
uint32_t aabbMin, aabbMax; //! snorm16_t2 packed as [uint16_t, uint16_t]
26+
uint32_t texId : 26;
27+
uint32_t samplerIx : 6;
28+
};
2729
}
2830
}
2931
}

0 commit comments

Comments
 (0)