Commit 20b1259a by Jamie Madill Committed by Commit Bot

Vulkan: Command graph linearization (Step 2).

ES 2.0 is feature complete. Passes all of the angle_end2end_tests with the new linear command recording method. Also runs the T-Rex benchmark without any obvious glitches. Likely has issues with creating too many RenderPasses. ES3 is mostly untouched. Bug: angleproject:4029 Change-Id: Ic5acf3d768495fbffd07b07bf0a6f2b5787c51f8 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2012900Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 806ba566
......@@ -229,8 +229,8 @@ angle::Result BufferVk::copySubData(const gl::Context *context,
}
else
{
contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, &sourceBuffer->getBuffer());
contextVk->onBufferWrite(VK_ACCESS_TRANSFER_WRITE_BIT, &mBuffer);
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, &sourceBuffer->getBuffer()));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_TRANSFER_WRITE_BIT, &mBuffer));
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
......@@ -421,8 +421,8 @@ angle::Result BufferVk::copyToBuffer(ContextVk *contextVk,
}
else
{
contextVk->onBufferWrite(VK_ACCESS_TRANSFER_WRITE_BIT, destBuffer);
contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, &mBuffer);
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_TRANSFER_WRITE_BIT, destBuffer));
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, &mBuffer));
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
......
......@@ -95,31 +95,43 @@ class CommandQueue final : angle::NonCopyable
vk::PersistentCommandPool mPrimaryCommandPool;
};
class OutsideRenderPassCommandBuffer final : angle::NonCopyable
struct CommandBufferHelper : angle::NonCopyable
{
public:
OutsideRenderPassCommandBuffer();
~OutsideRenderPassCommandBuffer();
void bufferRead(VkAccessFlags readAccessType, vk::BufferHelper *buffer);
void bufferWrite(VkAccessFlags writeAccessType, vk::BufferHelper *buffer);
void flushToPrimary(vk::PrimaryCommandBuffer *primary);
void bufferRead(vk::ResourceUseList *resourceUseList,
VkAccessFlags readAccessType,
vk::BufferHelper *buffer);
void bufferWrite(vk::ResourceUseList *resourceUseList,
VkAccessFlags writeAccessType,
vk::BufferHelper *buffer);
vk::CommandBuffer &getCommandBuffer() { return mCommandBuffer; }
bool empty() const { return mCommandBuffer.empty(); }
void reset();
protected:
CommandBufferHelper();
~CommandBufferHelper();
void recordBarrier(vk::PrimaryCommandBuffer *primary);
private:
VkFlags mGlobalMemoryBarrierSrcAccess;
VkFlags mGlobalMemoryBarrierDstAccess;
VkPipelineStageFlags mGlobalMemoryBarrierStages;
vk::CommandBuffer mCommandBuffer;
};
class RenderPassCommandBuffer final : angle::NonCopyable
class OutsideRenderPassCommandBuffer final : public CommandBufferHelper
{
public:
OutsideRenderPassCommandBuffer();
~OutsideRenderPassCommandBuffer();
void flushToPrimary(vk::PrimaryCommandBuffer *primary);
bool empty() const { return mCommandBuffer.empty(); }
void reset();
};
class RenderPassCommandBuffer final : public CommandBufferHelper
{
public:
RenderPassCommandBuffer();
......@@ -167,9 +179,11 @@ class RenderPassCommandBuffer final : angle::NonCopyable
mAttachmentOps[attachmentIndex].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
}
const gl::Rectangle &getRenderArea() const { return mRenderArea; }
angle::Result flushToPrimary(ContextVk *contextVk, vk::PrimaryCommandBuffer *primary);
bool empty() const { return mCommandBuffer.empty(); }
bool empty() const { return !mRenderPassStarted; }
void reset();
uint32_t getAndResetCounter()
......@@ -186,7 +200,7 @@ class RenderPassCommandBuffer final : angle::NonCopyable
vk::Framebuffer mFramebuffer;
gl::Rectangle mRenderArea;
gl::AttachmentArray<VkClearValue> mClearValues;
vk::CommandBuffer mCommandBuffer;
bool mRenderPassStarted;
};
class ContextVk : public ContextImpl, public vk::Context, public vk::RenderPassOwner
......@@ -517,7 +531,7 @@ class ContextVk : public ContextImpl, public vk::Context, public vk::RenderPassO
Serial generateTextureSerial() { return mTextureSerialFactory.generate(); }
const vk::TextureDescriptorDesc &getActiveTexturesDesc() const { return mActiveTexturesDesc; }
void updateScissor(const gl::State &glState);
angle::Result updateScissor(const gl::State &glState);
bool emulateSeamfulCubeMapSampling() const { return mEmulateSeamfulCubeMapSampling; }
......@@ -527,13 +541,22 @@ class ContextVk : public ContextImpl, public vk::Context, public vk::RenderPassO
vk::ResourceUseList &getResourceUseList() { return mResourceUseList; }
void onBufferRead(VkAccessFlags readAccessType, vk::BufferHelper *buffer);
void onBufferWrite(VkAccessFlags writeAccessType, vk::BufferHelper *buffer);
angle::Result onBufferRead(VkAccessFlags readAccessType, vk::BufferHelper *buffer);
angle::Result onBufferWrite(VkAccessFlags writeAccessType, vk::BufferHelper *buffer);
angle::Result onImageRead(VkImageAspectFlags aspectFlags,
vk::ImageLayout imageLayout,
vk::ImageHelper *image);
angle::Result onImageWrite(VkImageAspectFlags aspectFlags,
vk::ImageLayout imageLayout,
vk::ImageHelper *image);
angle::Result getOutsideRenderPassCommandBuffer(vk::CommandBuffer **commandBufferOut)
{
if (!mRenderPassCommands.empty())
{
ANGLE_TRY(mRenderPassCommands.flushToPrimary(this, &mPrimaryCommands));
ANGLE_TRY(endRenderPass());
}
*commandBufferOut = &mOutsideRenderPassCommands.getCommandBuffer();
return angle::Result::Continue;
......@@ -556,6 +579,7 @@ class ContextVk : public ContextImpl, public vk::Context, public vk::RenderPassO
}
egl::ContextPriority getContextPriority() const override { return mContextPriority; }
angle::Result endRenderPass();
private:
// Dirty bits.
......
......@@ -859,6 +859,9 @@ angle::Result FramebufferVk::resolveColorWithCommand(ContextVk *contextVk,
const UtilsVk::BlitResolveParameters &params,
vk::ImageHelper *srcImage)
{
vk::CommandBuffer *commandBuffer = nullptr;
if (contextVk->commandGraphEnabled())
{
if (srcImage->isLayoutChangeNecessary(vk::ImageLayout::TransferSrc))
{
vk::CommandBuffer *srcLayoutChange;
......@@ -867,11 +870,16 @@ angle::Result FramebufferVk::resolveColorWithCommand(ContextVk *contextVk,
srcLayoutChange);
}
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(mFramebuffer.recordCommands(contextVk, &commandBuffer));
// Source's layout change should happen before rendering
srcImage->addReadDependency(contextVk, &mFramebuffer);
}
else
{
ANGLE_TRY(contextVk->onImageRead(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::TransferSrc,
srcImage));
}
VkImageResolve resolveRegion = {};
resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
......@@ -893,9 +901,20 @@ angle::Result FramebufferVk::resolveColorWithCommand(ContextVk *contextVk,
for (size_t colorIndexGL : mState.getEnabledDrawBuffers())
{
RenderTargetVk *drawRenderTarget = mRenderTargetCache.getColors()[colorIndexGL];
vk::ImageHelper *drawImage = drawRenderTarget->getImageForWrite(contextVk, &mFramebuffer);
if (contextVk->commandGraphEnabled())
{
vk::ImageHelper *drawImage =
drawRenderTarget->getImageForWrite(contextVk, &mFramebuffer);
drawImage->changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::TransferDst,
commandBuffer);
}
else
{
ANGLE_TRY(contextVk->onImageWrite(VK_IMAGE_ASPECT_COLOR_BIT,
vk::ImageLayout::TransferDst,
&drawRenderTarget->getImage()));
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
resolveRegion.dstSubresource.mipLevel = drawRenderTarget->getLevelIndex();
resolveRegion.dstSubresource.baseArrayLayer = drawRenderTarget->getLayerIndex();
......@@ -1074,7 +1093,7 @@ angle::Result FramebufferVk::syncState(const gl::Context *context,
// The FBOs new attachment may have changed the renderable area
const gl::State &glState = context->getState();
contextVk->updateScissor(glState);
ANGLE_TRY(contextVk->updateScissor(glState));
mActiveColorComponents = gl_vk::GetColorComponentFlags(
mActiveColorComponentMasksForClear[0].any(), mActiveColorComponentMasksForClear[1].any(),
......@@ -1088,6 +1107,10 @@ angle::Result FramebufferVk::syncState(const gl::Context *context,
// create a new entry in the command graph.
mFramebuffer.finishCurrentCommands(contextVk);
}
else
{
ANGLE_TRY(contextVk->endRenderPass());
}
// Notify the ContextVk to update the pipeline desc.
updateRenderPassDesc();
......@@ -1222,7 +1245,7 @@ angle::Result FramebufferVk::clearWithRenderPassOp(
// render pass is needed,
// - the current render area doesn't match the clear area. We need the render area to be
// exactly as specified by the scissor for the loadOp to clear only that area. See
// onScissorChange for more information.
// ContextVk::updateScissor for more information.
if (!mFramebuffer.valid() || !mFramebuffer.renderPassStartedButEmpty() ||
mFramebuffer.getRenderPassRenderArea() != clearArea)
......@@ -1468,28 +1491,6 @@ gl::Rectangle FramebufferVk::getScissoredRenderArea(ContextVk *contextVk) const
return ClipRectToScissor(contextVk->getState(), renderArea, invertViewport);
}
void FramebufferVk::onScissorChange(ContextVk *contextVk)
{
gl::Rectangle scissoredRenderArea = getScissoredRenderArea(contextVk);
// If the scissor has grown beyond the previous scissoredRenderArea, make sure the render pass
// is restarted. Otherwise, we can continue using the same renderpass area.
//
// Without a scissor, the render pass area covers the whole of the framebuffer. With a
// scissored clear, the render pass area could be smaller than the framebuffer size. When the
// scissor changes, if the scissor area is completely encompassed by the render pass area, it's
// possible to continue using the same render pass. However, if the current render pass area
// is too small, we need to start a new one. The latter can happen if a scissored clear starts
// a render pass, the scissor is disabled and a draw call is issued to affect the whole
// framebuffer.
mFramebuffer.updateCurrentAccessNodes();
if (mFramebuffer.hasStartedRenderPass() &&
!mFramebuffer.getRenderPassRenderArea().encloses(scissoredRenderArea))
{
mFramebuffer.finishCurrentCommands(contextVk);
}
}
RenderTargetVk *FramebufferVk::getFirstRenderTarget() const
{
for (auto *renderTarget : mRenderTargetCache.getColors())
......
......@@ -105,8 +105,6 @@ class FramebufferVk : public FramebufferImpl
gl::Rectangle getCompleteRenderArea() const;
gl::Rectangle getScissoredRenderArea(ContextVk *contextVk) const;
void onScissorChange(ContextVk *contextVk);
const gl::DrawBufferMask &getEmulatedAlphaAttachmentMask() const;
RenderTargetVk *getColorDrawRenderTarget(size_t colorIndex) const;
RenderTargetVk *getColorReadRenderTarget() const;
......
......@@ -1428,29 +1428,18 @@ void ProgramVk::updateBuffersDescriptorSet(ContextVk *contextVk,
BufferVk *bufferVk = vk::GetImpl(bufferBinding.get());
vk::BufferHelper &bufferHelper = bufferVk->getBuffer();
if (contextVk->getFeatures().commandGraph.enabled)
{
if (isStorageBuffer)
{
// We set the SHADER_READ_BIT to be conservative.
VkAccessFlags accessFlags = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT;
if (contextVk->getFeatures().commandGraph.enabled)
{
bufferHelper.onWrite(contextVk, recorder, accessFlags);
}
else
{
contextVk->onBufferWrite(accessFlags, &bufferHelper);
}
}
else
{
if (contextVk->getFeatures().commandGraph.enabled)
{
bufferHelper.onRead(contextVk, recorder, VK_ACCESS_UNIFORM_READ_BIT);
}
else
{
contextVk->onBufferRead(VK_ACCESS_UNIFORM_READ_BIT, &bufferHelper);
}
}
++writeCount;
......
......@@ -61,15 +61,19 @@ angle::Result RenderTargetVk::onColorDraw(ContextVk *contextVk,
ASSERT(commandBuffer->valid());
ASSERT(!mImage->getFormat().actualImageFormat().hasDepthOrStencilBits());
// TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
if (contextVk->commandGraphEnabled())
{
mImage->changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::ColorAttachment,
commandBuffer);
if (contextVk->commandGraphEnabled())
{
// Set up dependencies between the RT resource and the Framebuffer.
mImage->addWriteDependency(contextVk, framebufferVk);
}
else
{
ANGLE_TRY(contextVk->onImageWrite(VK_IMAGE_ASPECT_COLOR_BIT,
vk::ImageLayout::ColorAttachment, mImage));
}
onImageViewAccess(contextVk);
......@@ -83,14 +87,21 @@ angle::Result RenderTargetVk::onDepthStencilDraw(ContextVk *contextVk,
ASSERT(commandBuffer->valid());
ASSERT(mImage->getFormat().actualImageFormat().hasDepthOrStencilBits());
// TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
const angle::Format &format = mImage->getFormat().actualImageFormat();
VkImageAspectFlags aspectFlags = vk::GetDepthStencilAspectFlags(format);
if (contextVk->commandGraphEnabled())
{
mImage->changeLayout(aspectFlags, vk::ImageLayout::DepthStencilAttachment, commandBuffer);
// Set up dependencies between the RT resource and the Framebuffer.
mImage->addWriteDependency(contextVk, framebufferVk);
}
else
{
ANGLE_TRY(
contextVk->onImageWrite(aspectFlags, vk::ImageLayout::DepthStencilAttachment, mImage));
}
onImageViewAccess(contextVk);
......@@ -180,7 +191,14 @@ angle::Result RenderTargetVk::flushStagedUpdates(ContextVk *contextVk)
return angle::Result::Continue;
vk::CommandBuffer *commandBuffer;
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(mImage->recordCommands(contextVk, &commandBuffer));
}
else
{
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
return mImage->flushStagedUpdates(contextVk, mLevelIndex, mLevelIndex + 1, mLayerIndex,
mLayerIndex + 1, commandBuffer);
}
......
......@@ -1086,13 +1086,23 @@ angle::Result WindowSurfaceVk::present(ContextVk *contextVk,
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(mColorImageMS.recordCommands(contextVk, &commandBuffer));
}
mColorImageMS.changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::TransferSrc,
commandBuffer);
image.image.changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::TransferDst,
commandBuffer);
// Setup graph dependency between the swapchain image and the multisampled one.
image.image.addReadDependency(contextVk, &mColorImageMS);
ANGLE_TRY(image.image.recordCommands(contextVk, &commandBuffer));
}
else
{
ANGLE_TRY(contextVk->onImageRead(VK_IMAGE_ASPECT_COLOR_BIT,
vk::ImageLayout::TransferSrc, &mColorImageMS));
ANGLE_TRY(contextVk->onImageWrite(VK_IMAGE_ASPECT_COLOR_BIT,
vk::ImageLayout::TransferDst, &image.image));
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
VkImageResolve resolveRegion = {};
resolveRegion.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
......@@ -1104,10 +1114,6 @@ angle::Result WindowSurfaceVk::present(ContextVk *contextVk,
resolveRegion.dstOffset = {};
resolveRegion.extent = image.image.getExtents();
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(image.image.recordCommands(contextVk, &commandBuffer));
}
mColorImageMS.resolve(&image.image, resolveRegion, commandBuffer);
}
......
......@@ -572,6 +572,8 @@ angle::Result TextureVk::copySubImageImplWithTransfer(ContextVk *contextVk,
gl::Extents extents = {sourceArea.width, sourceArea.height, 1};
// Change source layout if necessary
if (contextVk->commandGraphEnabled())
{
if (srcImage->isLayoutChangeNecessary(vk::ImageLayout::TransferSrc))
{
vk::CommandBuffer *srcLayoutChange;
......@@ -579,6 +581,12 @@ angle::Result TextureVk::copySubImageImplWithTransfer(ContextVk *contextVk,
srcImage->changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::TransferSrc,
srcLayoutChange);
}
}
else
{
ANGLE_TRY(contextVk->onImageRead(VK_IMAGE_ASPECT_COLOR_BIT, vk::ImageLayout::TransferSrc,
srcImage));
}
VkImageSubresourceLayers srcSubresource = {};
srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
......@@ -593,6 +601,8 @@ angle::Result TextureVk::copySubImageImplWithTransfer(ContextVk *contextVk,
ANGLE_TRY(ensureImageInitialized(contextVk, ImageMipLevels::EnabledLevels));
vk::CommandBuffer *commandBuffer;
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(mImage->recordCommands(contextVk, &commandBuffer));
// Change the image layout before the transfer
......@@ -601,6 +611,13 @@ angle::Result TextureVk::copySubImageImplWithTransfer(ContextVk *contextVk,
// Source's layout change should happen before the copy
srcImage->addReadDependency(contextVk, mImage);
}
else
{
ANGLE_TRY(contextVk->onImageWrite(VK_IMAGE_ASPECT_COLOR_BIT,
vk::ImageLayout::TransferDst, mImage));
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
VkImageSubresourceLayers destSubresource = srcSubresource;
destSubresource.mipLevel = level;
......@@ -628,6 +645,8 @@ angle::Result TextureVk::copySubImageImplWithTransfer(ContextVk *contextVk,
destFormat, kTransferStagingImageFlags, layerCount));
vk::CommandBuffer *commandBuffer;
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(stagingImage->recordCommands(contextVk, &commandBuffer));
// Change the image layout before the transfer
......@@ -636,6 +655,13 @@ angle::Result TextureVk::copySubImageImplWithTransfer(ContextVk *contextVk,
// Source's layout change should happen before the copy
srcImage->addReadDependency(contextVk, stagingImage.get());
}
else
{
ANGLE_TRY(contextVk->onImageWrite(VK_IMAGE_ASPECT_COLOR_BIT,
vk::ImageLayout::TransferDst, stagingImage.get()));
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
VkImageSubresourceLayers destSubresource = srcSubresource;
destSubresource.mipLevel = 0;
......@@ -1155,7 +1181,15 @@ angle::Result TextureVk::generateMipmap(const gl::Context *context)
if (mImage->hasStagedUpdates())
{
vk::CommandBuffer *commandBuffer = nullptr;
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(mImage->recordCommands(contextVk, &commandBuffer));
}
else
{
mImage->onResourceAccess(&contextVk->getResourceUseList());
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
ANGLE_TRY(mImage->flushStagedUpdates(contextVk, getNativeImageLevel(0),
mImage->getLevelCount(), getNativeImageLayer(0),
mImage->getLayerCount(), commandBuffer));
......@@ -1168,9 +1202,13 @@ angle::Result TextureVk::generateMipmap(const gl::Context *context)
// Create a new node for the image and add a global memory barrier for the staging buffer.
// It's written to and staged to be read from when ensureImageInitialized() is called.
if (contextVk->commandGraphEnabled())
{
mImage->finishCurrentCommands(contextVk);
mImage->addGlobalMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT, VK_ACCESS_TRANSFER_READ_BIT,
mImage->addGlobalMemoryBarrier(VK_ACCESS_TRANSFER_WRITE_BIT,
VK_ACCESS_TRANSFER_READ_BIT,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT);
}
onStagingBufferChange();
// Release the origin image and recreate it with new mipmap counts.
......
......@@ -108,15 +108,19 @@ void RendererVk::ensureCapsInitialized() const
// We use secondary command buffers almost everywhere and they require a feature to be
// able to execute in the presence of queries. As a result, we won't support queries
// unless that feature is available.
// TODO(jmadill): Enable without graph. http://anglebug.com/4029
mNativeExtensions.occlusionQueryBoolean =
vk::CommandBuffer::SupportsQueries(mPhysicalDeviceFeatures);
vk::CommandBuffer::SupportsQueries(mPhysicalDeviceFeatures) &&
mFeatures.commandGraph.enabled;
// From the Vulkan specs:
// > The number of valid bits in a timestamp value is determined by the
// > VkQueueFamilyProperties::timestampValidBits property of the queue on which the timestamp is
// > written. Timestamps are supported on any queue which reports a non-zero value for
// > timestampValidBits via vkGetPhysicalDeviceQueueFamilyProperties.
mNativeExtensions.disjointTimerQuery = queueFamilyProperties.timestampValidBits > 0;
// TODO(jmadill): Enable without graph. http://anglebug.com/4029
mNativeExtensions.disjointTimerQuery =
queueFamilyProperties.timestampValidBits > 0 && mFeatures.commandGraph.enabled;
mNativeExtensions.queryCounterBitsTimeElapsed = queueFamilyProperties.timestampValidBits;
mNativeExtensions.queryCounterBitsTimestamp = queueFamilyProperties.timestampValidBits;
......@@ -467,7 +471,8 @@ void RendererVk::ensureCapsInitialized() const
mNativeExtensions.pixelBufferObjectNV = true;
// Enable GL_NV_fence extension.
mNativeExtensions.fenceNV = true;
// TODO(jmadill): Enable without graph. http://anglebug.com/4029
mNativeExtensions.fenceNV = mFeatures.commandGraph.enabled;
// Geometry shader is optional.
if (mPhysicalDeviceFeatures.geometryShader)
......
......@@ -1528,12 +1528,20 @@ angle::Result BufferHelper::copyFromBuffer(ContextVk *contextVk,
{
// 'recordCommands' will implicitly stop any reads from using the old buffer data.
CommandBuffer *commandBuffer = nullptr;
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
}
else
{
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
if (mCurrentReadAccess != 0 || mCurrentWriteAccess != 0 || bufferAccessType != 0)
{
// Insert a barrier to ensure reads/writes are complete.
// Use a global memory barrier to keep things simple.
// TODO(jmadill): Can we revisit this with http://anglebug.com/4029
VkMemoryBarrier memoryBarrier = {};
memoryBarrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER;
memoryBarrier.srcAccessMask = mCurrentReadAccess | mCurrentWriteAccess | bufferAccessType;
......@@ -2192,9 +2200,18 @@ void ImageHelper::Copy(ImageHelper *srcImage,
angle::Result ImageHelper::generateMipmapsWithBlit(ContextVk *contextVk, GLuint maxLevel)
{
CommandBuffer *commandBuffer = nullptr;
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
changeLayout(VK_IMAGE_ASPECT_COLOR_BIT, ImageLayout::TransferDst, commandBuffer);
}
else
{
ANGLE_TRY(
contextVk->onImageWrite(VK_IMAGE_ASPECT_COLOR_BIT, ImageLayout::TransferDst, this));
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
// We are able to use blitImage since the image format we are using supports it. This
// is a faster way we can generate the mips.
......@@ -2274,8 +2291,6 @@ void ImageHelper::resolve(ImageHelper *dest,
CommandBuffer *commandBuffer)
{
ASSERT(mCurrentLayout == ImageLayout::TransferSrc);
dest->changeLayout(region.dstSubresource.aspectMask, ImageLayout::TransferDst, commandBuffer);
commandBuffer->resolveImage(getImage(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dest->getImage(),
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
}
......@@ -2852,7 +2867,14 @@ angle::Result ImageHelper::flushStagedUpdates(ContextVk *contextVk,
uint64_t subresourceUploadsInProgress = 0;
// Start in TransferDst.
if (contextVk->commandGraphEnabled())
{
changeLayout(aspectFlags, ImageLayout::TransferDst, commandBuffer);
}
else
{
ANGLE_TRY(contextVk->onImageWrite(aspectFlags, ImageLayout::TransferDst, this));
}
for (SubresourceUpdate &update : mSubresourceUpdates)
{
......@@ -2950,15 +2972,32 @@ angle::Result ImageHelper::flushStagedUpdates(ContextVk *contextVk,
BufferHelper *currentBuffer = bufferUpdate.bufferHelper;
ASSERT(currentBuffer && currentBuffer->valid());
if (contextVk->commandGraphEnabled())
{
currentBuffer->onResourceAccess(&contextVk->getResourceUseList());
}
else
{
ANGLE_TRY(contextVk->onBufferRead(VK_ACCESS_TRANSFER_READ_BIT, currentBuffer));
}
commandBuffer->copyBufferToImage(currentBuffer->getBuffer().getHandle(), mImage,
getCurrentLayout(), 1, &update.buffer.copyRegion);
}
else
{
update.image.image->changeLayout(aspectFlags, ImageLayout::TransferSrc, commandBuffer);
if (contextVk->commandGraphEnabled())
{
update.image.image->changeLayout(aspectFlags, ImageLayout::TransferSrc,
commandBuffer);
update.image.image->addReadDependency(contextVk, this);
}
else
{
ANGLE_TRY(contextVk->onImageRead(aspectFlags, ImageLayout::TransferSrc,
update.image.image));
}
commandBuffer->copyImage(update.image.image->getImage(),
update.image.image->getCurrentLayout(), mImage,
......@@ -2983,7 +3022,14 @@ angle::Result ImageHelper::flushAllStagedUpdates(ContextVk *contextVk)
{
// Clear the image.
CommandBuffer *commandBuffer = nullptr;
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
}
else
{
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
return flushStagedUpdates(contextVk, 0, mLevelCount, 0, mLayerCount, commandBuffer);
}
......@@ -3060,17 +3106,27 @@ angle::Result ImageHelper::copyImageDataToBuffer(ContextVk *contextVk,
*bufferSize = sourceArea.width * sourceArea.height * sourceArea.depth * pixelBytes * layerCount;
CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
// Transition the image to readable layout
const VkImageAspectFlags aspectFlags = getAspectFlags();
changeLayout(aspectFlags, ImageLayout::TransferSrc, commandBuffer);
// Allocate staging buffer data
ANGLE_TRY(allocateStagingMemory(contextVk, *bufferSize, outDataPtr, bufferOut, bufferOffsetsOut,
nullptr));
CommandBuffer *commandBuffer = nullptr;
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
// Transition the image to readable layout
changeLayout(aspectFlags, ImageLayout::TransferSrc, commandBuffer);
}
else
{
ANGLE_TRY(contextVk->onImageRead(aspectFlags, ImageLayout::TransferSrc, this));
ANGLE_TRY(contextVk->onBufferWrite(VK_ACCESS_TRANSFER_WRITE_BIT, *bufferOut));
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
VkBufferImageCopy regions[2] = {};
// Default to non-combined DS case
regions[0].bufferOffset = (*bufferOffsetsOut)[0];
......@@ -3208,17 +3264,43 @@ angle::Result ImageHelper::readPixels(ContextVk *contextVk,
RendererVk *renderer = contextVk->getRenderer();
// If the source image is multisampled, we need to resolve it into a temporary image before
// performing a readback.
bool isMultisampled = mSamples > 1;
DeviceScoped<ImageHelper> resolvedImage(contextVk->getDevice());
ImageHelper *src = this;
if (isMultisampled)
{
ANGLE_TRY(resolvedImage.get().init2DStaging(
contextVk, renderer->getMemoryProperties(), gl::Extents(area.width, area.height, 1),
*mFormat, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 1));
resolvedImage.get().onResourceAccess(&contextVk->getResourceUseList());
}
// Note that although we're reading from the image, we need to update the layout below.
CommandBuffer *commandBuffer;
if (contextVk->commandGraphEnabled())
{
ANGLE_TRY(recordCommands(contextVk, &commandBuffer));
if (isMultisampled)
{
resolvedImage.get().changeLayout(copyAspectFlags, ImageLayout::TransferDst,
commandBuffer);
}
changeLayout(copyAspectFlags, ImageLayout::TransferSrc, commandBuffer);
}
else
{
if (isMultisampled)
{
ANGLE_TRY(contextVk->onImageWrite(copyAspectFlags, ImageLayout::TransferDst,
&resolvedImage.get()));
}
ANGLE_TRY(contextVk->onImageRead(copyAspectFlags, ImageLayout::TransferSrc, this));
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(&commandBuffer));
}
changeLayout(copyAspectFlags, ImageLayout::TransferSrc, commandBuffer);
const angle::Format *readFormat = &mFormat->actualImageFormat();
......@@ -3245,20 +3327,8 @@ angle::Result ImageHelper::readPixels(ContextVk *contextVk,
srcSubresource.baseArrayLayer = 0;
}
// If the source image is multisampled, we need to resolve it into a temporary image before
// performing a readback.
bool isMultisampled = mSamples > 1;
DeviceScoped<ImageHelper> resolvedImage(contextVk->getDevice());
ImageHelper *src = this;
if (isMultisampled)
{
ANGLE_TRY(resolvedImage.get().init2DStaging(
contextVk, renderer->getMemoryProperties(), gl::Extents(area.width, area.height, 1),
*mFormat, VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, 1));
resolvedImage.get().onResourceAccess(&contextVk->getResourceUseList());
// Note: resolve only works on color images (not depth/stencil).
//
// TODO: Currently, depth/stencil blit can perform a depth/stencil readback, but that code
......@@ -3277,7 +3347,16 @@ angle::Result ImageHelper::readPixels(ContextVk *contextVk,
resolve(&resolvedImage.get(), resolveRegion, commandBuffer);
resolvedImage.get().changeLayout(copyAspectFlags, ImageLayout::TransferSrc, commandBuffer);
if (contextVk->commandGraphEnabled())
{
resolvedImage.get().changeLayout(copyAspectFlags, ImageLayout::TransferSrc,
commandBuffer);
}
else
{
ANGLE_TRY(contextVk->onImageRead(copyAspectFlags, ImageLayout::TransferSrc,
&resolvedImage.get()));
}
// Make the resolved image the target of buffer copy.
src = &resolvedImage.get();
......
......@@ -927,6 +927,9 @@ TEST_P(RobustResourceInitTest, Texture)
{
ANGLE_SKIP_TEST_IF(!hasGLExtension());
// Flaky failure on Linux / NV / Vulkan when run in a sequence. http://anglebug.com/3416
ANGLE_SKIP_TEST_IF(IsVulkan() && IsNVIDIA() && IsLinux());
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
......
......@@ -1080,6 +1080,6 @@ TEST_P(SimpleOperationTest, PrimitiveModeNegativeTest)
// Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against.
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND(SimpleOperationTest, WithNoCommandGraph(ES2_VULKAN()));
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(SimpleOperationTest);
} // namespace
......@@ -118,7 +118,7 @@ struct CombinedPrintToStringParamName
#define ANGLE_ALL_TEST_PLATFORMS_ES2 \
ES2_D3D9(), ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES(), ES2_VULKAN(), ES2_VULKAN_SWIFTSHADER(), \
ES2_METAL()
ES2_METAL(), WithNoCommandGraph(ES2_VULKAN())
#define ANGLE_ALL_TEST_PLATFORMS_ES3 \
ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES(), ES3_VULKAN(), ES3_VULKAN_SWIFTSHADER()
......
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