[Piglit] [PATCH v2 2/5] Add piglit_equal_images_update_rgba8 to piglit-util-gl

Nicolai Hähnle nhaehnle at gmail.com
Thu Jan 21 12:33:08 PST 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

This is a slightly extended variant of equal_images from texsubimage
which will also be used in the new texsubimage-unpack test.

I've decided to call it "equal" instead of "compare", since I feel that
makes the meaning of the return value more obvious.
---
 tests/texturing/texsubimage.c | 28 +++-----------------
 tests/util/piglit-util-gl.c   | 60 +++++++++++++++++++++++++++++++++++++++++++
 tests/util/piglit-util-gl.h   |  7 +++++
 3 files changed, 71 insertions(+), 24 deletions(-)

diff --git a/tests/texturing/texsubimage.c b/tests/texturing/texsubimage.c
index c66f93c..cc8f6b5 100644
--- a/tests/texturing/texsubimage.c
+++ b/tests/texturing/texsubimage.c
@@ -228,9 +228,6 @@ equal_images(GLenum target,
 	     GLuint tx, GLuint ty, GLuint tz,
 	     GLuint tw, GLuint th, GLuint td)
 {
-	const GLubyte *ref;
-	GLuint z, y, x;
-
 	switch (target) {
 	case GL_TEXTURE_1D:
 		ty = 0;
@@ -243,27 +240,10 @@ equal_images(GLenum target,
 		break;
 	}
 
-	for (z = 0; z < d; z++) {
-		for (y = 0; y < h; y++) {
-			for (x = 0; x < w; x++) {
-				if (x >= tx && x < tx + tw &&
-				    y >= ty && y < ty + th &&
-				    z >= tz && z < tz + td)
-					ref = updated_ref;
-				else
-					ref = original_ref;
-
-				if (memcmp(ref, testImg, 4))
-					return GL_FALSE;
-
-				testImg += 4;
-				original_ref += 4;
-				updated_ref += 4;
-			}
-		}
-	}
-
-	return GL_TRUE;
+	return piglit_equal_images_update_rgba8(original_ref, updated_ref, testImg,
+						w, h, d,
+						tx, ty, tz, tw, th, td,
+						8);
 }
 
 /**
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index 61764fb..8052a29 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -1573,6 +1573,66 @@ piglit_compare_images_ubyte(int x, int y, int w, int h,
 }
 
 /**
+ * Compare the image (array) stored in \p observed with the image obtained from
+ * \p expected_original with the box described by ux,uy,uz and uw,uh,ud
+ * replaced by \p expected_updated.
+ *
+ * Only the highest \p bits bits of all four channels are compared.
+ */
+int
+piglit_equal_images_update_rgba8(const GLubyte *expected_original,
+				 const GLubyte *expected_updated,
+				 const GLubyte *observed,
+				 unsigned w, unsigned h, unsigned d,
+				 unsigned ux, unsigned uy, unsigned uz,
+				 unsigned uw, unsigned uh, unsigned ud,
+				 unsigned bits)
+{
+	assert(bits > 0 && bits <= 8);
+
+	unsigned x, y, z;
+	const uint8_t compare_mask = 0xff << (8 - bits);
+
+	for (z = 0; z < d; ++z) {
+		for (y = 0; y < h; y++) {
+			for (x = 0; x < w; x++) {
+				const GLubyte *ref;
+
+				if (x >= ux && x < ux + uw &&
+				    y >= uy && y < uy + uh &&
+				    z >= uz && z < uz + ud)
+					ref = expected_updated;
+				else
+					ref = expected_original;
+
+				bool fail =
+					((ref[0] ^ observed[0]) |
+					 (ref[1] ^ observed[1]) |
+					 (ref[2] ^ observed[2]) |
+					 (ref[3] ^ observed[3])) &
+					compare_mask;
+				if (fail) {
+					printf("%u,%u,%u: test = %u,%u,%u,%u "
+						"ref = %u,%u,%u,%u (comparing %u bits)\n",
+						x, y, z,
+						observed[0], observed[1],
+						observed[2], observed[3],
+						ref[0], ref[1], ref[2], ref[3],
+						bits);
+					return 0;
+				}
+
+				observed += 4;
+				expected_original += 4;
+				expected_updated += 4;
+			}
+		}
+	}
+
+	return 1;
+}
+
+/**
  * Compare the contents of the current read framebuffer's stencil
  * buffer with the given in-memory byte image.
  */
diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
index 4ba0aa3..f64ffa9 100644
--- a/tests/util/piglit-util-gl.h
+++ b/tests/util/piglit-util-gl.h
@@ -176,6 +176,13 @@ int piglit_probe_image_rgba(int x, int y, int w, int h, const float *image);
 int piglit_compare_images_ubyte(int x, int y, int w, int h,
 				const GLubyte *expected_image,
 				const GLubyte *observed_image);
+int piglit_equal_images_update_rgba8(const GLubyte *expected_original,
+				     const GLubyte *expected_updated,
+				     const GLubyte *observed,
+				     unsigned w, unsigned h, unsigned d,
+				     unsigned ux, unsigned uy, unsigned uz,
+				     unsigned uw, unsigned uh, unsigned ud,
+				     unsigned bits);
 int piglit_probe_image_stencil(int x, int y, int w, int h, const GLubyte *image);
 int piglit_probe_image_ubyte(int x, int y, int w, int h, GLenum format,
 			     const GLubyte *image);
-- 
2.5.0



More information about the Piglit mailing list