Commit 977a28f3 by Shahbaz Youssefi Committed by Angle LUCI CQ

No-op glGenerateMipmap on zero-sized textures

The spec says: > Otherwise, ... if any dimension is zero, all mipmap levels are left > unchanged. This is not an error. Bug: chromium:1220250 Change-Id: I45e007c1f8e9b80f405d3d096eb896a7246f7c8e Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2979853 Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 5b314268
...@@ -1657,6 +1657,16 @@ angle::Result Texture::generateMipmap(Context *context) ...@@ -1657,6 +1657,16 @@ angle::Result Texture::generateMipmap(Context *context)
return angle::Result::Continue; return angle::Result::Continue;
} }
// If any dimension is zero, this is a no-op:
//
// > Otherwise, if level_base is not defined, or if any dimension is zero, all mipmap levels are
// > left unchanged. This is not an error.
const ImageDesc &baseImageInfo = mState.getImageDesc(mState.getBaseImageTarget(), baseLevel);
if (baseImageInfo.size.empty())
{
return angle::Result::Continue;
}
ANGLE_TRY(syncState(context, Command::GenerateMipmap)); ANGLE_TRY(syncState(context, Command::GenerateMipmap));
// Clear the base image(s) immediately if needed // Clear the base image(s) immediately if needed
...@@ -1681,7 +1691,6 @@ angle::Result Texture::generateMipmap(Context *context) ...@@ -1681,7 +1691,6 @@ angle::Result Texture::generateMipmap(Context *context)
// Propagate the format and size of the base mip to the smaller ones. Cube maps are guaranteed // Propagate the format and size of the base mip to the smaller ones. Cube maps are guaranteed
// to have faces of the same size and format so any faces can be picked. // to have faces of the same size and format so any faces can be picked.
const ImageDesc &baseImageInfo = mState.getImageDesc(mState.getBaseImageTarget(), baseLevel);
mState.setImageDescChain(baseLevel, maxLevel, baseImageInfo.size, baseImageInfo.format, mState.setImageDescChain(baseLevel, maxLevel, baseImageInfo.size, baseImageInfo.format,
InitState::Initialized); InitState::Initialized);
......
...@@ -1609,10 +1609,7 @@ angle::Result TextureVk::redefineLevel(const gl::Context *context, ...@@ -1609,10 +1609,7 @@ angle::Result TextureVk::redefineLevel(const gl::Context *context,
// is still valid and we shouldn't redefine it to use the new format. In that case, // is still valid and we shouldn't redefine it to use the new format. In that case,
// ensureImageAllocated will only use the format to update the staging buffer's alignment to // ensureImageAllocated will only use the format to update the staging buffer's alignment to
// support both the previous and the new formats. // support both the previous and the new formats.
if (!size.empty()) ANGLE_TRY(ensureImageAllocated(contextVk, format));
{
ANGLE_TRY(ensureImageAllocated(contextVk, format));
}
return angle::Result::Continue; return angle::Result::Continue;
} }
......
...@@ -2086,6 +2086,26 @@ TEST_P(MipmapTestES3, Generate3DMipmapRespecification) ...@@ -2086,6 +2086,26 @@ TEST_P(MipmapTestES3, Generate3DMipmapRespecification)
ASSERT_GL_NO_ERROR(); ASSERT_GL_NO_ERROR();
} }
// Test the calling glGenerateMipmap on a texture with a zero dimension doesn't crash.
TEST_P(MipmapTestES3, GenerateMipmapZeroSize)
{
GLTexture texture;
glBindTexture(GL_TEXTURE_2D, texture);
// Create a texture with at least one dimension that's zero.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
// Attempt to generate mipmap. This shouldn't crash.
glGenerateMipmap(GL_TEXTURE_2D);
EXPECT_GL_NO_ERROR();
// Try the same with a 3D texture where depth is 0.
GLTexture texture2;
glBindTexture(GL_TEXTURE_3D, texture2);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 2, 2, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
glGenerateMipmap(GL_TEXTURE_3D);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these // Use this to select which configurations (e.g. which renderer, which GLES major version) these
// tests should be run against. // tests should be run against.
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(MipmapTest); ANGLE_INSTANTIATE_TEST_ES2_AND_ES3(MipmapTest);
......
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