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()
mQueue(VK_NULL_HANDLE),
mCurrentQueueFamilyIndex(std::numeric_limits<uint32_t>::max()),
mDevice(VK_NULL_HANDLE),
mCommandPool(VK_NULL_HANDLE),
mHostVisibleMemoryIndex(std::numeric_limits<uint32_t>::max()),
mGlslangWrapper(nullptr)
{
......@@ -108,12 +107,7 @@ RendererVk::~RendererVk()
}
mCommandBuffer.reset(nullptr);
if (mCommandPool)
{
vkDestroyCommandPool(mDevice, mCommandPool, nullptr);
mCommandPool = VK_NULL_HANDLE;
}
mCommandPool.reset(nullptr);
if (mDevice)
{
......@@ -423,9 +417,10 @@ vk::Error RendererVk::initializeDevice(uint32_t queueFamilyIndex)
commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
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();
}
......
......@@ -90,7 +90,7 @@ class RendererVk : angle::NonCopyable
VkQueue mQueue;
uint32_t mCurrentQueueFamilyIndex;
VkDevice mDevice;
VkCommandPool mCommandPool;
std::unique_ptr<vk::CommandPool> mCommandPool;
std::unique_ptr<vk::CommandBuffer> mCommandBuffer;
uint32_t mHostVisibleMemoryIndex;
GlslangWrapper *mGlslangWrapper;
......
......@@ -217,8 +217,29 @@ bool Error::isError() const
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::CommandBuffer(VkDevice device, VkCommandPool commandPool)
CommandBuffer::CommandBuffer(VkDevice device, CommandPool *commandPool)
: WrappedObject(device), mCommandPool(commandPool)
{
}
......@@ -231,7 +252,7 @@ Error CommandBuffer::begin()
VkCommandBufferAllocateInfo commandBufferInfo;
commandBufferInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
commandBufferInfo.pNext = nullptr;
commandBufferInfo.commandPool = mCommandPool;
commandBufferInfo.commandPool = mCommandPool->getHandle();
commandBufferInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
commandBufferInfo.commandBufferCount = 1;
......@@ -282,8 +303,8 @@ CommandBuffer::~CommandBuffer()
{
if (mHandle)
{
ASSERT(validDevice());
vkFreeCommandBuffers(mDevice, mCommandPool, 1, &mHandle);
ASSERT(validDevice() && mCommandPool->valid());
vkFreeCommandBuffers(mDevice, mCommandPool->getHandle(), 1, &mHandle);
}
}
......
......@@ -114,11 +114,20 @@ class WrappedObject : angle::NonCopyable
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.
class CommandBuffer final : public WrappedObject<VkCommandBuffer>
{
public:
CommandBuffer(VkDevice device, VkCommandPool commandPool);
CommandBuffer(VkDevice device, CommandPool *commandPool);
~CommandBuffer() override;
Error begin();
......@@ -154,7 +163,7 @@ class CommandBuffer final : public WrappedObject<VkCommandBuffer>
const std::vector<VkDeviceSize> &offsets);
private:
VkCommandPool mCommandPool;
CommandPool *mCommandPool;
};
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