Commit 572ee7b9 by Amy Liu Committed by Commit Bot

Vulkan: Fix texture copy from texture3d to texture2d or cubemap

In vulkan spec, if srcImage or dstImage parameters are of VkImageType VK_IMAGE_TYPE_3D, the baseArrayLayer and layerCount members of the corresponding subresource must be 0 and 1. Bug: angleproject:4553 Change-Id: Iabdc9708c86606c0d78c095c9d44827951264180 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2166863Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent db8a0a77
...@@ -103,6 +103,14 @@ void GetRenderTargetLayerCountAndIndex(vk::ImageHelper *image, ...@@ -103,6 +103,14 @@ void GetRenderTargetLayerCountAndIndex(vk::ImageHelper *image,
UNREACHABLE(); UNREACHABLE();
} }
} }
void Set3DBaseArrayLayerAndLayerCount(VkImageSubresourceLayers *Subresource)
{
// If the srcImage/dstImage parameters are of VkImageType VK_IMAGE_TYPE_3D, the baseArrayLayer
// and layerCount members of the corresponding subresource must be 0 and 1, respectively.
Subresource->baseArrayLayer = 0;
Subresource->layerCount = 1;
}
} // anonymous namespace } // anonymous namespace
// TextureVk implementation. // TextureVk implementation.
...@@ -587,6 +595,12 @@ angle::Result TextureVk::copySubImageImplWithTransfer(ContextVk *contextVk, ...@@ -587,6 +595,12 @@ angle::Result TextureVk::copySubImageImplWithTransfer(ContextVk *contextVk,
srcSubresource.baseArrayLayer = static_cast<uint32_t>(sourceLayer); srcSubresource.baseArrayLayer = static_cast<uint32_t>(sourceLayer);
srcSubresource.layerCount = layerCount; srcSubresource.layerCount = layerCount;
if (srcImage->getExtents().depth > 1)
{
srcOffset.z = srcSubresource.baseArrayLayer;
Set3DBaseArrayLayerAndLayerCount(&srcSubresource);
}
// If destination is valid, copy the source directly into it. // If destination is valid, copy the source directly into it.
if (mImage->valid()) if (mImage->valid())
{ {
...@@ -605,8 +619,7 @@ angle::Result TextureVk::copySubImageImplWithTransfer(ContextVk *contextVk, ...@@ -605,8 +619,7 @@ angle::Result TextureVk::copySubImageImplWithTransfer(ContextVk *contextVk,
VkImageType imageType = gl_vk::GetImageType(mState.getType()); VkImageType imageType = gl_vk::GetImageType(mState.getType());
if (imageType == VK_IMAGE_TYPE_3D) if (imageType == VK_IMAGE_TYPE_3D)
{ {
destSubresource.baseArrayLayer = 0; Set3DBaseArrayLayerAndLayerCount(&destSubresource);
destSubresource.layerCount = 1;
} }
vk::ImageHelper::Copy(srcImage, mImage, srcOffset, destOffset, extents, srcSubresource, vk::ImageHelper::Copy(srcImage, mImage, srcOffset, destOffset, extents, srcSubresource,
......
...@@ -630,6 +630,43 @@ TEST_P(CopyTexImageTestES3, 2DArraySubImage) ...@@ -630,6 +630,43 @@ TEST_P(CopyTexImageTestES3, 2DArraySubImage)
ASSERT_GL_NO_ERROR(); ASSERT_GL_NO_ERROR();
} }
// Test if glCopyTexImage2D() implementation performs conversions well from GL_TEXTURE_3D to
// GL_TEXTURE_2D.
TEST_P(CopyTexImageTestES3, CopyTexSubImageFromTexture3D)
{
// TODO(anglebug.com/3801)
// Seems to fail on D3D11 Windows.
ANGLE_SKIP_TEST_IF(IsD3D11() & IsWindows());
constexpr GLsizei kTexSize = 4;
constexpr GLsizei kLayers = 2;
std::vector<GLColor> red(kTexSize * kTexSize * kLayers, GLColor::red);
GLFramebuffer fbo;
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindTexture(GL_TEXTURE_2D, 0);
// We will be reading from zeroth color attachment.
glReadBuffer(GL_COLOR_ATTACHMENT0);
GLTexture src_object_id;
glBindTexture(GL_TEXTURE_3D, src_object_id);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, kTexSize, kTexSize, kLayers, 0, GL_RGBA,
GL_UNSIGNED_BYTE, NULL);
glTexSubImage3D(GL_TEXTURE_3D, 0, 0, 0, 1, kTexSize, kTexSize, 1, GL_RGBA, GL_UNSIGNED_BYTE,
red.data());
glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, src_object_id, 0, 1);
ASSERT_GL_NO_ERROR();
GLTexture dst_object_id;
glBindTexture(GL_TEXTURE_2D, dst_object_id);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, kTexSize, kTexSize, 0);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, dst_object_id,
0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
ASSERT_GL_NO_ERROR();
}
// Initialize the 3D texture we will copy the subImage data into // Initialize the 3D texture we will copy the subImage data into
void CopyTexImageTestES3::initialize3DTexture(GLTexture &texture, void CopyTexImageTestES3::initialize3DTexture(GLTexture &texture,
const GLsizei imageWidth, const GLsizei imageWidth,
......
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