Commit 6ef0387d by Shahbaz Youssefi Committed by Commit Bot

Vulkan: Fix mipmap generation discarding levels above max

Bug: angleproject:4551 Change-Id: I1f65e41049b8cc8065ff988bb708cb44acfdb98b Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2257263 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarTim Van Patten <timvp@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 18d412cb
...@@ -1674,7 +1674,7 @@ angle::Result TextureVk::syncState(const gl::Context *context, ...@@ -1674,7 +1674,7 @@ angle::Result TextureVk::syncState(const gl::Context *context,
if (isGenerateMipmap) if (isGenerateMipmap)
{ {
mImage->removeStagedUpdates(contextVk, mState.getEffectiveBaseLevel() + 1, mImage->removeStagedUpdates(contextVk, mState.getEffectiveBaseLevel() + 1,
mState.getEffectiveMaxLevel()); mState.getMipmapMaxLevel());
} }
// Set base and max level before initializing the image // Set base and max level before initializing the image
......
...@@ -1149,6 +1149,62 @@ TEST_P(MipmapTestES3, GenerateMipmapBaseLevel) ...@@ -1149,6 +1149,62 @@ TEST_P(MipmapTestES3, GenerateMipmapBaseLevel)
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue); EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
} }
// Test that generating mipmaps doesn't discard updates staged to out-of-range mips.
TEST_P(MipmapTestES3, GenerateMipmapPreservesOutOfRangeMips)
{
// http://anglebug.com/4782
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsWindows() && (IsAMD() || IsIntel()));
constexpr GLint kTextureSize = 16;
const std::vector<GLColor> kLevel0Data(kTextureSize * kTextureSize, GLColor::red);
const std::vector<GLColor> kLevel1Data(kTextureSize * kTextureSize, GLColor::green);
const std::vector<GLColor> kLevel6Data(kTextureSize * kTextureSize, GLColor::blue);
// Initialize a 16x16 RGBA8 texture with red, green and blue for levels 0, 1 and 6 respectively.
GLTexture tex;
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kTextureSize, kTextureSize, 0, GL_RGBA,
GL_UNSIGNED_BYTE, kLevel0Data.data());
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, kTextureSize, kTextureSize, 0, GL_RGBA,
GL_UNSIGNED_BYTE, kLevel1Data.data());
glTexImage2D(GL_TEXTURE_2D, 6, GL_RGBA, kTextureSize, kTextureSize, 0, GL_RGBA,
GL_UNSIGNED_BYTE, kLevel6Data.data());
ASSERT_GL_NO_ERROR();
// Set base level to 1, and generate mipmaps. Levels 1 through 5 will be green.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glGenerateMipmap(GL_TEXTURE_2D);
ASSERT_GL_NO_ERROR();
// Verify that the mips are all green.
for (int mip = 0; mip < 5; ++mip)
{
int scale = 1 << mip;
clearAndDrawQuad(m2DProgram, getWindowWidth() / scale, getWindowHeight() / scale);
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / scale / 2, getWindowHeight() / scale / 2,
kLevel1Data[0]);
}
// Verify that level 0 is red. TODO: setting MAX_LEVEL should be unnecessary, but is needed to
// work around a bug in the Vulkan backend. http://anglebug.com/4780
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, kLevel0Data[0]);
// Verify that level 6 is blue.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 6);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 6);
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, kLevel6Data[0]);
}
// Create a cube map with levels 0-2, call GenerateMipmap with base level 1 so that level 0 stays // Create a cube map with levels 0-2, call GenerateMipmap with base level 1 so that level 0 stays
// the same, and then sample levels 0 and 2. // the same, and then sample levels 0 and 2.
// GLES 3.0.4 section 3.8.10: // GLES 3.0.4 section 3.8.10:
......
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