Skip to content

Commit 6abb8fb

Browse files
Fixed ex 20,21
1 parent 40b9b7e commit 6abb8fb

File tree

3 files changed

+45
-50
lines changed

3 files changed

+45
-50
lines changed

examples_tests/20.Megatexture/main.cpp

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
//! I advise to check out this file, its a basic input handler
1111
#include "../common/QToQuitEventReceiver.h"
1212
#include <nbl/video/IGPUVirtualTexture.h>
13-
#include <nbl/asset/CMTLPipelineMetadata.h>
1413
#include "nbl/ext/FullScreenTriangle/FullScreenTriangle.h"
15-
#include <nbl/asset/filters/CMipMapGenerationImageFilter.h>
1614

1715
//#include "nbl/ext/ScreenShot/ScreenShot.h"
1816
using namespace nbl;
@@ -177,12 +175,12 @@ struct SPushConstants
177175
static_assert(sizeof(SPushConstants)<=asset::ICPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE, "doesnt fit in push constants");
178176

179177
constexpr uint32_t texturesOfInterest[TEX_OF_INTEREST_CNT]{
180-
asset::CMTLPipelineMetadata::EMP_AMBIENT,
181-
asset::CMTLPipelineMetadata::EMP_DIFFUSE,
182-
asset::CMTLPipelineMetadata::EMP_SPECULAR,
183-
asset::CMTLPipelineMetadata::EMP_SHININESS,
184-
asset::CMTLPipelineMetadata::EMP_OPACITY,
185-
asset::CMTLPipelineMetadata::EMP_BUMP
178+
asset::CMTLMetadata::CRenderpassIndependentPipeline::EMP_AMBIENT,
179+
asset::CMTLMetadata::CRenderpassIndependentPipeline::EMP_DIFFUSE,
180+
asset::CMTLMetadata::CRenderpassIndependentPipeline::EMP_SPECULAR,
181+
asset::CMTLMetadata::CRenderpassIndependentPipeline::EMP_SHININESS,
182+
asset::CMTLMetadata::CRenderpassIndependentPipeline::EMP_OPACITY,
183+
asset::CMTLMetadata::CRenderpassIndependentPipeline::EMP_BUMP
186184
};
187185

188186
core::smart_refctd_ptr<asset::ICPUSpecializedShader> createModifiedFragShader(const asset::ICPUSpecializedShader* _fs, const asset::ICPUVirtualTexture* _vt)
@@ -290,19 +288,23 @@ int main()
290288

291289
asset::IAssetLoader::SAssetLoadParams lp;
292290
auto meshes_bundle = am->getAsset("sponza.obj", lp);
293-
assert(!meshes_bundle.isEmpty());
291+
assert(!meshes_bundle.getContents().empty());
292+
293+
const auto meta = meshes_bundle.getMetadata()->selfCast<const asset::COBJMetadata>();
294+
294295
auto mesh = meshes_bundle.getContents().begin()[0];
295296
auto mesh_raw = static_cast<asset::ICPUMesh*>(mesh.get());
296297

298+
// all pipelines will have the same metadata
299+
const asset::CMTLMetadata::CRenderpassIndependentPipeline* pipelineMetadata = nullptr;
297300
core::vector<commit_t> vt_commits;
298301
//modifying push constants and default fragment shader for VT
299-
for (uint32_t i = 0u; i < mesh_raw->getMeshBufferCount(); ++i)
302+
for (auto mb : mesh_raw->getMeshBuffers())
300303
{
301304
SPushConstants pushConsts;
302305
memset(pushConsts.map_data, 0xff, TEX_OF_INTEREST_CNT*sizeof(pushConsts.map_data[0]));
303306
pushConsts.extra = 0u;
304307

305-
auto* mb = mesh_raw->getMeshBuffer(i);
306308
auto* ds = mb->getAttachedDescriptorSet();
307309
if (!ds)
308310
continue;
@@ -333,24 +335,24 @@ int main()
333335
pushConsts.map_data[k] = reinterpret_cast<uint64_t*>(&texData)[0];
334336
}
335337

336-
auto* pipeline = mb->getPipeline();
337-
auto* metadata = static_cast<asset::CMTLPipelineMetadata*>( pipeline->getMetadata() );
338+
pipelineMetadata = static_cast<const asset::CMTLMetadata::CRenderpassIndependentPipeline*>(meta->getAssetSpecificMetadata(mb->getPipeline()));
338339

339340
//copy texture presence flags
340-
pushConsts.extra = metadata->getMaterialParams().extra;
341-
pushConsts.ambient = metadata->getMaterialParams().ambient;
342-
pushConsts.diffuse = metadata->getMaterialParams().diffuse;
343-
pushConsts.emissive = metadata->getMaterialParams().emissive;
344-
pushConsts.specular = metadata->getMaterialParams().specular;
345-
pushConsts.IoR = metadata->getMaterialParams().IoR;
346-
pushConsts.opacity = metadata->getMaterialParams().opacity;
347-
pushConsts.shininess = metadata->getMaterialParams().shininess;
341+
pushConsts.extra = pipelineMetadata->m_materialParams.extra;
342+
pushConsts.ambient = pipelineMetadata->m_materialParams.ambient;
343+
pushConsts.diffuse = pipelineMetadata->m_materialParams.diffuse;
344+
pushConsts.emissive = pipelineMetadata->m_materialParams.emissive;
345+
pushConsts.specular = pipelineMetadata->m_materialParams.specular;
346+
pushConsts.IoR = pipelineMetadata->m_materialParams.IoR;
347+
pushConsts.opacity = pipelineMetadata->m_materialParams.opacity;
348+
pushConsts.shininess = pipelineMetadata->m_materialParams.shininess;
348349
memcpy(mb->getPushConstantsDataPtr(), &pushConsts, sizeof(pushConsts));
349350

350351
//we dont want this DS to be converted into GPU DS, so set to nullptr
351352
//dont worry about deletion of textures (invalidation of pointers), they're grabbed in VTtexDataMap
352353
mb->setAttachedDescriptorSet(nullptr);
353354
}
355+
assert(pipelineMetadata);
354356

355357
core::smart_refctd_ptr<asset::ICPUDescriptorSetLayout> ds0layout;
356358
{
@@ -383,15 +385,15 @@ int main()
383385
pipelineLayout = core::make_smart_refctd_ptr<asset::ICPUPipelineLayout>(&pcrng, &pcrng + 1, core::smart_refctd_ptr(ds0layout), nullptr, core::smart_refctd_ptr(ds2layout), nullptr);
384386
}
385387

386-
for (uint32_t i = 0u; i < mesh_raw->getMeshBufferCount(); ++i)
388+
for (auto mb : mesh_raw->getMeshBuffers())
387389
{
388-
auto* mb = mesh_raw->getMeshBuffer(i);
389-
390390
auto* pipeline = mb->getPipeline();
391+
391392
auto newPipeline = core::smart_refctd_ptr_static_cast<asset::ICPURenderpassIndependentPipeline>(pipeline->clone(0u));//shallow copy
392393
//leave original ds1 layout since it's for UBO with matrices
393394
if (!pipelineLayout->getDescriptorSetLayout(1u))
394395
pipelineLayout->setDescriptorSetLayout(1u, core::smart_refctd_ptr<asset::ICPUDescriptorSetLayout>(pipeline->getLayout()->getDescriptorSetLayout(1u)));
396+
395397
newPipeline->setLayout(core::smart_refctd_ptr(pipelineLayout));
396398
{
397399
auto* fs = pipeline->getShaderAtIndex(asset::ICPURenderpassIndependentPipeline::ESSI_FRAGMENT_SHADER_IX);
@@ -405,8 +407,6 @@ int main()
405407
}
406408
newPipeline->setShaderAtIndex(asset::ICPURenderpassIndependentPipeline::ESSI_FRAGMENT_SHADER_IX, newfs.get());
407409
}
408-
auto* metadata = static_cast<asset::CMTLPipelineMetadata*>(pipeline->getMetadata());
409-
am->setAssetMetadata(newPipeline.get(), core::smart_refctd_ptr<asset::IAssetMetadata>(metadata));
410410

411411
//set new pipeline (with overriden FS and layout)
412412
mb->setPipeline(std::move(newPipeline));
@@ -435,7 +435,7 @@ int main()
435435
//we can safely assume that all meshbuffers within mesh loaded from OBJ has same DS1 layout (used for camera-specific data)
436436
//so we can create just one DS
437437

438-
asset::ICPUDescriptorSetLayout* ds1layout = mesh_raw->getMeshBuffer(0u)->getPipeline()->getLayout()->getDescriptorSetLayout(1u);
438+
asset::ICPUDescriptorSetLayout* ds1layout = mesh_raw->getMeshBuffers().begin()[0]->getPipeline()->getLayout()->getDescriptorSetLayout(1u);
439439
uint32_t ds1UboBinding = 0u;
440440
for (const auto& bnd : ds1layout->getBindings())
441441
if (bnd.type==asset::EDT_UNIFORM_BUFFER)
@@ -446,9 +446,8 @@ int main()
446446

447447
size_t neededDS1UBOsz = 0ull;
448448
{
449-
auto pipelineMetadata = static_cast<const asset::IPipelineMetadata*>(mesh_raw->getMeshBuffer(0u)->getPipeline()->getMetadata());
450-
for (const auto& shdrIn : pipelineMetadata->getCommonRequiredInputs())
451-
if (shdrIn.descriptorSection.type==asset::IPipelineMetadata::ShaderInput::ET_UNIFORM_BUFFER && shdrIn.descriptorSection.uniformBufferObject.set==1u && shdrIn.descriptorSection.uniformBufferObject.binding==ds1UboBinding)
449+
for (const auto& shdrIn : pipelineMetadata->getRequiredShaderInputs())
450+
if (shdrIn.descriptorSection.type==asset::IRenderpassIndependentPipelineMetadata::ShaderInput::ET_UNIFORM_BUFFER && shdrIn.descriptorSection.uniformBufferObject.set==1u && shdrIn.descriptorSection.uniformBufferObject.binding==ds1UboBinding)
452451
neededDS1UBOsz = std::max<size_t>(neededDS1UBOsz, shdrIn.descriptorSection.uniformBufferObject.relByteoffset+shdrIn.descriptorSection.uniformBufferObject.bytesize);
453452
}
454453

@@ -519,26 +518,25 @@ int main()
519518
camera->render();
520519

521520
core::vector<uint8_t> uboData(gpuubo->getSize());
522-
auto pipelineMetadata = static_cast<const asset::IPipelineMetadata*>(mesh_raw->getMeshBuffer(0u)->getPipeline()->getMetadata());
523-
for (const auto& shdrIn : pipelineMetadata->getCommonRequiredInputs())
521+
for (const auto& shdrIn : pipelineMetadata->getRequiredShaderInputs())
524522
{
525-
if (shdrIn.descriptorSection.type==asset::IPipelineMetadata::ShaderInput::ET_UNIFORM_BUFFER && shdrIn.descriptorSection.uniformBufferObject.set==1u && shdrIn.descriptorSection.uniformBufferObject.binding==ds1UboBinding)
523+
if (shdrIn.descriptorSection.type==asset::IRenderpassIndependentPipelineMetadata::ShaderInput::ET_UNIFORM_BUFFER && shdrIn.descriptorSection.uniformBufferObject.set==1u && shdrIn.descriptorSection.uniformBufferObject.binding==ds1UboBinding)
526524
{
527525
switch (shdrIn.type)
528526
{
529-
case asset::IPipelineMetadata::ECSI_WORLD_VIEW_PROJ:
527+
case asset::IRenderpassIndependentPipelineMetadata::ECSI_WORLD_VIEW_PROJ:
530528
{
531529
core::matrix4SIMD mvp = camera->getConcatenatedMatrix();
532530
memcpy(uboData.data()+shdrIn.descriptorSection.uniformBufferObject.relByteoffset, mvp.pointer(), shdrIn.descriptorSection.uniformBufferObject.bytesize);
533531
}
534532
break;
535-
case asset::IPipelineMetadata::ECSI_WORLD_VIEW:
533+
case asset::IRenderpassIndependentPipelineMetadata::ECSI_WORLD_VIEW:
536534
{
537535
core::matrix3x4SIMD MV = camera->getViewMatrix();
538536
memcpy(uboData.data() + shdrIn.descriptorSection.uniformBufferObject.relByteoffset, MV.pointer(), shdrIn.descriptorSection.uniformBufferObject.bytesize);
539537
}
540538
break;
541-
case asset::IPipelineMetadata::ECSI_WORLD_VIEW_INVERSE_TRANSPOSE:
539+
case asset::IRenderpassIndependentPipelineMetadata::ECSI_WORLD_VIEW_INVERSE_TRANSPOSE:
542540
{
543541
core::matrix3x4SIMD MV = camera->getViewMatrix();
544542
memcpy(uboData.data()+shdrIn.descriptorSection.uniformBufferObject.relByteoffset, MV.pointer(), shdrIn.descriptorSection.uniformBufferObject.bytesize);
@@ -549,9 +547,8 @@ int main()
549547
}
550548
driver->updateBufferRangeViaStagingBuffer(gpuubo.get(), 0ull, gpuubo->getSize(), uboData.data());
551549

552-
for (uint32_t i = 0u; i < gpumesh->getMeshBufferCount(); ++i)
550+
for (auto gpumb : gpumesh->getMeshBuffers())
553551
{
554-
video::IGPUMeshBuffer* gpumb = gpumesh->getMeshBuffer(i);
555552
const video::IGPURenderpassIndependentPipeline* pipeline = gpumb->getPipeline();
556553

557554
driver->bindGraphicsPipeline(pipeline);

examples_tests/21.DynamicTextureIndexing/main.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
//! I advise to check out this file, its a basic input handler
99
#include "../common/QToQuitEventReceiver.h"
10-
#include <nbl/asset/CCPUMeshPacker.h>
11-
//#include "nbl/ext/ScreenShot/ScreenShot.h"
10+
#include "nbl/asset/utils/CCPUMeshPacker.h"
1211

1312
using namespace nbl;
1413
using namespace core;
@@ -63,13 +62,12 @@ int main()
6362
auto mesh_raw = static_cast<asset::ICPUMesh*>(mesh.get());
6463

6564
//saving cache to file
66-
//qnc->saveCacheToFile(asset::CQuantNormalCache::E_CACHE_TYPE::ECT_2_10_10_10, fs, "../../tmp/normalCache101010.sse");
67-
68-
const uint32_t mbCount = mesh_raw->getMeshBufferCount();
65+
qnc->saveCacheToFile(asset::CQuantNormalCache::E_CACHE_TYPE::ECT_2_10_10_10, fs, "../../tmp/normalCache101010.sse");
6966

70-
core::vector<ICPUMeshBuffer*> meshBuffers(mbCount);
71-
for (uint32_t i = 0u; i < mbCount; i++)
72-
meshBuffers[i] = mesh_raw->getMeshBuffer(i);
67+
const auto meta = meshes_bundle.getMetadata()->selfCast<const COBJMetadata>();
68+
69+
const auto meshbuffers = mesh_raw->getMeshBuffers();
70+
core::vector<ICPUMeshBuffer*> meshBuffers(meshbuffers.begin(),meshbuffers.end());
7371

7472
//divide mesh buffers into sets, where sum of textures used by meshes in one set is <= 16
7573
struct MBRangeTexturesPair
@@ -87,7 +85,7 @@ int main()
8785

8886
for (auto it = meshBuffers.begin(); it < meshBuffers.end(); it++)
8987
{
90-
auto ds3 = dynamic_cast<CMTLPipelineMetadata*>((*it)->getPipeline()->getMetadata())->getDescriptorSet();
88+
auto ds3 = (*it)->getAttachedDescriptorSet();
9189
ICPUImageView* tex = dynamic_cast<ICPUImageView*>(ds3->getDescriptors(0u).begin()->desc.get());
9290
ICPUImageView* texBump = dynamic_cast<ICPUImageView*>(ds3->getDescriptors(6u).begin()->desc.get());
9391

@@ -140,7 +138,7 @@ int main()
140138
core::vector<core::smart_refctd_ptr<IGPUBuffer>> gpuIndirectDrawBuffer(mbRangesTex.size());
141139
for(size_t i = 0u; i < mbRangesTex.size(); i++)
142140
{
143-
asset::SVertexInputParams& inputParams = mesh_raw->getMeshBuffer(0u)->getPipeline()->getVertexInputParams();
141+
asset::SVertexInputParams& inputParams = mesh_raw->getMeshBuffers().begin()[0]->getPipeline()->getVertexInputParams();
144142
asset::MeshPackerBase::AllocationParams allocationParams;
145143

146144
auto& mbRange = mbRangesTex[i].mbRanges;
@@ -180,7 +178,7 @@ int main()
180178
uint32_t mbIdx = 0u;
181179
for (auto it = mbRange.begin(); it != mbRange.end(); it++)
182180
{
183-
auto ds3 = dynamic_cast<CMTLPipelineMetadata*>((*it)->getPipeline()->getMetadata())->getDescriptorSet();
181+
auto ds3 = (*it)->getAttachedDescriptorSet();
184182
ICPUImageView* tex = dynamic_cast<ICPUImageView*>(ds3->getDescriptors(0u).begin()->desc.get());
185183
ICPUImageView* texBump = dynamic_cast<ICPUImageView*>(ds3->getDescriptors(6u).begin()->desc.get());
186184

include/nbl/asset/utils/CCPUMeshPacker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ MeshPackerBase::ReservedAllocationMeshBuffers CCPUMeshPacker<MDIStructType>::all
150150
size_t vtxCnt = 0u;
151151
for (auto it = begin; it != end; it++)
152152
{
153-
ICPUMeshBuffer* mb = it->get();
153+
ICPUMeshBuffer* mb = *it;
154154
idxCnt += mb->getIndexCount();
155155
vtxCnt += IMeshManipulator::upperBoundVertexID(mb);
156156
}

0 commit comments

Comments
 (0)