[Piglit] [PATCH] Add a test for EXT_texture_swizzle and DEPTH_TEXTURE_MODE together.

Brian Paul brianp at vmware.com
Fri Sep 21 08:41:39 PDT 2012


On 09/21/2012 03:47 AM, Kenneth Graunke wrote:
> This tests every possible DEPTH_TEXTURE_MODE with a random smattering of
> EXT_texture_swizzle modes.  While it could be more exhaustive (or use a
> more logically ordered layout), it does catch the bugs I wanted to
> detect.
>
> Signed-off-by: Kenneth Graunke<kenneth at whitecape.org>
> ---
>   tests/all.tests                                    |   1 +
>   tests/spec/CMakeLists.txt                          |   1 +
>   tests/spec/ext_texture_swizzle/CMakeLists.gl.txt   |  14 ++
>   tests/spec/ext_texture_swizzle/CMakeLists.txt      |   1 +
>   .../depth_texture_mode_and_swizzle.c               | 194 +++++++++++++++++++++
>   5 files changed, 211 insertions(+)
>   create mode 100644 tests/spec/ext_texture_swizzle/CMakeLists.gl.txt
>   create mode 100644 tests/spec/ext_texture_swizzle/CMakeLists.txt
>   create mode 100644 tests/spec/ext_texture_swizzle/depth_texture_mode_and_swizzle.c
>
> We could also make it run without EXT_texture_rg and just skip GL_RED,
> but GL_RED is one of the more interesting modes since LUMINANCE/INTENSITY
> are so darn similar.  I figured basically everybody who supports
> EXT_texture_swizzle probably supports ARB_texture_rg anyway, so meh...
>
> diff --git a/tests/all.tests b/tests/all.tests
> index 6f9982b..b049ed3 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -1626,6 +1626,7 @@ spec['ARB_texture_cube_map'] = arb_texture_cube_map
>   arb_texture_cube_map['copyteximage CUBE'] = PlainExecTest(['copyteximage', '-auto', 'CUBE'])
>   add_plain_test(arb_texture_cube_map, 'crash-cubemap-order')
>
> +profile.test_list['spec/EXT_texture_swizzle/depth_texture_mode_and_swizzle'] = concurrent_test('depth_texture_mode_and_swizzle')
>
>   ext_texture_compression_latc = Group()
>   spec['EXT_texture_compression_latc'] = ext_texture_compression_latc
> diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
> index cd374d1..126b218 100644
> --- a/tests/spec/CMakeLists.txt
> +++ b/tests/spec/CMakeLists.txt
> @@ -27,6 +27,7 @@ add_subdirectory (ext_fog_coord)
>   add_subdirectory (ext_framebuffer_multisample)
>   add_subdirectory (ext_packed_depth_stencil)
>   add_subdirectory (ext_packed_float)
> +add_subdirectory (ext_texture_swizzle)
>   add_subdirectory (ext_timer_query)
>   add_subdirectory (ext_transform_feedback)
>   add_subdirectory (nv_conditional_render)
> diff --git a/tests/spec/ext_texture_swizzle/CMakeLists.gl.txt b/tests/spec/ext_texture_swizzle/CMakeLists.gl.txt
> new file mode 100644
> index 0000000..047a199
> --- /dev/null
> +++ b/tests/spec/ext_texture_swizzle/CMakeLists.gl.txt
> @@ -0,0 +1,14 @@
> +include_directories(
> +	${GLEXT_INCLUDE_DIR}
> +	${OPENGL_INCLUDE_PATH}
> +)
> +
> +link_libraries (
> +	piglitutil_${piglit_target_api}
> +	${OPENGL_gl_LIBRARY}
> +	${OPENGL_glu_LIBRARY}
> +)
> +
> +piglit_add_executable (depth_texture_mode_and_swizzle depth_texture_mode_and_swizzle.c)
> +
> +# vim: ft=cmake:
> diff --git a/tests/spec/ext_texture_swizzle/CMakeLists.txt b/tests/spec/ext_texture_swizzle/CMakeLists.txt
> new file mode 100644
> index 0000000..144a306
> --- /dev/null
> +++ b/tests/spec/ext_texture_swizzle/CMakeLists.txt
> @@ -0,0 +1 @@
> +piglit_include_target_api()
> diff --git a/tests/spec/ext_texture_swizzle/depth_texture_mode_and_swizzle.c b/tests/spec/ext_texture_swizzle/depth_texture_mode_and_swizzle.c
> new file mode 100644
> index 0000000..f75e7bc
> --- /dev/null
> +++ b/tests/spec/ext_texture_swizzle/depth_texture_mode_and_swizzle.c
> @@ -0,0 +1,194 @@
> +/*
> + * 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 depth_texture_mode_and_swizzle.c
> + *
> + * Tests the interactions between EXT_texture_swizzle and DEPTH_TEXTURE_MODE.
> + *
> + * From the EXT_texture_swizzle specfication:
> + * "4) How does this interact with depth component textures?
> + *
> + *  RESOLVED: The swizzle is applied after the DEPTH_TEXTURE_MODE. This
> + *  naturally falls out of specifying the swizzle in terms of Table 3.20."
> + *
> + * It would be very easy to write an implementation that respects one or the
> + * other (but not both), or applies them in the wrong order.  This test guards
> + * against those pitfalls.
> + */
> +
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_MAIN(170, 30, GLUT_RGBA | GLUT_DOUBLE)
> +
> +#define Elements(x) (sizeof(x)/sizeof(*(x)))

We have an ARRAY_SIZE() macro already.


> +
> +enum piglit_result
> +piglit_display()
> +{
> +	bool pass = true;
> +	int i = 0;
> +	static const struct {
> +		int depth_mode;
> +		int swizzles[4];

minor nit: s/int/GLenum/


> +		float expected[4];
> +	} tests[] = {
> +		{
> +			GL_INTENSITY,
> +			{ GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
> +			{ .5, .5, .5, .5 }
> +		},
> +		{
> +			GL_INTENSITY,
> +			{ GL_ONE, GL_GREEN, GL_BLUE, GL_ALPHA },
> +			{ 1, .5, .5, .5 }
> +		},
> +		{
> +			GL_LUMINANCE,
> +			{ GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
> +			{ .5, .5, .5, 1 }
> +		},
> +		{
> +			GL_LUMINANCE,
> +			{ GL_RED, GL_ALPHA, GL_ALPHA, GL_ONE },
> +			{ .5, 1, 1, 1 }
> +		},
> +		{
> +			GL_RED,
> +			{ GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
> +			{ .5, 0, 0, 1 }
> +		},
> +		{
> +			GL_RED,
> +			{ GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA },
> +			{ 0, 0, .5, 1 }
> +		},
> +		{
> +			GL_ALPHA,
> +			{ GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
> +			{ 0, 0, 0, 0.5 }
> +		},
> +		{
> +			GL_ALPHA,
> +			{ GL_ONE, GL_GREEN, GL_ALPHA, GL_ZERO },
> +			{ 1, 0, .5, 0 }
> +		},
> +	};
> +
> +	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
> +
> +	glClearColor(0.15, 0.0, 0.0, 1.0);
> +	glClear(GL_COLOR_BUFFER_BIT);
> +
> +	for (i = 0; i<  Elements(tests); i++) {
> +		glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE,
> +				tests[i].depth_mode);
> +		glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA,
> +				 tests[i].swizzles);
> +
> +		piglit_draw_rect(10 + 20 * i, 10, 10, 10);
> +
> +		piglit_probe_rect_rgba(10 + 20 * i, 10, 10, 10,
> +				       tests[i].expected);

Don't you need "pass = piglit_probe_rect_rgba() && pass"?  :)


> +	}
> +
> +	piglit_present_results();
> +
> +	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +/**
> + * Create texel data: a 1x1 depth texture containing 0.5.
> + */
> +void
> +setup_texture()
> +{
> +	GLuint tex;
> +
> +	const float contents = 0.5;
> +
> +	glGenTextures(1,&tex);
> +	glActiveTexture(GL_TEXTURE0);
> +	glBindTexture(GL_TEXTURE_2D, tex);
> +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
> +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
> +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
> +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
> +	glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 1, 1, 0,
> +		     GL_DEPTH_COMPONENT, GL_FLOAT,&contents);
> +
> +	/* Omit the complexity of depth comparisons; just use the raw data. */
> +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
> +}
> +
> +/**
> + * Generate, compile, link, and use the GLSL shaders.
> + */
> +void
> +setup_shaders()
> +{
> +	int vs, fs, prog, tex_location;

another nit:  GLuint vs, fs, prog;

> +
> +	static const char *vs_code =
> +		 "#version 120\n"
> +		 "void main()\n"
> +		 "{\n"
> +		 "   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
> +		 "}\n";
> +	static const char *fs_code =
> +		 "#version 120\n"
> +		 "uniform sampler2D tex;\n"
> +		 "void main()\n"
> +		 "{\n"
> +		 "   gl_FragColor = texture2D(tex, vec2(0.5, 0.5));\n"
> +		 "}\n";
> +
> +	vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_code);
> +	if (!vs) {
> +		printf("VS code:\n%s", vs_code);
> +		piglit_report_result(PIGLIT_FAIL);
> +	}
> +	fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_code);
> +	if (!fs) {
> +		printf("FS code:\n%s", fs_code);
> +		piglit_report_result(PIGLIT_FAIL);
> +	}
> +	prog = piglit_link_simple_program(vs, fs);
> +	if (!piglit_link_check_status(prog))
> +		piglit_report_result(PIGLIT_FAIL);
> +
> +	piglit_UseProgram(prog);
> +
> +	tex_location = piglit_GetUniformLocation(prog, "tex");
> +	piglit_Uniform1i(tex_location, 0);
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	piglit_require_extension("GL_EXT_texture_swizzle");
> +	piglit_require_extension("GL_ARB_texture_rg");

require GLSL too?


> +
> +	setup_shaders();
> +	setup_texture();
> +}

Looks good otherwise.

Reviewed-by: Brian Paul <brianp at vmware.com>


More information about the Piglit mailing list