Skip to content

Commit ead11eb

Browse files
fixed ex 31 and 44
1 parent a06712b commit ead11eb

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

examples_tests/31.SkinningDataBenchmark/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,17 @@ int main()
165165
newInputParams.attributes[4].format = EF_R32_UINT;
166166
newInputParams.attributes[4].relativeOffset = 0u;
167167

168+
const auto vertexUpperBound = asset::IMeshManipulator::upperBoundVertexID(meshBuffer.get());
169+
168170
SBufferBinding<ICPUBuffer> boneIDBuffer;
169171
boneIDBuffer.offset = 0u;
170-
boneIDBuffer.buffer = core::make_smart_refctd_ptr<ICPUBuffer>(meshBuffer->calcVertexCount() * sizeof(uint32_t));
172+
boneIDBuffer.buffer = core::make_smart_refctd_ptr<ICPUBuffer>(vertexUpperBound*sizeof(uint32_t));
171173

172174
uint32_t* buffPtr = static_cast<uint32_t*>(boneIDBuffer.buffer->getPointer());
173-
for (int i = 0; i < meshBuffer->calcVertexCount(); i++)
175+
for (auto i=0u; i<vertexUpperBound; i++)
174176
buffPtr[i] = bonesCreatedCnt + getRandomNumber<uint32_t>(1u, boneMatMaxCnt[mbID]) - 1u;
175177
// don't want total random access to bones, sort roughly
176-
std::sort(buffPtr,buffPtr+meshBuffer->calcVertexCount());
178+
std::sort(buffPtr,buffPtr+vertexUpperBound);
177179

178180
meshBuffer->setVertexBufferBinding(std::move(boneIDBuffer), 1);
179181

examples_tests/44.LevelCurveExtraction/main.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ int main()
390390
{
391391
//lp.loaderFlags = asset::IAssetLoader::ELPF_DONT_COMPILE_GLSL;
392392
meshes_bundle = am->getAsset(file.result()[0], lp);
393-
if (meshes_bundle.isEmpty())
393+
if (meshes_bundle.getContents().empty())
394394
{
395395
pfd::message("Choose file to open", "Chosen file could not be loaded. Choose another OBJ file to open or press cancel to open a default scene.", pfd::choice::ok);
396396
continue;
@@ -402,7 +402,7 @@ int main()
402402

403403
fs->addFileArchive("../../media/sponza.zip");
404404
meshes_bundle = am->getAsset("sponza.obj", lp);
405-
if (meshes_bundle.isEmpty())
405+
if (meshes_bundle.getContents().empty())
406406
{
407407
std::cout << "Could not open Sponza.zip. Quitting program";
408408
return 1;
@@ -423,21 +423,21 @@ int main()
423423
if (!asset::IMeshManipulator::getPolyCount(triangleCount, mesh_raw))
424424
assert(false);
425425

426-
const asset::CMTLPipelineMetadata* pipelineMetadata = nullptr;
426+
const auto meta = meshes_bundle.getMetadata()->selfCast<const asset::COBJMetadata>();
427+
const asset::CMTLMetadata::CRenderpassIndependentPipeline* pipelineMetadata = nullptr;
427428
core::map<const asset::ICPURenderpassIndependentPipeline*,core::smart_refctd_ptr<asset::ICPURenderpassIndependentPipeline>> modifiedPipelines;
428-
for (uint32_t i=0u; i<mesh_raw->getMeshBufferCount(); i++)
429+
for (auto mb : mesh_raw->getMeshBuffers())
429430
{
430-
auto mb = mesh_raw->getMeshBuffer(i);
431431
auto* pipeline = mb->getPipeline();
432432
auto found = modifiedPipelines.find(pipeline);
433433
if (found==modifiedPipelines.end())
434434
{
435+
pipelineMetadata = static_cast<const asset::CMTLMetadata::CRenderpassIndependentPipeline*>(meta->getAssetSpecificMetadata(pipeline));
436+
435437
// new pipeline to modify, copy the pipeline
436438
auto pipeline_cp = core::smart_refctd_ptr_static_cast<asset::ICPURenderpassIndependentPipeline>(pipeline->clone(1u));
437439

438440
// insert a geometry shader into the pipeline
439-
assert(pipelineMetadata->getLoaderName() == "CGraphicsPipelineLoaderMTL");
440-
pipelineMetadata = static_cast<const asset::CMTLPipelineMetadata*>(pipeline->getMetadata());
441441
pipeline_cp->setShaderAtIndex(asset::ICPURenderpassIndependentPipeline::ESSI_GEOMETRY_SHADER_IX,(pipelineMetadata->usesShaderWithUVs() ? geomShaderUV:geomShaderNOUV).get());
442442

443443
// add descriptor set layout with one that has an SSBO and UBO
@@ -454,7 +454,7 @@ int main()
454454

455455
//we can safely assume that all meshbuffers within mesh loaded from OBJ has same DS1 layout (used for camera-specific data)
456456
//so we can create just one DS
457-
asset::ICPUDescriptorSetLayout* ds1layout = mesh_raw->getMeshBuffer(0u)->getPipeline()->getLayout()->getDescriptorSetLayout(1u);
457+
asset::ICPUDescriptorSetLayout* ds1layout = mesh_raw->getMeshBuffers().begin()[0]->getPipeline()->getLayout()->getDescriptorSetLayout(1u);
458458
uint32_t ds1UboBinding = 0u;
459459
for (const auto& bnd : ds1layout->getBindings())
460460
if (bnd.type==asset::EDT_UNIFORM_BUFFER)
@@ -465,8 +465,8 @@ int main()
465465

466466
size_t neededDS1UBOsz = 0ull;
467467
{
468-
for (const auto& shdrIn : pipelineMetadata->getCommonRequiredInputs())
469-
if (shdrIn.descriptorSection.type==asset::IPipelineMetadata::ShaderInput::ET_UNIFORM_BUFFER && shdrIn.descriptorSection.uniformBufferObject.set==1u && shdrIn.descriptorSection.uniformBufferObject.binding==ds1UboBinding)
468+
for (const auto& shdrIn : pipelineMetadata->getRequiredShaderInputs())
469+
if (shdrIn.descriptorSection.type==asset::IRenderpassIndependentPipelineMetadata::ShaderInput::ET_UNIFORM_BUFFER && shdrIn.descriptorSection.uniformBufferObject.set==1u && shdrIn.descriptorSection.uniformBufferObject.binding==ds1UboBinding)
470470
neededDS1UBOsz = std::max<size_t>(neededDS1UBOsz, shdrIn.descriptorSection.uniformBufferObject.relByteoffset+shdrIn.descriptorSection.uniformBufferObject.bytesize);
471471
}
472472

@@ -545,25 +545,25 @@ int main()
545545

546546

547547
core::vector<uint8_t> uboData(gpuubo->getSize());
548-
for (const auto& shdrIn : pipelineMetadata->getCommonRequiredInputs())
548+
for (const auto& shdrIn : pipelineMetadata->getRequiredShaderInputs())
549549
{
550-
if (shdrIn.descriptorSection.type==asset::IPipelineMetadata::ShaderInput::ET_UNIFORM_BUFFER && shdrIn.descriptorSection.uniformBufferObject.set==1u && shdrIn.descriptorSection.uniformBufferObject.binding==ds1UboBinding)
550+
if (shdrIn.descriptorSection.type==asset::IRenderpassIndependentPipelineMetadata::ShaderInput::ET_UNIFORM_BUFFER && shdrIn.descriptorSection.uniformBufferObject.set==1u && shdrIn.descriptorSection.uniformBufferObject.binding==ds1UboBinding)
551551
{
552552
switch (shdrIn.type)
553553
{
554-
case asset::IPipelineMetadata::ECSI_WORLD_VIEW_PROJ:
554+
case asset::IRenderpassIndependentPipelineMetadata::ECSI_WORLD_VIEW_PROJ:
555555
{
556556
core::matrix4SIMD mvp = camera->getConcatenatedMatrix();
557557
memcpy(uboData.data()+shdrIn.descriptorSection.uniformBufferObject.relByteoffset, mvp.pointer(), shdrIn.descriptorSection.uniformBufferObject.bytesize);
558558
}
559559
break;
560-
case asset::IPipelineMetadata::ECSI_WORLD_VIEW:
560+
case asset::IRenderpassIndependentPipelineMetadata::ECSI_WORLD_VIEW:
561561
{
562562
core::matrix3x4SIMD MV = camera->getViewMatrix();
563563
memcpy(uboData.data() + shdrIn.descriptorSection.uniformBufferObject.relByteoffset, MV.pointer(), shdrIn.descriptorSection.uniformBufferObject.bytesize);
564564
}
565565
break;
566-
case asset::IPipelineMetadata::ECSI_WORLD_VIEW_INVERSE_TRANSPOSE:
566+
case asset::IRenderpassIndependentPipelineMetadata::ECSI_WORLD_VIEW_INVERSE_TRANSPOSE:
567567
{
568568
core::matrix3x4SIMD MV = camera->getViewMatrix();
569569
memcpy(uboData.data()+shdrIn.descriptorSection.uniformBufferObject.relByteoffset, MV.pointer(), shdrIn.descriptorSection.uniformBufferObject.bytesize);
@@ -575,9 +575,8 @@ int main()
575575
driver->updateBufferRangeViaStagingBuffer(gpuubo.get(), 0ull, gpuubo->getSize(), uboData.data());
576576

577577
// draw the meshbuffers and compute lines
578-
for (uint32_t i = 0u; i < gpumesh->getMeshBufferCount(); ++i)
578+
for (auto gpumb : gpumesh->getMeshBuffers())
579579
{
580-
video::IGPUMeshBuffer* gpumb = gpumesh->getMeshBuffer(i);
581580
const video::IGPURenderpassIndependentPipeline* pipeline = gpumb->getPipeline();
582581
const video::IGPUDescriptorSet* ds3 = gpumb->getAttachedDescriptorSet();
583582

include/nbl/asset/utils/CCPUMeshPacker.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ MeshPackerBase::ReservedAllocationMeshBuffers CCPUMeshPacker<MDIStructType>::all
118118

119119
auto* pipeline = (*it)->getPipeline();
120120

121-
if ((*it)->getIndexBufferBinding()->buffer.get() == nullptr ||
121+
if ((*it)->getIndexBufferBinding().buffer.get() == nullptr ||
122122
pipeline->getPrimitiveAssemblyParams().primitiveType != EPT_TRIANGLE_LIST)
123123
{
124124
_NBL_DEBUG_BREAK_IF(true);
@@ -150,9 +150,9 @@ MeshPackerBase::ReservedAllocationMeshBuffers CCPUMeshPacker<MDIStructType>::all
150150
size_t vtxCnt = 0u;
151151
for (auto it = begin; it != end; it++)
152152
{
153-
ICPUMeshBuffer& mb = **it;
154-
idxCnt += mb.getIndexCount();
155-
vtxCnt += mb.calcVertexCount();
153+
ICPUMeshBuffer* mb = it->get();
154+
idxCnt += mb->getIndexCount();
155+
vtxCnt += IMeshManipulator::upperBoundVertexID(mb);
156156
}
157157

158158
const uint32_t minIdxCntPerPatch = m_minTriangleCountPerMDIData * 3;
@@ -365,9 +365,9 @@ auto CCPUMeshPacker<MDIStructType>::constructTriangleBatches(ICPUMeshBuffer& mes
365365

366366
//TODO: triangle reordering
367367

368-
auto* srcIdxBuffer = meshBuffer.getIndexBufferBinding();
369-
uint32_t* idxBufferPtr32Bit = static_cast<uint32_t*>(srcIdxBuffer->buffer->getPointer()) + (srcIdxBuffer->offset / sizeof(uint32_t)); //will be changed after benchmarks
370-
uint16_t* idxBufferPtr16Bit = static_cast<uint16_t*>(srcIdxBuffer->buffer->getPointer()) + (srcIdxBuffer->offset / sizeof(uint16_t));
368+
const auto& srcIdxBuffer = meshBuffer.getIndexBufferBinding();
369+
auto idxBufferPtr32Bit = static_cast<const uint32_t*>(srcIdxBuffer.buffer->getPointer()) + (srcIdxBuffer.offset / sizeof(uint32_t)); //will be changed after benchmarks
370+
auto idxBufferPtr16Bit = static_cast<const uint16_t*>(srcIdxBuffer.buffer->getPointer()) + (srcIdxBuffer.offset / sizeof(uint16_t));
371371
for (TriangleBatch& batch : output)
372372
{
373373
for (Triangle& tri : batch.triangles)

include/nbl/asset/utils/IMeshManipulator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,10 @@ class IMeshManipulator : public virtual core::IReferenceCounted
596596
return false;
597597

598598
bool retval = true;
599-
for (uint32_t g = 0; g < mesh->getMeshBufferCount(); ++g)
599+
for (auto mb : mesh->getMeshBuffers())
600600
{
601601
uint32_t trianglecount;
602-
retval = retval && getPolyCount(trianglecount, mesh->getMeshBuffer(g));
602+
retval = retval && getPolyCount(trianglecount,mb);
603603
outCount += trianglecount;
604604
}
605605

0 commit comments

Comments
 (0)