[2/3] util: add piglit_probe_rect_r_ubyte

Submitted by Marek Olšák on Aug. 23, 2014, 4:38 p.m.

Details

Message ID 1408811898-10593-2-git-send-email-maraeo@gmail.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Marek Olšák Aug. 23, 2014, 4:38 p.m.
From: Marek Olšák <marek.olsak@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(+)

Patch hide | download patch | download mbox

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);

Comments

On Sun, Aug 24, 2014 at 4:38 AM, Marek Olšák <maraeo@gmail.com> wrote:
> From: Marek Olšák <marek.olsak@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) {

Looks like you want abs() here?