Skip to content

Commit 70e123c

Browse files
committed
Improvements
1 parent 94a87e0 commit 70e123c

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

include/nbl/asset/utils/IMeshPacker.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,25 @@ class IMeshPackerBase : public virtual core::IReferenceCounted
102102
}
103103
}
104104

105+
void initializeCommonAllocators(
106+
const core::GeneralpurposeAddressAllocator<uint32_t>& mdiAlctr,
107+
const core::GeneralpurposeAddressAllocator<uint32_t>& idxAlctr,
108+
const core::GeneralpurposeAddressAllocator<uint32_t>& vtxAlctr
109+
)
110+
{
111+
uint32_t alctrBuffSz = alctrTraits::get_total_size(mdiAlctr);
112+
void* resSpcTmp = _NBL_ALIGNED_MALLOC(alctrTraits::reserved_size(alctrBuffSz, mdiAlctr), _NBL_SIMD_ALIGNMENT);
113+
m_MDIDataAlctr = core::GeneralpurposeAddressAllocator<uint32_t>(alctrBuffSz, mdiAlctr, resSpcTmp);
114+
115+
alctrBuffSz = alctrTraits::get_total_size(idxAlctr);
116+
resSpcTmp = _NBL_ALIGNED_MALLOC(alctrTraits::reserved_size(alctrBuffSz, idxAlctr), _NBL_SIMD_ALIGNMENT);
117+
m_idxBuffAlctr = core::GeneralpurposeAddressAllocator<uint32_t>(alctrBuffSz, idxAlctr, resSpcTmp);
118+
119+
alctrBuffSz = alctrTraits::get_total_size(vtxAlctr);
120+
resSpcTmp = _NBL_ALIGNED_MALLOC(alctrTraits::reserved_size(alctrBuffSz, vtxAlctr), _NBL_SIMD_ALIGNMENT);
121+
m_vtxBuffAlctr = core::GeneralpurposeAddressAllocator<uint32_t>(alctrBuffSz, vtxAlctr, resSpcTmp);
122+
}
123+
105124
protected:
106125
core::GeneralpurposeAddressAllocator<uint32_t> m_vtxBuffAlctr;
107126
core::GeneralpurposeAddressAllocator<uint32_t> m_idxBuffAlctr;
@@ -221,7 +240,7 @@ class IMeshPacker : public IMeshPackerBase
221240
//TODO: functions: constructTriangleBatches, convertIdxBufferToTriangles, deinterleaveAndCopyAttribute and deinterleaveAndCopyPerInstanceAttribute
222241
//will not work with IGPUMeshBuffer as MeshBufferType, move it to new `ICPUMeshPacker`
223242

224-
TriangleBatches constructTriangleBatches(MeshBufferType* meshBuffer, IdxBufferParams idxBufferParams, core::aabbox3df* aabbs) const
243+
TriangleBatches constructTriangleBatches(const MeshBufferType* meshBuffer, IdxBufferParams idxBufferParams, core::aabbox3df* aabbs) const
225244
{
226245
uint32_t triCnt;
227246
const bool success = IMeshManipulator::getPolyCount(triCnt,meshBuffer);

include/nbl/asset/utils/IMeshPackerV2.h

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -631,21 +631,11 @@ class IMeshPackerV2 : public IMeshPacker<MeshBufferType,MDIStructType>, public I
631631
: base_t(otherMp->getMinTriangleCountPerMDI(),otherMp->getMaxTriangleCountPerMDI()),
632632
IMeshPackerV2Base(otherMp->getVirtualAttribConfig())
633633
{
634-
635-
const auto& mdiAlctr = otherMp->getMDIAllocator();
636-
uint32_t alctrBuffSz = alctrTraits::get_total_size(mdiAlctr);
637-
void* resSpcTmp = _NBL_ALIGNED_MALLOC(alctrTraits::reserved_size(alctrBuffSz, mdiAlctr), _NBL_SIMD_ALIGNMENT);
638-
m_MDIDataAlctr = core::GeneralpurposeAddressAllocator<uint32_t>(alctrBuffSz, mdiAlctr, resSpcTmp);
639-
640-
const auto& idxAlctr = otherMp->getIndexAllocator();
641-
alctrBuffSz = alctrTraits::get_total_size(idxAlctr);
642-
resSpcTmp = _NBL_ALIGNED_MALLOC(alctrTraits::reserved_size(alctrBuffSz, idxAlctr), _NBL_SIMD_ALIGNMENT);
643-
m_idxBuffAlctr = core::GeneralpurposeAddressAllocator<uint32_t>(alctrBuffSz, idxAlctr, resSpcTmp);
644-
645-
const auto& vtxAlctr = otherMp->getVertexAllocator();
646-
alctrBuffSz = alctrTraits::get_total_size(vtxAlctr);
647-
resSpcTmp = _NBL_ALIGNED_MALLOC(alctrTraits::reserved_size(alctrBuffSz, vtxAlctr), _NBL_SIMD_ALIGNMENT);
648-
m_vtxBuffAlctr = core::GeneralpurposeAddressAllocator<uint32_t>(alctrBuffSz, vtxAlctr, resSpcTmp);
634+
initializeCommonAllocators(
635+
otherMp->getMDIAllocator(),
636+
otherMp->getIndexAllocator(),
637+
otherMp->getVertexAllocator()
638+
);
649639
};
650640

651641
PackerDataStore m_packerDataStore;

0 commit comments

Comments
 (0)