r300g: fix psychedelic colors with SWTCL
[mesa.git] / src / gallium / drivers / r300 / r300_context.c
index deaa03e1f616e44c346358f543900ca15e7abf2e..c45d4b64f424ae87c32c1fd92dbe965ae9fc9235 100644 (file)
 #include "r300_state_invariant.h"
 #include "r300_winsys.h"
 
+#include <inttypes.h>
+
 static void r300_destroy_context(struct pipe_context* context)
 {
     struct r300_context* r300 = r300_context(context);
     struct r300_query* query, * temp;
+    struct r300_atom *atom;
 
     util_blitter_destroy(r300->blitter);
     draw_destroy(r300->draw);
 
+    /* Print stats, if enabled. */
+    if (SCREEN_DBG_ON(r300->screen, DBG_STATS)) {
+        fprintf(stderr, "r300: Stats for context %p:\n", r300);
+        fprintf(stderr, "    : Flushes: %" PRIu64 "\n", r300->flush_counter);
+        foreach(atom, &r300->atom_list) {
+            fprintf(stderr, "    : %s: %" PRIu64 " emits\n",
+                atom->name, atom->counter);
+        }
+    }
+
     /* Free the OQ BO. */
     context->screen->resource_destroy(context->screen, r300->oqbo);
 
@@ -63,11 +76,13 @@ static void r300_destroy_context(struct pipe_context* context)
     FREE(r300->rs_block_state.state);
     FREE(r300->scissor_state.state);
     FREE(r300->textures_state.state);
-    FREE(r300->vap_output_state.state);
     FREE(r300->viewport_state.state);
     FREE(r300->ztop_state.state);
     FREE(r300->fs_constants.state);
     FREE(r300->vs_constants.state);
+    if (!r300->screen->caps.has_tcl) {
+        FREE(r300->vertex_stream_state.state);
+    }
     FREE(r300);
 }
 
@@ -112,7 +127,6 @@ static void r300_setup_atoms(struct r300_context* r300)
     R300_INIT_ATOM(viewport_state, 9);
     R300_INIT_ATOM(rs_block_state, 0);
     R300_INIT_ATOM(vertex_stream_state, 0);
-    R300_INIT_ATOM(vap_output_state, 6);
     R300_INIT_ATOM(pvs_flush, 2);
     R300_INIT_ATOM(vs_state, 0);
     R300_INIT_ATOM(vs_constants, 0);
@@ -136,11 +150,20 @@ static void r300_setup_atoms(struct r300_context* r300)
     r300->rs_block_state.state = CALLOC_STRUCT(r300_rs_block);
     r300->scissor_state.state = CALLOC_STRUCT(pipe_scissor_state);
     r300->textures_state.state = CALLOC_STRUCT(r300_textures_state);
-    r300->vap_output_state.state = CALLOC_STRUCT(r300_vap_output_state);
     r300->viewport_state.state = CALLOC_STRUCT(r300_viewport_state);
     r300->ztop_state.state = CALLOC_STRUCT(r300_ztop_state);
     r300->fs_constants.state = CALLOC_STRUCT(r300_constant_buffer);
     r300->vs_constants.state = CALLOC_STRUCT(r300_constant_buffer);
+    if (!r300->screen->caps.has_tcl) {
+        r300->vertex_stream_state.state = CALLOC_STRUCT(r300_vertex_stream_state);
+    }
+
+    /* Some non-CSO atoms don't use the state pointer. */
+    r300->invariant_state.allow_null_state = TRUE;
+    r300->fs_rc_constant_state.allow_null_state = TRUE;
+    r300->pvs_flush.allow_null_state = TRUE;
+    r300->query_start.allow_null_state = TRUE;
+    r300->texture_cache_inval.allow_null_state = TRUE;
 }
 
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
@@ -191,9 +214,6 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
         draw_set_rasterize_stage(r300->draw, r300_draw_stage(r300));
         /* Enable Draw's clipping. */
         draw_set_driver_clipping(r300->draw, FALSE);
-        /* Force Draw to never do viewport transform, since we can do
-         * transform in hardware, always. */
-        draw_set_viewport_state(r300->draw, &r300_viewport_identity);
     }
 
     r300_setup_atoms(r300);