Commit 615ae1a7 by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Improve copy buffer self-dependency

The check in addReadDependency to avoid setting self-dependencies was causing the barrier set in `copySubData` to be potentially set earlier than the buffer's previous usage. This change allows buffer self-dependencies to be handled especially. Bug: angleproject:3194 Change-Id: I08f2c39f420f020ad5faa9735193e6b7142fa756 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1670952 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent f20daf0b
...@@ -156,16 +156,28 @@ angle::Result BufferVk::copySubData(const gl::Context *context, ...@@ -156,16 +156,28 @@ angle::Result BufferVk::copySubData(const gl::Context *context,
auto *sourceBuffer = GetAs<BufferVk>(source); auto *sourceBuffer = GetAs<BufferVk>(source);
vk::CommandBuffer *commandBuffer = nullptr; vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(mBuffer.recordCommands(contextVk, &commandBuffer));
// Handle self-dependency especially.
if (sourceBuffer->mBuffer.getBuffer().getHandle() == mBuffer.getBuffer().getHandle())
{
mBuffer.onSelfReadWrite(contextVk, VK_ACCESS_TRANSFER_READ_BIT,
VK_ACCESS_TRANSFER_WRITE_BIT);
ANGLE_TRY(mBuffer.recordCommands(contextVk, &commandBuffer));
}
else
{
ANGLE_TRY(mBuffer.recordCommands(contextVk, &commandBuffer));
sourceBuffer->mBuffer.onRead(&mBuffer, VK_ACCESS_TRANSFER_READ_BIT);
mBuffer.onWrite(contextVk, VK_ACCESS_TRANSFER_WRITE_BIT);
}
// Enqueue a copy command on the GPU. // Enqueue a copy command on the GPU.
VkBufferCopy copyRegion = {static_cast<VkDeviceSize>(sourceOffset), VkBufferCopy copyRegion = {static_cast<VkDeviceSize>(sourceOffset),
static_cast<VkDeviceSize>(destOffset), static_cast<VkDeviceSize>(destOffset),
static_cast<VkDeviceSize>(size)}; static_cast<VkDeviceSize>(size)};
sourceBuffer->mBuffer.onRead(&mBuffer, VK_ACCESS_TRANSFER_READ_BIT);
mBuffer.onWrite(contextVk, VK_ACCESS_TRANSFER_WRITE_BIT);
commandBuffer->copyBuffer(sourceBuffer->getBuffer().getBuffer(), mBuffer.getBuffer(), 1, commandBuffer->copyBuffer(sourceBuffer->getBuffer().getBuffer(), mBuffer.getBuffer(), 1,
&copyRegion); &copyRegion);
......
...@@ -275,7 +275,7 @@ void CommandGraphResource::addReadDependency(CommandGraphResource *readingResour ...@@ -275,7 +275,7 @@ void CommandGraphResource::addReadDependency(CommandGraphResource *readingResour
CommandGraphNode *readingNode = readingResource->mCurrentWritingNode; CommandGraphNode *readingNode = readingResource->mCurrentWritingNode;
ASSERT(readingNode); ASSERT(readingNode);
if (mCurrentWritingNode && (mCurrentWritingNode != readingNode)) if (mCurrentWritingNode)
{ {
// Ensure 'readingNode' happens after the current writing node. // Ensure 'readingNode' happens after the current writing node.
CommandGraphNode::SetHappensBeforeDependency(mCurrentWritingNode, readingNode); CommandGraphNode::SetHappensBeforeDependency(mCurrentWritingNode, readingNode);
......
...@@ -1237,6 +1237,21 @@ void BufferHelper::onWrite(ContextVk *contextVk, VkAccessFlags writeAccessType) ...@@ -1237,6 +1237,21 @@ void BufferHelper::onWrite(ContextVk *contextVk, VkAccessFlags writeAccessType)
} }
} }
void BufferHelper::onSelfReadWrite(ContextVk *contextVk,
VkAccessFlags readAccessType,
VkAccessFlags writeAccessType)
{
if (mCurrentReadAccess || mCurrentWriteAccess)
{
finishCurrentCommands(contextVk);
addGlobalMemoryBarrier(mCurrentReadAccess | mCurrentWriteAccess,
readAccessType | writeAccessType);
}
mCurrentReadAccess = readAccessType;
mCurrentWriteAccess = writeAccessType;
}
angle::Result BufferHelper::copyFromBuffer(ContextVk *contextVk, angle::Result BufferHelper::copyFromBuffer(ContextVk *contextVk,
const Buffer &buffer, const Buffer &buffer,
VkAccessFlags bufferAccessType, VkAccessFlags bufferAccessType,
......
...@@ -446,6 +446,9 @@ class BufferHelper final : public CommandGraphResource ...@@ -446,6 +446,9 @@ class BufferHelper final : public CommandGraphResource
} }
void onWrite(ContextVk *contextVk, VkAccessFlags writeAccessType); void onWrite(ContextVk *contextVk, VkAccessFlags writeAccessType);
void onSelfReadWrite(ContextVk *contextVk,
VkAccessFlags readAccessType,
VkAccessFlags writeAccessType);
// Also implicitly sets up the correct barriers. // Also implicitly sets up the correct barriers.
angle::Result copyFromBuffer(ContextVk *contextVk, angle::Result copyFromBuffer(ContextVk *contextVk,
......
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