1
1
2
+ using namespace nbl ::hlsl;
3
+ using namespace nbl ;
4
+ using namespace core ;
5
+ using namespace system ;
6
+ using namespace asset ;
7
+ using namespace ui ;
8
+ using namespace video ;
9
+
2
10
3
11
#include " nbl/application_templates/MonoAssetManagerAndBuiltinResourceApplication.hpp"
4
12
#include " ../common/SimpleWindowedApplication.hpp"
@@ -32,15 +40,7 @@ enum class ExampleMode
32
40
CASE_5, // Advanced Styling
33
41
};
34
42
35
- constexpr ExampleMode mode = ExampleMode::CASE_4;
36
-
37
- using namespace nbl ::hlsl;
38
- using namespace nbl ;
39
- using namespace core ;
40
- using namespace system ;
41
- using namespace asset ;
42
- using namespace ui ;
43
- using namespace video ;
43
+ constexpr ExampleMode mode = ExampleMode::CASE_5;
44
44
45
45
class Camera2D
46
46
{
@@ -248,12 +248,11 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
248
248
constexpr static uint32_t MaxFramesInFlight = 8u ;
249
249
public:
250
250
251
- void initCADResources (uint32_t maxObjects)
251
+ void allocateResources (uint32_t maxObjects)
252
252
{
253
253
drawBuffer = DrawBuffersFiller (core::smart_refctd_ptr (m_utils));
254
254
255
255
uint32_t maxIndices = maxObjects * 6u * 2u ;
256
- drawBuffer.allocateIndexBuffer (m_device.get (), maxIndices);
257
256
drawBuffer.allocateMainObjectsBuffer (m_device.get (), maxObjects);
258
257
drawBuffer.allocateDrawObjectsBuffer (m_device.get (), maxObjects * 5u );
259
258
drawBuffer.allocateStylesBuffer (m_device.get (), 32u );
@@ -263,16 +262,15 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
263
262
size_t geometryBufferSize = maxObjects * sizeof (QuadraticBezierInfo) * 3 ;
264
263
drawBuffer.allocateGeometryBuffer (m_device.get (), geometryBufferSize);
265
264
266
- for (uint32_t i = 0 ; i < m_framesInFlight; ++i)
267
265
{
268
266
IGPUBuffer::SCreationParams globalsCreationParams = {};
269
267
globalsCreationParams.size = sizeof (Globals);
270
268
globalsCreationParams.usage = IGPUBuffer::EUF_UNIFORM_BUFFER_BIT | IGPUBuffer::EUF_TRANSFER_DST_BIT | IGPUBuffer::EUF_INLINE_UPDATE_VIA_CMDBUF;
271
- globalsBuffer[i] = m_device->createBuffer (std::move (globalsCreationParams));
269
+ globalsBuffer = m_device->createBuffer (std::move (globalsCreationParams));
272
270
273
- IDeviceMemoryBacked::SDeviceMemoryRequirements memReq = globalsBuffer[i] ->getMemoryReqs ();
271
+ IDeviceMemoryBacked::SDeviceMemoryRequirements memReq = globalsBuffer->getMemoryReqs ();
274
272
memReq.memoryTypeBits &= m_device->getPhysicalDevice ()->getDeviceLocalMemoryTypeBits ();
275
- auto globalsBufferMem = m_device->allocate (memReq, globalsBuffer[i] .get ());
273
+ auto globalsBufferMem = m_device->allocate (memReq, globalsBuffer.get ());
276
274
}
277
275
278
276
// pseudoStencil
@@ -284,7 +282,6 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
284
282
promotionRequest.usages .storageImageAtomic = true ;
285
283
pseudoStencilFormat = m_physicalDevice->promoteImageFormat (promotionRequest, IGPUImage::TILING::OPTIMAL);
286
284
287
- for (uint32_t i = 0u ; i < m_framesInFlight; ++i)
288
285
{
289
286
IGPUImage::SCreationParams imgInfo;
290
287
imgInfo.format = pseudoStencilFormat;
@@ -318,7 +315,7 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
318
315
imgViewInfo.subresourceRange .layerCount = 1u ;
319
316
imgViewInfo.subresourceRange .levelCount = 1u ;
320
317
321
- pseudoStencilImageViews[i] = m_device->createImageView (std::move (imgViewInfo));
318
+ pseudoStencilImageView = m_device->createImageView (std::move (imgViewInfo));
322
319
}
323
320
}
324
321
@@ -457,16 +454,14 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
457
454
renderpassFinal = createRenderpass (format, IGPURenderpass::LOAD_OP::LOAD, IImage::LAYOUT::ATTACHMENT_OPTIMAL, IImage::LAYOUT::PRESENT_SRC);
458
455
const auto compatibleRenderPass = renderpassInitial; // all 3 above are compatible
459
456
460
-
461
457
scResources->setCompatibleRenderpass (compatibleRenderPass);
462
458
463
459
if (!m_surface->init (getGraphicsQueue (),std::move (scResources),{}))
464
460
return logFail (" Could not initialize the Surface!" );
465
461
466
462
m_framesInFlight = min (m_surface->getMaxFramesInFlight (), MaxFramesInFlight);
467
-
468
463
469
- initCADResources (40960u );
464
+ allocateResources (40960u );
470
465
471
466
// Create DescriptorSetLayout, PipelineLayout and update DescriptorSets
472
467
{
@@ -528,23 +523,22 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
528
523
529
524
smart_refctd_ptr<IDescriptorPool> descriptorPool = nullptr ;
530
525
{
531
- const uint32_t setCounts[2u ] = { m_framesInFlight, m_framesInFlight };
526
+ const uint32_t setCounts[2u ] = { 1u , 1u };
532
527
descriptorPool = m_device->createDescriptorPoolForDSLayouts (IDescriptorPool::E_CREATE_FLAGS::ECF_NONE, layouts, setCounts);
533
528
if (!descriptorPool)
534
529
return logFail (" Failed to Create Descriptor Pool" );
535
530
}
536
531
537
- for (size_t i = 0 ; i < m_framesInFlight; i++)
538
532
{
539
- descriptorSets0[i] = descriptorPool->createDescriptorSet (smart_refctd_ptr (descriptorSetLayout0));
540
- descriptorSets1[i] = descriptorPool->createDescriptorSet (smart_refctd_ptr (descriptorSetLayout1));
533
+ descriptorSet0 = descriptorPool->createDescriptorSet (smart_refctd_ptr (descriptorSetLayout0));
534
+ descriptorSet1 = descriptorPool->createDescriptorSet (smart_refctd_ptr (descriptorSetLayout1));
541
535
constexpr uint32_t DescriptorCount = 6u ;
542
536
video::IGPUDescriptorSet::SDescriptorInfo descriptorInfos[DescriptorCount] = {};
543
537
544
538
// Descriptors For Set 0:
545
539
descriptorInfos[0u ].info .buffer .offset = 0u ;
546
- descriptorInfos[0u ].info .buffer .size = globalsBuffer[i] ->getCreationParams ().size ;
547
- descriptorInfos[0u ].desc = globalsBuffer[i] ;
540
+ descriptorInfos[0u ].info .buffer .size = globalsBuffer->getCreationParams ().size ;
541
+ descriptorInfos[0u ].desc = globalsBuffer;
548
542
549
543
descriptorInfos[1u ].info .buffer .offset = 0u ;
550
544
descriptorInfos[1u ].info .buffer .size = drawBuffer.gpuDrawBuffers .drawObjectsBuffer ->getCreationParams ().size ;
@@ -565,43 +559,43 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
565
559
// Descriptors For Set 1:
566
560
descriptorInfos[5u ].info .image .imageLayout = IImage::LAYOUT::GENERAL;
567
561
descriptorInfos[5u ].info .image .sampler = nullptr ;
568
- descriptorInfos[5u ].desc = pseudoStencilImageViews[i] ;
562
+ descriptorInfos[5u ].desc = pseudoStencilImageView ;
569
563
570
564
video::IGPUDescriptorSet::SWriteDescriptorSet descriptorUpdates[6u ] = {};
571
565
572
566
// Set 0 Updates:
573
- descriptorUpdates[0u ].dstSet = descriptorSets0[i] .get ();
567
+ descriptorUpdates[0u ].dstSet = descriptorSet0 .get ();
574
568
descriptorUpdates[0u ].binding = 0u ;
575
569
descriptorUpdates[0u ].arrayElement = 0u ;
576
570
descriptorUpdates[0u ].count = 1u ;
577
571
descriptorUpdates[0u ].info = &descriptorInfos[0u ];
578
572
579
- descriptorUpdates[1u ].dstSet = descriptorSets0[i] .get ();
573
+ descriptorUpdates[1u ].dstSet = descriptorSet0 .get ();
580
574
descriptorUpdates[1u ].binding = 1u ;
581
575
descriptorUpdates[1u ].arrayElement = 0u ;
582
576
descriptorUpdates[1u ].count = 1u ;
583
577
descriptorUpdates[1u ].info = &descriptorInfos[1u ];
584
578
585
- descriptorUpdates[2u ].dstSet = descriptorSets0[i] .get ();
579
+ descriptorUpdates[2u ].dstSet = descriptorSet0 .get ();
586
580
descriptorUpdates[2u ].binding = 2u ;
587
581
descriptorUpdates[2u ].arrayElement = 0u ;
588
582
descriptorUpdates[2u ].count = 1u ;
589
583
descriptorUpdates[2u ].info = &descriptorInfos[2u ];
590
584
591
- descriptorUpdates[3u ].dstSet = descriptorSets0[i] .get ();
585
+ descriptorUpdates[3u ].dstSet = descriptorSet0 .get ();
592
586
descriptorUpdates[3u ].binding = 3u ;
593
587
descriptorUpdates[3u ].arrayElement = 0u ;
594
588
descriptorUpdates[3u ].count = 1u ;
595
589
descriptorUpdates[3u ].info = &descriptorInfos[3u ];
596
590
597
- descriptorUpdates[4u ].dstSet = descriptorSets0[i] .get ();
591
+ descriptorUpdates[4u ].dstSet = descriptorSet0 .get ();
598
592
descriptorUpdates[4u ].binding = 4u ;
599
593
descriptorUpdates[4u ].arrayElement = 0u ;
600
594
descriptorUpdates[4u ].count = 1u ;
601
595
descriptorUpdates[4u ].info = &descriptorInfos[4u ];
602
596
603
597
// Set 1 Updates:
604
- descriptorUpdates[5u ].dstSet = descriptorSets1[i] .get ();
598
+ descriptorUpdates[5u ].dstSet = descriptorSet1 .get ();
605
599
descriptorUpdates[5u ].binding = 0u ;
606
600
descriptorUpdates[5u ].arrayElement = 0u ;
607
601
descriptorUpdates[5u ].count = 1u ;
@@ -858,13 +852,13 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
858
852
globalData.screenToWorldRatio = screenToWorld;
859
853
globalData.worldToScreenRatio = (1.0 /screenToWorld);
860
854
globalData.miterLimit = 10 .0f ;
861
- SBufferRange<IGPUBuffer> globalBufferUpdateRange = { .offset = 0ull , .size = sizeof (Globals), .buffer = globalsBuffer[resourceIx] .get () };
855
+ SBufferRange<IGPUBuffer> globalBufferUpdateRange = { .offset = 0ull , .size = sizeof (Globals), .buffer = globalsBuffer.get () };
862
856
bool updateSuccess = cb->updateBuffer (globalBufferUpdateRange, &globalData);
863
857
assert (updateSuccess);
864
858
865
859
// Clear pseudoStencil
866
860
{
867
- auto pseudoStencilImage = pseudoStencilImageViews[resourceIx] ->getCreationParameters ().image ;
861
+ auto pseudoStencilImage = pseudoStencilImageView ->getCreationParameters ().image ;
868
862
869
863
IGPUCommandBuffer::SPipelineBarrierDependencyInfo::image_barrier_t imageBarriers[] =
870
864
{
@@ -961,7 +955,7 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
961
955
// pipelineBarriersBeforeDraw
962
956
{
963
957
// prepare pseudoStencilImage for usage in drawcall
964
- auto pseudoStencilImage = pseudoStencilImageViews[resourceIx] ->getCreationParameters ().image ;
958
+ auto pseudoStencilImage = pseudoStencilImageView ->getCreationParameters ().image ;
965
959
IGPUCommandBuffer::SPipelineBarrierDependencyInfo::image_barrier_t imageBarriers[] =
966
960
{
967
961
{
@@ -2419,10 +2413,10 @@ class ComputerAidedDesign final : public examples::SimpleWindowedApplication, pu
2419
2413
std::array<smart_refctd_ptr<IGPUCommandPool>, MaxFramesInFlight> m_graphicsCommandPools;
2420
2414
std::array<smart_refctd_ptr<IGPUCommandBuffer>, MaxFramesInFlight> m_commandBuffers;
2421
2415
2422
- std::array< smart_refctd_ptr<IGPUImageView>, MaxFramesInFlight> pseudoStencilImageViews ;
2423
- std::array< smart_refctd_ptr<IGPUBuffer>, MaxFramesInFlight> globalsBuffer;
2424
- std::array< smart_refctd_ptr<IGPUDescriptorSet>, MaxFramesInFlight> descriptorSets0 ;
2425
- std::array< smart_refctd_ptr<IGPUDescriptorSet>, MaxFramesInFlight> descriptorSets1 ;
2416
+ smart_refctd_ptr<IGPUImageView> pseudoStencilImageView ;
2417
+ smart_refctd_ptr<IGPUBuffer> globalsBuffer;
2418
+ smart_refctd_ptr<IGPUDescriptorSet> descriptorSet0 ;
2419
+ smart_refctd_ptr<IGPUDescriptorSet> descriptorSet1 ;
2426
2420
DrawBuffersFiller drawBuffer; // you can think of this as the scene data needed to draw everything, we only have one instance so let's use a timeline semaphore to sync all renders
2427
2421
2428
2422
smart_refctd_ptr<ISemaphore> m_renderSemaphore; // timeline semaphore to sync frames together
0 commit comments