Skip to content

Commit ed9bfa1

Browse files
Fixed the vertex counts for reservations
1 parent 361951c commit ed9bfa1

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

include/nbl/asset/IMeshPackerV2.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ bool IMeshPackerV2<MeshBufferType, BufferType, MDIStructType>::alloc(ReservedAll
249249
{
250250
ReservedAllocationMeshBuffers& ramb = *(rambOut + i);
251251
const size_t idxCnt = (*it)->getIndexCount();
252-
const size_t maxVtxCnt = IMeshManipulator::upperBoundVertexID(*it); //ahsdfjkasdfgasdklfhasdf TODO: deal with vertex duplication, same for v1
252+
// TODO: deal with per-instance attributes!!
253+
const size_t maxVtxCnt = calcVertexCountBoundWithBatchDuplication(IMeshManipulator::getPolyCount(*it));
253254

254255
//allocate indices
255256
ramb.indexAllocationOffset = m_idxBuffAlctr.alloc_addr(idxCnt, 1u);

include/nbl/asset/utils/CCPUMeshPackerV1.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ typename CCPUMeshPackerV1<MDIStructType>::ReservedAllocationMeshBuffers CCPUMesh
258258
{
259259
ICPUMeshBuffer* mb = *it;
260260
idxCnt += mb->getIndexCount();
261-
vtxCnt += IMeshManipulator::upperBoundVertexID(mb);
261+
vtxCnt += calcVertexCountBoundWithBatchDuplication(IMeshManipulator::getPolyCount(mb));
262262
}
263263

264264
const uint32_t minIdxCntPerPatch = m_minTriangleCountPerMDIData * 3;

include/nbl/asset/utils/IMeshPacker.h

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef __NBL_ASSET_I_MESH_PACKER_H_INCLUDED__
66
#define __NBL_ASSET_I_MESH_PACKER_H_INCLUDED__
77

8+
#include "nbl/asset/utils/IMeshManipulator.h"
9+
810
namespace nbl
911
{
1012
namespace asset
@@ -45,6 +47,7 @@ class IMeshPackerBase
4547

4648
struct AllocationParamsCommon
4749
{
50+
// TODO: review all names and documnetation!
4851
size_t indexBuffSupportedCnt = 1073741824ull; /* 2GB*/
4952
size_t vertexBuffSupportedSize = 1ull << 31ull; /* 2GB*/
5053
size_t MDIDataBuffSupportedCnt = 16777216ull; /* 16MB assuming MDIStructType is DrawElementsIndirectCommand_t*/
@@ -125,7 +128,12 @@ class IMeshPacker : public IMeshPackerBase
125128
return size;
126129
}
127130

128-
inline constexpr uint32_t calcBatchCount(uint32_t triCnt)
131+
inline constexpr uint32_t calcVertexCountBoundWithBatchDuplication(uint32_t triCnt)
132+
{
133+
return triCnt*3u;
134+
}
135+
136+
inline constexpr uint32_t calcBatchCountBound(uint32_t triCnt)
129137
{
130138
if (triCnt!=0u)
131139
return (triCnt-1u)/m_minTriangleCountPerMDIData+1u;
@@ -144,13 +152,40 @@ class IMeshPacker : public IMeshPackerBase
144152

145153
core::vector<TriangleBatch> constructTriangleBatches(MeshBufferType* meshBuffer)
146154
{
147-
const size_t idxCnt = meshBuffer->getIndexCount();
148-
const uint32_t triCnt = idxCnt / 3;
149-
assert(idxCnt % 3 == 0);
155+
uint32_t triCnt;
156+
const bool success = IMeshManipulator::getPolyCount(meshBuffer);
157+
assert(success);
158+
159+
const uint32_t batchCount = calcBatchCountBound(triCnt);
160+
/*
161+
TODO:
162+
163+
//struct TriangleMortonCodePair
164+
//{
165+
// Triangle triangle;
166+
// //uint64_t mortonCode; TODO after benchmarks
167+
//};
168+
169+
core::vector<TriangleMortonCodePair> triangles(triCnt);
170+
uint32_t ix=0u;
171+
for (auto it=triangles.begin(); it!=triangles.end(); it++)
172+
{
173+
*it = IMeshManipulator::getTriangleIndices(meshbuffer,ix++);
174+
}
175+
176+
std::sort(triangles.begin(),triangles.end(),[]()->bool{return lhs.mortonCode<rhs.mortonCode;}); // maybe use our new core::radix_sort?
150177
151-
const uint32_t batchCount = calcBatchCount(triCnt);
178+
// do batch splitting
179+
core::vector<const TriangleMortonCodePair*> batches;
180+
batches.reserve(calcBatchCountBound(triCnt)+1u); // actual batch count will be different
181+
{
182+
// use batches.push_back();
183+
}
184+
batches.push_back(triangles.data()+triangles.size());
152185
153-
core::vector<TriangleBatch> output(batchCount);
186+
return {std::move(triangles),std::move(batches)};
187+
*/
188+
core::vector<TriangleBatch> output(batchCount); // nested vectors are evil
154189

155190
for (uint32_t i = 0u; i < batchCount; i++)
156191
{
@@ -166,12 +201,6 @@ class IMeshPacker : public IMeshPackerBase
166201
output[i].triangles = core::vector<Triangle>(m_maxTriangleCountPerMDIData);
167202
}
168203

169-
//struct TriangleMortonCodePair
170-
//{
171-
// Triangle triangle;
172-
// //uint64_t mortonCode; TODO after benchmarks
173-
//};
174-
175204
//TODO: triangle reordering
176205

177206
const auto& srcIdxBuffer = meshBuffer->getIndexBufferBinding();

0 commit comments

Comments
 (0)