r3OOg: support rendering of more than 65535 vertices per draw call (almost)
authorMarek Olšák <maraeo@gmail.com>
Sun, 21 Feb 2010 19:49:29 +0000 (20:49 +0100)
committerMarek Olšák <maraeo@gmail.com>
Mon, 22 Feb 2010 02:12:13 +0000 (03:12 +0100)
The path for VAP_ALT_NUM_VERTICES is also in place (and tested)
but not enabled by default due to the missing support of this reg
in the upstream kernel.

Also, a non-zero BUFFER_BASE in the INDX_BUFFER packet3 hangs the machine.
Am I missing something? Because of this, only draw_arrays can render
more than 65535 vertices without the use of VAP_ALT_NUM_VERTICES.

src/gallium/drivers/r300/r300_reg.h
src/gallium/drivers/r300/r300_render.c

index a049da69e2e4edd8c1642606400db181e5a7eef7..a249e8b36bedf84ea986441c9d7f17134afb6ce2 100644 (file)
@@ -113,11 +113,14 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 
        /* index size - when not set the indices are assumed to be 16 bit */
 #      define  R300_VAP_VF_CNTL__INDEX_SIZE_32bit              (1<<11)
+#       define R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS          (1<<14)
        /* number of vertices */
 #      define  R300_VAP_VF_CNTL__NUM_VERTICES__SHIFT           16
 
 #define R500_VAP_INDEX_OFFSET              0x208c
 
+#define R500_VAP_ALT_NUM_VERTICES                           0x2088
+
 #define R300_VAP_OUTPUT_VTX_FMT_0           0x2090
 #       define R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT     (1<<0)
 #       define R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT (1<<1)
index cd4971ae1364d449d99b180d309684f967fed89c..754eb4dc76922d7baba9fcc1366a784c924c1540 100644 (file)
@@ -42,6 +42,9 @@
 /* r300_render: Vertex and index buffer primitive emission. */
 #define R300_MAX_VBO_SIZE  (1024 * 1024)
 
+/* XXX The DRM rejects VAP_ALT_NUM_VERTICES.. */
+//#define ENABLE_ALT_NUM_VERTS
+
 uint32_t r300_translate_primitive(unsigned prim)
 {
     switch (prim) {
@@ -210,16 +213,28 @@ static void r300_emit_draw_arrays(struct r300_context *r300,
                                   unsigned mode,
                                   unsigned count)
 {
+#if defined(ENABLE_ALT_NUM_VERTS)
+    boolean alt_num_verts = count > 65535;
+#else
+    boolean alt_num_verts = FALSE;
+#endif
     CS_LOCALS(r300);
 
-    BEGIN_CS(8);
+    if (alt_num_verts) {
+        assert(count < (1 << 24));
+        BEGIN_CS(10);
+        OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES, count);
+    } else {
+        BEGIN_CS(8);
+    }
     OUT_CS_REG(R300_GA_COLOR_CONTROL,
             r300_provoking_vertex_fixes(r300, mode));
     OUT_CS_REG(R300_VAP_VF_MIN_VTX_INDX, 0);
     OUT_CS_REG(R300_VAP_VF_MAX_VTX_INDX, count - 1);
     OUT_CS_PKT3(R300_PACKET3_3D_DRAW_VBUF_2, 0);
     OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_VERTEX_LIST | (count << 16) |
-           r300_translate_primitive(mode));
+           r300_translate_primitive(mode) |
+           (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0));
     END_CS;
 }
 
@@ -234,14 +249,27 @@ static void r300_emit_draw_elements(struct r300_context *r300,
 {
     uint32_t count_dwords;
     uint32_t offset_dwords = indexSize * start / sizeof(uint32_t);
+#if defined(ENABLE_ALT_NUM_VERTS)
+    boolean alt_num_verts = count > 65535;
+#else
+    boolean alt_num_verts = FALSE;
+#endif
     CS_LOCALS(r300);
 
-    /* XXX most of these are stupid */
-    assert(indexSize == 4 || indexSize == 2);
     assert((start * indexSize)  % 4 == 0);
-    assert(offset_dwords == 0);
 
-    BEGIN_CS(14);
+    /* XXX Non-zero offset locks up. */
+    if (offset_dwords != 0) {
+        return;
+    }
+
+    if (alt_num_verts) {
+        assert(count < (1 << 24));
+        BEGIN_CS(16);
+        OUT_CS_REG(R500_VAP_ALT_NUM_VERTICES, count);
+    } else {
+        BEGIN_CS(14);
+    }
     OUT_CS_REG(R300_GA_COLOR_CONTROL,
             r300_provoking_vertex_fixes(r300, mode));
     OUT_CS_REG(R300_VAP_VF_MIN_VTX_INDX, minIndex);
@@ -251,24 +279,24 @@ static void r300_emit_draw_elements(struct r300_context *r300,
         count_dwords = count + start;
         OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
                R300_VAP_VF_CNTL__INDEX_SIZE_32bit |
-               r300_translate_primitive(mode));
+               r300_translate_primitive(mode) |
+               (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0));
     } else {
         count_dwords = (count + start + 1) / 2;
         OUT_CS(R300_VAP_VF_CNTL__PRIM_WALK_INDICES | (count << 16) |
-               r300_translate_primitive(mode));
+               r300_translate_primitive(mode) |
+               (alt_num_verts ? R500_VAP_VF_CNTL__USE_ALT_NUM_VERTS : 0));
     }
 
     /* INDX_BUFFER is a truly special packet3.
      * Unlike most other packet3, where the offset is after the count,
      * the order is reversed, so the relocation ends up carrying the
      * size of the indexbuf instead of the offset.
-     *
-     * XXX Fix offset
      */
     OUT_CS_PKT3(R300_PACKET3_INDX_BUFFER, 2);
     OUT_CS(R300_INDX_BUFFER_ONE_REG_WR | (R300_VAP_PORT_IDX0 >> 2) |
            (0 << R300_INDX_BUFFER_SKIP_SHIFT));
-    OUT_CS(offset_dwords);
+    OUT_CS(offset_dwords << 2);
     OUT_CS_RELOC(indexBuffer, count_dwords,
         RADEON_GEM_DOMAIN_GTT, 0, 0);
 
@@ -343,18 +371,18 @@ void r300_draw_range_elements(struct pipe_context* pipe,
 {
     struct r300_context* r300 = r300_context(pipe);
     struct pipe_buffer* orgIndexBuffer = indexBuffer;
+#if defined(ENABLE_ALT_NUM_VERTS)
+    boolean alt_num_verts = r300_screen(pipe->screen)->caps->is_r500 &&
+                            count > 65536;
+#else
+    boolean alt_num_verts = FALSE;
+#endif
+    unsigned short_count;
 
     if (!u_trim_pipe_prim(mode, &count)) {
         return;
     }
 
-    if (count > 65535) {
-       /* XXX: use aux/indices functions to split this into smaller
-        * primitives.
-        */
-        return;
-    }
-
     r300_update_derived_state(r300);
 
     r300_emit_buffer_validate(r300);
@@ -381,8 +409,19 @@ void r300_draw_range_elements(struct pipe_context* pipe,
 
     r300_emit_aos(r300, 0);
 
-    r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex, maxIndex,
-                            mode, start, count);
+    if (alt_num_verts || count <= 65535) {
+        r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex,
+                                maxIndex, mode, start, count);
+    } else {
+        do {
+            short_count = MIN2(count, 65534);
+            r300_emit_draw_elements(r300, indexBuffer, indexSize, minIndex,
+                                    maxIndex, mode, start, short_count);
+
+            start += short_count;
+            count -= short_count;
+        } while (count);
+    }
 
 cleanup:
     if (indexBuffer != orgIndexBuffer) {
@@ -404,18 +443,18 @@ void r300_draw_arrays(struct pipe_context* pipe, unsigned mode,
                       unsigned start, unsigned count)
 {
     struct r300_context* r300 = r300_context(pipe);
+#if defined(ENABLE_ALT_NUM_VERTS)
+    boolean alt_num_verts = r300_screen(pipe->screen)->caps->is_r500 &&
+                            count > 65536;
+#else
+    boolean alt_num_verts = FALSE;
+#endif
+    unsigned short_count;
 
     if (!u_trim_pipe_prim(mode, &count)) {
         return;
     }
 
-    if (count > 65535) {
-        /* XXX: driver needs to handle this -- use the functions in
-         * aux/indices to split this into several smaller primitives.
-         */
-        return;
-    }
-
     r300_update_derived_state(r300);
 
     r300_emit_buffer_validate(r300);
@@ -428,8 +467,20 @@ void r300_draw_arrays(struct pipe_context* pipe, unsigned mode,
         }
 
         r300_emit_dirty_state(r300);
-        r300_emit_aos(r300, start);
-        r300_emit_draw_arrays(r300, mode, count);
+
+        if (alt_num_verts || count <= 65535) {
+            r300_emit_aos(r300, start);
+            r300_emit_draw_arrays(r300, mode, count);
+        } else {
+            do {
+                short_count = MIN2(count, 65535);
+                r300_emit_aos(r300, start);
+                r300_emit_draw_arrays(r300, mode, short_count);
+
+                start += short_count;
+                count -= short_count;
+            } while (count);
+        }
     }
 }