[Piglit] [PATCH] Fix probing for tests based on arb_uniform_buffer_object/rendering

Neil Roberts nroberts at igalia.com
Thu Feb 1 09:12:20 UTC 2018


These tests set up either UBOs or SSBOs containing different values in
order to render squares with different colors, sizes and rotations.
However the test was only probing the center pixel of the square so it
wouldn’t actually matter if the rotation or size was wrong. The
rotation is the only thing that isn’t in the first UBO for a shader
stage so it is important to test it to ensure that the driver can cope
with multiple UBOs.
---
 .../explicit-offset-bufferstorage.c                | 66 ++++++++++++++++------
 .../arb_shader_storage_buffer_object/rendering.c   | 66 ++++++++++++++++------
 .../spec/arb_uniform_buffer_object/bufferstorage.c | 66 ++++++++++++++++------
 .../spec/arb_uniform_buffer_object/rendering-dsa.c | 66 ++++++++++++++++------
 tests/spec/arb_uniform_buffer_object/rendering.c   | 66 ++++++++++++++++------
 5 files changed, 250 insertions(+), 80 deletions(-)

diff --git a/tests/spec/arb_enhanced_layouts/explicit-offset-bufferstorage.c b/tests/spec/arb_enhanced_layouts/explicit-offset-bufferstorage.c
index 438ba32f2..401c189a8 100644
--- a/tests/spec/arb_enhanced_layouts/explicit-offset-bufferstorage.c
+++ b/tests/spec/arb_enhanced_layouts/explicit-offset-bufferstorage.c
@@ -100,6 +100,10 @@ static const float color[NUM_SQUARES][8] = {
 	{ 0.2, 0.2, 0.2, 0.2, 0.0, 5.00, 0.0, 0.0 }
 };
 
+static const float clear_color[] = {
+	0.2, 0.2, 0.2, 0.2
+};
+
 /* Square rotations */
 static const float rotation[NUM_SQUARES] = {
 	0.0,
@@ -183,22 +187,58 @@ piglit_init(int argc, char **argv)
 
 	setup_ubos();
 
-	glClearColor(0.2, 0.2, 0.2, 0.2);
+	glClearColor(clear_color[0], clear_color[1],
+		     clear_color[2], clear_color[3]);
 }
 
 
 static bool
-probe(int x, int y, int color_index)
+probe(int square_index)
 {
-	float expected[4];
+	float square_color[4];
+	const float *expected;
+
+	assert(piglit_width == piglit_height);
+
+	float cx = (pos_size[square_index][2] / 2.0f + 0.5f) * piglit_width;
+	float cy = (pos_size[square_index][3] / 2.0f + 0.5f) * piglit_height;
+	int size = pos_size[square_index][6] * piglit_width - 2;
+	float rot = rotation[square_index];
+	float rot_cos = cosf(rot);
+	float rot_sin = sinf(rot);
 
 	/* mul color by color_scale */
-	expected[0] = color[color_index][0] * color[color_index][5];
-	expected[1] = color[color_index][1] * color[color_index][5];
-	expected[2] = color[color_index][2] * color[color_index][5];
-	expected[3] = color[color_index][3] * color[color_index][5];
+	for (int i = 0; i < 4; i++) {
+		square_color[i] = (color[square_index][i] *
+				   color[square_index][5]);
+	}
+
+	for (int y = -(size / 2) - 4; y <= size / 2 + 4; y++) {
+		for (int x = -(size / 2) - 4 ; x <= size / 2 + 4; x++) {
+			int px = cx + x * rot_cos - y * rot_sin;
+			int py = cy + x * rot_sin + y * rot_cos;
+			/* Skip pixels that are outside of the screen
+			 * or too close to the edge of the square
+			 */
+			if (px < 0 || px >= piglit_width ||
+			    py < 0 || py >= piglit_height ||
+			    abs(abs(x) - size / 2) <= 2 ||
+			    abs(abs(y) - size / 2) <= 2) {
+				continue;
+			}
+
+			if (abs(x) >= size / 2 ||
+			    abs(y) >= size / 2)
+				expected = clear_color;
+			else
+				expected = square_color;
+
+			if (!piglit_probe_pixel_rgba(px, py, expected))
+				return false;
+		}
+	}
 
-	return piglit_probe_pixel_rgba(x, y, expected);
+	return true;
 }
 
 
@@ -207,10 +247,6 @@ piglit_display(void)
 {
 	GLsync fence;
 	bool pass = true;
-	int x0 = piglit_width / 4;
-	int x1 = piglit_width * 3 / 4;
-	int y0 = piglit_height / 4;
-	int y1 = piglit_height * 3 / 4;
 	int i;
 
 	glViewport(0, 0, piglit_width, piglit_height);
@@ -233,10 +269,8 @@ piglit_display(void)
 		piglit_draw_rect(-1, -1, 2, 2);
 	}
 
-	pass = probe(x0, y0, 0) && pass;
-	pass = probe(x1, y0, 1) && pass;
-	pass = probe(x0, y1, 2) && pass;
-	pass = probe(x1, y1, 3) && pass;
+	for (i = 0; i < NUM_SQUARES; i++)
+		pass = probe(i) && pass;
 
 	piglit_present_results();
 
diff --git a/tests/spec/arb_shader_storage_buffer_object/rendering.c b/tests/spec/arb_shader_storage_buffer_object/rendering.c
index e68acbfaf..c5afcde1c 100644
--- a/tests/spec/arb_shader_storage_buffer_object/rendering.c
+++ b/tests/spec/arb_shader_storage_buffer_object/rendering.c
@@ -107,6 +107,10 @@ static const float color[NUM_SQUARES][8] = {
 	{ 0.2, 0.2, 0.2, 0.2,   5.00, 0.0, 0.0, 0.0 }
 };
 
+static const float clear_color[] = {
+	0.2, 0.2, 0.2, 0.2
+};
+
 /* Square rotations */
 static const float rotation[NUM_SQUARES] = {
 	0.0,
@@ -240,22 +244,58 @@ piglit_init(int argc, char **argv)
 
 	setup_ubos();
 
-	glClearColor(0.2, 0.2, 0.2, 0.2);
+	glClearColor(clear_color[0], clear_color[1],
+		     clear_color[2], clear_color[3]);
 }
 
 
 static bool
-probe(int x, int y, int color_index)
+probe(int square_index)
 {
-	float expected[4];
+	float square_color[4];
+	const float *expected;
+
+	assert(piglit_width == piglit_height);
+
+	float cx = (pos_size[square_index][0] / 2.0f + 0.5f) * piglit_width;
+	float cy = (pos_size[square_index][1] / 2.0f + 0.5f) * piglit_height;
+	int size = pos_size[square_index][2] * piglit_width - 2;
+	float rot = rotation[square_index];
+	float rot_cos = cosf(rot);
+	float rot_sin = sinf(rot);
 
 	/* mul color by color_scale */
-	expected[0] = color[color_index][0] * color[color_index][4];
-	expected[1] = color[color_index][1] * color[color_index][4];
-	expected[2] = color[color_index][2] * color[color_index][4];
-	expected[3] = color[color_index][3] * color[color_index][4];
+	for (int i = 0; i < 4; i++) {
+		square_color[i] = (color[square_index][i] *
+				   color[square_index][4]);
+	}
+
+	for (int y = -(size / 2) - 4; y <= size / 2 + 4; y++) {
+		for (int x = -(size / 2) - 4 ; x <= size / 2 + 4; x++) {
+			int px = cx + x * rot_cos - y * rot_sin;
+			int py = cy + x * rot_sin + y * rot_cos;
+			/* Skip pixels that are outside of the screen
+			 * or too close to the edge of the square
+			 */
+			if (px < 0 || px >= piglit_width ||
+			    py < 0 || py >= piglit_height ||
+			    abs(abs(x) - size / 2) <= 2 ||
+			    abs(abs(y) - size / 2) <= 2) {
+				continue;
+			}
+
+			if (abs(x) >= size / 2 ||
+			    abs(y) >= size / 2)
+				expected = clear_color;
+			else
+				expected = square_color;
+
+			if (!piglit_probe_pixel_rgba(px, py, expected))
+				return false;
+		}
+	}
 
-	return piglit_probe_pixel_rgba(x, y, expected);
+	return true;
 }
 
 
@@ -263,10 +303,6 @@ enum piglit_result
 piglit_display(void)
 {
 	bool pass = true;
-	int x0 = piglit_width / 4;
-	int x1 = piglit_width * 3 / 4;
-	int y0 = piglit_height / 4;
-	int y1 = piglit_height * 3 / 4;
 	int i;
 
 	glViewport(0, 0, piglit_width, piglit_height);
@@ -303,10 +339,8 @@ piglit_display(void)
 		piglit_draw_rect(-1, -1, 2, 2);
 	}
 
-	pass = probe(x0, y0, 0) && pass;
-	pass = probe(x1, y0, 1) && pass;
-	pass = probe(x0, y1, 2) && pass;
-	pass = probe(x1, y1, 3) && pass;
+	for (i = 0; i < NUM_SQUARES; i++)
+		pass = probe(i) && pass;
 
 	piglit_present_results();
 
diff --git a/tests/spec/arb_uniform_buffer_object/bufferstorage.c b/tests/spec/arb_uniform_buffer_object/bufferstorage.c
index e3e138342..98ecb5838 100644
--- a/tests/spec/arb_uniform_buffer_object/bufferstorage.c
+++ b/tests/spec/arb_uniform_buffer_object/bufferstorage.c
@@ -86,6 +86,10 @@ static const float color[NUM_SQUARES][8] = {
 	{ 0.2, 0.2, 0.2, 0.2,   5.00, 0.0, 0.0, 0.0 }
 };
 
+static const float clear_color[] = {
+	0.2, 0.2, 0.2, 0.2
+};
+
 /* Square rotations */
 static const float rotation[NUM_SQUARES] = {
 	0.0,
@@ -167,22 +171,58 @@ piglit_init(int argc, char **argv)
 
 	setup_ubos();
 
-	glClearColor(0.2, 0.2, 0.2, 0.2);
+	glClearColor(clear_color[0], clear_color[1],
+		     clear_color[2], clear_color[3]);
 }
 
 
 static bool
-probe(int x, int y, int color_index)
+probe(int square_index)
 {
-	float expected[4];
+	float square_color[4];
+	const float *expected;
+
+	assert(piglit_width == piglit_height);
+
+	float cx = (pos_size[square_index][0] / 2.0f + 0.5f) * piglit_width;
+	float cy = (pos_size[square_index][1] / 2.0f + 0.5f) * piglit_height;
+	int size = pos_size[square_index][2] * piglit_width - 2;
+	float rot = rotation[square_index];
+	float rot_cos = cosf(rot);
+	float rot_sin = sinf(rot);
 
 	/* mul color by color_scale */
-	expected[0] = color[color_index][0] * color[color_index][4];
-	expected[1] = color[color_index][1] * color[color_index][4];
-	expected[2] = color[color_index][2] * color[color_index][4];
-	expected[3] = color[color_index][3] * color[color_index][4];
+	for (int i = 0; i < 4; i++) {
+		square_color[i] = (color[square_index][i] *
+				   color[square_index][4]);
+	}
+
+	for (int y = -(size / 2) - 4; y <= size / 2 + 4; y++) {
+		for (int x = -(size / 2) - 4 ; x <= size / 2 + 4; x++) {
+			int px = cx + x * rot_cos - y * rot_sin;
+			int py = cy + x * rot_sin + y * rot_cos;
+			/* Skip pixels that are outside of the screen
+			 * or too close to the edge of the square
+			 */
+			if (px < 0 || px >= piglit_width ||
+			    py < 0 || py >= piglit_height ||
+			    abs(abs(x) - size / 2) <= 2 ||
+			    abs(abs(y) - size / 2) <= 2) {
+				continue;
+			}
+
+			if (abs(x) >= size / 2 ||
+			    abs(y) >= size / 2)
+				expected = clear_color;
+			else
+				expected = square_color;
+
+			if (!piglit_probe_pixel_rgba(px, py, expected))
+				return false;
+		}
+	}
 
-	return piglit_probe_pixel_rgba(x, y, expected);
+	return true;
 }
 
 
@@ -191,10 +231,6 @@ piglit_display(void)
 {
 	GLsync fence;
 	bool pass = true;
-	int x0 = piglit_width / 4;
-	int x1 = piglit_width * 3 / 4;
-	int y0 = piglit_height / 4;
-	int y1 = piglit_height * 3 / 4;
 	int i;
 
 	glViewport(0, 0, piglit_width, piglit_height);
@@ -217,10 +253,8 @@ piglit_display(void)
 		piglit_draw_rect(-1, -1, 2, 2);
 	}
 
-	pass = probe(x0, y0, 0) && pass;
-	pass = probe(x1, y0, 1) && pass;
-	pass = probe(x0, y1, 2) && pass;
-	pass = probe(x1, y1, 3) && pass;
+	for (i = 0; i < NUM_SQUARES; i++)
+		pass = probe(i) && pass;
 
 	piglit_present_results();
 
diff --git a/tests/spec/arb_uniform_buffer_object/rendering-dsa.c b/tests/spec/arb_uniform_buffer_object/rendering-dsa.c
index 599a6c304..be8c31b43 100644
--- a/tests/spec/arb_uniform_buffer_object/rendering-dsa.c
+++ b/tests/spec/arb_uniform_buffer_object/rendering-dsa.c
@@ -84,6 +84,10 @@ static const float color[NUM_SQUARES][8] = {
 	{ 0.2, 0.2, 0.2, 0.2,   5.00, 0.0, 0.0, 0.0 }
 };
 
+static const float clear_color[] = {
+	0.2, 0.2, 0.2, 0.2
+};
+
 /* Square rotations */
 static const float rotation[NUM_SQUARES] = {
 	0.0,
@@ -165,22 +169,58 @@ piglit_init(int argc, char **argv)
 
 	setup_ubos();
 
-	glClearColor(0.2, 0.2, 0.2, 0.2);
+	glClearColor(clear_color[0], clear_color[1],
+		     clear_color[2], clear_color[3]);
 }
 
 
 static bool
-probe(int x, int y, int color_index)
+probe(int square_index)
 {
-	float expected[4];
+	float square_color[4];
+	const float *expected;
+
+	assert(piglit_width == piglit_height);
+
+	float cx = (pos_size[square_index][0] / 2.0f + 0.5f) * piglit_width;
+	float cy = (pos_size[square_index][1] / 2.0f + 0.5f) * piglit_height;
+	int size = pos_size[square_index][2] * piglit_width - 2;
+	float rot = rotation[square_index];
+	float rot_cos = cosf(rot);
+	float rot_sin = sinf(rot);
 
 	/* mul color by color_scale */
-	expected[0] = color[color_index][0] * color[color_index][4];
-	expected[1] = color[color_index][1] * color[color_index][4];
-	expected[2] = color[color_index][2] * color[color_index][4];
-	expected[3] = color[color_index][3] * color[color_index][4];
+	for (int i = 0; i < 4; i++) {
+		square_color[i] = (color[square_index][i] *
+				   color[square_index][4]);
+	}
+
+	for (int y = -(size / 2) - 4; y <= size / 2 + 4; y++) {
+		for (int x = -(size / 2) - 4 ; x <= size / 2 + 4; x++) {
+			int px = cx + x * rot_cos - y * rot_sin;
+			int py = cy + x * rot_sin + y * rot_cos;
+			/* Skip pixels that are outside of the screen
+			 * or too close to the edge of the square
+			 */
+			if (px < 0 || px >= piglit_width ||
+			    py < 0 || py >= piglit_height ||
+			    abs(abs(x) - size / 2) <= 2 ||
+			    abs(abs(y) - size / 2) <= 2) {
+				continue;
+			}
+
+			if (abs(x) >= size / 2 ||
+			    abs(y) >= size / 2)
+				expected = clear_color;
+			else
+				expected = square_color;
+
+			if (!piglit_probe_pixel_rgba(px, py, expected))
+				return false;
+		}
+	}
 
-	return piglit_probe_pixel_rgba(x, y, expected);
+	return true;
 }
 
 
@@ -188,10 +228,6 @@ enum piglit_result
 piglit_display(void)
 {
 	bool pass = true;
-	int x0 = piglit_width / 4;
-	int x1 = piglit_width * 3 / 4;
-	int y0 = piglit_height / 4;
-	int y1 = piglit_height * 3 / 4;
 	int i;
 
 	glViewport(0, 0, piglit_width, piglit_height);
@@ -213,10 +249,8 @@ piglit_display(void)
 		piglit_draw_rect(-1, -1, 2, 2);
 	}
 
-	pass = probe(x0, y0, 0) && pass;
-	pass = probe(x1, y0, 1) && pass;
-	pass = probe(x0, y1, 2) && pass;
-	pass = probe(x1, y1, 3) && pass;
+	for (i = 0; i < NUM_SQUARES; i++)
+		pass = probe(i) && pass;
 
 	piglit_present_results();
 
diff --git a/tests/spec/arb_uniform_buffer_object/rendering.c b/tests/spec/arb_uniform_buffer_object/rendering.c
index f5b1e7f5d..f16eff8d3 100644
--- a/tests/spec/arb_uniform_buffer_object/rendering.c
+++ b/tests/spec/arb_uniform_buffer_object/rendering.c
@@ -84,6 +84,10 @@ static const float color[NUM_SQUARES][8] = {
 	{ 0.2, 0.2, 0.2, 0.2,   5.00, 0.0, 0.0, 0.0 }
 };
 
+static const float clear_color[] = {
+	0.2, 0.2, 0.2, 0.2
+};
+
 /* Square rotations */
 static const float rotation[NUM_SQUARES] = {
 	0.0,
@@ -172,22 +176,58 @@ piglit_init(int argc, char **argv)
 
 	setup_ubos();
 
-	glClearColor(0.2, 0.2, 0.2, 0.2);
+	glClearColor(clear_color[0], clear_color[1],
+		     clear_color[2], clear_color[3]);
 }
 
 
 static bool
-probe(int x, int y, int color_index)
+probe(int square_index)
 {
-	float expected[4];
+	float square_color[4];
+	const float *expected;
+
+	assert(piglit_width == piglit_height);
+
+	float cx = (pos_size[square_index][0] / 2.0f + 0.5f) * piglit_width;
+	float cy = (pos_size[square_index][1] / 2.0f + 0.5f) * piglit_height;
+	int size = pos_size[square_index][2] * piglit_width - 2;
+	float rot = rotation[square_index];
+	float rot_cos = cosf(rot);
+	float rot_sin = sinf(rot);
 
 	/* mul color by color_scale */
-	expected[0] = color[color_index][0] * color[color_index][4];
-	expected[1] = color[color_index][1] * color[color_index][4];
-	expected[2] = color[color_index][2] * color[color_index][4];
-	expected[3] = color[color_index][3] * color[color_index][4];
+	for (int i = 0; i < 4; i++) {
+		square_color[i] = (color[square_index][i] *
+				   color[square_index][4]);
+	}
+
+	for (int y = -(size / 2) - 4; y <= size / 2 + 4; y++) {
+		for (int x = -(size / 2) - 4 ; x <= size / 2 + 4; x++) {
+			int px = cx + x * rot_cos - y * rot_sin;
+			int py = cy + x * rot_sin + y * rot_cos;
+			/* Skip pixels that are outside of the screen
+			 * or too close to the edge of the square
+			 */
+			if (px < 0 || px >= piglit_width ||
+			    py < 0 || py >= piglit_height ||
+			    abs(abs(x) - size / 2) <= 2 ||
+			    abs(abs(y) - size / 2) <= 2) {
+				continue;
+			}
+
+			if (abs(x) >= size / 2 ||
+			    abs(y) >= size / 2)
+				expected = clear_color;
+			else
+				expected = square_color;
+
+			if (!piglit_probe_pixel_rgba(px, py, expected))
+				return false;
+		}
+	}
 
-	return piglit_probe_pixel_rgba(x, y, expected);
+	return true;
 }
 
 
@@ -195,10 +235,6 @@ enum piglit_result
 piglit_display(void)
 {
 	bool pass = true;
-	int x0 = piglit_width / 4;
-	int x1 = piglit_width * 3 / 4;
-	int y0 = piglit_height / 4;
-	int y1 = piglit_height * 3 / 4;
 	int i;
 
 	glViewport(0, 0, piglit_width, piglit_height);
@@ -223,10 +259,8 @@ piglit_display(void)
 		piglit_draw_rect(-1, -1, 2, 2);
 	}
 
-	pass = probe(x0, y0, 0) && pass;
-	pass = probe(x1, y0, 1) && pass;
-	pass = probe(x0, y1, 2) && pass;
-	pass = probe(x1, y1, 3) && pass;
+	for (i = 0; i < NUM_SQUARES; i++)
+		pass = probe(i) && pass;
 
 	piglit_present_results();
 
-- 
2.14.3



More information about the Piglit mailing list