Skip to content

Commit 01f07b1

Browse files
aaand I broke everything
1 parent dd382a3 commit 01f07b1

File tree

4 files changed

+54
-65
lines changed

4 files changed

+54
-65
lines changed

examples_tests/41.VisibilityBuffer/common.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
struct BatchInstanceData
1616
{
1717
vec3 Ka;
18-
uint baseVertex;
18+
uint firstIndex;
1919
vec3 Kd;
2020
nbl_glsl_VG_VirtualAttributePacked_t vAttrPos;
2121
vec3 Ks;

examples_tests/41.VisibilityBuffer/fillVBuffer.frag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ layout(location = 0) out uvec4 triangleIDdrawID_unorm16Bary_dBarydScreenHalf2x2;
1111
uint nbl_glsl_barycentric_frag_getDrawID() {return drawGUID;}
1212
vec3 nbl_glsl_barycentric_frag_getVertexPos(in uint drawID, in uint primID, in uint primsVx)
1313
{
14-
const uint ix = nbl_glsl_VG_fetchTriangleVertexIndex(primID*3u+batchInstanceData[drawID].baseVertex,primsVx);
14+
const uint ix = nbl_glsl_VG_fetchTriangleVertexIndex(primID*3u+batchInstanceData[drawID].firstIndex,primsVx);
1515
return nbl_glsl_fetchVtxPos(ix,drawID);
1616
}
1717

examples_tests/41.VisibilityBuffer/main.cpp

Lines changed: 51 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,26 @@ struct BatchInstanceData
6161
const auto invalid_tex = STextureData::invalid();
6262
std::fill_n(map_data,TEX_OF_INTEREST_CNT,reinterpret_cast<const uint64_t&>(invalid_tex));
6363
}
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)
6573
{
6674
ambient = other.ambient;
6775
diffuse = other.diffuse;
6876
specular = other.specular;
6977
emissive = other.emissive;
7078
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;
7484
}
7585

7686
union
@@ -80,7 +90,7 @@ struct BatchInstanceData
8090
struct
8191
{
8292
uint32_t invalid_0[3];
83-
uint32_t baseVertex;
93+
uint32_t firstIndex;
8494
};
8595
};
8696
union
@@ -471,96 +481,75 @@ int main()
471481

472482
auto wholeMbRangeBegin = pipelineMeshBufferRanges.front();
473483
auto wholeMbRangeEnd = pipelineMeshBufferRanges.back();
474-
const uint32_t meshBufferCnt = std::distance(wholeMbRangeBegin,wholeMbRangeEnd);
475-
476484
const uint32_t mdiCntBound = mp->calcMDIStructMaxCount(wholeMbRangeBegin,wholeMbRangeEnd);
477485

478486
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();
481488
for (auto it=pipelineMeshBufferRanges.begin(); it!=pipelineMeshBufferRanges.end()-1u; )
482489
{
483490
auto mbRangeBegin = &(*it)->get();
484491
auto mbRangeEnd = &(*(++it))->get();
485492

486-
bool allocSuccessfull = mp->alloc(allocData->data()+*allocOffsetIt,mbRangeBegin,mbRangeEnd);
493+
bool allocSuccessfull = mp->alloc(&*allocDataIt,mbRangeBegin,mbRangeEnd);
487494
if (!allocSuccessfull)
488495
{
489496
std::cout << "Alloc failed \n";
490497
_NBL_DEBUG_BREAK_IF(true);
491498
}
492-
493-
*allocOffsetIt = *(allocOffsetIt++)+mp->calcMDIStructMaxCount(mbRangeBegin,mbRangeEnd);
499+
allocDataIt += mp->calcMDIStructMaxCount(mbRangeBegin,mbRangeEnd);
494500
}
495501
mp->shrinkOutputBuffersSize();
496502
mp->instantiateDataStorage();
497503

498504
core::vector<BatchInstanceData> batchData;
499505
batchData.reserve(mdiCntBound);
500-
#if 0
501-
core::vector<uint32_t> mdiCntForMeshBuffer;
502-
mdiCntForMeshBuffer.reserve(meshBufferCnt);
503506

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; )
507510
{
508-
auto mbRangeBegin = &it->get();
509-
auto mbRangeEnd = &(++it)->get();
511+
auto mbRangeBegin = &(*it)->get();
512+
auto mbRangeEnd = &(*(++it))->get();
510513

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;
514519

515-
uint32_t mdiCnt = mp.commit(pmbd.data(), cdot.data(), allocData->data() + allocDataOffsetForDrawCall[i], mbRangeBegin, mbRangeEnd);
516-
if (mdiCnt == 0u)
520+
if (actualMdiCnt==0u)
517521
{
518522
std::cout << "Commit failed \n";
519523
_NBL_DEBUG_BREAK_IF(true);
520524
}
521525

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;
528528

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);
530532

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++)
533536
{
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+
}
561551
}
562552
}
563-
#endif
564553
batchDataSSBO = driver->createFilledDeviceLocalGPUBufferOnDedMem(batchData.size()*sizeof(BatchInstanceData),batchData.data());
565554

566555
gpump = core::make_smart_refctd_ptr<CGPUMeshPackerV2<>>(driver,mp.get());

examples_tests/41.VisibilityBuffer/shadeVBuffer.comp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void main()
9999

100100
gBatchInstance = batchInstanceData[drawID];
101101
uvec3 vertexIDs;
102-
const uint baseTriangleVertex = triangleID*3u+gBatchInstance.baseTriangle;
102+
const uint baseTriangleVertex = triangleID*3u+gBatchInstance.firstIndex;
103103
for (uint i=0u; i<3u; i++)
104104
vertexIDs[i] = nbl_glsl_VG_fetchTriangleVertexIndex(baseTriangleVertex,i)
105105

0 commit comments

Comments
 (0)