2 * Copyright © 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #include "piglit-util-gl.h"
27 PIGLIT_GL_TEST_CONFIG_BEGIN
29 config
.supports_gl_compat_version
= 11;
30 config
.supports_gl_es_version
= 20;
31 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
33 PIGLIT_GL_TEST_CONFIG_END
35 static const GLenum cube_map_face_targets
[] = {
36 GL_TEXTURE_CUBE_MAP_POSITIVE_X
,
37 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
,
38 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
,
39 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
,
40 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
,
41 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
44 static const GLenum good_compressed_tex_3d_targets
[] = {
46 GL_TEXTURE_CUBE_MAP_ARRAY_EXT
,
50 #define REQUIRE_ERROR(expected_error) \
52 if (!piglit_check_gl_error(expected_error)) \
53 piglit_report_result(PIGLIT_FAIL); \
58 have_tex_storage_support()
60 #if defined (PIGLIT_USE_OPENGL)
61 return piglit_get_gl_version() >= 42 ||
62 piglit_is_extension_supported("GL_ARB_texture_storage");
64 return piglit_get_gl_version() >= 30 ||
65 piglit_is_extension_supported("GL_EXT_texture_storage");
71 have_cube_map_array_support()
73 #if defined (PIGLIT_USE_OPENGL)
74 return piglit_get_gl_version() >= 40 ||
75 piglit_is_extension_supported("GL_ARB_texture_cube_map_array");
77 return piglit_get_gl_version() >= 32 ||
78 piglit_is_extension_supported("GL_EXT_texture_cube_map_array");
83 have_gen_mipmap_support()
85 #if defined (PIGLIT_USE_OPENGL)
86 return piglit_get_gl_version() >= 30;
88 return piglit_get_gl_version() >= 20;
94 * The KHR_texture_compression_astc_ldr spec says:
95 * * An INVALID_OPERATION error is generated by CompressedTexImage3D if
96 * <internalformat> is one of the the formats in table 8.19 and <target>
97 * is not TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY, or TEXTURE_3D.
99 * * An INVALID_OPERATION error is generated by CompressedTexImage3D if
100 * <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the "Cube Map Array"
101 * column of table 8.19 is *not* checked, or if <internalformat> is
102 * TEXTURE_3D and the "3D Tex." column of table 8.19 is *not* checked"
105 * * Since this extension only increases the allowed targets, the
106 * existing errors are assumed to be already handled, and the allowed
107 * targets are tested to be free of errors.
109 * * Since all ASTC formats have the "Cube Map Array" column checked,
110 * test that no error is generated from calling CompressedTexImage3D with
111 * the TEXTURE_CUBE_MAP_ARRAY target.
114 void test_compressed_teximg_3d(int fi
, bool have_cube_map_ext
,
115 bool have_hdr_or_sliced_3d
)
119 char fake_tex_data
[6*16];
121 for (j
= 0; j
< ARRAY_SIZE(good_compressed_tex_3d_targets
); ++j
) {
123 /* Skip the cube_map target if there's no support */
124 if ((good_compressed_tex_3d_targets
[j
] ==
125 GL_TEXTURE_CUBE_MAP_ARRAY_EXT
) && !have_cube_map_ext
)
128 /* Run the command */
129 glGenTextures(1, &tex3D
);
130 glBindTexture(good_compressed_tex_3d_targets
[j
], tex3D
);
131 glCompressedTexImage3D(good_compressed_tex_3d_targets
[j
], 0,
132 formats
[fi
].fmt
, 4, 4, 6, 0, 6*formats
[fi
].bb
, fake_tex_data
);
134 /* Test expected GL errors */
135 if (good_compressed_tex_3d_targets
[j
] == GL_TEXTURE_3D
136 && !have_hdr_or_sliced_3d
) {
137 REQUIRE_ERROR(GL_INVALID_OPERATION
);
139 REQUIRE_ERROR(GL_NO_ERROR
);
142 glDeleteTextures(1, &tex3D
);
147 * The KHR_texture_compression_astc_ldr spec says:
148 * "An INVALID_VALUE error is generated by
150 * * CompressedTexImage2D if <target> is
151 * one of the cube map face targets from table 8.21, and
152 * * CompressedTexImage3D if <target> is TEXTURE_CUBE_MAP_ARRAY,
154 * and <width> and <height> are not equal."
156 void test_non_square_img(int fi
, bool have_hdr
)
159 char fake_tex_data
[6*16];
162 glGenTextures(1, &cube_tex
);
163 glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY_EXT
, cube_tex
);
165 /* Test CompressedTexImage2D */
166 for (j
= 0; j
< ARRAY_SIZE(cube_map_face_targets
); ++j
) {
167 glCompressedTexImage2D(cube_map_face_targets
[j
], 0,
168 formats
[fi
].fmt
, 4, 3, 0,
169 formats
[fi
].bb
, fake_tex_data
);
170 REQUIRE_ERROR(GL_INVALID_VALUE
);
173 /* Test CompressedTexImage3D */
174 glCompressedTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY_EXT
, 0,
175 formats
[fi
].fmt
, 4, 3, 6, 0, 6*formats
[fi
].bb
, fake_tex_data
);
176 REQUIRE_ERROR(GL_INVALID_VALUE
);
178 glDeleteTextures(1, &cube_tex
);
182 int get_expected_size(int width
, int height
, int bw
, int bh
, int bb
)
184 int nbw
= (width
+ bw
- 1) / bw
;
185 int nbh
= (height
+ bh
- 1) / bh
;
186 return nbw
* nbh
* bb
;
191 * The KHR_texture_compression_astc_ldr spec says:
192 * * "An INVALID_OPERATION error is generated if format is one of the formats
193 * in table 8.19 and any of the following conditions occurs. The block
194 * width and height refer to the values in the corresponding column of the
197 * * <width> is not a multiple of the format's block width, and <width> +
198 * <xoffset> is not equal to the value of TEXTURE_WIDTH.
199 * * height is not a multiple of the format's block height, and <height>
200 * + <yoffset> is not equal to the value of TEXTURE_HEIGHT.
201 * * <xoffset> or <yoffset> is not a multiple of the block width or
202 * height, respectively."
206 * ASTC texture formats are supported by immutable-format textures only if
207 * such textures are supported by the underlying implementation (e.g.
208 * OpenGL 4.1 or later, OpenGL ES 3.0 or later, or earlier versions
209 * supporting the GL_EXT_texture_storage extension). Otherwise, remove all
210 * references to the Tex*Storage* commands from this specification.
212 void test_sub_img(int fi
)
215 char fake_tex_data
[4*16];
218 int expected_size_good
= get_expected_size(4, 4,
220 formats
[fi
].bh
, formats
[fi
].bb
);
221 int expected_size_bad
= get_expected_size(width
, height
,
223 formats
[fi
].bh
, formats
[fi
].bb
);
225 /* Ensure enough space has been allocated */
226 assert(expected_size_bad
<= sizeof(fake_tex_data
));
227 assert(expected_size_good
<= sizeof(fake_tex_data
));
229 /* Allocate enough to hold the larger case */
230 glGenTextures(1, &tex
);
231 glBindTexture(GL_TEXTURE_2D
, tex
);
232 glTexStorage2D(GL_TEXTURE_2D
, 1, formats
[fi
].fmt
, 14, 14);
233 REQUIRE_ERROR(GL_NO_ERROR
);
235 /* Check for No Error */
236 glCompressedTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0,
237 formats
[fi
].bw
, formats
[fi
].bh
,
238 formats
[fi
].fmt
, expected_size_good
, fake_tex_data
);
239 REQUIRE_ERROR(GL_NO_ERROR
);
241 /* Check for expected Error */
242 glCompressedTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, width
, height
,
243 formats
[fi
].fmt
, expected_size_bad
, fake_tex_data
);
244 REQUIRE_ERROR(GL_INVALID_OPERATION
);
246 glDeleteTextures(1, &tex
);
248 /* Check for expected Error */
249 glGenTextures(1, &tex
);
250 glBindTexture(GL_TEXTURE_3D
, tex
);
251 glTexStorage3D(GL_TEXTURE_3D
, 1, formats
[fi
].fmt
, 14, 14, 1);
252 glCompressedTexImage3D(GL_TEXTURE_3D
, 0, formats
[fi
].fmt
,
253 7, 7, 1, 0, expected_size_bad
, fake_tex_data
);
254 REQUIRE_ERROR(GL_INVALID_OPERATION
);
255 glDeleteTextures(1, &tex
);
257 /* XXX : Test the methods exposed by GL_EXT_texture_storage
258 * once support is added in Mesa.
263 * The KHR_texture_compression_astc_ldr spec says:
264 * [...] the ASTC format specifiers will not be added to
265 * Table 3.14, and thus will not be accepted by the TexImage*D
266 * functions, and will not be returned by the (already deprecated)
267 * COMPRESSED_TEXTURE_FORMATS query.
270 * The deprecated query is handled by:
271 * tests/spec/arb_texture_compression/invalid-formats.c
272 * In TexImage*D, the format should be automatically
273 * converted to the base internal format of GL_RGBA.
275 void test_tex_img(int fi
, bool have_mipmap
)
278 char fake_tex_data
[16];
280 glGenTextures(1, &tex
);
281 glBindTexture(GL_TEXTURE_2D
, tex
);
283 /* Since TexImage*D must fail, then the corresponding TexSubImage
284 * calls must fail as well.
286 glCompressedTexImage2D(GL_TEXTURE_2D
, 0,
287 formats
[fi
].fmt
, 4, 4, 0, formats
[fi
].bb
, fake_tex_data
);
288 REQUIRE_ERROR(GL_NO_ERROR
);
290 /* Check for expected error from Tex*Image*D family of functions */
291 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0,
292 4, 4, GL_RGBA
, GL_UNSIGNED_BYTE
, fake_tex_data
);
293 REQUIRE_ERROR(GL_INVALID_OPERATION
);
295 glTexImage2D(GL_TEXTURE_2D
, 0,
296 formats
[fi
].fmt
, 4, 4, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
297 REQUIRE_ERROR(GL_INVALID_OPERATION
);
299 glCopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 4, 4);
300 REQUIRE_ERROR(GL_INVALID_OPERATION
);
302 glCopyTexImage2D(GL_TEXTURE_2D
, 0, formats
[fi
].fmt
, 0, 0, 4, 4, 0);
303 REQUIRE_ERROR(GL_INVALID_OPERATION
);
305 /* Check for expected error from the online compression resulting from
306 * calling GenerateMipmap.
309 glGenerateMipmap(GL_TEXTURE_2D
);
310 REQUIRE_ERROR(GL_INVALID_OPERATION
);
313 glDeleteTextures(1, &tex
);
318 piglit_init(int argc
, char **argv
)
320 piglit_require_extension("GL_KHR_texture_compression_astc_ldr");
327 bool have_cube_map_ext
= have_cube_map_array_support();
328 bool have_tex_stor_ext
= have_tex_storage_support();
329 bool have_gen_mipmap
= have_gen_mipmap_support();
330 bool have_hdr
= piglit_is_extension_supported(
331 "GL_KHR_texture_compression_astc_hdr");
332 bool have_hdr_or_sliced_3d
= have_hdr
||
333 piglit_is_extension_supported(
334 "GL_KHR_texture_compression_astc_sliced_3d");
336 for (i
= 0; i
< ARRAY_SIZE(formats
); i
++) {
337 if (have_cube_map_ext
)
338 test_non_square_img(i
, have_hdr
);
339 if (have_tex_stor_ext
)
341 test_compressed_teximg_3d(i
, have_cube_map_ext
,
342 have_hdr_or_sliced_3d
);
343 test_tex_img(i
, have_gen_mipmap
);
346 piglit_report_result(PIGLIT_PASS
);