[Piglit] [PATCH 02/15] arb_direct_state_access: Testing NamedBufferStorage.

Martin Peres martin.peres at linux.intel.com
Wed Apr 1 05:25:59 PDT 2015



On 23/01/15 21:03, Laura Ekstrand wrote:
> ---
>   tests/all.py                                       |   1 +
>   .../spec/arb_direct_state_access/CMakeLists.gl.txt |   1 +
>   .../arb_direct_state_access/namedbufferstorage.c   | 283 +++++++++++++++++++++
>   3 files changed, 285 insertions(+)
>   create mode 100644 tests/spec/arb_direct_state_access/namedbufferstorage.c
>
> diff --git a/tests/all.py b/tests/all.py
> index 32aa60a..7df3787 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -4421,6 +4421,7 @@ spec['ARB_direct_state_access']['getcompressedtextureimage'] = PiglitGLTest(['ar
>   spec['ARB_direct_state_access']['texture-storage-multisample'] = PiglitGLTest(['arb_direct_state_access-texture-storage-multisample'], run_concurrent=True)
>   spec['ARB_direct_state_access']['texture-buffer'] = PiglitGLTest(['arb_direct_state_access-texture-buffer'], run_concurrent=True)
>   spec['ARB_direct_state_access']['texture-buffer-range'] = PiglitGLTest(['arb_direct_state_access-texture-buffer-range'], run_concurrent=True)
> +spec['ARB_direct_state_access']['namedbufferstorage-persistent'] = PiglitGLTest(['arb_direct_state_access-namedbufferstorage-persistent'], run_concurrent=True)
>   
>   profile.tests['hiz'] = hiz
>   profile.tests['fast_color_clear'] = fast_color_clear
> diff --git a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
> index 26c0099..9228917 100644
> --- a/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
> +++ b/tests/spec/arb_direct_state_access/CMakeLists.gl.txt
> @@ -9,6 +9,7 @@ link_libraries (
>   	${OPENGL_glu_LIBRARY}
>   )
>   
> +piglit_add_executable (arb_direct_state_access-namedbufferstorage-persistent namedbufferstorage.c)
>   piglit_add_executable (arb_direct_state_access-dsa-textures dsa-textures.c dsa-utils.c)
>   piglit_add_executable (arb_direct_state_access-texturesubimage texturesubimage.c)
>   piglit_add_executable (arb_direct_state_access-bind-texture-unit bind-texture-unit.c)
> diff --git a/tests/spec/arb_direct_state_access/namedbufferstorage.c b/tests/spec/arb_direct_state_access/namedbufferstorage.c
> new file mode 100644
> index 0000000..2ddfab6
> --- /dev/null
> +++ b/tests/spec/arb_direct_state_access/namedbufferstorage.c
> @@ -0,0 +1,283 @@
> +/*
> + * Copyright © 2014 Advanced Micro Devices, Inc.
> + * All rights reserved.
> + * Copyright 2015 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.
> + *
> + * Authors:
> + *    Marek Olšák <marek.olsak at amd.com>
> + *    Laura Ekstrand <laura at jlekstrand.net>
> + *
> + * Adapted to test NamedBufferStorage by Laura Ekstrand <laura at jlekstrand.net>
> + * January 2015
> + */
> +
> +#include "piglit-util-gl.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_compat_version = 10;

You may want to ask for gl_core_version = 32, like you did for your 
texture tests.
> +	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +#define BUF_SIZE (12 * 4 * sizeof(float))
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	piglit_require_gl_version(15);
> +	piglit_require_extension("GL_ARB_buffer_storage");
> +	piglit_require_extension("GL_ARB_map_buffer_range");
This one would not be needed because the extension got introduced in 
OpenGL 3.0.

Otherwise, with all the other relevant commits squashed in this one, 
this is:

Reviewed-by: Martin Peres <martin.peres at linux.intel.com>
> +	piglit_require_extension("GL_ARB_direct_state_access");
> +
> +	piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
> +}
> +
> +static bool
> +create_mapped_buffer(GLuint *buffer, GLfloat **map, GLboolean coherent,
> +		     GLboolean client_storage)
> +{
> +	glCreateBuffers(1, buffer);
> +	glNamedBufferStorage(*buffer, BUF_SIZE, NULL,
> +			     GL_MAP_WRITE_BIT |
> +			     GL_MAP_PERSISTENT_BIT |
> +			     (coherent ? GL_MAP_COHERENT_BIT : 0) |
> +			     GL_DYNAMIC_STORAGE_BIT |
> +			     (client_storage ? GL_CLIENT_STORAGE_BIT : 0));
> +	glBindBuffer(GL_ARRAY_BUFFER, *buffer);
> +
> +	piglit_check_gl_error(GL_NO_ERROR);
> +
> +	*map = glMapBufferRange(GL_ARRAY_BUFFER, 0, BUF_SIZE,
> +			        GL_MAP_WRITE_BIT |
> +			        GL_MAP_PERSISTENT_BIT |
> +			        (coherent ? GL_MAP_COHERENT_BIT : 0));
> +
> +	piglit_check_gl_error(GL_NO_ERROR);
> +
> +	if (!*map)
> +		return false;
> +
> +	glBindBuffer(GL_ARRAY_BUFFER, 0);
> +
> +	return true;
> +}
> +
> +static enum piglit_result result = PIGLIT_PASS;
> +static float white[4] = {1.0, 1.0, 1.0, 0.0};
> +static float black[4] = {0.0, 0.0, 0.0, 0.0};
> +#define RECT_WIDTH 20
> +#define RECT_HEIGHT 10
> +
> +/**
> + * Looks like this:
> + * ----------
> + * |    HHHH|
> + * |HHHH    |
> + * |    HHHH|
> + * |HHHH    |
> + * ----------
> + */
> +static float array[] = {
> +	1 * RECT_WIDTH, 0 * RECT_HEIGHT, 0,
> +	1 * RECT_WIDTH, 1 * RECT_HEIGHT, 0,
> +	0 * RECT_WIDTH, 0 * RECT_HEIGHT, 0,
> +	0 * RECT_WIDTH, 1 * RECT_HEIGHT, 0,
> +
> +	2 * RECT_WIDTH, 1 * RECT_HEIGHT, 0,
> +	2 * RECT_WIDTH, 2 * RECT_HEIGHT, 0,
> +	1 * RECT_WIDTH, 1 * RECT_HEIGHT, 0,
> +	1 * RECT_WIDTH, 2 * RECT_HEIGHT, 0,
> +
> +	1 * RECT_WIDTH, 2 * RECT_HEIGHT, 0,
> +	1 * RECT_WIDTH, 3 * RECT_HEIGHT, 0,
> +	0 * RECT_WIDTH, 2 * RECT_HEIGHT, 0,
> +	0 * RECT_WIDTH, 3 * RECT_HEIGHT, 0,
> +
> +	2 * RECT_WIDTH, 3 * RECT_HEIGHT, 0,
> +	2 * RECT_WIDTH, 4 * RECT_HEIGHT, 0,
> +	1 * RECT_WIDTH, 3 * RECT_HEIGHT, 0,
> +	1 * RECT_WIDTH, 4 * RECT_HEIGHT, 0
> +};
> +
> +static void
> +verify_rect(bool *pass, int hpos, int vpos, const float *expected)
> +{
> +	*pass = piglit_probe_rect_rgb(hpos * RECT_WIDTH, vpos * RECT_HEIGHT,
> +				      RECT_WIDTH, RECT_HEIGHT,
> +				      expected) && *pass;
> +}
> +
> +static void
> +draw_subtest(GLboolean coherent, GLboolean client_storage)
> +{
> +	GLuint buffer;
> +	GLfloat *map;
> +	bool pass = true;
> +
> +	if (!create_mapped_buffer(&buffer, &map, coherent, client_storage)) {
> +		piglit_report_subtest_result(PIGLIT_FAIL,
> +			"draw%s%s", coherent ? " coherent" : "",
> +			client_storage ? " client-storage" : "");
> +		result = PIGLIT_FAIL;
> +		return;
> +	}
> +
> +	glClear(GL_COLOR_BUFFER_BIT);
> +	glEnableClientState(GL_VERTEX_ARRAY);
> +	glBindBuffer(GL_ARRAY_BUFFER, buffer);
> +	glVertexPointer(3, GL_FLOAT, 0, 0);
> +	glBindBuffer(GL_ARRAY_BUFFER, 0);
> +
> +	memcpy(map, array, 12 * sizeof(float));
> +	if (!coherent)
> +		glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT);
> +
> +	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
> +
> +	memcpy(map+12, array+12, 12 * sizeof(float));
> +	if (!coherent)
> +		glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT);
> +
> +	glDrawArrays(GL_TRIANGLE_STRIP, 4, 4);
> +
> +	memcpy(map+12*2, array+12*2, 12 * sizeof(float));
> +	if (!coherent)
> +		glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT);
> +
> +	glDrawArrays(GL_TRIANGLE_STRIP, 8, 4);
> +
> +	memcpy(map+12*3, array+12*3, 12 * sizeof(float));
> +	if (!coherent)
> +		glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT);
> +
> +	glDrawArrays(GL_TRIANGLE_STRIP, 12, 4);
> +
> +	piglit_check_gl_error(0);
> +
> +	if (!piglit_automatic)
> +		piglit_present_results();
> +
> +	verify_rect(&pass, 0, 0, white);
> +	verify_rect(&pass, 1, 1, white);
> +	verify_rect(&pass, 0, 2, white);
> +	verify_rect(&pass, 1, 3, white);
> +
> +	verify_rect(&pass, 1, 0, black);
> +	verify_rect(&pass, 0, 1, black);
> +	verify_rect(&pass, 1, 2, black);
> +	verify_rect(&pass, 0, 3, black);
> +
> +	glDisableClientState(GL_VERTEX_ARRAY);
> +
> +	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
> +		"draw%s%s", coherent ? " coherent" : "",
> +		client_storage ? " client-storage" : "");
> +
> +	if (!pass)
> +		result = PIGLIT_FAIL;
> +}
> +
> +static void
> +read_subtest(GLboolean coherent, GLboolean client_storage)
> +{
> +	GLuint buffer;
> +	GLfloat *map;
> +	bool pass = true;
> +
> +	int i;
> +	GLuint srcbuf;
> +
> +	if (!create_mapped_buffer(&buffer, &map, coherent, client_storage)) {
> +		piglit_report_subtest_result(PIGLIT_FAIL,
> +			"read%s%s", coherent ? " coherent" : "",
> +			client_storage ? " client-storage" : "");
> +		result = PIGLIT_FAIL;
> +		return;
> +	}
> +
> +	glClear(GL_COLOR_BUFFER_BIT);
> +	glCreateBuffers(1, &srcbuf);
> +	glBindBuffer(GL_COPY_READ_BUFFER, srcbuf);
> +	glBufferData(GL_COPY_READ_BUFFER, BUF_SIZE, array, GL_STATIC_DRAW);
> +
> +	/* Copy some data to the mapped buffer and check if the CPU can see it. */
> +	glBindBuffer(GL_COPY_WRITE_BUFFER, buffer);
> +	glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
> +			    0, 0, BUF_SIZE);
> +
> +	glBindBuffer(GL_COPY_READ_BUFFER, 0);
> +	glBindBuffer(GL_COPY_WRITE_BUFFER, 0);
> +	glDeleteBuffers(1, &srcbuf);
> +
> +	if (!coherent)
> +		glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT);
> +
> +	/* Wait for the GPU to flush */
> +	glFinish();
> +
> +	for (i = 0; i < ARRAY_SIZE(array); i++) {
> +		if (map[i] != array[i]) {
> +			printf("Probe [%i] failed. Expected: %f  Observed: %f\n",
> +			       i, array[i], map[i]);
> +			pass = false;
> +		}
> +	}
> +
> +	piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
> +		"read%s%s", coherent ? " coherent" : "",
> +		client_storage ? " client-storage" : "");
> +
> +	if (!pass)
> +		result = PIGLIT_FAIL;
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	/* !Coherent draw subtests: require MemoryBarrier */
> +	if (piglit_is_extension_supported("GL_ARB_shader_image_load_store")) {
> +		draw_subtest(false, false);
> +		draw_subtest(false, true);
> +	}
> +
> +	/* Coherent draw subtests */
> +	draw_subtest(true, false);
> +	draw_subtest(true, true);
> +
> +	/* Need copy buffer extension for read tests */
> +	if (piglit_is_extension_supported("GL_ARB_copy_buffer")) {
> +
> +		/* !Coherent read subtests: require MemoryBarrier */
> +		if (piglit_is_extension_supported(
> +		       "GL_ARB_shader_image_load_store")) {
> +			read_subtest(false, false);
> +			read_subtest(false, true);
> +		}
> +
> +		/* Coherent read subtests */
> +		read_subtest(true, false);
> +		read_subtest(true, true);
> +	}
> +
> +	return result;
> +}



More information about the Piglit mailing list