[Piglit] [PATCH 07/18] arb_geometry_shader4: Test valid vertices out count.
Brian Paul
brianp at vmware.com
Tue Jun 11 07:55:13 PDT 2013
On 06/07/2013 12:30 PM, Fabian Bieler wrote:
> Test that glProgramParameter() triggers the required errors.
>
> The value of GEOMETRY_VERTICES_OUT is limited by the implementation
> dependend constants MAX_GEOMETRY_OUTPUT_VERTICES and
> MAX_VERTEX_VARYING_COMPONENTS.
>
>>From the ARB_geometry_shader4 spec (section Errors):
> "The error INVALID_VALUE is generated by ProgramParameteriARB if <pname> is
> GEOMETRY_VERTICES_OUT_ARB and <value> is negative.
>
> The error INVALID_VALUE is generated by ProgramParameteriARB if <pname> is
> GEOMETRY_VERTICES_OUT_ARB and <value> exceeds
> MAX_GEOMETRY_OUTPUT_VERTICES_ARB.
>
> The error INVALID_VALUE is generated by ProgramParameteriARB if <pname> is
> set to GEOMETRY_VERTICES_OUT_ARB and the product of <value> and the sum of
> all components of all active varying variables exceeds
> MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_ARB."
> ---
> tests/all.tests | 2 +
> .../execution/program-parameter/CMakeLists.gl.txt | 1 +
> .../execution/program-parameter/vertices-out.c | 209 +++++++++++++++++++++
> 3 files changed, 212 insertions(+)
> create mode 100644 tests/spec/arb_geometry_shader4/execution/program-parameter/vertices-out.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index f21666a..b6d7cd1 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -2299,6 +2299,8 @@ add_plain_test(arb_map_buffer_alignment, 'arb_map_buffer_alignment-sanity_test')
> arb_geometry_shader4 = Group()
> add_concurrent_test(arb_geometry_shader4, 'program-parameter-input-type')
> add_concurrent_test(arb_geometry_shader4, 'program-parameter-output-type')
> +for mode in ['4', 'tf 1', '32', 'tf 32']:
> + add_concurrent_test(arb_geometry_shader4, 'program-parameter-vertices-out {0}'.format(mode))
> spec['ARB_geometry_shader4'] = arb_geometry_shader4
> add_shader_test_dir(spec['ARB_geometry_shader4'],
> os.path.join(testsDir, 'spec', 'arb_geometry_shader4'),
> diff --git a/tests/spec/arb_geometry_shader4/execution/program-parameter/CMakeLists.gl.txt b/tests/spec/arb_geometry_shader4/execution/program-parameter/CMakeLists.gl.txt
> index aee7a98..5768ead 100644
> --- a/tests/spec/arb_geometry_shader4/execution/program-parameter/CMakeLists.gl.txt
> +++ b/tests/spec/arb_geometry_shader4/execution/program-parameter/CMakeLists.gl.txt
> @@ -12,3 +12,4 @@ link_libraries (
>
> piglit_add_executable (program-parameter-input-type input-type.c)
> piglit_add_executable (program-parameter-output-type output-type.c)
> +piglit_add_executable (program-parameter-vertices-out vertices-out.c)
> diff --git a/tests/spec/arb_geometry_shader4/execution/program-parameter/vertices-out.c b/tests/spec/arb_geometry_shader4/execution/program-parameter/vertices-out.c
> new file mode 100644
> index 0000000..5ffbfae
> --- /dev/null
> +++ b/tests/spec/arb_geometry_shader4/execution/program-parameter/vertices-out.c
> @@ -0,0 +1,209 @@
> +/*
> + * Copyright © 2013 The Piglit project
> + *
> + * 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 vertices-out.c
> + *
> + * Test required errors for wrong GL_GEOMETRY_VERTICES_OUT parameters with
> + * variable number of output components.
> + */
> +
> +#include "common.h"
> +
> +
> +static const char gs_textn[] =
> + "uniform int vertex_count;\n"
> + "varying out float var[n];\n"
> + "void main()\n"
> + "{\n"
> + " for (int i = 0; i < vertex_count; i++) {\n"
> + " gl_Position = vec4(0.0);\n"
> + " for (int j = 0; j < n; j++)\n"
> + " var[j] = 1.0 / exp2(float(j + 1));\n"
> + " EmitVertex();\n"
> + " }\n"
> + "}\n";
> +
> +static const char fs_textn[] =
> + "varying float var[n];\n"
> + "void main()\n"
> + "{\n"
> + " gl_FragColor = vec4(0.0);\n"
> + " for (int j = 0; j < n; j++)\n"
> + " gl_FragColor += vec4(var[j]);\n"
> + "}\n";
> +
> +static bool transform_feedback = false;
> +static int components = -1;
> +
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> + config.supports_gl_compat_version = 20;
> + config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +
> +static bool
> +test_geometry_vertices_out(const GLuint prog)
> +{
> + bool pass = true;
> + int max_geometry_output_vertices;
> + int max_geometry_total_output_components;
> + int max_vertices_out;
> +
> + glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES,
> + &max_geometry_output_vertices);
> + glGetIntegerv(GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS,
> + &max_geometry_total_output_components);
> +
> + printf("Testing negative (-1) vertices out.\n");
> + glProgramParameteri(prog, GL_GEOMETRY_VERTICES_OUT_ARB, -1);
> + pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
> +
> + /* Setting GEOMETRY_VERTICES_OUT to zero should generate no error but
> + * linking with a geometry shader should fail.
> + */
> + printf("Testing zero (0) vertices out.\n");
> + glProgramParameteri(prog, GL_GEOMETRY_VERTICES_OUT_ARB, 0);
> + glLinkProgram(prog);
> + pass = piglit_check_gl_error(GL_NO_ERROR) && piglit_link_check_status_quiet(prog) && pass;
> +
> + printf("Testing too many (%d) vertices out.\n", max_geometry_output_vertices + 1);
> + glProgramParameteri(prog, GL_GEOMETRY_VERTICES_OUT_ARB,
> + max_geometry_output_vertices + 1);
> + pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;
> +
> + /* If MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS results in an even smaller limit for
> + * GEOMETRY_VERTICES_OUT than GL_MAX_GEOMETRY_OUTPUT_VERTICES test that, too.
> + */
> + if (max_geometry_total_output_components / components + 1 < max_geometry_output_vertices + 1) {
> + /* The spec requires ProgramParameter to throw an INVALID_VALUE if
> + * (GEOMETRY_VERTICES_OUT * (sum of components of all out varyings)) >
> + * MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS. But the number of output
> + * components can only be infered from the geometry shader source
> + * (and a geometry shader might not even be attached to the program
> + * object when ProgramParameter is called). Also accept failed linking
> + * for tests that depend on the number of output components.
> + */
> + printf("Testing too many (%d) vertices out (total output components).\n", max_geometry_total_output_components / components + 1);
> + glProgramParameteri(prog, GL_GEOMETRY_VERTICES_OUT_ARB,
> + max_geometry_total_output_components / components + 1);
> + if (!piglit_check_gl_error(GL_INVALID_VALUE) &&
> + (glLinkProgram(prog), piglit_link_check_status(prog))) {
> + pass = false;
> + }
> + }
> +
> + max_vertices_out = MIN2(max_geometry_output_vertices, max_geometry_total_output_components / components);
> + printf("Testing maximal (%d) vertices out.\n", max_vertices_out);
> + glProgramParameteri(prog, GL_GEOMETRY_VERTICES_OUT_ARB,
> + max_vertices_out);
> + glLinkProgram(prog);
> + pass = piglit_check_gl_error(GL_NO_ERROR) &&
> + (glLinkProgram(prog), piglit_link_check_status_quiet(prog)) && pass;
> +
> + glProgramParameteri(prog, GL_GEOMETRY_VERTICES_OUT_ARB, 1);
> +
> + return pass;
> +}
> +
> +
Can you put a comment on this function explaining what the command line
arguments are?
> +static void
> +parse_cmd_line(int argc, char **argv)
> +{
> + int i;
> +
> + for (i = 1; i < argc; i++) {
> + if (strcmp(argv[i], "tf") == 0) {
> + transform_feedback = true;
> + } else if(argv[i][0] != '-') {
> + char *e;
> + long int l = strtol(argv[i], &e, 10);
> + if (*e == '\0')
> + components = l;
> + }
> + }
> +
> + if (transform_feedback) {
> + if ((components < 1) || components > 32) {
> + fprintf(stderr, "Please specify number of components "
> + "from 1 to 32 (inclusive) on the command line\n");
> + piglit_report_result(PIGLIT_FAIL);
> + }
> + } else {
> + if ((components < 4) || components > 32) {
> + fprintf(stderr, "Please specify number of components "
> + "from 4 to 32 (inclusive) on the command line\n");
> + piglit_report_result(PIGLIT_FAIL);
> + }
> + }
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + bool pass = true;
> + GLuint prog;
> + int n;
> + const char *gs_string, *fs_string;
> +
> + parse_cmd_line(argc, argv);
> +
> + /* NV_geometry_shader4 relaxes some restrictions on valid program
> + * parameters.
> + */
> + piglit_require_not_extension("GL_NV_geometry_shader4");
> + if (transform_feedback)
> + piglit_require_extension("GL_EXT_transform_feedback");
> +
> + /* Prepare shader source strings.
> + *
> + * If we're not using transform feedback gl_Position counts for 4 output components.
> + */
> + n = transform_feedback ? components : components - 4;
> + if (n == 0) {
> + gs_string = gs_text4;
> + fs_string = fs_text4;
> + } else {
> + asprintf((char **)&gs_string, "#extension GL_ARB_geometry_shader4: enable\n"
> + "const int n = %d;\n%s", n, gs_textn);
> + if (transform_feedback)
> + fs_string = NULL;
> + else
> + asprintf((char **)&fs_string, "const int n = %d;\n%s", n, fs_textn);
> + }
> +
> + /* Create shader and run test. */
> + prog = create_shader(vs_text, gs_string, fs_string);
> + pass = test_geometry_vertices_out(prog) && pass;
> + glDeleteProgram(prog);
> +
> + piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> + /* Should never be reached */
> + return PIGLIT_FAIL;
> +}
>
>
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
>
More information about the Piglit
mailing list