xref: /aosp_15_r20/external/angle/src/tests/gl_tests/CompressedTextureFormatsTest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // CompressedTextureFormatsTest:
7 //   Tests that only the appropriate entry points are affected after
8 //   enabling compressed texture extensions.
9 //
10 
11 #include "common/gl_enum_utils.h"
12 #include "test_utils/ANGLETest.h"
13 #include "test_utils/gl_raii.h"
14 
15 using namespace angle;
16 
17 namespace
18 {
19 
20 struct FormatDesc
21 {
22     GLenum format;
23     GLsizei blockX;
24     GLsizei blockY;
25     GLsizei size;
26 
isPVRTC1__anon209b30dd0111::FormatDesc27     bool isPVRTC1() const
28     {
29         return ((format & ~3) == GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG) ||
30                ((format & ~3) == GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT);
31     }
mayBeEmulated__anon209b30dd0111::FormatDesc32     bool mayBeEmulated() const
33     {
34         return format == GL_COMPRESSED_R11_EAC || format == GL_COMPRESSED_RG11_EAC ||
35                format == GL_COMPRESSED_SIGNED_R11_EAC || format == GL_COMPRESSED_SIGNED_RG11_EAC ||
36                format == GL_ETC1_RGB8_OES || format == GL_COMPRESSED_RGB8_ETC2 ||
37                format == GL_COMPRESSED_SRGB8_ETC2 ||
38                format == GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 ||
39                format == GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 ||
40                format == GL_COMPRESSED_RGBA8_ETC2_EAC ||
41                format == GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
42     }
43 };
44 using CompressedTextureTestParams = std::tuple<angle::PlatformParameters, FormatDesc>;
45 
46 class CompressedTextureFormatsTest : public ANGLETest<CompressedTextureTestParams>
47 {
48   public:
CompressedTextureFormatsTest(const std::string ext1,const std::string ext2,const bool supportsUpdates,const bool supportsPartialUpdates,const bool supports2DArray,const bool supports3D,const bool alwaysOnES3)49     CompressedTextureFormatsTest(const std::string ext1,
50                                  const std::string ext2,
51                                  const bool supportsUpdates,
52                                  const bool supportsPartialUpdates,
53                                  const bool supports2DArray,
54                                  const bool supports3D,
55                                  const bool alwaysOnES3)
56         : mExtNames({ext1, ext2}),
57           mSupportsUpdates(supportsUpdates),
58           mSupportsPartialUpdates(supportsPartialUpdates),
59           mSupports2DArray(supports2DArray),
60           mSupports3D(supports3D),
61           mAlwaysOnES3(alwaysOnES3)
62     {
63         setExtensionsEnabled(false);
64     }
65 
testSetUp()66     void testSetUp() override
67     {
68         // Apple platforms require PVRTC1 textures to be squares.
69         mSquarePvrtc1 = IsAppleGPU();
70     }
71 
checkSubImage2D(FormatDesc desc,int numX)72     void checkSubImage2D(FormatDesc desc, int numX)
73     {
74         GLubyte data[64] = {};
75 
76         // The semantic of this call is to take uncompressed data, compress it on-the-fly,
77         // and perform a partial update of an existing GPU-compressed texture. This
78         // operation is not supported in OpenGL ES.
79         glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, desc.blockX, desc.blockY, GL_RGBA, GL_UNSIGNED_BYTE,
80                         nullptr);
81         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
82 
83         // Compressed texture extensions never extend TexSubImage2D.
84         glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, desc.blockX, desc.blockY, desc.format,
85                         GL_UNSIGNED_BYTE, nullptr);
86         EXPECT_GL_ERROR(GL_INVALID_ENUM);
87 
88         // The semantic of this call is to take pixel data from the current framebuffer, compress it
89         // on-the-fly, and perform a partial update of an existing GPU-compressed texture. This
90         // operation is not supported in OpenGL ES.
91         glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, desc.blockX, desc.blockY);
92         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
93 
94         // Try whole image update. It is always valid when API supports updates.
95         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, desc.blockX * numX, desc.blockY * 2,
96                                   desc.format, desc.size * 4, data);
97         if (!mSupportsUpdates)
98         {
99             EXPECT_GL_ERROR(GL_INVALID_OPERATION);
100             return;
101         }
102         EXPECT_GL_NO_ERROR();
103 
104         if (!mSupportsPartialUpdates)
105         {
106             glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, desc.blockX, desc.blockY, desc.format,
107                                       desc.size, data);
108             EXPECT_GL_ERROR(GL_INVALID_OPERATION);
109             return;
110         }
111 
112         // All compressed formats that support partial updates require the offsets to be
113         // multiples of block dimensions.
114         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 1, 0, desc.blockX, desc.blockY, desc.format,
115                                   desc.size, data);
116         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
117 
118         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 1, desc.blockX, desc.blockY, desc.format,
119                                   desc.size, data);
120         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
121 
122         // All compressed formats that support partial updates require the dimensions to be
123         // multiples of block dimensions or reach the image boundaries.
124         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, desc.blockX - 1, desc.blockY, desc.format,
125                                   desc.size, data);
126         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
127 
128         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, desc.blockX, desc.blockY - 1, desc.format,
129                                   desc.size, data);
130         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
131 
132         // Test should pass when replaced region dimensions are multiples the of block
133         // dimensions
134         // clang-format off
135         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0,           0,           desc.blockX, desc.blockY, desc.format, desc.size, data);
136         EXPECT_GL_NO_ERROR();
137         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, desc.blockX, 0,           desc.blockX, desc.blockY, desc.format, desc.size, data);
138         EXPECT_GL_NO_ERROR();
139         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0,           desc.blockY, desc.blockX, desc.blockY, desc.format, desc.size, data);
140         EXPECT_GL_NO_ERROR();
141         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, desc.blockX, desc.blockY, desc.blockX, desc.blockY, desc.format, desc.size, data);
142         EXPECT_GL_NO_ERROR();
143 
144         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0,           0,           desc.blockX * 2, desc.blockY,     desc.format, desc.size * 2, data);
145         EXPECT_GL_NO_ERROR();
146         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0,           0,           desc.blockX,     desc.blockY * 2, desc.format, desc.size * 2, data);
147         EXPECT_GL_NO_ERROR();
148         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0,           desc.blockY, desc.blockX * 2, desc.blockY,     desc.format, desc.size * 2, data);
149         EXPECT_GL_NO_ERROR();
150         glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, desc.blockX, 0,           desc.blockX,     desc.blockY * 2, desc.format, desc.size * 2, data);
151         EXPECT_GL_NO_ERROR();
152         // clang-format on
153 
154         // Test should pass when replaced region dimensions are not multiples of block dimensions
155         // but reach the image boundaries. For example, it is valid to replace right-bottom 2x2
156         // region of a 6x6 texture made of 4x4 blocks. To check this on all platforms with the same
157         // code, level 1 should be used to avoid hitting a D3D11 limitation.
158         if (getClientMajorVersion() >= 3 || EnsureGLExtensionEnabled("GL_OES_texture_npot"))
159         {
160             GLTexture texture;
161             glBindTexture(GL_TEXTURE_2D, texture);
162             const int newW = desc.blockX * 3;
163             const int newH = desc.blockY * 3;
164             glCompressedTexImage2D(GL_TEXTURE_2D, 0, desc.format, newW, newH, 0, desc.size * 9,
165                                    nullptr);
166             EXPECT_GL_NO_ERROR();
167 
168             glCompressedTexImage2D(GL_TEXTURE_2D, 1, desc.format, newW / 2, newH / 2, 0,
169                                    desc.size * 4, nullptr);
170             EXPECT_GL_NO_ERROR();
171 
172             // clang-format off
173             glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, desc.blockX, 0,           desc.blockX / 2,     desc.blockY,         desc.format, desc.size * 1, data);
174             EXPECT_GL_NO_ERROR();
175             glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, desc.blockX, 0,           desc.blockX / 2,     desc.blockY * 3 / 2, desc.format, desc.size * 2, data);
176             EXPECT_GL_NO_ERROR();
177             glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0,           desc.blockY, desc.blockX,         desc.blockY / 2,     desc.format, desc.size * 1, data);
178             EXPECT_GL_NO_ERROR();
179             glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, 0,           desc.blockY, desc.blockX * 3 / 2, desc.blockY / 2,     desc.format, desc.size * 2, data);
180             EXPECT_GL_NO_ERROR();
181             glCompressedTexSubImage2D(GL_TEXTURE_2D, 1, desc.blockX, desc.blockY, desc.blockX / 2,     desc.blockY / 2,     desc.format, desc.size * 1, data);
182             EXPECT_GL_NO_ERROR();
183             // clang-format on
184         }
185     }
186 
checkSubImage3D(GLenum target,FormatDesc desc)187     void checkSubImage3D(GLenum target, FormatDesc desc)
188     {
189         GLubyte data[128] = {};
190 
191         // The semantic of this call is to take uncompressed data, compress it on-the-fly,
192         // and perform a partial update of an existing GPU-compressed texture. This
193         // operation is not supported in OpenGL ES.
194         glTexSubImage3D(target, 0, 0, 0, 0, desc.blockX, desc.blockY, 2, GL_RGBA, GL_UNSIGNED_BYTE,
195                         nullptr);
196         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
197 
198         // Compressed texture extensions never extend TexSubImage3D.
199         glTexSubImage3D(target, 0, 0, 0, 0, desc.blockX, desc.blockY, 2, desc.format,
200                         GL_UNSIGNED_BYTE, nullptr);
201         EXPECT_GL_ERROR(GL_INVALID_ENUM);
202 
203         // The semantic of this call is to take pixel data from the current framebuffer, compress it
204         // on-the-fly, and perform a partial update of an existing GPU-compressed texture. This
205         // operation is not supported in OpenGL ES.
206         glCopyTexSubImage3D(target, 0, 0, 0, 0, 0, 0, desc.blockX, desc.blockY);
207         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
208 
209         // All formats that are accepted for 3D entry points support updates.
210         ASSERT(mSupportsUpdates);
211 
212         // Try whole image update. It is always valid for formats that support updates.
213         glCompressedTexSubImage3D(target, 0, 0, 0, 0, desc.blockX * 2, desc.blockY * 2, 2,
214                                   desc.format, desc.size * 8, data);
215         EXPECT_GL_NO_ERROR();
216 
217         // Try a whole image update from a pixel unpack buffer.
218         // Don't test non-emulated formats on Desktop GL.
219         // TODO(anglebug.com/42264819): implement emulation on Desktop GL, then remove this check.
220         if (!(IsDesktopOpenGL() && desc.mayBeEmulated()))
221         {
222             GLBuffer buffer;
223             glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);
224             glBufferData(GL_PIXEL_UNPACK_BUFFER, 128, data, GL_STREAM_DRAW);
225             EXPECT_GL_NO_ERROR();
226 
227             glCompressedTexSubImage3D(target, 0, 0, 0, 0, desc.blockX * 2, desc.blockY * 2, 2,
228                                       desc.format, desc.size * 8, nullptr);
229             EXPECT_GL_NO_ERROR();
230 
231             glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
232         }
233 
234         // All formats that are accepted for 3D entry points support partial updates.
235         ASSERT(mSupportsPartialUpdates);
236 
237         // All compressed formats that support partial updates require the offsets to be
238         // multiples of block dimensions.
239         glCompressedTexSubImage3D(target, 0, 1, 0, 0, desc.blockX, desc.blockY, 1, desc.format,
240                                   desc.size, data);
241         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
242 
243         glCompressedTexSubImage3D(target, 0, 0, 1, 0, desc.blockX, desc.blockY, 1, desc.format,
244                                   desc.size, data);
245         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
246 
247         // All compressed formats that support partial updates require the dimensions to be
248         // multiples of block dimensions or reach the image boundaries.
249         glCompressedTexSubImage3D(target, 0, 0, 0, 0, desc.blockX - 1, desc.blockY, 1, desc.format,
250                                   desc.size, data);
251         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
252 
253         glCompressedTexSubImage3D(target, 0, 0, 0, 0, desc.blockX, desc.blockY - 1, 1, desc.format,
254                                   desc.size, data);
255         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
256 
257         // Valid partial updates
258         // clang-format off
259         glCompressedTexSubImage3D(target, 0, 0,           0,           0, desc.blockX, desc.blockY, 1, desc.format, desc.size, data);
260         EXPECT_GL_NO_ERROR();
261         glCompressedTexSubImage3D(target, 0, desc.blockX, 0,           0, desc.blockX, desc.blockY, 1, desc.format, desc.size, data);
262         EXPECT_GL_NO_ERROR();
263         glCompressedTexSubImage3D(target, 0, 0,           desc.blockY, 0, desc.blockX, desc.blockY, 1, desc.format, desc.size, data);
264         EXPECT_GL_NO_ERROR();
265         glCompressedTexSubImage3D(target, 0, desc.blockX, desc.blockY, 0, desc.blockX, desc.blockY, 1, desc.format, desc.size, data);
266         EXPECT_GL_NO_ERROR();
267         glCompressedTexSubImage3D(target, 0, 0,           0,           1, desc.blockX, desc.blockY, 1, desc.format, desc.size, data);
268         EXPECT_GL_NO_ERROR();
269         glCompressedTexSubImage3D(target, 0, desc.blockX, 0,           1, desc.blockX, desc.blockY, 1, desc.format, desc.size, data);
270         EXPECT_GL_NO_ERROR();
271         glCompressedTexSubImage3D(target, 0, 0,           desc.blockY, 1, desc.blockX, desc.blockY, 1, desc.format, desc.size, data);
272         EXPECT_GL_NO_ERROR();
273         glCompressedTexSubImage3D(target, 0, desc.blockX, desc.blockY, 1, desc.blockX, desc.blockY, 1, desc.format, desc.size, data);
274         EXPECT_GL_NO_ERROR();
275 
276         glCompressedTexSubImage3D(target, 0, 0,           0,           0, desc.blockX * 2, desc.blockY,     1, desc.format, desc.size * 2, data);
277         EXPECT_GL_NO_ERROR();
278         glCompressedTexSubImage3D(target, 0, 0,           0,           0, desc.blockX,     desc.blockY * 2, 1, desc.format, desc.size * 2, data);
279         EXPECT_GL_NO_ERROR();
280         glCompressedTexSubImage3D(target, 0, 0,           desc.blockY, 0, desc.blockX * 2, desc.blockY,     1, desc.format, desc.size * 2, data);
281         EXPECT_GL_NO_ERROR();
282         glCompressedTexSubImage3D(target, 0, desc.blockX, 0,           0, desc.blockX,     desc.blockY * 2, 1, desc.format, desc.size * 2, data);
283         EXPECT_GL_NO_ERROR();
284         glCompressedTexSubImage3D(target, 0, 0,           0,           1, desc.blockX * 2, desc.blockY,     1, desc.format, desc.size * 2, data);
285         EXPECT_GL_NO_ERROR();
286         glCompressedTexSubImage3D(target, 0, 0,           0,           1, desc.blockX,     desc.blockY * 2, 1, desc.format, desc.size * 2, data);
287         EXPECT_GL_NO_ERROR();
288         glCompressedTexSubImage3D(target, 0, 0,           desc.blockY, 1, desc.blockX * 2, desc.blockY,     1, desc.format, desc.size * 2, data);
289         EXPECT_GL_NO_ERROR();
290         glCompressedTexSubImage3D(target, 0, desc.blockX, 0,           1, desc.blockX,     desc.blockY * 2, 1, desc.format, desc.size * 2, data);
291         EXPECT_GL_NO_ERROR();
292         glCompressedTexSubImage3D(target, 0, 0,           0,           0, desc.blockX,     desc.blockY,     2, desc.format, desc.size * 2, data);
293         EXPECT_GL_NO_ERROR();
294         glCompressedTexSubImage3D(target, 0, desc.blockX, 0,           0, desc.blockX,     desc.blockY,     2, desc.format, desc.size * 2, data);
295         EXPECT_GL_NO_ERROR();
296         glCompressedTexSubImage3D(target, 0, 0,           desc.blockY, 0, desc.blockX,     desc.blockY,     2, desc.format, desc.size * 2, data);
297         EXPECT_GL_NO_ERROR();
298         glCompressedTexSubImage3D(target, 0, desc.blockX, desc.blockY, 0, desc.blockX,     desc.blockY,     2, desc.format, desc.size * 2, data);
299         EXPECT_GL_NO_ERROR();
300         // clang-format on
301 
302         // Test should pass when replaced region dimensions are not multiples of block dimensions
303         // but reach the image boundaries. For example, it is valid to replace right-bottom 2x2
304         // region of a 6x6 texture made of 4x4 blocks. To check this on all platforms with the same
305         // code, level 1 should be used to avoid hitting a D3D11 limitation.
306         {
307             GLTexture texture;
308             glBindTexture(target, texture);
309             const int newW = desc.blockX * 3;
310             const int newH = desc.blockY * 3;
311             glCompressedTexImage3D(target, 0, desc.format, newW, newH, 2, 0, desc.size * 18,
312                                    nullptr);
313             EXPECT_GL_NO_ERROR();
314 
315             if (target == GL_TEXTURE_2D_ARRAY)
316             {
317                 glCompressedTexImage3D(target, 1, desc.format, newW / 2, newH / 2, 2, 0,
318                                        desc.size * 8, nullptr);
319                 EXPECT_GL_NO_ERROR();
320 
321                 // clang-format off
322                 glCompressedTexSubImage3D(target, 1, desc.blockX, 0,           0, desc.blockX / 2,     desc.blockY,         1, desc.format, desc.size * 1, data);
323                 EXPECT_GL_NO_ERROR();
324                 glCompressedTexSubImage3D(target, 1, desc.blockX, 0,           0, desc.blockX / 2,     desc.blockY * 3 / 2, 1, desc.format, desc.size * 2, data);
325                 EXPECT_GL_NO_ERROR();
326                 glCompressedTexSubImage3D(target, 1, 0,           desc.blockY, 0, desc.blockX,         desc.blockY / 2,     1, desc.format, desc.size * 1, data);
327                 EXPECT_GL_NO_ERROR();
328                 glCompressedTexSubImage3D(target, 1, 0,           desc.blockY, 0, desc.blockX * 3 / 2, desc.blockY / 2,     1, desc.format, desc.size * 2, data);
329                 EXPECT_GL_NO_ERROR();
330                 glCompressedTexSubImage3D(target, 1, desc.blockX, desc.blockY, 0, desc.blockX / 2,     desc.blockY / 2,     1, desc.format, desc.size * 1, data);
331                 EXPECT_GL_NO_ERROR();
332 
333                 glCompressedTexSubImage3D(target, 1, desc.blockX, 0,           1, desc.blockX / 2,     desc.blockY,         1, desc.format, desc.size * 1, data);
334                 EXPECT_GL_NO_ERROR();
335                 glCompressedTexSubImage3D(target, 1, desc.blockX, 0,           1, desc.blockX / 2,     desc.blockY * 3 / 2, 1, desc.format, desc.size * 2, data);
336                 EXPECT_GL_NO_ERROR();
337                 glCompressedTexSubImage3D(target, 1, 0,           desc.blockY, 1, desc.blockX,         desc.blockY / 2,     1, desc.format, desc.size * 1, data);
338                 EXPECT_GL_NO_ERROR();
339                 glCompressedTexSubImage3D(target, 1, 0,           desc.blockY, 1, desc.blockX * 3 / 2, desc.blockY / 2,     1, desc.format, desc.size * 2, data);
340                 EXPECT_GL_NO_ERROR();
341                 glCompressedTexSubImage3D(target, 1, desc.blockX, desc.blockY, 1, desc.blockX / 2,     desc.blockY / 2,     1, desc.format, desc.size * 1, data);
342                 EXPECT_GL_NO_ERROR();
343 
344                 glCompressedTexSubImage3D(target, 1, desc.blockX, 0,           0, desc.blockX / 2,     desc.blockY,         2, desc.format, desc.size * 2, data);
345                 EXPECT_GL_NO_ERROR();
346                 glCompressedTexSubImage3D(target, 1, desc.blockX, 0,           0, desc.blockX / 2,     desc.blockY * 3 / 2, 2, desc.format, desc.size * 4, data);
347                 EXPECT_GL_NO_ERROR();
348                 glCompressedTexSubImage3D(target, 1, 0,           desc.blockY, 0, desc.blockX,         desc.blockY / 2,     2, desc.format, desc.size * 2, data);
349                 EXPECT_GL_NO_ERROR();
350                 glCompressedTexSubImage3D(target, 1, 0,           desc.blockY, 0, desc.blockX * 3 / 2, desc.blockY / 2,     2, desc.format, desc.size * 4, data);
351                 EXPECT_GL_NO_ERROR();
352                 glCompressedTexSubImage3D(target, 1, desc.blockX, desc.blockY, 0, desc.blockX / 2,     desc.blockY / 2,     2, desc.format, desc.size * 2, data);
353                 EXPECT_GL_NO_ERROR();
354                 // clang-format on
355             }
356             else
357             {
358                 glCompressedTexImage3D(target, 1, desc.format, newW / 2, newH / 2, 1, 0,
359                                        desc.size * 4, nullptr);
360                 EXPECT_GL_NO_ERROR();
361 
362                 // clang-format off
363                 glCompressedTexSubImage3D(target, 1, desc.blockX, 0,           0, desc.blockX / 2,     desc.blockY,         1, desc.format, desc.size * 1, data);
364                 EXPECT_GL_NO_ERROR();
365                 glCompressedTexSubImage3D(target, 1, desc.blockX, 0,           0, desc.blockX / 2,     desc.blockY * 3 / 2, 1, desc.format, desc.size * 2, data);
366                 EXPECT_GL_NO_ERROR();
367                 glCompressedTexSubImage3D(target, 1, 0,           desc.blockY, 0, desc.blockX,         desc.blockY / 2,     1, desc.format, desc.size * 1, data);
368                 EXPECT_GL_NO_ERROR();
369                 glCompressedTexSubImage3D(target, 1, 0,           desc.blockY, 0, desc.blockX * 3 / 2, desc.blockY / 2,     1, desc.format, desc.size * 2, data);
370                 EXPECT_GL_NO_ERROR();
371                 glCompressedTexSubImage3D(target, 1, desc.blockX, desc.blockY, 0, desc.blockX / 2,     desc.blockY / 2,     1, desc.format, desc.size * 1, data);
372                 EXPECT_GL_NO_ERROR();
373                 // clang-format on
374             }
375         }
376     }
377 
check2D(const bool compressedFormatEnabled)378     void check2D(const bool compressedFormatEnabled)
379     {
380         const FormatDesc desc = ::testing::get<1>(GetParam());
381 
382         {
383             GLTexture texture;
384             glBindTexture(GL_TEXTURE_2D, texture);
385 
386             // The semantic of this call is to take uncompressed data and compress it on-the-fly.
387             // This operation is not supported in OpenGL ES.
388             glTexImage2D(GL_TEXTURE_2D, 0, desc.format, desc.blockX, desc.blockY, 0, GL_RGB,
389                          GL_UNSIGNED_BYTE, nullptr);
390             EXPECT_GL_ERROR(GL_INVALID_VALUE);
391 
392             // Try compressed enum as format. Compressed texture extensions never allow this.
393             glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, desc.blockX, desc.blockY, 0, desc.format,
394                          GL_UNSIGNED_BYTE, nullptr);
395             EXPECT_GL_ERROR(GL_INVALID_ENUM);
396 
397             // The semantic of this call is to take pixel data from the current framebuffer
398             // and create a compressed texture from it on-the-fly. This operation is not supported
399             // in OpenGL ES.
400             glCopyTexImage2D(GL_TEXTURE_2D, 0, desc.format, 0, 0, desc.blockX, desc.blockY, 0);
401             EXPECT_GL_ERROR(GL_INVALID_OPERATION);
402 
403             glCompressedTexImage2D(GL_TEXTURE_2D, 0, desc.format, desc.blockX, desc.blockY, 0,
404                                    desc.size, nullptr);
405             if (compressedFormatEnabled)
406             {
407                 int numX = 2;
408                 if (desc.isPVRTC1())
409                 {
410                     if (mSquarePvrtc1 && desc.blockX == 8)
411                     {
412                         EXPECT_GL_ERROR(GL_INVALID_OPERATION);
413                         numX = 1;
414                     }
415                     else
416                     {
417                         // PVRTC1 formats require data size for at least 2x2 blocks.
418                         EXPECT_GL_ERROR(GL_INVALID_VALUE);
419                     }
420                 }
421                 else
422                 {
423                     EXPECT_GL_NO_ERROR();
424                 }
425 
426                 // Create a texture with more than one block to test partial updates
427                 glCompressedTexImage2D(GL_TEXTURE_2D, 0, desc.format, desc.blockX * numX,
428                                        desc.blockY * 2, 0, desc.size * 4, nullptr);
429                 EXPECT_GL_NO_ERROR();
430 
431                 checkSubImage2D(desc, numX);
432             }
433             else
434             {
435                 EXPECT_GL_ERROR(GL_INVALID_ENUM);
436             }
437         }
438 
439         if (getClientMajorVersion() >= 3)
440         {
441             GLTexture texture;
442             glBindTexture(GL_TEXTURE_2D, texture);
443 
444             glTexStorage2D(GL_TEXTURE_2D, 1, desc.format, desc.blockX * 2, desc.blockY * 2);
445             if (compressedFormatEnabled)
446             {
447                 int numX = 2;
448                 if (desc.isPVRTC1() && mSquarePvrtc1 && desc.blockX == 8)
449                 {
450                     EXPECT_GL_ERROR(GL_INVALID_OPERATION);
451                     numX = 1;
452                     glTexStorage2D(GL_TEXTURE_2D, 1, desc.format, desc.blockX, desc.blockY * 2);
453                 }
454                 EXPECT_GL_NO_ERROR();
455 
456                 checkSubImage2D(desc, numX);
457             }
458             else
459             {
460                 EXPECT_GL_ERROR(GL_INVALID_ENUM);
461             }
462         }
463 
464         if (EnsureGLExtensionEnabled("GL_EXT_texture_storage"))
465         {
466             GLTexture texture;
467             glBindTexture(GL_TEXTURE_2D, texture);
468 
469             glTexStorage2DEXT(GL_TEXTURE_2D, 1, desc.format, desc.blockX * 2, desc.blockY * 2);
470             if (compressedFormatEnabled)
471             {
472                 int numX = 2;
473                 if (desc.isPVRTC1() && mSquarePvrtc1 && desc.blockX == 8)
474                 {
475                     EXPECT_GL_ERROR(GL_INVALID_OPERATION);
476                     numX = 1;
477                     glTexStorage2DEXT(GL_TEXTURE_2D, 1, desc.format, desc.blockX, desc.blockY * 2);
478                 }
479                 EXPECT_GL_NO_ERROR();
480 
481                 checkSubImage2D(desc, numX);
482             }
483             else
484             {
485                 EXPECT_GL_ERROR(GL_INVALID_ENUM);
486             }
487         }
488     }
489 
check3D(GLenum target,const bool compressedFormatEnabled,const bool supportsTarget)490     void check3D(GLenum target, const bool compressedFormatEnabled, const bool supportsTarget)
491     {
492         const FormatDesc desc = ::testing::get<1>(GetParam());
493 
494         {
495             GLTexture texture;
496             glBindTexture(target, texture);
497 
498             // Try compressed enum as internalformat. The semantic of this call is to take
499             // uncompressed data and compress it on-the-fly. This operation is not supported in
500             // OpenGL ES.
501             glTexImage3D(target, 0, desc.format, desc.blockX, desc.blockX, 1, 0, GL_RGB,
502                          GL_UNSIGNED_BYTE, nullptr);
503             EXPECT_GL_ERROR(GL_INVALID_VALUE);
504 
505             // Try compressed enum as format. Compressed texture extensions never allow this.
506             glTexImage3D(target, 0, GL_RGB, desc.blockX, desc.blockX, 1, 0, desc.format,
507                          GL_UNSIGNED_BYTE, nullptr);
508             EXPECT_GL_ERROR(GL_INVALID_ENUM);
509 
510             glCompressedTexImage3D(target, 0, desc.format, desc.blockX * 2, desc.blockY * 2, 2, 0,
511                                    desc.size * 8, nullptr);
512             if (compressedFormatEnabled)
513             {
514                 if (supportsTarget)
515                 {
516                     EXPECT_GL_NO_ERROR();
517 
518                     checkSubImage3D(target, desc);
519                 }
520                 else
521                 {
522                     EXPECT_GL_ERROR(GL_INVALID_OPERATION);
523                 }
524             }
525             else
526             {
527                 EXPECT_GL_ERROR(GL_INVALID_ENUM);
528             }
529         }
530 
531         {
532             GLTexture texture;
533             glBindTexture(target, texture);
534 
535             glTexStorage3D(target, 1, desc.format, desc.blockX * 2, desc.blockY * 2, 2);
536             if (compressedFormatEnabled)
537             {
538                 if (supportsTarget)
539                 {
540                     EXPECT_GL_NO_ERROR();
541 
542                     checkSubImage3D(target, desc);
543                 }
544                 else
545                 {
546                     EXPECT_GL_ERROR(GL_INVALID_OPERATION);
547                 }
548             }
549             else
550             {
551                 EXPECT_GL_ERROR(GL_INVALID_ENUM);
552             }
553         }
554     }
555 
testSamplerSliced3D(GLenum target)556     void testSamplerSliced3D(GLenum target)
557     {
558         ASSERT(target == GL_TEXTURE_2D_ARRAY || target == GL_TEXTURE_3D);
559 
560         const FormatDesc desc = ::testing::get<1>(GetParam());
561         {
562             int width                                    = desc.blockX;
563             int height                                   = desc.blockY;
564             int depth                                    = 9;
565             static GLubyte red_RGBA_ASTC_block_data[144] = {
566                 252, 253, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255,
567                 252, 253, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255,
568                 252, 253, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255,
569                 252, 253, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255,
570                 252, 253, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255,
571                 252, 253, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255,
572                 252, 253, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255,
573                 252, 253, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255,
574                 252, 253, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255};
575 
576             GLTexture texID;
577             glActiveTexture(GL_TEXTURE0);
578             glBindTexture(target, texID);
579             EXPECT_GL_NO_ERROR();
580             glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
581             glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
582 
583             glCompressedTexImage3D(target, 0, desc.format, width, height, depth, 0,
584                                    desc.size * depth, red_RGBA_ASTC_block_data);
585             EXPECT_GL_NO_ERROR();
586 
587             float layer = 0.0f;
588             for (int i = 0; i < depth; i++)
589             {
590                 GLFramebuffer fb;
591                 glBindFramebuffer(GL_FRAMEBUFFER, fb);
592                 GLRenderbuffer rb;
593                 glBindRenderbuffer(GL_RENDERBUFFER, rb);
594                 glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, width, height);
595                 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
596                                           rb);
597                 EXPECT_GL_NO_ERROR();
598 
599                 glViewport(0, 0, width, height);
600                 glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
601                 glClear(GL_COLOR_BUFFER_BIT);
602 
603                 if (target == GL_TEXTURE_2D_ARRAY)
604                 {
605                     layer = i * 1.0f;
606                     draw2DArrayTexturedQuad(0.0f, 1.0f, false, layer);
607                 }
608                 else
609                 {
610                     layer = ((float)i + 0.5f) / (float)depth;
611                     draw3DTexturedQuad(0.0f, 1.0f, false, layer);
612                 }
613 
614                 std::vector<GLColor> pixels(width * height);
615                 glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
616                 for (int y = 0; y < height; y++)
617                 {
618                     for (int x = 0; x < width; x++)
619                     {
620                         const int curPos = y * width + x;
621                         EXPECT_COLOR_NEAR(GLColor::red, pixels[curPos], 2);
622                     }
623                 }
624             }
625         }
626     }
627 
test()628     void test()
629     {
630         // ETC2/EAC formats always pass validation on ES3 contexts but in some cases fail in drivers
631         // because their emulation is not implemented for OpenGL renderer.
632         // https://crbug.com/angleproject/6300
633         if (mAlwaysOnES3)
634         {
635             ANGLE_SKIP_TEST_IF(getClientMajorVersion() >= 3 &&
636                                !IsGLExtensionRequestable(mExtNames[0]));
637         }
638 
639         // It's not possible to disable ETC2/EAC support on ES 3.0.
640         const bool compressedFormatEnabled = mAlwaysOnES3 && getClientMajorVersion() >= 3;
641         check2D(compressedFormatEnabled);
642         if (getClientMajorVersion() >= 3)
643         {
644             check3D(GL_TEXTURE_2D_ARRAY, compressedFormatEnabled, mSupports2DArray);
645             check3D(GL_TEXTURE_3D, compressedFormatEnabled, mSupports3D && !mDisableTexture3D);
646         }
647 
648         for (const std::string &extName : mExtNames)
649         {
650             if (!extName.empty())
651             {
652                 if (IsGLExtensionRequestable(extName))
653                 {
654                     glRequestExtensionANGLE(extName.c_str());
655                 }
656                 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled(extName));
657             }
658         }
659 
660         // Repeat all checks after enabling the extensions.
661         check2D(true);
662         if (getClientMajorVersion() >= 3)
663         {
664             check3D(GL_TEXTURE_2D_ARRAY, true, mSupports2DArray);
665             check3D(GL_TEXTURE_3D, true, mSupports3D && !mDisableTexture3D);
666         }
667     }
668 
testSamplerASTCSliced3D()669     void testSamplerASTCSliced3D()
670     {
671         for (const std::string &extName : mExtNames)
672         {
673             if (!extName.empty())
674             {
675                 if (IsGLExtensionRequestable(extName))
676                 {
677                     glRequestExtensionANGLE(extName.c_str());
678                 }
679                 ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled(extName));
680             }
681         }
682 
683         if (getClientMajorVersion() >= 3)
684         {
685             testSamplerSliced3D(GL_TEXTURE_2D_ARRAY);
686             testSamplerSliced3D(GL_TEXTURE_3D);
687         }
688     }
689 
690   private:
691     bool mSquarePvrtc1     = false;
692     bool mDisableTexture3D = false;
693     const std::vector<std::string> mExtNames;
694     const bool mSupportsUpdates;
695     const bool mSupportsPartialUpdates;
696     const bool mSupports2DArray;
697     const bool mSupports3D;
698     const bool mAlwaysOnES3;
699 };
700 
701 template <char const *ext1,
702           char const *ext2,
703           bool supports_updates,
704           bool supports_partial_updates,
705           bool supports_2d_array,
706           bool supports_3d,
707           bool always_on_es3>
708 class _Test : public CompressedTextureFormatsTest
709 {
710   public:
_Test()711     _Test()
712         : CompressedTextureFormatsTest(ext1,
713                                        ext2,
714                                        supports_updates,
715                                        supports_partial_updates,
716                                        supports_2d_array,
717                                        supports_3d,
718                                        always_on_es3)
719     {}
720 };
721 
722 const char kDXT1[]     = "GL_EXT_texture_compression_dxt1";
723 const char kDXT3[]     = "GL_ANGLE_texture_compression_dxt3";
724 const char kDXT5[]     = "GL_ANGLE_texture_compression_dxt5";
725 const char kS3TCSRGB[] = "GL_EXT_texture_compression_s3tc_srgb";
726 const char kRGTC[]     = "GL_EXT_texture_compression_rgtc";
727 const char kBPTC[]     = "GL_EXT_texture_compression_bptc";
728 
729 const char kETC1[]    = "GL_OES_compressed_ETC1_RGB8_texture";
730 const char kETC1Sub[] = "GL_EXT_compressed_ETC1_RGB8_sub_texture";
731 
732 const char kEACR11U[]  = "GL_OES_compressed_EAC_R11_unsigned_texture";
733 const char kEACR11S[]  = "GL_OES_compressed_EAC_R11_signed_texture";
734 const char kEACRG11U[] = "GL_OES_compressed_EAC_RG11_unsigned_texture";
735 const char kEACRG11S[] = "GL_OES_compressed_EAC_RG11_signed_texture";
736 
737 const char kETC2RGB8[]       = "GL_OES_compressed_ETC2_RGB8_texture";
738 const char kETC2RGB8SRGB[]   = "GL_OES_compressed_ETC2_sRGB8_texture";
739 const char kETC2RGB8A1[]     = "GL_OES_compressed_ETC2_punchthroughA_RGBA8_texture";
740 const char kETC2RGB8A1SRGB[] = "GL_OES_compressed_ETC2_punchthroughA_sRGB8_alpha_texture";
741 const char kETC2RGBA8[]      = "GL_OES_compressed_ETC2_RGBA8_texture";
742 const char kETC2RGBA8SRGB[]  = "GL_OES_compressed_ETC2_sRGB8_alpha8_texture";
743 
744 const char kASTC[]         = "GL_KHR_texture_compression_astc_ldr";
745 const char kASTCSliced3D[] = "GL_KHR_texture_compression_astc_sliced_3d";
746 
747 const char kPVRTC1[]    = "GL_IMG_texture_compression_pvrtc";
748 const char kPVRTCSRGB[] = "GL_EXT_pvrtc_sRGB";
749 
750 const char kEmpty[] = "";
751 
752 // clang-format off
753 using CompressedTextureDXT1Test     = _Test<kDXT1,     kEmpty, true, true, true, false, false>;
754 using CompressedTextureDXT3Test     = _Test<kDXT3,     kEmpty, true, true, true, false, false>;
755 using CompressedTextureDXT5Test     = _Test<kDXT5,     kEmpty, true, true, true, false, false>;
756 using CompressedTextureS3TCSRGBTest = _Test<kS3TCSRGB, kEmpty, true, true, true, false, false>;
757 using CompressedTextureRGTCTest     = _Test<kRGTC,     kEmpty, true, true, true, false, false>;
758 using CompressedTextureBPTCTest     = _Test<kBPTC,     kEmpty, true, true, true, true,  false>;
759 
760 using CompressedTextureETC1Test    = _Test<kETC1, kEmpty,   false, false, false, false, false>;
761 using CompressedTextureETC1SubTest = _Test<kETC1, kETC1Sub, true,  true,  true,  false, false>;
762 
763 using CompressedTextureEACR11UTest  = _Test<kEACR11U,  kEmpty, true, true, true, false, true>;
764 using CompressedTextureEACR11STest  = _Test<kEACR11S,  kEmpty, true, true, true, false, true>;
765 using CompressedTextureEACRG11UTest = _Test<kEACRG11U, kEmpty, true, true, true, false, true>;
766 using CompressedTextureEACRG11STest = _Test<kEACRG11S, kEmpty, true, true, true, false, true>;
767 
768 using CompressedTextureETC2RGB8Test       = _Test<kETC2RGB8,       kEmpty, true, true, true, false, true>;
769 using CompressedTextureETC2RGB8SRGBTest   = _Test<kETC2RGB8SRGB,   kEmpty, true, true, true, false, true>;
770 using CompressedTextureETC2RGB8A1Test     = _Test<kETC2RGB8A1,     kEmpty, true, true, true, false, true>;
771 using CompressedTextureETC2RGB8A1SRGBTest = _Test<kETC2RGB8A1SRGB, kEmpty, true, true, true, false, true>;
772 using CompressedTextureETC2RGBA8Test      = _Test<kETC2RGBA8,      kEmpty, true, true, true, false, true>;
773 using CompressedTextureETC2RGBA8SRGBTest  = _Test<kETC2RGBA8SRGB,  kEmpty, true, true, true, false, true>;
774 
775 using CompressedTextureASTCTest         = _Test<kASTC, kEmpty,        true, true, true, false, false>;
776 using CompressedTextureASTCSliced3DTest = _Test<kASTC, kASTCSliced3D, true, true, true, true,  false>;
777 using CompressedTextureSamplerASTCSliced3DTest = _Test<kASTC, kASTCSliced3D, true, true, true, true,  false>;
778 
779 using CompressedTexturePVRTC1Test     = _Test<kPVRTC1, kEmpty,     true, false, false, false, false>;
780 using CompressedTexturePVRTC1SRGBTest = _Test<kPVRTC1, kPVRTCSRGB, true, false, false, false, false>;
781 // clang-format on
782 
PrintToStringParamName(const::testing::TestParamInfo<CompressedTextureTestParams> & info)783 std::string PrintToStringParamName(
784     const ::testing::TestParamInfo<CompressedTextureTestParams> &info)
785 {
786     std::string name = gl::GLinternalFormatToString(std::get<1>(info.param).format);
787     if (name.find("GL_") == 0)
788         name.erase(0, 3);
789     if (name.find("COMPRESSED_") == 0)
790         name.erase(0, 11);
791     for (std::string str : {"_EXT", "_IMG", "_KHR", "_OES"})
792     {
793         if (name.find(str) != std::string::npos)
794         {
795             name.erase(name.length() - 4, 4);
796             break;
797         }
798     }
799     std::stringstream nameStr;
800     nameStr << std::get<0>(info.param) << "__" << name;
801     return nameStr.str();
802 }
803 
804 static const FormatDesc kDXT1Formats[] = {{GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 8},
805                                           {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 8}};
806 
807 static const FormatDesc kDXT3Formats[] = {{GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 4, 4, 16}};
808 
809 static const FormatDesc kDXT5Formats[] = {{GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 4, 4, 16}};
810 
811 static const FormatDesc kS3TCSRGBFormats[] = {{GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 8},
812                                               {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 8},
813                                               {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 16},
814                                               {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 16}};
815 
816 static const FormatDesc kRGTCFormats[] = {{GL_COMPRESSED_RED_RGTC1_EXT, 4, 4, 8},
817                                           {GL_COMPRESSED_SIGNED_RED_RGTC1_EXT, 4, 4, 8},
818                                           {GL_COMPRESSED_RED_GREEN_RGTC2_EXT, 4, 4, 16},
819                                           {GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, 4, 4, 16}};
820 
821 static const FormatDesc kBPTCFormats[] = {{GL_COMPRESSED_RGBA_BPTC_UNORM_EXT, 4, 4, 16},
822                                           {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, 4, 4, 16},
823                                           {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, 4, 4, 16},
824                                           {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, 4, 4, 16}};
825 
826 static const FormatDesc kETC1Formats[] = {{GL_ETC1_RGB8_OES, 4, 4, 8}};
827 
828 // clang-format off
829 static const FormatDesc kEACR11UFormats[]        = {{GL_COMPRESSED_R11_EAC, 4, 4, 8}};
830 static const FormatDesc kEACR11SFormats[]        = {{GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 8}};
831 static const FormatDesc kEACRG11UFormats[]       = {{GL_COMPRESSED_RG11_EAC, 4, 4, 16}};
832 static const FormatDesc kEACRG11SFormats[]       = {{GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 16}};
833 static const FormatDesc kETC2RGB8Formats[]       = {{GL_COMPRESSED_RGB8_ETC2, 4, 4, 8}};
834 static const FormatDesc kETC2RGB8SRGBFormats[]   = {{GL_COMPRESSED_SRGB8_ETC2, 4, 4, 8}};
835 static const FormatDesc kETC2RGB8A1Formats[]     = {{GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 8}};
836 static const FormatDesc kETC2RGB8A1SRGBFormats[] = {{GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 8}};
837 static const FormatDesc kETC2RGBA8Formats[]      = {{GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 16}};
838 static const FormatDesc kETC2RGBA8SRGBFormats[]  = {{GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 4, 4, 16}};
839 // clang-format on
840 
841 static const FormatDesc kASTCFormats[] = {{GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 4, 4, 16},
842                                           {GL_COMPRESSED_RGBA_ASTC_5x4_KHR, 5, 4, 16},
843                                           {GL_COMPRESSED_RGBA_ASTC_5x5_KHR, 5, 5, 16},
844                                           {GL_COMPRESSED_RGBA_ASTC_6x5_KHR, 6, 5, 16},
845                                           {GL_COMPRESSED_RGBA_ASTC_6x6_KHR, 6, 6, 16},
846                                           {GL_COMPRESSED_RGBA_ASTC_8x5_KHR, 8, 5, 16},
847                                           {GL_COMPRESSED_RGBA_ASTC_8x6_KHR, 8, 6, 16},
848                                           {GL_COMPRESSED_RGBA_ASTC_8x8_KHR, 8, 8, 16},
849                                           {GL_COMPRESSED_RGBA_ASTC_10x5_KHR, 10, 5, 16},
850                                           {GL_COMPRESSED_RGBA_ASTC_10x6_KHR, 10, 6, 16},
851                                           {GL_COMPRESSED_RGBA_ASTC_10x8_KHR, 10, 8, 16},
852                                           {GL_COMPRESSED_RGBA_ASTC_10x10_KHR, 10, 10, 16},
853                                           {GL_COMPRESSED_RGBA_ASTC_12x10_KHR, 12, 10, 16},
854                                           {GL_COMPRESSED_RGBA_ASTC_12x12_KHR, 12, 12, 16},
855                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, 4, 4, 16},
856                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, 5, 4, 16},
857                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, 5, 5, 16},
858                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, 6, 5, 16},
859                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, 6, 6, 16},
860                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, 8, 5, 16},
861                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, 8, 6, 16},
862                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, 8, 8, 16},
863                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, 10, 5, 16},
864                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, 10, 6, 16},
865                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, 10, 8, 16},
866                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 10, 10, 16},
867                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 12, 10, 16},
868                                           {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 12, 12, 16}};
869 
870 static const FormatDesc kPVRTC1Formats[] = {{GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 4, 4, 8},
871                                             {GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG, 8, 4, 8},
872                                             {GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, 4, 4, 8},
873                                             {GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG, 8, 4, 8}};
874 
875 static const FormatDesc kPVRTC1SRGBFormats[] = {
876     {GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, 8, 4, 8},
877     {GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, 4, 4, 8},
878     {GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, 8, 4, 8},
879     {GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, 4, 4, 8}};
880 
881 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureDXT1Test,
882                                  PrintToStringParamName,
883                                  testing::ValuesIn(kDXT1Formats),
884                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
885                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
886 
887 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureDXT3Test,
888                                  PrintToStringParamName,
889                                  testing::ValuesIn(kDXT3Formats),
890                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
891                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
892 
893 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureDXT5Test,
894                                  PrintToStringParamName,
895                                  testing::ValuesIn(kDXT5Formats),
896                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
897                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
898 
899 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureS3TCSRGBTest,
900                                  PrintToStringParamName,
901                                  testing::ValuesIn(kS3TCSRGBFormats),
902                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
903                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
904 
905 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureRGTCTest,
906                                  PrintToStringParamName,
907                                  testing::ValuesIn(kRGTCFormats),
908                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
909                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
910 
911 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureBPTCTest,
912                                  PrintToStringParamName,
913                                  testing::ValuesIn(kBPTCFormats),
914                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
915                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
916 
917 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureETC1Test,
918                                  PrintToStringParamName,
919                                  testing::ValuesIn(kETC1Formats),
920                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
921                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
922 
923 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureETC1SubTest,
924                                  PrintToStringParamName,
925                                  testing::ValuesIn(kETC1Formats),
926                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
927                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
928 
929 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureEACR11UTest,
930                                  PrintToStringParamName,
931                                  testing::ValuesIn(kEACR11UFormats),
932                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
933                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
934 
935 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureEACR11STest,
936                                  PrintToStringParamName,
937                                  testing::ValuesIn(kEACR11SFormats),
938                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
939                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
940 
941 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureEACRG11UTest,
942                                  PrintToStringParamName,
943                                  testing::ValuesIn(kEACRG11UFormats),
944                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
945                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
946 
947 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureEACRG11STest,
948                                  PrintToStringParamName,
949                                  testing::ValuesIn(kEACRG11SFormats),
950                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
951                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
952 
953 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureETC2RGB8Test,
954                                  PrintToStringParamName,
955                                  testing::ValuesIn(kETC2RGB8Formats),
956                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
957                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
958 
959 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureETC2RGB8SRGBTest,
960                                  PrintToStringParamName,
961                                  testing::ValuesIn(kETC2RGB8SRGBFormats),
962                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
963                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
964 
965 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureETC2RGB8A1Test,
966                                  PrintToStringParamName,
967                                  testing::ValuesIn(kETC2RGB8A1Formats),
968                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
969                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
970 
971 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureETC2RGB8A1SRGBTest,
972                                  PrintToStringParamName,
973                                  testing::ValuesIn(kETC2RGB8A1SRGBFormats),
974                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
975                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
976 
977 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureETC2RGBA8Test,
978                                  PrintToStringParamName,
979                                  testing::ValuesIn(kETC2RGBA8Formats),
980                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
981                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
982 
983 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureETC2RGBA8SRGBTest,
984                                  PrintToStringParamName,
985                                  testing::ValuesIn(kETC2RGBA8SRGBFormats),
986                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
987                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
988 
989 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureASTCTest,
990                                  PrintToStringParamName,
991                                  testing::ValuesIn(kASTCFormats),
992                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
993                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
994 
995 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureASTCSliced3DTest,
996                                  PrintToStringParamName,
997                                  testing::ValuesIn(kASTCFormats),
998                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
999                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
1000 
1001 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTextureSamplerASTCSliced3DTest,
1002                                  PrintToStringParamName,
1003                                  testing::ValuesIn(kASTCFormats),
1004                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
1005                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
1006 
1007 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTexturePVRTC1Test,
1008                                  PrintToStringParamName,
1009                                  testing::ValuesIn(kPVRTC1Formats),
1010                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
1011                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
1012 
1013 ANGLE_INSTANTIATE_TEST_COMBINE_1(CompressedTexturePVRTC1SRGBTest,
1014                                  PrintToStringParamName,
1015                                  testing::ValuesIn(kPVRTC1SRGBFormats),
1016                                  ANGLE_ALL_TEST_PLATFORMS_ES2,
1017                                  ANGLE_ALL_TEST_PLATFORMS_ES3);
1018 
1019 // clang-format off
TEST_P(CompressedTextureDXT1Test,Test)1020 TEST_P(CompressedTextureDXT1Test,     Test) { test(); }
TEST_P(CompressedTextureDXT3Test,Test)1021 TEST_P(CompressedTextureDXT3Test,     Test) { test(); }
TEST_P(CompressedTextureDXT5Test,Test)1022 TEST_P(CompressedTextureDXT5Test,     Test) { test(); }
TEST_P(CompressedTextureS3TCSRGBTest,Test)1023 TEST_P(CompressedTextureS3TCSRGBTest, Test) { test(); }
TEST_P(CompressedTextureRGTCTest,Test)1024 TEST_P(CompressedTextureRGTCTest,     Test) { test(); }
TEST_P(CompressedTextureBPTCTest,Test)1025 TEST_P(CompressedTextureBPTCTest,     Test) { test(); }
1026 
TEST_P(CompressedTextureETC1Test,Test)1027 TEST_P(CompressedTextureETC1Test,    Test) { test(); }
TEST_P(CompressedTextureETC1SubTest,Test)1028 TEST_P(CompressedTextureETC1SubTest, Test) { test(); }
1029 
TEST_P(CompressedTextureEACR11UTest,Test)1030 TEST_P(CompressedTextureEACR11UTest,  Test) { test(); }
TEST_P(CompressedTextureEACR11STest,Test)1031 TEST_P(CompressedTextureEACR11STest,  Test) { test(); }
TEST_P(CompressedTextureEACRG11UTest,Test)1032 TEST_P(CompressedTextureEACRG11UTest, Test) { test(); }
TEST_P(CompressedTextureEACRG11STest,Test)1033 TEST_P(CompressedTextureEACRG11STest, Test) { test(); }
1034 
TEST_P(CompressedTextureETC2RGB8Test,Test)1035 TEST_P(CompressedTextureETC2RGB8Test,       Test) { test(); }
TEST_P(CompressedTextureETC2RGB8SRGBTest,Test)1036 TEST_P(CompressedTextureETC2RGB8SRGBTest,   Test) { test(); }
TEST_P(CompressedTextureETC2RGB8A1Test,Test)1037 TEST_P(CompressedTextureETC2RGB8A1Test,     Test) { test(); }
TEST_P(CompressedTextureETC2RGB8A1SRGBTest,Test)1038 TEST_P(CompressedTextureETC2RGB8A1SRGBTest, Test) { test(); }
TEST_P(CompressedTextureETC2RGBA8Test,Test)1039 TEST_P(CompressedTextureETC2RGBA8Test,      Test) { test(); }
TEST_P(CompressedTextureETC2RGBA8SRGBTest,Test)1040 TEST_P(CompressedTextureETC2RGBA8SRGBTest,  Test) { test(); }
1041 
TEST_P(CompressedTextureASTCTest,Test)1042 TEST_P(CompressedTextureASTCTest,         Test) { test(); }
TEST_P(CompressedTextureASTCSliced3DTest,Test)1043 TEST_P(CompressedTextureASTCSliced3DTest, Test) { test(); }
1044 
1045 // Check that texture sampling works correctly
TEST_P(CompressedTextureSamplerASTCSliced3DTest,Test)1046 TEST_P(CompressedTextureSamplerASTCSliced3DTest, Test) { testSamplerASTCSliced3D(); }
1047 
TEST_P(CompressedTexturePVRTC1Test,Test)1048 TEST_P(CompressedTexturePVRTC1Test,     Test) { test(); }
TEST_P(CompressedTexturePVRTC1SRGBTest,Test)1049 TEST_P(CompressedTexturePVRTC1SRGBTest, Test) { test(); }
1050 // clang-format on
1051 }  // namespace
1052