[Piglit] [PATCH v2] KHR image from texture test

Eric Anholt eric at anholt.net
Tue Jan 15 13:35:31 PST 2013


Abdiel Janulgue <abdiel.janulgue at linux.intel.com> writes:
> +#include <EGL/eglext.h>
> +
> +#define WIDTH  448
> +#define HEIGHT 448

Just fold this #define into the config below, since it's never reused.

Oh, and this happens to be TEXTURE_SIZE * (number of texture levels,
which is 7, and that's why tex_box is divided by 7), right?  It took
me a bit to figure out how the drawing was actually working.

> +#define TEXTURE_SIZE  64
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_es_version = 20;
> +
> +	config.window_width = WIDTH;
> +	config.window_height = HEIGHT;
> +	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[][3] = {
> +	{1.0, 1.0, 1.0},
> +	{1.0, 1.0, 0.0},
> +	{1.0, 0.0, 0.0},
> +	{1.0, 0.0, 1.0},
> +	{0.0, 0.0, 1.0},
> +	{0.0, 1.0, 1.0},
> +	{0.0, 1.0, 0.0},
> +};
> +
> +static bool test_cubemap = false;
> +static bool test_2d = false;
> +
> +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[] =
> +	"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);
> +	piglit_link_check_status(program);

This won't report a failure if your program didn't link.

if (!piglit_link_check_status(program))
   piglit_report_result(PIGLIT_FAIL).

(We should really build better helpers for programs that need to do
something between attach and link)

> +static GLuint
> +create_egl_image_target(EGLenum target, GLuint texture, GLuint level)
> +{
> +	GLuint target_texture;
> +	EGLint attribs[] = {
> +		EGL_GL_TEXTURE_LEVEL_KHR, level,
> +		EGL_IMAGE_PRESERVED_KHR, EGL_TRUE,
> +		EGL_NONE
> +	};
> +
> +	EGLDisplay dpy = eglGetCurrentDisplay();
> +	EGLContext ctx = eglGetCurrentContext();
> +	EGLImageKHR image = eglCreateImageKHR(dpy, ctx, target,
> +					      (EGLClientBuffer)(uintptr_t)texture,
> +					      attribs);
> +	if (image == EGL_NO_IMAGE_KHR) {
> +		printf("Warning EGL_NO_IMAGE_KHR  0x%x\n",
> +		       eglGetError());

This is a fatal error, right?  piglit_report_result(PIGLIT_FAIL) here.

> +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;
> +	int x1 = x + size / 4, x2 = x + size * 3 / 4;
> +	int y1 = y + size / 4, y2 = y + size * 3 / 4;
> +
> +	if (size == 1) {
> +		pass = pass && piglit_probe_pixel_rgb(x1, y1, color1);
> +	} else {
> +		pass = pass && piglit_probe_pixel_rgb(x1, y1, color2);
> +		pass = pass && piglit_probe_pixel_rgb(x2, y1, color1);
> +		pass = pass && piglit_probe_pixel_rgb(x2, y2, color1);
> +		pass = pass && piglit_probe_pixel_rgb(x1, y2, color1);

Probe the whole image, so that any alignment issues that just cause
bad pixels near the borders get caught.  I think that's:

                pass = pass & piglit_probe_rect_rgb(x1,
                                                    y1,
                                                    size / 2
                                                    size / 2;
                pass = pass & piglit_probe_rect_rgb(x1 + size / 2,
                                                    y1,
                                                    size / 2,
                                                    size);
                pass = pass & piglit_probe_rect_rgb(x1,
                                                    y1 + size / 2,
                                                    size / 2,
                                                    size / 2);

> +/**
> + * Test if cubemap faces from all miplevels are rendered correctly.
> + * We reverse the order in which face colors are retrieved due to
> + * glReadPixels reading data from Y-bottom and we originally render
> + * from top to bottom.
> + */
> +static bool
> +test_cubemap_texture(int texture_size, int num_level)
> +{
> +	static int sz = ARRAY_SIZE(colors);
> +	int color = sz - 1;
> +	int face, size, dim, r = 0, mip_level = num_level;
> +	int vert_pos, horiz_pos = 0;
> +	int fail_score = 0;
> +
> +	for (size = 1, dim = texture_size; dim > 0; size *= 2, dim >>= 1) {
> +		mip_level--;
> +		for (vert_pos = piglit_width - texture_size, face = 5;
> +		     face >= 0; face--, vert_pos -= texture_size) {

In general, I'd move the things that aren't the iterator (so vert_pos
here) outside of the for () and just leave the iterator in there.
Also, you've got vert and horiz swapped (vert is the x position in
this code, and horiz is y, I'd call them x and y instead.  There's a
similar issue with vert_pos/layout_pos in draw_cubemap_textures.

> +			if (!test_results(vert_pos, horiz_pos, size, color)) {
> +				printf("Cube map failed at "
> +				       "miplevel %d, face %s\n",
> +				       mip_level, cube_face_names[face]);
> +				fail_score++;
> +			}
> +			r = (r + 1) % sz;
> +			color = sz - r - 1;
> +		}
> +		horiz_pos += texture_size;
> +	}
> +
> +	return (!fail_score);

I don't see any need for a fail_score; a boolean would be the same.

> +}


> +	glViewport(0, 0, piglit_width, piglit_height);

I don't think this is strictly needed -- viewport starts out pointing
at the whole default framebuffer.

> +void
> +piglit_init(int argc, char **argv)
> +{
> +	int i;
> +
> +	for (i = 1; i < argc; ++i) {
> +		if (!strcmp(argv[i], "-2d")) {
> +			test_2d = true;
> +			break;
> +		}
> +		if (!strcmp(argv[i], "-cubemap")) {
> +			test_cubemap = true;
> +			break;
> +		}
> +	}
> +
> +	test_2d = test_2d && piglit_is_egl_extension_supported(eglGetCurrentDisplay(),
> +						      "EGL_KHR_gl_texture_2D_image");
> +	test_cubemap = test_cubemap && piglit_is_egl_extension_supported(eglGetCurrentDisplay(),
> +						      "KHR_gl_texture_cubemap_image");

So if you don't have the extension and ask to test just 2d, the test
will report PASS?  It should report SKIP -- you want to have
piglit_require_egl_extension() in the args processing here I think.

> +}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20130115/8c947b0c/attachment.pgp>


More information about the Piglit mailing list