Skip to content

Commit 33bdcd5

Browse files
committed
Use constexpr for sizing sync objects
Except for semaphores related to presentation
1 parent bb2f03a commit 33bdcd5

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

base/vulkanexamplebase.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,6 @@ std::string VulkanExampleBase::getWindowTitle() const
190190

191191
void VulkanExampleBase::createCommandBuffers()
192192
{
193-
// Create one command buffer for each swap chain image
194-
drawCmdBuffers.resize(swapChain.images.size());
195193
VkCommandBufferAllocateInfo cmdBufAllocateInfo = vks::initializers::commandBufferAllocateInfo(cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, static_cast<uint32_t>(drawCmdBuffers.size()));
196194
VK_CHECK_RESULT(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, drawCmdBuffers.data()));
197195
}
@@ -2937,12 +2935,10 @@ void VulkanExampleBase::createSynchronizationPrimitives()
29372935
{
29382936
// Wait fences to sync command buffer access
29392937
VkFenceCreateInfo fenceCreateInfo = vks::initializers::fenceCreateInfo(VK_FENCE_CREATE_SIGNALED_BIT);
2940-
waitFences.resize(drawCmdBuffers.size());
29412938
for (auto& fence : waitFences) {
29422939
VK_CHECK_RESULT(vkCreateFence(device, &fenceCreateInfo, nullptr, &fence));
29432940
}
29442941
// Used to ensure that image presentation is complete before starting to submit again
2945-
presentCompleteSemaphores.resize(maxConcurrentFrames);
29462942
for (auto& semaphore : presentCompleteSemaphores) {
29472943
VkSemaphoreCreateInfo semaphoreCI{ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO };
29482944
VK_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreCI, nullptr, &semaphore));

base/vulkanexamplebase.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class VulkanExampleBase
133133
// Command buffer pool
134134
VkCommandPool cmdPool{ VK_NULL_HANDLE };
135135
// Command buffers used for rendering
136-
std::vector<VkCommandBuffer> drawCmdBuffers;
136+
std::array<VkCommandBuffer, maxConcurrentFrames> drawCmdBuffers;
137137
// Global render pass for frame buffer writes
138138
VkRenderPass renderPass{ VK_NULL_HANDLE };
139139
// List of available frame buffers (same as number of swap chain images)
@@ -150,10 +150,10 @@ class VulkanExampleBase
150150
// Synchronization related objects and variables
151151
// These are used to have multiple frame buffers "in flight" to get some CPU/GPU parallelism
152152
uint32_t currentImageIndex{ 0 };
153-
uint32_t currentBuffer = 0;
154-
std::vector<VkSemaphore> presentCompleteSemaphores{};
153+
uint32_t currentBuffer{ 0 };
154+
std::array<VkSemaphore, maxConcurrentFrames> presentCompleteSemaphores{};
155155
std::vector<VkSemaphore> renderCompleteSemaphores{};
156-
std::vector<VkFence> waitFences;
156+
std::array<VkFence, maxConcurrentFrames> waitFences;
157157

158158
bool requiresStencil{ false };
159159
public:

0 commit comments

Comments
 (0)