Skip to content

Commit da60a7b

Browse files
TODOs for @PrzemoG
Also where is CGPUMeshPackerV1 that can be constructed from CCPUMeshPackerV1?
1 parent 2e02e6a commit da60a7b

File tree

6 files changed

+33
-36
lines changed

6 files changed

+33
-36
lines changed

examples_tests/21.DynamicTextureIndexing/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
//! I advise to check out this file, its a basic input handler
99
#include "../common/QToQuitEventReceiver.h"
10-
#include "nbl/asset/utils/CCPUMeshPacker.h"
1110

1211
using namespace nbl;
1312
using namespace core;

include/nbl/asset/utils/CCPUMeshPackerV1.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
//AFTER SAFE SHRINK FIX TODO LIST:
1313
//1. new size for buffers (obviously)
14-
//3. Chandle case where (maxIdx - minIdx) > 0xFFFF
15-
//4. fix handling of per instance attributes
1614
//5. make it work for multiple `alloc` calls
1715
//6. provide `free` method
1816
//7. assertions on buffer overflow
@@ -73,6 +71,7 @@ class CCPUMeshPackerV1 final : public IMeshPacker<ICPUMeshBuffer, MDIStructType>
7371
using IdxBufferParams = typename base_t::IdxBufferParams;
7472

7573
public:
74+
// TODO: dont track the supported bytesize after constructing the mesh packer, its redundant information... its in your per_instance allocator size
7675
struct AllocationParams : IMeshPackerBase::AllocationParamsCommon
7776
{
7877
// Maximum byte size of per instance vertex data allocation
@@ -126,7 +125,7 @@ class CCPUMeshPackerV1 final : public IMeshPacker<ICPUMeshBuffer, MDIStructType>
126125
ReservedAllocationMeshBuffers alloc(const MeshBufferIterator mbBegin, const MeshBufferIterator mbEnd);
127126

128127
//TODO: test
129-
void free(const ReservedAllocationMeshBuffers& ramb)
128+
void free(const ReservedAllocationMeshBuffers& ramb) // TODO: this isn't special so do it in the base class
130129
{
131130
if (ramb.indexAllocationOffset != INVALID_ADDRESS)
132131
m_idxBuffAlctr.free_addr(ramb.indexAllocationOffset, ramb.indexAllocationReservedCnt);
@@ -157,12 +156,13 @@ class CCPUMeshPackerV1 final : public IMeshPacker<ICPUMeshBuffer, MDIStructType>
157156
MeshPackerConfigParams<Iterator>* packerParamsOut);
158157

159158
//! shrinks byte size of all output buffers, so they are large enough to fit currently allocated contents. Call this function before `instantiateDataStorage`
160-
void shrinkOutputBuffersSize()
159+
void shrinkOutputBuffersSize() // TODO: shrink isn't special, can only happen before data storage is instantiated, so do it in the base class
161160
{
162161
m_allocParams.MDIDataBuffSupportedCnt = m_MDIDataAlctr.safe_shrink_size(0u, 1u);
163162
m_allocParams.perInstanceVertexBuffSupportedByteSize = m_perInsVtxBuffAlctr.safe_shrink_size(0u, 1u);
164163
m_allocParams.indexBuffSupportedCnt = m_idxBuffAlctr.safe_shrink_size(0u, 1u);
165164
m_allocParams.vertexBuffSupportedByteSize = m_vtxBuffAlctr.safe_shrink_size(0u, 1u);
165+
// TODO: SHRINK ACTUAL ALLOCATORS AND THEIR RESERVED SPACES! (CREATE NEW ALLOCATORS WITH NEW RESERVED SPACES, THEN DELETE OLD RESERVED, THEN SWAP ALLOCATOR AND RESERVED MEMBERS)
166166
}
167167

168168
private:
@@ -173,7 +173,7 @@ class CCPUMeshPackerV1 final : public IMeshPacker<ICPUMeshBuffer, MDIStructType>
173173

174174
uint32_t m_vtxSize;
175175
uint32_t m_perInsVtxSize;
176-
AllocationParams m_allocParams;
176+
AllocationParams m_allocParams; // TODO: only track the min sizes, the other stuff is redundant with allocators
177177

178178
bool isInstancingEnabled;
179179
void* m_perInsVtxBuffAlctrResSpc;
@@ -233,6 +233,7 @@ CCPUMeshPackerV1<MDIStructType>::CCPUMeshPackerV1(const SVertexInputParams& preD
233233
);
234234
}
235235

236+
// TODO: why cant this implementation of `alloc` be common to both CPU and CPU?
236237
template <typename MDIStructType>
237238
//`Iterator` may be only an Iterator or pointer to pointer
238239
template <typename MeshBufferIterator>
@@ -245,7 +246,7 @@ typename CCPUMeshPackerV1<MDIStructType>::ReservedAllocationMeshBuffers CCPUMesh
245246

246247
//TODO:
247248
//allocation should be happening even if processed mesh buffer doesn't have attribute that was declared in pre defined `SVertexInputParams`, if mesh buffer has any attributes that are not declared in pre defined `SVertexInputParams` then these should be always ignored
248-
//include it in the ducumentation?
249+
//include it in the ducumentation? YES
249250

250251
//validation
251252
for (auto it = mbBegin; it != mbEnd; it++)

include/nbl/asset/utils/CCPUMeshPackerV2.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ class CCPUMeshPackerV2 final : public IMeshPackerV2<ICPUBuffer, ICPUMeshBuffer,
4040
//! shrinks byte size of all output buffers, so they are large enough to fit currently allocated contents. Call this function before `instantiateDataStorage`
4141
void shrinkOutputBuffersSize()
4242
{
43-
m_allocParams.MDIDataBuffSupportedCnt = m_MDIDataAlctr.safe_shrink_size(0u, 1u);
44-
m_allocParams.indexBuffSupportedCnt = m_idxBuffAlctr.safe_shrink_size(0u, 1u);
45-
m_allocParams.vertexBuffSupportedByteSize = m_vtxBuffAlctr.safe_shrink_size(0u, 1u);
43+
m_allocParams.MDIDataBuffSupportedCnt = m_MDIDataAlctr.safe_shrink_size(0u,1u);
44+
m_allocParams.indexBuffSupportedCnt = m_idxBuffAlctr.safe_shrink_size(0u,1u);
45+
m_allocParams.vertexBuffSupportedByteSize = m_vtxBuffAlctr.safe_shrink_size(0u,1u);
46+
// TODO: SHRINK ACTUAL ALLOCATORS AND THEIR RESERVED SPACES! (CREATE NEW ALLOCATORS WITH NEW RESERVED SPACES, THEN DELETE OLD RESERVED, THEN SWAP ALLOCATOR AND RESERVED MEMBERS)
4647
}
4748

4849
/**

include/nbl/asset/utils/IMeshPacker.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ class IMeshPackerBase : public virtual core::IReferenceCounted
4848
_NBL_ALIGNED_FREE(m_vtxBuffAlctrResSpc);
4949
}
5050

51+
struct MinimumAllocationParamsCommon
52+
{
53+
// Minimum count of 16 bit indicies allocated per allocation
54+
size_t indexBufferMinAllocCnt = 256ull;
55+
56+
// Minimum bytes of vertex data allocated per allocation
57+
size_t vertexBufferMinAllocByteSize = 32ull;
58+
59+
// Minimum count of MDI structs allocated per allocation
60+
size_t MDIDataBuffMinAllocCnt = 32ull;
61+
};
5162
struct AllocationParamsCommon
5263
{
5364
// Maximum number of 16 bit indicies that may be allocated
@@ -62,6 +73,9 @@ class IMeshPackerBase : public virtual core::IReferenceCounted
6273
// Maximum number of MDI structs that may be allocated
6374
size_t MDIDataBuffSupportedCnt = 16777216ull; /* 16MB assuming MDIStructType is DrawElementsIndirectCommand_t*/
6475

76+
// TODO: get rid of these, replace with
77+
// MinimumAllocationParamsCommon minAllocParams;
78+
//
6579
// Minimum count of 16 bit indicies allocated per allocation
6680
size_t indexBufferMinAllocCnt = 256ull;
6781

@@ -72,6 +86,7 @@ class IMeshPackerBase : public virtual core::IReferenceCounted
7286
size_t MDIDataBuffMinAllocCnt = 32ull;
7387
};
7488

89+
// TODO: make a function which initializes allocators as a copy (incl resized copy)
7590
void initializeCommonAllocators(const AllocationParamsCommon& allocParams)
7691
{
7792
if (allocParams.indexBuffSupportedCnt)

include/nbl/asset/utils/IMeshPackerV2.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class IMeshPackerV2 : public IMeshPacker<MeshBufferType,MDIStructType>, public I
235235
static_assert(std::is_base_of<IBuffer, BufferType>::value);
236236

237237
using base_t = IMeshPacker<MeshBufferType, MDIStructType>;
238+
using MinimumAllocationParams = IMeshPackerBase::MinimumAllocationParamsCommon;
238239
using AllocationParams = IMeshPackerBase::AllocationParamsCommon;
239240

240241
public:
@@ -632,11 +633,8 @@ class IMeshPackerV2 : public IMeshPacker<MeshBufferType,MDIStructType>, public I
632633
inline PackerDataStore getPackerDataStore() { return m_packerDataStore; };
633634

634635
protected:
635-
//core::vector<VirtualAttribute> virtualAttribTable; // Is this variable even used!?
636-
//uint16_t enabledAttribFlagsCombined = 0u; // Is this variable even used!?
637-
638636
PackerDataStore m_packerDataStore;
639-
AllocationParams m_allocParams;
637+
AllocationParams m_allocParams; // TODO: only hold onto MinimumAllocationParams, derive rest from the allocator sizes! (if you even need to)
640638

641639
};
642640

include/nbl/video/CGPUMeshPackerV2.h

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class CGPUMeshPackerV2 final : public IMeshPackerV2<video::IGPUBuffer,video::IGP
3636
m_driver(driver)
3737
{}
3838

39-
CGPUMeshPackerV2(video::IVideoDriver* driver, const asset::CCPUMeshPackerV2<MDIStructType>& cpuMP)
40-
:IMeshPackerV2<video::IGPUBuffer, video::IGPUMeshBuffer, MDIStructType>(cpuMP.m_allocParams, cpuMP.m_minTriangleCountPerMDIData, cpuMP.m_maxTriangleCountPerMDIData),
39+
CGPUMeshPackerV2(video::IVideoDriver* driver, const asset::CCPUMeshPackerV2<MDIStructType>* cpuMP)
40+
:IMeshPackerV2<video::IGPUBuffer,video::IGPUMeshBuffer,MDIStructType>(cpuMP.m_allocParams, cpuMP.m_minTriangleCountPerMDIData, cpuMP.m_maxTriangleCountPerMDIData),
4141
m_driver(driver)
4242
{
4343
m_virtualAttribConfig = cpuMP.m_virtualAttribConfig;
@@ -46,31 +46,14 @@ class CGPUMeshPackerV2 final : public IMeshPackerV2<video::IGPUBuffer,video::IGP
4646
auto& cpuIdxBuff = cpuMP.m_packerDataStore.indexBuffer;
4747
auto& cpuVtxBuff = cpuMP.m_packerDataStore.vertexBuffer;
4848

49+
// TODO: why are the allocators not copied!?
50+
51+
// TODO: call instantiateDataStorage() here and then copy CPU data to the initialized storage
4952
m_packerDataStore.MDIDataBuffer = driver->createFilledDeviceLocalGPUBufferOnDedMem(cpuMDIBuff->getSize(), cpuMDIBuff->getPointer());
5053
m_packerDataStore.indexBuffer = driver->createFilledDeviceLocalGPUBufferOnDedMem(cpuMDIBuff->getSize(), cpuMDIBuff->getPointer());
5154
m_packerDataStore.vertexBuffer = driver->createFilledDeviceLocalGPUBufferOnDedMem(cpuMDIBuff->getSize(), cpuMDIBuff->getPointer());
5255
}
5356

54-
CGPUMeshPackerV2(video::IVideoDriver* driver, asset::CCPUMeshPackerV2<MDIStructType>&& cpuMP)
55-
:IMeshPackerV2<video::IGPUBuffer, video::IGPUMeshBuffer, MDIStructType>(cpuMP.m_allocParams, cpuMP.m_minTriangleCountPerMDIData, cpuMP.m_maxTriangleCountPerMDIData),
56-
m_driver(driver)
57-
{
58-
m_virtualAttribConfig = std::move(cpuMP.m_virtualAttribConfig);
59-
60-
auto cpuMDIBuff = std::move(cpuMP.m_packerDataStore.MDIDataBuffer);
61-
auto cpuIdxBuff = std::move(cpuMP.m_packerDataStore.indexBuffer);
62-
auto cpuVtxBuff = std::move(cpuMP.m_packerDataStore.vertexBuffer);
63-
64-
m_packerDataStore.MDIDataBuffer = driver->createFilledDeviceLocalGPUBufferOnDedMem(cpuMDIBuff->getSize(), cpuMDIBuff->getPointer());
65-
m_packerDataStore.indexBuffer = driver->createFilledDeviceLocalGPUBufferOnDedMem(cpuIdxBuff->getSize(), cpuIdxBuff->getPointer());
66-
m_packerDataStore.vertexBuffer = driver->createFilledDeviceLocalGPUBufferOnDedMem(cpuVtxBuff->getSize(), cpuVtxBuff->getPointer());
67-
68-
cpuMP.m_vtxBuffAlctr.reset();
69-
cpuMP.m_idxBuffAlctr.reset();
70-
cpuMP.m_MDIDataAlctr.reset();
71-
}
72-
73-
7457
void instantiateDataStorage();
7558

7659
template <typename MeshBufferIterator>

0 commit comments

Comments
 (0)