[Piglit] [PATCH 5/8] arb_direct_state_access: New test for glGetTextureImage.

Laura Ekstrand laura at jlekstrand.net
Thu Feb 19 14:36:13 PST 2015


v2: Added increased error checking
    Review from Ian Romanick and Ilia Mirkin:
    - Compat context 20 (and remove check for ARB_texture_cube_map)
	- Change global_pass from GL_boolean to bool
	- Clean up the texture in upload_subtest
	- Restructure download commands to simplify use_pbo logic
	- Use separate pack and unpack pbos

I have not applied the pre-emptive R-b's because this patch series adds a new
getteximage-targets test, and, because the tests are so similar, it makes
sense to have the whole thing reviewed and pushed as a big chunk.
---
 tests/all.py                                       |   1 +
 .../spec/arb_direct_state_access/CMakeLists.gl.txt |   1 +
 .../gettextureimage-targets.c                      | 228 +++++++++++++++++++++
 3 files changed, 230 insertions(+)
 create mode 100644 tests/spec/arb_direct_state_access/gettextureimage-targets.c

diff --git a/tests/all.py b/tests/all.py
index f609643..c7f31f0 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -4422,6 +4422,7 @@ spec['ARB_direct_state_access']['gettextureimage-formats'] = PiglitGLTest(['arb_
 spec['ARB_direct_state_access']['gettextureimage-formats'] = PiglitGLTest(['arb_direct_state_access-gettextureimage-formats', 'init-by-rendering'], run_concurrent=True)
 spec['ARB_direct_state_access']['gettextureimage-luminance'] = PiglitGLTest(['arb_direct_state_access-gettextureimage-luminance'], run_concurrent=True)
 spec['ARB_direct_state_access']['gettextureimage-simple'] = PiglitGLTest(['arb_direct_state_access-gettextureimage-simple'], run_concurrent=True)
+spec['ARB_direct_state_access']['gettextureimage-targets'] = PiglitGLTest(['arb_direct_state_access-gettextureimage-targets'], run_concurrent=True)
 spec['ARB_direct_state_access']['compressedtextureimage'] = PiglitGLTest(['arb_direct_state_access-compressedtextureimage', 'GL_COMPRESSED_RGBA_FXT1_3DFX'], run_concurrent=True)
 spec['ARB_direct_state_access']['getcompressedtextureimage'] = PiglitGLTest(['arb_direct_state_access-getcompressedtextureimage'], run_concurrent=True)
 spec['ARB_direct_state_access']['compressedtexturesubimage'] = PiglitGLTest(['arb_direct_state_access-compressedtexturesubimage'], run_concurrent=True)
diff --git a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
index 168e58f..5d8d812 100644
--- a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
+++ b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
@@ -39,6 +39,7 @@ piglit_add_executable (arb_direct_state_access-get-textures get-textures.c)
 piglit_add_executable (arb_direct_state_access-gettextureimage-formats gettextureimage-formats.c)
 piglit_add_executable (arb_direct_state_access-gettextureimage-luminance gettextureimage-luminance.c)
 piglit_add_executable (arb_direct_state_access-gettextureimage-simple gettextureimage-simple.c)
+piglit_add_executable (arb_direct_state_access-gettextureimage-targets gettextureimage-targets.c)
 piglit_add_executable (arb_direct_state_access-compressedtextureimage compressedtextureimage.c)
 piglit_add_executable (arb_direct_state_access-getcompressedtextureimage getcompressedtextureimage.c)
 piglit_add_executable (arb_direct_state_access-compressedtexturesubimage compressedtexturesubimage.c)
diff --git a/tests/spec/arb_direct_state_access/gettextureimage-targets.c b/tests/spec/arb_direct_state_access/gettextureimage-targets.c
new file mode 100644
index 0000000..8b53ada
--- /dev/null
+++ b/tests/spec/arb_direct_state_access/gettextureimage-targets.c
@@ -0,0 +1,228 @@
+/*
+ * Copyright 2015 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 gettextureimage-targets.c
+ *
+ * Tests to make sure that glGetTextureImage works correctly.
+ * The basic idea is to create some data, upload it to the
+ * driver with the traditional commands, download it with DSA, and compare.
+ * Of course, this assumes that the traditional commands are correct, which
+ * may not actually be the case.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_compat_version = 20;
+
+	config.window_visual = PIGLIT_GL_VISUAL_RGBA |
+		PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+#define WIDTH 32
+#define HEIGHT 32
+#define IMAGE_SIZE (WIDTH * HEIGHT * 4)
+#define CHAR_LIMIT 100
+
+static GLubyte *expected;
+static bool global_pass = true;
+
+static void
+subtest(bool local_result, const char *test_name)
+{
+	global_pass = local_result && global_pass;
+	piglit_report_subtest_result(local_result ? PIGLIT_PASS : PIGLIT_FAIL,
+				     test_name);
+}
+
+static void
+init_random_data(void)
+{
+	int i;
+
+	expected = malloc(18 * IMAGE_SIZE);
+	for (i = 0; i < 18 * IMAGE_SIZE; ++i) {
+		expected[i] = (GLubyte) rand();
+	}
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	piglit_require_extension("GL_ARB_direct_state_access");
+	piglit_require_extension("GL_ARB_texture_storage");
+	srand(0);
+	init_random_data();
+}
+
+static bool
+compare_to_expected(const GLubyte *data, int num_layers)
+{
+	return memcmp(expected, data, num_layers * IMAGE_SIZE) == 0;
+}
+
+static void
+upload_subtest(GLenum target, bool use_pbo)
+{
+	GLuint tex, pbo_pack, pbo_unpack;
+	int num_layers;
+	char test_name [CHAR_LIMIT];
+	int i;
+	GLubyte *data = expected;
+	bool pass = true;
+
+	/* Prepare to read data from expected */
+	if (use_pbo) {
+		glGenBuffers(1, &pbo_unpack);
+		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_unpack);
+		glBufferData(GL_PIXEL_UNPACK_BUFFER, 18 * IMAGE_SIZE,
+		             expected, GL_STATIC_DRAW);
+		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+		data = NULL;
+	}
+
+	/* Upload it using traditional path */
+	glGenTextures(1, &tex);
+	glBindTexture(target, tex);
+
+	switch (target) {
+
+	case GL_TEXTURE_1D:
+		num_layers = 1;
+		glTexStorage1D(target, 1, GL_RGBA8, WIDTH * HEIGHT);
+		glTexSubImage1D(target, 0, 0, WIDTH * HEIGHT, GL_RGBA,
+		                GL_UNSIGNED_BYTE, data);
+		break;
+	case GL_TEXTURE_1D_ARRAY:  /* FALLTHROUGH */
+	case GL_TEXTURE_RECTANGLE: /* FALLTHROUGH */
+	case GL_TEXTURE_2D:
+		num_layers = 1;
+		glTexStorage2D(target, 1, GL_RGBA8, WIDTH, HEIGHT);
+		glTexSubImage2D(target, 0, 0, 0, WIDTH, HEIGHT,
+		                GL_RGBA, GL_UNSIGNED_BYTE, data);
+		break;
+	case GL_TEXTURE_3D: /* FALLTHROUGH */
+	case GL_TEXTURE_2D_ARRAY:
+		num_layers = 3;
+		glTexStorage3D(target, 1, GL_RGBA8, WIDTH, HEIGHT,
+		               num_layers);
+		glTexSubImage3D(target, 0, 0, 0, 0, WIDTH, HEIGHT,
+		                num_layers, GL_RGBA, GL_UNSIGNED_BYTE, data);
+		break;
+	case GL_TEXTURE_CUBE_MAP:
+		num_layers = 6;
+		glTexStorage2D(target, 1, GL_RGBA8, WIDTH, HEIGHT);
+		for (i = 0; i < num_layers; ++i) {
+			glTexSubImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
+					0, 0, 0, WIDTH, HEIGHT, GL_RGBA,
+					GL_UNSIGNED_BYTE,
+					data + i * IMAGE_SIZE);
+		}
+		break;
+	case GL_TEXTURE_CUBE_MAP_ARRAY:
+		num_layers = 18;
+		glTexStorage3D(target, 1, GL_RGBA8, WIDTH, HEIGHT,
+		               num_layers);
+		glTexSubImage3D(target, 0, 0, 0, 0, WIDTH, HEIGHT,
+		                num_layers, GL_RGBA, GL_UNSIGNED_BYTE, data);
+		break;
+	default:
+		printf("Bad texture target.\n");
+		piglit_report_result(PIGLIT_FAIL);
+
+	}
+	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+	/* Download it using DSA */
+	if (use_pbo) {
+		/* Prepare PBO */
+		GLubyte *junk = malloc(18 * IMAGE_SIZE);
+		memset(junk, 123, 18 * IMAGE_SIZE);
+		glGenBuffers(1, &pbo_pack);
+		glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo_pack);
+		glBufferData(GL_PIXEL_PACK_BUFFER, 18 * IMAGE_SIZE,
+		             junk, GL_STATIC_READ);
+		free(junk);
+		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+		/* Do the transfer */
+		glBindTexture(target, 0);
+		glGetTextureImage(tex, 0, GL_RGBA, GL_UNSIGNED_BYTE,
+				  num_layers * IMAGE_SIZE, (void *) 0);
+		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+
+		/* Map the data */
+		data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
+		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+	}
+	else {
+		data = malloc(18 * IMAGE_SIZE);
+		glBindTexture(target, 0);
+		glGetTextureImage(tex, 0, GL_RGBA, GL_UNSIGNED_BYTE,
+				  num_layers * IMAGE_SIZE, data);
+		pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
+	}
+
+
+	/* Perform comparison and report the results. */
+	snprintf(test_name, CHAR_LIMIT, "upload %s%s",
+	         piglit_get_gl_enum_name(target), use_pbo ? " PBO" : "");
+	pass = compare_to_expected(data, num_layers) && pass;
+	subtest(pass, test_name);
+
+	/* Clean up */
+	glDeleteTextures(1, &tex);
+	if (use_pbo) {
+		glDeleteBuffers(1, &pbo_unpack);
+		glDeleteBuffers(1, &pbo_pack);
+	}
+	else
+		free(data);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	int i;
+
+	for (i = 0; i < 2; ++i) {
+		upload_subtest(GL_TEXTURE_1D, (bool) i);
+		upload_subtest(GL_TEXTURE_2D, (bool) i);
+		upload_subtest(GL_TEXTURE_3D, (bool) i);
+		if (piglit_is_extension_supported("GL_ARB_texture_rectangle"))
+			upload_subtest(GL_TEXTURE_RECTANGLE, (bool) i);
+		if (piglit_is_extension_supported("GL_EXT_texture_array")) {
+			upload_subtest(GL_TEXTURE_1D_ARRAY, (bool) i);
+			upload_subtest(GL_TEXTURE_2D_ARRAY, (bool) i);
+		}
+		upload_subtest(GL_TEXTURE_CUBE_MAP, (bool) i);
+		if (piglit_is_extension_supported(
+				"GL_ARB_texture_cube_map_array"))
+			upload_subtest(GL_TEXTURE_CUBE_MAP_ARRAY, (bool) i);
+	}
+
+
+	return global_pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
-- 
2.1.0



More information about the Piglit mailing list