util: new util_fill_box helper
authorRoland Scheidegger <sroland@vmware.com>
Wed, 12 Jun 2013 22:40:34 +0000 (00:40 +0200)
committerRoland Scheidegger <sroland@vmware.com>
Wed, 12 Jun 2013 22:41:43 +0000 (00:41 +0200)
Use new util_fill_box helper for util_clear_render_target.
(Also fix off-by-one map error.)

v2: handle non-zero z correctly in new helper

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/util/u_surface.c
src/gallium/auxiliary/util/u_surface.h
src/gallium/drivers/llvmpipe/lp_rast.c

index 77d04ba7244046fcf56d2aa741c4a35128020e86..17591f11988522743a8c0e2fdb208414078da793 100644 (file)
@@ -214,6 +214,30 @@ util_fill_rect(ubyte * dst,
 }
 
 
+void
+util_fill_box(ubyte * dst,
+              enum pipe_format format,
+              unsigned stride,
+              unsigned layer_stride,
+              unsigned x,
+              unsigned y,
+              unsigned z,
+              unsigned width,
+              unsigned height,
+              unsigned depth,
+              union util_color *uc)
+{
+   unsigned layer;
+   dst += z * layer_stride;
+   for (layer = z; layer < depth; layer++) {
+      util_fill_rect(dst, format,
+                     stride,
+                     x, y, width, height, uc);
+      dst += layer_stride;
+   }
+}
+
+
 /**
  * Fallback function for pipe->resource_copy_region().
  * Note: (X,Y)=(0,0) is always the upper-left corner.
@@ -319,7 +343,7 @@ util_clear_render_target(struct pipe_context *pipe,
    struct pipe_transfer *dst_trans;
    ubyte *dst_map;
    union util_color uc;
-   unsigned max_layer, layer;
+   unsigned max_layer;
 
    assert(dst->texture);
    if (!dst->texture)
@@ -349,7 +373,7 @@ util_clear_render_target(struct pipe_context *pipe,
                                      dst->u.tex.level,
                                      PIPE_TRANSFER_WRITE,
                                      dstx, dsty, dst->u.tex.first_layer,
-                                     width, height, max_layer, &dst_trans);
+                                     width, height, max_layer + 1, &dst_trans);
    }
 
    assert(dst_map);
@@ -376,12 +400,9 @@ util_clear_render_target(struct pipe_context *pipe,
          util_pack_color(color->f, dst->format, &uc);
       }
 
-      for (layer = 0; layer <= max_layer; layer++) {
-         util_fill_rect(dst_map, dst->format,
-                        dst_trans->stride,
-                        0, 0, width, height, &uc);
-         dst_map += dst_trans->layer_stride;
-      }
+      util_fill_box(dst_map, dst->format,
+                    dst_trans->stride, dst_trans->layer_stride,
+                    0, 0, 0, width, height, max_layer + 1, &uc);
 
       pipe->transfer_unmap(pipe, dst_trans);
    }
@@ -430,8 +451,7 @@ util_clear_depth_stencil(struct pipe_context *pipe,
 
    if (dst_map) {
       unsigned dst_stride = dst_trans->stride;
-      uint64_t zstencil = util_pack64_z_stencil(format,
-                                                depth, stencil);
+      uint64_t zstencil = util_pack64_z_stencil(format, depth, stencil);
       ubyte *dst_layer = dst_map;
       unsigned i, j;
       assert(dst_trans->stride > 0);
index d6184acbdd33d2fa91460693894c2e0fcd32d7a1..bfd8f40d107ff919306b711f4ad912fa7c7d5027 100644 (file)
@@ -65,6 +65,13 @@ util_fill_rect(ubyte * dst, enum pipe_format format,
                unsigned dst_stride, unsigned dst_x, unsigned dst_y,
                unsigned width, unsigned height, union util_color *uc);
 
+extern void
+util_fill_box(ubyte * dst, enum pipe_format format,
+              unsigned stride, unsigned layer_stride,
+              unsigned x, unsigned y, unsigned z,
+              unsigned width, unsigned height, unsigned depth,
+              union util_color *uc);
+
 
 extern void
 util_resource_copy_region(struct pipe_context *pipe,
index dcd66ab00c1149c774c63d876f1ecbe05571a45b..79d4c588d12ba5e3aa48aac57a18cbf57714e491 100644 (file)
@@ -135,8 +135,6 @@ lp_rast_clear_color(struct lp_rasterizer_task *task,
 
          for (i = 0; i < scene->fb.nr_cbufs; i++) {
             enum pipe_format format = scene->fb.cbufs[i]->format;
-            unsigned layer;
-            uint8_t *map_layer = scene->cbufs[i].map;
 
             if (util_format_is_pure_sint(format)) {
                util_format_write_4i(format, arg.clear_color.i, 0, &uc, 0, 0, 0, 1, 1);
@@ -146,17 +144,17 @@ lp_rast_clear_color(struct lp_rasterizer_task *task,
                util_format_write_4ui(format, arg.clear_color.ui, 0, &uc, 0, 0, 0, 1, 1);
             }
 
-            for (layer = 0; layer <= scene->fb_max_layer; layer++) {
-               util_fill_rect(map_layer,
-                              scene->fb.cbufs[i]->format,
-                              scene->cbufs[i].stride,
-                              task->x,
-                              task->y,
-                              task->width,
-                              task->height,
-                              &uc);
-               map_layer += scene->cbufs[i].layer_stride;
-            }
+            util_fill_box(scene->cbufs[i].map,
+                          format,
+                          scene->cbufs[i].stride,
+                          scene->cbufs[i].layer_stride,
+                          task->x,
+                          task->y,
+                          0,
+                          task->width,
+                          task->height,
+                          scene->fb_max_layer + 1,
+                          &uc);
          }
       }
       else {
@@ -173,22 +171,20 @@ lp_rast_clear_color(struct lp_rasterizer_task *task,
                     clear_color[3]);
 
          for (i = 0; i < scene->fb.nr_cbufs; i++) {
-            unsigned layer;
-            uint8_t *map_layer = scene->cbufs[i].map;
-
-            for (layer = 0; layer <= scene->fb_max_layer; layer++) {
-               util_pack_color(arg.clear_color.f,
-                               scene->fb.cbufs[i]->format, &uc);
-               util_fill_rect(map_layer,
-                              scene->fb.cbufs[i]->format,
-                              scene->cbufs[i].stride,
-                              task->x,
-                              task->y,
-                              task->width,
-                              task->height,
-                              &uc);
-               map_layer += scene->cbufs[i].layer_stride;
-            }
+            util_pack_color(arg.clear_color.f,
+                            scene->fb.cbufs[i]->format, &uc);
+
+            util_fill_box(scene->cbufs[i].map,
+                          scene->fb.cbufs[i]->format,
+                          scene->cbufs[i].stride,
+                          scene->cbufs[i].layer_stride,
+                          task->x,
+                          task->y,
+                          0,
+                          task->width,
+                          task->height,
+                          scene->fb_max_layer + 1,
+                          &uc);
          }
       }
    }