[Piglit] [PATCH] arb_uniform_buffer_object: add 'offset' option to the rendering test

Brian Paul brianp at vmware.com
Mon Oct 20 11:53:39 PDT 2014


If argc[1]=="offset" use glBindBufferRange with a non-zero offset.
The offset is simply the value of GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT.
It seems no other UBO test actually exercises this.
---
 tests/all.py                                     |    1 +
 tests/spec/arb_uniform_buffer_object/rendering.c |   32 ++++++++++++++++++----
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/tests/all.py b/tests/all.py
index 8f75796..ea83695 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3281,6 +3281,7 @@ arb_uniform_buffer_object['negative-getactiveuniformblockiv'] = PiglitGLTest('ar
 arb_uniform_buffer_object['negative-getactiveuniformsiv'] = PiglitGLTest('arb_uniform_buffer_object-negative-getactiveuniformsiv', run_concurrent=True)
 arb_uniform_buffer_object['referenced-by-shader'] = PiglitGLTest('arb_uniform_buffer_object-referenced-by-shader', run_concurrent=True)
 arb_uniform_buffer_object['rendering'] = PiglitGLTest('arb_uniform_buffer_object-rendering', run_concurrent=True)
+arb_uniform_buffer_object['rendering-offset'] = PiglitGLTest('arb_uniform_buffer_object-rendering offset', run_concurrent=True)
 arb_uniform_buffer_object['row-major'] = PiglitGLTest('arb_uniform_buffer_object-row-major', run_concurrent=True)
 arb_uniform_buffer_object['uniformblockbinding'] = PiglitGLTest('arb_uniform_buffer_object-uniformblockbinding', run_concurrent=True)
 
diff --git a/tests/spec/arb_uniform_buffer_object/rendering.c b/tests/spec/arb_uniform_buffer_object/rendering.c
index 0f3b408..8179b6e 100644
--- a/tests/spec/arb_uniform_buffer_object/rendering.c
+++ b/tests/spec/arb_uniform_buffer_object/rendering.c
@@ -92,6 +92,8 @@ static const float rotation[NUM_SQUARES] = {
 
 static GLuint prog;
 static GLuint buffers[NUM_UBOS];
+static GLint alignment;
+static bool test_buffer_offset = false;
 
 
 static void
@@ -105,6 +107,17 @@ setup_ubos(void)
 	static GLubyte zeros[1000] = {0};
 	int i;
 
+	glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &alignment);
+	printf("GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT = %d\n", alignment);
+
+	if (test_buffer_offset) {
+		printf("Testing buffer offset %d\n", alignment);
+	}
+	else {
+		/* we use alignment as the offset */
+		alignment = 0;
+	}
+
 	glGenBuffers(NUM_UBOS, buffers);
 
 	for (i = 0; i < NUM_UBOS; i++) {
@@ -127,10 +140,13 @@ setup_ubos(void)
 		 * really shouldn't matter.
 		 */
 		glBindBuffer(GL_UNIFORM_BUFFER, buffers[i]);
-		glBufferData(GL_UNIFORM_BUFFER, size, zeros, GL_DYNAMIC_DRAW);
+		glBufferData(GL_UNIFORM_BUFFER, size + alignment,
+                             zeros, GL_DYNAMIC_DRAW);
 
 		/* Attach UBO */
-		glBindBufferBase(GL_UNIFORM_BUFFER, i, buffers[i]);
+		glBindBufferRange(GL_UNIFORM_BUFFER, i, buffers[i],
+				  alignment,  /* offset */
+				  size);
 		glUniformBlockBinding(prog, index, i);
 
 		if (!piglit_check_gl_error(GL_NO_ERROR))
@@ -144,6 +160,10 @@ piglit_init(int argc, char **argv)
 {
 	piglit_require_extension("GL_ARB_uniform_buffer_object");
 
+	if (argc > 1 && strcmp(argv[1], "offset") == 0) {
+		test_buffer_offset = true;
+	}
+
 	prog = piglit_build_simple_program(vert_shader_text, frag_shader_text);
 	assert(prog);
 	glUseProgram(prog);
@@ -184,15 +204,15 @@ piglit_display(void)
 	glClear(GL_COLOR_BUFFER_BIT);
 
 	for (i = 0; i < NUM_SQUARES; i++) {
-		/* Load UBO data */
+		/* Load UBO data, at offset=alignment */
 		glBindBuffer(GL_UNIFORM_BUFFER, buffers[0]);
-		glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(pos_size[0]),
+		glBufferSubData(GL_UNIFORM_BUFFER, alignment, sizeof(pos_size[0]),
 				pos_size[i]);
 		glBindBuffer(GL_UNIFORM_BUFFER, buffers[1]);
-		glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(color[0]),
+		glBufferSubData(GL_UNIFORM_BUFFER, alignment, sizeof(color[0]),
 				color[i]);
 		glBindBuffer(GL_UNIFORM_BUFFER, buffers[2]);
-		glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(rotation[0]),
+		glBufferSubData(GL_UNIFORM_BUFFER, alignment, sizeof(rotation[0]),
 				&rotation[i]);
 
 		if (!piglit_check_gl_error(GL_NO_ERROR))
-- 
1.7.10.4



More information about the Piglit mailing list