From 951d60f8cdc886adff09201ff65002e3ee1a4c61 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Wed, 27 Feb 2019 21:13:15 -0500 Subject: radeonsi: delay adding BOs at the beginning of IBs until the first draw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit so that bound compute shader resources won't be added when they are not needed and same for graphics. Acked-by: Nicolai Hähnle --- src/gallium/drivers/radeonsi/si_compute.c | 3 ++ src/gallium/drivers/radeonsi/si_descriptors.c | 42 ++++++++++++++++++++++----- src/gallium/drivers/radeonsi/si_gfx_cs.c | 1 - src/gallium/drivers/radeonsi/si_pipe.h | 3 ++ src/gallium/drivers/radeonsi/si_state.h | 3 +- src/gallium/drivers/radeonsi/si_state_draw.c | 3 ++ 6 files changed, 46 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/gallium/drivers/radeonsi/si_compute.c b/src/gallium/drivers/radeonsi/si_compute.c index f1afef2e66f..2f444a3a1b8 100644 --- a/src/gallium/drivers/radeonsi/si_compute.c +++ b/src/gallium/drivers/radeonsi/si_compute.c @@ -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 */ diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c b/src/gallium/drivers/radeonsi/si_descriptors.c index ac40ed27f91..f795c33cf26 100644 --- a/src/gallium/drivers/radeonsi/si_descriptors.c +++ b/src/gallium/drivers/radeonsi/si_descriptors.c @@ -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, diff --git a/src/gallium/drivers/radeonsi/si_gfx_cs.c b/src/gallium/drivers/radeonsi/si_gfx_cs.c index 39184e0e9da..3e369234597 100644 --- a/src/gallium/drivers/radeonsi/si_gfx_cs.c +++ b/src/gallium/drivers/radeonsi/si_gfx_cs.c @@ -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; diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h index 26b12a8a674..5d43a594759 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.h +++ b/src/gallium/drivers/radeonsi/si_pipe.h @@ -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 */ diff --git a/src/gallium/drivers/radeonsi/si_state.h b/src/gallium/drivers/radeonsi/si_state.h index 311e1a428ae..b0802416c73 100644 --- a/src/gallium/drivers/radeonsi/si_state.h +++ b/src/gallium/drivers/radeonsi/si_state.h @@ -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); diff --git a/src/gallium/drivers/radeonsi/si_state_draw.c b/src/gallium/drivers/radeonsi/si_state_draw.c index 1cadc416ca3..c220eaf24f8 100644 --- a/src/gallium/drivers/radeonsi/si_state_draw.c +++ b/src/gallium/drivers/radeonsi/si_state_draw.c @@ -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 -- cgit v1.2.3