From: Nicolai Hähnle <nicolai.haeh...@amd.com>

---
 tests/shaders/shader_runner.c | 41 +++++++++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 10 deletions(-)

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index dfa6991..6faa7f5 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -118,21 +118,21 @@ static GLuint fragment_shaders[256];
 static unsigned num_fragment_shaders = 0;
 static GLuint compute_shaders[256];
 static unsigned num_compute_shaders = 0;
 static GLuint textures[256];
 static unsigned num_textures = 0;
 static int num_uniform_blocks;
 static GLuint *uniform_block_bos;
 static GLenum geometry_layout_input_type = GL_TRIANGLES;
 static GLenum geometry_layout_output_type = GL_TRIANGLE_STRIP;
 static GLint geometry_layout_vertices_out = 0;
-static GLuint atomics_bo = 0;
+static GLuint atomics_bos[8];
 static GLuint ssbo[32];
 
 #define SHADER_TYPES 6
 static GLuint *subuniform_locations[SHADER_TYPES];
 static int num_subuniform_locations[SHADER_TYPES];
 static char *shader_string;
 static GLint shader_string_size;
 static const char *vertex_data_start = NULL;
 static const char *vertex_data_end = NULL;
 static GLuint prog;
@@ -2802,20 +2802,29 @@ teardown_ubos(void)
        if (num_uniform_blocks == 0) {
                return;
        }
 
        glDeleteBuffers(num_uniform_blocks, uniform_block_bos);
        free(uniform_block_bos);
        uniform_block_bos = NULL;
        num_uniform_blocks = 0;
 }
 
+static void
+teardown_atomics(void)
+{
+       for (unsigned i = 0; i < ARRAY_SIZE(atomics_bos); ++i) {
+               if (atomics_bos[i])
+                       glDeleteBuffers(1, &atomics_bos[i]);
+       }
+}
+
 static enum piglit_result
 program_must_be_in_use(void)
 {
        if (!link_ok) {
                fprintf(stderr, "Failed to link:\n%s\n", prog_err_info);
                return PIGLIT_FAIL;
        } else if (!prog_in_use) {
                fprintf(stderr, "Failed to use program: %s\n", prog_err_info);
                return PIGLIT_FAIL;
        }
@@ -2825,51 +2834,50 @@ program_must_be_in_use(void)
 static void
 bind_vao_if_supported()
 {
        if (vao == 0 && gl_version.num >= 31) {
                glGenVertexArrays(1, &vao);
                glBindVertexArray(vao);
        }
 }
 
 static bool
-probe_atomic_counter(GLint counter_num, const char *op, uint32_t value)
+probe_atomic_counter(unsigned buffer_num, GLint counter_num, const char *op, 
uint32_t value)
 {
         uint32_t *p;
        uint32_t observed;
        enum comparison cmp;
        bool result;
 
        process_comparison(op, &cmp);
 
-       glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, atomics_bo);
-       p = glMapBufferRange(GL_ATOMIC_COUNTER_BUFFER, counter_num * 
sizeof(uint32_t),
+       p = glMapNamedBufferRange(atomics_bos[buffer_num], counter_num * 
sizeof(uint32_t),
                             sizeof(uint32_t), GL_MAP_READ_BIT);
 
         if (!p) {
                 printf("Couldn't map atomic counter to verify expected 
value.\n");
                 return false;
         }
 
        observed = *p;
        result = compare_uint(value, observed, cmp);
 
        if (!result) {
                printf("Atomic counter %d test failed: Reference %s Observed\n",
                       counter_num, comparison_string(cmp));
                printf("  Reference: %u\n", value);
                printf("  Observed:  %u\n", observed);
-               glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
+               glUnmapNamedBuffer(atomics_bos[buffer_num]);
                return false;
         }
 
-        glUnmapBuffer(GL_ATOMIC_COUNTER_BUFFER);
+        glUnmapNamedBuffer(atomics_bos[buffer_num]);
         return true;
 }
 
 static bool
 probe_ssbo_uint(GLint ssbo_index, GLint ssbo_offset, const char *op, uint32_t 
value)
 {
        uint32_t *p;
        uint32_t observed;
        enum comparison cmp;
        bool result;
@@ -2950,28 +2958,40 @@ piglit_display(void)
                        case GL_GEOMETRY_SHADER:
                                glActiveShaderProgram(pipeline, 
sso_geometry_prog);
                        break;
                        case GL_FRAGMENT_SHADER:
                                glActiveShaderProgram(pipeline, 
sso_fragment_prog);
                        break;
                        case GL_COMPUTE_SHADER:
                                glActiveShaderProgram(pipeline, 
sso_compute_prog);
                        break;
                        }
+               } else if (sscanf(line, "atomic counter buffer %u %u", &x, &y) 
== 2) {
+                       GLuint *atomics_buf = calloc(y, sizeof(GLuint));
+                       glGenBuffers(1, &atomics_bos[x]);
+                       glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, x, 
atomics_bos[x]);
+                       glBufferData(GL_ATOMIC_COUNTER_BUFFER,
+                                    sizeof(GLuint) * y, atomics_buf,
+                                    GL_STATIC_DRAW);
+                       free(atomics_buf);
                } else if (sscanf(line, "atomic counters %d", &x) == 1) {
                        GLuint *atomics_buf = calloc(x, sizeof(GLuint));
-                       glGenBuffers(1, &atomics_bo);
-                       glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, 
atomics_bo);
+                       glGenBuffers(1, &atomics_bos[0]);
+                       glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, 0, 
atomics_bos[0]);
                        glBufferData(GL_ATOMIC_COUNTER_BUFFER,
                                     sizeof(GLuint) * x,
                                     atomics_buf, GL_STATIC_DRAW);
                        free(atomics_buf);
+               } else if (sscanf(line, "atomic counter %u %u %u", &x, &y, &z) 
== 3) {
+                       glNamedBufferSubData(atomics_bos[x],
+                                            sizeof(GLuint) * y, sizeof(GLuint),
+                                            &z);
                } else if (string_match("clear color", line)) {
                        get_floats(line + 11, c, 4);
                        glClearColor(c[0], c[1], c[2], c[3]);
                        clear_bits |= GL_COLOR_BUFFER_BIT;
                } else if (string_match("clear depth", line)) {
                        get_floats(line + 11, c, 1);
                        glClearDepth(c[0]);
                        clear_bits |= GL_DEPTH_BUFFER_BIT;
                } else if (string_match("clear", line)) {
                        glClear(clear_bits);
@@ -3158,21 +3178,21 @@ piglit_display(void)
                        }
                } else if (string_match("probe depth", line)) {
                        get_floats(line + 11, c, 3);
                        if (!piglit_probe_pixel_depth((int) c[0], (int) c[1],
                                                      c[2])) {
                                result = PIGLIT_FAIL;
                        }
                } else if (sscanf(line,
                                  "probe atomic counter %u %s %u",
                                  &ux, s, &uy) == 3) {
-                       if (!probe_atomic_counter(ux, s, uy)) {
+                       if (!probe_atomic_counter(0, ux, s, uy)) {
                                piglit_report_result(PIGLIT_FAIL);
                        }
                } else if (sscanf(line, "probe ssbo uint %d %d %s 0x%x",
                                  &x, &y, s, &z) == 4) {
                        if (!probe_ssbo_uint(x, y, s, z))
                                result = PIGLIT_FAIL;
                } else if (sscanf(line, "probe ssbo uint %d %d %s %d",
                                  &x, &y, s, &z) == 4) {
                        if (!probe_ssbo_uint(x, y, s, z))
                                result = PIGLIT_FAIL;
@@ -3687,21 +3707,21 @@ piglit_init(int argc, char **argv)
                        assert(num_tess_eval_shaders == 0);
                        assert(num_geometry_shaders == 0);
                        assert(num_fragment_shaders == 0);
                        assert(num_compute_shaders == 0);
                        assert(num_textures == 0);
                        assert(num_uniform_blocks == 0);
                        assert(uniform_block_bos == NULL);
                        geometry_layout_input_type = GL_TRIANGLES;
                        geometry_layout_output_type = GL_TRIANGLE_STRIP;
                        geometry_layout_vertices_out = 0;
-                       atomics_bo = 0;
+                       memset(atomics_bos, 0, sizeof(atomics_bos));
                        memset(ssbo, 0, sizeof(ssbo));
                        for (j = 0; j < ARRAY_SIZE(subuniform_locations); j++)
                                assert(subuniform_locations[j] == NULL);
                        memset(num_subuniform_locations, 0, 
sizeof(num_subuniform_locations));
                        shader_string = NULL;
                        shader_string_size = 0;
                        vertex_data_start = NULL;
                        vertex_data_end = NULL;
                        prog = 0;
                        sso_vertex_prog = 0;
@@ -3831,18 +3851,19 @@ piglit_init(int argc, char **argv)
                         */
                        if (report_subtests) {
                                piglit_report_subtest_result(
                                        result, "%s", testname);
                        } else {
                                piglit_report_result(result);
                        }
 
                        /* destroy GL objects? */
                        teardown_ubos();
+                       teardown_atomics();
                }
                exit(0);
        }
 
        result = init_test(argv[1]);
        if (result != PIGLIT_PASS)
                piglit_report_result(result);
 }
-- 
2.7.4

_______________________________________________
Piglit mailing list
Piglit@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to