@@ -34,7 +34,6 @@ class VulkanExample : public VulkanExampleBase
3434 VkPipeline starsphere{ VK_NULL_HANDLE };
3535 } pipelines;
3636 VkPipelineLayout pipelineLayout{ VK_NULL_HANDLE };
37- std::array<VkCommandBuffer, maxConcurrentFrames> primaryCommandBuffers{};
3837
3938 // Secondary scene command buffers used to store backdrop and user interface
4039 struct SecondaryCommandBuffers {
@@ -133,14 +132,9 @@ class VulkanExample : public VulkanExampleBase
133132 // Create all threads and initialize shader push constants
134133 void prepareMultiThreadedRenderer ()
135134 {
136- // Since this demo updates the command buffers on each frame
137- // we don't use the per-framebuffer command buffers from the
138- // base class, and create a single primary command buffer instead
135+ // The actual commands are issued in secondary command buffers, this also applies to the background and the user interface
139136 for (uint32_t i = 0 ; i < maxConcurrentFrames; i++) {
140- VkCommandBufferAllocateInfo cmdBufAllocateInfo = vks::initializers::commandBufferAllocateInfo (cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1 );
141- VK_CHECK_RESULT (vkAllocateCommandBuffers (device, &cmdBufAllocateInfo, &primaryCommandBuffers[i]));
142- // Create additional secondary CBs for background and ui
143- cmdBufAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY;
137+ VkCommandBufferAllocateInfo cmdBufAllocateInfo = vks::initializers::commandBufferAllocateInfo (cmdPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY, 1 );
144138 VK_CHECK_RESULT (vkAllocateCommandBuffers (device, &cmdBufAllocateInfo, &secondaryCommandBuffers[i].background ));
145139 VK_CHECK_RESULT (vkAllocateCommandBuffers (device, &cmdBufAllocateInfo, &secondaryCommandBuffers[i].ui ));
146140 }
@@ -378,34 +372,12 @@ class VulkanExample : public VulkanExampleBase
378372 prepared = true ;
379373 }
380374
381- void draw ()
382- {
383- // Wait for fence to signal that all command buffers are ready
384- // VkResult fenceRes;
385- // do {
386- // fenceRes = vkWaitForFences(device, 1, &renderFence, VK_TRUE, 100000000);
387- // } while (fenceRes == VK_TIMEOUT);
388- // VK_CHECK_RESULT(fenceRes);
389- // vkResetFences(device, 1, &renderFence);
390-
391- // VulkanExampleBase::prepareFrame();
392-
393- // updateCommandBuffers(frameBuffers[currentBuffer]);
394-
395- // submitInfo.commandBufferCount = 1;
396- // submitInfo.pCommandBuffers = &primaryCommandBuffer;
397-
398- // VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, renderFence));
399-
400- // VulkanExampleBase::submitFrame();
401- }
402-
403375 // Updates the secondary command buffers using a thread pool
404376 // and puts them into the primary command buffer that's
405377 // lat submitted to the queue for rendering
406378 void updateCommandBuffer ()
407379 {
408- VkCommandBuffer cmdBuffer = primaryCommandBuffers [currentBuffer];
380+ VkCommandBuffer cmdBuffer = drawCmdBuffers [currentBuffer];
409381 vkResetCommandBuffer (cmdBuffer, 0 );
410382
411383 // Contains the list of secondary command buffers to be submitted
@@ -427,13 +399,11 @@ class VulkanExample : public VulkanExampleBase
427399 renderPassBeginInfo.pClearValues = clearValues;
428400 renderPassBeginInfo.framebuffer = frameBuffers[currentImageIndex];
429401
430- // Set target frame buffer
431-
432- VK_CHECK_RESULT (vkBeginCommandBuffer (primaryCommandBuffers[currentBuffer], &cmdBufInfo));
402+ VK_CHECK_RESULT (vkBeginCommandBuffer (drawCmdBuffers[currentBuffer], &cmdBufInfo));
433403
434404 // The primary command buffer does not contain any rendering commands
435405 // These are stored (and retrieved) from the secondary command buffers
436- vkCmdBeginRenderPass (primaryCommandBuffers [currentBuffer], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
406+ vkCmdBeginRenderPass (drawCmdBuffers [currentBuffer], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
437407
438408 // Inheritance info for the secondary command buffers
439409 VkCommandBufferInheritanceInfo inheritanceInfo = vks::initializers::commandBufferInheritanceInfo ();
@@ -472,11 +442,11 @@ class VulkanExample : public VulkanExampleBase
472442 }
473443
474444 // Execute render commands from the secondary command buffer
475- vkCmdExecuteCommands (primaryCommandBuffers [currentBuffer], static_cast <uint32_t >(commandBuffers.size ()), commandBuffers.data ());
445+ vkCmdExecuteCommands (drawCmdBuffers [currentBuffer], static_cast <uint32_t >(commandBuffers.size ()), commandBuffers.data ());
476446
477- vkCmdEndRenderPass (primaryCommandBuffers [currentBuffer]);
447+ vkCmdEndRenderPass (drawCmdBuffers [currentBuffer]);
478448
479- VK_CHECK_RESULT (vkEndCommandBuffer (primaryCommandBuffers [currentBuffer]));
449+ VK_CHECK_RESULT (vkEndCommandBuffer (drawCmdBuffers [currentBuffer]));
480450 }
481451
482452
@@ -490,7 +460,7 @@ class VulkanExample : public VulkanExampleBase
490460 updateMatrices ();
491461 // @todo: maybe find a better way than passing the cmd buffer like this
492462 // Or use drawCmdBuffes from base
493- VulkanExampleBase::submitFrame (primaryCommandBuffers[currentBuffer] );
463+ VulkanExampleBase::submitFrame ();
494464 }
495465
496466 virtual void OnUpdateUIOverlay (vks::UIOverlay *overlay)
0 commit comments