Skip to content

Commit 81fb2e1

Browse files
committed
Implement resetCommandPool
1 parent aacbc22 commit 81fb2e1

4 files changed

Lines changed: 48 additions & 68 deletions

File tree

include/luna/luna.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ VkResult lunaCreateDescriptorSetLayout(const LunaDescriptorSetLayoutCreationInfo
2929
VkResult lunaAllocateDescriptorSets(const LunaDescriptorSetAllocationInfo *allocationInfo,
3030
LunaDescriptorSet *descriptorSets);
3131
void lunaWriteDescriptorSets(uint32_t writeCount, const LunaWriteDescriptorSet *descriptorWrites);
32-
void lunaDestroyDescriptorSet(LunaDescriptorSet descriptorSet);
32+
// void lunaDestroyDescriptorSet(LunaDescriptorSet descriptorSet);
3333

3434
VkResult lunaCreateShaderModule(const LunaShaderModuleCreationInfo *creationInfo, LunaShaderModule *shaderModule);
3535

@@ -38,6 +38,7 @@ VkResult lunaCreateGraphicsPipeline(const LunaGraphicsPipelineCreationInfo *crea
3838

3939
VkResult lunaCreateCommandPool(const LunaCommandPoolCreationInfo *creationInfo, LunaCommandPool *commandPool);
4040
VkResult lunaResetCommandPool(LunaCommandPool commandPool, VkCommandPoolResetFlagBits flags);
41+
VkResult lunaResetCommandPoolWithTimeout(LunaCommandPool commandPool, VkCommandPoolResetFlagBits flags, size_t timeout);
4142

4243
#ifdef __cplusplus
4344
}

src/CommandPool.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//
44

55
#include <cassert>
6+
#include <cstddef>
7+
#include <cstdint>
68
#include <luna/luna.h>
79
#include <luna/lunaTypes.h>
810
#include <vulkan/vulkan_core.h>
@@ -16,14 +18,28 @@ VkResult lunaCreateCommandPool(const LunaCommandPoolCreationInfo *creationInfo,
1618
return VK_SUCCESS;
1719
}
1820

19-
// VkResult lunaResetCommandPool(const LunaCommandPool commandPool, const VkCommandPoolResetFlagBits flags)
20-
// {
21-
// switch (reinterpret_cast<uintptr_t>(commandPool))
22-
// {
23-
// case LUNA_INTERNAL_GRAPHICS_COMMAND_POOL:
24-
// CHECK_RESULT_RETURN(luna::device.commandPools().graphics.reset(luna::device, flags));
25-
// return VK_SUCCESS;
26-
// default:
27-
// return VK_ERROR_UNKNOWN;
28-
// }
29-
// }
21+
VkResult lunaResetCommandPool(const LunaCommandPool commandPool, const VkCommandPoolResetFlagBits flags)
22+
{
23+
switch (reinterpret_cast<uintptr_t>(commandPool))
24+
{
25+
case LUNA_INTERNAL_GRAPHICS_COMMAND_POOL:
26+
CHECK_RESULT_RETURN(luna::device.commandPools().graphics.reset(luna::device, flags));
27+
return VK_SUCCESS;
28+
default:
29+
return VK_ERROR_UNKNOWN;
30+
}
31+
}
32+
33+
VkResult lunaResetCommandPoolWithTimeout(const LunaCommandPool commandPool,
34+
const VkCommandPoolResetFlagBits flags,
35+
const size_t timeout)
36+
{
37+
switch (reinterpret_cast<uintptr_t>(commandPool))
38+
{
39+
case LUNA_INTERNAL_GRAPHICS_COMMAND_POOL:
40+
CHECK_RESULT_RETURN(luna::device.commandPools().graphics.reset(luna::device, flags, timeout));
41+
return VK_SUCCESS;
42+
default:
43+
return VK_ERROR_UNKNOWN;
44+
}
45+
}

src/Luna.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,3 @@ void lunaWriteDescriptorSets(const uint32_t writeCount, const LunaWriteDescripto
294294
}
295295
vkUpdateDescriptorSets(device, writeCount, writes.data(), 0, nullptr);
296296
}
297-
void lunaDestroyDescriptorSet(LunaDescriptorSet descriptorSet)
298-
{
299-
(void)descriptorSet;
300-
// static_cast<const luna::DescriptorSetIndex *>(descriptorSet);
301-
// vkDestroyDescriptorPool();
302-
}

src/headers/CommandPool.hpp

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

181150
inline const CommandBuffer &CommandPool::commandBuffer(const uint32_t index) const
182151
{

0 commit comments

Comments
 (0)