summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolai Hähnle <nicolai.haehnle@amd.com>2016-01-21 15:19:56 -0500
committerNicolai Hähnle <nicolai.haehnle@amd.com>2016-02-03 15:01:37 +0100
commit6a2328ce487e16fdda2ceb422687cf711be3632e (patch)
tree981d6e189f99cec06d94ccc2ebc21a8b11f6e7ea
parente8492e40729405c21bf8ddcbb89a315334abd9f6 (diff)
Add piglit_equal_images_update_rgba8 to piglit-util-gl
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.
-rw-r--r--tests/texturing/texsubimage.c28
-rw-r--r--tests/util/piglit-util-gl.c60
-rw-r--r--tests/util/piglit-util-gl.h7
3 files changed, 71 insertions, 24 deletions
diff --git a/tests/texturing/texsubimage.c b/tests/texturing/texsubimage.c
index c66f93c93..cc8f6b560 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 98600ff57..d636810c9 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 7e98e3b45..00c106b7a 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);