Commit e2d2270a by Jamie Madill Committed by Commit Bot

Vulkan: Merge append/beginWriteResource.

The new API is named 'recordCommands'. These two APIs were basically doing the same thing. We don't need to have an understanding of creating a new graph node to know that we want to record some Vulkan commands to a command buffer. The prior design was actually masking a bug where we would allow appending commands to a command graph node that had already started a render pass. Fix this by adding a render pass check to recordCommands. Also removes 'hasStartedWriteResource' since this method wasn't used anywhere. Also renames 'onResourceChanged' to 'finishCurrentCommands'. Bug: angleproject:2828 Change-Id: I00bd5b893fcfc37172b6c1706cb2f5fc57e79f54 Reviewed-on: https://chromium-review.googlesource.com/1235654 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 5272a543
......@@ -216,7 +216,7 @@ angle::Result BufferVk::setDataImpl(ContextVk *contextVk,
// 'beginWriteResource' will stop any subsequent rendering from using the old buffer data,
// by marking any current read operations / command buffers as 'finished'.
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteResource(contextVk, &commandBuffer));
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
// Insert a barrier to ensure reads from the buffer are complete.
// TODO(jmadill): Insert minimal barriers.
......
......@@ -81,28 +81,16 @@ Serial CommandGraphResource::getStoredQueueSerial() const
return mStoredQueueSerial;
}
bool CommandGraphResource::hasStartedWriteResource() const
{
return hasChildlessWritingNode() &&
mCurrentWritingNode->getOutsideRenderPassCommands()->valid();
}
angle::Result CommandGraphResource::beginWriteResource(Context *context,
CommandBuffer **commandBufferOut)
{
onResourceChanged(context->getRenderer());
return mCurrentWritingNode->beginOutsideRenderPassRecording(
context, context->getRenderer()->getCommandPool(), commandBufferOut);
}
angle::Result CommandGraphResource::appendWriteResource(Context *context,
CommandBuffer **commandBufferOut)
angle::Result CommandGraphResource::recordCommands(Context *context,
CommandBuffer **commandBufferOut)
{
updateQueueSerial(context->getRenderer()->getCurrentQueueSerial());
if (!hasChildlessWritingNode())
if (!hasChildlessWritingNode() || hasStartedRenderPass())
{
return beginWriteResource(context, commandBufferOut);
finishCurrentCommands(context->getRenderer());
return mCurrentWritingNode->beginOutsideRenderPassRecording(
context, context->getRenderer()->getCommandPool(), commandBufferOut);
}
CommandBuffer *outsideRenderPassCommands = mCurrentWritingNode->getOutsideRenderPassCommands();
......@@ -154,7 +142,7 @@ angle::Result CommandGraphResource::beginRenderPass(Context *context,
return mCurrentWritingNode->beginInsideRenderPassRecording(context, commandBufferOut);
}
void CommandGraphResource::onResourceChanged(RendererVk *renderer)
void CommandGraphResource::finishCurrentCommands(RendererVk *renderer)
{
CommandGraphNode *newCommands = renderer->getCommandGraph()->allocateNode();
onWriteImpl(newCommands, renderer->getCurrentQueueSerial());
......
......@@ -125,15 +125,8 @@ class CommandGraphResource
protected:
// Allocates a write node via getNewWriteNode and returns a started command buffer.
// The started command buffer will render outside of a RenderPass.
angle::Result beginWriteResource(Context *context, CommandBuffer **commandBufferOut);
// Check if we have started writing outside a RenderPass.
bool hasStartedWriteResource() const;
// Starts rendering to an existing command buffer for the resource.
// The started command buffer will render outside of a RenderPass.
// Calls beginWriteResource if we have not yet started writing.
angle::Result appendWriteResource(Context *context, CommandBuffer **commandBufferOut);
// Will append to an existing command buffer/graph node if possible.
angle::Result recordCommands(Context *context, CommandBuffer **commandBufferOut);
// Begins a command buffer on the current graph node for in-RenderPass rendering.
// Currently only called from FramebufferVk::getCommandBufferForDraw.
......@@ -152,7 +145,7 @@ class CommandGraphResource
const gl::Rectangle &getRenderPassRenderArea() const;
// Called when 'this' object changes, but we'd like to start a new command buffer later.
void onResourceChanged(RendererVk *renderer);
void finishCurrentCommands(RendererVk *renderer);
// Get the current queue serial for this resource. Only used to release resources.
Serial getStoredQueueSerial() const;
......
......@@ -232,7 +232,7 @@ gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
// Standard Depth/stencil clear without scissor.
if (clearDepth || clearStencil)
{
ANGLE_TRY(beginWriteResource(contextVk, &commandBuffer));
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
const VkClearDepthStencilValue &clearDepthStencilValue =
contextVk->getClearDepthStencilValue().depthStencil;
......@@ -255,7 +255,7 @@ gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
if (!commandBuffer)
{
ANGLE_TRY(beginWriteResource(contextVk, &commandBuffer));
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
}
// TODO(jmadill): Support gaps in RenderTargets. http://anglebug.com/2394
......@@ -482,7 +482,7 @@ angle::Result FramebufferVk::blitWithReadback(ContextVk *contextVk,
// Reinitialize the commandBuffer after a read pixels because it calls
// renderer->finish which makes command buffers obsolete.
ANGLE_TRY(beginWriteResource(contextVk, &commandBuffer));
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
// We read the bytes of the image in a buffer, now we have to copy them into the
// destination target.
......@@ -516,7 +516,7 @@ gl::Error FramebufferVk::blit(const gl::Context *context,
bool blitStencilBuffer = (mask & GL_STENCIL_BUFFER_BIT) != 0;
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteResource(contextVk, &commandBuffer));
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
FramebufferVk *sourceFramebufferVk = vk::GetImpl(sourceFramebuffer);
bool flipSource = contextVk->isViewportFlipEnabledForReadFBO();
bool flipDest = contextVk->isViewportFlipEnabledForDrawFBO();
......@@ -772,7 +772,7 @@ gl::Error FramebufferVk::syncState(const gl::Context *context,
// Will freeze the current set of dependencies on this FBO. The next time we render we will
// create a new entry in the command graph.
onResourceChanged(renderer);
finishCurrentCommands(renderer);
contextVk->invalidateCurrentPipeline();
......@@ -879,7 +879,7 @@ angle::Result FramebufferVk::clearWithClearAttachments(ContextVk *contextVk,
bool clearStencil)
{
// Trigger a new command node to ensure overlapping writes happen sequentially.
onResourceChanged(contextVk->getRenderer());
finishCurrentCommands(contextVk->getRenderer());
// This command can only happen inside a render pass, so obtain one if its already happening
// or create a new one if not.
......@@ -980,7 +980,7 @@ angle::Result FramebufferVk::clearWithDraw(ContextVk *contextVk,
vk::ShaderLibrary *shaderLibrary = renderer->getShaderLibrary();
// Trigger a new command node to ensure overlapping writes happen sequentially.
onResourceChanged(renderer);
finishCurrentCommands(renderer);
const vk::ShaderAndSerial *fullScreenQuad = nullptr;
ANGLE_TRY(shaderLibrary->getShader(contextVk, vk::InternalShaderID::FullScreenQuad_vert,
......@@ -1040,7 +1040,7 @@ angle::Result FramebufferVk::clearWithDraw(ContextVk *contextVk,
pipeline->updateSerial(renderer->getCurrentQueueSerial());
vk::CommandBuffer *writeCommands = nullptr;
ANGLE_TRY(appendWriteResource(contextVk, &writeCommands));
ANGLE_TRY(recordCommands(contextVk, &writeCommands));
// If the format of the framebuffer does not have an alpha channel, we need to make sure we does
// not affect the alpha channel of the type we're using to emulate the format.
......@@ -1099,7 +1099,7 @@ angle::Result FramebufferVk::startNewRenderPass(ContextVk *contextVk,
std::vector<VkClearValue> attachmentClearValues;
vk::CommandBuffer *writeCommands = nullptr;
ANGLE_TRY(appendWriteResource(contextVk, &writeCommands));
ANGLE_TRY(recordCommands(contextVk, &writeCommands));
vk::RenderPassDesc renderPassDesc;
......@@ -1152,7 +1152,7 @@ angle::Result FramebufferVk::readPixelsImpl(ContextVk *contextVk,
RendererVk *renderer = contextVk->getRenderer();
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteResource(contextVk, &commandBuffer));
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
// Note that although we're reading from the image, we need to update the layout below.
......
......@@ -87,7 +87,7 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context,
// TODO(jmadill): Fold this into the RenderPass load/store ops. http://anglebug.com/2361
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteResource(contextVk, &commandBuffer));
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
if (isDepthOrStencilFormat)
{
......
......@@ -480,7 +480,7 @@ angle::Result WindowSurfaceVk::initializeImpl(DisplayVk *displayVk)
// Allocate a command buffer for clearing our images to black.
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteResource(displayVk, &commandBuffer));
ANGLE_TRY(recordCommands(displayVk, &commandBuffer));
VkClearColorValue transparentBlack;
transparentBlack.float32[0] = 0.0f;
......@@ -565,7 +565,7 @@ angle::Result WindowSurfaceVk::swapImpl(DisplayVk *displayVk)
RendererVk *renderer = displayVk->getRenderer();
vk::CommandBuffer *swapCommands = nullptr;
ANGLE_TRY(beginWriteResource(displayVk, &swapCommands));
ANGLE_TRY(recordCommands(displayVk, &swapCommands));
SwapchainImage &image = mSwapchainImages[mCurrentSwapchainImageIndex];
......
......@@ -475,7 +475,7 @@ gl::Error TextureVk::setImage(const gl::Context *context,
}
// Create a new graph node to store image initialization commands.
onResourceChanged(renderer);
finishCurrentCommands(renderer);
// Handle initial data.
if (pixels)
......@@ -503,7 +503,7 @@ gl::Error TextureVk::setSubImage(const gl::Context *context,
gl::Offset(area.x, area.y, area.z), formatInfo, unpack, type, pixels));
// Create a new graph node to store image initialization commands.
onResourceChanged(contextVk->getRenderer());
finishCurrentCommands(contextVk->getRenderer());
return gl::NoError();
}
......@@ -629,7 +629,7 @@ angle::Result TextureVk::copySubImageImpl(const gl::Context *context,
gl::Extents(clippedSourceArea.width, clippedSourceArea.height, 1), internalFormat,
framebufferVk));
onResourceChanged(renderer);
finishCurrentCommands(renderer);
framebufferVk->addReadDependency(this);
return angle::Result::Continue();
}
......@@ -679,7 +679,7 @@ gl::Error TextureVk::copySubTextureImpl(ContextVk *contextVk,
unpackUnmultiplyAlpha);
// Create a new graph node to store image initialization commands.
onResourceChanged(contextVk->getRenderer());
finishCurrentCommands(contextVk->getRenderer());
return angle::Result::Continue();
}
......@@ -687,7 +687,7 @@ gl::Error TextureVk::copySubTextureImpl(ContextVk *contextVk,
angle::Result TextureVk::getCommandBufferForWrite(ContextVk *contextVk,
vk::CommandBuffer **commandBufferOut)
{
ANGLE_TRY(appendWriteResource(contextVk, commandBufferOut));
ANGLE_TRY(recordCommands(contextVk, commandBufferOut));
return angle::Result::Continue();
}
......@@ -999,7 +999,7 @@ gl::Error TextureVk::generateMipmap(const gl::Context *context)
}
// We're changing this textureVk content, make sure we let the graph know.
onResourceChanged(renderer);
finishCurrentCommands(renderer);
return gl::NoError();
}
......
......@@ -425,7 +425,7 @@ angle::Result LineLoopHelper::getIndexBufferForElementArrayBuffer(Context *conte
std::array<VkBufferCopy, 2> copies = {{copy1, copy2}};
vk::CommandBuffer *commandBuffer;
ANGLE_TRY(beginWriteResource(context, &commandBuffer));
ANGLE_TRY(recordCommands(context, &commandBuffer));
elementArrayBufferVk->addReadDependency(this);
commandBuffer->copyBuffer(elementArrayBufferVk->getVkBuffer().getHandle(), *bufferHandleOut, 2,
......
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