radeonsi: delay adding BOs at the beginning of IBs until the first draw
authorMarek Olšák <marek.olsak@amd.com>
Thu, 28 Feb 2019 02:13:15 +0000 (21:13 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 23 Apr 2019 15:36:36 +0000 (11:36 -0400)
so that bound compute shader resources won't be added when they are not
needed and same for graphics.

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

index f1afef2e66f6ae4ba72efc3208498247714ce1f1..2f444a3a1b887b74a52f2c404d877804f83528a0 100644 (file)
@@ -885,6 +885,9 @@ static void si_launch_grid(
                si_decompress_textures(sctx, 1 << PIPE_SHADER_COMPUTE);
        }
 
+       if (sctx->bo_list_add_all_compute_resources)
+               si_compute_resources_add_all_to_bo_list(sctx);
+
        /* Add buffer sizes for memory checking in need_cs_space. */
        si_context_add_resource_size(sctx, &program->shader.bo->b.b);
        /* TODO: add the scratch buffer */
index ac40ed27f91936e31626321cf3bdcedabfb042ed..f795c33cf2657cfc2203cf01b61824e910a8c031 100644 (file)
@@ -2614,8 +2614,7 @@ static void si_make_image_handle_resident(struct pipe_context *ctx,
        }
 }
 
-
-void si_all_resident_buffers_begin_new_cs(struct si_context *sctx)
+static void si_resident_buffers_add_all_to_bo_list(struct si_context *sctx)
 {
        unsigned num_resident_tex_handles, num_resident_img_handles;
 
@@ -2647,6 +2646,8 @@ void si_all_resident_buffers_begin_new_cs(struct si_context *sctx)
 
        sctx->num_resident_handles += num_resident_tex_handles +
                                        num_resident_img_handles;
+       assert(sctx->bo_list_add_all_resident_resources);
+       sctx->bo_list_add_all_resident_resources = false;
 }
 
 /* INIT/DEINIT/UPLOAD */
@@ -2822,11 +2823,9 @@ void si_release_all_descriptors(struct si_context *sctx)
        si_release_bindless_descriptors(sctx);
 }
 
-void si_all_descriptors_begin_new_cs(struct si_context *sctx)
+void si_gfx_resources_add_all_to_bo_list(struct si_context *sctx)
 {
-       int i;
-
-       for (i = 0; i < SI_NUM_SHADERS; i++) {
+       for (unsigned i = 0; i < SI_NUM_GRAPHICS_SHADERS; i++) {
                si_buffer_resources_begin_new_cs(sctx, &sctx->const_and_shader_buffers[i]);
                si_sampler_views_begin_new_cs(sctx, &sctx->samplers[i]);
                si_image_views_begin_new_cs(sctx, &sctx->images[i]);
@@ -2834,11 +2833,40 @@ void si_all_descriptors_begin_new_cs(struct si_context *sctx)
        si_buffer_resources_begin_new_cs(sctx, &sctx->rw_buffers);
        si_vertex_buffers_begin_new_cs(sctx);
 
-       for (i = 0; i < SI_NUM_DESCS; ++i)
+       if (sctx->bo_list_add_all_resident_resources)
+               si_resident_buffers_add_all_to_bo_list(sctx);
+
+       assert(sctx->bo_list_add_all_gfx_resources);
+       sctx->bo_list_add_all_gfx_resources = false;
+}
+
+void si_compute_resources_add_all_to_bo_list(struct si_context *sctx)
+{
+       unsigned sh = PIPE_SHADER_COMPUTE;
+
+       si_buffer_resources_begin_new_cs(sctx, &sctx->const_and_shader_buffers[sh]);
+       si_sampler_views_begin_new_cs(sctx, &sctx->samplers[sh]);
+       si_image_views_begin_new_cs(sctx, &sctx->images[sh]);
+       si_buffer_resources_begin_new_cs(sctx, &sctx->rw_buffers);
+
+       if (sctx->bo_list_add_all_resident_resources)
+               si_resident_buffers_add_all_to_bo_list(sctx);
+
+       assert(sctx->bo_list_add_all_compute_resources);
+       sctx->bo_list_add_all_compute_resources = false;
+}
+
+void si_all_descriptors_begin_new_cs(struct si_context *sctx)
+{
+       for (unsigned i = 0; i < SI_NUM_DESCS; ++i)
                si_descriptors_begin_new_cs(sctx, &sctx->descriptors[i]);
        si_descriptors_begin_new_cs(sctx, &sctx->bindless_descriptors);
 
        si_shader_pointers_begin_new_cs(sctx);
+
+       sctx->bo_list_add_all_resident_resources = true;
+       sctx->bo_list_add_all_gfx_resources = true;
+       sctx->bo_list_add_all_compute_resources = true;
 }
 
 void si_set_active_descriptors(struct si_context *sctx, unsigned desc_idx,
index 39184e0e9dacecad5becbc89e2e13a132856ce03..3e36923459756738754b2a3880db95442c698344 100644 (file)
@@ -244,7 +244,6 @@ void si_begin_new_gfx_cs(struct si_context *ctx)
 
        ctx->cs_shader_state.initialized = false;
        si_all_descriptors_begin_new_cs(ctx);
-       si_all_resident_buffers_begin_new_cs(ctx);
 
        if (!ctx->has_graphics) {
                ctx->initial_gfx_cs_size = ctx->gfx_cs->current.cdw;
index 26b12a8a674bd14955c7e317a4b0e40dec0a4e80..5d43a594759ee2c778298dba29802b718f05fefd 100644 (file)
@@ -921,6 +921,9 @@ struct si_context {
        struct si_buffer_resources      const_and_shader_buffers[SI_NUM_SHADERS];
        struct si_samplers              samplers[SI_NUM_SHADERS];
        struct si_images                images[SI_NUM_SHADERS];
+       bool                            bo_list_add_all_resident_resources;
+       bool                            bo_list_add_all_gfx_resources;
+       bool                            bo_list_add_all_compute_resources;
 
        /* other shader resources */
        struct pipe_constant_buffer     null_const_buf; /* used for set_constant_buffer(NULL) on CIK */
index 311e1a428ae3eb33c2d3fdbaf4a3e919a12cec8b..b0802416c73d97df70c47633faf73844cf76478c 100644 (file)
@@ -462,8 +462,9 @@ bool si_upload_vertex_buffer_descriptors(struct si_context *sctx);
 bool si_upload_graphics_shader_descriptors(struct si_context *sctx);
 bool si_upload_compute_shader_descriptors(struct si_context *sctx);
 void si_release_all_descriptors(struct si_context *sctx);
+void si_gfx_resources_add_all_to_bo_list(struct si_context *sctx);
+void si_compute_resources_add_all_to_bo_list(struct si_context *sctx);
 void si_all_descriptors_begin_new_cs(struct si_context *sctx);
-void si_all_resident_buffers_begin_new_cs(struct si_context *sctx);
 void si_upload_const_buffer(struct si_context *sctx, struct si_resource **buf,
                            const uint8_t *ptr, unsigned size, uint32_t *const_offset);
 void si_update_all_texture_descriptors(struct si_context *sctx);
index 1cadc416ca3dfbb40a30de36e065021b7d8df266..c220eaf24f84911a2c3fa3e9d9756422ea491f08 100644 (file)
@@ -1311,6 +1311,9 @@ static void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *i
 
        si_decompress_textures(sctx, u_bit_consecutive(0, SI_NUM_GRAPHICS_SHADERS));
 
+       if (sctx->bo_list_add_all_gfx_resources)
+               si_gfx_resources_add_all_to_bo_list(sctx);
+
        /* Set the rasterization primitive type.
         *
         * This must be done after si_decompress_textures, which can call