vc4: Allow user index buffers, to avoid slow readback for shadow IBs.
authorEric Anholt <eric@anholt.net>
Tue, 28 Jul 2015 18:35:03 +0000 (11:35 -0700)
committerEric Anholt <eric@anholt.net>
Fri, 30 Oct 2015 05:58:01 +0000 (22:58 -0700)
Improves low-settings openarena performance by 31.9975% +/- 0.659931%
(n=7).

src/gallium/drivers/vc4/vc4_draw.c
src/gallium/drivers/vc4/vc4_resource.c
src/gallium/drivers/vc4/vc4_screen.c
src/gallium/drivers/vc4/vc4_state.c

index da81599fcc39e53ddf8681f12dc4a1702f9876fc..624a236c5733ed501aa9dd4dd8ab7cbc31aa3cc4 100644 (file)
@@ -25,6 +25,7 @@
 #include "util/u_prim.h"
 #include "util/u_format.h"
 #include "util/u_pack_color.h"
+#include "util/u_upload_mgr.h"
 #include "indices/u_primconvert.h"
 
 #include "vc4_context.h"
@@ -319,7 +320,15 @@ vc4_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
                                                            info->count, &offset);
                         index_size = 2;
                 } else {
-                        prsc = vc4->indexbuf.buffer;
+                        if (vc4->indexbuf.user_buffer) {
+                                prsc = NULL;
+                                u_upload_data(vc4->uploader, 0,
+                                              info->count * index_size,
+                                              vc4->indexbuf.user_buffer,
+                                              &offset, &prsc);
+                        } else {
+                                prsc = vc4->indexbuf.buffer;
+                        }
                 }
                 struct vc4_resource *rsc = vc4_resource(prsc);
 
@@ -334,7 +343,7 @@ vc4_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
                 cl_reloc(vc4, &vc4->bcl, &bcl, rsc->bo, offset);
                 cl_u32(&bcl, vc4->max_index);
 
-                if (vc4->indexbuf.index_size == 4)
+                if (vc4->indexbuf.index_size == 4 || vc4->indexbuf.user_buffer)
                         pipe_resource_reference(&prsc, NULL);
         } else {
                 cl_u8(&bcl, VC4_PACKET_GL_ARRAY_PRIMITIVE);
index 5d5166fd818792622eee386a8e802820750674ea..122bda0bac6ce2442fad27fb916458270fa06aec 100644 (file)
@@ -667,11 +667,16 @@ vc4_get_shadow_index_buffer(struct pipe_context *pctx,
                        shadow_offset, &shadow_rsc, &data);
         uint16_t *dst = data;
 
-        struct pipe_transfer *src_transfer;
-        uint32_t *src = pipe_buffer_map_range(pctx, &orig->base.b,
-                                              ib->offset,
-                                              count * 4,
-                                              PIPE_TRANSFER_READ, &src_transfer);
+        struct pipe_transfer *src_transfer = NULL;
+        uint32_t *src;
+        if (ib->user_buffer) {
+                src = ib->user_buffer;
+        } else {
+                src = pipe_buffer_map_range(pctx, &orig->base.b,
+                                            ib->offset,
+                                            count * 4,
+                                            PIPE_TRANSFER_READ, &src_transfer);
+        }
 
         for (int i = 0; i < count; i++) {
                 uint32_t src_index = src[i];
@@ -679,7 +684,8 @@ vc4_get_shadow_index_buffer(struct pipe_context *pctx,
                 dst[i] = src_index;
         }
 
-        pctx->transfer_unmap(pctx, src_transfer);
+        if (src_transfer)
+                pctx->transfer_unmap(pctx, src_transfer);
 
         return shadow_rsc;
 }
index 432b1d1b86ea79121b5fc0a0f757c93e3a042112..bb867611804368e746dd04269013770f2065bdac 100644 (file)
@@ -94,6 +94,7 @@ vc4_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
         case PIPE_CAP_TEXTURE_SHADOW_MAP:
         case PIPE_CAP_BLEND_EQUATION_SEPARATE:
         case PIPE_CAP_TWO_SIDED_STENCIL:
+        case PIPE_CAP_USER_INDEX_BUFFERS:
                 return 1;
 
                 /* lying for GL 2.0 */
@@ -152,7 +153,6 @@ vc4_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
         case PIPE_CAP_FRAGMENT_COLOR_CLAMPED:
         case PIPE_CAP_VERTEX_COLOR_CLAMPED:
         case PIPE_CAP_USER_VERTEX_BUFFERS:
-        case PIPE_CAP_USER_INDEX_BUFFERS:
         case PIPE_CAP_QUERY_PIPELINE_STATISTICS:
         case PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK:
         case PIPE_CAP_TGSI_VS_LAYER_VIEWPORT:
index 147694644f05206e739d49342aae0610eadba146..78aa344ab1d4dbcbf08309f837a3963cbf5cb6a3 100644 (file)
@@ -305,10 +305,10 @@ vc4_set_index_buffer(struct pipe_context *pctx,
         struct vc4_context *vc4 = vc4_context(pctx);
 
         if (ib) {
-                assert(!ib->user_buffer);
                 pipe_resource_reference(&vc4->indexbuf.buffer, ib->buffer);
                 vc4->indexbuf.index_size = ib->index_size;
                 vc4->indexbuf.offset = ib->offset;
+                vc4->indexbuf.user_buffer = ib->user_buffer;
         } else {
                 pipe_resource_reference(&vc4->indexbuf.buffer, NULL);
         }