[Piglit] [PATCH 2/2] arb_shader_storage_buffer_object: add AoA test for std430 layout
Samuel Iglesias Gonsalvez
siglesias at igalia.com
Tue Oct 6 04:01:45 PDT 2015
Signed-off-by: Samuel Iglesias Gonsalvez <siglesias at igalia.com>
---
tests/all.py | 1 +
.../CMakeLists.gl.txt | 1 +
.../layout-std430-arrays-of-arrays-write-shader.c | 229 +++++++++++++++++++++
3 files changed, 231 insertions(+)
create mode 100644 tests/spec/arb_shader_storage_buffer_object/layout-std430-arrays-of-arrays-write-shader.c
diff --git a/tests/all.py b/tests/all.py
index a9b3baa..a42308c 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -4089,6 +4089,7 @@ with profile.group_manager(
g(['arb_shader_storage_buffer_object-layout-std140-write-shader'], 'layout-std140-write-shader')
g(['arb_shader_storage_buffer_object-program_interface_query'], 'program-interface-query')
g(['arb_shader_storage_buffer_object-layout-std140-arrays-of-arrays-write-shader'], 'layout-std140-arrays-of-arrays-write-shader')
+ g(['arb_shader_storage_buffer_object-layout-std430-arrays-of-arrays-write-shader'], 'layout-std430-arrays-of-arrays-write-shader')
with profile.group_manager(
PiglitGLTest,
diff --git a/tests/spec/arb_shader_storage_buffer_object/CMakeLists.gl.txt b/tests/spec/arb_shader_storage_buffer_object/CMakeLists.gl.txt
index e425df7..0d2331b 100644
--- a/tests/spec/arb_shader_storage_buffer_object/CMakeLists.gl.txt
+++ b/tests/spec/arb_shader_storage_buffer_object/CMakeLists.gl.txt
@@ -20,5 +20,6 @@ piglit_add_executable (arb_shader_storage_buffer_object-layout-std430-write-shad
piglit_add_executable (arb_shader_storage_buffer_object-layout-std140-write-shader layout-std140-write-shader.c)
piglit_add_executable (arb_shader_storage_buffer_object-program_interface_query program-interface-query.c)
piglit_add_executable (arb_shader_storage_buffer_object-layout-std140-arrays-of-arrays-write-shader layout-std140-arrays-of-arrays-write-shader.c)
+piglit_add_executable (arb_shader_storage_buffer_object-layout-std430-arrays-of-arrays-write-shader layout-std430-arrays-of-arrays-write-shader.c)
# vim: ft=cmake:
diff --git a/tests/spec/arb_shader_storage_buffer_object/layout-std430-arrays-of-arrays-write-shader.c b/tests/spec/arb_shader_storage_buffer_object/layout-std430-arrays-of-arrays-write-shader.c
new file mode 100644
index 0000000..d7ed42a
--- /dev/null
+++ b/tests/spec/arb_shader_storage_buffer_object/layout-std430-arrays-of-arrays-write-shader.c
@@ -0,0 +1,229 @@
+/*
+ * 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.
+ */
+
+/** @file layout-std430-arrays-of-arrays-write-shader.c
+ *
+ * Tests that shader storage block writes in GLSL works correctly (offsets and
+ * values) when interface packing qualifier is std140 and row_major.
+ * This test includes some buffer variables defined as arrays of arrays.
+ */
+
+#include "piglit-util-gl.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+ config.window_width = 100;
+ config.window_height = 100;
+ config.supports_gl_compat_version = 32;
+ config.supports_gl_core_version = 32;
+ config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+#define SSBO_SIZE 728
+#define NUM_QUERIES 11
+
+static const char vs_pass_thru_text[] =
+ "#version 130\n"
+ "#extension GL_ARB_shader_storage_buffer_object : require\n"
+ "#extension GL_ARB_arrays_of_arrays : require\n"
+ "#extension GL_ARB_uniform_buffer_object : require\n"
+ "\n"
+ "struct A {\n"
+ " float a1;\n"
+ " vec2 a2_2[2][2];\n"
+ " mat3x4 a34_2[2][2];\n"
+ "};\n"
+ "layout(std430, binding=2) buffer ssbo {\n"
+ " vec4 v;\n"
+ " float f;\n"
+ " A s[2][3];\n"
+ " A unsized_array[][3];\n"
+ "};\n"
+ "in vec4 piglit_vertex;\n"
+ "void main() {\n"
+ " gl_Position = piglit_vertex;\n"
+ " f = 4.0;\n"
+ " s[0][1].a2_2[0][1] = vec2(6.0, 7.0); \n"
+ " int index = int(v.x); // index should be zero\n"
+ " unsized_array[index + gl_VertexID][1].a1 = unsized_array.length();\n"
+ "}\n";
+
+static const char fs_source[] =
+ "#version 130\n"
+ "#extension GL_ARB_shader_storage_buffer_object : require\n"
+ "#extension GL_ARB_arrays_of_arrays : require\n"
+ "#extension GL_ARB_uniform_buffer_object : require\n"
+ "\n"
+ "struct A {\n"
+ " float a1;\n"
+ " vec2 a2_2[2][2];\n"
+ " mat3x4 a34_2[2][2];\n"
+ "};\n"
+ "layout(std430, binding=2) buffer ssbo {\n"
+ " vec4 v;\n"
+ " float f;\n"
+ " A s[2][3];\n"
+ " A unsized_array[][3];\n"
+ "};\n"
+ "out vec4 color;\n"
+ "\n"
+ "void main() {\n"
+ " color = vec4(0,1,0,1);\n"
+ " v = vec4(0.0, 1.0, 2.0, 3.0);\n"
+ " s[1][2].a1 = 5.0;\n"
+ " s[1][2].a2_2[1][1] = vec2(8.0, 9.0);\n"
+ " s[1][2].a34_2[1][0][1] = vec4(10.0, 11.0, 12.0, 13.0);\n"
+ " uint index = uint(v.z);\n"
+ " unsized_array[0][index].a34_2[1][1][index].w = unsized_array.length() * 2.0;\n"
+ "}\n";
+
+GLuint prog;
+
+float expected[SSBO_SIZE] = {0};
+
+static void
+set_expected_values(void)
+{
+ expected[1] = 1.00;
+ expected[2] = 2.00;
+ expected[3] = 3.00;
+ expected[4] = 4.00;
+ expected[72] = 6.00;
+ expected[73] = 7.00;
+ expected[308] = 5.00;
+ expected[316] = 8.00;
+ expected[317] = 9.00;
+ expected[348] = 10.00;
+ expected[349] = 11.00;
+ expected[350] = 12.00;
+ expected[351] = 13.00;
+ expected[428] = 2.00;
+ expected[547] = 4.00;
+ expected[608] = 2.00;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ bool pass = true;
+ GLuint buffer;
+ unsigned int i;
+ float *ssbo_values = (float *) calloc(SSBO_SIZE, sizeof(GLfloat));
+ float *map;
+
+ if (!ssbo_values) {
+ printf("Cannot allocate space for ssbo_values\n");
+ piglit_report_result(PIGLIT_FAIL);
+ return;
+ }
+
+ piglit_require_extension("GL_ARB_shader_storage_buffer_object");
+ piglit_require_extension("GL_ARB_arrays_of_arrays");
+ piglit_require_extension("GL_ARB_program_interface_query");
+ piglit_require_GLSL_version(130);
+
+ prog = piglit_build_simple_program(vs_pass_thru_text, fs_source);
+
+ glUseProgram(prog);
+
+ glClearColor(0, 0, 0, 0);
+
+ glGenBuffers(1, &buffer);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, buffer);
+ glBufferData(GL_SHADER_STORAGE_BUFFER, SSBO_SIZE*sizeof(GLfloat),
+ &ssbo_values[0], GL_DYNAMIC_DRAW);
+
+ glViewport(0, 0, piglit_width, piglit_height);
+
+ piglit_draw_rect(-1, -1, 2, 2);
+
+ set_expected_values();
+
+ glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);
+ map = (float *) glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);
+
+ for (i = 0; i < SSBO_SIZE; i++) {
+ if (map[i] != expected[i]) {
+ printf("expected[%d] = %.2f. Read value: %.2f\n",
+ i, expected[i], map[i]);
+ pass = false;
+ }
+ }
+
+ glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
+
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ pass = false;
+
+ const char *prop_names[NUM_QUERIES] = {"GL_TOP_LEVEL_ARRAY_SIZE",
+ "GL_TOP_LEVEL_ARRAY_STRIDE",
+ "GL_TYPE",
+ "GL_ARRAY_SIZE",
+ "GL_BLOCK_INDEX",
+ "GL_OFFSET",
+ "GL_ARRAY_STRIDE",
+ "GL_MATRIX_STRIDE",
+ "GL_IS_ROW_MAJOR",
+ "GL_REFERENCED_BY_VERTEX_SHADER",
+ "GL_REFERENCED_BY_FRAGMENT_SHADER" };
+ int query_std430[NUM_QUERIES] = {0};
+ GLint index = glGetProgramResourceIndex(prog,
+ GL_BUFFER_VARIABLE,
+ "s[0][1].a2_2[0][0]");
+ const GLenum prop[NUM_QUERIES] = {GL_TOP_LEVEL_ARRAY_SIZE,
+ GL_TOP_LEVEL_ARRAY_STRIDE,
+ GL_TYPE,
+ GL_ARRAY_SIZE,
+ GL_BLOCK_INDEX,
+ GL_OFFSET,
+ GL_ARRAY_STRIDE,
+ GL_MATRIX_STRIDE,
+ GL_IS_ROW_MAJOR,
+ GL_REFERENCED_BY_VERTEX_SHADER,
+ GL_REFERENCED_BY_FRAGMENT_SHADER };
+ glGetProgramResourceiv(prog, GL_BUFFER_VARIABLE, index,
+ NUM_QUERIES, prop, NUM_QUERIES, NULL,
+ query_std430);
+ const int expected_std430[NUM_QUERIES] =
+ { 2, 240*3, GL_FLOAT_VEC2, 2, 0, 32 + 240 + 8, 8, 0, 0, 1, 1 };
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ pass = false;
+
+ for (i = 0 ; i < NUM_QUERIES; i++) {
+ if (query_std430[i] != expected_std430[i]) {
+ printf("std430 %s expected = %d. Value = %d.\n",
+ prop_names[i], expected_std430[i],
+ query_std430[i]);
+ pass = false;
+ }
+ }
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+ free(ssbo_values);
+}
+
+enum piglit_result piglit_display(void)
+{
+ /* UNREACHED */
+ return PIGLIT_FAIL;
+}
--
2.4.3
More information about the Piglit
mailing list