Skip to content

Commit 5a8fd45

Browse files
put PoolAddressAllocator on a diet and get rid of the remnant of old times supportsNullBuffer
1 parent e40dbbf commit 5a8fd45

8 files changed

+22
-86
lines changed

include/nbl/core/alloc/GeneralpurposeAddressAllocator.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,6 @@ class GeneralpurposeAddressAllocator : public AddressAllocatorBase<Generalpurpos
440440
public:
441441
_NBL_DECLARE_ADDRESS_ALLOCATOR_TYPEDEFS(_size_type);
442442

443-
static constexpr bool supportsNullBuffer = true;
444-
445443
#define DUMMY_DEFAULT_CONSTRUCTOR GeneralpurposeAddressAllocator() noexcept : AllocStrategy(invalid_address,invalid_address) {}
446444
GCC_CONSTRUCTOR_INHERITANCE_BUG_WORKAROUND(DUMMY_DEFAULT_CONSTRUCTOR)
447445
#undef DUMMY_DEFAULT_CONSTRUCTOR
@@ -465,7 +463,7 @@ class GeneralpurposeAddressAllocator : public AddressAllocatorBase<Generalpurpos
465463
AllocStrategy(newBuffSz-Base::alignOffset,std::move(other),newReservedSpc)
466464
{
467465
}
468-
//! When resizing we require that the copying of data buffer has already been handled by the user of the address allocator even if `supportsNullBuffer==true`
466+
//! When resizing we require that the copying of data buffer has already been handled by the user of the address allocator
469467
template<typename... Args>
470468
GeneralpurposeAddressAllocator(size_type newBuffSz, GeneralpurposeAddressAllocator&& other, void* newReservedSpc, Args&&... args) noexcept :
471469
Base(std::move(other),newReservedSpc,std::forward<Args>(args)...),

include/nbl/core/alloc/HeterogenousMemoryAddressAllocatorAdaptor.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,7 @@ class HeterogenousMemoryAddressAllocatorAdaptor : public impl::HeterogenousMemor
116116
AddressAllocator(ImplBase::mReservedAlloc.allocate(ImplBase::mReservedSize,_NBL_SIMD_ALIGNMENT),
117117
addressOffsetToApply,alignOffsetNeeded,maxAllocatableAlignment,bufSz,std::forward<Args>(args)...)
118118
{
119-
mAllocation = ImplBase::mDataAlloc.allocate(bufSz,maxAllocatableAlignment);
120-
if constexpr(!alloc_traits::supportsNullBuffer)
121-
{
122-
this->getBaseAddrAllocRef().setDataBufferPtr(std::get<1u>(mAllocation));
123-
}
124-
119+
mAllocation = ImplBase::mDataAlloc.allocate(bufSz,maxAllocatableAlignment);
125120
}
126121

127122
virtual ~HeterogenousMemoryAddressAllocatorAdaptor()

include/nbl/core/alloc/LinearAddressAllocator.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ class LinearAddressAllocator : public AddressAllocatorBase<LinearAddressAllocato
2020
public:
2121
_NBL_DECLARE_ADDRESS_ALLOCATOR_TYPEDEFS(_size_type);
2222

23-
static constexpr bool supportsNullBuffer = true;
24-
2523
#define DUMMY_DEFAULT_CONSTRUCTOR LinearAddressAllocator() : bufferSize(invalid_address), cursor(invalid_address) {}
2624
GCC_CONSTRUCTOR_INHERITANCE_BUG_WORKAROUND(DUMMY_DEFAULT_CONSTRUCTOR)
2725
#undef DUMMY_DEFAULT_CONSTRUCTOR
@@ -34,7 +32,7 @@ class LinearAddressAllocator : public AddressAllocatorBase<LinearAddressAllocato
3432
reset();
3533
}
3634

37-
//! When resizing we require that the copying of data buffer has already been handled by the user of the address allocator even if `supportsNullBuffer==true`
35+
//! When resizing we require that the copying of data buffer has already been handled by the user of the address allocator
3836
template<typename... Args>
3937
LinearAddressAllocator(_size_type newBuffSz, LinearAddressAllocator&& other, Args&&... args) :
4038
Base(std::move(other),std::forward<Args>(args)...), bufferSize(invalid_address), cursor(invalid_address)

include/nbl/core/alloc/PoolAddressAllocator.h

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,19 @@ class PoolAddressAllocator : public AddressAllocatorBase<PoolAddressAllocator<_s
3232
#endif // _NBL_DEBUG
3333

3434
for (size_type i=0u; i<freeStackCtr; i++)
35-
freeStack[i] = (blockCount-1u-i)*blockSize+Base::combinedOffset;
35+
getFreeStack(i) = (blockCount-1u-i)*blockSize+Base::combinedOffset;
3636

3737
for (size_type i=0; i<other.freeStackCtr; i++)
3838
{
39-
size_type freeEntry = other.freeStack[i]-other.combinedOffset;
39+
size_type freeEntry = other.getFreeStack(i)-other.combinedOffset;
4040

4141
if (freeEntry<blockCount*blockSize)
42-
freeStack[freeStackCtr++] = freeEntry+Base::combinedOffset;
42+
getFreeStack(freeStackCtr++) = freeEntry+Base::combinedOffset;
4343
}
4444
}
4545
public:
4646
_NBL_DECLARE_ADDRESS_ALLOCATOR_TYPEDEFS(_size_type);
4747

48-
static constexpr bool supportsNullBuffer = true;
49-
5048
#define DUMMY_DEFAULT_CONSTRUCTOR PoolAddressAllocator() : blockSize(1u), blockCount(0u) {}
5149
GCC_CONSTRUCTOR_INHERITANCE_BUG_WORKAROUND(DUMMY_DEFAULT_CONSTRUCTOR)
5250
#undef DUMMY_DEFAULT_CONSTRUCTOR
@@ -55,16 +53,16 @@ class PoolAddressAllocator : public AddressAllocatorBase<PoolAddressAllocator<_s
5553

5654
PoolAddressAllocator(void* reservedSpc, _size_type addressOffsetToApply, _size_type alignOffsetNeeded, _size_type maxAllocatableAlignment, size_type bufSz, size_type blockSz) noexcept :
5755
Base(reservedSpc,addressOffsetToApply,alignOffsetNeeded,maxAllocatableAlignment),
58-
blockCount((bufSz-alignOffsetNeeded)/blockSz), blockSize(blockSz), freeStack(reinterpret_cast<size_type*>(Base::reservedSpace)), freeStackCtr(0u)
56+
blockCount((bufSz-alignOffsetNeeded)/blockSz), blockSize(blockSz), freeStackCtr(0u)
5957
{
6058
reset();
6159
}
6260

63-
//! When resizing we require that the copying of data buffer has already been handled by the user of the address allocator even if `supportsNullBuffer==true`
61+
//! When resizing we require that the copying of data buffer has already been handled by the user of the address allocator
6462
template<typename... Args>
6563
PoolAddressAllocator(_size_type newBuffSz, PoolAddressAllocator&& other, Args&&... args) noexcept :
6664
Base(std::move(other),std::forward<Args>(args)...),
67-
blockCount((newBuffSz-Base::alignOffset)/other.blockSize), blockSize(other.blockSize), freeStack(reinterpret_cast<size_type*>(Base::reservedSpace)), freeStackCtr(0u)
65+
blockCount((newBuffSz-Base::alignOffset)/other.blockSize), blockSize(other.blockSize), freeStackCtr(0u)
6866
{
6967
copyState(other, newBuffSz);
7068

@@ -76,7 +74,7 @@ class PoolAddressAllocator : public AddressAllocatorBase<PoolAddressAllocator<_s
7674
template<typename... Args>
7775
PoolAddressAllocator(_size_type newBuffSz, const PoolAddressAllocator& other, Args&&... args) noexcept :
7876
Base(other, std::forward<Args>(args)...),
79-
blockCount((newBuffSz-Base::alignOffset)/other.blockSize), blockSize(other.blockSize), freeStack(reinterpret_cast<size_type*>(Base::reservedSpace)), freeStackCtr(0u)
77+
blockCount((newBuffSz-Base::alignOffset)/other.blockSize), blockSize(other.blockSize), freeStackCtr(0u)
8078
{
8179
copyState(other, newBuffSz);
8280
}
@@ -86,7 +84,6 @@ class PoolAddressAllocator : public AddressAllocatorBase<PoolAddressAllocator<_s
8684
Base::operator=(std::move(other));
8785
std::swap(blockCount,other.blockCount);
8886
std::swap(blockSize,other.blockSize);
89-
std::swap(freeStack,other.freeStack);
9087
std::swap(freeStackCtr,other.freeStackCtr);
9188
return *this;
9289
}
@@ -97,21 +94,21 @@ class PoolAddressAllocator : public AddressAllocatorBase<PoolAddressAllocator<_s
9794
if (freeStackCtr==0u || (blockSize%alignment)!=0u || bytes==0u || bytes>blockSize)
9895
return invalid_address;
9996

100-
return freeStack[--freeStackCtr];
97+
return getFreeStack(--freeStackCtr);
10198
}
10299

103100
inline void free_addr(size_type addr, size_type bytes) noexcept
104101
{
105102
#ifdef _NBL_DEBUG
106103
assert(addr>=Base::combinedOffset && (addr-Base::combinedOffset)%blockSize==0 && freeStackCtr<blockCount);
107104
#endif // _NBL_DEBUG
108-
freeStack[freeStackCtr++] = addr;
105+
getFreeStack(freeStackCtr++) = addr;
109106
}
110107

111108
inline void reset()
112109
{
113110
for (freeStackCtr=0u; freeStackCtr<blockCount; freeStackCtr++)
114-
freeStack[freeStackCtr] = (blockCount-1u-freeStackCtr)*blockSize+Base::combinedOffset;
111+
getFreeStack(freeStackCtr) = (blockCount-1u-freeStackCtr)*blockSize+Base::combinedOffset;
115112
}
116113

117114
//! conservative estimate, does not account for space lost to alignment
@@ -139,12 +136,12 @@ class PoolAddressAllocator : public AddressAllocatorBase<PoolAddressAllocator<_s
139136
if (allocSize>sizeBound)
140137
sizeBound = allocSize;
141138

142-
auto tmpStackCopy = freeStack+freeStackCtr;
139+
auto tmpStackCopy = &getFreeStack(freeStackCtr);
143140

144141
size_type boundedCount = 0;
145142
for (size_type i=0; i<freeStackCtr; i++)
146143
{
147-
auto freeAddr = freeStack[i];
144+
auto freeAddr = getFreeStack(i);
148145
if (freeAddr<sizeBound+Base::combinedOffset)
149146
continue;
150147

@@ -206,8 +203,10 @@ class PoolAddressAllocator : public AddressAllocatorBase<PoolAddressAllocator<_s
206203
// although to implement that one of the heaps would have to be in reverse in the memory (no wiggle room)
207204
// then can minimize fragmentation due to allocation and give lighting fast returns from `safe_shrink_size`
208205
// but then should probably have two pool allocators, because doing that changes insertion/removal from O(1) to O(log(N))
209-
size_type* freeStack;
210206
size_type freeStackCtr;
207+
208+
inline size_type& getFreeStack(size_type i) {return reinterpret_cast<size_type*>(Base::reservedSpace)[i];}
209+
inline const size_type& getFreeStack(size_type i) const {return reinterpret_cast<const size_type*>(Base::reservedSpace)[i];}
211210
};
212211

213212

include/nbl/core/alloc/ResizableHeterogenousMemoryAllocator.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ namespace core
1818
// if only we could use c++17 if-constexpr
1919
namespace impl
2020
{
21-
template<class HeterogenousMemoryAllocator, bool supportsNullBuffer=HeterogenousMemoryAllocator::alloc_traits::supportsNullBuffer> class ResizableHeterogenousMemoryAllocatorBase;
21+
template<class HeterogenousMemoryAllocator> class ResizableHeterogenousMemoryAllocatorBase;
2222

2323
template<class HeterogenousMemoryAllocator>
24-
class ResizableHeterogenousMemoryAllocatorBase<HeterogenousMemoryAllocator,true> : public HeterogenousMemoryAllocator // make protected?
24+
class ResizableHeterogenousMemoryAllocatorBase : public HeterogenousMemoryAllocator // make protected?
2525
{
2626
protected:
2727
typedef HeterogenousMemoryAllocator Base;
@@ -37,25 +37,6 @@ namespace impl
3737
mAddrAlloc = AddressAllocator(Base::mDataSize,std::move(mAddrAlloc),newReserved);
3838
}
3939
};
40-
41-
template<class HeterogenousMemoryAllocator>
42-
class ResizableHeterogenousMemoryAllocatorBase<HeterogenousMemoryAllocator,false> : public HeterogenousMemoryAllocator // make protected?
43-
{
44-
protected:
45-
typedef HeterogenousMemoryAllocator Base;
46-
47-
using Base::Base;
48-
49-
inline void resizeAddressAllocator(void* newReserved)
50-
{
51-
using alloc_traits = typename Base::alloc_traits;
52-
using AddressAllocator = typename alloc_traits::allocator_type;
53-
54-
AddressAllocator& mAddrAlloc = Base::getBaseAddrAllocRef();
55-
void* templateDeductionWorkaround = std::get<1u>(Base::mAllocation);
56-
mAddrAlloc = AddressAllocator(templateDeductionWorkaround,Base::mDataSize,std::move(mAddrAlloc),newReserved);
57-
}
58-
};
5940
}
6041

6142
template<class HeterogenousMemoryAllocator>

include/nbl/core/alloc/StackAddressAllocator.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class StackAddressAllocator : protected LinearAddressAllocator<_size_type>
2424

2525
_NBL_DECLARE_ADDRESS_ALLOCATOR_TYPEDEFS(_size_type);
2626

27-
static constexpr bool supportsNullBuffer = true;
28-
2927
#define DUMMY_DEFAULT_CONSTRUCTOR StackAddressAllocator() : minimumAllocSize(invalid_address), allocStackPtr(invalid_address) {}
3028
GCC_CONSTRUCTOR_INHERITANCE_BUG_WORKAROUND(DUMMY_DEFAULT_CONSTRUCTOR)
3129
#undef DUMMY_DEFAULT_CONSTRUCTOR
@@ -35,7 +33,7 @@ class StackAddressAllocator : protected LinearAddressAllocator<_size_type>
3533
StackAddressAllocator(void* reservedSpc, _size_type addressOffsetToApply, _size_type alignOffsetNeeded, _size_type maxAllocatableAlignment, size_type bufSz, size_type minAllocSize) noexcept :
3634
Base(reservedSpc,addressOffsetToApply,alignOffsetNeeded,maxAllocatableAlignment,bufSz), minimumAllocSize(minAllocSize), allocStackPtr(0u) {}
3735

38-
//! When resizing we require that the copying of data buffer has already been handled by the user of the address allocator even if `supportsNullBuffer==true`
36+
//! When resizing we require that the copying of data buffer has already been handled by the user of the address allocator
3937
template<typename... Args>
4038
StackAddressAllocator(size_type newBuffSz, StackAddressAllocator&& other, Args&&... args) :
4139
Base(newBuffSz,std::move(other),std::forward<Args>(args)...), minimumAllocSize(invalid_address), allocStackPtr(invalid_address)

include/nbl/core/alloc/address_allocator_traits.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ namespace core
126126

127127
template<class U> using cstexpr_supportsArbitraryOrderFrees = decltype(std::declval<U&>().supportsArbitraryOrderFrees);
128128
template<class U> using cstexpr_maxMultiOps = decltype(std::declval<U&>().maxMultiOps);
129-
template<class U> using cstexpr_supportsNullBuffer = decltype(std::declval<U&>().supportsNullBuffer);
130129

131130
template<class U> using func_multi_alloc_addr = decltype(std::declval<U&>().multi_alloc_addr(0u,nullptr,nullptr,nullptr,nullptr));
132131
template<class U> using func_multi_free_addr = decltype(std::declval<U&>().multi_free_addr(0u,nullptr,nullptr));
@@ -136,7 +135,6 @@ namespace core
136135
public:
137136
template<class,class=void> struct resolve_supportsArbitraryOrderFrees : std::true_type {};
138137
template<class,class=void> struct resolve_maxMultiOps : std::integral_constant<uint32_t,256u> {};
139-
template<class,class=void> struct resolve_supportsNullBuffer : std::true_type {};
140138

141139
template<class,class=void> struct has_func_multi_alloc_addr : std::false_type {};
142140
template<class,class=void> struct has_func_multi_free_addr : std::false_type {};
@@ -148,8 +146,6 @@ namespace core
148146
: std::conditional<std::true_type/*std::is_same<cstexpr_supportsArbitraryOrderFrees<U>,bool>*/::value,nbl::bool_constant<U::supportsArbitraryOrderFrees>,resolve_supportsArbitraryOrderFrees<void,void> >::type {};
149147
template<class U> struct resolve_maxMultiOps<U,std::void_t<cstexpr_maxMultiOps<U> > >
150148
: std::conditional<std::true_type/*std::is_integral<cstexpr_maxMultiOps<U> >*/::value,std::integral_constant<uint32_t,U::maxMultiOps>, resolve_maxMultiOps<void, void> >::type {};
151-
template<class U> struct resolve_supportsNullBuffer<U,std::void_t<cstexpr_supportsNullBuffer<U> > >
152-
: std::conditional<std::true_type/*std::is_same<cstexpr_supportsNullBuffer<U>,bool>*/::value,nbl::bool_constant<U::supportsNullBuffer>,resolve_supportsNullBuffer<void,void> >::type {};
153149

154150
template<class U> struct has_func_multi_alloc_addr<U,std::void_t<func_multi_alloc_addr<U> > >
155151
: std::is_same<func_multi_alloc_addr<U>,void> {};
@@ -160,7 +156,6 @@ namespace core
160156

161157
_NBL_STATIC_INLINE_CONSTEXPR bool supportsArbitraryOrderFrees = resolve_supportsArbitraryOrderFrees<AddressAlloc>::value;
162158
_NBL_STATIC_INLINE_CONSTEXPR uint32_t maxMultiOps = resolve_maxMultiOps<AddressAlloc>::value;
163-
_NBL_STATIC_INLINE_CONSTEXPR bool supportsNullBuffer = resolve_supportsNullBuffer<AddressAlloc>::value;
164159

165160
static inline void printDebugInfo()
166161
{
@@ -170,7 +165,6 @@ namespace core
170165

171166
printf("supportsArbitraryOrderFrees == %d\n", supportsArbitraryOrderFrees);
172167
printf("maxMultiOps == %d\n", maxMultiOps);
173-
printf("supportsNullBuffer == %d\n", supportsNullBuffer);
174168
}
175169

176170

include/nbl/video/IPropertyPool.h

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,4 @@ class IPropertyPool : public core::IReferenceCounted
112112
}
113113
}
114114

115-
#endif
116-
117-
/*
118-
Old Code
119-
120-
class IMeshSceneNodeInstanced : public ISceneNode
121-
{
122-
struct MeshLoD
123-
{
124-
video::IGPUMesh* mesh;
125-
void* userDataForVAOSetup; //put array of vertex attribute mappings here or something
126-
float lodDistance;
127-
};
128-
129-
virtual bool setLoDMeshes(const core::vector<MeshLoD>& levelsOfDetail, const size_t& dataSizePerInstanceOutput, const video::SGPUMaterial& lodSelectionShader, VaoSetupOverrideFunc vaoSetupOverride,
130-
const size_t shaderLoDsPerPass = 1, void* overrideUserData = NULL, const size_t& extraDataSizePerInstanceInput = 0) = 0;
131-
132-
virtual video::CGPUMesh* getLoDMesh(const size_t& lod) = 0;
133-
134-
135-
virtual const core::aabbox3df& getLoDInvariantBBox() const = 0;
136-
137-
138-
inline void setBBoxUpdateEnabled() { wantBBoxUpdate = true; }
139-
inline void setBBoxUpdateDisabled() { wantBBoxUpdate = false; }
140-
inline const bool& getBBoxUpdateMode() { return wantBBoxUpdate; }
141-
};
142-
*/
115+
#endif

0 commit comments

Comments
 (0)