Commit cd610c9a by Alexis Hetu Committed by Alexis Hétu

CommandPool reset and trim

Implemented vkResetCommandPool and vkTrimCommandPool. The reset command out all command buffers in the command pool back to the initial state. It also frees up the entire pool. The trim command is a potential future memory usage optimization. It is currently a noop. Passes a few tests in dEQP-VK.api.command_buffers. Bug b/119827933 Change-Id: Ic974f63a8dfca014462ac904218b9dcc3035fc8a Reviewed-on: https://swiftshader-review.googlesource.com/c/24370Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent debaacab
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
#include "VkCommandPool.hpp" #include "VkCommandPool.hpp"
#include "VkCommandBuffer.hpp"
#include "VkDestroy.h" #include "VkDestroy.h"
#include <algorithm> #include <algorithm>
...@@ -79,4 +80,28 @@ void CommandPool::freeCommandBuffers(uint32_t commandBufferCount, const VkComman ...@@ -79,4 +80,28 @@ void CommandPool::freeCommandBuffers(uint32_t commandBufferCount, const VkComman
} }
} }
VkResult CommandPool::reset(VkCommandPoolResetFlags flags)
{
// According the Vulkan 1.1 spec:
// "All command buffers that have been allocated from
// the command pool are put in the initial state."
for(auto commandBuffer : *commandBuffers)
{
Cast(commandBuffer)->reset(flags);
}
// According the Vulkan 1.1 spec:
// "Resetting a command pool recycles all of the
// resources from all of the command buffers allocated
// from the command pool back to the command pool."
commandBuffers->clear();
return VK_SUCCESS;
}
void CommandPool::trim(VkCommandPoolTrimFlags flags)
{
// TODO (b/119827933): Optimize memory usage here
}
} // namespace vk } // namespace vk
...@@ -32,6 +32,8 @@ public: ...@@ -32,6 +32,8 @@ public:
VkResult allocateCommandBuffers(VkCommandBufferLevel level, uint32_t commandBufferCount, VkCommandBuffer* pCommandBuffers); VkResult allocateCommandBuffers(VkCommandBufferLevel level, uint32_t commandBufferCount, VkCommandBuffer* pCommandBuffers);
void freeCommandBuffers(uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers); void freeCommandBuffers(uint32_t commandBufferCount, const VkCommandBuffer* pCommandBuffers);
VkResult reset(VkCommandPoolResetFlags flags);
void trim(VkCommandPoolTrimFlags flags);
private: private:
std::set<VkCommandBuffer>* commandBuffers; std::set<VkCommandBuffer>* commandBuffers;
......
...@@ -1175,9 +1175,10 @@ VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool c ...@@ -1175,9 +1175,10 @@ VKAPI_ATTR void VKAPI_CALL vkDestroyCommandPool(VkDevice device, VkCommandPool c
VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags) VKAPI_ATTR VkResult VKAPI_CALL vkResetCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolResetFlags flags)
{ {
TRACE("()"); TRACE("(VkDevice device = 0x%X, VkCommandPool commandPool = 0x%X, VkCommandPoolResetFlags flags = %d )",
UNIMPLEMENTED(); device, commandPool, flags);
return VK_SUCCESS;
return vk::Cast(commandPool)->reset(flags);
} }
VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers) VKAPI_ATTR VkResult VKAPI_CALL vkAllocateCommandBuffers(VkDevice device, const VkCommandBufferAllocateInfo* pAllocateInfo, VkCommandBuffer* pCommandBuffers)
...@@ -1888,8 +1889,10 @@ VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties2(VkPhy ...@@ -1888,8 +1889,10 @@ VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceSparseImageFormatProperties2(VkPhy
VKAPI_ATTR void VKAPI_CALL vkTrimCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlags flags) VKAPI_ATTR void VKAPI_CALL vkTrimCommandPool(VkDevice device, VkCommandPool commandPool, VkCommandPoolTrimFlags flags)
{ {
TRACE("()"); TRACE("(VkDevice device = 0x%X, VkCommandPool commandPool = 0x%X, VkCommandPoolTrimFlags flags = %d)",
UNIMPLEMENTED(); device, commandPool, flags);
vk::Cast(commandPool)->trim(flags);
} }
VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2* pQueueInfo, VkQueue* pQueue) VKAPI_ATTR void VKAPI_CALL vkGetDeviceQueue2(VkDevice device, const VkDeviceQueueInfo2* pQueueInfo, VkQueue* pQueue)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment