@@ -61,16 +61,26 @@ struct BatchInstanceData
61
61
const auto invalid_tex = STextureData::invalid ();
62
62
std::fill_n (map_data,TEX_OF_INTEREST_CNT,reinterpret_cast <const uint64_t &>(invalid_tex));
63
63
}
64
- BatchInstanceData (const BatchInstanceData& other) : shininess(other.shininess), opacity(other.opacity), IoR(other.IoR), extra(other.extra)
64
+ BatchInstanceData (const BatchInstanceData& other) : BatchInstanceData()
65
+ {
66
+ this ->operator =(other);
67
+ }
68
+ ~BatchInstanceData ()
69
+ {
70
+ }
71
+
72
+ BatchInstanceData& operator =(const BatchInstanceData& other)
65
73
{
66
74
ambient = other.ambient ;
67
75
diffuse = other.diffuse ;
68
76
specular = other.specular ;
69
77
emissive = other.emissive ;
70
78
std::copy_n (other.map_data ,TEX_OF_INTEREST_CNT,map_data);
71
- }
72
- ~BatchInstanceData ()
73
- {
79
+ shininess = other.shininess ;
80
+ opacity = other.opacity ;
81
+ IoR = other.IoR ;
82
+ extra = other.extra ;
83
+ return *this ;
74
84
}
75
85
76
86
union
@@ -80,7 +90,7 @@ struct BatchInstanceData
80
90
struct
81
91
{
82
92
uint32_t invalid_0[3 ];
83
- uint32_t baseVertex ;
93
+ uint32_t firstIndex ;
84
94
};
85
95
};
86
96
union
@@ -471,96 +481,75 @@ int main()
471
481
472
482
auto wholeMbRangeBegin = pipelineMeshBufferRanges.front ();
473
483
auto wholeMbRangeEnd = pipelineMeshBufferRanges.back ();
474
- const uint32_t meshBufferCnt = std::distance (wholeMbRangeBegin,wholeMbRangeEnd);
475
-
476
484
const uint32_t mdiCntBound = mp->calcMDIStructMaxCount (wholeMbRangeBegin,wholeMbRangeEnd);
477
485
478
486
auto allocData = core::make_refctd_dynamic_array<core::smart_refctd_dynamic_array<MeshPacker::ReservedAllocationMeshBuffers>>(mdiCntBound);
479
- core::vector<uint32_t > allocDataOffsetForDrawCall (pipelineMeshBufferRanges.size (),0u );
480
- auto allocOffsetIt = allocDataOffsetForDrawCall.begin ();
487
+ auto allocDataIt = allocData->begin ();
481
488
for (auto it=pipelineMeshBufferRanges.begin (); it!=pipelineMeshBufferRanges.end ()-1u ; )
482
489
{
483
490
auto mbRangeBegin = &(*it)->get ();
484
491
auto mbRangeEnd = &(*(++it))->get ();
485
492
486
- bool allocSuccessfull = mp->alloc (allocData-> data ()+*allocOffsetIt ,mbRangeBegin,mbRangeEnd);
493
+ bool allocSuccessfull = mp->alloc (&*allocDataIt ,mbRangeBegin,mbRangeEnd);
487
494
if (!allocSuccessfull)
488
495
{
489
496
std::cout << " Alloc failed \n " ;
490
497
_NBL_DEBUG_BREAK_IF (true );
491
498
}
492
-
493
- *allocOffsetIt = *(allocOffsetIt++)+mp->calcMDIStructMaxCount (mbRangeBegin,mbRangeEnd);
499
+ allocDataIt += mp->calcMDIStructMaxCount (mbRangeBegin,mbRangeEnd);
494
500
}
495
501
mp->shrinkOutputBuffersSize ();
496
502
mp->instantiateDataStorage ();
497
503
498
504
core::vector<BatchInstanceData> batchData;
499
505
batchData.reserve (mdiCntBound);
500
- #if 0
501
- core::vector<uint32_t> mdiCntForMeshBuffer;
502
- mdiCntForMeshBuffer.reserve(meshBufferCnt);
503
506
504
- uint32_t offsetForDrawCall = 0u ;
505
- i = 0u;
506
- for (auto it=ranges .begin(); it!=ranges .end()-1u;)
507
+ allocDataIt = allocData-> begin () ;
508
+ uint32_t mdiListOffset = 0u ;
509
+ for (auto it=pipelineMeshBufferRanges .begin (); it!=pipelineMeshBufferRanges .end ()-1u ; )
507
510
{
508
- auto mbRangeBegin = &it ->get();
509
- auto mbRangeEnd = &(++it)->get();
511
+ auto mbRangeBegin = &(*it) ->get ();
512
+ auto mbRangeEnd = &(*( ++it) )->get ();
510
513
511
- const uint32_t mdiMaxCnt = mp.calcMDIStructMaxCount(mbRangeBegin, mbRangeEnd);
512
- core::vector<IMeshPackerBase::PackedMeshBufferData> pmbd(mdiMaxCnt); //why mdiMaxCnt and not meshBuffersInRangeCnt??????????
513
- core::vector<MeshPacker::CombinedDataOffsetTable> cdot(mdiMaxCnt);
514
+ const uint32_t meshMdiBound = mp->calcMDIStructMaxCount (mbRangeBegin,mbRangeEnd);
515
+ core::vector<IMeshPackerBase::PackedMeshBufferData> pmbd (std::distance (mbRangeBegin,mbRangeEnd));
516
+ core::vector<MeshPacker::CombinedDataOffsetTable> cdot (meshMdiBound);
517
+ uint32_t actualMdiCnt = mp->commit (pmbd.data (),cdot.data (),&*allocDataIt,mbRangeBegin,mbRangeEnd);
518
+ allocDataIt += meshMdiBound;
514
519
515
- uint32_t mdiCnt = mp.commit(pmbd.data(), cdot.data(), allocData->data() + allocDataOffsetForDrawCall[i], mbRangeBegin, mbRangeEnd);
516
- if (mdiCnt == 0u)
520
+ if (actualMdiCnt==0u )
517
521
{
518
522
std::cout << " Commit failed \n " ;
519
523
_NBL_DEBUG_BREAK_IF (true );
520
524
}
521
525
522
- sceneData.pushConstantsData.push_back(offsetForDrawCall);
523
- offsetForDrawCall += mdiCnt;
524
-
525
- DrawIndexedIndirectInput mdiCallInput;
526
- mdiCallInput.maxCount = mdiCnt;
527
- mdiCallInput.offset = pmbd[0].mdiParameterOffset * sizeof(DrawElementsIndirectCommand_t);
526
+ sceneData.pushConstantsData .push_back (mdiListOffset);
527
+ mdiListOffset += actualMdiCnt;
528
528
529
- sceneData.drawIndirectInput.push_back(mdiCallInput);
529
+ DrawIndexedIndirectInput& mdiCallInput = sceneData.drawIndirectInput .emplace_back ();
530
+ mdiCallInput.maxCount = actualMdiCnt;
531
+ mdiCallInput.offset = pmbd.front ().mdiParameterOffset *sizeof (DrawElementsIndirectCommand_t);
530
532
531
- const uint32_t mbInRangeCnt = std::distance(mbRangeBegin, mbRangeEnd);
532
- for (uint32_t j = 0u; j < mbInRangeCnt; j++)
533
+ auto pmbdIt = pmbd.begin ();
534
+ auto cdotIt = cdot.begin ();
535
+ for (auto mbIt=mbRangeBegin; mbIt!=mbRangeEnd; mbIt++)
533
536
{
534
- mdiCntForMeshBuffer.push_back(pmbd[j].mdiParameterCount);
535
- }
536
-
537
- //setOffsetTables
538
- for (uint32_t j = 0u; j < mdiCnt; j++)
539
- {
540
- MeshPacker::CombinedDataOffsetTable& virtualAttribTable = cdot[j];
541
-
542
- offsetTableLocal.push_back(virtualAttribTable.attribInfo[0]);
543
- offsetTableLocal.push_back(virtualAttribTable.attribInfo[2]);
544
- offsetTableLocal.push_back(virtualAttribTable.attribInfo[3]);
545
- }
546
-
547
- i++;
548
- }
549
-
550
- //prepare data for (set = 1, binding = 0) shader ssbo
551
- {
552
-
553
- uint32_t i = 0u;
554
- for (auto it = wholeMbRangeBegin; it != wholeMbRangeEnd; it++)
555
- {
556
- const uint32_t mdiCntForThisMb = mdiCntForMeshBuffer[i];
557
- for (uint32_t i = 0u; i < mdiCntForThisMb; i++)
558
- vtData.push_back(*reinterpret_cast<MaterialParams*>((*it)->getPushConstantsDataPtr()));
559
-
560
- i++;
537
+ const auto & material = *reinterpret_cast <BatchInstanceData*>((*mbIt)->getPushConstantsDataPtr ());
538
+ const IMeshPackerBase::PackedMeshBufferData& packedData = *(pmbdIt++);
539
+ for (uint32_t mdi=0u ; mdi<packedData.mdiParameterCount ; mdi++)
540
+ {
541
+ auto & batch = batchData.emplace_back ();
542
+ batch = material;
543
+ batch.firstIndex = reinterpret_cast <const DrawElementsIndirectCommand_t*>(mp->getPackerDataStore ().MDIDataBuffer ->getPointer ())[packedData.mdiParameterOffset +mdi].firstIndex ;
544
+
545
+ MeshPacker::CombinedDataOffsetTable& virtualAttribTable = *(cdotIt++);
546
+ constexpr auto UVAttributeIx = 2 ;
547
+ batch.vAttrPos = reinterpret_cast <const uint32_t &>(virtualAttribTable.attribInfo [(*mbIt)->getPositionAttributeIx ()]);
548
+ batch.vAttrUV = reinterpret_cast <const uint32_t &>(virtualAttribTable.attribInfo [UVAttributeIx]);
549
+ batch.vAttrNormal = reinterpret_cast <const uint32_t &>(virtualAttribTable.attribInfo [(*mbIt)->getNormalAttributeIx ()]);
550
+ }
561
551
}
562
552
}
563
- #endif
564
553
batchDataSSBO = driver->createFilledDeviceLocalGPUBufferOnDedMem (batchData.size ()*sizeof (BatchInstanceData),batchData.data ());
565
554
566
555
gpump = core::make_smart_refctd_ptr<CGPUMeshPackerV2<>>(driver,mp.get ());
0 commit comments