[Piglit] [PATCH v2 1/2] Add test for KHR_gl_texture_image EGL extension

Ander Conselvan de Oliveira conselvan2 at gmail.com
Fri Feb 7 16:40:41 CET 2014


From: Abdiel Janulgue <abdiel.janulgue at linux.intel.com>

Changes from Abdiel's original patch [anderco]:
 - Set default precision for fragment shader
 - Remove unused variables and unnecessary defines
 - Create EGL images before defining texture pixel contents and remove
   the use of the EGL_IMAGE_PRESERVED_KHR attribute

Signed-off-by: Abdiel Janulgue <abdiel.janulgue at linux.intel.com>
Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
---
 tests/all.py                                       |    5 +
 tests/spec/CMakeLists.txt                          |    1 +
 .../spec/khr_gl_texture_image/CMakeLists.gles2.txt |   17 +
 tests/spec/khr_gl_texture_image/CMakeLists.txt     |    1 +
 .../khr_gl_texture_image/khr_gl_texture_image.c    |  470 ++++++++++++++++++++
 5 files changed, 494 insertions(+)
 create mode 100644 tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt
 create mode 100644 tests/spec/khr_gl_texture_image/CMakeLists.txt
 create mode 100644 tests/spec/khr_gl_texture_image/khr_gl_texture_image.c

diff --git a/tests/all.py b/tests/all.py
index 9a4b92e..2f53a5a 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3730,6 +3730,11 @@ add_concurrent_test(gles20, 'minmax_gles2')
 add_concurrent_test(gles20, 'multiple-shader-objects_gles2')
 add_concurrent_test(gles20, 'fbo_discard_gles2')
 
+egl_khr_gl_image = Group()
+spec['EGL_KHR_gl_image'] = egl_khr_gl_image
+egl_khr_gl_image['EGL_KHR_gl_texture_2D_image'] = plain_test('khr_gl_texture_image_gles2 -2d')
+egl_khr_gl_image['EGL_KHR_gl_texture_cubemap_image'] = plain_test('khr_gl_texture_image_gles2 -cubemap')
+
 gles30 = Group()
 spec['!OpenGL ES 3.0'] = gles30
 for tex_format in ('rgb8', 'srgb8', 'rgba8', 'srgb8-alpha8', 'r11', 'rg11', 'rgb8-punchthrough-alpha1', 'srgb8-punchthrough-alpha1'):
diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
index 8a8ec90..79c3046 100644
--- a/tests/spec/CMakeLists.txt
+++ b/tests/spec/CMakeLists.txt
@@ -96,3 +96,4 @@ add_subdirectory (ext_image_dma_buf_import)
 add_subdirectory (arb_blend_func_extended)
 add_subdirectory (ext_unpack_subimage)
 add_subdirectory (arb_vertex_array_object)
+add_subdirectory (khr_gl_texture_image)
diff --git a/tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt b/tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt
new file mode 100644
index 0000000..d1887a1
--- /dev/null
+++ b/tests/spec/khr_gl_texture_image/CMakeLists.gles2.txt
@@ -0,0 +1,17 @@
+#add_definitions(-DSOURCE_DIR="${piglit_SOURCE_DIR}/")
+
+include_directories(
+	${OPENGL_INCLUDE_PATH}
+	)
+
+link_libraries(
+	${OPENGL_gles2_LIBRARY}
+	${OPENGL_egl_LIBRARY}
+	piglitutil_gles2
+	)
+
+piglit_add_executable(khr_gl_texture_image_gles2
+	khr_gl_texture_image.c
+	)
+
+# vim: ft=cmake:
diff --git a/tests/spec/khr_gl_texture_image/CMakeLists.txt b/tests/spec/khr_gl_texture_image/CMakeLists.txt
new file mode 100644
index 0000000..144a306
--- /dev/null
+++ b/tests/spec/khr_gl_texture_image/CMakeLists.txt
@@ -0,0 +1 @@
+piglit_include_target_api()
diff --git a/tests/spec/khr_gl_texture_image/khr_gl_texture_image.c b/tests/spec/khr_gl_texture_image/khr_gl_texture_image.c
new file mode 100644
index 0000000..edf47ef
--- /dev/null
+++ b/tests/spec/khr_gl_texture_image/khr_gl_texture_image.c
@@ -0,0 +1,470 @@
+/*
+ * Copyright © 2012-2013 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.
+ *
+ * Authors:
+ *    Abdiel Janulgue <abdiel.janulgue at linux.intel.com>
+ *    Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
+ *
+ */
+
+#include "piglit-util-gl-common.h"
+#include "piglit-util-egl.h"
+
+#define TEXTURE_SIZE  64
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+	config.supports_gl_es_version = 20;
+
+	config.window_width = TEXTURE_SIZE * 7;
+	config.window_height = TEXTURE_SIZE * 7;
+	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+const GLenum egl_cube_face_targets[6] = {
+	EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR,
+	EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_X_KHR,
+	EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Y_KHR,
+	EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR,
+	EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR,
+	EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR,
+};
+
+static GLfloat colors[][4] = {
+	{1.0, 1.0, 1.0, 1.0},
+	{1.0, 1.0, 0.0, 1.0},
+	{1.0, 0.0, 0.0, 1.0},
+	{1.0, 0.0, 1.0, 1.0},
+	{0.0, 0.0, 1.0, 1.0},
+	{0.0, 1.0, 1.0, 1.0},
+	{0.0, 1.0, 0.0, 1.0},
+};
+
+static bool test_cubemap = false;
+static bool test_2d = false;
+
+struct target_textures {
+	GLuint source_texture;
+	EGLImageKHR *images;
+	GLuint *target_textures;
+	int levels;
+};
+
+struct cubemap {
+	GLuint source_texture;
+	struct target_textures *faces[6];
+};
+
+static const char
+vertex_shader[] =
+	"attribute vec4 pos_attrib;\n"
+	"attribute vec2 tex_attrib;\n"
+	"varying vec2 tex_coord;\n"
+	"void main () {\n"
+	"gl_Position = pos_attrib;\n"
+	"tex_coord = tex_attrib;\n"
+	"}\n";
+
+static const char
+fragment_shader[] =
+	"precision mediump float;\n"
+	"uniform sampler2D tex;\n"
+	"varying vec2 tex_coord;\n"
+	"void main () {\n"
+	"gl_FragColor = texture2D(tex, tex_coord);\n"
+	"}\n";
+
+static void
+make_program(const char *vertex_source,
+	     const char *fragment_source)
+{
+	GLuint program, shader;
+	GLuint uniform;
+
+	program = glCreateProgram();
+	shader = piglit_compile_shader_text(GL_VERTEX_SHADER, vertex_source);
+	glAttachShader(program, shader);
+	shader = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fragment_source);
+	glAttachShader(program, shader);
+
+	glBindAttribLocation(program, PIGLIT_ATTRIB_POS, "pos_attrib");
+	glBindAttribLocation(program, PIGLIT_ATTRIB_TEX, "tex_attrib");
+
+	glLinkProgram(program);
+	if (!piglit_link_check_status(program))
+		piglit_report_result(PIGLIT_FAIL);
+
+	uniform = glGetUniformLocation(program, "tex");
+	glUseProgram(program);
+	glUniform1i(uniform, 0);
+}
+
+static void
+create_egl_image_target(EGLenum target, struct target_textures *targets, GLuint level)
+{
+	GLuint tex;
+	EGLint attribs[] = {
+		EGL_GL_TEXTURE_LEVEL_KHR, level,
+		EGL_NONE
+	};
+
+	EGLDisplay dpy = eglGetCurrentDisplay();
+	EGLContext ctx = eglGetCurrentContext();
+	EGLClientBuffer buffer =
+		(EGLClientBuffer) (uintptr_t) targets->source_texture;
+
+	targets->images[level] =
+		eglCreateImageKHR(dpy, ctx, target, buffer, attribs);
+	if (targets->images[level] == EGL_NO_IMAGE_KHR)
+		piglit_report_result(PIGLIT_FAIL);
+
+	glGenTextures(1, &tex);
+	glBindTexture(GL_TEXTURE_2D, tex);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+			GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+			GL_LINEAR);
+	glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, targets->images[level]);
+
+	targets->target_textures[level] = tex;
+}
+
+static struct target_textures *
+create_egl_images_and_targets(EGLenum egl_target, GLuint texture, int levels)
+{
+	struct target_textures *targets = malloc(sizeof *targets);
+	int l;
+
+	targets->source_texture = texture;
+	targets->levels = levels;
+	targets->images = malloc(sizeof targets->images[0] * levels);
+	targets->target_textures =
+		malloc(sizeof targets->target_textures[0] * levels);
+
+	for (l = 0; l < levels; l++)
+		create_egl_image_target(egl_target, targets, l);
+
+	return targets;
+}
+
+static void
+set_face_image(int level, GLenum face, int size, int color)
+{
+	GLfloat *color1 = colors[color];
+	GLfloat *color2 = colors[(color + 1) % ARRAY_SIZE(colors)];
+	GLubyte *tex;
+	int x, y;
+
+	tex = malloc(size * size * 4 * sizeof(GLubyte));
+
+	for (y = 0; y < size; y++) {
+		for (x = 0; x < size; x++) {
+			GLfloat *chosen_color;
+
+			if (y >= (size / 2) || x >= (size / 2))
+				chosen_color = color1;
+			else
+				chosen_color = color2;
+
+			tex[(y * size + x) * 4 + 0] = chosen_color[0] * 255;
+			tex[(y * size + x) * 4 + 1] = chosen_color[1] * 255;
+			tex[(y * size + x) * 4 + 2] = chosen_color[2] * 255;
+			tex[(y * size + x) * 4 + 3] = 255;
+		}
+	}
+
+	glTexImage2D(face, level, GL_RGBA, size, size, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex);
+	piglit_check_gl_error(GL_NO_ERROR);
+
+	free(tex);
+}
+
+static struct cubemap *
+make_cubemap_texture(int size)
+{
+	struct cubemap *cubemap = malloc(sizeof *cubemap);
+
+	GLuint texture;
+	int f, sz, level, color = 0;
+
+	glGenTextures(1, &texture);
+	glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
+	glTexParameteri(GL_TEXTURE_CUBE_MAP,
+			GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
+	glTexParameteri(GL_TEXTURE_CUBE_MAP,
+			GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+	glTexParameteri(GL_TEXTURE_CUBE_MAP,
+			GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_CUBE_MAP,
+			GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+	for (sz = size, level = 0 ; sz > 0; sz >>= 1) {
+		for (f = 0; f < 6; f++)
+			glTexImage2D(cube_face_targets[f], level, GL_RGBA, sz, sz, 0,
+				     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+		level++;
+	}
+
+	cubemap->source_texture = texture;
+	for (f = 0; f < 6; f++)
+		cubemap->faces[f] =
+			create_egl_images_and_targets(egl_cube_face_targets[f],
+						      texture, level);
+
+	glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
+
+	/* Generate colors in miplevel-major ordering to avoid repeating
+	 * the same sequence of miplevel colors per face;
+	 */
+	for (sz = size, level = 0; sz > 0; sz >>= 1) {
+		for (f = 0; f < 6; ++f) {
+			set_face_image(level, cube_face_targets[f], sz, color);
+			color = (color + 1) % ARRAY_SIZE(colors);
+		}
+		level++;
+	}
+
+	return cubemap;
+}
+
+static struct target_textures *
+make_2d_texture(int size)
+{
+	GLuint texture;
+	int sz, level = 0, color = 0;
+	struct target_textures *targets;
+
+	glGenTextures(1, &texture);
+	glBindTexture(GL_TEXTURE_2D, texture);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
+			GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
+			GL_LINEAR_MIPMAP_NEAREST);
+
+	for (sz = size; sz > 0; sz >>= 1) {
+		glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, sz, sz, 0,
+			     GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+		level++;
+	}
+
+	targets = create_egl_images_and_targets(EGL_GL_TEXTURE_2D_KHR, texture, level);
+
+	glBindTexture(GL_TEXTURE_2D, texture);
+
+	for (sz = size, level = 0; sz > 0; sz >>= 1) {
+		set_face_image(level, GL_TEXTURE_2D, sz, color);
+		color = (color + 1) % ARRAY_SIZE(colors);
+		level++;
+	}
+
+	return targets;
+}
+
+static bool
+test_results(int x, int y, int size, int color)
+{
+	GLfloat *color1 = colors[color];
+	GLfloat *color2 = colors[(color + 1) % ARRAY_SIZE(colors)];
+	bool pass = true;
+
+	if (size == 1) {
+		pass = pass && piglit_probe_rect_rgba(x, y,
+						     size/2, size/2, color1);
+	} else {
+		pass = pass && piglit_probe_rect_rgba(x, y,
+						      size/2, size/2,
+						      color2);
+		pass = pass && piglit_probe_rect_rgba(x + size/2, y,
+						      size/2, size, color1);
+		pass = pass && piglit_probe_rect_rgba(x, y + size/2,
+						      size/2,size/2,color1);
+	}
+
+	return pass;
+}
+
+static bool
+test_2d_texture(int texture_size)
+{
+	int color = ARRAY_SIZE(colors) - 1;
+	int level, y = 0, size = 1;
+	bool pass = true;
+
+	for (level = texture_size; level > 0; level >>= 1) {
+		pass = test_results(0, y, size, color) && pass;
+		y += TEXTURE_SIZE;
+		size *=2;
+		color--;
+	}
+
+	return pass;
+}
+
+/**
+ * Test if cubemap faces from all miplevels are rendered correctly.
+ */
+static bool
+test_cubemap_texture(int texture_size, int num_level)
+{
+	static int sz = ARRAY_SIZE(colors);
+	int color = sz - 1;
+	int face, dim, size = 1, r = 0, mip_level = num_level;
+	int x, y = 0;
+
+	x = piglit_width - texture_size;
+	for (dim = texture_size; dim > 0; dim >>= 1) {
+		mip_level--;
+		y = texture_size;
+		for (face = 5; face >= 0; face--) {
+			if (!test_results(x, y, size, color)) {
+				printf("Cube map failed at "
+				       "miplevel %d, face %s\n",
+				       mip_level, cube_face_names[face]);
+				return false;
+			}
+			y += texture_size;
+			r = (r + 1) % sz;
+			color = sz - r - 1;
+		}
+		x -= texture_size;
+		size *= 2;
+	}
+
+	return true;
+}
+
+/**
+ * Draws all cubemap face textures in miplevel-major notation
+ */
+static int
+draw_cubemap_textures(struct cubemap *cubemap, int tex_sz, float tex_box)
+{
+	float x, y, size;
+	int tex_size, face, level = 0;
+
+	x = -1.0;
+	level = 0;
+	size = tex_box;
+	for (tex_size = tex_sz; tex_size > 0; tex_size >>= 1) {
+		y = 1.0;
+		for (face = 0; face < 6; face++) {
+			y -= tex_box;
+			glBindTexture(GL_TEXTURE_2D,
+				      cubemap->faces[face]->target_textures[level]);
+			piglit_draw_rect_tex(x, y, size, size, 0, 0, 1, 1);
+		}
+		x += tex_box;
+		size /=2;
+		level++;
+	}
+
+	return level;
+}
+
+static void
+draw_2d_texture(struct target_textures *targets, int tex_sz, float tex_box)
+{
+	float size = tex_box, y = 1.0;
+	int tex_size, level = 0;
+
+	for (tex_size = tex_sz; tex_size > 0; tex_size >>= 1) {
+		y -= tex_box;
+		glBindTexture(GL_TEXTURE_2D, targets->target_textures[level]);
+		piglit_draw_rect_tex(-1, y, size, size,  0, 0, 1, 1);
+		size /=2;
+		level++;
+	}
+}
+
+enum piglit_result
+piglit_display(void)
+{
+	/* Bounding box size for each test image to layout
+	   nicely within our test window
+	 */
+	const float tex_box = 2.0 * (1.0 / (piglit_width/TEXTURE_SIZE));
+
+	struct target_textures *tex_2d;
+	struct cubemap *tex_cubemap;
+	bool pass = true;
+	int levels;
+
+	glClearColor(0,0, 0, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	/* Set up a source texture object with mipmap generation */
+	if (test_2d)
+		tex_2d = make_2d_texture(TEXTURE_SIZE);
+	if (test_cubemap)
+		tex_cubemap = make_cubemap_texture(TEXTURE_SIZE);
+
+	glActiveTexture(GL_TEXTURE0);
+	make_program(vertex_shader, fragment_shader);
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		pass = false;
+
+	/* Generate EGLImage target textures from source texture
+	   and render all miplevels */
+	if (test_2d)
+		draw_2d_texture(tex_2d, TEXTURE_SIZE, tex_box);
+	if (test_cubemap)
+		levels = draw_cubemap_textures(tex_cubemap, TEXTURE_SIZE, tex_box);
+
+	if (!piglit_check_gl_error(GL_NO_ERROR))
+		pass = false;
+	piglit_present_results();
+
+	/* Check if we have rendered correctly */
+	if (test_2d)
+		pass = pass && test_2d_texture(TEXTURE_SIZE);
+	if (test_cubemap)
+		pass = pass && test_cubemap_texture(TEXTURE_SIZE, levels);
+
+	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+	int i;
+	EGLDisplay dpy = eglGetCurrentDisplay();
+
+	for (i = 1; i < argc; ++i) {
+		if (!strcmp(argv[i], "-2d")) {
+			if (!piglit_is_egl_extension_supported(dpy,
+						      "EGL_KHR_gl_texture_2D_image"))
+				piglit_report_result(PIGLIT_SKIP);
+			test_2d = true;
+			break;
+		}
+		if (!strcmp(argv[i], "-cubemap")) {
+			if (!piglit_is_egl_extension_supported(dpy,
+						     "KHR_gl_texture_cubemap_image"))
+				piglit_report_result(PIGLIT_SKIP);
+			test_cubemap = true;
+			break;
+		}
+	}
+}
-- 
1.7.9.5



More information about the Piglit mailing list