Vulkan: Defer command buffer submission.
This packs more rendering commands into fewer command buffers.
Instead of using a single command buffer per-command, create a
buffer and record commands into it until we need to present the
frame. More sophisticated management will be necessary in the future
when we can do other types of copied and read-back from image data.
This also reduces the number of Fences we use for checking if the
device is finished with resources. Instead of creating a Fence
per-command-buffer, it creates one per-swap.
BUG=angleproject:1898
Change-Id: I9c6033bc04289fd8f936c0df914afc51fc434b29
Reviewed-on: https://chromium-review.googlesource.com/445800
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/vulkan/FramebufferVk.cpp b/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
index 1752837..921cdb7 100644
--- a/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
+++ b/src/libANGLE/renderer/vulkan/FramebufferVk.cpp
@@ -162,8 +162,8 @@
const auto &size = attachment->getSize();
const gl::Rectangle renderArea(0, 0, size.width, size.height);
- vk::CommandBuffer *commandBuffer = contextVk->getCommandBuffer();
- ANGLE_TRY(commandBuffer->begin(contextVk->getDevice()));
+ vk::CommandBuffer *commandBuffer = nullptr;
+ ANGLE_TRY(contextVk->getStartedCommandBuffer(&commandBuffer));
for (const auto &colorAttachment : mState.getColorAttachments())
{
@@ -177,10 +177,6 @@
}
}
- commandBuffer->end();
-
- ANGLE_TRY(contextVk->submitCommands(*commandBuffer));
-
return gl::NoError();
}
@@ -271,8 +267,9 @@
ANGLE_TRY(renderer->createStagingImage(TextureDimension::TEX_2D, *renderTarget->format,
renderTarget->extents, &stagingImage));
- vk::CommandBuffer *commandBuffer = contextVk->getCommandBuffer();
- commandBuffer->begin(device);
+ vk::CommandBuffer *commandBuffer = nullptr;
+ ANGLE_TRY(contextVk->getStartedCommandBuffer(&commandBuffer));
+
stagingImage.getImage().changeLayoutTop(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL,
commandBuffer);
@@ -288,9 +285,8 @@
commandBuffer);
commandBuffer->copySingleImage(*readImage, stagingImage.getImage(), copyRegion,
VK_IMAGE_ASPECT_COLOR_BIT);
- commandBuffer->end();
- ANGLE_TRY(renderer->submitAndFinishCommandBuffer(*commandBuffer));
+ ANGLE_TRY(renderer->submitAndFinishCommandBuffer(commandBuffer));
// TODO(jmadill): parameters
uint8_t *mapPointer = nullptr;
@@ -587,7 +583,6 @@
ANGLE_TRY(mState.getFirstColorAttachment()->getRenderTarget(&renderTarget));
renderTarget->image->updateLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
- ANGLE_TRY(commandBuffer->begin(device));
commandBuffer->beginRenderPass(*renderPass, *framebuffer, glState.getViewport(),
attachmentClearValues);