Make the alpha test state a cso.
authorZack Rusin <zack@tungstengraphics.com>
Fri, 21 Sep 2007 11:00:20 +0000 (07:00 -0400)
committerZack Rusin <zack@tungstengraphics.com>
Fri, 21 Sep 2007 11:00:20 +0000 (07:00 -0400)
23 files changed:
src/mesa/pipe/cso_cache/cso_cache.c
src/mesa/pipe/cso_cache/cso_cache.h
src/mesa/pipe/failover/fo_context.h
src/mesa/pipe/failover/fo_state.c
src/mesa/pipe/failover/fo_state_emit.c
src/mesa/pipe/i915simple/i915_context.h
src/mesa/pipe/i915simple/i915_state.c
src/mesa/pipe/i915simple/i915_state_immediate.c
src/mesa/pipe/p_context.h
src/mesa/pipe/softpipe/sp_context.c
src/mesa/pipe/softpipe/sp_context.h
src/mesa/pipe/softpipe/sp_quad.c
src/mesa/pipe/softpipe/sp_quad_alpha_test.c
src/mesa/pipe/softpipe/sp_state.h
src/mesa/pipe/softpipe/sp_state_blend.c
src/mesa/state_tracker/st_atom.c
src/mesa/state_tracker/st_atom.h
src/mesa/state_tracker/st_atom_alphatest.c
src/mesa/state_tracker/st_cache.c
src/mesa/state_tracker/st_cache.h
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_context.h

index 71f0d0872611a7402c7e114c9dd11371c04f10ad..0bba5914dc8ad85d1e03fecde23247db80da9d55 100644 (file)
@@ -90,6 +90,9 @@ static struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_
    case CSO_VERTEX_SHADER:
       hash = sc->vs_hash;
       break;
+   case CSO_ALPHA_TEST:
+      hash = sc->alpha_hash;
+      break;
    }
 
    return hash;
@@ -110,6 +113,8 @@ static int _cso_size_for_type(enum cso_cache_type type)
       return sizeof(struct pipe_shader_state);
    case CSO_VERTEX_SHADER:
       return sizeof(struct pipe_shader_state);
+   case CSO_ALPHA_TEST:
+      return sizeof(struct pipe_alpha_test_state);
    }
    return 0;
 }
@@ -164,6 +169,7 @@ struct cso_cache *cso_cache_create(void)
    sc->rasterizer_hash    = cso_hash_create();
    sc->fs_hash            = cso_hash_create();
    sc->vs_hash            = cso_hash_create();
+   sc->alpha_hash         = cso_hash_create();
 
    return sc;
 }
@@ -177,5 +183,6 @@ void cso_cache_delete(struct cso_cache *sc)
    cso_hash_delete(sc->rasterizer_hash);
    cso_hash_delete(sc->fs_hash);
    cso_hash_delete(sc->vs_hash);
+   cso_hash_delete(sc->alpha_hash);
    free(sc);
 }
index 2acb58c66b66073720b7b9bc7e30448cca752c35..cd36dd51e985f38b6ee7959d8ca3f8915e755918 100644 (file)
 struct cso_hash;
 
 struct cso_cache {
+   struct cso_hash *alpha_hash;
    struct cso_hash *blend_hash;
-   struct cso_hash *sampler_hash;
    struct cso_hash *depth_stencil_hash;
-   struct cso_hash *rasterizer_hash;
    struct cso_hash *fs_hash;
    struct cso_hash *vs_hash;
+   struct cso_hash *rasterizer_hash;
+   struct cso_hash *sampler_hash;
 };
 
 struct cso_blend {
@@ -78,13 +79,19 @@ struct cso_sampler {
    void *data;
 };
 
+struct cso_alpha_test {
+   struct pipe_alpha_test_state state;
+   void *data;
+};
+
 enum cso_cache_type {
    CSO_BLEND,
    CSO_SAMPLER,
    CSO_DEPTH_STENCIL,
    CSO_RASTERIZER,
    CSO_FRAGMENT_SHADER,
-   CSO_VERTEX_SHADER
+   CSO_VERTEX_SHADER,
+   CSO_ALPHA_TEST
 };
 
 unsigned cso_construct_key(void *item, int item_size);
index 8a2fbe2be9b1e86c723029252e158572ee095b92..7a597013ab2f98f5b0be5ed2d964e6b13526eeb4 100644 (file)
@@ -64,12 +64,13 @@ struct fo_state {
    void *sw_state;
    void *hw_state;
 };
-struct failover_context {     
+struct failover_context {
    struct pipe_context pipe;  /**< base class */
 
 
    /* The most recent drawing state as set by the driver:
     */
+   const struct fo_state     *alpha_test;
    const struct fo_state     *blend;
    const struct fo_state     *sampler[PIPE_MAX_SAMPLERS];
    const struct fo_state     *depth_stencil;
@@ -77,7 +78,6 @@ struct failover_context {
    const struct fo_state     *fragment_shader;
    const struct fo_state     *vertex_shader;
 
-   struct pipe_alpha_test_state alpha_test;
    struct pipe_blend_color blend_color;
    struct pipe_clear_color_state clear_color;
    struct pipe_clip_state clip;
index ce3f0ca63582612240aaa626c5bfa9f423b12a07..f63137f5913256945a74f70bd1d08a10fddac193 100644 (file)
  * lower overheads.
  */
 
+static void *
+failover_create_alpha_test_state(struct pipe_context *pipe,
+                                 const struct pipe_alpha_test_state *templ)
+{
+   struct fo_state *state = malloc(sizeof(struct fo_state));
+   struct failover_context *failover = failover_context(pipe);
+
+   state->sw_state = failover->sw->create_alpha_test_state(pipe, templ);
+   state->hw_state = failover->hw->create_alpha_test_state(pipe, templ);
+
+   return state;
+}
+
 static void
-failover_set_alpha_test_state(struct pipe_context *pipe,
-                              const struct pipe_alpha_test_state *alpha)
+failover_bind_alpha_test_state(struct pipe_context *pipe,
+                               void *alpha)
 {
    struct failover_context *failover = failover_context(pipe);
+   struct fo_state *state = (struct fo_state *)alpha;
 
-   failover->alpha_test = *alpha;
+   failover->alpha_test = state;
    failover->dirty |= FO_NEW_ALPHA_TEST;
-   failover->hw->set_alpha_test_state( failover->hw, alpha );
+   failover->hw->bind_alpha_test_state(failover->hw,
+                                       state->hw_state);
+}
+
+static void
+failover_delete_alpha_test_state(struct pipe_context *pipe,
+                                 void *alpha)
+{
+   struct fo_state *state = (struct fo_state*)alpha;
+   struct failover_context *failover = failover_context(pipe);
+
+   failover->sw->delete_alpha_test_state(pipe, state->sw_state);
+   failover->hw->delete_alpha_test_state(pipe, state->hw_state);
+   state->sw_state = 0;
+   state->hw_state = 0;
+   free(state);
 }
 
 
@@ -95,7 +124,7 @@ failover_delete_blend_state( struct pipe_context *pipe,
    free(state);
 }
 
-static void 
+static void
 failover_set_blend_color( struct pipe_context *pipe,
                          const struct pipe_blend_color *blend_color )
 {
@@ -414,8 +443,11 @@ failover_set_vertex_element(struct pipe_context *pipe,
 void
 failover_init_state_functions( struct failover_context *failover )
 {
+   failover->pipe.create_alpha_test_state = failover_create_alpha_test_state;
+   failover->pipe.bind_alpha_test_state   = failover_bind_alpha_test_state;
+   failover->pipe.delete_alpha_test_state = failover_delete_alpha_test_state;
    failover->pipe.create_blend_state = failover_create_blend_state;
-   failover->pipe.bind_blend_state = failover_bind_blend_state;
+   failover->pipe.bind_blend_state   = failover_bind_blend_state;
    failover->pipe.delete_blend_state = failover_delete_blend_state;
    failover->pipe.create_sampler_state = failover_create_sampler_state;
    failover->pipe.bind_sampler_state   = failover_bind_sampler_state;
@@ -433,7 +465,6 @@ failover_init_state_functions( struct failover_context *failover )
    failover->pipe.bind_vs_state   = failover_bind_vs_state;
    failover->pipe.delete_vs_state = failover_delete_vs_state;
 
-   failover->pipe.set_alpha_test_state = failover_set_alpha_test_state;
    failover->pipe.set_blend_color = failover_set_blend_color;
    failover->pipe.set_clip_state = failover_set_clip_state;
    failover->pipe.set_clear_color_state = failover_set_clear_color_state;
index c0ea6810246fee1f7a6a25ea3c19ab2b898c251d..a3aff8abd2a47dc90d80fd317b4374ffa2622a82 100644 (file)
@@ -56,7 +56,8 @@ failover_state_emit( struct failover_context *failover )
    unsigned i;
 
    if (failover->dirty & FO_NEW_ALPHA_TEST)
-      failover->sw->set_alpha_test_state( failover->sw, &failover->alpha_test );
+      failover->sw->bind_alpha_test_state( failover->sw,
+                                           failover->alpha_test->sw_state );
 
    if (failover->dirty & FO_NEW_BLEND)
       failover->sw->bind_blend_state( failover->sw,
index f1e10f34332664aaaadadf583938927c9884121a..9958a8592dcf4b3b8daec7f8c46827acc8d53ac2 100644 (file)
@@ -154,13 +154,13 @@ struct i915_context
 
    /* The most recent drawing state as set by the driver:
     */
+   const struct pipe_alpha_test_state      *alpha_test;
    const struct i915_blend_state           *blend;
    const struct i915_sampler_state         *sampler[PIPE_MAX_SAMPLERS];
    const struct i915_depth_stencil_state   *depth_stencil;
    const struct i915_rasterizer_state      *rasterizer;
    const struct pipe_shader_state *fs;
 
-   struct pipe_alpha_test_state alpha_test;
    struct pipe_blend_color blend_color;
    struct pipe_clear_color_state clear_color;
    struct pipe_clip_state clip;
index 525f8ce13a26659b087e9da5a40804e59715ba2d..8bfd2da3b5c91803edde12231c800a7ec4951d94 100644 (file)
@@ -394,16 +394,29 @@ static void i915_delete_depth_stencil_state(struct pipe_context *pipe,
    free(depth_stencil);
 }
 
-static void i915_set_alpha_test_state(struct pipe_context *pipe,
-                              const struct pipe_alpha_test_state *alpha)
+
+static void *
+i915_create_alpha_test_state(struct pipe_context *pipe,
+                             const struct pipe_alpha_test_state *alpha)
+{
+   return 0;
+}
+
+static void i915_bind_alpha_test_state(struct pipe_context *pipe,
+                                       void *alpha)
 {
    struct i915_context *i915 = i915_context(pipe);
 
-   i915->alpha_test = *alpha;
+   i915->alpha_test = (const struct pipe_alpha_test_state*)alpha;
 
    i915->dirty |= I915_NEW_ALPHA_TEST;
 }
 
+static void i915_delete_alpha_test_state(struct pipe_context *pipe,
+                                         void *alpha)
+{
+}
+
 static void i915_set_scissor_state( struct pipe_context *pipe,
                                  const struct pipe_scissor_state *scissor )
 {
@@ -664,6 +677,10 @@ static void i915_set_vertex_element( struct pipe_context *pipe,
 void
 i915_init_state_functions( struct i915_context *i915 )
 {
+   i915->pipe.create_alpha_test_state = i915_create_alpha_test_state;
+   i915->pipe.bind_alpha_test_state   = i915_bind_alpha_test_state;
+   i915->pipe.delete_alpha_test_state = i915_delete_alpha_test_state;
+
    i915->pipe.create_blend_state = i915_create_blend_state;
    i915->pipe.bind_blend_state = i915_bind_blend_state;
    i915->pipe.delete_blend_state = i915_delete_blend_state;
@@ -686,7 +703,6 @@ i915_init_state_functions( struct i915_context *i915 )
    i915->pipe.bind_vs_state = i915_bind_vs_state;
    i915->pipe.delete_vs_state = i915_delete_shader_state;
 
-   i915->pipe.set_alpha_test_state = i915_set_alpha_test_state;
    i915->pipe.set_blend_color = i915_set_blend_color;
    i915->pipe.set_clip_state = i915_set_clip_state;
    i915->pipe.set_clear_color_state = i915_set_clear_color_state;
index 874c3819f25c0042f37bd151b3ea7f5a9431eb3f..014fddfdda519b77692bb57ae7aa3ab2d2d6dd90 100644 (file)
@@ -121,9 +121,9 @@ static void upload_S6( struct i915_context *i915 )
 
    /* I915_NEW_ALPHA_TEST
     */
-   if (i915->alpha_test.enabled) {
-      int test = i915_translate_compare_func(i915->alpha_test.func);
-      ubyte refByte = float_to_ubyte(i915->alpha_test.ref);
+   if (i915->alpha_test->enabled) {
+      int test = i915_translate_compare_func(i915->alpha_test->func);
+      ubyte refByte = float_to_ubyte(i915->alpha_test->ref);
       
 
       LIS6 |= (S6_ALPHA_TEST_ENABLE |
index 07ee01988077eeceb228f98c2347113de4605a06..8ba1031efe51e9d4c6860e18d7bc46019bd1f1b1 100644 (file)
@@ -86,26 +86,30 @@ struct pipe_context {
    /*
     * State functions
     */
+   void * (*create_alpha_test_state)(struct pipe_context *,
+                                     const struct pipe_alpha_test_state *);
+   void   (*bind_alpha_test_state)(struct pipe_context *, void *);
+   void   (*delete_alpha_test_state)(struct pipe_context *, void *);
+
    void * (*create_blend_state)(struct pipe_context *,
                                 const struct pipe_blend_state *);
-   void (*bind_blend_state)(struct pipe_context *, void *);
-   void (*delete_blend_state)(struct pipe_context *, void  *);
+   void   (*bind_blend_state)(struct pipe_context *, void *);
+   void   (*delete_blend_state)(struct pipe_context *, void  *);
 
    void * (*create_sampler_state)(struct pipe_context *,
                                   const struct pipe_sampler_state *);
-   void (*bind_sampler_state)(struct pipe_context *, unsigned unit,
-                              void *);
-   void (*delete_sampler_state)(struct pipe_context *, void *);
+   void   (*bind_sampler_state)(struct pipe_context *, unsigned unit, void *);
+   void   (*delete_sampler_state)(struct pipe_context *, void *);
 
-   void *(*create_rasterizer_state)(struct pipe_context *,
-                                    const struct pipe_rasterizer_state *);
-   void (*bind_rasterizer_state)(struct pipe_context *, void *);
-   void (*delete_rasterizer_state)(struct pipe_context *, void *);
+   void * (*create_rasterizer_state)(struct pipe_context *,
+                                     const struct pipe_rasterizer_state *);
+   void   (*bind_rasterizer_state)(struct pipe_context *, void *);
+   void   (*delete_rasterizer_state)(struct pipe_context *, void *);
 
    void * (*create_depth_stencil_state)(struct pipe_context *,
                                         const struct pipe_depth_stencil_state *);
-   void (*bind_depth_stencil_state)(struct pipe_context *, void *);
-   void (*delete_depth_stencil_state)(struct pipe_context *, void *);
+   void   (*bind_depth_stencil_state)(struct pipe_context *, void *);
+   void   (*delete_depth_stencil_state)(struct pipe_context *, void *);
 
    void * (*create_fs_state)(struct pipe_context *,
                              const struct pipe_shader_state *);
@@ -117,9 +121,9 @@ struct pipe_context {
    void   (*bind_vs_state)(struct pipe_context *, void *);
    void   (*delete_vs_state)(struct pipe_context *, void *);
 
-   void (*set_alpha_test_state)( struct pipe_context *,
-                                 const struct pipe_alpha_test_state * );
-
+   /* The following look more properties than states.
+    * maybe combine a few of them into states or pass them
+    * in the bind calls to the state */
    void (*set_blend_color)( struct pipe_context *,
                             const struct pipe_blend_color * );
 
index cac44606f74a91568f8a411eec50d6a32c8bcc6f..a6ab45314cfd3e5a32501e7e6f0c1f2cd708d116 100644 (file)
@@ -260,6 +260,9 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
    softpipe->pipe.get_param = softpipe_get_param;
 
    /* state setters */
+   softpipe->pipe.create_alpha_test_state = softpipe_create_alpha_test_state;
+   softpipe->pipe.bind_alpha_test_state   = softpipe_bind_alpha_test_state;
+   softpipe->pipe.delete_alpha_test_state = softpipe_delete_alpha_test_state;
    softpipe->pipe.create_blend_state = softpipe_create_blend_state;
    softpipe->pipe.bind_blend_state   = softpipe_bind_blend_state;
    softpipe->pipe.delete_blend_state = softpipe_delete_blend_state;
@@ -279,7 +282,6 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
    softpipe->pipe.bind_vs_state   = softpipe_bind_vs_state;
    softpipe->pipe.delete_vs_state = softpipe_delete_shader_state;
 
-   softpipe->pipe.set_alpha_test_state = softpipe_set_alpha_test_state;
    softpipe->pipe.set_blend_color = softpipe_set_blend_color;
    softpipe->pipe.set_clip_state = softpipe_set_clip_state;
    softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state;
index 95215eb6408ea495a51c263222e06abe822cef43..7b1518cfaca9f4f57520b1515ac90e10615a8b7a 100644 (file)
@@ -70,6 +70,7 @@ struct softpipe_context {
 
    /* The most recent drawing state as set by the driver:
     */
+   const struct pipe_alpha_test_state *alpha_test;
    const struct pipe_blend_state   *blend;
    const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
    const struct pipe_depth_stencil_state   *depth_stencil;
@@ -77,7 +78,6 @@ struct softpipe_context {
    const struct pipe_shader_state *fs;
    const struct pipe_shader_state *vs;
 
-   struct pipe_alpha_test_state alpha_test;
    struct pipe_blend_color blend_color;
    struct pipe_clear_color_state clear_color;
    struct pipe_clip_state clip;
index fc4f8328cf8637faf93077cfb6628e498c0a14ba..74a21dc54b42964f15c7117b0b21080d4d838178 100644 (file)
@@ -54,7 +54,7 @@ sp_build_quad_pipeline(struct softpipe_context *sp)
       sp->quad.first = sp->quad.depth_test;
    }
 
-   if (sp->alpha_test.enabled) {
+   if (sp->alpha_test->enabled) {
       sp->quad.alpha_test->next = sp->quad.first;
       sp->quad.first = sp->quad.alpha_test;
    }
index 64c1624bd0e7bad694d6f96e06c5bd9412401cdf..4f28414b0e0a90718d4766522f9a175bfc54006b 100644 (file)
@@ -14,10 +14,10 @@ static void
 alpha_test_quad(struct quad_stage *qs, struct quad_header *quad)
 {
    struct softpipe_context *softpipe = qs->softpipe;
-   const float ref = softpipe->alpha_test.ref;
+   const float ref = softpipe->alpha_test->ref;
    unsigned passMask = 0x0, j;
 
-   switch (softpipe->alpha_test.func) {
+   switch (softpipe->alpha_test->func) {
    case PIPE_FUNC_NEVER:
       quad->mask = 0x0;
       break;
index 62323c41c3b7dc3b92ed74036ee63c480b37a143..f0e1461d2582d2204850ee3854cb3c102883f0dc 100644 (file)
 
 #include "pipe/p_state.h"
 
+
+void *
+softpipe_create_alpha_test_state(struct pipe_context *,
+                                 const struct pipe_alpha_test_state *);
+void
+softpipe_bind_alpha_test_state(struct pipe_context *, void *);
+void
+softpipe_delete_alpha_test_state(struct pipe_context *, void *);
+
 void *
 softpipe_create_blend_state(struct pipe_context *,
                             const struct pipe_blend_state *);
@@ -62,9 +71,6 @@ void softpipe_delete_rasterizer_state(struct pipe_context *, void *);
 void softpipe_set_framebuffer_state( struct pipe_context *,
                             const struct pipe_framebuffer_state * );
 
-void softpipe_set_alpha_test_state( struct pipe_context *,
-                                    const struct pipe_alpha_test_state * );
-
 void softpipe_set_blend_color( struct pipe_context *pipe,
                                const struct pipe_blend_color *blend_color );
 
index cf476079557a43810beac388a8d6f877fbc5440e..cb0921f687b35dd3eb2b7dcd14714a71422ab768 100644 (file)
@@ -71,17 +71,31 @@ void softpipe_set_blend_color( struct pipe_context *pipe,
  * into one file.
  */
 
+void *
+softpipe_create_alpha_test_state(struct pipe_context *pipe,
+                                 const struct pipe_alpha_test_state *alpha)
+{
+   return 0;
+}
+
 void
-softpipe_set_alpha_test_state(struct pipe_context *pipe,
-                              const struct pipe_alpha_test_state *alpha)
+softpipe_bind_alpha_test_state(struct pipe_context *pipe,
+                               void *alpha)
 {
    struct softpipe_context *softpipe = softpipe_context(pipe);
 
-   softpipe->alpha_test = *alpha;
+   softpipe->alpha_test = (const struct pipe_alpha_test_state *)alpha;
 
    softpipe->dirty |= SP_NEW_ALPHA_TEST;
 }
 
+void
+softpipe_delete_alpha_test_state(struct pipe_context *pipe,
+                                 void *alpha)
+{
+   /* do nothing */
+}
+
 void *
 softpipe_create_depth_stencil_state(struct pipe_context *pipe,
                               const struct pipe_depth_stencil_state *depth_stencil)
index a4af3aeb2057d945f7704186246a53743b535d1e..fc339b91ed7c41c67fad3a4254b68013c892a369 100644 (file)
@@ -62,6 +62,7 @@ static const struct st_tracked_state *atoms[] =
    &st_update_texture,
    &st_update_vs_constants,
    &st_update_fs_constants,
+   &st_update_alpha_test
 };
 
 
index 26f6514698c337a2241e45f650c71b116ca7ca1e..6710c1a26956eafcf70468c7ac7c7be070960755 100644 (file)
@@ -60,6 +60,7 @@ const struct st_tracked_state st_update_sampler;
 const struct st_tracked_state st_update_texture;
 const struct st_tracked_state st_update_fs_constants;
 const struct st_tracked_state st_update_vs_constants;
+const struct st_tracked_state st_update_alpha_test;
 
 
 #endif
index 4378154053d78f346f3f7012c70b22eb1bfda003..873520ab02553d69c38afc72c9d7a51fe3161f9c 100644 (file)
@@ -33,6 +33,7 @@
  
 
 #include "st_context.h"
+#include "st_cache.h"
 #include "st_atom.h"
 #include "pipe/p_context.h"
 #include "pipe/p_defines.h"
@@ -63,6 +64,7 @@ static void
 update_alpha_test( struct st_context *st )
 {
    struct pipe_alpha_test_state alpha;
+   const struct cso_alpha_test *cso;
 
    memset(&alpha, 0, sizeof(alpha));
 
@@ -71,11 +73,11 @@ update_alpha_test( struct st_context *st )
       alpha.func = gl_alpha_func_to_sp(st->ctx->Color.AlphaFunc);
       alpha.ref = st->ctx->Color.AlphaRef;
    }
-
-   if (memcmp(&alpha, &st->state.alpha_test, sizeof(alpha)) != 0) {
+   cso = st_cached_alpha_test_state(st, &alpha);
+   if (st->state.alpha_test != cso) {
       /* state has changed */
-      st->state.alpha_test = alpha;  /* struct copy */
-      st->pipe->set_alpha_test_state(st->pipe, &alpha); /* set new state */
+      st->state.alpha_test = cso;
+      st->pipe->bind_alpha_test_state(st->pipe, cso->data); /* bind new state */
    }
 }
 
@@ -88,8 +90,3 @@ const struct st_tracked_state st_update_alpha_test = {
    },
    .update = update_alpha_test
 };
-
-
-
-
-
index 01d1934232b11f120f6431aeb57f73ad3241ccb1..1686721990acd3c51d421a1b0fce23bb73175657 100644 (file)
@@ -159,3 +159,23 @@ st_cached_vs_state(struct st_context *st,
    }
    return (struct cso_vertex_shader*)(cso_hash_iter_data(iter));
 }
+
+const struct cso_alpha_test *
+st_cached_alpha_test_state(struct st_context *st,
+                           const struct pipe_alpha_test_state *templ)
+{
+   unsigned hash_key = cso_construct_key((void*)templ,
+                                         sizeof(struct pipe_alpha_test_state));
+   struct cso_hash_iter iter = cso_find_state_template(st->cache,
+                                                       hash_key, CSO_ALPHA_TEST,
+                                                       (void*)templ);
+   if (cso_hash_iter_is_null(iter)) {
+      struct cso_alpha_test *cso = malloc(sizeof(struct cso_alpha_test));
+      memcpy(&cso->state, templ, sizeof(struct pipe_alpha_test_state));
+      cso->data = st->pipe->create_alpha_test_state(st->pipe, &cso->state);
+      if (!cso->data)
+         cso->data = &cso->state;
+      iter = cso_insert_state(st->cache, hash_key, CSO_ALPHA_TEST, cso);
+   }
+   return ((struct cso_alpha_test *)cso_hash_iter_data(iter));
+}
index 483af6fdb43fdeaf3cc7cfce414038cf2f7a8cb6..422f668c56195a0b65774e5af7683209c7fbfe38 100644 (file)
@@ -39,6 +39,10 @@ struct pipe_blend_state;
 struct pipe_sampler_state;
 struct st_context;
 
+const struct cso_alpha_test *
+st_cached_alpha_test_state(struct st_context *st,
+                           const struct pipe_alpha_test_state *alpha);
+
 const struct cso_blend *
 st_cached_blend_state(struct st_context *st,
                       const struct pipe_blend_state *blend);
index 5e632050885a8c18fb22e60a4c76cbc3a3eda90c..c53446d588dd71e327b8b8de897f48a5cf575851 100644 (file)
@@ -275,8 +275,10 @@ clear_with_quad(GLcontext *ctx,
    /* alpha state: disabled */
    {
       struct pipe_alpha_test_state alpha_test;
+      const struct cso_alpha_test *cso;
       memset(&alpha_test, 0, sizeof(alpha_test));
-      pipe->set_alpha_test_state(pipe, &alpha_test);
+      cso = st_cached_alpha_test_state(st, &alpha_test);
+      pipe->bind_alpha_test_state(pipe, cso->data);
    }
 
    /* blend state: RGBA masking */
@@ -379,7 +381,7 @@ clear_with_quad(GLcontext *ctx,
    draw_quad(ctx, x0, y0, x1, y1, ctx->Depth.Clear, ctx->Color.ClearColor);
 
    /* Restore pipe state */
-   pipe->set_alpha_test_state(pipe, &st->state.alpha_test);
+   pipe->bind_alpha_test_state(pipe, st->state.alpha_test->data);
    pipe->bind_blend_state(pipe, st->state.blend->data);
    pipe->bind_depth_stencil_state(pipe, st->state.depth_stencil->data);
    pipe->bind_fs_state(pipe, st->state.fs->data);
index d814e34157552971a83fa460721e86420fbba7fa..65c5465546405f4945315a7fd7a6c561aff87ba8 100644 (file)
@@ -468,7 +468,7 @@ compatible_formats(GLenum format, GLenum type, GLuint pipeFormat)
 static GLboolean
 any_fragment_ops(const struct st_context *st)
 {
-   if (st->state.alpha_test.enabled ||
+   if (st->state.alpha_test->state.enabled ||
        st->state.blend->state.blend_enable ||
        st->state.blend->state.logicop_enable ||
        st->state.depth_stencil->state.depth.enabled)
index 55a857f46d4270a03d70855dc2e3c43aa15b3bda..3713328eb14dd3c2bffde3f5d63992b50013cc66 100644 (file)
@@ -75,14 +75,14 @@ struct st_context
     * though, we just shove random objects across the interface.  
     */
    struct {
-      const struct cso_blend *blend;
-      const struct cso_sampler *sampler[PIPE_MAX_SAMPLERS];
-      const struct cso_depth_stencil *depth_stencil;
-      const struct cso_rasterizer  *rasterizer;
+      const struct cso_alpha_test      *alpha_test;
+      const struct cso_blend           *blend;
+      const struct cso_sampler         *sampler[PIPE_MAX_SAMPLERS];
+      const struct cso_depth_stencil   *depth_stencil;
+      const struct cso_rasterizer      *rasterizer;
       const struct cso_fragment_shader *fs;
       const struct cso_vertex_shader   *vs;
 
-      struct pipe_alpha_test_state  alpha_test;
       struct pipe_blend_color  blend_color;
       struct pipe_clear_color_state clear_color;
       struct pipe_clip_state clip;