radeonsi: determine in advance which VBOs should be added to the buffer list
authorMarek Olšák <marek.olsak@amd.com>
Tue, 17 Jan 2017 21:03:23 +0000 (22:03 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 18 Jan 2017 18:51:31 +0000 (19:51 +0100)
v2: now it should be correct

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/drivers/radeonsi/si_descriptors.c
src/gallium/drivers/radeonsi/si_state.c
src/gallium/drivers/radeonsi/si_state.h

index f61dec6c8e57420dc6d57c2e7327a7f2e462cad5..df0905d897732f798a4a0267b7ee590802f35351 100644 (file)
@@ -939,7 +939,6 @@ bool si_upload_vertex_buffer_descriptors(struct si_context *sctx)
 {
        struct si_vertex_element *velems = sctx->vertex_elements;
        struct si_descriptors *desc = &sctx->vertex_buffers;
-       bool bound[SI_NUM_VERTEX_BUFFERS] = {};
        unsigned i, count = velems->count;
        uint64_t va;
        uint32_t *ptr;
@@ -948,6 +947,7 @@ bool si_upload_vertex_buffer_descriptors(struct si_context *sctx)
                return true;
 
        unsigned fix_size3 = velems->fix_size3;
+       unsigned first_vb_use_mask = velems->first_vb_use_mask;
 
        /* Vertex buffer descriptors are the only ones which are uploaded
         * directly through a staging buffer and don't go through
@@ -969,9 +969,10 @@ bool si_upload_vertex_buffer_descriptors(struct si_context *sctx)
                struct pipe_vertex_buffer *vb;
                struct r600_resource *rbuffer;
                unsigned offset;
+               unsigned vbo_index = ve->vertex_buffer_index;
                uint32_t *desc = &ptr[i*4];
 
-               vb = &sctx->vertex_buffer[ve->vertex_buffer_index];
+               vb = &sctx->vertex_buffer[vbo_index];
                rbuffer = (struct r600_resource*)vb->buffer;
                if (!rbuffer) {
                        memset(desc, 0, 16);
@@ -1018,11 +1019,10 @@ bool si_upload_vertex_buffer_descriptors(struct si_context *sctx)
 
                desc[3] = velems->rsrc_word3[i];
 
-               if (!bound[ve->vertex_buffer_index]) {
+               if (first_vb_use_mask & (1 << i)) {
                        radeon_add_to_buffer_list(&sctx->b, &sctx->b.gfx,
                                              (struct r600_resource*)vb->buffer,
                                              RADEON_USAGE_READ, RADEON_PRIO_VERTEX_BUFFER);
-                       bound[ve->vertex_buffer_index] = true;
                }
        }
 
index 3022260f2ff2121564baeed810833ab44b7e3980..f60a4992bc355ea147880ed628daabe94a163778 100644 (file)
@@ -3323,6 +3323,7 @@ static void *si_create_vertex_elements(struct pipe_context *ctx,
                                       const struct pipe_vertex_element *elements)
 {
        struct si_vertex_element *v = CALLOC_STRUCT(si_vertex_element);
+       bool used[SI_NUM_VERTEX_BUFFERS] = {};
        int i;
 
        assert(count <= SI_MAX_ATTRIBS);
@@ -3342,6 +3343,11 @@ static void *si_create_vertex_elements(struct pipe_context *ctx,
                        return NULL;
                }
 
+               if (!used[vbo_index]) {
+                       v->first_vb_use_mask |= 1 << i;
+                       used[vbo_index] = true;
+               }
+
                desc = util_format_description(elements[i].src_format);
                first_non_void = util_format_get_first_non_void_channel(elements[i].src_format);
                data_format = si_translate_buffer_dataformat(ctx->screen, desc, first_non_void);
index 34a0f578492de9f830adbddf84ea90b279bd9f9a..03e5011779b82c87dfc1e0d822386bbfb684ee3c 100644 (file)
@@ -99,6 +99,7 @@ struct si_stencil_ref {
 struct si_vertex_element
 {
        unsigned                        count;
+       unsigned                        first_vb_use_mask;
 
        /* Two bits per attribute indicating the size of each vector component
         * in bytes if the size 3-workaround must be applied.