[Piglit] [PATCH v4] arb_shader_atomic_counters-semantics: test different binding points
Alejandro PiƱeiro
apinheiro at igalia.com
Sat Aug 1 09:24:23 PDT 2015
Piglit was only checking the expected effects using binding point 0.
With this commit, all the values between 0 and
GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS are checked. It also checks that
the binding point used on the shader and the one returned by
glGetActiveAtomicCounterBufferiv(..., ...,
GL_ATOMIC_COUNTER_BUFFER_BINDING, ...) is the same.
Test added in order to detect things like this mesa bug:
https://bugs.freedesktop.org/show_bug.cgi?id=90175
---
v4: moved the loop to the new test_shader function. It makes the function
somewhat more ellaborated, as it needs to receive which of the parameters
is a template in order to asprintf to the final source code.
tests/spec/arb_shader_atomic_counters/semantics.c | 155 ++++++++++++++++------
1 file changed, 112 insertions(+), 43 deletions(-)
diff --git a/tests/spec/arb_shader_atomic_counters/semantics.c b/tests/spec/arb_shader_atomic_counters/semantics.c
index 694f1fe..05f606e 100644
--- a/tests/spec/arb_shader_atomic_counters/semantics.c
+++ b/tests/spec/arb_shader_atomic_counters/semantics.c
@@ -24,7 +24,8 @@
/** @file semantics.c
*
* Tests that the atomic built-in functions have the expected effects
- * on memory and return the expected results.
+ * on memory and return the expected results, with different binding
+ * points.
*/
#include "common.h"
@@ -40,7 +41,92 @@ PIGLIT_GL_TEST_CONFIG_BEGIN
PIGLIT_GL_TEST_CONFIG_END
static bool
-run_test_vertex(void)
+atomic_counters_expected_binding(GLuint prog,
+ GLuint binding)
+{
+ GLint param;
+
+ glGetActiveAtomicCounterBufferiv(prog, 0,
+ GL_ATOMIC_COUNTER_BUFFER_BINDING,
+ ¶m);
+ if (binding != param)
+ printf ("Wrong binding point on the shader, %i expected, %i found\n",
+ binding, param);
+
+ return binding == param;
+}
+
+/*
+ * @vs_source, @fs_source, @gs_source would be considered a template based on
+ * @stage.
+ */
+static bool
+test_shader(GLint max_bindings,
+ GLuint stage,
+ const char *vs_source,
+ const char *fs_source,
+ const char *gs_source,
+ const uint32_t *start_buffer,
+ const uint32_t *expected_buffer,
+ const uint32_t *expected_color)
+{
+ GLuint prog;
+ bool ret = true;
+ GLuint buffer;
+ char *stage_source;
+ int i;
+ int asprintf_ret;
+ char *real_vs_source = (char*) vs_source;
+ char *real_fs_source = (char*) fs_source;
+ char *real_gs_source = (char*) gs_source;
+
+ glGenBuffers(1, &buffer);
+ for (i = 0; i < max_bindings; i++) {
+ prog = glCreateProgram();
+ glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, i, buffer);
+
+ switch (stage) {
+ case GL_VERTEX_SHADER:
+ asprintf_ret = asprintf(&stage_source, vs_source, i);
+ real_vs_source = stage_source;
+ break;
+ case GL_FRAGMENT_SHADER:
+ asprintf_ret = asprintf(&stage_source, fs_source, i);
+ real_fs_source = stage_source;
+ break;
+ case GL_GEOMETRY_SHADER:
+ asprintf_ret = asprintf(&stage_source, gs_source, i);
+ real_gs_source = stage_source;
+ break;
+ default:
+ printf("Wrong stage %i\n", stage);
+ return false;
+ }
+ assert(asprintf_ret > 0);
+
+ ret =
+ atomic_counters_compile(prog, GL_FRAGMENT_SHADER, real_fs_source) &&
+ atomic_counters_compile(prog, GL_VERTEX_SHADER, real_vs_source) &&
+ (gs_source != NULL ? atomic_counters_compile(prog, GL_GEOMETRY_SHADER, real_gs_source) : true) &&
+ atomic_counters_draw_point(prog, 1, start_buffer) &&
+ piglit_probe_rect_rgba_uint(0, 0, 1, 1, expected_color) &&
+ atomic_counters_probe_buffer(0, 1, expected_buffer) &&
+ atomic_counters_expected_binding(prog, i);
+
+ free(stage_source);
+ glDeleteProgram(prog);
+
+ if (!ret)
+ break;
+ }
+
+ glDeleteBuffers(1, &buffer);
+
+ return ret;
+}
+
+static bool
+run_test_vertex(GLint max_bindings)
{
const char *fs_source = "#version 140\n"
"flat in ivec4 vcolor;\n"
@@ -48,10 +134,10 @@ run_test_vertex(void)
"void main() {\n"
" fcolor = vcolor;\n"
"}\n";
- const char *vs_source = "#version 140\n"
+ const char *vs_template = "#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"\n"
- "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
+ "layout(binding = %i, offset = 0) uniform atomic_uint x;\n"
"in vec4 piglit_vertex;\n"
"flat out ivec4 vcolor;\n"
"\n"
@@ -66,26 +152,20 @@ run_test_vertex(void)
const uint32_t expected_buffer[] = { 0x0 };
const uint32_t expected_color[] = { 0xfffffffe, 0xfffffffe,
0xffffffff, 0x0 };
- GLuint prog = glCreateProgram();
- bool ret =
- atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
- atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
- atomic_counters_draw_point(prog, 1, start_buffer) &&
- piglit_probe_rect_rgba_uint(0, 0, 1, 1, expected_color) &&
- atomic_counters_probe_buffer(0, 1, expected_buffer);
- glDeleteProgram(prog);
- return ret;
+ return test_shader(max_bindings, GL_VERTEX_SHADER,
+ vs_template, fs_source, NULL,
+ start_buffer, expected_buffer, expected_color);
}
static bool
-run_test_fragment(void)
+run_test_fragment(GLint max_bindings)
{
- const char *fs_source = "#version 140\n"
+ const char *fs_template = "#version 140\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"\n"
"out ivec4 fcolor;\n"
- "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
+ "layout(binding = %i, offset = 0) uniform atomic_uint x;\n"
"\n"
"void main() {\n"
" fcolor.x = int(atomicCounterDecrement(x));\n"
@@ -105,20 +185,14 @@ run_test_fragment(void)
const uint32_t expected_buffer[] = { 0x0 };
const uint32_t expected_color[] = { 0xfffffffe, 0xfffffffe,
0xffffffff, 0x0 };
- GLuint prog = glCreateProgram();
- bool ret =
- atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
- atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
- atomic_counters_draw_point(prog, 1, start_buffer) &&
- piglit_probe_rect_rgba_uint(0, 0, 1, 1, expected_color) &&
- atomic_counters_probe_buffer(0, 1, expected_buffer);
- glDeleteProgram(prog);
- return ret;
+ return test_shader(max_bindings, GL_FRAGMENT_SHADER,
+ vs_source, fs_template, NULL,
+ start_buffer, expected_buffer, expected_color);
}
static bool
-run_test_geometry(void)
+run_test_geometry(GLint max_bindings)
{
const char *fs_source = "#version 140\n"
"flat in ivec4 gcolor;\n"
@@ -126,7 +200,7 @@ run_test_geometry(void)
"void main() {\n"
" fcolor = gcolor;\n"
"}\n";
- const char *gs_source = "#version 150\n"
+ const char *gs_template = "#version 150\n"
"#extension GL_ARB_shader_atomic_counters : enable\n"
"\n"
"layout(points) in;\n"
@@ -134,7 +208,7 @@ run_test_geometry(void)
"\n"
"flat out ivec4 gcolor;\n"
"\n"
- "layout(binding = 0, offset = 0) uniform atomic_uint x;\n"
+ "layout(binding = %i, offset = 0) uniform atomic_uint x;\n"
"\n"
"void main() {\n"
" gl_Position = gl_in[0].gl_Position;\n"
@@ -156,17 +230,10 @@ run_test_geometry(void)
const uint32_t expected_buffer[] = { 0x0 };
const uint32_t expected_color[] = { 0xfffffffe, 0xfffffffe,
0xffffffff, 0x0 };
- GLuint prog = glCreateProgram();
- bool ret =
- atomic_counters_compile(prog, GL_FRAGMENT_SHADER, fs_source) &&
- atomic_counters_compile(prog, GL_GEOMETRY_SHADER, gs_source) &&
- atomic_counters_compile(prog, GL_VERTEX_SHADER, vs_source) &&
- atomic_counters_draw_point(prog, 1, start_buffer) &&
- piglit_probe_rect_rgba_uint(0, 0, 1, 1, expected_color) &&
- atomic_counters_probe_buffer(0, 1, expected_buffer);
- glDeleteProgram(prog);
- return ret;
+ return test_shader(max_bindings, GL_GEOMETRY_SHADER,
+ vs_source, fs_source, gs_template,
+ start_buffer, expected_buffer, expected_color);
}
static bool
@@ -331,6 +398,7 @@ piglit_init(int argc, char **argv)
{
GLuint fb, rb, buffer;
enum piglit_result status = PIGLIT_PASS;
+ GLint max_bindings;
piglit_require_extension("GL_ARB_shader_atomic_counters");
@@ -345,21 +413,22 @@ piglit_init(int argc, char **argv)
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_RENDERBUFFER, rb);
- glGenBuffers(1, &buffer);
- glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, buffer);
+ glGetIntegerv(GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS, &max_bindings);
atomic_counters_subtest(&status, GL_FRAGMENT_SHADER,
"Fragment shader atomic built-in semantics",
- run_test_fragment);
+ run_test_fragment, max_bindings);
atomic_counters_subtest(&status, GL_VERTEX_SHADER,
"Vertex shader atomic built-in semantics",
- run_test_vertex);
+ run_test_vertex, max_bindings);
atomic_counters_subtest(&status, GL_GEOMETRY_SHADER,
"Geometry shader atomic built-in semantics",
- run_test_geometry);
+ run_test_geometry, max_bindings);
+ glGenBuffers(1, &buffer);
+ glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, buffer);
atomic_counters_subtest(&status, GL_TESS_CONTROL_SHADER,
"Tessellation control shader atomic built-in "
"semantics",
--
2.1.0
More information about the Piglit
mailing list