Fix validation of PVRTC compressed texture sizes.

The PVRTC format, as pointed out by Le Hoang Quyen and Geoff Lang,
uses 4x4 or 8x4 blocks, but due to sampling from adjacent blocks,
requires a minimum size of 2x2 blocks per the OpenGL extension:
https://www.khronos.org/registry/OpenGL/extensions/IMG/IMG_texture_compression_pvrtc.txt
. Thanks to Quyen and Geoff for pointing out the intricacies.

Add a helper function to formatutils.cpp which returns the minimum
number of blocks (width and height) for a given compressed texture
format, and incorporate this into the compressed texture size
computation.

This patch makes WebKit on ANGLE pass WebGL's PVRTC compressed texture
test on iOS hardware.

Bug: angleproject:4652
No-Presubmit: True
Change-Id: I1046a091321b7948d712d16686ee0cb8795b8c99
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2213676
Commit-Queue: Kenneth Russell <kbr@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
This commit is contained in:
Kenneth Russell
2020-05-22 13:52:41 -07:00
committed by Commit Bot
parent f2d4abb2ef
commit 3ecaa283eb
5 changed files with 66 additions and 27 deletions

View File

@@ -2,11 +2,11 @@
"src/libANGLE/renderer/FormatID_autogen.h":
"bbdb3beae2da4629e3583d6d014ebb2d",
"src/libANGLE/renderer/Format_table_autogen.cpp":
"ef632d9cf04b4ba6103f80b61ac26bc9",
"29000a1abc79c129662637f76e7d2a03",
"src/libANGLE/renderer/angle_format.py":
"32ba71942c0fd00e6807104f1bb80a3c",
"src/libANGLE/renderer/angle_format_data.json":
"b8bfe470c31b12b27f3a2bdb0288e4be",
"e5cc162abe241ea9ba270309c8ec1330",
"src/libANGLE/renderer/angle_format_map.json":
"c79d833aea7007c7d0d51cdaa9b265a6",
"src/libANGLE/renderer/gen_angle_format_table.py":

View File

@@ -964,17 +964,17 @@ static InternalFormatInfoMap BuildInternalFormatInfoMap()
// From GL_IMG_texture_compression_pvrtc
// | Internal format | W | H | D | BS |CC| SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer | Blend
AddCompressedFormat(&map, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 1, 1, 1, 1, 3, false, RequireExt<&Extensions::compressedTexturePVRTC>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 1, 1, 1, 1, 3, false, RequireExt<&Extensions::compressedTexturePVRTC>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 1, 1, 1, 1, 4, false, RequireExt<&Extensions::compressedTexturePVRTC>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, 1, 1, 1, 1, 4, false, RequireExt<&Extensions::compressedTexturePVRTC>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 4, 4, 1, 64, 3, false, RequireExt<&Extensions::compressedTexturePVRTC>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 8, 4, 1, 64, 3, false, RequireExt<&Extensions::compressedTexturePVRTC>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 4, 4, 1, 64, 4, false, RequireExt<&Extensions::compressedTexturePVRTC>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, 8, 4, 1, 64, 4, false, RequireExt<&Extensions::compressedTexturePVRTC>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
// From GL_EXT_pvrtc_sRGB
// | Internal format | W | H | D | BS |CC| SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer | Blend
AddCompressedFormat(&map, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, 1, 1, 1, 1, 3, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, 1, 1, 1, 1, 3, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, 1, 1, 1, 1, 4, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, 1, 1, 1, 1, 4, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, 8, 4, 1, 64, 3, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, 4, 4, 1, 64, 3, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, 8, 4, 1, 64, 4, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, 4, 4, 1, 64, 4, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>, AlwaysSupported, NeverSupported, NeverSupported, NeverSupported);
// For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
// - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
@@ -1311,14 +1311,51 @@ bool InternalFormat::computeCompressedImageSize(const Extents &size, GLuint *res
CheckedNumeric<GLuint> checkedDepth(size.depth);
CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
GLuint minBlockWidth, minBlockHeight;
std::tie(minBlockWidth, minBlockHeight) = getCompressedImageMinBlocks();
ASSERT(compressed);
auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
if (numBlocksWide.IsValid() && numBlocksWide.ValueOrDie() < minBlockWidth)
numBlocksWide = minBlockWidth;
if (numBlocksHigh.IsValid() && numBlocksHigh.ValueOrDie() < minBlockHeight)
numBlocksHigh = minBlockHeight;
auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
return CheckedMathResult(bytes, resultOut);
}
std::pair<GLuint, GLuint> InternalFormat::getCompressedImageMinBlocks() const
{
GLuint minBlockWidth = 0;
GLuint minBlockHeight = 0;
// Per the specification, a PVRTC block needs information from the 3 nearest blocks.
// GL_IMG_texture_compression_pvrtc specifies the minimum size requirement in pixels, but
// ANGLE's texture tables are written in terms of blocks. The 4BPP formats use 4x4 blocks, and
// the 2BPP formats, 8x4 blocks. Therefore, both kinds of formats require a minimum of 2x2
// blocks.
switch (internalFormat)
{
case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
case GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT:
case GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT:
case GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT:
case GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT:
minBlockWidth = 2;
minBlockHeight = 2;
break;
default:
break;
}
return std::make_pair(minBlockWidth, minBlockHeight);
}
bool InternalFormat::computeSkipBytes(GLenum formatType,
GLuint rowPitch,
GLuint depthPitch,

View File

@@ -156,6 +156,8 @@ struct InternalFormat
ANGLE_NO_DISCARD bool computeCompressedImageSize(const Extents &size, GLuint *resultOut) const;
ANGLE_NO_DISCARD std::pair<GLuint, GLuint> getCompressedImageMinBlocks() const;
ANGLE_NO_DISCARD bool computeSkipBytes(GLenum formatType,
GLuint rowPitch,
GLuint depthPitch,

View File

@@ -131,14 +131,14 @@ const Format gFormatInfoTable[] = {
{ FormatID::L32_FLOAT, GL_LUMINANCE32F_EXT, GL_LUMINANCE32F_EXT, GenerateMip<L32F>, NoCopyFunctions, ReadColor<L32F, GLfloat>, WriteColor<L32F, GLfloat>, GL_FLOAT, 0, 0, 0, 0, 32, 0, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::Float },
{ FormatID::L8A8_UNORM, GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE8_ALPHA8_EXT, GenerateMip<L8A8>, NoCopyFunctions, ReadColor<L8A8, GLfloat>, WriteColor<L8A8, GLfloat>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 8, 8, 0, 0, 2, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::L8_UNORM, GL_LUMINANCE8_EXT, GL_LUMINANCE8_EXT, GenerateMip<L8>, NoCopyFunctions, ReadColor<L8, GLfloat>, WriteColor<L8, GLfloat>, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 8, 0, 0, 1, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGBA_2BPP_UNORM_BLOCK, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 1, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGBA_2BPP_UNORM_SRGB_BLOCK, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 1, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGBA_4BPP_UNORM_BLOCK, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 1, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGBA_4BPP_UNORM_SRGB_BLOCK, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 1, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGB_2BPP_UNORM_BLOCK, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 1, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGB_2BPP_UNORM_SRGB_BLOCK, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 1, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGB_4BPP_UNORM_BLOCK, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 1, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGB_4BPP_UNORM_SRGB_BLOCK, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 1, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGBA_2BPP_UNORM_BLOCK, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 8, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGBA_2BPP_UNORM_SRGB_BLOCK, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 8, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGBA_4BPP_UNORM_BLOCK, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 8, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGBA_4BPP_UNORM_SRGB_BLOCK, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 8, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGB_2BPP_UNORM_BLOCK, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 8, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGB_2BPP_UNORM_SRGB_BLOCK, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 8, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGB_4BPP_UNORM_BLOCK, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 8, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::PVRTC1_RGB_4BPP_UNORM_SRGB_BLOCK, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, nullptr, NoCopyFunctions, nullptr, nullptr, GL_UNSIGNED_NORMALIZED, 0, 0, 0, 0, 0, 0, 0, 8, std::numeric_limits<GLuint>::max(), true, false, false, gl::VertexAttribType::InvalidEnum },
{ FormatID::R10G10B10A2_SINT, GL_RGB10_A2_SINT_ANGLEX, GL_RGB10_A2_SINT_ANGLEX, GenerateMip<R10G10B10A2S>, NoCopyFunctions, ReadColor<R10G10B10A2S, GLint>, WriteColor<R10G10B10A2S, GLint>, GL_INT, 10, 10, 10, 2, 0, 0, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::Int2101010 },
{ FormatID::R10G10B10A2_SNORM, GL_RGB10_A2_SNORM_ANGLEX, GL_RGB10_A2_SNORM_ANGLEX, GenerateMip<R10G10B10A2S>, NoCopyFunctions, ReadColor<R10G10B10A2S, GLfloat>, WriteColor<R10G10B10A2S, GLfloat>, GL_SIGNED_NORMALIZED, 10, 10, 10, 2, 0, 0, 0, 4, std::numeric_limits<GLuint>::max(), false, false, false, gl::VertexAttribType::Int2101010 },
{ FormatID::R10G10B10A2_SSCALED, GL_RGB10_A2_SSCALED_ANGLEX, GL_RGB10_A2_SSCALED_ANGLEX, GenerateMip<R10G10B10A2S>, NoCopyFunctions, ReadColor<R10G10B10A2S, GLint>, WriteColor<R10G10B10A2S, GLint>, GL_INT, 10, 10, 10, 2, 0, 0, 0, 4, std::numeric_limits<GLuint>::max(), false, false, true, gl::VertexAttribType::Int2101010 },

View File

@@ -262,27 +262,27 @@
"blockPixelBytes": "16"
},
"PVRTC1_RGB_4BPP_UNORM_BLOCK": {
"blockPixelBytes": "1"
"blockPixelBytes": "8"
},
"PVRTC1_RGB_2BPP_UNORM_BLOCK": {
"blockPixelBytes": "1"
"blockPixelBytes": "8"
},
"PVRTC1_RGBA_4BPP_UNORM_BLOCK": {
"blockPixelBytes": "1"
"blockPixelBytes": "8"
},
"PVRTC1_RGBA_2BPP_UNORM_BLOCK": {
"blockPixelBytes": "1"
"blockPixelBytes": "8"
},
"PVRTC1_RGB_2BPP_UNORM_SRGB_BLOCK": {
"blockPixelBytes": "1"
"blockPixelBytes": "8"
},
"PVRTC1_RGB_4BPP_UNORM_SRGB_BLOCK": {
"blockPixelBytes": "1"
"blockPixelBytes": "8"
},
"PVRTC1_RGBA_2BPP_UNORM_SRGB_BLOCK": {
"blockPixelBytes": "1"
"blockPixelBytes": "8"
},
"PVRTC1_RGBA_4BPP_UNORM_SRGB_BLOCK": {
"blockPixelBytes": "1"
"blockPixelBytes": "8"
}
}