Skip to content

Commit 8469d0f

Browse files
fix bugs (false assert triggers)
1 parent 84a290e commit 8469d0f

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

include/nbl/builtin/hlsl/macros.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#ifdef __HLSL_VERSION
88
#define static_assert(...) _Static_assert(__VA_ARGS__)
9+
// TODO: switch between enabled and disabled depending on Nabla build config
910
#define assert(expr) \
1011
{ \
1112
bool con = (expr); \

include/nbl/builtin/hlsl/workgroup/ballot.hlsl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace impl
2020
uint16_t getDWORD(uint16_t invocation)
2121
{
2222
uint16_t dword = invocation>>5;
23-
assert(dword<((Volume()+31)>>5));
2423
return dword; // log2 of sizeof(uint32_t)*8
2524
}
2625

@@ -29,6 +28,10 @@ uint16_t BallotDWORDCount(const uint16_t itemCount)
2928
{
3029
return getDWORD(itemCount+31); // round up, in case all items don't fit in even number of DWORDs
3130
}
31+
32+
// this silly thing exists only because we can't make the above `constexpr`
33+
template<uint16_t ItemCount>
34+
struct ballot_dword_count : integral_constant<uint16_t,((ItemCount+31)>>5)> {};
3235
}
3336

3437
/**
@@ -55,17 +58,15 @@ void ballot(const bool value, NBL_REF_ARG(Accessor) accessor)
5558
if (initialize)
5659
accessor.set(index,0u);
5760

58-
accessor.ballot.workgroupExecutionAndMemoryBarrier();
61+
accessor.workgroupExecutionAndMemoryBarrier();
5962
if(value)
60-
{
61-
uint32_t dummy;
62-
accessor.atomicOr(impl::getDWORD(index),1u<<(index&31u),dummy);
63-
}
63+
accessor.atomicOr(impl::getDWORD(index),1u<<(index&31u));
6464
}
6565

6666
template<class Accessor>
6767
bool ballotBitExtract(const uint16_t index, NBL_REF_ARG(Accessor) accessor)
6868
{
69+
assert(index<Volume());
6970
return bool(accessor.get(impl::getDWORD(index))&(1u<<(index&31u)));
7071
}
7172

include/nbl/builtin/hlsl/workgroup/basic.hlsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ uint16_t Volume()
2525

2626
uint16_t SubgroupContiguousIndex()
2727
{
28-
return uint16_t(glsl::gl_SubgroupID()*glsl::gl_SubgroupSize()+glsl::gl_SubgroupInvocationID());
28+
const uint16_t retval = (uint16_t(glsl::gl_SubgroupID())<<glsl::gl_SubgroupSizeLog2())+uint16_t(glsl::gl_SubgroupInvocationID());
29+
assert(retval<Volume());
30+
return retval;
2931
}
3032

3133
bool Elect()

src/nbl/builtin/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup/basic.hlsl")
276276
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup/ballot.hlsl")
277277
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup/broadcast.hlsl")
278278
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup/scratch_size.hlsl")
279-
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup/shared_Scan.hlsl")
279+
LIST_BUILTIN_RESOURCE(NBL_RESOURCES_TO_EMBED "hlsl/workgroup/shared_scan.hlsl")
280280

281281

282282
macro(NBL_ADD_BUILTIN_RESOURCES _TARGET_) # internal & Nabla only, must be added with the macro to properly propagate scope

0 commit comments

Comments
 (0)