Title: [262460] trunk/Source/ThirdParty/ANGLE
Revision
262460
Author
[email protected]
Date
2020-06-02 16:18:03 -0700 (Tue, 02 Jun 2020)

Log Message

Revise PVRTC compressed texture validation in ANGLE backend for WebGL
https://bugs.webkit.org/show_bug.cgi?id=212612

Patch by Kenneth Russell <[email protected]> on 2020-06-02
Reviewed by Dean Jackson.

Correct the block sizes of PVRTC textures, and incorporate minimum
block sizes for width and height, as required by these formats.

* src/libANGLE/formatutils.cpp:
(gl::BuildInternalFormatInfoMap):
(gl::InternalFormat::computeCompressedImageSize const):
(gl::InternalFormat::getCompressedImageMinBlocks const):
* src/libANGLE/formatutils.h:

Modified Paths

Diff

Modified: trunk/Source/ThirdParty/ANGLE/ChangeLog (262459 => 262460)


--- trunk/Source/ThirdParty/ANGLE/ChangeLog	2020-06-02 23:10:26 UTC (rev 262459)
+++ trunk/Source/ThirdParty/ANGLE/ChangeLog	2020-06-02 23:18:03 UTC (rev 262460)
@@ -1,3 +1,19 @@
+2020-06-02  Kenneth Russell  <[email protected]>
+
+        Revise PVRTC compressed texture validation in ANGLE backend for WebGL
+        https://bugs.webkit.org/show_bug.cgi?id=212612
+
+        Reviewed by Dean Jackson.
+
+        Correct the block sizes of PVRTC textures, and incorporate minimum
+        block sizes for width and height, as required by these formats.
+
+        * src/libANGLE/formatutils.cpp:
+        (gl::BuildInternalFormatInfoMap):
+        (gl::InternalFormat::computeCompressedImageSize const):
+        (gl::InternalFormat::getCompressedImageMinBlocks const):
+        * src/libANGLE/formatutils.h:
+
 2020-05-29  Keith Rollin  <[email protected]>
 
         Revert switch to XCBuild

Modified: trunk/Source/ThirdParty/ANGLE/src/libANGLE/formatutils.cpp (262459 => 262460)


--- trunk/Source/ThirdParty/ANGLE/src/libANGLE/formatutils.cpp	2020-06-02 23:10:26 UTC (rev 262459)
+++ trunk/Source/ThirdParty/ANGLE/src/libANGLE/formatutils.cpp	2020-06-02 23:18:03 UTC (rev 262460)
@@ -964,17 +964,17 @@
 
     // 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,      8,  8,  1, 256,  3, false, RequireExt<&Extensions::compressedTexturePVRTC>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
-    AddCompressedFormat(&map, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,     16,  8,  1, 256,  3, false, RequireExt<&Extensions::compressedTexturePVRTC>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
-    AddCompressedFormat(&map, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,     8,  8,  1, 256,  4, false, RequireExt<&Extensions::compressedTexturePVRTC>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
-    AddCompressedFormat(&map, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,    16,  8,  1, 256,  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,          16,  8,  1, 256,  3, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
-    AddCompressedFormat(&map, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT,           8,  8,  1, 256,  3, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
-    AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT,    16,  8,  1, 256,  4, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
-    AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT,     8,  8,  1, 256,  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,48 @@
     CheckedNumeric<GLuint> checkedDepth(size.depth);
     CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
     CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
+    GLuint minBlockWidth, minBlockHeight;
+    getCompressedImageMinBlocks(&minBlockWidth, &minBlockHeight);
 
     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);
 }
 
+void InternalFormat::getCompressedImageMinBlocks(GLuint* minBlockWidth, GLuint* minBlockHeight) const
+{
+    *minBlockWidth = 0;
+    *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;
+    }
+}
+
 bool InternalFormat::computeSkipBytes(GLenum formatType,
                                       GLuint rowPitch,
                                       GLuint depthPitch,

Modified: trunk/Source/ThirdParty/ANGLE/src/libANGLE/formatutils.h (262459 => 262460)


--- trunk/Source/ThirdParty/ANGLE/src/libANGLE/formatutils.h	2020-06-02 23:10:26 UTC (rev 262459)
+++ trunk/Source/ThirdParty/ANGLE/src/libANGLE/formatutils.h	2020-06-02 23:18:03 UTC (rev 262460)
@@ -156,6 +156,8 @@
 
     ANGLE_NO_DISCARD bool computeCompressedImageSize(const Extents &size, GLuint *resultOut) const;
 
+    void getCompressedImageMinBlocks(GLuint* minBlockWidth, GLuint* minBlockHeight) const;
+
     ANGLE_NO_DISCARD bool computeSkipBytes(GLenum formatType,
                                            GLuint rowPitch,
                                            GLuint depthPitch,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to