r300-gallium: Factor out common functionality in vbuf emit.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Wed, 18 Feb 2009 14:38:21 +0000 (06:38 -0800)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Wed, 18 Feb 2009 14:40:38 +0000 (06:40 -0800)
src/gallium/drivers/r300/r300_swtcl_emit.c

index fb009247a50bf5ec5a5a982576eee996b8d56fc2..327d4ac2e1014a926a3c117cd95e682016405015 100644 (file)
@@ -174,13 +174,9 @@ static boolean r300_swtcl_render_set_primitive(struct vbuf_render* render,
     return true;
 }
 
-static void r300_swtcl_render_draw_arrays(struct vbuf_render* render,
-                                          unsigned start,
-                                          unsigned count)
+static void prepare_render(struct r300_swtcl_render* render)
 {
-    struct r300_swtcl_render* r300render = r300_swtcl_render(render);
-    struct r300_context* r300 = r300render->r300;
-    struct pipe_screen* screen = r300->context.screen;
+    struct r300_context* r300 = render->r300;
 
     CS_LOCALS(r300);
 
@@ -188,7 +184,7 @@ static void r300_swtcl_render_draw_arrays(struct vbuf_render* render,
     r300_update_derived_state(r300);
     r300_emit_dirty_state(r300);
 
-    /* Take care of vertex formats and routes */
+    /* Take care of vertex formats and routes. */
     BEGIN_CS(3);
     OUT_CS_REG_SEQ(R300_VAP_OUTPUT_VTX_FMT_0, 2);
     OUT_CS(r300->vertex_info.hwfmt[0]);
@@ -196,10 +192,39 @@ static void r300_swtcl_render_draw_arrays(struct vbuf_render* render,
     END_CS;
 
     /* Draw stuff! */
+    BEGIN_CS(6);
+
+    /* Set the pointer to our vertex buffer. The emitted values are this:
+     * PACKET3 [3D_LOAD_VBPNTR]
+     * COUNT   [1]
+     * FORMAT  [size | stride << 8]
+     * VBPNTR  [relocated BO]
+     *
+     * And of course that extra dword is space for the relocation. */
+    OUT_CS(CP_PACKET3(R300_PACKET3_3D_LOAD_VBPNTR, 3));
+    OUT_CS(1);
+    OUT_CS(r300->vertex_info.size | (r300->vertex_info.size << 8));
+    OUT_CS(0);
+    OUT_CS_RELOC(render->vbo, 0, RADEON_GEM_DOMAIN_GTT, 0, 0);
+}
+
+static void r300_swtcl_render_draw_arrays(struct vbuf_render* render,
+                                          unsigned start,
+                                          unsigned count)
+{
+    struct r300_swtcl_render* r300render = r300_swtcl_render(render);
+    struct r300_context* r300 = r300render->r300;
+    struct pipe_screen* screen = r300->context.screen;
+
+    CS_LOCALS(r300);
+
+    prepare_render(r300render);
+
     BEGIN_CS(2);
     OUT_CS(CP_PACKET3(R300_PACKET3_3D_DRAW_VBUF_2, 0));
     OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
            r300render->hwprim | R300_VAP_VF_CNTL__INDEX_SIZE_32bit);
+    END_CS;
 }
 
 static void r300_swtcl_render_draw(struct vbuf_render* render,
@@ -214,9 +239,7 @@ static void r300_swtcl_render_draw(struct vbuf_render* render,
 
     CS_LOCALS(r300);
 
-    /* Make sure that all possible state is emitted. */
-    r300_update_derived_state(r300);
-    r300_emit_dirty_state(r300);
+    prepare_render(r300render);
 
     /* Send our indices into an index buffer. */
     index_buffer = pipe_buffer_create(screen, 64, PIPE_BUFFER_USAGE_VERTEX,
@@ -230,15 +253,7 @@ static void r300_swtcl_render_draw(struct vbuf_render* render,
     memcpy(index_map, indices, count * 4);
     pipe_buffer_unmap(screen, index_buffer);
 
-    /* Take care of vertex formats and routes */
-    BEGIN_CS(3);
-    OUT_CS_REG_SEQ(R300_VAP_OUTPUT_VTX_FMT_0, 2);
-    OUT_CS(r300->vertex_info.hwfmt[0]);
-    OUT_CS(r300->vertex_info.hwfmt[1]);
-    END_CS;
-
-    /* Draw stuff! */
-    BEGIN_CS(10);
+    BEGIN_CS(5);
     OUT_CS(CP_PACKET3(R300_PACKET3_3D_DRAW_INDX_2, 0));
     OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
            r300render->hwprim | R300_VAP_VF_CNTL__INDEX_SIZE_32bit);