[Piglit] [PATCH 6/6] arb_transform_feedback3: add test trying to set invalid separate mode

Ian Romanick idr at freedesktop.org
Sat Oct 26 02:15:54 CEST 2013


On 10/22/2013 06:48 AM, Topi Pohjolainen wrote:
> Pass on NVIDIA (319.60 on GTX 660).
> 
> Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
> ---
>  tests/all.tests                                    |   1 +
>  .../spec/arb_transform_feedback3/CMakeLists.gl.txt |   1 +
>  .../arb_transform_feedback3/set_invalid_varyings.c | 191 +++++++++++++++++++++
>  3 files changed, 193 insertions(+)
>  create mode 100644 tests/spec/arb_transform_feedback3/set_invalid_varyings.c
> 
> diff --git a/tests/all.tests b/tests/all.tests
> index 172bf04..156444a 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -2360,6 +2360,7 @@ arb_transform_feedback3['arb_transform_feedback3-ext_interleaved_draw_streams']
>  arb_transform_feedback3['arb_transform_feedback3-bind_buffer_invalid_index'] = PlainExecTest(['arb_transform_feedback3-bind_buffer_invalid_index', '-auto'])
>  arb_transform_feedback3['arb_transform_feedback3-draw_using_invalid_stream_index'] = PlainExecTest(['arb_transform_feedback3-draw_using_invalid_stream_index', '-auto'])
>  arb_transform_feedback3['arb_transform_feedback3-set_varyings_with_invalid_args'] = PlainExecTest(['arb_transform_feedback3-set_varyings_with_invalid_args', '-auto'])
> +arb_transform_feedback3['arb_transform_feedback3-set_invalid_varyings'] = PlainExecTest(['arb_transform_feedback3-set_invalid_varyings', '-auto'])
>  
>  for param in ['vs', 'gs', 'gs_max']:
>      arb_transform_feedback3['arb_transform_feedback3-ext_interleaved_two_bufs_vs'] = PlainExecTest(['arb_transform_feedback3-ext_interleaved_two_bufs', '-auto', param])
> diff --git a/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt b/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt
> index 888683a..7112e73 100644
> --- a/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt
> +++ b/tests/spec/arb_transform_feedback3/CMakeLists.gl.txt
> @@ -17,5 +17,6 @@ piglit_add_executable (arb_transform_feedback3-query_with_invalid_index query_wi
>  piglit_add_executable (arb_transform_feedback3-end_query_with_name_zero end_query_with_name_zero.c)
>  piglit_add_executable (arb_transform_feedback3-draw_using_invalid_stream_index draw_using_invalid_stream_index.c)
>  piglit_add_executable (arb_transform_feedback3-set_varyings_with_invalid_args set_varyings_with_invalid_args.c)
> +piglit_add_executable (arb_transform_feedback3-set_invalid_varyings set_invalid_varyings.c)
>  
>  # vim: ft=cmake:
> diff --git a/tests/spec/arb_transform_feedback3/set_invalid_varyings.c b/tests/spec/arb_transform_feedback3/set_invalid_varyings.c
> new file mode 100644
> index 0000000..6868183
> --- /dev/null
> +++ b/tests/spec/arb_transform_feedback3/set_invalid_varyings.c
> @@ -0,0 +1,191 @@
> +/*
> + * Copyright © 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.
> + */
> +
> +#include "piglit-util-gl-common.h"
> +#include "xfb3_common.h"
> +
> +/**
> + * @file set_invalid_varyings.c 
> + *
> + * Tests that varyings for separate attributes cannot be set using keywords
> + * reserved solely for the interleaved use. The spec:
> + *
> + * "The error INVALID_OPERATION is generated by TransformFeedbackVaryings
> + *  if any pointer in <varyings> identifies the special names "gl_NextBuffer",
> + *  "gl_SkipComponents1", "gl_SkipComponents2", "gl_SkipComponents3", or
> + *  "gl_SkipComponents4" and <bufferMode> is not INTERLEAVED_ATTRIBS_NV, or if
> + *  the number of "gl_NextBuffer" pointers in <varyings> is greater than or
> + *  equal to the value of MAX_TRANSFORM_FEEDBACK_BUFFERS."
> + */
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_compat_version = 32;
> +	config.supports_gl_core_version = 32;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static const char gs_simple_text[] =
> +	"#version 150\n"
> +	"layout(points) in;\n"
> +	"layout(points) out;\n"
> +	"out float x1_out;\n"
> +	"void main() {\n"
> +	"  gl_Position = gl_in[0].gl_Position;\n"
> +	"  x1_out = 1.0;\n"
> +	"}";
> +
> +static const struct {
> +	const char *description;
> +	const char *varyings[2];
> +} invalid_for_separated[] = {
> +	{
> +		"gl_NextBuffer should not be accepted in separate mode",
> +		{ "x1_out", "gl_NextBuffer" }
> +	},
> +	{
> +		"gl_SkipComponents1 should not be accepted in separate mode",
> +		{ "gl_SkipComponents1", "x1_out" }
> +	},
> +	{
> +		"gl_SkipComponents2 should not be accepted in separate mode",
> +		{ "gl_SkipComponents2", "x1_out" }
> +	},
> +	{
> +		"gl_SkipComponents3 should not be accepted in separate mode",
> +		{ "gl_SkipComponents3", "x1_out" }
> +	},
> +	{
> +		"gl_SkipComponents4 should not be accepted in separate mode",
> +		{ "gl_SkipComponents4", "x1_out" }
> +	}
> +};
> +
> +static bool
> +try_invalid_separate_mode(GLuint prog)
> +{
> +	unsigned i;
> +
> +	for (i = 0; i < ARRAY_SIZE(invalid_for_separated); ++i) {
> +		glTransformFeedbackVaryings(prog,
> +			ARRAY_SIZE(invalid_for_separated[i].varyings),
> +			invalid_for_separated[i].varyings,
> +			GL_SEPARATE_ATTRIBS);
> +
> +		if (!piglit_check_gl_error(GL_INVALID_OPERATION)) {
> +			printf("fail: %s\n",
> +				invalid_for_separated[i].description);
> +			return false;
> +		}
> +	}
> +
> +	return true;
> +}
> +
> +/**
> + * Dynamically reserve space and setup an array of 'n + n + 1' string pointers
> + * having the following layout:
> + *
> + * [0]: "x_0x00000000"
> + * [1]: "gl_NextBuffer"
> + * [2]: "x_0x00000001"
> + * [3]: "gl_NextBuffer"
> + * ...
> + * [2n]: "x_0x..n"
> + *
> + * For testing the upper bound of sepators (gl_NextBuffer) the varying names
> + * need to be mutually unique as the driver could simply bail out before
> + * encountering 'n' separators simply because the driver did not except already
> + * declared varying.
> + */
> +static bool
> +try_max_separators(GLuint prog, unsigned n)
> +{
> +	static const char var_template[] = "x_0x%08x";
> +	static const char separator[] = "gl_NextBuffer";
> +	/**

You don't want the Doxygen comment magic here.

> +	 * Prepare space for ascii running number having eight hex-digits,
> +	 * format contains three (%08x) -> add four bytes more.
> +	 */
> +	static const unsigned var_length = sizeof(var_template) + 4;
> +	const unsigned var_array_size = 2 * n + 1;
> +	char *var_strings;
> +	const char **var_array;
> +	unsigned i;
> +
> +	var_strings = (char *)malloc((n + 1) * var_length);
> +	var_array = (const char **)malloc(var_array_size *
> +					sizeof(const char *));
> +
> +	for (i = 0; i < n; ++i) {
> +		sprintf(var_strings + (i * var_length), var_template, i);

Since there's only one template, I would just put it directly in the
sprintf call.  Rather than packing everything into one char array, it
would be much easier to understand the code if you used asprintf here
and had separate allocations.  We don't care much about performance or
memory usage in test cases. :)

> +		var_array[2 * i + 0] = var_strings + (i * var_length);
> +		var_array[2 * i + 1] = separator;
> +	}
> +
> +	sprintf(var_strings + (i * var_length), var_template, i);
> +	var_array[2 * i] = var_strings + (i * var_length);
> +
> +	glTransformFeedbackVaryings(prog, var_array_size, var_array,
> +				GL_INTERLEAVED_ATTRIBS);
> +
> +	free(var_array);
> +	free(var_strings);
> +
> +	return piglit_check_gl_error(GL_INVALID_OPERATION);
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	bool pass = true;
> +	GLuint prog;
> +	GLint max_attrib_n;
> +
> +	piglit_require_GLSL_version(150);

GLSL 1.50 is a required part of OpenGL 3.2, so you don't need to
explicitly check for it here.  I think some of the other patches may
have this problem as well.

> +	piglit_require_extension("GL_ARB_transform_feedback3");
> +
> +	glGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS,
> +		&max_attrib_n);
> +	if (!max_attrib_n) {
> +		printf("Maximum number of separete attributes is zero\n");
> +		piglit_report_result(PIGLIT_FAIL);
> +	}
> +
> +	prog = piglit_build_simple_program_multiple_shaders(
> +			GL_VERTEX_SHADER, vs_pass_thru_text,
> +			GL_GEOMETRY_SHADER, gs_simple_text, 0);
> +
> +	/* Try too many attributes */
> +	pass = try_invalid_separate_mode(prog) && pass;
> +	pass = try_max_separators(prog, max_attrib_n) && pass;
> +
> +	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	/* Should never be reached */
> +	return PIGLIT_FAIL;
> +}
> 



More information about the Piglit mailing list