@@ -35,7 +35,7 @@ class CommandPool
3535 const void *allocateInfoPNext,
3636 const VkSemaphoreCreateInfo *semaphoreCreateInfo,
3737 uint32_t arraySize = 1 );
38- VkResult reset (VkDevice logicalDevice, VkCommandPoolResetFlagBits flags, uint64_t timeout = UINT64_MAX );
38+ VkResult reset (VkDevice logicalDevice, VkCommandPoolResetFlagBits flags, uint64_t timeout = UINT64_MAX ) const ;
3939
4040 [[nodiscard]] const CommandBuffer &commandBuffer (uint32_t index = 0 ) const ;
4141 [[nodiscard]] CommandBuffer &commandBuffer (uint32_t index = 0 );
@@ -128,55 +128,24 @@ inline VkResult CommandPool::allocateCommandBuffer(VkDevice logicalDevice,
128128 arraySize));
129129 return VK_SUCCESS ;
130130}
131- // inline VkResult CommandPool::reset(const VkDevice logicalDevice,
132- // const VkCommandPoolResetFlagBits flags,
133- // const uint64_t timeout)
134- // {
135- // std::vector<VkFence> fences;
136- // fences.reserve(commandBufferArrays_.size());
137- // for (CommandBufferArray<arraySize> &commandBufferArray: commandBufferArrays_)
138- // {
139- // // TODO: This is cursed and could cause bugs.
140- // // Fences should be reworked so that I can check if the fence needs to be waited upon.
141- // if (commandBufferArray.semaphore_.isSignaled())
142- // {
143- // fences.emplace_back(commandBufferArray.fence_);
144- // }
145- // commandBufferArray.isRecording_ = false;
146- // }
147- // // TODO: If this fails with the default timeout it will block the the render thread for 585 years,
148- // // which is unacceptable. While it is not the responsibility of this method to handle this problem,
149- // // all usages of this method currently use the default timeout.
150- // CHECK_RESULT_RETURN(vkWaitForFences(logicalDevice, fences.size(), fences.data(), VK_TRUE, timeout));
151- // CHECK_RESULT_RETURN(vkResetCommandPool(logicalDevice, commandPool_, flags));
152- //
153- // return VK_SUCCESS;
154- // }
155- // inline VkResult CommandPool::reset(const VkDevice logicalDevice,
156- // const VkCommandPoolResetFlagBits flags,
157- // const uint64_t timeout)
158- // {
159- // std::vector<VkFence> fences;
160- // fences.reserve(commandBuffers_.size());
161- // for (std::unique_ptr<CommandBuffer> &commandBuffer: commandBuffers_)
162- // {
163- //
164- // // TODO: This is cursed and could cause bugs.
165- // // Fences should be reworked so that I can check if the fence needs to be waited upon.
166- // if (commandBuffer.semaphore_.isSignaled())
167- // {
168- // fences.emplace_back(commandBuffer.fence_);
169- // }
170- // commandBuffer = false;
171- // }
172- // // TODO: If this fails with the default timeout it will block the the render thread for 585 years,
173- // // which is unacceptable. While it is not the responsibility of this method to handle this problem,
174- // // all usages of this method currently use the default timeout.
175- // CHECK_RESULT_RETURN(vkWaitForFences(logicalDevice, fences.size(), fences.data(), VK_TRUE, timeout));
176- // CHECK_RESULT_RETURN(vkResetCommandPool(logicalDevice, commandPool_, flags));
177- //
178- // return VK_SUCCESS;
179- // }
131+ inline VkResult CommandPool::reset (const VkDevice logicalDevice,
132+ const VkCommandPoolResetFlagBits flags,
133+ const uint64_t timeout) const
134+ {
135+ for (const CommandBuffer &commandBuffer: commandBuffers_)
136+ {
137+ if (commandBuffer.type () == CommandBuffer::Type::ARRAY )
138+ {
139+ CHECK_RESULT_RETURN (commandBuffer.commandBufferArray ().waitForAllFences (logicalDevice, timeout));
140+ } else
141+ {
142+ CHECK_RESULT_RETURN (commandBuffer.commandBuffer ().waitForFence (logicalDevice, timeout));
143+ }
144+ }
145+ CHECK_RESULT_RETURN (vkResetCommandPool (logicalDevice, commandPool_, flags));
146+
147+ return VK_SUCCESS ;
148+ }
180149
181150inline const CommandBuffer &CommandPool::commandBuffer (const uint32_t index) const
182151{
0 commit comments