[Piglit] [PATCH v4 1/5] util: Add a piglit_probe_rects_equal_rgba() function

Nanley Chery nanleychery at gmail.com
Fri Oct 2 14:44:01 PDT 2015


From: Nanley Chery <nanley.g.chery at intel.com>

This function compares two rectangles for equality. This is useful
to compare the rendering of individual miplevels in a miptree while
avoiding too much resource consumption.

v2: insert spaces in addition operation (Chad).

Reviewed-by: Chad Versace <chad.versace at intel.com>
Signed-off-by: Nanley Chery <nanley.g.chery at intel.com>
---
 tests/util/piglit-util-gl.c | 81 +++++++++++++++++++++++++++++++++++++++++++++
 tests/util/piglit-util-gl.h | 31 +++++++++++++++++
 2 files changed, 112 insertions(+)

diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 1a24067..ca5d939 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -1240,6 +1240,41 @@ piglit_probe_rect_rgb(int x, int y, int w, int h, const float *expected)
 }
 
 int
+piglit_probe_rects_equal(int x1, int y1, int x2, int y2,
+			int w, int h, GLenum format)
+{
+	int retval;
+	GLfloat *pixels;
+	int ncomponents, rect_size;
+
+	/* Allocate buffer large enough for two rectangles */
+	ncomponents = piglit_num_components(format);
+	rect_size = w * h * ncomponents;
+	pixels = malloc(2 * rect_size * sizeof(GLfloat));
+
+	/* Load the pixels into the buffer and compare */
+	/* We only need to do one glReadPixels if the images are adjacent */
+	if ((x1 + w) == x2 && y1 == y2) {
+		piglit_read_pixels_float(x1, y1, 2*w, h, format, pixels);
+		retval = piglit_compare_image_halves_color(2*w, h,
+						       ncomponents,
+						       piglit_tolerance,
+						       pixels);
+	} else {
+		piglit_read_pixels_float(x1, y1, w, h, format, pixels);
+		piglit_read_pixels_float(x2, y2, w, h, format,
+					pixels + rect_size);
+		retval = piglit_compare_images_color(0, 0, w, h,
+					       ncomponents,
+					       piglit_tolerance,
+					       pixels, pixels + rect_size);
+	}
+
+	free(pixels);
+	return retval;
+}
+
+int
 piglit_probe_rect_rgba(int x, int y, int w, int h, const float *expected)
 {
 	int i, j, p;
@@ -1376,6 +1411,52 @@ piglit_compute_probe_tolerance(GLenum format, float *tolerance)
 	}
 }
 
+int
+piglit_compare_pixels(int x, int y, const float *expected, const float *probe,
+			 const float *tolerance, int num_components)
+{
+	int p;
+
+	for (p = 0; p < num_components; ++p) {
+		if (fabs(probe[p] - expected[p]) >= tolerance[p]) {
+			printf("Probe at (%i,%i)\n", x, y);
+			printf("  Expected:");
+			print_pixel_float(expected, num_components);
+			printf("\n  Observed:");
+			print_pixel_float(probe, num_components);
+			printf("\n");
+
+			return 0;
+		}
+	}
+
+	return 1;
+}
+
+int
+piglit_compare_image_halves_color(int w, int h, int num_components,
+			    const float *tolerance,
+			    const float *image)
+{
+	int i, j, half_width;
+
+	half_width = w/2;
+	for (j = 0; j < h; j++) {
+		for (i = 0; i < half_width; i++) {
+			const float *probe =
+				&image[(j*w+i)*num_components];
+			const float *expected =
+				&image[(j*w+half_width+i)*num_components];
+			if (!piglit_compare_pixels(i, j, expected, probe,
+						tolerance,
+						num_components))
+				return 0;
+		}
+	}
+
+	return 1;
+}
+
 /**
  * Compare two in-memory floating-point images.
  */
diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
index ddba1bb..f06438a 100644
--- a/tests/util/piglit-util-gl.h
+++ b/tests/util/piglit-util-gl.h
@@ -142,6 +142,27 @@ int piglit_probe_rect_rgba(int x, int y, int w, int h, const float* expected);
 int piglit_probe_rect_rgba_int(int x, int y, int w, int h, const int* expected);
 int piglit_probe_rect_rgba_uint(int x, int y, int w, int h, const unsigned int* expected);
 void piglit_compute_probe_tolerance(GLenum format, float *tolerance);
+
+/**
+ * Compare two pixels.
+ * \param x the x coordinate of the pixel being probed
+ * \param y the y coordinate of the pixel being probed
+ */
+int piglit_compare_pixels(int x, int y, const float *expected, const float *probe,
+			 const float *tolerance, int num_components);
+
+/**
+ * Compare two adjacent in-memory floating-point images.
+ * Adjacent means: y1 == y2 && x1 == x2 - w;
+ *
+ * \param w the width of the rectangle containing both images
+ * \param h the height of the rectangle containing both images
+ * \param images : the start of the buffer containing the observed image on
+ *		the left and the expected image on the right
+ */
+int piglit_compare_image_halves_color(int w, int h, int num_components,
+			    const float *tolerance,
+			    const float *expected_observed_image);
 int piglit_compare_images_color(int x, int y, int w, int h, int num_components,
 				const float *tolerance,
 				const float *expected_image,
@@ -171,6 +192,16 @@ int piglit_probe_pixel_stencil(int x, int y, unsigned expected);
 int piglit_probe_rect_stencil(int x, int y, int w, int h, unsigned expected);
 int piglit_probe_rect_halves_equal_rgba(int x, int y, int w, int h);
 
+/**
+ * \brief Check if two rectangles are equivalent
+ *
+ * Given the coordinates of two rectangles, check that the two are equal.
+ * The first rectangle is what's observed, whereas the second rectangle is
+ * what's expected.
+ */
+int piglit_probe_rects_equal(int x1, int y1, int x2, int y2,
+			int w, int h, GLenum format);
+
 bool piglit_probe_buffer(GLuint buf, GLenum target, const char *label,
 			 unsigned n, unsigned num_components,
 			 const float *expected);
-- 
2.6.0



More information about the Piglit mailing list