r300g: fix corruption when nr_cbufs==0 and multiwrites enabled
[mesa.git] / src / gallium / drivers / r300 / r300_context.c
index fd3f21d2a6aaa660b870666800dbfc068d3409c6..7ba8e710554087a2a59a119626f30c608e95a827 100644 (file)
@@ -35,7 +35,9 @@
 #include "r300_screen_buffer.h"
 #include "r300_winsys.h"
 
-#include <inttypes.h>
+#ifdef HAVE_LLVM
+#include "gallivm/lp_bld_init.h"
+#endif
 
 static void r300_update_num_contexts(struct r300_screen *r300screen,
                                      int diff)
@@ -100,21 +102,15 @@ static void r300_release_referenced_objects(struct r300_context *r300)
 static void r300_destroy_context(struct pipe_context* context)
 {
     struct r300_context* r300 = r300_context(context);
-    struct r300_atom *atom;
 
     if (r300->blitter)
         util_blitter_destroy(r300->blitter);
-    if (r300->draw)
+    if (r300->draw) {
         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);
-        }
+#ifdef HAVE_LLVM
+        gallivm_destroy(r300->gallivm);
+#endif
     }
 
     if (r300->upload_vb)
@@ -177,7 +173,6 @@ void r300_flush_cb(void *data)
     r300->atomname.size = atomsize; \
     r300->atomname.emit = r300_emit_##atomname; \
     r300->atomname.dirty = FALSE; \
-    insert_at_tail(&r300->atom_list, &r300->atomname); \
  } while (0)
 
 #define R300_ALLOC_ATOM(atomname, statetype) \
@@ -198,9 +193,6 @@ static boolean r300_setup_atoms(struct r300_context* r300)
     boolean has_hiz_ram = r300->screen->caps.hiz_ram > 0;
 
     /* Create the actual atom list.
-     *
-     * Each atom is examined and emitted in the order it appears here, which
-     * can affect performance and conformance if not handled with care.
      *
      * Some atoms never change size, others change every emit - those have
      * the size of 0 here.
@@ -213,7 +205,6 @@ static boolean r300_setup_atoms(struct r300_context* r300)
      * - fb_state_pipelined (pipelined regs)
      * The motivation behind this is to be able to emit a strict
      * subset of the regs, and to have reasonable register ordering. */
-    make_empty_list(&r300->atom_list);
     /* SC, GB (unpipelined), RB3D (unpipelined), ZB (unpipelined). */
     R300_INIT_ATOM(gpu_flush, 9);
     R300_INIT_ATOM(aa_state, 4);
@@ -296,11 +287,11 @@ static boolean r300_setup_atoms(struct r300_context* r300)
 
     /* Some states must be marked as dirty here to properly set up
      * hardware in the first command stream. */
-    r300->invariant_state.dirty = TRUE;
-    r300->pvs_flush.dirty = TRUE;
-    r300->vap_invariant_state.dirty = TRUE;
-    r300->texture_cache_inval.dirty = TRUE;
-    r300->textures_state.dirty = TRUE;
+    r300_mark_atom_dirty(r300, &r300->invariant_state);
+    r300_mark_atom_dirty(r300, &r300->pvs_flush);
+    r300_mark_atom_dirty(r300, &r300->vap_invariant_state);
+    r300_mark_atom_dirty(r300, &r300->texture_cache_inval);
+    r300_mark_atom_dirty(r300, &r300->textures_state);
 
     return TRUE;
 }
@@ -440,7 +431,12 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
 
     if (!r300screen->caps.has_tcl) {
         /* Create a Draw. This is used for SW TCL. */
+#ifdef HAVE_LLVM
+        r300->gallivm = gallivm_create();
+        r300->draw = draw_create_gallivm(&r300->context, r300->gallivm);
+#else
         r300->draw = draw_create(&r300->context);
+#endif
         if (r300->draw == NULL)
             goto fail;
         /* Enable our renderer. */
@@ -474,14 +470,14 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
             goto fail;
 
     r300->upload_ib = u_upload_create(&r300->context,
-                                     32 * 1024, 16,
+                                     64 * 1024, 16,
                                      PIPE_BIND_INDEX_BUFFER);
 
     if (r300->upload_ib == NULL)
         goto fail;
 
     r300->upload_vb = u_upload_create(&r300->context,
-                                     128 * 1024, 16,
+                                     1024 * 1024, 16,
                                      PIPE_BIND_VERTEX_BUFFER);
     if (r300->upload_vb == NULL)
         goto fail;