llvmpipe: clean up deferred zstencil clears
authorKeith Whitwell <keithw@vmware.com>
Fri, 27 Aug 2010 16:30:07 +0000 (17:30 +0100)
committerKeith Whitwell <keithw@vmware.com>
Tue, 7 Sep 2010 12:22:55 +0000 (13:22 +0100)
src/gallium/drivers/llvmpipe/lp_rast.c
src/gallium/drivers/llvmpipe/lp_rast.h
src/gallium/drivers/llvmpipe/lp_scene.c
src/gallium/drivers/llvmpipe/lp_scene.h
src/gallium/drivers/llvmpipe/lp_setup.c
src/gallium/drivers/llvmpipe/lp_setup_context.h

index ce6896d16e4dd4ff288ca8f62a58b227ae4f60b0..d8dc24e4519162115f37a782bc49cb56d0dd009d 100644 (file)
@@ -255,9 +255,8 @@ lp_rast_clear_zstencil(struct lp_rasterizer_task *task,
                        const union lp_rast_cmd_arg arg)
 {
    struct lp_rasterizer *rast = task->rast;
-   const struct lp_rast_clearzs *clearzs = arg.clear_zstencil;
-   unsigned clear_value = clearzs->clearzs_value;
-   unsigned clear_mask = clearzs->clearzs_mask;
+   unsigned clear_value = arg.clear_zstencil.value;
+   unsigned clear_mask = arg.clear_zstencil.mask;
    const unsigned height = TILE_SIZE / TILE_VECTOR_HEIGHT;
    const unsigned width = TILE_SIZE * TILE_VECTOR_HEIGHT;
    const unsigned block_size = rast->zsbuf.blocksize;
index 9d3deb4e8862d325e4cf7be2b2757b72c8f3ff13..d6e53f31aa1e8c3cf0752bab9028004d0417ce8a 100644 (file)
@@ -88,10 +88,6 @@ struct lp_rast_shader_inputs {
    const struct lp_rast_state *state;
 };
 
-struct lp_rast_clearzs {
-   unsigned clearzs_value;
-   unsigned clearzs_mask;
-};
 
 struct lp_rast_plane {
    /* one-pixel sized trivial accept offsets for each plane */
@@ -151,7 +147,10 @@ union lp_rast_cmd_arg {
    } triangle;
    const struct lp_rast_state *set_state;
    uint8_t clear_color[4];
-   const struct lp_rast_clearzs *clear_zstencil;
+   struct {
+      unsigned value;
+      unsigned mask;
+   } clear_zstencil;
    struct lp_fence *fence;
    struct llvmpipe_query *query_obj;
 };
@@ -195,13 +194,15 @@ lp_rast_arg_fence( struct lp_fence *fence )
 
 
 static INLINE union lp_rast_cmd_arg
-lp_rast_arg_clearzs( const struct lp_rast_clearzs *clearzs )
+lp_rast_arg_clearzs( unsigned value, unsigned mask )
 {
    union lp_rast_cmd_arg arg;
-   arg.clear_zstencil = clearzs;
+   arg.clear_zstencil.value = value;
+   arg.clear_zstencil.mask = mask;
    return arg;
 }
 
+
 static INLINE union lp_rast_cmd_arg
 lp_rast_arg_null( void )
 {
index 15a09b71006e923972ae3e37f5659988e852f405..51389c23120ade21c4c7135aa437a242415d8f99 100644 (file)
@@ -206,7 +206,6 @@ lp_scene_reset(struct lp_scene *scene )
 
    scene->scene_size = 0;
 
-   scene->has_color_clear = FALSE;
    scene->has_depthstencil_clear = FALSE;
 }
 
index fa1b311fa1762d40badcbda4f8a5d602940d50aa..e933a84b902b6d8d2f610b0a8751f56c8fe88236 100644 (file)
@@ -125,7 +125,6 @@ struct lp_scene {
     */
    unsigned scene_size;
 
-   boolean has_color_clear;
    boolean has_depthstencil_clear;
 
    /**
index ae6d67850253fa94ddab24ef555adb89c501d100..3bef620961933ddd02120eaf1447d7a73e30e69e 100644 (file)
@@ -135,8 +135,7 @@ static void reset_context( struct lp_setup_context *setup )
 
    /* Reset some state:
     */
-   setup->clear.flags = 0;
-   setup->clear.clearzs.clearzs_mask = 0;
+   memset(&setup->clear, 0, sizeof setup->clear);
 
    /* Have an explicit "start-binning" call and get rid of this
     * pointer twiddling?
@@ -195,7 +194,6 @@ begin_binning( struct lp_setup_context *setup )
          lp_scene_bin_everywhere( scene, 
                                  lp_rast_clear_color, 
                                  setup->clear.color );
-         scene->has_color_clear = TRUE;
       }
    }
 
@@ -205,7 +203,9 @@ begin_binning( struct lp_setup_context *setup )
             scene->has_depthstencil_clear = TRUE;
          lp_scene_bin_everywhere( scene,
                                   lp_rast_clear_zstencil,
-                                  lp_rast_arg_clearzs(&setup->clear.clearzs) );
+                                  lp_rast_arg_clearzs(
+                                     setup->clear.zsmask,
+                                     setup->clear.zsvalue));
       }
    }
 
@@ -341,67 +341,26 @@ lp_setup_clear( struct lp_setup_context *setup,
                 unsigned flags )
 {
    struct lp_scene *scene = lp_setup_get_current_scene(setup);
+   uint32_t zsmask = 0;
+   uint32_t zsvalue = 0;
+   uint8_t clear_color[4];
    unsigned i;
-   boolean full_zs_clear = TRUE;
-   uint32_t mask = 0;
 
    LP_DBG(DEBUG_SETUP, "%s state %d\n", __FUNCTION__, setup->state);
 
-
    if (flags & PIPE_CLEAR_COLOR) {
-      for (i = 0; i < 4; ++i)
-         setup->clear.color.clear_color[i] = float_to_ubyte(color[i]);
+      for (i = 0; i < 4; i++)
+         clear_color[i] = float_to_ubyte(color[i]);
    }
 
    if (flags & PIPE_CLEAR_DEPTHSTENCIL) {
-      if (setup->fb.zsbuf &&
-          ((flags & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) &&
-           util_format_is_depth_and_stencil(setup->fb.zsbuf->format))
-         full_zs_clear = FALSE;
-
-      if (full_zs_clear) {
-         setup->clear.clearzs.clearzs_value =
-            util_pack_z_stencil(setup->fb.zsbuf->format,
-                                depth,
-                                stencil);
-         setup->clear.clearzs.clearzs_mask = 0xffffffff;
-      }
-      else {
-         /* hmm */
-         uint32_t tmpval;
-         if (flags & PIPE_CLEAR_DEPTH) {
-            tmpval = util_pack_z(setup->fb.zsbuf->format,
-                                 depth);
-            switch (setup->fb.zsbuf->format) {
-            case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
-               mask = 0xffffff;
-               break;
-            case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
-               mask = 0xffffff00;
-               break;
-            default:
-               assert(0);
-            }
-         }
-         else {
-            switch (setup->fb.zsbuf->format) {
-            case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
-               mask = 0xff000000;
-               tmpval = stencil << 24;
-               break;
-            case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
-               mask = 0xff;
-               tmpval = stencil;
-               break;
-            default:
-               assert(0);
-               tmpval = 0;
-            }
-         }
-         setup->clear.clearzs.clearzs_mask |= mask;
-         setup->clear.clearzs.clearzs_value =
-            (setup->clear.clearzs.clearzs_value & ~mask) | (tmpval & mask);
-      }
+      zsvalue = util_pack_z_stencil(setup->fb.zsbuf->format,
+                                    depth,
+                                    stencil);
+
+      zsmask = util_pack_uint_z_stencil(setup->fb.zsbuf->format,
+                                        0xffffffff,
+                                        0xff);
    }
 
    if (setup->state == SETUP_ACTIVE) {
@@ -415,21 +374,13 @@ lp_setup_clear( struct lp_setup_context *setup,
          lp_scene_bin_everywhere( scene, 
                                   lp_rast_clear_color,
                                   setup->clear.color );
-         scene->has_color_clear = TRUE;
       }
 
       if (flags & PIPE_CLEAR_DEPTHSTENCIL) {
-         if (full_zs_clear)
-            scene->has_depthstencil_clear = TRUE;
-         else
-            setup->clear.clearzs.clearzs_mask = mask;
          lp_scene_bin_everywhere( scene,
                                   lp_rast_clear_zstencil,
-                                  lp_rast_arg_clearzs(&setup->clear.clearzs) );
-
-
+                                  lp_rast_arg_clearzs(zsmask, zsvalue) );
       }
-
    }
    else {
       /* Put ourselves into the 'pre-clear' state, specifically to try
@@ -440,6 +391,18 @@ lp_setup_clear( struct lp_setup_context *setup,
       set_scene_state( setup, SETUP_CLEARED );
 
       setup->clear.flags |= flags;
+
+      if (flags & PIPE_CLEAR_DEPTHSTENCIL) {
+         setup->clear.zsmask |= zsmask;
+         setup->clear.zsvalue =
+            (setup->clear.zsvalue & ~zsmask) | (zsvalue & zsmask);
+      }
+
+      if (flags & PIPE_CLEAR_COLOR) {
+         memcpy(setup->clear.color.clear_color,
+                clear_color,
+                sizeof clear_color);
+      }
    }
 }
 
index 91b5d4d79f09c14c30761792f83b98be1285e63e..fa4e5e911807d51ea12d3ab1244e983be4623bfb 100644 (file)
@@ -108,7 +108,8 @@ struct lp_setup_context
    struct {
       unsigned flags;
       union lp_rast_cmd_arg color;    /**< lp_rast_clear_color() cmd */
-      struct lp_rast_clearzs clearzs; /**< lp_rast_clear_zstencil() cmd */
+      unsigned zsmask;
+      unsigned zsvalue;               /**< lp_rast_clear_zstencil() cmd */
    } clear;
 
    enum setup_state {