Commit 815a6c9a by Jamie Madill Committed by Commit Bot

Vulkan: Fix copyImage region parameters.

In cases where we were reading back more than one pixel in ReadPixels, and in some cases for texture init, we weren't using the correct parameters to vkCmdCopyImage. This CL fixes both of those by using more correct copy regions, and fixing the row and depth pitch computation using vkGetImageSubresourceLayout. BUG=angleproject:2167 Change-Id: Ib70217ed4a17be6b4b1b8aeec9a8a6199d210d88 Reviewed-on: https://chromium-review.googlesource.com/732190Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 8df71735
...@@ -295,18 +295,29 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context, ...@@ -295,18 +295,29 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
stagingImage.getImage().changeLayoutTop(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL, stagingImage.getImage().changeLayoutTop(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL,
commandBuffer); commandBuffer);
gl::Box copyRegion;
copyRegion.x = area.x;
copyRegion.y = area.y;
copyRegion.z = 0;
copyRegion.width = area.width;
copyRegion.height = area.height;
copyRegion.depth = 1;
readImage->changeLayoutTop(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, readImage->changeLayoutTop(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
commandBuffer); commandBuffer);
commandBuffer->copySingleImage(*readImage, stagingImage.getImage(), copyRegion,
VK_IMAGE_ASPECT_COLOR_BIT); VkImageCopy region;
region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
region.srcSubresource.mipLevel = 0;
region.srcSubresource.baseArrayLayer = 0;
region.srcSubresource.layerCount = 1;
region.srcOffset.x = area.x;
region.srcOffset.y = area.y;
region.srcOffset.z = 0;
region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
region.dstSubresource.mipLevel = 0;
region.dstSubresource.baseArrayLayer = 0;
region.dstSubresource.layerCount = 1;
region.dstOffset.x = 0;
region.dstOffset.y = 0;
region.dstOffset.z = 0;
region.extent.width = area.width;
region.extent.height = area.height;
region.extent.depth = 1;
commandBuffer->copyImage(*readImage, stagingImage.getImage(), 1, &region);
ANGLE_TRY(renderer->submitAndFinishCommandBuffer(commandBuffer)); ANGLE_TRY(renderer->submitAndFinishCommandBuffer(commandBuffer));
......
...@@ -154,13 +154,25 @@ gl::Error TextureVk::setImage(const gl::Context *context, ...@@ -154,13 +154,25 @@ gl::Error TextureVk::setImage(const gl::Context *context,
auto loadFunction = vkFormat.getLoadFunctions()(type); auto loadFunction = vkFormat.getLoadFunctions()(type);
uint8_t *mapPointer = nullptr; uint8_t *mapPointer = nullptr;
ANGLE_TRY( ANGLE_TRY(stagingImage.getDeviceMemory().map(device, 0, VK_WHOLE_SIZE, 0, &mapPointer));
stagingImage.getDeviceMemory().map(device, 0, stagingImage.getSize(), 0, &mapPointer));
const uint8_t *source = pixels + inputSkipBytes; const uint8_t *source = pixels + inputSkipBytes;
// Get the subresource layout. This has important parameters like row pitch.
// TODO(jmadill): Fill out this structure based on input parameters.
VkImageSubresource subresource;
subresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
subresource.mipLevel = 0;
subresource.arrayLayer = 0;
VkSubresourceLayout subresourceLayout;
vkGetImageSubresourceLayout(device, stagingImage.getImage().getHandle(), &subresource,
&subresourceLayout);
loadFunction.loadFunction(size.width, size.height, size.depth, source, inputRowPitch, loadFunction.loadFunction(size.width, size.height, size.depth, source, inputRowPitch,
inputDepthPitch, mapPointer, inputRowPitch, inputDepthPitch); inputDepthPitch, mapPointer,
static_cast<size_t>(subresourceLayout.rowPitch),
static_cast<size_t>(subresourceLayout.depthPitch));
stagingImage.getDeviceMemory().unmap(device); stagingImage.getDeviceMemory().unmap(device);
......
...@@ -362,12 +362,6 @@ void CommandBuffer::copySingleImage(const vk::Image &srcImage, ...@@ -362,12 +362,6 @@ void CommandBuffer::copySingleImage(const vk::Image &srcImage,
const gl::Box &copyRegion, const gl::Box &copyRegion,
VkImageAspectFlags aspectMask) VkImageAspectFlags aspectMask)
{ {
ASSERT(valid());
ASSERT(srcImage.getCurrentLayout() == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL ||
srcImage.getCurrentLayout() == VK_IMAGE_LAYOUT_GENERAL);
ASSERT(destImage.getCurrentLayout() == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL ||
destImage.getCurrentLayout() == VK_IMAGE_LAYOUT_GENERAL);
VkImageCopy region; VkImageCopy region;
region.srcSubresource.aspectMask = aspectMask; region.srcSubresource.aspectMask = aspectMask;
region.srcSubresource.mipLevel = 0; region.srcSubresource.mipLevel = 0;
...@@ -387,8 +381,21 @@ void CommandBuffer::copySingleImage(const vk::Image &srcImage, ...@@ -387,8 +381,21 @@ void CommandBuffer::copySingleImage(const vk::Image &srcImage,
region.extent.height = copyRegion.height; region.extent.height = copyRegion.height;
region.extent.depth = copyRegion.depth; region.extent.depth = copyRegion.depth;
vkCmdCopyImage(mHandle, srcImage.getHandle(), srcImage.getCurrentLayout(), copyImage(srcImage, destImage, 1, &region);
destImage.getHandle(), destImage.getCurrentLayout(), 1, &region); }
void CommandBuffer::copyImage(const vk::Image &srcImage,
const vk::Image &dstImage,
uint32_t regionCount,
const VkImageCopy *regions)
{
ASSERT(valid() && srcImage.valid() && dstImage.valid());
ASSERT(srcImage.getCurrentLayout() == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL ||
srcImage.getCurrentLayout() == VK_IMAGE_LAYOUT_GENERAL);
ASSERT(dstImage.getCurrentLayout() == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL ||
dstImage.getCurrentLayout() == VK_IMAGE_LAYOUT_GENERAL);
vkCmdCopyImage(mHandle, srcImage.getHandle(), srcImage.getCurrentLayout(), dstImage.getHandle(),
dstImage.getCurrentLayout(), 1, regions);
} }
void CommandBuffer::beginRenderPass(const RenderPass &renderPass, void CommandBuffer::beginRenderPass(const RenderPass &renderPass,
......
...@@ -223,6 +223,11 @@ class CommandBuffer final : public WrappedObject<CommandBuffer, VkCommandBuffer> ...@@ -223,6 +223,11 @@ class CommandBuffer final : public WrappedObject<CommandBuffer, VkCommandBuffer>
const gl::Box &copyRegion, const gl::Box &copyRegion,
VkImageAspectFlags aspectMask); VkImageAspectFlags aspectMask);
void copyImage(const vk::Image &srcImage,
const vk::Image &dstImage,
uint32_t regionCount,
const VkImageCopy *regions);
void beginRenderPass(const RenderPass &renderPass, void beginRenderPass(const RenderPass &renderPass,
const Framebuffer &framebuffer, const Framebuffer &framebuffer,
const gl::Rectangle &renderArea, const gl::Rectangle &renderArea,
......
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