Commit 294a5608 by Jamie Madill Committed by Commit Bot

Vulkan: Make CommandPool a wrapped type.

This faciliatates an upcoming change to treat all handle types uniformly with respect to releasing. BUG=angleproject:1684 Change-Id: I632262a57b3a447cf4999c28ab359fe931549576 Reviewed-on: https://chromium-review.googlesource.com/442674Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 3764b257
...@@ -93,7 +93,6 @@ RendererVk::RendererVk() ...@@ -93,7 +93,6 @@ RendererVk::RendererVk()
mQueue(VK_NULL_HANDLE), mQueue(VK_NULL_HANDLE),
mCurrentQueueFamilyIndex(std::numeric_limits<uint32_t>::max()), mCurrentQueueFamilyIndex(std::numeric_limits<uint32_t>::max()),
mDevice(VK_NULL_HANDLE), mDevice(VK_NULL_HANDLE),
mCommandPool(VK_NULL_HANDLE),
mHostVisibleMemoryIndex(std::numeric_limits<uint32_t>::max()), mHostVisibleMemoryIndex(std::numeric_limits<uint32_t>::max()),
mGlslangWrapper(nullptr) mGlslangWrapper(nullptr)
{ {
...@@ -108,12 +107,7 @@ RendererVk::~RendererVk() ...@@ -108,12 +107,7 @@ RendererVk::~RendererVk()
} }
mCommandBuffer.reset(nullptr); mCommandBuffer.reset(nullptr);
mCommandPool.reset(nullptr);
if (mCommandPool)
{
vkDestroyCommandPool(mDevice, mCommandPool, nullptr);
mCommandPool = VK_NULL_HANDLE;
}
if (mDevice) if (mDevice)
{ {
...@@ -423,9 +417,10 @@ vk::Error RendererVk::initializeDevice(uint32_t queueFamilyIndex) ...@@ -423,9 +417,10 @@ vk::Error RendererVk::initializeDevice(uint32_t queueFamilyIndex)
commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
commandPoolInfo.queueFamilyIndex = mCurrentQueueFamilyIndex; commandPoolInfo.queueFamilyIndex = mCurrentQueueFamilyIndex;
ANGLE_VK_TRY(vkCreateCommandPool(mDevice, &commandPoolInfo, nullptr, &mCommandPool)); mCommandPool.reset(new vk::CommandPool(mDevice));
ANGLE_TRY(mCommandPool->init(commandPoolInfo));
mCommandBuffer.reset(new vk::CommandBuffer(mDevice, mCommandPool)); mCommandBuffer.reset(new vk::CommandBuffer(mDevice, mCommandPool.get()));
return vk::NoError(); return vk::NoError();
} }
......
...@@ -90,7 +90,7 @@ class RendererVk : angle::NonCopyable ...@@ -90,7 +90,7 @@ class RendererVk : angle::NonCopyable
VkQueue mQueue; VkQueue mQueue;
uint32_t mCurrentQueueFamilyIndex; uint32_t mCurrentQueueFamilyIndex;
VkDevice mDevice; VkDevice mDevice;
VkCommandPool mCommandPool; std::unique_ptr<vk::CommandPool> mCommandPool;
std::unique_ptr<vk::CommandBuffer> mCommandBuffer; std::unique_ptr<vk::CommandBuffer> mCommandBuffer;
uint32_t mHostVisibleMemoryIndex; uint32_t mHostVisibleMemoryIndex;
GlslangWrapper *mGlslangWrapper; GlslangWrapper *mGlslangWrapper;
......
...@@ -217,8 +217,29 @@ bool Error::isError() const ...@@ -217,8 +217,29 @@ bool Error::isError() const
return (mResult != VK_SUCCESS); return (mResult != VK_SUCCESS);
} }
// CommandPool implementation.
CommandPool::CommandPool(VkDevice device) : WrappedObject(device)
{
}
CommandPool::~CommandPool()
{
if (mHandle)
{
ASSERT(validDevice());
vkDestroyCommandPool(mDevice, mHandle, nullptr);
}
}
Error CommandPool::init(const VkCommandPoolCreateInfo &createInfo)
{
ASSERT(!valid() && validDevice());
ANGLE_VK_TRY(vkCreateCommandPool(mDevice, &createInfo, nullptr, &mHandle));
return NoError();
}
// CommandBuffer implementation. // CommandBuffer implementation.
CommandBuffer::CommandBuffer(VkDevice device, VkCommandPool commandPool) CommandBuffer::CommandBuffer(VkDevice device, CommandPool *commandPool)
: WrappedObject(device), mCommandPool(commandPool) : WrappedObject(device), mCommandPool(commandPool)
{ {
} }
...@@ -231,7 +252,7 @@ Error CommandBuffer::begin() ...@@ -231,7 +252,7 @@ Error CommandBuffer::begin()
VkCommandBufferAllocateInfo commandBufferInfo; VkCommandBufferAllocateInfo commandBufferInfo;
commandBufferInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; commandBufferInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
commandBufferInfo.pNext = nullptr; commandBufferInfo.pNext = nullptr;
commandBufferInfo.commandPool = mCommandPool; commandBufferInfo.commandPool = mCommandPool->getHandle();
commandBufferInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; commandBufferInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
commandBufferInfo.commandBufferCount = 1; commandBufferInfo.commandBufferCount = 1;
...@@ -282,8 +303,8 @@ CommandBuffer::~CommandBuffer() ...@@ -282,8 +303,8 @@ CommandBuffer::~CommandBuffer()
{ {
if (mHandle) if (mHandle)
{ {
ASSERT(validDevice()); ASSERT(validDevice() && mCommandPool->valid());
vkFreeCommandBuffers(mDevice, mCommandPool, 1, &mHandle); vkFreeCommandBuffers(mDevice, mCommandPool->getHandle(), 1, &mHandle);
} }
} }
......
...@@ -114,11 +114,20 @@ class WrappedObject : angle::NonCopyable ...@@ -114,11 +114,20 @@ class WrappedObject : angle::NonCopyable
HandleT mHandle; HandleT mHandle;
}; };
class CommandPool final : public WrappedObject<VkCommandPool>
{
public:
CommandPool(VkDevice device);
~CommandPool() override;
Error init(const VkCommandPoolCreateInfo &createInfo);
};
// Helper class that wraps a Vulkan command buffer. // Helper class that wraps a Vulkan command buffer.
class CommandBuffer final : public WrappedObject<VkCommandBuffer> class CommandBuffer final : public WrappedObject<VkCommandBuffer>
{ {
public: public:
CommandBuffer(VkDevice device, VkCommandPool commandPool); CommandBuffer(VkDevice device, CommandPool *commandPool);
~CommandBuffer() override; ~CommandBuffer() override;
Error begin(); Error begin();
...@@ -154,7 +163,7 @@ class CommandBuffer final : public WrappedObject<VkCommandBuffer> ...@@ -154,7 +163,7 @@ class CommandBuffer final : public WrappedObject<VkCommandBuffer>
const std::vector<VkDeviceSize> &offsets); const std::vector<VkDeviceSize> &offsets);
private: private:
VkCommandPool mCommandPool; CommandPool *mCommandPool;
}; };
class Image final : public WrappedObject<VkImage> class Image final : public WrappedObject<VkImage>
......
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