Skip to content

Commit 5db89ec

Browse files
committed
Code cleanup
1 parent 9ea856b commit 5db89ec

File tree

7 files changed

+19
-53
lines changed

7 files changed

+19
-53
lines changed

base/vulkanexamplebase.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -762,19 +762,15 @@ void VulkanExampleBase::prepareFrame(bool waitForFence)
762762
}
763763
}
764764

765-
void VulkanExampleBase::submitFrame(VkCommandBuffer cmdBuffer, bool skipQueueSubmit)
765+
void VulkanExampleBase::submitFrame(bool skipQueueSubmit)
766766
{
767767
// @todo: make this an argument
768768
if (!skipQueueSubmit) {
769769
const VkPipelineStageFlags waitPipelineStage{ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
770770
VkSubmitInfo submitInfo{ .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO };
771771
submitInfo.pWaitDstStageMask = &waitPipelineStage;
772772
submitInfo.commandBufferCount = 1;
773-
if (cmdBuffer != VK_NULL_HANDLE) {
774-
submitInfo.pCommandBuffers = &cmdBuffer;
775-
} else {
776-
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
777-
}
773+
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
778774
submitInfo.pWaitSemaphores = &presentCompleteSemaphores[currentBuffer];
779775
submitInfo.waitSemaphoreCount = 1;
780776
submitInfo.pSignalSemaphores = &renderCompleteSemaphores[currentImageIndex];

base/vulkanexamplebase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ class VulkanExampleBase
404404
void prepareFrame(bool waitForFence = true);
405405
/** @brief Presents the current image to the swap chain */
406406
// @todo: rework once new sync is in place, maybe overload with submission info
407-
void submitFrame(VkCommandBuffer cmdBuffer = VK_NULL_HANDLE, bool skipQueueSubmit = false);
407+
void submitFrame(bool skipQueueSubmit = false);
408408

409409
/** @brief (Virtual) Called when the UI overlay is updating, can be used to add custom elements to the overlay */
410410
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay);

examples/computecloth/computecloth.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class VulkanExample : public VulkanExampleBase
535535
// Signal first used ready semaphore
536536
VkSubmitInfo computeSubmitInfo = vks::initializers::submitInfo();
537537
computeSubmitInfo.signalSemaphoreCount = 1;
538-
computeSubmitInfo.pSignalSemaphores = &compute.semaphores[-1 % maxConcurrentFrames].ready;
538+
computeSubmitInfo.pSignalSemaphores = &compute.semaphores[maxConcurrentFrames - 1].ready;
539539
VK_CHECK_RESULT(vkQueueSubmit(compute.queue, 1, &computeSubmitInfo, VK_NULL_HANDLE));
540540
}
541541

@@ -727,7 +727,7 @@ class VulkanExample : public VulkanExampleBase
727727
submitInfo.pSignalSemaphores = signalSemaphores;
728728
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer]));
729729

730-
VulkanExampleBase::submitFrame(VK_NULL_HANDLE, true);
730+
VulkanExampleBase::submitFrame(true);
731731
}
732732
}
733733

examples/computecullandlod/computecullandlod.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ class VulkanExample : public VulkanExampleBase
493493
// Signal first used ready semaphore
494494
VkSubmitInfo computeSubmitInfo = vks::initializers::submitInfo();
495495
computeSubmitInfo.signalSemaphoreCount = 1;
496-
computeSubmitInfo.pSignalSemaphores = &compute.semaphores[-1 % maxConcurrentFrames].ready;
496+
computeSubmitInfo.pSignalSemaphores = &compute.semaphores[maxConcurrentFrames - 1].ready;
497497
VK_CHECK_RESULT(vkQueueSubmit(compute.queue, 1, &computeSubmitInfo, VK_NULL_HANDLE));
498498
}
499499

@@ -775,7 +775,7 @@ class VulkanExample : public VulkanExampleBase
775775
submitInfo.pSignalSemaphores = signalSemaphores;
776776
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer]));
777777

778-
VulkanExampleBase::submitFrame(VK_NULL_HANDLE, true);
778+
VulkanExampleBase::submitFrame(true);
779779
}
780780
}
781781

examples/computenbody/computenbody.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ class VulkanExample : public VulkanExampleBase
425425
// Signal first used ready semaphore
426426
VkSubmitInfo computeSubmitInfo = vks::initializers::submitInfo();
427427
computeSubmitInfo.signalSemaphoreCount = 1;
428-
computeSubmitInfo.pSignalSemaphores = &compute.semaphores[-1 % maxConcurrentFrames].ready;
428+
computeSubmitInfo.pSignalSemaphores = &compute.semaphores[maxConcurrentFrames - 1].ready;
429429
VK_CHECK_RESULT(vkQueueSubmit(compute.queue, 1, &computeSubmitInfo, VK_NULL_HANDLE));
430430
}
431431

@@ -700,7 +700,7 @@ class VulkanExample : public VulkanExampleBase
700700
submitInfo.pSignalSemaphores = signalSemaphores;
701701
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, waitFences[currentBuffer]));
702702

703-
VulkanExampleBase::submitFrame(VK_NULL_HANDLE, true);
703+
VulkanExampleBase::submitFrame(true);
704704
}
705705
}
706706
};

examples/multithreading/multithreading.cpp

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

examples/timelinesemaphore/timelinesemaphore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ class VulkanExample : public VulkanExampleBase
690690
// Increase timeline value base for next frame
691691
timeLineSemaphore.value = allFinished;
692692

693-
VulkanExampleBase::submitFrame(VK_NULL_HANDLE, true);
693+
VulkanExampleBase::submitFrame(true);
694694
}
695695
};
696696

0 commit comments

Comments
 (0)