radeonsi: delay adding BOs at the beginning of IBs until the first draw

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>
This commit is contained in:
Marek Olšák 2019-02-27 21:13:15 -05:00
parent 09bb8c8557
commit 951d60f8cd
6 changed files with 46 additions and 9 deletions

View 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 */

View 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,

View 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;

View 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 */

View 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);

View 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