13
13
14
14
using namespace nbl ;
15
15
using namespace core ;
16
+ using namespace ui ;
16
17
17
18
/*
18
19
Uncomment for more detailed logging
@@ -34,7 +35,11 @@ int main()
34
35
constexpr uint32_t FRAMES_IN_FLIGHT = 5u ;
35
36
static_assert (FRAMES_IN_FLIGHT > SC_IMG_COUNT);
36
37
37
- auto initOutput = CommonAPI::Init<WIN_W, WIN_H, SC_IMG_COUNT>(video::EAT_OPENGL, " Ply and Stl demo" , nbl::asset::EF_D32_SFLOAT);
38
+ CommonAPI::InitOutput initOutput;
39
+ const auto swapchainImageUsage = static_cast <asset::IImage::E_USAGE_FLAGS>(asset::IImage::EUF_COLOR_ATTACHMENT_BIT | asset::IImage::EUF_TRANSFER_DST_BIT);
40
+ const video::ISurface::SFormat surfaceFormat (asset::EF_B8G8R8A8_SRGB, asset::ECP_COUNT, asset::EOTF_UNKNOWN);
41
+ CommonAPI::InitWithDefaultExt (initOutput, video::EAT_OPENGL, " Ply and Stl demo" , WIN_W, WIN_H, SC_IMG_COUNT, swapchainImageUsage, surfaceFormat, nbl::asset::EF_D32_SFLOAT);
42
+
38
43
auto window = std::move (initOutput.window );
39
44
auto gl = std::move (initOutput.apiConnection );
40
45
auto surface = std::move (initOutput.surface );
@@ -44,13 +49,16 @@ int main()
44
49
auto swapchain = std::move (initOutput.swapchain );
45
50
auto renderpass = std::move (initOutput.renderpass );
46
51
auto fbos = std::move (initOutput.fbo );
47
- auto commandPool = std::move (initOutput.commandPool );
52
+ auto commandPools = std::move (initOutput.commandPools );
48
53
auto assetManager = std::move (initOutput.assetManager );
49
54
auto logger = std::move (initOutput.logger );
50
55
auto inputSystem = std::move (initOutput.inputSystem );
51
56
auto system = std::move (initOutput.system );
52
57
auto windowCallback = std::move (initOutput.windowCb );
53
58
auto utilities = std::move (initOutput.utilities );
59
+ auto cpu2gpuParams = std::move (initOutput.cpu2gpuParams );
60
+
61
+ nbl::video::IGPUObjectFromAssetConverter cpu2gpu;
54
62
55
63
auto createDescriptorPool = [&](const uint32_t count, asset::E_DESCRIPTOR_TYPE type)
56
64
{
@@ -63,54 +71,21 @@ int main()
63
71
}
64
72
};
65
73
66
- nbl::video::IGPUObjectFromAssetConverter cpu2gpu;
67
- nbl::video::IGPUObjectFromAssetConverter::SParams cpu2gpuParams;
68
-
69
- nbl::core::smart_refctd_ptr<nbl::video::IGPUFence> gpuTransferFence;
70
- nbl::core::smart_refctd_ptr<nbl::video::IGPUSemaphore> gpuTransferSemaphore;
71
-
72
- nbl::core::smart_refctd_ptr<nbl::video::IGPUFence> gpuComputeFence;
73
- nbl::core::smart_refctd_ptr<nbl::video::IGPUSemaphore> gpuComputeSemaphore;
74
-
74
+ auto loadAndGetCpuMesh = [&](std::string path) -> std::pair<core::smart_refctd_ptr<asset::ICPUMesh>, const asset::IAssetMetadata*>
75
75
{
76
- gpuTransferFence = logicalDevice->createFence (static_cast <video::IGPUFence::E_CREATE_FLAGS>(0 ));
77
- gpuTransferSemaphore = logicalDevice->createSemaphore ();
78
-
79
- gpuComputeFence = logicalDevice->createFence (static_cast <video::IGPUFence::E_CREATE_FLAGS>(0 ));
80
- gpuComputeSemaphore = logicalDevice->createSemaphore ();
81
-
82
- cpu2gpuParams.assetManager = assetManager.get ();
83
- cpu2gpuParams.device = logicalDevice.get ();
84
- cpu2gpuParams.finalQueueFamIx = queues[decltype (initOutput)::EQT_GRAPHICS]->getFamilyIndex ();
85
- cpu2gpuParams.limits = gpuPhysicalDevice->getLimits ();
86
- cpu2gpuParams.pipelineCache = nullptr ;
87
- cpu2gpuParams.sharingMode = nbl::asset::ESM_CONCURRENT;
88
- cpu2gpuParams.utilities = utilities.get ();
89
-
90
- cpu2gpuParams.perQueue [nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].fence = &gpuTransferFence;
91
- cpu2gpuParams.perQueue [nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].semaphore = &gpuTransferSemaphore;
92
- cpu2gpuParams.perQueue [nbl::video::IGPUObjectFromAssetConverter::EQU_TRANSFER].queue = queues[decltype (initOutput)::EQT_TRANSFER_UP];
93
-
94
- cpu2gpuParams.perQueue [nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].fence = &gpuComputeFence;
95
- cpu2gpuParams.perQueue [nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].semaphore = &gpuComputeSemaphore;
96
- cpu2gpuParams.perQueue [nbl::video::IGPUObjectFromAssetConverter::EQU_COMPUTE].queue = queues[decltype (initOutput)::EQT_COMPUTE];
97
- }
98
-
99
- auto loadAndGetCpuMesh = [&](std::string path) -> std::pair<core::smart_refctd_ptr<asset::ICPUMesh>, const asset::IAssetMetadata*>
100
- {
101
76
auto meshes_bundle = assetManager->getAsset (path, {});
102
77
{
103
78
bool status = !meshes_bundle.getContents ().empty ();
104
79
assert (status);
105
80
}
106
81
107
- return std::make_pair (core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(meshes_bundle.getContents ().begin ()[0 ]), meshes_bundle.getMetadata ());
108
- };
82
+ return std::make_pair (core::smart_refctd_ptr_static_cast<asset::ICPUMesh>(meshes_bundle.getContents ().begin ()[0 ]), meshes_bundle.getMetadata ());
83
+ };
109
84
110
85
auto cpuBundlePLYData = loadAndGetCpuMesh (" ../../media/ply/Spanner-ply.ply" );
111
86
auto cpuBundleSTLData = loadAndGetCpuMesh (" ../../media/extrusionLogo_TEST_fixed.stl" );
112
87
113
- core::smart_refctd_ptr<asset::ICPUMesh> cpuMeshPly = cpuBundlePLYData.first ;
88
+ core::smart_refctd_ptr<asset::ICPUMesh> cpuMeshPly = cpuBundlePLYData.first ;
114
89
auto metadataPly = cpuBundlePLYData.second ->selfCast <const asset::CPLYMetadata>();
115
90
116
91
core::smart_refctd_ptr<asset::ICPUMesh> cpuMeshStl = cpuBundleSTLData.first ;
@@ -275,7 +250,7 @@ int main()
275
250
dtList[i] = 0.0 ;
276
251
277
252
core::smart_refctd_ptr<video::IGPUCommandBuffer> commandBuffers[FRAMES_IN_FLIGHT];
278
- logicalDevice->createCommandBuffers (commandPool .get (), video::IGPUCommandBuffer::EL_PRIMARY, FRAMES_IN_FLIGHT, commandBuffers);
253
+ logicalDevice->createCommandBuffers (commandPools[CommonAPI::InitOutput::EQT_GRAPHICS] .get (), video::IGPUCommandBuffer::EL_PRIMARY, FRAMES_IN_FLIGHT, commandBuffers);
279
254
280
255
core::smart_refctd_ptr<video::IGPUFence> frameComplete[FRAMES_IN_FLIGHT] = { nullptr };
281
256
core::smart_refctd_ptr<video::IGPUSemaphore> imageAcquire[FRAMES_IN_FLIGHT] = { nullptr };
@@ -429,12 +404,12 @@ int main()
429
404
commandBuffer->bindGraphicsPipeline (gpuGraphicsPipeline.get ());
430
405
431
406
const video::IGPUDescriptorSet* gpuds1_ptr = gpuds1.get ();
432
- commandBuffer->bindDescriptorSets (asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout (), 1u , 1u , &gpuds1_ptr, nullptr );
407
+ commandBuffer->bindDescriptorSets (asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout (), 1u , 1u , &gpuds1_ptr);
433
408
const video::IGPUDescriptorSet* gpuds3_ptr = gpuMeshBuffer->getAttachedDescriptorSet ();
434
409
435
410
if (gpuds3_ptr)
436
- commandBuffer->bindDescriptorSets (asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout (), 3u , 1u , &gpuds3_ptr, nullptr );
437
- commandBuffer->pushConstants (gpuRenderpassIndependentPipeline->getLayout (), video::IGPUSpecializedShader ::ESS_FRAGMENT, 0u , gpuMeshBuffer->MAX_PUSH_CONSTANT_BYTESIZE , gpuMeshBuffer->getPushConstantsDataPtr ());
411
+ commandBuffer->bindDescriptorSets (asset::EPBP_GRAPHICS, gpuRenderpassIndependentPipeline->getLayout (), 3u , 1u , &gpuds3_ptr);
412
+ commandBuffer->pushConstants (gpuRenderpassIndependentPipeline->getLayout (), asset::IShader ::ESS_FRAGMENT, 0u , gpuMeshBuffer->MAX_PUSH_CONSTANT_BYTESIZE , gpuMeshBuffer->getPushConstantsDataPtr ());
438
413
439
414
commandBuffer->drawMeshBuffer (gpuMeshBuffer);
440
415
}
@@ -450,14 +425,22 @@ int main()
450
425
commandBuffer->endRenderPass ();
451
426
commandBuffer->end ();
452
427
453
- CommonAPI::Submit (logicalDevice.get (), swapchain.get (), commandBuffer.get (), queues[decltype (initOutput) ::EQT_GRAPHICS], imageAcquire[resourceIx].get (), renderFinished[resourceIx].get (), fence.get ());
454
- CommonAPI::Present (logicalDevice.get (), swapchain.get (), queues[decltype (initOutput) ::EQT_GRAPHICS], renderFinished[resourceIx].get (), acquiredNextFBO);
428
+ CommonAPI::Submit (logicalDevice.get (), swapchain.get (), commandBuffer.get (), queues[CommonAPI::InitOutput ::EQT_GRAPHICS], imageAcquire[resourceIx].get (), renderFinished[resourceIx].get (), fence.get ());
429
+ CommonAPI::Present (logicalDevice.get (), swapchain.get (), queues[CommonAPI::InitOutput ::EQT_GRAPHICS], renderFinished[resourceIx].get (), acquiredNextFBO);
455
430
}
456
431
457
432
const auto & fboCreationParams = fbos[acquiredNextFBO]->getCreationParameters ();
458
433
auto gpuSourceImageView = fboCreationParams.attachments [0 ];
459
434
460
- bool status = ext::ScreenShot::createScreenShot (logicalDevice.get (), queues[decltype (initOutput)::EQT_TRANSFER_UP], renderFinished[resourceIx].get (), gpuSourceImageView.get (), assetManager.get (), " ScreenShot.png" );
435
+ bool status = ext::ScreenShot::createScreenShot (
436
+ logicalDevice.get (),
437
+ queues[CommonAPI::InitOutput::EQT_TRANSFER_UP],
438
+ renderFinished[resourceIx].get (),
439
+ gpuSourceImageView.get (),
440
+ assetManager.get (),
441
+ " ScreenShot.png" ,
442
+ asset::EIL_PRESENT_SRC,
443
+ static_cast <asset::E_ACCESS_FLAGS>(0u ));
461
444
assert (status);
462
445
463
446
return 0 ;
0 commit comments