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.
26 * \brief Test texturing from an ASTC miptree of a real image.
28 * This test is an adaptation of the oes_compressed_etc1_rgb8_textures test.
30 * The files under compressed/2D contain full miptrees, in the
31 * GL_*_ASTC_* formats, of a 2D texture of waffles and fruit [1]. The base
32 * level size was shrunken to 160x106 pixels. The files under the decompressed/2D
33 * directory contain the same miptree in GL_RGBA format. Each miplevel was
34 * obtained by decompressing the corresponding ASTC texture with astcenc [2].
36 * This test draws miplevels of the compressed textures in a space-efficient
37 * manner It does the same when drawing the decompressed texture on the right.
38 * Each miplevel of both images are compared for equality after being drawn.
40 * [1] The reference image is located at http://people.freedesktop.org/~chadversary/permalink/2012-07-09/1574cff2-d091-4421-a3cf-b56c7943d060.jpg.
41 * [2] astcenc is the reference ASTC compression tool, available at http://malideveloper.arm.com/develop-for-mali/tools/software-tools/astc-evaluation-codec/.
44 #include "piglit-util-gl.h"
45 #include "piglit_ktx.h"
48 #define LEVEL0_WIDTH 160
49 #define LEVEL0_HEIGHT 106
51 #define NUM_VERTICES 4
55 static struct piglit_gl_test_config
*piglit_config
;
67 test_miptrees(void* input_type
);
69 static enum test_type ldr_test
= TEST_TYPE_LDR
;
70 static enum test_type hdr_test
= TEST_TYPE_HDR
;
71 static enum test_type srgb_test
= TEST_TYPE_SRGB
;
72 static enum test_type srgb_fp_test
= TEST_TYPE_SRGB_FP
;
73 static enum test_type srgb_skip_test
= TEST_TYPE_SRGB_SD
;
74 static const struct piglit_subtest subtests
[] = {
94 "sRGB decode full precision",
108 PIGLIT_GL_TEST_CONFIG_BEGIN
110 piglit_config
= &config
;
111 config
.supports_gl_compat_version
= 11;
112 config
.supports_gl_es_version
= 20;
114 config
.window_width
= 2 * LEVEL0_WIDTH
;
115 config
.window_height
= LEVEL0_HEIGHT
+ (LEVEL0_HEIGHT
>> 1);
116 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
118 config
.subtests
= subtests
;
120 PIGLIT_GL_TEST_CONFIG_END
124 * The \a filename is relative to the current test's source directory.
126 * A new texture is created and returned in \a tex_name.
129 load_texture(const char *dir1
, const char *dir2
,
130 const char *block_dim_str
, GLuint
*tex_name
)
132 struct piglit_ktx
*ktx
;
133 const struct piglit_ktx_info
*info
;
138 /* Generate filename for compressed texture */
139 snprintf(cur_file
, sizeof(cur_file
), "waffles-%s.ktx",
142 piglit_join_paths(filepath
, sizeof(filepath
), 7,
146 "khr_texture_compression_astc",
151 ktx
= piglit_ktx_read_file(filepath
);
153 piglit_report_result(PIGLIT_FAIL
);
155 info
= piglit_ktx_get_info(ktx
);
156 assert(info
->num_miplevels
== NUM_LEVELS
);
157 assert(info
->target
== GL_TEXTURE_2D
);
158 assert(info
->pixel_width
== LEVEL0_WIDTH
);
159 assert(info
->pixel_height
== LEVEL0_HEIGHT
);
162 ok
= piglit_ktx_load_texture(ktx
, tex_name
, NULL
);
164 piglit_report_result(PIGLIT_FAIL
);
166 piglit_ktx_destroy(ktx
);
169 /** Compares the compressed texture against the decompressed texture */
170 bool draw_compare_levels(bool check_error
, bool srgb_skip_decode
,
171 GLint level_pixel_size_loc
, GLint pixel_offset_loc
,
172 GLuint compressed_tex
, GLuint decompressed_tex
)
174 /* Fully-saturated magenta */
175 static const float error_color
[4] = {1.0, 0.0, 1.0, 1.0};
182 for (; level
< NUM_LEVELS
; ++level
) {
183 int w
= LEVEL0_WIDTH
>> level
;
184 int h
= LEVEL0_HEIGHT
>> level
;
185 glUniform2f(level_pixel_size_loc
, (float) w
, (float) h
);
188 /* Draw miplevel of compressed texture. */
189 glBindTexture(GL_TEXTURE_2D
, compressed_tex
);
190 if (srgb_skip_decode
)
191 glTexParameteri(GL_TEXTURE_2D
,
192 GL_TEXTURE_SRGB_DECODE_EXT
,
194 glUniform2f(pixel_offset_loc
, x
, y
);
195 glDrawArrays(GL_TRIANGLE_FAN
, 0, NUM_VERTICES
);
197 /* Draw miplevel of decompressed texture. */
199 glBindTexture(GL_TEXTURE_2D
, decompressed_tex
);
200 if (srgb_skip_decode
)
201 glTexParameteri(GL_TEXTURE_2D
,
202 GL_TEXTURE_SRGB_DECODE_EXT
,
204 glUniform2f(pixel_offset_loc
, LEVEL0_WIDTH
+ x
, y
);
205 glDrawArrays(GL_TRIANGLE_FAN
, 0, NUM_VERTICES
);
208 /* Check the textures (or error-colors) for equivalence. */
211 pass
= piglit_probe_rect_rgba(x
, y
, w
, h
,
214 pass
= piglit_probe_rects_equal(x
, y
,
220 piglit_loge("Miplevel %d", level
);
223 /* Update the next miplevel arrangement */
230 /* Delete bound textures */
231 glDeleteTextures(1, &compressed_tex
);
232 glDeleteTextures(1, &decompressed_tex
);
234 piglit_present_results();
239 test_miptrees(void* input_type
)
241 const enum test_type subtest
= *(enum test_type
*) input_type
;
242 const bool is_srgb_test
= subtest
== TEST_TYPE_SRGB
;
243 const bool is_srgb_skip_decode_test
= subtest
== TEST_TYPE_SRGB_SD
;
244 const bool is_hdr_test
= subtest
== TEST_TYPE_HDR
;
246 static const char * tests
[5] = {"hdr", "ldrl", "ldrs", "ldrs", "ldrs"};
247 static const char * block_dim_str
[14] = {
264 GLint pixel_offset_loc
= glGetUniformLocation(prog
, "pixel_offset");
265 GLint level_pixel_size_loc
= glGetUniformLocation(prog
,
268 if (is_srgb_skip_decode_test
)
269 piglit_require_extension("GL_EXT_texture_sRGB_decode");
271 /* Check for error color if an LDR-only sys reading an HDR
272 * texture. No need to draw a reference mipmap in this case.
274 const bool has_hdr
= piglit_is_extension_supported(
275 "GL_KHR_texture_compression_astc_hdr");
276 const bool check_error
= is_hdr_test
&& !has_hdr
;
280 /* Loosen up the tolerance for sRGB tests. This will allow testing
281 * sRGB formats which have known precision issues in void extent
282 * blocks. See khronos bug#11294 for details.
284 piglit_set_tolerance_for_bits(7, 7, 7, 7);
286 piglit_set_tolerance_for_bits(8, 8, 8, 8);
288 for (block_dims
= 0; block_dims
< ARRAY_SIZE(block_dim_str
); ++block_dims
) {
290 /* Texture objects. */
291 GLuint tex_compressed
= 0;
292 GLuint tex_decompressed
= 0;
294 /* Load texture for current submode and block size */
295 load_texture("compressed/2D", tests
[subtest
],
296 block_dim_str
[block_dims
],
299 load_texture("decompressed/2D", tests
[subtest
],
300 block_dim_str
[block_dims
],
304 /* Draw and compare each level of the two textures */
305 glClear(GL_COLOR_BUFFER_BIT
);
306 if (!draw_compare_levels(check_error
, is_srgb_skip_decode_test
,
307 level_pixel_size_loc
,
311 piglit_loge("Mode %s Block %s.",
313 block_dim_str
[block_dims
]);
321 piglit_init(int argc
, char **argv
)
323 static const char vs_source
[] =
326 "uniform vec2 window_pixel_size;\n"
327 "uniform vec2 level_pixel_size;\n"
328 "uniform vec2 pixel_offset;\n"
330 "// vertex is some corner of the unit square [0,1]^2 \n"
331 "attribute vec2 vertex;\n"
332 "varying vec2 tex_coord;\n"
336 " vec2 pos = vertex;\n"
337 " pos *= level_pixel_size;\n"
338 " pos += pixel_offset;\n"
339 " pos /= 0.5 * window_pixel_size;\n"
340 " pos -= vec2(1, 1);\n"
341 " gl_Position = vec4(pos.xy, 0.0, 1.0);\n"
343 " tex_coord = vertex;\n"
346 static const char fs_source
[] =
348 "precision highp float;\n"
350 "uniform sampler2D tex;\n"
351 "varying vec2 tex_coord;\n"
355 " vec4 t = texture2D(tex, tex_coord);\n"
356 " gl_FragColor = vec4(t.rgb, 1.0);\n"
359 /* Vertices to draw a square triangle strip. */
360 static const GLfloat vertices
[2 * NUM_VERTICES
] = {
371 piglit_require_extension("GL_KHR_texture_compression_astc_ldr");
373 glClearColor(0.9098, 0.8314, 0.7843, 1.0);
374 glViewport(0, 0, piglit_width
, piglit_height
);
376 glGenBuffers(1, &vertex_buf
);
377 glBindBuffer(GL_ARRAY_BUFFER
, vertex_buf
);
379 glGenVertexArrays(1, &vao
);
380 glBindVertexArray(vao
);
382 prog
= piglit_build_simple_program(vs_source
, fs_source
);
383 glReleaseShaderCompiler();
386 vertex_loc
= glGetAttribLocation(prog
, "vertex");
387 glEnableVertexAttribArray(vertex_loc
);
388 glVertexAttribPointer(vertex_loc
, 2, GL_FLOAT
, GL_FALSE
, 0, NULL
);
389 glBufferData(GL_ARRAY_BUFFER
, sizeof(vertices
), vertices
,
392 glUniform1i(glGetUniformLocation(prog
, "tex"), 0);
393 glUniform2f(glGetUniformLocation(prog
, "window_pixel_size"),
394 piglit_width
, piglit_height
);
400 return piglit_run_selected_subtests(piglit_config
->subtests
,
401 piglit_config
->selected_subtests
,
402 piglit_config
->num_selected_subtests
,