Commit df31624e by Charlie Lao Committed by Commit Bot

Vulkan: Reduce the onBufferRead/onBufferWrite API verbosity a bit

This adds helper functions to handle common use case for onBufferRead and onBufferWrite to reduce the API verbosity a little bit. Also fix the transform feedback bug that we are passing in wrong access/stage flags when it is emulated by vertex shader. Bug: b/155122200 Change-Id: Id2549ca00cad184a90c6230dc3665aaff44dda08 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2174265 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org>
parent 67da0051
......@@ -305,10 +305,8 @@ angle::Result BufferVk::copySubData(const gl::Context *context,
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
&sourceBuffer->getBuffer()));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
mBuffer));
ANGLE_TRY(contextVk->onBufferTransferRead(&sourceBuffer->getBuffer()));
ANGLE_TRY(contextVk->onBufferTransferWrite(mBuffer));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
// Enqueue a copy command on the GPU.
......@@ -553,10 +551,8 @@ angle::Result BufferVk::copyToBufferImpl(ContextVk *contextVk,
const VkBufferCopy *copies)
{
vk::CommandBuffer *commandBuffer;
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
destBuffer));
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
mBuffer));
ANGLE_TRY(contextVk->onBufferTransferWrite(destBuffer));
ANGLE_TRY(contextVk->onBufferTransferRead(mBuffer));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
commandBuffer->copyBuffer(mBuffer->getBuffer(), destBuffer->getBuffer(), copyCount, copies);
......
......@@ -1433,9 +1433,8 @@ angle::Result ContextVk::handleDirtyGraphicsTransformFeedbackBuffersEmulation(
BufferVk *bufferVk = vk::GetImpl(buffer);
vk::BufferHelper &bufferHelper = bufferVk->getBuffer();
mRenderPassCommands.bufferWrite(
&mResourceUseList, VK_ACCESS_TRANSFORM_FEEDBACK_WRITE_BIT_EXT,
VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT, &bufferHelper);
mRenderPassCommands.bufferWrite(&mResourceUseList, VK_ACCESS_SHADER_WRITE_BIT,
VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, &bufferHelper);
}
// TODO(http://anglebug.com/3570): Need to update to handle Program Pipelines
......
......@@ -617,12 +617,24 @@ class ContextVk : public ContextImpl, public vk::Context
vk::ResourceUseList &getResourceUseList() { return mResourceUseList; }
angle::Result onBufferRead(VkAccessFlags readAccessType,
VkPipelineStageFlags readStage,
vk::BufferHelper *buffer);
angle::Result onBufferWrite(VkAccessFlags writeAccessType,
VkPipelineStageFlags writeStage,
vk::BufferHelper *buffer);
angle::Result onBufferTransferRead(vk::BufferHelper *buffer)
{
return onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, buffer);
}
angle::Result onBufferTransferWrite(vk::BufferHelper *buffer)
{
return onBufferWrite(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, buffer);
}
angle::Result onBufferComputeShaderRead(vk::BufferHelper *buffer)
{
return onBufferRead(VK_ACCESS_SHADER_READ_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
buffer);
}
angle::Result onBufferComputeShaderWrite(vk::BufferHelper *buffer)
{
return onBufferWrite(VK_ACCESS_SHADER_WRITE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
buffer);
}
angle::Result onImageRead(VkImageAspectFlags aspectFlags,
vk::ImageLayout imageLayout,
......@@ -941,6 +953,13 @@ class ContextVk : public ContextImpl, public vk::Context
ANGLE_INLINE void onRenderPassFinished() { mRenderPassCommandBuffer = nullptr; }
angle::Result onBufferRead(VkAccessFlags readAccessType,
VkPipelineStageFlags readStage,
vk::BufferHelper *buffer);
angle::Result onBufferWrite(VkAccessFlags writeAccessType,
VkPipelineStageFlags writeStage,
vk::BufferHelper *buffer);
void initIndexTypeMap();
std::array<DirtyBitHandler, DIRTY_BIT_MAX> mGraphicsDirtyBitHandlers;
......
......@@ -122,8 +122,7 @@ angle::Result OverlayVk::createFont(ContextVk *contextVk)
// Copy font data from staging buffer.
vk::CommandBuffer *fontDataUpload;
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
&fontDataBuffer.get()));
ANGLE_TRY(contextVk->onBufferTransferRead(&fontDataBuffer.get()));
ANGLE_TRY(contextVk->onImageWrite(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::TransferDst,
&mFontImage));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&fontDataUpload));
......
......@@ -42,7 +42,7 @@ the primary command buffer.
The back-end usually records Image and Buffer barriers through additional `ContextVk` APIs:
* `onBufferRead` and `onBufferWrite` accumulate `VkBuffer` barriers.
* `onBufferTransferRead/onBufferComputeShaderRead` and `onBufferTransferWrite/onBufferComputeShaderWrite` accumulate `VkBuffer` barriers.
* `onImageRead` and `onImageWrite` accumulate `VkImage` barriers.
* `onRenderPassImageWrite` is a special API for write barriers inside a RenderPass instance.
......@@ -57,8 +57,8 @@ In this example we'll be recording a buffer copy command:
```
# Ensure that ANGLE sets proper read and write barriers for the Buffers.
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_TRANSFER_WRITE_BIT, destBuffer));
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, srcBuffer));
ANGLE_TRY(contextVk->onBufferTransferWrite(destBuffer));
ANGLE_TRY(contextVk->onBufferTransferRead(srcBuffer));
# Get a pointer to a secondary command buffer for command recording. May "flush" the RP.
vk::CommandBuffer *commandBuffer;
......
......@@ -1035,8 +1035,7 @@ angle::Result TextureVk::copyBufferDataToImage(ContextVk *contextVk,
ANGLE_TRY(ensureImageInitialized(contextVk, ImageMipLevels::EnabledLevels));
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
srcBuffer));
ANGLE_TRY(contextVk->onBufferTransferRead(srcBuffer));
ANGLE_TRY(
contextVk->onImageWrite(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::TransferDst, mImage));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
......
......@@ -795,8 +795,7 @@ angle::Result UtilsVk::clearBuffer(ContextVk *contextVk,
vk::CommandBuffer *commandBuffer;
// Tell the context dest that we are writing to dest.
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_SHADER_WRITE_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, dest));
ANGLE_TRY(contextVk->onBufferComputeShaderWrite(dest));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
const vk::Format &destFormat = dest->getViewFormat();
......@@ -846,10 +845,8 @@ angle::Result UtilsVk::convertIndexBuffer(ContextVk *contextVk,
ANGLE_TRY(ensureConvertIndexResourcesInitialized(contextVk));
vk::CommandBuffer *commandBuffer;
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, src));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_SHADER_WRITE_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, dest));
ANGLE_TRY(contextVk->onBufferComputeShaderRead(src));
ANGLE_TRY(contextVk->onBufferComputeShaderWrite(dest));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
VkDescriptorSet descriptorSet;
......@@ -910,14 +907,10 @@ angle::Result UtilsVk::convertIndexIndirectBuffer(ContextVk *contextVk,
ANGLE_TRY(ensureConvertIndexIndirectResourcesInitialized(contextVk));
vk::CommandBuffer *commandBuffer;
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, srcIndirectBuf));
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, srcIndexBuf));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_SHADER_WRITE_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, dstIndirectBuf));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_SHADER_WRITE_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, dstIndexBuf));
ANGLE_TRY(contextVk->onBufferComputeShaderRead(srcIndirectBuf));
ANGLE_TRY(contextVk->onBufferComputeShaderRead(srcIndexBuf));
ANGLE_TRY(contextVk->onBufferComputeShaderWrite(dstIndirectBuf));
ANGLE_TRY(contextVk->onBufferComputeShaderWrite(dstIndexBuf));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
VkDescriptorSet descriptorSet;
......@@ -982,14 +975,10 @@ angle::Result UtilsVk::convertLineLoopIndexIndirectBuffer(
ANGLE_TRY(ensureConvertIndexIndirectLineLoopResourcesInitialized(contextVk));
vk::CommandBuffer *commandBuffer;
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, srcIndirectBuffer));
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, srcIndexBuffer));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_SHADER_WRITE_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, dstIndirectBuffer));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_SHADER_WRITE_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, dstIndexBuffer));
ANGLE_TRY(contextVk->onBufferComputeShaderRead(srcIndirectBuffer));
ANGLE_TRY(contextVk->onBufferComputeShaderRead(srcIndexBuffer));
ANGLE_TRY(contextVk->onBufferComputeShaderWrite(dstIndirectBuffer));
ANGLE_TRY(contextVk->onBufferComputeShaderWrite(dstIndexBuffer));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
VkDescriptorSet descriptorSet;
......@@ -1046,12 +1035,9 @@ angle::Result UtilsVk::convertLineLoopArrayIndirectBuffer(
ANGLE_TRY(ensureConvertIndirectLineLoopResourcesInitialized(contextVk));
vk::CommandBuffer *commandBuffer;
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, srcIndirectBuffer));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_SHADER_WRITE_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, destIndirectBuffer));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_SHADER_WRITE_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, destIndexBuffer));
ANGLE_TRY(contextVk->onBufferComputeShaderRead(srcIndirectBuffer));
ANGLE_TRY(contextVk->onBufferComputeShaderWrite(destIndirectBuffer));
ANGLE_TRY(contextVk->onBufferComputeShaderWrite(destIndexBuffer));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
VkDescriptorSet descriptorSet;
......@@ -1105,10 +1091,8 @@ angle::Result UtilsVk::convertVertexBuffer(ContextVk *contextVk,
ANGLE_TRY(ensureConvertVertexResourcesInitialized(contextVk));
vk::CommandBuffer *commandBuffer;
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, src));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_SHADER_WRITE_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, dest));
ANGLE_TRY(contextVk->onBufferComputeShaderRead(src));
ANGLE_TRY(contextVk->onBufferComputeShaderWrite(dest));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
ConvertVertexShaderParams shaderParams;
......@@ -1819,8 +1803,7 @@ angle::Result UtilsVk::cullOverlayWidgets(ContextVk *contextVk,
&descriptorSet));
vk::CommandBuffer *commandBuffer;
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, enabledWidgetsBuffer));
ANGLE_TRY(contextVk->onBufferComputeShaderRead(enabledWidgetsBuffer));
ANGLE_TRY(contextVk->onImageWrite(VK_IMAGE_ASPECT_COLOR_BIT,
vk::ImageLayout::ComputeShaderWrite, dest));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
......@@ -1897,10 +1880,8 @@ angle::Result UtilsVk::drawOverlay(ContextVk *contextVk,
vk::ImageLayout::ComputeShaderReadOnly, culledWidgets));
ANGLE_TRY(contextVk->onImageRead(VK_IMAGE_ASPECT_COLOR_BIT,
vk::ImageLayout::ComputeShaderReadOnly, font));
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, textWidgetsBuffer));
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_SHADER_READ_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, graphWidgetsBuffer));
ANGLE_TRY(contextVk->onBufferComputeShaderRead(textWidgetsBuffer));
ANGLE_TRY(contextVk->onBufferComputeShaderRead(graphWidgetsBuffer));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
......
......@@ -1813,10 +1813,8 @@ angle::Result BufferHelper::copyFromBuffer(ContextVk *contextVk,
const VkBufferCopy &copyRegion)
{
CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
this));
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
srcBuffer));
ANGLE_TRY(contextVk->onBufferTransferRead(srcBuffer));
ANGLE_TRY(contextVk->onBufferTransferWrite(this));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
commandBuffer->copyBuffer(srcBuffer->getBuffer(), mBuffer, 1, &copyRegion);
......@@ -1952,6 +1950,8 @@ void BufferHelper::updateWriteBarrier(VkAccessFlags writeAccessType,
{
// We don't need to check mCurrentReadStages here since if it is not zero, mCurrentReadAccess
// must not be zero as well. stage is finer grain than accessType.
ASSERT((!mCurrentReadStages && !mCurrentReadAccess) ||
(mCurrentReadStages && mCurrentReadAccess));
if (mCurrentReadAccess != 0 || mCurrentWriteAccess != 0)
{
*barrierSrcOut |= mCurrentWriteAccess;
......@@ -3358,8 +3358,7 @@ angle::Result ImageHelper::flushStagedUpdates(ContextVk *contextVk,
BufferHelper *currentBuffer = bufferUpdate.bufferHelper;
ASSERT(currentBuffer && currentBuffer->valid());
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT, currentBuffer));
ANGLE_TRY(contextVk->onBufferTransferRead(currentBuffer));
commandBuffer->copyBufferToImage(currentBuffer->getBuffer().getHandle(), mImage,
getCurrentLayout(), 1, &update.buffer.copyRegion);
......@@ -3477,8 +3476,7 @@ angle::Result ImageHelper::copyImageDataToBuffer(ContextVk *contextVk,
CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(contextVk->onImageRead(aspectFlags, ImageLayout::TransferSrc, this));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT,
*bufferOut));
ANGLE_TRY(contextVk->onBufferTransferWrite(*bufferOut));
ANGLE_TRY(contextVk->endRenderPassAndGetCommandBuffer(&commandBuffer));
VkBufferImageCopy regions[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