Commit 422ebad2 by Jamie Madill Committed by Commit Bot

Fix ANGLE_get_image cube map handling.

Was missing a layer parameter. Also includes a regression test. Also updates incomplete texture handling in Vulkan. Will try to sync the texture storage if the texture has never been used. Bug: angleproject:3944 Change-Id: I5fcd6931f9cb9e008faaeaecb1f6df275a2af73f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1894142 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com>
parent 35f74cd6
......@@ -1742,20 +1742,18 @@ angle::Result TextureVk::getTexImage(const gl::Context *context,
void *pixels)
{
ContextVk *contextVk = vk::GetImpl(context);
if (mImage && mImage->valid())
{
ANGLE_TRY(mImage->flushAllStagedUpdates(contextVk));
size_t layer =
gl::IsCubeMapFaceTarget(target) ? gl::CubeMapTextureTargetToFaceIndex(target) : 0;
return mImage->readPixelsForGetImage(contextVk, packState, packBuffer, level,
static_cast<uint32_t>(layer), format, type, pixels);
// Assumes Texture is consistent.
// TODO(http://anglebug.com/4058): Handle incomplete textures.
if (!mImage || !mImage->valid())
{
ANGLE_TRY(ensureImageInitialized(contextVk, ImageMipLevels::EnabledLevels));
}
// Incomplete or unused texture. Will require a staging texture.
// TODO(http://anglebug.com/4058): Incomplete texture readback.
UNIMPLEMENTED();
return angle::Result::Continue;
size_t layer =
gl::IsCubeMapFaceTarget(target) ? gl::CubeMapTextureTargetToFaceIndex(target) : 0;
return mImage->readPixelsForGetImage(contextVk, packState, packBuffer, level,
static_cast<uint32_t>(layer), format, type, pixels);
}
const vk::Format &TextureVk::getBaseLevelFormat(RendererVk *renderer) const
......
......@@ -3020,7 +3020,7 @@ angle::Result ImageHelper::readPixelsForGetImage(ContextVk *contextVk,
stagingBuffer.get().init(contextVk->getRenderer(), VK_BUFFER_USAGE_TRANSFER_DST_BIT, 1,
kStagingBufferSize, true);
return readPixels(contextVk, area, params, VK_IMAGE_ASPECT_COLOR_BIT, level, 0,
return readPixels(contextVk, area, params, VK_IMAGE_ASPECT_COLOR_BIT, level, layer,
static_cast<uint8_t *>(pixels) + outputSkipBytes, &stagingBuffer.get());
}
......
......@@ -16,6 +16,7 @@ namespace
{
constexpr uint32_t kSize = 32;
constexpr char kExtensionName[] = "GL_ANGLE_get_image";
constexpr uint32_t kSmallSize = 2;
class GetImageTest : public ANGLETest
{
......@@ -174,13 +175,52 @@ TEST_P(GetImageTest, GetTexImage)
EXPECT_EQ(expectedData, actualData);
}
// Simple cube map test for GetTexImage
TEST_P(GetImageTest, CubeMap)
{
// Verify the extension is enabled.
ASSERT_TRUE(IsGLExtensionEnabled(kExtensionName));
const std::array<std::array<GLColor, kSmallSize * kSmallSize>, kCubeFaces.size()> expectedData =
{{
{GLColor::red, GLColor::red, GLColor::red, GLColor::red},
{GLColor::green, GLColor::green, GLColor::green, GLColor::green},
{GLColor::blue, GLColor::blue, GLColor::blue, GLColor::blue},
{GLColor::yellow, GLColor::yellow, GLColor::yellow, GLColor::yellow},
{GLColor::cyan, GLColor::cyan, GLColor::cyan, GLColor::cyan},
{GLColor::magenta, GLColor::magenta, GLColor::magenta, GLColor::magenta},
}};
GLTexture texture;
glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
for (size_t faceIndex = 0; faceIndex < kCubeFaces.size(); ++faceIndex)
{
glTexImage2D(kCubeFaces[faceIndex], 0, GL_RGBA, kSmallSize, kSmallSize, 0, GL_RGBA,
GL_UNSIGNED_BYTE, expectedData[faceIndex].data());
}
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// Pack pixels tightly.
glPixelStorei(GL_PACK_ALIGNMENT, 1);
// Verify GetImage.
std::array<GLColor, kSmallSize *kSmallSize> actualData = {};
for (size_t faceIndex = 0; faceIndex < kCubeFaces.size(); ++faceIndex)
{
glGetTexImageANGLE(kCubeFaces[faceIndex], 0, GL_RGBA, GL_UNSIGNED_BYTE, actualData.data());
EXPECT_GL_NO_ERROR();
EXPECT_EQ(expectedData[faceIndex], actualData);
}
}
// Simple test for GetRenderbufferImage
TEST_P(GetImageTest, GetRenderbufferImage)
{
// Verify the extension is enabled.
ASSERT_TRUE(IsGLExtensionEnabled(kExtensionName));
constexpr uint32_t kSmallSize = 2;
std::vector<GLColor> expectedData = {GLColor::red, GLColor::blue, GLColor::green,
GLColor::yellow};
......
......@@ -31,11 +31,6 @@ constexpr char kGreenFragmentShader[] =
gl_FragColor = vec4(0, 1, 0, 1);
})";
constexpr std::array<GLenum, 6> kCubeFaces = {
{GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z}};
class SimpleOperationTest : public ANGLETest
{
protected:
......
......@@ -168,6 +168,11 @@ bool operator==(const GLColor32F &a, const GLColor32F &b);
std::ostream &operator<<(std::ostream &ostream, const GLColor32F &color);
GLColor32F ReadColor32F(GLint x, GLint y);
constexpr std::array<GLenum, 6> kCubeFaces = {
{GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z}};
} // namespace angle
#define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
......
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