2 * Copyright 2016 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 * The files under compressed/SLICED3D/{hdr, ldrl, ldrs} contain full miptrees,
29 * in the GL_*_ASTC_* formats, of a sliced 3D texture of waffles and fruit [1].
30 * The base level size was shrunken to 160x106 pixels and used to create a sliced
31 * 3D texture with depth=8.
32 * The files under the decompressed/SLICED3D/{hdr, ldrl, ldrs} directory contain
33 * the same miptree in GL_RGBA format. Each miplevel was obtained by decompressing
34 * 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:
41 * http://people.freedesktop.org/~chadversary/permalink/2012-07-09/1574cff2-d091-4421-a3cf-b56c7943d060.jpg.
42 * [2] astcenc is the reference ASTC compression tool, available at:
43 * http://malideveloper.arm.com/develop-for-mali/tools/software-tools/astc-evaluation-codec/.
46 #include "piglit-util-gl.h"
47 #include "piglit_ktx.h"
50 #define LEVEL0_WIDTH 160
51 #define LEVEL0_HEIGHT 106
52 #define LEVEL0_DEPTH 8
54 #define NUM_VERTICES 4
58 static struct piglit_gl_test_config
*piglit_config
;
69 test_miptrees(void* input_type
);
71 static enum test_type ldr_test
= TEST_TYPE_LDR
;
72 static enum test_type hdr_test
= TEST_TYPE_HDR
;
73 static enum test_type srgb_test
= TEST_TYPE_SRGB
;
74 static enum test_type srgb_fp_test
= TEST_TYPE_SRGB_FP
;
75 static const struct piglit_subtest subtests
[] = {
95 "sRGB decode full precision",
103 PIGLIT_GL_TEST_CONFIG_BEGIN
105 piglit_config
= &config
;
106 config
.supports_gl_compat_version
= 11;
107 config
.supports_gl_es_version
= 30;
109 config
.window_width
= 2 * LEVEL0_WIDTH
;
110 config
.window_height
= LEVEL0_HEIGHT
+ (LEVEL0_HEIGHT
>> 1);
111 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
113 config
.subtests
= subtests
;
115 PIGLIT_GL_TEST_CONFIG_END
118 * The \a filename is relative to the current test's source directory.
120 * A new texture is created and returned in \a tex_name.
123 load_texture(const char *dir1
, const char *dir2
,
124 const char *block_dim_str
, GLuint
*tex_name
)
126 struct piglit_ktx
*ktx
;
127 const struct piglit_ktx_info
*info
;
132 /* Generate filename for compressed texture */
133 snprintf(cur_file
, sizeof(cur_file
), "waffles-%s.ktx",
136 piglit_join_paths(filepath
, sizeof(filepath
), 7,
140 "khr_texture_compression_astc",
145 ktx
= piglit_ktx_read_file(filepath
);
147 piglit_report_result(PIGLIT_FAIL
);
149 info
= piglit_ktx_get_info(ktx
);
150 assert(info
->num_miplevels
== NUM_LEVELS
);
151 assert(info
->target
== GL_TEXTURE_3D
);
152 assert(info
->pixel_width
== LEVEL0_WIDTH
);
153 assert(info
->pixel_height
== LEVEL0_HEIGHT
);
154 assert(info
->pixel_depth
== LEVEL0_DEPTH
);
157 ok
= piglit_ktx_load_texture(ktx
, tex_name
, NULL
);
159 piglit_report_result(PIGLIT_FAIL
);
161 piglit_ktx_destroy(ktx
);
164 /** Compares the compressed texture against the decompressed texture */
165 bool draw_compare_levels(bool check_error
,
166 GLint level_pixel_size_loc
, GLint pixel_offset_loc
,
167 GLint slice_loc
, GLint depth_loc
, GLint slice
,
168 GLuint compressed_tex
, GLuint decompressed_tex
)
170 /* Fully-saturated magenta */
171 static const float error_color
[4] = {1.0, 0.0, 1.0, 1.0};
178 for (; level
< NUM_LEVELS
; ++level
) {
179 int w
= LEVEL0_WIDTH
>> level
;
180 int h
= LEVEL0_HEIGHT
>> level
;
181 int d
= LEVEL0_DEPTH
>> level
;
183 glUniform2f(level_pixel_size_loc
, (float) w
, (float) h
);
184 glUniform1f(slice_loc
, slice
);
185 glUniform1f(depth_loc
, d
);
187 /* Draw miplevel of compressed texture. */
188 glBindTexture(GL_TEXTURE_3D
, compressed_tex
);
189 glUniform2f(pixel_offset_loc
, x
, y
);
190 glDrawArrays(GL_TRIANGLE_FAN
, 0, NUM_VERTICES
);
192 /* Check the textures (or error-colors) for equivalence. */
194 pass
= piglit_probe_rect_rgba(x
, y
, w
, h
,
197 /* Draw miplevel of decompressed texture. */
198 glBindTexture(GL_TEXTURE_3D
, decompressed_tex
);
199 glUniform2f(pixel_offset_loc
, LEVEL0_WIDTH
+ x
, y
);
200 glDrawArrays(GL_TRIANGLE_FAN
, 0, NUM_VERTICES
);
202 pass
= piglit_probe_rects_equal(x
, y
,
207 piglit_loge("Slice: %d, Miplevel: %d",
212 /* Update the next miplevel arrangement */
219 piglit_present_results();
224 test_miptrees(void* input_type
)
226 GLint slice_loc
, depth_loc
, pixel_offset_loc
, level_pixel_size_loc
;
227 const enum test_type subtest
= *(enum test_type
*) input_type
;
228 const bool is_srgb_test
= subtest
== TEST_TYPE_SRGB
;
229 const bool is_hdr_test
= subtest
== TEST_TYPE_HDR
;
231 static const char * tests
[4] = {"hdr", "ldrl", "ldrs", "ldrs"};
232 static const char * block_dim_str
[14] = {
249 piglit_require_extension("GL_KHR_texture_compression_astc_ldr");
251 pixel_offset_loc
= glGetUniformLocation(prog
, "pixel_offset");
252 level_pixel_size_loc
= glGetUniformLocation(prog
, "level_pixel_size");
253 slice_loc
= glGetUniformLocation(prog
, "slice");
254 depth_loc
= glGetUniformLocation(prog
, "depth");
256 /* Check for error color if an LDR-only sys reading an HDR
257 * texture. No need to draw a reference mipmap in this case.
259 const bool has_hdr
= piglit_is_extension_supported(
260 "GL_KHR_texture_compression_astc_hdr");
261 const bool check_error
= is_hdr_test
&& !has_hdr
;
262 int slice
, block_dims
= 0;
265 piglit_require_extension(
266 "GL_KHR_texture_compression_astc_sliced_3d");
269 /* Loosen up the tolerence for sRGB tests. This will allow testing
270 * sRGB formats which have known precision issues in void extent
271 * blocks. See khronos bug#11294 for details.
273 piglit_set_tolerance_for_bits(7, 7, 7, 7);
275 piglit_set_tolerance_for_bits(8, 8, 8, 8);
277 for ( ; block_dims
< ARRAY_SIZE(block_dim_str
); block_dims
++) {
278 /* Texture objects. */
279 GLuint tex_compressed
= 0;
280 GLuint tex_decompressed
= 0;
282 /* Load texture for current submode and block size */
283 load_texture("compressed/SLICED3D", tests
[subtest
],
284 block_dim_str
[block_dims
],
287 load_texture("decompressed/SLICED3D",
289 block_dim_str
[block_dims
],
292 for (slice
= 0 ; slice
< LEVEL0_DEPTH
; slice
++) {
293 /* Draw and compare each level of the two textures */
294 glClear(GL_COLOR_BUFFER_BIT
);
295 if (!draw_compare_levels(check_error
,
296 level_pixel_size_loc
,
298 slice_loc
, depth_loc
,
302 piglit_loge("Mode: %s Block: %s.",
304 block_dim_str
[block_dims
]);
308 /* Delete bound textures */
309 glDeleteTextures(1, &tex_compressed
);
311 glDeleteTextures(1, &tex_decompressed
);
318 piglit_init(int argc
, char **argv
)
320 static const char vs_source
[] =
323 "uniform vec2 window_pixel_size;\n"
324 "uniform vec2 level_pixel_size;\n"
325 "uniform vec2 pixel_offset;\n"
327 "// vertex is some corner of the unit square [0,1]^2 \n"
329 "out vec2 tex_coord;\n"
333 " vec2 pos = vertex;\n"
334 " pos *= level_pixel_size;\n"
335 " pos += pixel_offset;\n"
336 " pos /= 0.5 * window_pixel_size;\n"
337 " pos -= vec2(1, 1);\n"
338 " gl_Position = vec4(pos.xy, 0.0, 1.0);\n"
340 " tex_coord = vertex;\n"
343 static const char fs_source
[] =
345 "precision highp float;\n"
347 "uniform highp sampler3D tex;\n"
348 "uniform float slice;\n"
349 "uniform float depth;\n"
350 "in vec2 tex_coord;\n"
351 "out vec4 fragment_color;\n"
355 " vec4 t = texture(tex, vec3(tex_coord.x, tex_coord.y,\n"
356 " slice / (depth - 1.0)));\n"
357 " fragment_color = vec4(t.rgb, 1.0);\n"
360 /* Vertices to draw a square triangle strip. */
361 static const GLfloat vertices
[2 * NUM_VERTICES
] = {
372 if (!piglit_is_gles())
373 piglit_require_extension("GL_ARB_ES3_compatibility");
375 glClearColor(0.9098, 0.8314, 0.7843, 1.0);
376 glViewport(0, 0, piglit_width
, piglit_height
);
378 glGenBuffers(1, &vertex_buf
);
379 glBindBuffer(GL_ARRAY_BUFFER
, vertex_buf
);
381 glGenVertexArrays(1, &vao
);
382 glBindVertexArray(vao
);
384 prog
= piglit_build_simple_program(vs_source
, fs_source
);
385 glReleaseShaderCompiler();
388 vertex_loc
= glGetAttribLocation(prog
, "vertex");
389 glEnableVertexAttribArray(vertex_loc
);
390 glVertexAttribPointer(vertex_loc
, 2, GL_FLOAT
, GL_FALSE
, 0, NULL
);
391 glBufferData(GL_ARRAY_BUFFER
, sizeof(vertices
), vertices
,
394 glUniform1i(glGetUniformLocation(prog
, "tex"), 0);
395 glUniform2f(glGetUniformLocation(prog
, "window_pixel_size"),
396 piglit_width
, piglit_height
);
402 return piglit_run_selected_subtests(piglit_config
->subtests
,
403 piglit_config
->selected_subtests
,
404 piglit_config
->num_selected_subtests
,