Commit 4a24786e by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Fix PBO read pixels with unaligned output pitch

Vulkan takes the output pitch in texels instead of bytes in VkBufferImageCopy::bufferRowLength. This means that it's impossible to use vkCmdCopyImageToBuffer when the pitch is not a multiple of texel size. This change makes sure the fallback path is taken. Bug: angleproject:5667 Change-Id: I3f2ef312bb8288de8ca3c6730d85a3c14858812e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2717006Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent 999da35e
......@@ -683,10 +683,9 @@ bool CanCopyWithTransferForCopyImage(RendererVk *renderer,
}
bool CanCopyWithTransformForReadPixels(const PackPixelsParams &packPixelsParams,
const vk::Format *imageFormat)
const vk::Format *imageFormat,
const angle::Format *readFormat)
{
const angle::Format *readFormat = &imageFormat->actualImageFormat();
// Don't allow copies from emulated formats for simplicity.
const bool isEmulatedFormat = imageFormat->hasEmulatedImageFormat();
......@@ -697,7 +696,12 @@ bool CanCopyWithTransformForReadPixels(const PackPixelsParams &packPixelsParams,
const bool needsTransformation =
packPixelsParams.rotation != SurfaceRotation::Identity || packPixelsParams.reverseRowOrder;
return !isEmulatedFormat && isSameFormatCopy && !needsTransformation;
// Disallow copies when the output pitch cannot be correctly specified in Vulkan.
const bool isPitchMultipleOfTexelSize =
packPixelsParams.outputPitch % readFormat->pixelBytes == 0;
return !isEmulatedFormat && isSameFormatCopy && !needsTransformation &&
isPitchMultipleOfTexelSize;
}
void ReleaseBufferListToRenderer(RendererVk *renderer, BufferHelperPointerVector *buffers)
......@@ -6354,7 +6358,8 @@ angle::Result ImageHelper::readPixels(ContextVk *contextVk,
}
// If PBO and if possible, copy directly on the GPU.
if (packPixelsParams.packBuffer && CanCopyWithTransformForReadPixels(packPixelsParams, mFormat))
if (packPixelsParams.packBuffer &&
CanCopyWithTransformForReadPixels(packPixelsParams, mFormat, readFormat))
{
BufferHelper &packBuffer = GetImpl(packPixelsParams.packBuffer)->getBuffer();
......@@ -6365,6 +6370,8 @@ angle::Result ImageHelper::readPixels(ContextVk *contextVk,
CommandBuffer *copyCommandBuffer;
ANGLE_TRY(contextVk->getOutsideRenderPassCommandBuffer(copyAccess, &copyCommandBuffer));
ASSERT(packPixelsParams.outputPitch % readFormat->pixelBytes == 0);
VkBufferImageCopy region = {};
region.bufferImageHeight = srcExtent.height;
region.bufferOffset = packPixelsParams.offset;
......
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