Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6ef0387

Browse files
ShabbyXCommit Bot
authored and
Commit Bot
committed
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 <[email protected]> Reviewed-by: Tim Van Patten <[email protected]> Reviewed-by: Jamie Madill <[email protected]>
1 parent 18d412c commit 6ef0387

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/libANGLE/renderer/vulkan/TextureVk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ angle::Result TextureVk::syncState(const gl::Context *context,
16741674
if (isGenerateMipmap)
16751675
{
16761676
mImage->removeStagedUpdates(contextVk, mState.getEffectiveBaseLevel() + 1,
1677-
mState.getEffectiveMaxLevel());
1677+
mState.getMipmapMaxLevel());
16781678
}
16791679

16801680
// Set base and max level before initializing the image

src/tests/gl_tests/MipmapTest.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,62 @@ TEST_P(MipmapTestES3, GenerateMipmapBaseLevel)
11491149
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, GLColor::blue);
11501150
}
11511151

1152+
// Test that generating mipmaps doesn't discard updates staged to out-of-range mips.
1153+
TEST_P(MipmapTestES3, GenerateMipmapPreservesOutOfRangeMips)
1154+
{
1155+
// http://anglebug.com/4782
1156+
ANGLE_SKIP_TEST_IF(IsOpenGL() && IsWindows() && (IsAMD() || IsIntel()));
1157+
1158+
constexpr GLint kTextureSize = 16;
1159+
const std::vector<GLColor> kLevel0Data(kTextureSize * kTextureSize, GLColor::red);
1160+
const std::vector<GLColor> kLevel1Data(kTextureSize * kTextureSize, GLColor::green);
1161+
const std::vector<GLColor> kLevel6Data(kTextureSize * kTextureSize, GLColor::blue);
1162+
1163+
// Initialize a 16x16 RGBA8 texture with red, green and blue for levels 0, 1 and 6 respectively.
1164+
GLTexture tex;
1165+
glBindTexture(GL_TEXTURE_2D, tex);
1166+
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kTextureSize, kTextureSize, 0, GL_RGBA,
1167+
GL_UNSIGNED_BYTE, kLevel0Data.data());
1168+
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, kTextureSize, kTextureSize, 0, GL_RGBA,
1169+
GL_UNSIGNED_BYTE, kLevel1Data.data());
1170+
glTexImage2D(GL_TEXTURE_2D, 6, GL_RGBA, kTextureSize, kTextureSize, 0, GL_RGBA,
1171+
GL_UNSIGNED_BYTE, kLevel6Data.data());
1172+
ASSERT_GL_NO_ERROR();
1173+
1174+
// Set base level to 1, and generate mipmaps. Levels 1 through 5 will be green.
1175+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 1);
1176+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
1177+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1178+
1179+
glGenerateMipmap(GL_TEXTURE_2D);
1180+
ASSERT_GL_NO_ERROR();
1181+
1182+
// Verify that the mips are all green.
1183+
for (int mip = 0; mip < 5; ++mip)
1184+
{
1185+
int scale = 1 << mip;
1186+
clearAndDrawQuad(m2DProgram, getWindowWidth() / scale, getWindowHeight() / scale);
1187+
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / scale / 2, getWindowHeight() / scale / 2,
1188+
kLevel1Data[0]);
1189+
}
1190+
1191+
// Verify that level 0 is red. TODO: setting MAX_LEVEL should be unnecessary, but is needed to
1192+
// work around a bug in the Vulkan backend. http://anglebug.com/4780
1193+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
1194+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
1195+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1196+
1197+
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
1198+
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, kLevel0Data[0]);
1199+
1200+
// Verify that level 6 is blue.
1201+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 6);
1202+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 6);
1203+
1204+
clearAndDrawQuad(m2DProgram, getWindowWidth(), getWindowHeight());
1205+
EXPECT_PIXEL_COLOR_EQ(getWindowWidth() / 2, getWindowHeight() / 2, kLevel6Data[0]);
1206+
}
1207+
11521208
// Create a cube map with levels 0-2, call GenerateMipmap with base level 1 so that level 0 stays
11531209
// the same, and then sample levels 0 and 2.
11541210
// GLES 3.0.4 section 3.8.10:

0 commit comments

Comments
 (0)