[Piglit] [PATCH] arb_uniform_buffer_object: Add new tests for GL_MAX_UNIFORM_BLOCK_SIZE.
Ian Romanick
idr at freedesktop.org
Tue Dec 18 11:52:00 PST 2012
On 12/18/2012 10:50 AM, Eric Anholt wrote:
> ---
> tests/all.tests | 4 +
> .../arb_uniform_buffer_object/CMakeLists.gl.txt | 1 +
> .../maxuniformblocksize.c | 237 ++++++++++++++++++++
> 3 files changed, 242 insertions(+)
> create mode 100644 tests/spec/arb_uniform_buffer_object/maxuniformblocksize.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index a471203..74d8f9c 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -1965,6 +1965,10 @@ arb_uniform_buffer_object['layout-std140'] = concurrent_test('arb_uniform_buffer
> arb_uniform_buffer_object['layout-std140-base-size-and-alignment'] = concurrent_test('arb_uniform_buffer_object-layout-std140-base-size-and-alignment')
> arb_uniform_buffer_object['link-mismatch-blocks'] = concurrent_test('arb_uniform_buffer_object-link-mismatch-blocks')
> arb_uniform_buffer_object['maxblocks'] = concurrent_test('arb_uniform_buffer_object-maxblocks')
> +arb_uniform_buffer_object['maxuniformblocksize/vs'] = concurrent_test('arb_uniform_buffer_object-maxuniformblocksize vs')
> +arb_uniform_buffer_object['maxuniformblocksize/vsexceed'] = concurrent_test('arb_uniform_buffer_object-maxuniformblocksize vsexceed')
> +arb_uniform_buffer_object['maxuniformblocksize/fs'] = concurrent_test('arb_uniform_buffer_object-maxuniformblocksize fs')
> +arb_uniform_buffer_object['maxuniformblocksize/fsexceed'] = concurrent_test('arb_uniform_buffer_object-maxuniformblocksize fsexceed')
> arb_uniform_buffer_object['minmax'] = concurrent_test('arb_uniform_buffer_object-minmax')
> arb_uniform_buffer_object['negative-bindbuffer-index'] = concurrent_test('arb_uniform_buffer_object-negative-bindbuffer-index')
> arb_uniform_buffer_object['negative-bindbuffer-target'] = concurrent_test('arb_uniform_buffer_object-negative-bindbuffer-target')
> diff --git a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
> index b2a5b44..b088ab4 100644
> --- a/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
> +++ b/tests/spec/arb_uniform_buffer_object/CMakeLists.gl.txt
> @@ -30,6 +30,7 @@ add_executable (arb_uniform_buffer_object-layout-std140 layout-std140.c)
> add_executable (arb_uniform_buffer_object-layout-std140-base-size-and-alignment layout-std140-base-size-and-alignment.c uniform-types.c)
> add_executable (arb_uniform_buffer_object-link-mismatch-blocks link-mismatch-blocks.c)
> add_executable (arb_uniform_buffer_object-maxblocks maxblocks.c)
> +add_executable (arb_uniform_buffer_object-maxuniformblocksize maxuniformblocksize.c)
> add_executable (arb_uniform_buffer_object-minmax minmax.c)
> add_executable (arb_uniform_buffer_object-negative-bindbuffer-index negative-bindbuffer-index.c)
> add_executable (arb_uniform_buffer_object-negative-bindbuffer-target negative-bindbuffer-target.c)
> diff --git a/tests/spec/arb_uniform_buffer_object/maxuniformblocksize.c b/tests/spec/arb_uniform_buffer_object/maxuniformblocksize.c
> new file mode 100644
> index 0000000..d29b0f7
> --- /dev/null
> +++ b/tests/spec/arb_uniform_buffer_object/maxuniformblocksize.c
> @@ -0,0 +1,237 @@
> +/*
> + * 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 maxblocks.c
> + *
> + * Tests linking and drawing with uniform buffer objects of size
> + * MAX_UNIFORM_BLOCK_SIZE and MAX_UNIFORM_BLOCK_SIZE + 4.
> + *
> + * We test the max size + 4 because implementations are allowed to
> + * link and draw beyond the exposed limits, but at that point there
> + * are no guarantees it will link. Those tests are the "vsexceed" and
> + * "fsexceed" arguments.
> + */
> +
> +#define _GNU_SOURCE
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> + config.supports_gl_compat_version = 10;
> +
> + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_ALPHA;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static enum {
> + VS,
> + VS_EXCEED,
> + FS,
> + FS_EXCEED,
> +} mode;
> +
> +static void
> +usage(const char *name)
> +{
> + fprintf(stderr, "usage: %s <vs | vs_exceed | fs | fs_exceed>\n",
> + name);
> + piglit_report_result(PIGLIT_FAIL);
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> + const char *vs_ubo_template =
> + "#extension GL_ARB_uniform_buffer_object : enable\n"
> + "\n"
> + "varying vec4 vary;"
> + "\n"
> + "layout(std140) uniform ubo {\n"
> + " vec4 v[%d];\n"
> + "};\n"
> + "uniform int i;\n"
> + "\n"
> + "void main() {\n"
> + " gl_Position = gl_Vertex;\n"
> + " vary = v[i];\n"
> + "}\n";
> +
> + const char *fs_template =
> + "#extension GL_ARB_uniform_buffer_object : enable\n"
> + "\n"
> + "varying vec4 vary;"
> + "\n"
> + "void main() {\n"
> + " gl_FragColor = vary;\n"
> + "}\n";
> +
> + const char *vs_template =
> + "#extension GL_ARB_uniform_buffer_object : enable\n"
> + "\n"
> + "void main() {\n"
> + " gl_Position = gl_Vertex;\n"
> + "}\n";
> +
> + const char *fs_ubo_template =
> + "#extension GL_ARB_uniform_buffer_object : enable\n"
> + "\n"
> + "layout(std140) uniform ubo {\n"
> + " vec4 v[%d];\n"
> + "};\n"
> + "uniform int i;\n"
> + "\n"
> + "void main() {\n"
> + " gl_FragColor = v[i];\n"
> + "}\n";
> +
> + char *vs_source, *fs_source;
> + GLint max_size, vec4s, i_location;
> + GLuint vs, fs, prog, bo;
> + GLenum target;
> + float *data;
> + size_t size;
> + bool pass = true;
> + bool may_link_fail;
> + const float green[4] = { 0, 1, 0, 0 };
> +
> + piglit_require_extension("GL_ARB_uniform_buffer_object");
> +
> + glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &max_size);
> + printf("Max uniform block size: %d\n", max_size);
> + vec4s = max_size / 4 / 4;
> +
> + switch (mode) {
> + case VS:
> + target = GL_VERTEX_SHADER;
> + may_link_fail = false;
> + break;
> + case VS_EXCEED:
> + target = GL_VERTEX_SHADER;
> + may_link_fail = true;
> + vec4s++;
> + break;
> + case FS:
> + target = GL_FRAGMENT_SHADER;
> + may_link_fail = false;
> + break;
> + case FS_EXCEED:
> + target = GL_FRAGMENT_SHADER;
> + may_link_fail = true;
> + vec4s++;
> + break;
> + }
> +
> + switch (target) {
> + case GL_VERTEX_SHADER:
> + asprintf(&vs_source, vs_ubo_template, vec4s);
> + asprintf(&fs_source, fs_template);
Is asprintf universally available? I thought we ran into some trouble
with that before... Maybe Vinson will know...
> + printf("Testing VS with uniform block vec4 v[%d]\n", vec4s);
> + break;
> + case GL_FRAGMENT_SHADER:
> + asprintf(&vs_source, vs_template);
> + asprintf(&fs_source, fs_ubo_template, vec4s);
> + printf("Testing FS with uniform block vec4 v[%d]\n", vec4s);
> + break;
> + default:
> + piglit_report_result(PIGLIT_FAIL);
> + }
> +
> + vs = piglit_compile_shader_text(GL_VERTEX_SHADER, vs_source);
> + if (!vs) {
> + fprintf(stderr, "Failed to compile VS:\n%s", vs_source);
> + piglit_report_result(PIGLIT_FAIL);
> + }
> +
> + fs = piglit_compile_shader_text(GL_FRAGMENT_SHADER, fs_source);
> + if (!fs) {
> + fprintf(stderr, "Failed to compile FS:\n%s", fs_source);
> + piglit_report_result(PIGLIT_FAIL);
> + }
> +
> + prog = glCreateProgram();
> + glAttachShader(prog, vs);
> + glAttachShader(prog, fs);
> + glLinkProgram(prog);
piglit_link_simple_program? Or is that not used because of the link
checks below?
> +
> + if (may_link_fail) {
> + if (!piglit_link_check_status_quiet(prog)) {
> + printf("Failed to link with uniform block vec4 "
> + "v[%d]\n", vec4s);
> + piglit_report_result(PIGLIT_PASS);
> + }
> + } else {
> + if (!piglit_link_check_status_quiet(prog)) {
> + fprintf(stderr,
> + "Failed to link with uniform block vec4 "
> + "v[%d]\n", vec4s);
> + return PIGLIT_FAIL;
> + }
> + }
> +
> + size = vec4s * 4 * sizeof(float);
> + glGenBuffers(1, &bo);
> + glBindBuffer(GL_UNIFORM_BUFFER, bo);
> + glBufferData(GL_UNIFORM_BUFFER, size, NULL, GL_DYNAMIC_DRAW);
> + data = glMapBuffer(GL_UNIFORM_BUFFER, GL_READ_WRITE);
> + memset(data, 0, size);
> +
> + data[(vec4s - 1) * 4 + 0] = 0.0;
> + data[(vec4s - 1) * 4 + 1] = 1.0;
> + data[(vec4s - 1) * 4 + 2] = 0.0;
> + data[(vec4s - 1) * 4 + 3] = 0.0;
> +
> + glUseProgram(prog);
> + i_location = glGetUniformLocation(prog, "i");
> + glUniform1i(i_location, vec4s - 1);
> +
> + glUniformBlockBinding(prog, 0, 0);
> + glBindBufferBase(GL_UNIFORM_BUFFER, 0, bo);
> + piglit_draw_rect(-1, -1, 2, 2);
> +
> + pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green);
> +
> + glDeleteProgram(prog);
> +
> + piglit_present_results();
> +
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + if (argc < 2)
> + usage(argv[0]);
> +
> + if (strcmp(argv[1], "vs") == 0)
> + mode = VS;
> + else if (strcmp(argv[1], "vsexceed") == 0)
> + mode = VS_EXCEED;
> + else if (strcmp(argv[1], "fs") == 0)
> + mode = FS;
> + else if (strcmp(argv[1], "fsexceed") == 0)
> + mode = FS_EXCEED;
> + else
> + usage(argv[0]);
> +}
>
More information about the Piglit
mailing list