[Piglit] [PATCH 3/3] arb_compute_shader: Test compute shader synchronization.

Nicolai Hähnle nhaehnle at gmail.com
Tue Apr 12 14:42:39 UTC 2016


 From a quick skim, the tests look good to me.

However, for the synchronization/barrier one, I'd appreciate if you'd 
add a "sanity check" mode similar to the barrier tests for shader 
images. That is, a mode in which the barriers *aren't* emitted, so that 
one can easily see whether/how the tests really do require the barriers.

Cheers,
Nicolai

On 11.04.2016 08:45, Bas Nieuwenhuizen wrote:
> Signed-off-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
> ---
>   tests/all.py                                    |   1 +
>   tests/spec/arb_compute_shader/CMakeLists.gl.txt |   1 +
>   tests/spec/arb_compute_shader/synchronization.c | 658 ++++++++++++++++++++++++
>   3 files changed, 660 insertions(+)
>   create mode 100644 tests/spec/arb_compute_shader/synchronization.c
>
> diff --git a/tests/all.py b/tests/all.py
> index 72c540c..ca1f319 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -4256,6 +4256,7 @@ with profile.group_manager(
>       g(['arb_compute_shader-zero-dispatch-size'], 'zero-dispatch-size')
>       g(['arb_compute_shader-conditional-dispatch'], 'conditional-dispatch')
>       g(['arb_compute_shader-large-block-size'], 'large-block-size')
> +    g(['arb_compute_shader-synchronization'], 'synchronization')
>
>   with profile.group_manager(
>           PiglitGLTest,
> diff --git a/tests/spec/arb_compute_shader/CMakeLists.gl.txt b/tests/spec/arb_compute_shader/CMakeLists.gl.txt
> index a264626..8932941 100644
> --- a/tests/spec/arb_compute_shader/CMakeLists.gl.txt
> +++ b/tests/spec/arb_compute_shader/CMakeLists.gl.txt
> @@ -20,5 +20,6 @@ piglit_add_executable (arb_compute_shader-render-and-compute render-and-compute.
>   piglit_add_executable (arb_compute_shader-zero-dispatch-size zero-dispatch-size.c ${depends})
>   piglit_add_executable (arb_compute_shader-conditional-dispatch conditional-dispatch.c)
>   piglit_add_executable (arb_compute_shader-large-block-size large-block-size.c)
> +piglit_add_executable (arb_compute_shader-synchronization synchronization.c)
>
>   # vim: ft=cmake:
> diff --git a/tests/spec/arb_compute_shader/synchronization.c b/tests/spec/arb_compute_shader/synchronization.c
> new file mode 100644
> index 0000000..43dda95
> --- /dev/null
> +++ b/tests/spec/arb_compute_shader/synchronization.c
> @@ -0,0 +1,658 @@
> +/*
> + * Copyright 2016 Bas Nieuwenhuizen
> + *
> + * 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.
> + */
> +
> +/*
> + * Tests whether reads and writes are synchronized properly for compute shaders.
> + */
> +
> +#include "piglit-util-gl.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_core_version = 42;
> +
> +	config.window_width = 320;
> +	config.window_height = 320;
> +	config.window_visual = PIGLIT_GL_VISUAL_RGB;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +const char *compute_ssbo_write_source =
> +	"#version 420\n"
> +	"#extension GL_ARB_compute_shader : require\n"
> +	"#extension GL_ARB_shader_storage_buffer_object : require\n"
> +	"layout (local_size_x = 256, local_size_y = 1, local_size_z = 1) in;\n"
> +	"layout(binding = 1, std430) buffer Out {\n"
> +	"	int out_arr[];\n"
> +	"};\n"
> +	"uniform int value;\n"
> +	"void main() {\n"
> +	"	out_arr[gl_GlobalInvocationID.x] = value;\n"
> +	"}\n";
> +
> +const char *compute_ssbo_copy_source =
> +	"#version 420\n"
> +	"#extension GL_ARB_compute_shader : require\n"
> +	"#extension GL_ARB_shader_storage_buffer_object : require\n"
> +	"layout (local_size_x = 256, local_size_y = 1, local_size_z = 1) in;\n"
> +	"layout(binding = 0, std430) buffer In {\n"
> +	"	int in_arr[];\n"
> +	"};\n"
> +	"layout(binding = 1, std430) buffer Out {\n"
> +	"	int out_arr[];\n"
> +	"};\n"
> +	"void main() {\n"
> +	"	out_arr[gl_GlobalInvocationID.x] =\n"
> +	"		in_arr[gl_GlobalInvocationID.x];\n"
> +	"}\n";
> +
> +const char *compute_image_write_source =
> +	"#version 420\n"
> +	"#extension GL_ARB_compute_shader : require\n"
> +	"layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;\n"
> +	"layout(binding = 1, r32i) uniform iimage2D out_img;\n"
> +	"uniform int value;\n"
> +	"void main() {\n"
> +	"	imageStore(out_img, ivec2(gl_GlobalInvocationID.xy), ivec4(value));\n"
> +	"}\n";
> +
> +const char *compute_image_copy_source =
> +	"#version 420\n"
> +	"#extension GL_ARB_compute_shader : require\n"
> +	"layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;\n"
> +	"layout(binding = 0, r32i) uniform iimage2D in_img;\n"
> +	"layout(binding = 1, r32i) uniform iimage2D out_img;\n"
> +	"void main() {\n"
> +	"	imageStore(out_img, ivec2(gl_GlobalInvocationID.xy),\n"
> +	"		imageLoad(in_img, ivec2(gl_GlobalInvocationID.xy)));\n"
> +	"}\n";
> +
> +const char *vs_passthrough =
> +	"#version 420\n"
> +	"in vec4 piglit_vertex;\n"
> +	"void main() {\n"
> +	"	gl_Position = piglit_vertex;\n"
> +	"}\n";
> +
> +const char *graphics_ssbo_write_source =
> +	"#version 420\n"
> +	"#extension GL_ARB_shader_storage_buffer_object : require\n"
> +	"layout(binding = 1, std430) buffer Out {\n"
> +	"	int out_arr[];\n"
> +	"};\n"
> +	"uniform int value;\n"
> +	"void main() {\n"
> +	"	int index = int(gl_FragCoord.y) * 64 + int(gl_FragCoord.x);\n"
> +	"	out_arr[index] = value;\n"
> +	"}\n";
> +
> +const char *graphics_ssbo_copy_source =
> +	"#version 420\n"
> +	"#extension GL_ARB_shader_storage_buffer_object : require\n"
> +	"layout(binding = 0, std430) buffer In {\n"
> +	"	int in_arr[];\n"
> +	"};\n"
> +	"layout(binding = 1, std430) buffer Out {\n"
> +	"	int out_arr[];\n"
> +	"};\n"
> +	"void main() {\n"
> +	"	int index = int(gl_FragCoord.y) * 64 + int(gl_FragCoord.x);\n"
> +	"	out_arr[index] = in_arr[index];\n"
> +	"}\n";
> +
> +const char *graphics_image_write_source =
> +	"#version 420\n"
> +	"#extension GL_ARB_shader_storage_buffer_object : require\n"
> +	"layout(binding = 1, r32i) uniform iimage2D out_img;\n"
> +	"uniform int value;\n"
> +	"void main() {\n"
> +	"	imageStore(out_img, ivec2(gl_FragCoord.xy), ivec4(value));\n"
> +	"}\n";
> +
> +const char *graphics_image_copy_source =
> +	"#version 420\n"
> +	"#extension GL_ARB_shader_storage_buffer_object : require\n"
> +	"layout(binding = 0, r32i) uniform iimage2D in_img;\n"
> +	"layout(binding = 1, r32i) uniform iimage2D out_img;\n"
> +	"void main() {\n"
> +	"	imageStore(out_img, ivec2(gl_FragCoord.xy),\n"
> +	"		imageLoad(in_img, ivec2(gl_FragCoord.xy)));\n"
> +	"}\n";
> +
> +const char *graphics_fbo_write_source =
> +	"#version 420\n"
> +	"#extension GL_ARB_shader_storage_buffer_object : require\n"
> +	"layout(binding = 1, r32i) uniform iimage2D out_img;\n"
> +	"uniform int value;\n"
> +	"out int dest;\n"
> +	"void main() {\n"
> +	"	dest = value;\n"
> +	"}\n";
> +
> +const char *graphics_fbo_copy_source =
> +	"#version 420\n"
> +	"#extension GL_ARB_shader_storage_buffer_object : require\n"
> +	"layout(binding = 0, r32i) uniform iimage2D in_img;\n"
> +	"out int dest;\n"
> +	"void main() {\n"
> +	"	dest = imageLoad(in_img, ivec2(gl_FragCoord.xy)).x;\n"
> +	"}\n";
> +
> +const char *vs_write_source =
> +	"#version 420\n"
> +	"out int out_value;\n"
> +	"uniform int value;\n"
> +	"void main() {\n"
> +	"	out_value = value;\n"
> +	"	gl_Position = vec4(0.0);\n"
> +	"}\n";
> +
> +const char *vs_copy_source =
> +	"#version 420\n"
> +	"#extension GL_ARB_shader_storage_buffer_object : require\n"
> +	"out int out_value;\n"
> +	"in int in_value;\n"
> +	"void main() {\n"
> +	"	out_value = in_value;\n"
> +	"	gl_Position = vec4(0.0);\n"
> +	"}\n";
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	return PIGLIT_FAIL;
> +}
> +
> +struct test_context {
> +	GLuint compute_ssbo_write;
> +	GLuint compute_ssbo_copy;
> +
> +	GLuint compute_image_write;
> +	GLuint compute_image_copy;
> +
> +	GLuint graphics_ssbo_write;
> +	GLuint graphics_ssbo_copy;
> +
> +	GLuint graphics_image_write;
> +	GLuint graphics_image_copy;
> +
> +	GLuint graphics_feedback_write;
> +	GLuint graphics_feedback_copy;
> +
> +	GLuint graphics_fbo_write;
> +	GLuint graphics_fbo_copy;
> +
> +	GLuint buffers[2];
> +	GLuint textures[2];
> +
> +	GLuint empty_fbo;
> +	GLuint fbos[2];
> +};
> +
> +static unsigned create_compute_program(const char *source)
> +{
> +	GLuint shader, prog;
> +
> +	shader = piglit_compile_shader_text(GL_COMPUTE_SHADER, source);
> +	prog =  piglit_link_simple_program_multiple_shaders(shader, 0);
> +	glDeleteShader(shader);
> +
> +	return prog;
> +}
> +
> +
> +static unsigned create_feedback_program(const char *source)
> +{
> +	GLuint prog, shader;
> +	const GLchar *feedback = "out_value";
> +
> +	shader = piglit_compile_shader_text(GL_VERTEX_SHADER, source);
> +
> +	prog = glCreateProgram();
> +	glAttachShader(prog, shader);
> +
> +	glTransformFeedbackVaryings(prog, 1, &feedback, GL_INTERLEAVED_ATTRIBS);
> +
> +	glLinkProgram(prog);
> +	return prog;
> +}
> +
> +static void init_test_context(struct test_context *ctx)
> +{
> +	int i;
> +
> +	ctx->compute_ssbo_write = create_compute_program(compute_ssbo_write_source);
> +	ctx->compute_ssbo_copy = create_compute_program(compute_ssbo_copy_source);
> +	ctx->compute_image_write = create_compute_program(compute_image_write_source);
> +	ctx->compute_image_copy = create_compute_program(compute_image_copy_source);
> +	ctx->graphics_ssbo_write =
> +	                piglit_build_simple_program(vs_passthrough,
> +	                                            graphics_ssbo_write_source);
> +	ctx->graphics_ssbo_copy =
> +	                piglit_build_simple_program(vs_passthrough,
> +	                                            graphics_ssbo_copy_source);
> +	ctx->graphics_image_write =
> +	                piglit_build_simple_program(vs_passthrough,
> +	                                            graphics_image_write_source);
> +	ctx->graphics_image_copy =
> +	                piglit_build_simple_program(vs_passthrough,
> +	                                            graphics_image_copy_source);
> +	ctx->graphics_fbo_write =
> +	                piglit_build_simple_program(vs_passthrough,
> +	                                            graphics_fbo_write_source);
> +	ctx->graphics_fbo_copy =
> +	                piglit_build_simple_program(vs_passthrough,
> +	                                            graphics_fbo_copy_source);
> +	ctx->graphics_feedback_write = create_feedback_program(vs_write_source);
> +	ctx->graphics_feedback_copy = create_feedback_program(vs_copy_source);
> +
> +	glGenBuffers(2, ctx->buffers);
> +	for (i = 0; i < 2; ++i) {
> +		glBindBuffer(GL_SHADER_STORAGE_BUFFER, ctx->buffers[i]);
> +		glBufferData(GL_SHADER_STORAGE_BUFFER, 16384, NULL,
> +		             GL_STREAM_DRAW);
> +	}
> +
> +	glGenTextures(2, ctx->textures);
> +	glGenFramebuffers(2, ctx->fbos);
> +
> +	for (i = 0; i < 2; ++i) {
> +		glBindTexture(GL_TEXTURE_2D, ctx->textures[i]);
> +		glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32I, 64, 64);
> +
> +		glBindFramebuffer(GL_FRAMEBUFFER, ctx->fbos[i]);
> +		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
> +		                       GL_TEXTURE_2D, ctx->textures[i], 0);
> +	}
> +
> +	glGenFramebuffers(1, &ctx->empty_fbo);
> +	glBindFramebuffer(GL_FRAMEBUFFER, ctx->empty_fbo);
> +	glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_WIDTH, 64);
> +	glFramebufferParameteri(GL_FRAMEBUFFER, GL_FRAMEBUFFER_DEFAULT_HEIGHT, 64);
> +	glBindFramebuffer(GL_FRAMEBUFFER, 0);
> +
> +}
> +
> +static void deinit_test_context(struct test_context *ctx)
> +{
> +	glDeleteProgram(ctx->compute_ssbo_write);
> +	glDeleteProgram(ctx->compute_ssbo_copy);
> +	glDeleteProgram(ctx->compute_image_write);
> +	glDeleteProgram(ctx->compute_image_copy);
> +	glDeleteProgram(ctx->graphics_ssbo_write);
> +	glDeleteProgram(ctx->graphics_ssbo_copy);
> +	glDeleteProgram(ctx->graphics_image_write);
> +	glDeleteProgram(ctx->graphics_image_copy);
> +	glDeleteProgram(ctx->graphics_feedback_write);
> +	glDeleteProgram(ctx->graphics_feedback_copy);
> +	glDeleteProgram(ctx->graphics_fbo_write);
> +	glDeleteProgram(ctx->graphics_fbo_copy);
> +
> +	glDeleteBuffers(2, ctx->buffers);
> +	glDeleteTextures(2, ctx->textures);
> +
> +	glDeleteFramebuffers(1, &ctx->empty_fbo);
> +	glDeleteFramebuffers(2, ctx->fbos);
> +}
> +
> +static void setup_test(struct test_context *ctx)
> +{
> +	int i;
> +	int clear_colors[4] = {0};
> +
> +	for(i = 0; i < 2; ++i) {
> +		int *data;
> +		glBindBuffer(GL_SHADER_STORAGE_BUFFER, ctx->buffers[i]);
> +		data = (int*)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_WRITE_ONLY);
> +
> +		memset(data, i ? 127 : 0, 16384);
> +
> +		glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
> +	}
> +	glViewport(0, 0, 64, 64);
> +	for(i = 0; i < 2; ++i) {
> +		glBindFramebuffer(GL_FRAMEBUFFER, ctx->fbos[i]);
> +		glClearBufferiv(GL_COLOR, 0, clear_colors);
> +	}
> +	glFinish();
> +}
> +
> +static bool check_buffer(struct test_context *ctx, unsigned buffer, int value,
> +                         const char *test_name)
> +{
> +	int *data;
> +	int i;
> +	bool result = true;
> +
> +	glFinish();
> +
> +	glBindBuffer(GL_SHADER_STORAGE_BUFFER, ctx->buffers[buffer]);
> +	data = (int*)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);
> +
> +	for (i = 0; i < 4096; ++i)
> +		if (data[i] != value) {
> +			result = false;
> +			break;
> +		}
> +
> +	glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
> +
> +	piglit_report_subtest_result(result ? PIGLIT_PASS : PIGLIT_FAIL,
> +	                             "%s", test_name);
> +
> +	return result;
> +}
> +
> +static bool check_image(struct test_context *ctx, unsigned image, int value,
> +                         const char *test_name)
> +{
> +	int *data = malloc(64 * 64 * sizeof(int));
> +	int i;
> +	bool result = true;
> +
> +	glFinish();
> +
> +	glBindTexture(GL_TEXTURE_2D, ctx->textures[image]);
> +	glGetTexImage(GL_TEXTURE_2D, 0, GL_RED_INTEGER, GL_INT, data);
> +
> +	for (i = 0; i < 4096; ++i)
> +		if (data[i] != value) {
> +			result = false;
> +			break;
> +		}
> +	piglit_report_subtest_result(result ? PIGLIT_PASS : PIGLIT_FAIL,
> +	                             "%s", test_name);
> +
> +	free(data);
> +	return result;
> +}
> +
> +static void compute_ssbo_write(struct test_context *ctx, int value)
> +{
> +	glUseProgram(ctx->compute_ssbo_write);
> +	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ctx->buffers[0]);
> +	glUniform1i(glGetUniformLocation(ctx->compute_ssbo_write, "value"), value);
> +	glDispatchCompute(16, 1, 1);
> +
> +}
> +
> +static void compute_ssbo_copy(struct test_context *ctx)
> +{
> +	glUseProgram(ctx->compute_ssbo_copy);
> +	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, ctx->buffers[0]);
> +	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ctx->buffers[1]);
> +	glDispatchCompute(16, 1, 1);
> +
> +}
> +
> +static void compute_image_write(struct test_context *ctx, int value)
> +{
> +	glUseProgram(ctx->compute_image_write);
> +	glBindImageTexture(1, ctx->textures[0], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32I);
> +	glUniform1i(glGetUniformLocation(ctx->compute_image_write, "value"), value);
> +	glDispatchCompute(4, 4, 1);
> +
> +}
> +
> +static void compute_image_copy(struct test_context *ctx)
> +{
> +	glUseProgram(ctx->compute_image_copy);
> +	glBindImageTexture(0, ctx->textures[0], 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32I);
> +	glBindImageTexture(1, ctx->textures[1], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32I);
> +	glDispatchCompute(4, 4, 1);
> +
> +}
> +
> +static void graphics_ssbo_write(struct test_context *ctx, int value)
> +{
> +	glUseProgram(ctx->graphics_ssbo_write);
> +	glBindFramebuffer(GL_FRAMEBUFFER, ctx->empty_fbo);
> +	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ctx->buffers[0]);
> +	glUniform1i(glGetUniformLocation(ctx->graphics_ssbo_write, "value"), value);
> +	piglit_draw_rect(-1, -1, 2, 2);
> +
> +}
> +
> +static void graphics_ssbo_copy(struct test_context *ctx)
> +{
> +	glUseProgram(ctx->graphics_ssbo_copy);
> +	glBindFramebuffer(GL_FRAMEBUFFER, ctx->empty_fbo);
> +	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, ctx->buffers[0]);
> +	glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ctx->buffers[1]);
> +	piglit_draw_rect(-1, -1, 2, 2);
> +
> +}
> +
> +static void graphics_image_write(struct test_context *ctx, int value)
> +{
> +	glUseProgram(ctx->graphics_image_write);
> +	glBindFramebuffer(GL_FRAMEBUFFER, ctx->empty_fbo);
> +	glBindImageTexture(1, ctx->textures[0], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32I);
> +	glUniform1i(glGetUniformLocation(ctx->graphics_image_write, "value"), value);
> +	piglit_draw_rect(-1, -1, 2, 2);
> +
> +}
> +
> +static void graphics_image_copy(struct test_context *ctx)
> +{
> +	glUseProgram(ctx->graphics_image_copy);
> +	glBindFramebuffer(GL_FRAMEBUFFER, ctx->empty_fbo);
> +	glBindImageTexture(0, ctx->textures[0], 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32I);
> +	glBindImageTexture(1, ctx->textures[1], 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_R32I);
> +	piglit_draw_rect(-1, -1, 2, 2);
> +}
> +
> +static void graphics_fbo_write(struct test_context *ctx, int value)
> +{
> +	glUseProgram(ctx->graphics_fbo_write);
> +	glBindFramebuffer(GL_FRAMEBUFFER, ctx->fbos[0]);
> +	glUniform1i(glGetUniformLocation(ctx->graphics_fbo_write, "value"), value);
> +	piglit_draw_rect(-1, -1, 2, 2);
> +
> +}
> +
> +static void graphics_fbo_copy(struct test_context *ctx)
> +{
> +	glUseProgram(ctx->graphics_fbo_copy);
> +	glBindFramebuffer(GL_FRAMEBUFFER, ctx->fbos[1]);
> +	glBindImageTexture(0, ctx->textures[0], 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32I);
> +	piglit_draw_rect(-1, -1, 2, 2);
> +}
> +
> +static void graphics_feedback_write(struct test_context *ctx,  int value)
> +{
> +	glUseProgram(ctx->graphics_feedback_write);
> +	glBindFramebuffer(GL_FRAMEBUFFER, ctx->empty_fbo);
> +	glUniform1i(glGetUniformLocation(ctx->graphics_feedback_write, "value"), value);
> +	glEnable(GL_RASTERIZER_DISCARD);
> +	glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, ctx->buffers[0]);
> +	glBeginTransformFeedback(GL_POINTS);
> +	glDrawArrays(GL_POINTS, 0, 4096);
> +	glEndTransformFeedback();
> +	glDisable(GL_RASTERIZER_DISCARD);
> +}
> +
> +static void graphics_feedback_copy(struct test_context *ctx)
> +{
> +	glUseProgram(ctx->graphics_feedback_copy);
> +	glBindFramebuffer(GL_FRAMEBUFFER, ctx->empty_fbo);
> +	glEnable(GL_RASTERIZER_DISCARD);
> +	glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, ctx->buffers[1]);
> +	glBeginTransformFeedback(GL_POINTS);
> +	glEnableVertexAttribArray(0);
> +	glBindBuffer(GL_ARRAY_BUFFER, ctx->buffers[0]);
> +	glVertexAttribIPointer(0, 1, GL_INT, 4, 0);
> +	glDrawArrays(GL_POINTS, 0, 4096);
> +	glEndTransformFeedback();
> +	glDisableVertexAttribArray(0);
> +	glDisable(GL_RASTERIZER_DISCARD);
> +}
> +
> +struct method {
> +	void (*write)(struct test_context*, int);
> +	void (*copy)(struct test_context*);
> +	const char *name;
> +};
> +
> +static struct method buffer_methods[] = {
> +	{compute_ssbo_write, compute_ssbo_copy, "compute-ssbo"},
> +	{graphics_ssbo_write, graphics_ssbo_copy, "graphics-ssbo"},
> +	{graphics_feedback_write, graphics_feedback_copy, "graphics-feedback"}
> +};
> +
> +static struct method image_methods[] = {
> +	{compute_image_write, compute_image_copy, "compute-image"},
> +	{graphics_image_write, graphics_image_copy, "graphics-image"},
> +	{graphics_fbo_write, graphics_fbo_copy, "graphics-fbo"}
> +};
> +
> +static void synchronize(void* a, void *b) {
> +	bool need_memory_barrier = false;
> +	GLbitfield memory_barrier_bits = 0;
> +
> +	if (a == compute_ssbo_write || a == graphics_ssbo_write ||
> +	    b == compute_ssbo_write || b == graphics_ssbo_write ||
> +	    a == compute_image_write || a == graphics_image_write ||
> +	    b == compute_image_write || b == graphics_image_write)
> +		need_memory_barrier = true;
> +
> +	if (b == compute_ssbo_write || b == compute_ssbo_copy ||
> +	   b == graphics_ssbo_write || b == graphics_ssbo_copy)
> +		memory_barrier_bits |= GL_SHADER_STORAGE_BARRIER_BIT;
> +
> +	if (b == compute_image_write || b == compute_image_copy ||
> +	    b == graphics_image_write || b == graphics_image_copy ||
> +	    b == graphics_fbo_copy)
> +		memory_barrier_bits |= GL_SHADER_IMAGE_ACCESS_BARRIER_BIT;
> +
> +	if (b == graphics_feedback_copy)
> +		memory_barrier_bits |= GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT;
> +
> +	if (b == graphics_feedback_write)
> +		memory_barrier_bits |= GL_TRANSFORM_FEEDBACK_BARRIER_BIT;
> +
> +	if (b == graphics_fbo_write)
> +		memory_barrier_bits |= GL_FRAMEBUFFER_BARRIER_BIT;
> +
> +	if (need_memory_barrier)
> +		glMemoryBarrier(memory_barrier_bits);
> +}
> +static bool test_buffers(struct test_context *ctx, const struct method* a,
> +                         const struct method *b)
> +{
> +	bool result = true;
> +	char name[1024];
> +
> +	setup_test(ctx);
> +	a->write(ctx, 1);
> +	synchronize(a->write, b->copy);
> +	b->copy(ctx);
> +	sprintf(name, "%s-%s-read-after-write", a->name, b->name);
> +	result &= check_buffer(ctx, 1, 1, name);
> +
> +	setup_test(ctx);
> +	a->write(ctx, 1);
> +	synchronize(a->write, b->write);
> +	b->write(ctx, 2);
> +	sprintf(name, "%s-%s-write-after-write", a->name, b->name);
> +	result &= check_buffer(ctx, 0, 2, name);
> +
> +	setup_test(ctx);
> +	a->copy(ctx);
> +	synchronize(a->copy, b->write);
> +	b->write(ctx, 2);
> +	sprintf(name, "%s-%s-write-after-read", a->name, b->name);
> +	result &= check_buffer(ctx, 1, 0, name);
> +
> +	return result;
> +}
> +
> +static bool test_images(struct test_context *ctx, const struct method* a,
> +                         const struct method *b)
> +{
> +	bool result = true;
> +	char name[1024];
> +
> +	setup_test(ctx);
> +	a->write(ctx, 1);
> +	synchronize(a->write, b->copy);
> +	b->copy(ctx);
> +	sprintf(name, "%s-%s-read-after-write", a->name, b->name);
> +	result &= check_image(ctx, 1, 1, name);
> +
> +	setup_test(ctx);
> +	a->write(ctx, 1);
> +	synchronize(a->write, b->write);
> +	b->write(ctx, 2);
> +	sprintf(name, "%s-%s-write-after-write", a->name, b->name);
> +	result &= check_image(ctx, 0, 2, name);
> +
> +	setup_test(ctx);
> +	a->copy(ctx);
> +	synchronize(a->copy, b->write);
> +	b->write(ctx, 2);
> +	sprintf(name, "%s-%s-write-after-read", a->name, b->name);
> +	result &= check_image(ctx, 1, 0, name);
> +
> +	return result;
> +}
> +
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	struct test_context ctx;
> +	bool result = true;
> +	GLuint vao;
> +	int i, j;
> +	int buffer_method_count = sizeof(buffer_methods) /
> +	                          sizeof(buffer_methods[0]);
> +	int image_method_count = sizeof(image_methods) /
> +	                         sizeof(image_methods[0]);
> +
> +	piglit_require_gl_version(42);
> +	piglit_require_extension("GL_ARB_compute_shader");
> +	piglit_require_extension("GL_ARB_shader_storage_buffer_object");
> +	piglit_require_extension("GL_ARB_framebuffer_no_attachments");
> +
> +	glGenVertexArrays(1, &vao);
> +	glBindVertexArray(vao);
> +
> +	init_test_context(&ctx);
> +	for (i = 0; i < buffer_method_count; ++i) {
> +		for (j = 0; j < buffer_method_count; ++j) {
> +			result &= test_buffers(&ctx, &buffer_methods[i],
> +					       &buffer_methods[j]);
> +		}
> +	}
> +	for (i = 0; i < image_method_count; ++i) {
> +		for (j = 0; j < image_method_count; ++j) {
> +			result &= test_images(&ctx, &image_methods[i],
> +					      &image_methods[j]);
> +		}
> +	}
> +	deinit_test_context(&ctx);
> +
> +	glDeleteVertexArrays(1, &vao);
> +	piglit_report_result(result ? PIGLIT_PASS : PIGLIT_FAIL);
> +}
>


More information about the Piglit mailing list