gallium: avoid deleting currently-bound CSO's on cache destruction
authorKeith Whitwell <keith@tungstengraphics.com>
Sun, 9 Mar 2008 20:21:45 +0000 (20:21 +0000)
committerKeith Whitwell <keith@tungstengraphics.com>
Sun, 9 Mar 2008 20:23:05 +0000 (20:23 +0000)
src/gallium/auxiliary/cso_cache/cso_context.c

index 596e5a9ad66ec3f46a99485a6aa13ee54e380956..fbb26ca511e19ad71de69d3fa85da45909670023 100644 (file)
@@ -72,6 +72,9 @@ struct cso_context *cso_create_context( struct pipe_context *pipe )
 
    ctx->pipe = pipe;
 
+   /* Enable for testing: */
+   if (0) cso_set_maximum_cache_size( ctx->cache, 4 );
+
    return ctx;
 
 out:
@@ -79,20 +82,31 @@ out:
    return NULL;
 }
 
+static void cso_release_all( struct cso_context *ctx )
+{
+   if (ctx->pipe) {
+      ctx->pipe->bind_blend_state( ctx->pipe, NULL );
+      ctx->pipe->bind_rasterizer_state( ctx->pipe, NULL );
+      ctx->pipe->bind_sampler_states( ctx->pipe, 0, NULL );
+      ctx->pipe->bind_depth_stencil_alpha_state( ctx->pipe, NULL );
+      ctx->pipe->bind_fs_state( ctx->pipe, NULL );
+      ctx->pipe->bind_vs_state( ctx->pipe, NULL );
+   }
+
+   if (ctx->cache) {
+      cso_cache_delete( ctx->cache );
+      ctx->cache = NULL;
+   }
+}
+
 
 void cso_destroy_context( struct cso_context *ctx )
 {
-   if (ctx == NULL)
-      return;
-   
-/*
-   if (ctx->pipe) 
-      ctx->pipe->flush( ctx->pipe, PIPE_FLUSH_UNBIND_ALL );
-*/
+   debug_printf("%s\n", __FUNCTION__);
+
+   if (ctx)
+      cso_release_all( ctx );
 
-   if (ctx->cache)
-      cso_cache_delete( ctx->cache );
-   
    FREE( ctx );
 }