10
10
// ! I advise to check out this file, its a basic input handler
11
11
#include " ../common/QToQuitEventReceiver.h"
12
12
#include < nbl/video/IGPUVirtualTexture.h>
13
- #include < nbl/asset/CMTLPipelineMetadata.h>
14
13
#include " nbl/ext/FullScreenTriangle/FullScreenTriangle.h"
15
- #include < nbl/asset/filters/CMipMapGenerationImageFilter.h>
16
14
17
15
// #include "nbl/ext/ScreenShot/ScreenShot.h"
18
16
using namespace nbl ;
@@ -177,12 +175,12 @@ struct SPushConstants
177
175
static_assert (sizeof (SPushConstants)<=asset::ICPUMeshBuffer::MAX_PUSH_CONSTANT_BYTESIZE, "doesnt fit in push constants");
178
176
179
177
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
186
184
};
187
185
188
186
core::smart_refctd_ptr<asset::ICPUSpecializedShader> createModifiedFragShader (const asset::ICPUSpecializedShader* _fs, const asset::ICPUVirtualTexture* _vt)
@@ -290,19 +288,23 @@ int main()
290
288
291
289
asset::IAssetLoader::SAssetLoadParams lp;
292
290
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
+
294
295
auto mesh = meshes_bundle.getContents ().begin ()[0 ];
295
296
auto mesh_raw = static_cast <asset::ICPUMesh*>(mesh.get ());
296
297
298
+ // all pipelines will have the same metadata
299
+ const asset::CMTLMetadata::CRenderpassIndependentPipeline* pipelineMetadata = nullptr ;
297
300
core::vector<commit_t > vt_commits;
298
301
// 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 () )
300
303
{
301
304
SPushConstants pushConsts;
302
305
memset (pushConsts.map_data , 0xff , TEX_OF_INTEREST_CNT*sizeof (pushConsts.map_data [0 ]));
303
306
pushConsts.extra = 0u ;
304
307
305
- auto * mb = mesh_raw->getMeshBuffer (i);
306
308
auto * ds = mb->getAttachedDescriptorSet ();
307
309
if (!ds)
308
310
continue ;
@@ -333,24 +335,24 @@ int main()
333
335
pushConsts.map_data [k] = reinterpret_cast <uint64_t *>(&texData)[0 ];
334
336
}
335
337
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 ()));
338
339
339
340
// 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 ;
348
349
memcpy (mb->getPushConstantsDataPtr (), &pushConsts, sizeof (pushConsts));
349
350
350
351
// we dont want this DS to be converted into GPU DS, so set to nullptr
351
352
// dont worry about deletion of textures (invalidation of pointers), they're grabbed in VTtexDataMap
352
353
mb->setAttachedDescriptorSet (nullptr );
353
354
}
355
+ assert (pipelineMetadata);
354
356
355
357
core::smart_refctd_ptr<asset::ICPUDescriptorSetLayout> ds0layout;
356
358
{
@@ -383,15 +385,15 @@ int main()
383
385
pipelineLayout = core::make_smart_refctd_ptr<asset::ICPUPipelineLayout>(&pcrng, &pcrng + 1 , core::smart_refctd_ptr (ds0layout), nullptr , core::smart_refctd_ptr (ds2layout), nullptr );
384
386
}
385
387
386
- for (uint32_t i = 0u ; i < mesh_raw->getMeshBufferCount (); ++i )
388
+ for (auto mb : mesh_raw->getMeshBuffers () )
387
389
{
388
- auto * mb = mesh_raw->getMeshBuffer (i);
389
-
390
390
auto * pipeline = mb->getPipeline ();
391
+
391
392
auto newPipeline = core::smart_refctd_ptr_static_cast<asset::ICPURenderpassIndependentPipeline>(pipeline->clone (0u ));// shallow copy
392
393
// leave original ds1 layout since it's for UBO with matrices
393
394
if (!pipelineLayout->getDescriptorSetLayout (1u ))
394
395
pipelineLayout->setDescriptorSetLayout (1u , core::smart_refctd_ptr<asset::ICPUDescriptorSetLayout>(pipeline->getLayout ()->getDescriptorSetLayout (1u )));
396
+
395
397
newPipeline->setLayout (core::smart_refctd_ptr (pipelineLayout));
396
398
{
397
399
auto * fs = pipeline->getShaderAtIndex (asset::ICPURenderpassIndependentPipeline::ESSI_FRAGMENT_SHADER_IX);
@@ -405,8 +407,6 @@ int main()
405
407
}
406
408
newPipeline->setShaderAtIndex (asset::ICPURenderpassIndependentPipeline::ESSI_FRAGMENT_SHADER_IX, newfs.get ());
407
409
}
408
- auto * metadata = static_cast <asset::CMTLPipelineMetadata*>(pipeline->getMetadata ());
409
- am->setAssetMetadata (newPipeline.get (), core::smart_refctd_ptr<asset::IAssetMetadata>(metadata));
410
410
411
411
// set new pipeline (with overriden FS and layout)
412
412
mb->setPipeline (std::move (newPipeline));
@@ -435,7 +435,7 @@ int main()
435
435
// we can safely assume that all meshbuffers within mesh loaded from OBJ has same DS1 layout (used for camera-specific data)
436
436
// so we can create just one DS
437
437
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 );
439
439
uint32_t ds1UboBinding = 0u ;
440
440
for (const auto & bnd : ds1layout->getBindings ())
441
441
if (bnd.type ==asset::EDT_UNIFORM_BUFFER)
@@ -446,9 +446,8 @@ int main()
446
446
447
447
size_t neededDS1UBOsz = 0ull ;
448
448
{
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)
452
451
neededDS1UBOsz = std::max<size_t >(neededDS1UBOsz, shdrIn.descriptorSection .uniformBufferObject .relByteoffset +shdrIn.descriptorSection .uniformBufferObject .bytesize );
453
452
}
454
453
@@ -519,26 +518,25 @@ int main()
519
518
camera->render ();
520
519
521
520
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 ())
524
522
{
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)
526
524
{
527
525
switch (shdrIn.type )
528
526
{
529
- case asset::IPipelineMetadata ::ECSI_WORLD_VIEW_PROJ:
527
+ case asset::IRenderpassIndependentPipelineMetadata ::ECSI_WORLD_VIEW_PROJ:
530
528
{
531
529
core::matrix4SIMD mvp = camera->getConcatenatedMatrix ();
532
530
memcpy (uboData.data ()+shdrIn.descriptorSection .uniformBufferObject .relByteoffset , mvp.pointer (), shdrIn.descriptorSection .uniformBufferObject .bytesize );
533
531
}
534
532
break ;
535
- case asset::IPipelineMetadata ::ECSI_WORLD_VIEW:
533
+ case asset::IRenderpassIndependentPipelineMetadata ::ECSI_WORLD_VIEW:
536
534
{
537
535
core::matrix3x4SIMD MV = camera->getViewMatrix ();
538
536
memcpy (uboData.data () + shdrIn.descriptorSection .uniformBufferObject .relByteoffset , MV.pointer (), shdrIn.descriptorSection .uniformBufferObject .bytesize );
539
537
}
540
538
break ;
541
- case asset::IPipelineMetadata ::ECSI_WORLD_VIEW_INVERSE_TRANSPOSE:
539
+ case asset::IRenderpassIndependentPipelineMetadata ::ECSI_WORLD_VIEW_INVERSE_TRANSPOSE:
542
540
{
543
541
core::matrix3x4SIMD MV = camera->getViewMatrix ();
544
542
memcpy (uboData.data ()+shdrIn.descriptorSection .uniformBufferObject .relByteoffset , MV.pointer (), shdrIn.descriptorSection .uniformBufferObject .bytesize );
@@ -549,9 +547,8 @@ int main()
549
547
}
550
548
driver->updateBufferRangeViaStagingBuffer (gpuubo.get (), 0ull , gpuubo->getSize (), uboData.data ());
551
549
552
- for (uint32_t i = 0u ; i < gpumesh->getMeshBufferCount (); ++i )
550
+ for (auto gpumb : gpumesh->getMeshBuffers () )
553
551
{
554
- video::IGPUMeshBuffer* gpumb = gpumesh->getMeshBuffer (i);
555
552
const video::IGPURenderpassIndependentPipeline* pipeline = gpumb->getPipeline ();
556
553
557
554
driver->bindGraphicsPipeline (pipeline);
0 commit comments