arb_direct_state_access: New test for glCompressedTextureSubImage*D.

Submitted by Laura Ekstrand on Feb. 13, 2015, 10:12 p.m.

Details

Message ID 1423865544-7022-1-git-send-email-laura@jlekstrand.net
State New
Headers show

Not browsing as part of any series.

Commit Message

Laura Ekstrand Feb. 13, 2015, 10:12 p.m.
---
 tests/all.py                                       |   1 +
 .../spec/arb_direct_state_access/CMakeLists.gl.txt |   1 +
 .../compressedtexturesubimage.c                    | 214 +++++++++++++++++++++
 3 files changed, 216 insertions(+)
 create mode 100644 tests/spec/arb_direct_state_access/compressedtexturesubimage.c

Patch hide | download patch | download mbox

diff --git a/tests/all.py b/tests/all.py
index 3953acf..72bc111 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -4419,6 +4419,7 @@  spec['ARB_direct_state_access']['gettextureimage-simple'] = PiglitGLTest(['arb_d
 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)
 spec['ARB_direct_state_access']['texture-storage-multisample'] = PiglitGLTest(['arb_direct_state_access-texture-storage-multisample'], run_concurrent=True)
 spec['ARB_direct_state_access']['texture-buffer'] = PiglitGLTest(['arb_direct_state_access-texture-buffer'], run_concurrent=True)
 spec['ARB_direct_state_access']['texture-buffer-range'] = PiglitGLTest(['arb_direct_state_access-texture-buffer-range'], 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 a327253..5d8d812 100644
--- a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
+++ b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
@@ -42,6 +42,7 @@  piglit_add_executable (arb_direct_state_access-gettextureimage-simple gettexture
 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)
 piglit_add_executable (arb_direct_state_access-texture-storage-multisample texture-storage-multisample.c)
 piglit_add_executable (arb_direct_state_access-texture-buffer texture-buffer.c)
 piglit_add_executable (arb_direct_state_access-texture-buffer-range texture-buffer-range.c)
diff --git a/tests/spec/arb_direct_state_access/compressedtexturesubimage.c b/tests/spec/arb_direct_state_access/compressedtexturesubimage.c
new file mode 100644
index 0000000..5372d10
--- /dev/null
+++ b/tests/spec/arb_direct_state_access/compressedtexturesubimage.c
@@ -0,0 +1,214 @@ 
+/*
+ * 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 compressedtexturesubimage.c
+ *
+ * The opposite of getcompressedtextureimage.
+ * The basic idea is to create some fake compressed data, upload it to the
+ * driver with DSA, download it with the traditional commands, 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 = 10;
+
+	config.window_visual = PIGLIT_GL_VISUAL_RGBA |
+		PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+/* Copied from Mesa src/mesa/main/formats.csv:
+ * MESA_FORMAT_RGBA_DXT5, s3tc, 4, 4, x128
+ */
+#define FORMAT GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
+#define WIDTH 32
+#define HEIGHT 32
+#define WIDTH_IN_BLOCKS 8
+#define HEIGHT_IN_BLOCKS 8
+#define BLOCK_BYTES 16
+#define IMAGE_SIZE (WIDTH_IN_BLOCKS * HEIGHT_IN_BLOCKS * BLOCK_BYTES)
+#define CHAR_LIMIT 100
+
+static GLubyte *expected;
+static GLboolean pass = GL_TRUE;
+
+static void
+subtest(GLboolean local_result, const char *test_name)
+{
+	pass = local_result && 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_EXT_texture_compression_s3tc");
+	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;
+	int num_layers;
+	char test_name [CHAR_LIMIT];
+	int i;
+
+	/* Prepare to read data from expected */
+	GLubyte *data = expected;
+	if (use_pbo) {
+		glGenBuffers(1, &pbo);
+		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
+		glBufferData(GL_PIXEL_UNPACK_BUFFER, 18 * IMAGE_SIZE,
+		             expected, GL_STATIC_DRAW);
+		data = NULL;
+		piglit_check_gl_error(GL_NO_ERROR);
+	}
+
+	/* Upload it using DSA */
+	glCreateTextures(target, 1, &tex);
+
+	switch (target) {
+
+	case GL_TEXTURE_2D:
+		num_layers = 1;
+		glTextureStorage2D(tex, 1, FORMAT, WIDTH, HEIGHT);
+		glCompressedTextureSubImage2D(tex, 0, 0, 0, WIDTH, HEIGHT,
+		                              FORMAT, num_layers * IMAGE_SIZE,
+					      data);
+		break;
+	case GL_TEXTURE_2D_ARRAY:
+		num_layers = 3;
+		glTextureStorage3D(tex, 1, FORMAT, WIDTH, HEIGHT, num_layers);
+		glCompressedTextureSubImage3D(tex, 0, 0, 0, 0, WIDTH, HEIGHT,
+		                              num_layers, FORMAT,
+					      num_layers * IMAGE_SIZE, data);
+		break;
+	case GL_TEXTURE_CUBE_MAP:
+		num_layers = 6;
+		glTextureStorage2D(tex, 1, FORMAT, WIDTH, HEIGHT);
+		glCompressedTextureSubImage3D(tex, 0, 0, 0, 0, WIDTH, HEIGHT,
+		                              num_layers, FORMAT,
+					      num_layers * IMAGE_SIZE, data);
+		break;
+	case GL_TEXTURE_CUBE_MAP_ARRAY:
+		num_layers = 18;
+		glTextureStorage3D(tex, 1, FORMAT, WIDTH, HEIGHT, num_layers);
+		glCompressedTextureSubImage3D(tex, 0, 0, 0, 0, WIDTH, HEIGHT,
+		                              num_layers, FORMAT,
+					      num_layers * IMAGE_SIZE, data);
+		break;
+	default:
+		printf("Bad texture target.\n");
+		piglit_report_result(PIGLIT_FAIL);
+
+	}
+	piglit_check_gl_error(GL_NO_ERROR);
+
+	/* Prepare to download into data. */
+	if (use_pbo) {
+		glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
+		glBufferData(GL_PIXEL_PACK_BUFFER, 18 * IMAGE_SIZE,
+		             NULL, GL_STATIC_READ);
+		piglit_check_gl_error(GL_NO_ERROR);
+		/* data = NULL from above */
+	}
+	else
+		data = malloc(18 * IMAGE_SIZE);
+
+	/* Download it using traditional path */
+	glBindTexture(target, tex);
+	if (target == GL_TEXTURE_CUBE_MAP) {
+		for (i = 0; i < num_layers; ++i) {
+			glGetCompressedTexImage(
+				GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
+				data + i * IMAGE_SIZE);
+		}
+	}
+	else
+		glGetCompressedTexImage(target, 0, data);
+	piglit_check_gl_error(GL_NO_ERROR);
+
+	if (use_pbo)
+		data = glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
+
+	/* Perform comparison and report the results. */
+	snprintf(test_name, CHAR_LIMIT, "upload %s%s",
+	         piglit_get_gl_enum_name(target), use_pbo ? " PBO" : "");
+	subtest(compare_to_expected(data, num_layers), test_name);
+
+	/* Clean up */
+	if (use_pbo)
+		glDeleteBuffers(1, &pbo);
+	else
+		free(data);
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	/* Non-PBO tests */
+	upload_subtest(GL_TEXTURE_2D, false);
+	if (piglit_is_extension_supported("GL_EXT_texture_array"))
+		upload_subtest(GL_TEXTURE_2D_ARRAY, false);
+	if (piglit_is_extension_supported("GL_ARB_texture_cube_map"))
+		upload_subtest(GL_TEXTURE_CUBE_MAP, false);
+	if (piglit_is_extension_supported("GL_ARB_texture_cube_map_array"))
+		upload_subtest(GL_TEXTURE_CUBE_MAP_ARRAY, false);
+
+	/* PBO tests */
+	upload_subtest(GL_TEXTURE_2D, true);
+	if (piglit_is_extension_supported("GL_EXT_texture_array"))
+		upload_subtest(GL_TEXTURE_2D_ARRAY, true);
+	if (piglit_is_extension_supported("GL_ARB_texture_cube_map"))
+		upload_subtest(GL_TEXTURE_CUBE_MAP, true);
+	if (piglit_is_extension_supported("GL_ARB_texture_cube_map_array"))
+		upload_subtest(GL_TEXTURE_CUBE_MAP_ARRAY, true);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}