Mesa (lp-binning): llvmpipe: optimize lp_rast_clear_color() for non-gray colors

Brian Paul brianp at kemper.freedesktop.org
Thu Jan 14 02:01:33 UTC 2010


Module: Mesa
Branch: lp-binning
Commit: f94a99170ecdc3286408b3628fbae9f45518007e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f94a99170ecdc3286408b3628fbae9f45518007e

Author: Brian Paul <brianp at vmware.com>
Date:   Wed Jan 13 18:54:48 2010 -0700

llvmpipe: optimize lp_rast_clear_color() for non-gray colors

This makes a big difference in progs that clear to a non-gray color.
Some demos are 30-50% faster.

---

 src/gallium/drivers/llvmpipe/lp_rast.c |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c
index 6c7ece9..3849116 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast.c
+++ b/src/gallium/drivers/llvmpipe/lp_rast.c
@@ -187,17 +187,33 @@ void lp_rast_clear_color( struct lp_rasterizer *rast,
    if (clear_color[0] == clear_color[1] &&
        clear_color[1] == clear_color[2] &&
        clear_color[2] == clear_color[3]) {
+      /* clear to grayscale value {x, x, x, x} */
       for (i = 0; i < rast->state.fb.nr_cbufs; i++) {
 	 memset(color_tile[i], clear_color[0], TILE_SIZE * TILE_SIZE * 4);
       }
    }
    else {
-      unsigned x, y, chan;
-      for (i = 0; i < rast->state.fb.nr_cbufs; i++)
-	 for (y = 0; y < TILE_SIZE; y++)
-	    for (x = 0; x < TILE_SIZE; x++)
-	       for (chan = 0; chan < 4; ++chan)
-		  TILE_PIXEL(color_tile[i], x, y, chan) = clear_color[chan];
+      /* Non-gray color.
+       * Note: if the swizzled tile layout changes (see TILE_PIXEL) this code
+       * will need to change.  It'll be pretty obvious when clearing no longer
+       * works.
+       */
+      const unsigned chunk = TILE_SIZE / 4;
+      for (i = 0; i < rast->state.fb.nr_cbufs; i++) {
+         uint8_t *c = color_tile[i];
+         unsigned j;
+         for (j = 0; j < 4 * TILE_SIZE; j++) {
+            memset(c, clear_color[0], chunk);
+            c += chunk;
+            memset(c, clear_color[1], chunk);
+            c += chunk;
+            memset(c, clear_color[2], chunk);
+            c += chunk;
+            memset(c, clear_color[3], chunk);
+            c += chunk;
+         }
+         assert(c - color_tile[i] == TILE_SIZE * TILE_SIZE * 4);
+      }
    }
 }
 




More information about the mesa-commit mailing list