Squashed commit of the following:
[mesa.git] / src / gallium / drivers / i965 / brw_draw.c
index a2bed6256b7593465f776a2410c3d6577caac88b..eb73ec2f272c8a382ff5742f0e331cad98b029f4 100644 (file)
@@ -26,6 +26,7 @@
  **************************************************************************/
 
 
+#include "util/u_inlines.h"
 #include "util/u_prim.h"
 #include "util/u_upload_mgr.h"
 
@@ -34,7 +35,6 @@
 #include "brw_context.h"
 #include "brw_state.h"
 #include "brw_debug.h"
-#include "brw_screen.h"
 
 #include "brw_batchbuffer.h"
 
@@ -92,6 +92,10 @@ static int brw_emit_prim(struct brw_context *brw,
    struct brw_3d_primitive prim_packet;
    int ret;
 
+   if (BRW_DEBUG & DEBUG_PRIMS)
+      debug_printf("%s start %d count %d indexed %d hw_prim %d\n",
+                   __FUNCTION__, start, count, indexed, hw_prim); 
+
    prim_packet.header.opcode = CMD_3D_PRIM;
    prim_packet.header.length = sizeof(prim_packet)/4 - 2;
    prim_packet.header.pad = 0;
@@ -104,7 +108,7 @@ static int brw_emit_prim(struct brw_context *brw,
       prim_packet.start_vert_location += brw->ib.start_vertex_offset;
    prim_packet.instance_count = 1;
    prim_packet.start_instance_location = 0;
-   prim_packet.base_vert_location = 0; // prim->basevertex; XXX: add this to gallium
+   prim_packet.base_vert_location = 0; /* prim->basevertex; XXX: add this to gallium */
 
 
    /* If we're set to always flush, do it before and after the primitive emit.
@@ -138,7 +142,7 @@ static int brw_emit_prim(struct brw_context *brw,
  */
 static int
 try_draw_range_elements(struct brw_context *brw,
-                       struct pipe_buffer *index_buffer,
+                       struct pipe_resource *index_buffer,
                        unsigned hw_prim, 
                        unsigned start, unsigned count)
 {
@@ -172,9 +176,9 @@ try_draw_range_elements(struct brw_context *brw,
 }
 
 
-static boolean
+static void
 brw_draw_range_elements(struct pipe_context *pipe,
-                       struct pipe_buffer *index_buffer,
+                       struct pipe_resource *index_buffer,
                        unsigned index_size,
                        unsigned min_index,
                        unsigned max_index,
@@ -187,15 +191,18 @@ brw_draw_range_elements(struct pipe_context *pipe,
    hw_prim = brw_set_prim(brw, mode);
 
    if (BRW_DEBUG & DEBUG_PRIMS)
-      debug_printf("PRIM: %s %d %d\n", u_prim_name(mode), start, count);
+      debug_printf("PRIM: %s start %d count %d index_buffer %p\n",
+                   u_prim_name(mode), start, count, (void *)index_buffer);
 
    /* Potentially trigger upload of new index buffer.
     *
     * XXX: do we need to go through state validation to achieve this?
     * Could just call upload code directly.
     */
-   if (brw->curr.index_buffer != index_buffer) {
-      pipe_buffer_reference( &brw->curr.index_buffer, index_buffer );
+   if (brw->curr.index_buffer != index_buffer ||
+       brw->curr.index_size != index_size) {
+      pipe_resource_reference( &brw->curr.index_buffer, index_buffer );
+      brw->curr.index_size = index_size;
       brw->state.dirty.mesa |= PIPE_NEW_INDEX_BUFFER;
    }
 
@@ -221,29 +228,27 @@ brw_draw_range_elements(struct pipe_context *pipe,
       ret = try_draw_range_elements(brw, index_buffer, hw_prim, start, count );
       assert(ret == 0);
    }
-
-   return TRUE;
 }
 
-static boolean
+static void
 brw_draw_elements(struct pipe_context *pipe,
-                 struct pipe_buffer *index_buffer,
+                 struct pipe_resource *index_buffer,
                  unsigned index_size,
                  unsigned mode, 
                  unsigned start, unsigned count)
 {
-   return brw_draw_range_elements( pipe, index_buffer,
-                                  index_size,
-                                  0, 0xffffffff,
-                                  mode, 
-                                  start, count );
+   brw_draw_range_elements( pipe, index_buffer,
+                            index_size,
+                            0, 0xffffffff,
+                            mode, 
+                            start, count );
 }
 
-static boolean
+static void
 brw_draw_arrays(struct pipe_context *pipe, unsigned mode,
                      unsigned start, unsigned count)
 {
-   return brw_draw_elements(pipe, NULL, 0, mode, start, count);
+   brw_draw_elements(pipe, NULL, 0, mode, start, count);
 }
 
 
@@ -258,17 +263,17 @@ boolean brw_draw_init( struct brw_context *brw )
 
    /* Create helpers for uploading data in user buffers:
     */
-   brw->vb.upload_vertex = u_upload_create( &brw->brw_screen->base,
+   brw->vb.upload_vertex = u_upload_create( &brw->base,
                                            128 * 1024,
                                            64,
-                                           PIPE_BUFFER_USAGE_VERTEX );
+                                           PIPE_BIND_VERTEX_BUFFER );
    if (brw->vb.upload_vertex == NULL)
       return FALSE;
 
-   brw->vb.upload_index = u_upload_create( &brw->brw_screen->base,
-                                          128 * 1024,
+   brw->vb.upload_index = u_upload_create( &brw->base,
+                                          32 * 1024,
                                           64,
-                                          PIPE_BUFFER_USAGE_INDEX );
+                                          PIPE_BIND_INDEX_BUFFER );
    if (brw->vb.upload_index == NULL)
       return FALSE;
 
@@ -280,6 +285,5 @@ void brw_draw_cleanup( struct brw_context *brw )
    u_upload_destroy( brw->vb.upload_vertex );
    u_upload_destroy( brw->vb.upload_index );
 
-   brw->sws->bo_unreference(brw->ib.bo);
-   brw->ib.bo = NULL;
+   bo_reference(&brw->ib.bo, NULL);
 }