[Piglit] [PATCH 3/3] Add tests for glCompressedTex{Image,SubImage}3D().
Paul Berry
stereotype441 at gmail.com
Mon Dec 31 11:14:18 PST 2012
---
tests/all.tests | 6 +
tests/spec/ext_texture_array/CMakeLists.gl.txt | 1 +
tests/spec/ext_texture_array/CMakeLists.gles3.txt | 8 +
tests/spec/ext_texture_array/compressed.c | 307 ++++++++++++++++++++++
4 files changed, 322 insertions(+)
create mode 100644 tests/spec/ext_texture_array/CMakeLists.gles3.txt
create mode 100644 tests/spec/ext_texture_array/compressed.c
diff --git a/tests/all.tests b/tests/all.tests
index 9eacc85..d3ec020 100644
--- a/tests/all.tests
+++ b/tests/all.tests
@@ -1623,6 +1623,9 @@ ext_texture_array['copyteximage 2D_ARRAY'] = PlainExecTest(['copyteximage', '-au
add_plain_test(ext_texture_array, 'fbo-array')
add_plain_test(ext_texture_array, 'fbo-depth-array')
add_plain_test(ext_texture_array, 'array-texture')
+for test_mode in ['teximage', 'texsubimage']:
+ test_name = 'compressed {0}'.format(test_mode)
+ ext_texture_array[test_name] = PlainExecTest('ext_texture_array-' + test_name + ' -auto -fbo')
arb_texture_cube_map = Group()
spec['ARB_texture_cube_map'] = arb_texture_cube_map
@@ -2697,6 +2700,9 @@ for tex_format in ('rgb8', 'srgb8', 'rgba8', 'srgb8-alpha8', 'r11', 'rg11', 'rgb
executable = '{0} -auto'.format(test_name)
gles30[test_name] = concurrent_test(executable)
gles30['minmax'] = concurrent_test('minmax_gles3')
+for test_mode in ['teximage', 'texsubimage']:
+ test_name = 'ext_texture_array-compressed_gles3 {0}'.format(test_mode)
+ gles30[test_name] = PlainExecTest(test_name + ' -auto -fbo')
add_shader_test_dir(spec, os.path.join(generatedTestDir, 'spec'),
recursive=True)
diff --git a/tests/spec/ext_texture_array/CMakeLists.gl.txt b/tests/spec/ext_texture_array/CMakeLists.gl.txt
index 0bf4a7d..5b10962 100644
--- a/tests/spec/ext_texture_array/CMakeLists.gl.txt
+++ b/tests/spec/ext_texture_array/CMakeLists.gl.txt
@@ -10,3 +10,4 @@ link_libraries (
)
piglit_add_executable (ext_texture_array-maxlayers maxlayers.c)
+piglit_add_executable (ext_texture_array-compressed compressed.c)
diff --git a/tests/spec/ext_texture_array/CMakeLists.gles3.txt b/tests/spec/ext_texture_array/CMakeLists.gles3.txt
new file mode 100644
index 0000000..2e4da1b
--- /dev/null
+++ b/tests/spec/ext_texture_array/CMakeLists.gles3.txt
@@ -0,0 +1,8 @@
+link_libraries(
+ piglitutil_${piglit_target_api}
+ ${OPENGL_gles2_LIBRARY}
+ )
+
+piglit_add_executable (ext_texture_array-compressed_${piglit_target_api} compressed.c)
+
+# vim: ft=cmake:
diff --git a/tests/spec/ext_texture_array/compressed.c b/tests/spec/ext_texture_array/compressed.c
new file mode 100644
index 0000000..49ddb9c
--- /dev/null
+++ b/tests/spec/ext_texture_array/compressed.c
@@ -0,0 +1,307 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file compressed.c
+ *
+ * Confirm that the functions glCompressedTexImage3D and
+ * glCompressedTexSubImage3D work properly for 2D array textures.
+ *
+ * This test performs the following operations:
+ *
+ * - Create a 2D array texture with a width of 8 texture blocks, a
+ * height of 8 texture blocks, and a depth of 4.
+ *
+ * - If the test is operating in "teximage" mode, use a single call to
+ * glCompressedTexImage3D to upload a single array texture where
+ * each compressed block has a different grayscale value.
+ *
+ * - If the test is operating in "texsubimage" mode, use multiple
+ * calls to glCompressedTexSubImage3D to upload the texture in
+ * pieces.
+ *
+ * - Draw each layer of the texture to a separate region on the
+ * screen.
+ *
+ * - Verify that each portion of the drawn image matches the expected
+ * grayscale intensity.
+ *
+ * On GLES3, this test is performed using either ETC2 textures. On
+ * desktop GL, it is performed using FXT1 textures.
+ */
+
+#include "piglit-util-gl-common.h"
+#include "piglit-util-compressed.h"
+
+#ifdef PIGLIT_USE_OPENGL
+#define GRAYSCALE_IMAGES piglit_fxt1_grayscale_images
+#define COMPRESSED_FORMAT GL_COMPRESSED_RGB_FXT1_3DFX
+#define BLOCK_WIDTH 8
+#define BLOCK_HEIGHT 4
+#define BLOCK_BYTES 16
+#define GLSL_VERSION "120"
+#else // PIGLIT_USE_OPENGL_ES3
+#define GRAYSCALE_IMAGES piglit_etc1_grayscale_images
+#define COMPRESSED_FORMAT GL_COMPRESSED_RGB8_ETC2
+#define BLOCK_WIDTH 4
+#define BLOCK_HEIGHT 4
+#define BLOCK_BYTES 8
+#define GLSL_VERSION "300 es"
+#endif
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+#ifdef PIGLIT_USE_OPENGL
+ config.supports_gl_compat_version = 10;
+#else // PIGLIT_USE_OPENGL_ES3
+ config.supports_gl_es_version = 30;
+#endif
+
+ if (config.window_width < 4 * 8 * BLOCK_WIDTH)
+ config.window_width = 4 * 8 * BLOCK_WIDTH;
+ if (config.window_height < 8 * BLOCK_HEIGHT)
+ config.window_height = 8 * BLOCK_HEIGHT;
+ config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const char vs_text[] =
+ "#version " GLSL_VERSION "\n"
+#ifdef PIGLIT_USE_OPENGL
+ "#define piglit_Vertex gl_Vertex\n"
+ "#define piglit_MultiTexCoord0 gl_MultiTexCoord0\n"
+ "#define piglit_in attribute\n"
+ "#define piglit_out varying\n"
+#else // PIGLIT_USE_OPENGL_ES3
+ "#define piglit_in in\n"
+ "#define piglit_out out\n"
+ "piglit_in vec4 piglit_Vertex;\n"
+ "piglit_in vec4 piglit_MultiTexCoord0;\n"
+#endif
+ "piglit_out vec3 texcoord;\n"
+ "uniform mat4 proj;\n"
+ "uniform int layer;\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = proj * piglit_Vertex;\n"
+ " texcoord = vec3(piglit_MultiTexCoord0.xy, float(layer));\n"
+ "}\n";
+
+static const char fs_text[] =
+ "#version " GLSL_VERSION "\n"
+#ifdef PIGLIT_USE_OPENGL
+ "#extension GL_EXT_texture_array : require\n"
+ "#define piglit_FragColor gl_FragColor\n"
+ "#define piglit_in varying\n"
+ "#define piglit_texture2DArray texture2DArray\n"
+#else // PIGLIT_USE_OPENGL_ES3
+ "#define piglit_in in\n"
+ "#define piglit_texture2DArray texture\n"
+ "out vec4 piglit_FragColor;\n"
+#endif
+ "piglit_in vec3 texcoord;\n"
+ "uniform sampler2DArray samp;\n"
+ "void main()\n"
+ "{\n"
+ " piglit_FragColor = piglit_texture2DArray(samp, texcoord);\n"
+ "}\n";
+
+static bool test_texsubimage;
+static GLuint tex;
+static GLuint prog;
+static GLint proj_loc;
+static GLint layer_loc;
+static unsigned expected_gray_levels[8][8][4]; /* x, y, z */
+
+
+static void
+print_usage_and_exit(const char *prog_name)
+{
+ printf("Usage: %s <test_mode>\n"
+ " where <test_mode> is one of the following:\n"
+ " teximage: test glCompressedTexImage3D\n"
+ " texsubimage: test glCompressedTexSubImage3D\n",
+ prog_name);
+ piglit_report_result(PIGLIT_FAIL);
+}
+
+
+static void
+compute_expected_gray_levels(unsigned width, unsigned height, unsigned depth,
+ unsigned xoffset, unsigned yoffset,
+ unsigned zoffset, unsigned gray_level)
+{
+ unsigned x, y, z;
+ for (z = 0; z < depth; z++) {
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ expected_gray_levels
+ [x + xoffset]
+ [y + yoffset]
+ [z + zoffset]
+ = gray_level++;
+ }
+ }
+ }
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ /* Parse args */
+ if (argc != 2)
+ print_usage_and_exit(argv[0]);
+ if (strcmp(argv[1], "teximage") == 0)
+ test_texsubimage = false;
+ else if (strcmp(argv[1], "texsubimage") == 0)
+ test_texsubimage = true;
+ else
+ print_usage_and_exit(argv[0]);
+
+ /* Make sure required GL features are present */
+#ifdef PIGLIT_USE_OPENGL
+ piglit_require_gl_version(21);
+ piglit_require_extension("GL_ARB_texture_compression");
+ piglit_require_extension("GL_3DFX_texture_compression_FXT1");
+#endif
+
+ /* We're using texture unit 0 for this entire test */
+ glActiveTexture(GL_TEXTURE0);
+
+ /* Create the texture */
+ glGenTextures(1, &tex);
+ glBindTexture(GL_TEXTURE_2D_ARRAY, tex);
+ glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, 0);
+ glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ /* Upload the image */
+ if (!test_texsubimage) {
+ glCompressedTexImage3D(GL_TEXTURE_2D_ARRAY, 0,
+ COMPRESSED_FORMAT,
+ 8 * BLOCK_WIDTH,
+ 8 * BLOCK_HEIGHT,
+ 4,
+ 0 /* border */,
+ 256 * BLOCK_BYTES,
+ GRAYSCALE_IMAGES);
+ compute_expected_gray_levels(8, 8, 4, 0, 0, 0, 0);
+ } else {
+ unsigned xoffset, yoffset, zoffset;
+ unsigned gray_level = 0;
+ glCompressedTexImage3D(GL_TEXTURE_2D_ARRAY, 0,
+ COMPRESSED_FORMAT,
+ 8 * BLOCK_WIDTH,
+ 8 * BLOCK_HEIGHT,
+ 4,
+ 0 /* border */,
+ 8 * 8 * 4 * BLOCK_BYTES,
+ NULL);
+ for (xoffset = 0; xoffset < 8; xoffset += 4) {
+ for (yoffset = 0; yoffset < 8; yoffset += 4) {
+ for (zoffset = 0; zoffset < 4; zoffset += 2) {
+ glCompressedTexSubImage3D(
+ GL_TEXTURE_2D_ARRAY, 0,
+ xoffset * BLOCK_WIDTH,
+ yoffset * BLOCK_HEIGHT,
+ zoffset,
+ 4 * BLOCK_WIDTH,
+ 4 * BLOCK_HEIGHT,
+ 2,
+ COMPRESSED_FORMAT,
+ 4 * 4 * 2 * BLOCK_BYTES,
+ GRAYSCALE_IMAGES[gray_level]);
+ compute_expected_gray_levels(
+ 4, 4, 2,
+ xoffset, yoffset, zoffset,
+ gray_level);
+ gray_level += 4 * 4 * 2;
+ }
+ }
+ }
+ }
+
+ /* Create the shaders */
+ prog = glCreateProgram();
+ glAttachShader(prog, piglit_compile_shader_text(GL_VERTEX_SHADER,
+ vs_text));
+ glAttachShader(prog, piglit_compile_shader_text(GL_FRAGMENT_SHADER,
+ fs_text));
+ glBindAttribLocation(prog, PIGLIT_ATTRIB_POS, "piglit_Vertex");
+ glBindAttribLocation(prog, PIGLIT_ATTRIB_TEX, "piglit_MultiTexCoord0");
+ glLinkProgram(prog);
+ if (!piglit_link_check_status(prog))
+ piglit_report_result(PIGLIT_FAIL);
+ proj_loc = glGetUniformLocation(prog, "proj");
+ layer_loc = glGetUniformLocation(prog, "layer");
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ piglit_report_result(PIGLIT_FAIL);
+}
+
+
+bool
+check_result(unsigned x, unsigned y, unsigned z)
+{
+ float f = expected_gray_levels[x][y][z] / 255.0;
+ float expected[] = { f, f, f };
+ return piglit_probe_rect_rgb((z * 8 + x) * BLOCK_WIDTH,
+ y * BLOCK_HEIGHT,
+ BLOCK_WIDTH,
+ BLOCK_HEIGHT,
+ expected);
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ unsigned x, y, z;
+ bool pass = true;
+
+ /* Draw each texture level */
+ glClear(GL_COLOR_BUFFER_BIT);
+ glUseProgram(prog);
+ piglit_ortho_uniform(proj_loc, piglit_width, piglit_height);
+ for (z = 0; z < 4; z++) {
+ glUniform1i(layer_loc, z);
+ piglit_draw_rect_tex(z * 8 * BLOCK_WIDTH, 0,
+ 8 * BLOCK_WIDTH, 8 * BLOCK_HEIGHT,
+ 0, 0, 1, 1);
+ }
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ pass = false;
+
+ /* Check results */
+ for (z = 0; z < 4; z++) {
+ for (y = 0; y < 8; y++) {
+ for (x = 0; x < 8; x++) {
+ pass = check_result(x, y, z) && pass;
+ }
+ }
+ }
+
+ piglit_present_results();
+
+ return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
--
1.8.0.3
More information about the Piglit
mailing list