[Piglit] [PATCH 2/3] util: add piglit_probe_rect_r_ubyte

Marek Olšák maraeo at gmail.com
Sat Aug 23 09:38:17 PDT 2014


From: Marek Olšák <marek.olsak at amd.com>

This is a lot faster than RGBA FLOAT.

There is a potential to speed up piglit by switching tests to ubyte
r, rg, or rgba probing.
---
 tests/util/piglit-util-gl.c | 32 ++++++++++++++++++++++++++++++++
 tests/util/piglit-util-gl.h |  1 +
 2 files changed, 33 insertions(+)

diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
index b711000..0858b01 100644
--- a/tests/util/piglit-util-gl.c
+++ b/tests/util/piglit-util-gl.c
@@ -1145,6 +1145,38 @@ piglit_probe_rect_rgb_silent(int x, int y, int w, int h, const float *expected)
 	return 1;
 }
 
+/* More efficient variant if you don't know need floats and GBA channels. */
+int
+piglit_probe_rect_r_ubyte(int x, int y, int w, int h, GLubyte expected)
+{
+	int i, j, w_aligned;
+	GLubyte *pixels;
+	GLubyte tolerance = ceil(piglit_tolerance[0] * 255);
+
+	w_aligned = ALIGN(w, 4);
+	pixels = malloc(w_aligned * h);
+
+	glReadPixels(x, y, w, h, GL_RED, GL_UNSIGNED_BYTE, pixels);
+
+	for (j = 0; j < h; j++) {
+		for (i = 0; i < w; i++) {
+			GLubyte probe = pixels[j*w_aligned+i];
+
+			if (probe - expected >= tolerance) {
+				printf("Probe color at (%i,%i)\n", x+i, y+j);
+				printf("  Expected: %u\n", expected);
+				printf("  Observed: %u\n", probe);
+
+				free(pixels);
+				return 0;
+			}
+		}
+	}
+
+	free(pixels);
+	return 1;
+}
+
 int
 piglit_probe_rect_rgb(int x, int y, int w, int h, const float *expected)
 {
diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h
index 5c74069..adf98d8 100644
--- a/tests/util/piglit-util-gl.h
+++ b/tests/util/piglit-util-gl.h
@@ -126,6 +126,7 @@ int piglit_probe_pixel_rgb_silent(int x, int y, const float* expected, float *ou
 int piglit_probe_pixel_rgba_silent(int x, int y, const float* expected, float *out_probe);
 int piglit_probe_pixel_rgb(int x, int y, const float* expected);
 int piglit_probe_pixel_rgba(int x, int y, const float* expected);
+int piglit_probe_rect_r_ubyte(int x, int y, int w, int h, GLubyte expected);
 int piglit_probe_rect_rgb(int x, int y, int w, int h, const float* expected);
 int piglit_probe_rect_rgb_silent(int x, int y, int w, int h, const float *expected);
 int piglit_probe_rect_rgba(int x, int y, int w, int h, const float* expected);
-- 
1.9.1



More information about the Piglit mailing list