Merge remote branch 'origin/master' into lp-binning
[mesa.git] / src / gallium / drivers / i965 / brw_draw_upload.c
index f0b7c741c0a1a2bf709360eb891caf501afbadc5..a27da5f1c1713e99284725a0840e4f8197fe1527 100644 (file)
@@ -26,7 +26,6 @@
  **************************************************************************/
 
 #include "pipe/p_context.h"
-#include "pipe/p_error.h"
 
 #include "util/u_upload_mgr.h"
 #include "util/u_math.h"
@@ -202,7 +201,7 @@ static int brw_prepare_vertices(struct brw_context *brw)
    for (i = 0; i < brw->curr.num_vertex_buffers; i++) {
       struct pipe_vertex_buffer *vb = &brw->curr.vertex_buffer[i];
       struct brw_winsys_buffer *bo;
-      struct pipe_buffer *upload_buf;
+      struct pipe_buffer *upload_buf = NULL;
       unsigned offset;
       
       if (BRW_DEBUG & DEBUG_VERTS)
@@ -252,9 +251,8 @@ static int brw_prepare_vertices(struct brw_context *brw)
       brw->vb.vb[i].vertex_count = (vb->stride == 0 ?
                                    1 :
                                    (bo->size - offset) / vb->stride);
-      brw->sws->bo_unreference(brw->vb.vb[i].bo);
-      brw->vb.vb[i].bo = bo;
-      brw->sws->bo_reference(brw->vb.vb[i].bo);
+
+      bo_reference( &brw->vb.vb[i].bo,  bo );
 
       /* Don't need to retain this reference.  We have a reference on
        * the underlying winsys buffer:
@@ -319,6 +317,7 @@ static int brw_emit_vertex_buffers( struct brw_context *brw )
 
 static int brw_emit_vertex_elements(struct brw_context *brw)
 {
+   GLuint nr = brw->curr.num_vertex_elements;
    GLuint i;
 
    brw_emit_query_begin(brw);
@@ -330,7 +329,7 @@ static int brw_emit_vertex_elements(struct brw_context *brw)
     * The stale VB state stays in place, but they don't do anything unless
     * a VE loads from them.
     */
-   if (brw->vb.nr_ve == 0) {
+   if (nr == 0) {
       BEGIN_BATCH(3, IGNORE_CLIPRECTS);
       OUT_BATCH((CMD_VERTEX_ELEMENT << 16) | 1);
       OUT_BATCH((0 << BRW_VE0_INDEX_SHIFT) |
@@ -348,9 +347,9 @@ static int brw_emit_vertex_elements(struct brw_context *brw)
    /* Now emit vertex element (VEP) state packets.
     *
     */
-   BEGIN_BATCH(1 + brw->curr.num_vertex_elements * 2, IGNORE_CLIPRECTS);
-   OUT_BATCH((CMD_VERTEX_ELEMENT << 16) | ((1 + brw->vb.nr_ve * 2) - 2));
-   for (i = 0; i < brw->vb.nr_ve; i++) {
+   BEGIN_BATCH(1 + nr * 2, IGNORE_CLIPRECTS);
+   OUT_BATCH((CMD_VERTEX_ELEMENT << 16) | ((1 + nr * 2) - 2));
+   for (i = 0; i < nr; i++) {
       const struct pipe_vertex_element *input = &brw->curr.vertex_element[i];
       uint32_t format = brw_translate_surface_format( input->src_format );
       uint32_t comp0 = BRW_VE1_COMPONENT_STORE_SRC;
@@ -366,10 +365,10 @@ static int brw_emit_vertex_elements(struct brw_context *brw)
         break;
       }
 
-      OUT_BATCH((i << BRW_VE0_INDEX_SHIFT) |
+      OUT_BATCH((input->vertex_buffer_index << BRW_VE0_INDEX_SHIFT) |
                BRW_VE0_VALID |
                (format << BRW_VE0_FORMAT_SHIFT) |
-               (0 << BRW_VE0_SRC_OFFSET_SHIFT));
+               (input->src_offset << BRW_VE0_SRC_OFFSET_SHIFT));
 
       if (BRW_IS_IGDNG(brw))
           OUT_BATCH((comp0 << BRW_VE1_COMPONENT_0_SHIFT) |
@@ -406,8 +405,9 @@ static int brw_emit_vertices( struct brw_context *brw )
 
 const struct brw_tracked_state brw_vertices = {
    .dirty = {
-      .mesa = PIPE_NEW_INDEX_RANGE,
-      .brw = BRW_NEW_BATCH | BRW_NEW_VERTICES,
+      .mesa = (PIPE_NEW_INDEX_RANGE |
+               PIPE_NEW_VERTEX_BUFFER),
+      .brw = BRW_NEW_BATCH,
       .cache = 0,
    },
    .prepare = brw_prepare_vertices,
@@ -418,6 +418,7 @@ const struct brw_tracked_state brw_vertices = {
 static int brw_prepare_indices(struct brw_context *brw)
 {
    struct pipe_buffer *index_buffer = brw->curr.index_buffer;
+   struct pipe_buffer *upload_buf = NULL;
    struct brw_winsys_buffer *bo = NULL;
    GLuint offset;
    GLuint index_size;
@@ -427,7 +428,7 @@ static int brw_prepare_indices(struct brw_context *brw)
    if (index_buffer == NULL)
       return 0;
 
-   if (DEBUG & DEBUG_VERTS)
+   if (BRW_DEBUG & DEBUG_VERTS)
       debug_printf("%s: index_size:%d index_buffer->size:%d\n",
                   __FUNCTION__,
                   brw->curr.index_size,
@@ -439,7 +440,6 @@ static int brw_prepare_indices(struct brw_context *brw)
    /* Turn userbuffer into a proper hardware buffer?
     */
    if (brw_buffer_is_user_buffer(index_buffer)) {
-      struct pipe_buffer *upload_buf;
 
       ret = u_upload_buffer( brw->vb.upload_index,
                             0,
@@ -451,8 +451,6 @@ static int brw_prepare_indices(struct brw_context *brw)
         return ret;
 
       bo = brw_buffer(upload_buf)->bo;
-      brw->sws->bo_reference(bo);
-      pipe_buffer_reference( &upload_buf, NULL );
 
       /* XXX: annotate the userbuffer with the upload information so
        * that successive calls don't get re-uploaded.
@@ -460,8 +458,6 @@ static int brw_prepare_indices(struct brw_context *brw)
    }
    else {
       bo = brw_buffer(index_buffer)->bo;
-      brw->sws->bo_reference(bo);
-      
       ib_size = bo->size;
       offset = 0;
    }
@@ -487,15 +483,12 @@ static int brw_prepare_indices(struct brw_context *brw)
    if (brw->ib.bo != bo ||
        brw->ib.size != ib_size)
    {
-      brw->sws->bo_unreference(brw->ib.bo);
-      brw->ib.bo = bo;
+      bo_reference(&brw->ib.bo, bo);
       brw->ib.size = ib_size;
       brw->state.dirty.brw |= BRW_NEW_INDEX_BUFFER;
    }
-   else {
-      brw->sws->bo_unreference(bo);
-   }
 
+   pipe_buffer_reference( &upload_buf, NULL );
    brw_add_validated_bo(brw, brw->ib.bo);
    return 0;
 }