[Piglit] [PATCH 2/4] fbo-pbo-readpixels-small: make it endian-safe

Oded Gabbay oded.gabbay at gmail.com
Mon Mar 28 13:25:13 UTC 2016


In this test we use GL_BGRA + GL_UNSIGNED_BYTE. However, the probe
function receives two 4-byte values to compare, expected and observed.
This is wrong as the correct way to compare array_of_bytes
(GL_UNSIGNED_BYTE) in an endian-safe way is by comparing memory (and not
values).

This patch fixes this bug by changing the function to receive two
pointers instead of values. It also corrects the way the expected values
are constructed to be in endian-safe way for array-of-bytes

This fixes the test in llvmpipe, softpipe and r600g in big-endian machine.

Signed-off-by: Oded Gabbay <oded.gabbay at gmail.com>
---
 tests/fbo/fbo-pbo-readpixels-small.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/tests/fbo/fbo-pbo-readpixels-small.c b/tests/fbo/fbo-pbo-readpixels-small.c
index c7730b2..7f17e0e 100644
--- a/tests/fbo/fbo-pbo-readpixels-small.c
+++ b/tests/fbo/fbo-pbo-readpixels-small.c
@@ -80,12 +80,17 @@ make_fbo(GLuint *fbo, GLuint *tex)
 }
 
 static GLboolean
-probe(int x, int y, uint32_t expected, uint32_t observed)
+probe(int x, int y, uint32_t *expected, uint32_t *observed)
 {
-	if ((expected & 0xffffff) != (observed & 0xffffff)) {
+	uint8_t *p_exp = (uint8_t *) expected;
+	uint8_t *p_obs = (uint8_t *) observed;
+
+	if (p_exp[0] != p_obs[0] ||
+		 p_exp[1] != p_obs[1] ||
+		 p_exp[2] != p_obs[2]) {
 		printf("Probe color at (%i,%i)\n", x, y);
-		printf("  Expected: 0x%08x\n", expected);
-		printf("  Observed: 0x%08x\n", observed);
+		printf("  Expected: 0x%08x\n", *expected);
+		printf("  Observed: 0x%08x\n", *observed);
 
 		return GL_FALSE;
 	} else {
@@ -99,6 +104,13 @@ piglit_display(void)
 	GLboolean pass = GL_TRUE;
 	GLuint fbo, tex, pbo;
 	uint32_t *addr;
+	GLuint green = 0, blue = 0;
+	GLbyte *ptr;
+
+	ptr = (GLbyte *) &green;
+	ptr[1] = 0xFF;
+	ptr = (GLbyte *) &blue;
+	ptr[0] = 0xFF;
 
 	make_fbo(&fbo, &tex);
 
@@ -122,24 +134,25 @@ piglit_display(void)
 	glReadPixels(0, 0, 2, 2,
 		     GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)0);
 	addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
-	pass &= probe(0, 0, 0x0000ff00, addr[0]);
-	pass &= probe(1, 0, 0x0000ff00, addr[1]);
-	pass &= probe(0, 1, 0x000000ff, addr[2]);
-	pass &= probe(1, 1, 0x000000ff, addr[3]);
+
+	pass &= probe(0, 0, &green, &addr[0]);
+	pass &= probe(1, 0, &green, &addr[1]);
+	pass &= probe(0, 1, &blue, &addr[2]);
+	pass &= probe(1, 1, &blue, &addr[3]);
 	glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
 
 	/* Read with an offset. */
 	glReadPixels(1, 0, 1, 1,
 		     GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4);
 	addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
-	pass &= probe(1, 0, 0x0000ff00, addr[1]);
+	pass &= probe(1, 0, &green, &addr[1]);
 	glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
 
 	/* Read with an offset. */
 	glReadPixels(1, 1, 1, 1,
 		     GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4);
 	addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
-	pass &= probe(1, 1, 0x000000ff, addr[1]);
+	pass &= probe(1, 1, &blue, &addr[1]);
 	glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
 
 	glDeleteBuffersARB(1, &pbo);
-- 
2.5.5



More information about the Piglit mailing list