Skip to content

Commit

Permalink
workaround Boost.Wave bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
devshgraphicsprogramming committed Nov 29, 2023
1 parent cc37325 commit 145fac5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
9 changes: 2 additions & 7 deletions include/nbl/builtin/hlsl/spirv_intrinsics/core.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace hlsl
namespace spirv
{

#pragma region ATOMICS
template<typename T>
T atomicAdd([[vk::ext_reference]] T ptr, uint32_t memoryScope, uint32_t memorySemantics, T value);
template<>
Expand Down Expand Up @@ -95,9 +94,9 @@ int32_t atomicCompSwap([[vk::ext_reference]] int32_t ptr, uint32_t memoryScope,
template<>
[[vk::ext_instruction( spv::OpAtomicCompareExchange )]]
uint32_t atomicCompSwap([[vk::ext_reference]] uint32_t ptr, uint32_t memoryScope, uint32_t memSemanticsEqual, uint32_t memSemanticsUnequal, uint32_t value, uint32_t comparator);
#pragma endregion ATOMICS

#pragma region BARRIERS


// Memory Semantics link here: https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#Memory_Semantics_-id-

// https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_memory_semantics_id
Expand All @@ -108,16 +107,12 @@ void controlBarrier(uint32_t executionScope, uint32_t memoryScope, uint32_t memo

[[vk::ext_instruction( spv::OpMemoryBarrier )]]
void memoryBarrier(uint32_t memoryScope, uint32_t memorySemantics);
#pragma endregion BARRIERS

#pragma region CONVERSION

// 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)
template<class T, class U>
[[vk::ext_instruction(spv::OpBitcast)]]
T bitcast(U);

#pragma endregion CONVERSION
}
#endif
}
Expand Down
8 changes: 5 additions & 3 deletions include/nbl/builtin/hlsl/type_traits.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -662,16 +662,18 @@ struct unsigned_integer_of_size<8>
// shoudl really return a std::type_info like struct or something, but no `constexpr` and unsure whether its possible to have a `const static SomeStruct` makes it hard to do...
#define typeid(expr) (::nbl::hlsl::impl::typeid_t<__decltype(expr)>::value)

#define NBL_REGISTER_OBJ_TYPE(T, A) namespace nbl { namespace hlsl { \
namespace impl { template<> struct typeid_t<T> : integral_constant<uint32_t,__COUNTER__> {}; } \
// Found a bug in Boost.Wave, try to avoid multi-line macros https://github.com/boostorg/wave/issues/195
#define NBL_IMPL_SPECIALIZE_TYPE_ID(T) namespace impl { template<> struct typeid_t<T> : integral_constant<uint32_t,__COUNTER__> {}; }

#define NBL_REGISTER_OBJ_TYPE(T,A) namespace nbl { namespace hlsl { NBL_IMPL_SPECIALIZE_TYPE_ID(T) \
template<> struct alignment_of<T> : integral_constant<uint32_t,A> {}; \
template<> struct alignment_of<const T> : integral_constant<uint32_t,A> {}; \
template<> struct alignment_of<typename impl::add_lvalue_reference<T>::type> : integral_constant<uint32_t,A> {}; \
template<> struct alignment_of<typename impl::add_lvalue_reference<const T>::type> : integral_constant<uint32_t,A> {}; \
}}

// TODO: find out how to do it such that we don't get duplicate definition if we use two function identifiers with same signature
#define NBL_REGISTER_FUN_TYPE(fn) namespace nbl { namespace hlsl { template<> struct typeid_t<__decltype(fn)> : integral_constant<uint32_t,__COUNTER__> {}; }}
#define NBL_REGISTER_FUN_TYPE(fn) namespace nbl { namespace hlsl { NBL_IMPL_SPECIALIZE_TYPE_ID(__decltype(fn)) }}
// TODO: ideally we'd like to call NBL_REGISTER_FUN_TYPE under the hood, but we can't right now. Also we have a bigger problem, the passing of the function identifier as the second template parameter doesn't work :(
/*
template<> \
Expand Down
4 changes: 2 additions & 2 deletions src/nbl/asset/utils/waveContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ class context : private boost::noncopyable
, macros(*this_())
, language(language_support(
support_cpp20
| support_option_convert_trigraphs
| support_option_preserve_comments
| support_option_emit_line_directives
| support_option_emit_pragma_directives
| support_option_insert_whitespace
// | support_option_emit_contnewlines
// | support_option_insert_whitespace
))
, hooks(hooks_)
{
Expand Down

0 comments on commit 145fac5

Please sign in to comment.