Commit 9413c402 by Courtney Goeltzenleuchter Committed by Commit Bot

Vulkan: Move CommandBatch for threading support

Will need access to CommandBatch class in threading worker. Bug: b/154030730 Change-Id: Ia79eab77a81b135c22bdeecbaf65bf3c301dc987 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2447442Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Courtney Goeltzenleuchter <courtneygo@google.com>
parent 82962a0d
...@@ -12,6 +12,34 @@ ...@@ -12,6 +12,34 @@
namespace rx namespace rx
{ {
namespace vk
{
// CommandBatch implementation.
CommandBatch::CommandBatch() = default;
CommandBatch::~CommandBatch() = default;
CommandBatch::CommandBatch(CommandBatch &&other)
{
*this = std::move(other);
}
CommandBatch &CommandBatch::operator=(CommandBatch &&other)
{
std::swap(primaryCommands, other.primaryCommands);
std::swap(commandPool, other.commandPool);
std::swap(fence, other.fence);
std::swap(serial, other.serial);
return *this;
}
void CommandBatch::destroy(VkDevice device)
{
primaryCommands.destroy(device);
commandPool.destroy(device);
fence.reset(device);
}
} // namespace vk
CommandProcessor::CommandProcessor() : mWorkerThreadIdle(true) {} CommandProcessor::CommandProcessor() : mWorkerThreadIdle(true) {}
......
...@@ -38,6 +38,22 @@ struct CommandProcessorTask ...@@ -38,6 +38,22 @@ struct CommandProcessorTask
}; };
static const CommandProcessorTask kEndCommandProcessorThread = {nullptr, nullptr, nullptr}; static const CommandProcessorTask kEndCommandProcessorThread = {nullptr, nullptr, nullptr};
struct CommandBatch final : angle::NonCopyable
{
CommandBatch();
~CommandBatch();
CommandBatch(CommandBatch &&other);
CommandBatch &operator=(CommandBatch &&other);
void destroy(VkDevice device);
vk::PrimaryCommandBuffer primaryCommands;
// commandPool is for secondary CommandBuffer allocation
vk::CommandPool commandPool;
vk::Shared<vk::Fence> fence;
Serial serial;
};
} // namespace vk } // namespace vk
class CommandProcessor : angle::NonCopyable class CommandProcessor : angle::NonCopyable
......
...@@ -364,32 +364,6 @@ void ContextVk::DriverUniformsDescriptorSet::destroy(RendererVk *renderer) ...@@ -364,32 +364,6 @@ void ContextVk::DriverUniformsDescriptorSet::destroy(RendererVk *renderer)
descriptorSetCache.clear(); descriptorSetCache.clear();
} }
// CommandBatch implementation.
CommandBatch::CommandBatch() = default;
CommandBatch::~CommandBatch() = default;
CommandBatch::CommandBatch(CommandBatch &&other)
{
*this = std::move(other);
}
CommandBatch &CommandBatch::operator=(CommandBatch &&other)
{
std::swap(primaryCommands, other.primaryCommands);
std::swap(commandPool, other.commandPool);
std::swap(fence, other.fence);
std::swap(serial, other.serial);
return *this;
}
void CommandBatch::destroy(VkDevice device)
{
primaryCommands.destroy(device);
commandPool.destroy(device);
fence.reset(device);
}
// CommandQueue implementation. // CommandQueue implementation.
CommandQueue::CommandQueue() = default; CommandQueue::CommandQueue() = default;
CommandQueue::~CommandQueue() = default; CommandQueue::~CommandQueue() = default;
...@@ -419,7 +393,7 @@ angle::Result CommandQueue::checkCompletedCommands(vk::Context *context) ...@@ -419,7 +393,7 @@ angle::Result CommandQueue::checkCompletedCommands(vk::Context *context)
int finishedCount = 0; int finishedCount = 0;
for (CommandBatch &batch : mInFlightCommands) for (vk::CommandBatch &batch : mInFlightCommands)
{ {
VkResult result = batch.fence.get().getStatus(device); VkResult result = batch.fence.get().getStatus(device);
if (result == VK_NOT_READY) if (result == VK_NOT_READY)
...@@ -474,7 +448,7 @@ angle::Result CommandQueue::checkCompletedCommands(vk::Context *context) ...@@ -474,7 +448,7 @@ angle::Result CommandQueue::checkCompletedCommands(vk::Context *context)
angle::Result CommandQueue::releaseToCommandBatch(vk::Context *context, angle::Result CommandQueue::releaseToCommandBatch(vk::Context *context,
vk::PrimaryCommandBuffer &&commandBuffer, vk::PrimaryCommandBuffer &&commandBuffer,
vk::CommandPool *commandPool, vk::CommandPool *commandPool,
CommandBatch *batch) vk::CommandBatch *batch)
{ {
RendererVk *renderer = context->getRenderer(); RendererVk *renderer = context->getRenderer();
VkDevice device = renderer->getDevice(); VkDevice device = renderer->getDevice();
...@@ -528,7 +502,7 @@ void CommandQueue::handleDeviceLost(RendererVk *renderer) ...@@ -528,7 +502,7 @@ void CommandQueue::handleDeviceLost(RendererVk *renderer)
{ {
VkDevice device = renderer->getDevice(); VkDevice device = renderer->getDevice();
for (CommandBatch &batch : mInFlightCommands) for (vk::CommandBatch &batch : mInFlightCommands)
{ {
// On device loss we need to wait for fence to be signaled before destroying it // On device loss we need to wait for fence to be signaled before destroying it
VkResult status = batch.fence.get().wait(device, renderer->getMaxFenceWaitTimeNs()); VkResult status = batch.fence.get().wait(device, renderer->getMaxFenceWaitTimeNs());
...@@ -577,7 +551,7 @@ angle::Result CommandQueue::finishToSerial(vk::Context *context, Serial serial, ...@@ -577,7 +551,7 @@ angle::Result CommandQueue::finishToSerial(vk::Context *context, Serial serial,
break; break;
} }
} }
const CommandBatch &batch = mInFlightCommands[batchIndex]; const vk::CommandBatch &batch = mInFlightCommands[batchIndex];
// Wait for it finish // Wait for it finish
VkDevice device = context->getDevice(); VkDevice device = context->getDevice();
...@@ -603,8 +577,8 @@ angle::Result CommandQueue::submitFrame(vk::Context *context, ...@@ -603,8 +577,8 @@ angle::Result CommandQueue::submitFrame(vk::Context *context,
RendererVk *renderer = context->getRenderer(); RendererVk *renderer = context->getRenderer();
VkDevice device = renderer->getDevice(); VkDevice device = renderer->getDevice();
vk::DeviceScoped<CommandBatch> scopedBatch(device); vk::DeviceScoped<vk::CommandBatch> scopedBatch(device);
CommandBatch &batch = scopedBatch.get(); vk::CommandBatch &batch = scopedBatch.get();
batch.fence.copy(device, sharedFence); batch.fence.copy(device, sharedFence);
ANGLE_TRY(renderer->queueSubmit(context, priority, submitInfo, resourceList, &batch.fence.get(), ANGLE_TRY(renderer->queueSubmit(context, priority, submitInfo, resourceList, &batch.fence.get(),
......
...@@ -34,22 +34,6 @@ class RendererVk; ...@@ -34,22 +34,6 @@ class RendererVk;
class WindowSurfaceVk; class WindowSurfaceVk;
class ShareGroupVk; class ShareGroupVk;
struct CommandBatch final : angle::NonCopyable
{
CommandBatch();
~CommandBatch();
CommandBatch(CommandBatch &&other);
CommandBatch &operator=(CommandBatch &&other);
void destroy(VkDevice device);
vk::PrimaryCommandBuffer primaryCommands;
// commandPool is for secondary CommandBuffer allocation
vk::CommandPool commandPool;
vk::Shared<vk::Fence> fence;
Serial serial;
};
class CommandQueue final : angle::NonCopyable class CommandQueue final : angle::NonCopyable
{ {
public: public:
...@@ -92,10 +76,10 @@ class CommandQueue final : angle::NonCopyable ...@@ -92,10 +76,10 @@ class CommandQueue final : angle::NonCopyable
angle::Result releaseToCommandBatch(vk::Context *context, angle::Result releaseToCommandBatch(vk::Context *context,
vk::PrimaryCommandBuffer &&commandBuffer, vk::PrimaryCommandBuffer &&commandBuffer,
vk::CommandPool *commandPool, vk::CommandPool *commandPool,
CommandBatch *batch); vk::CommandBatch *batch);
vk::GarbageQueue mGarbageQueue; vk::GarbageQueue mGarbageQueue;
std::vector<CommandBatch> mInFlightCommands; std::vector<vk::CommandBatch> mInFlightCommands;
// Keeps a free list of reusable primary command buffers. // Keeps a free list of reusable primary command buffers.
vk::PersistentCommandPool mPrimaryCommandPool; vk::PersistentCommandPool mPrimaryCommandPool;
......
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