radeonsi: lock a mutex when updating scratch_va for compute shaders
Fixes: 3b0bfd254f
- radeonsi/gfx11: make flat_scratch changes for compute
Reviewed-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30071>
This commit is contained in:
@@ -218,6 +218,7 @@ static void *si_create_compute_state(struct pipe_context *ctx, const struct pipe
|
|||||||
pipe_reference_init(&sel->base.reference, 1);
|
pipe_reference_init(&sel->base.reference, 1);
|
||||||
sel->stage = MESA_SHADER_COMPUTE;
|
sel->stage = MESA_SHADER_COMPUTE;
|
||||||
sel->screen = sscreen;
|
sel->screen = sscreen;
|
||||||
|
simple_mtx_init(&sel->mutex, mtx_plain);
|
||||||
sel->const_and_shader_buf_descriptors_index =
|
sel->const_and_shader_buf_descriptors_index =
|
||||||
si_const_and_shader_buffer_descriptors_idx(PIPE_SHADER_COMPUTE);
|
si_const_and_shader_buffer_descriptors_idx(PIPE_SHADER_COMPUTE);
|
||||||
sel->sampler_and_images_descriptors_index =
|
sel->sampler_and_images_descriptors_index =
|
||||||
@@ -480,6 +481,16 @@ static bool si_switch_compute_shader(struct si_context *sctx, struct si_compute
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config->scratch_bytes_per_wave) {
|
if (config->scratch_bytes_per_wave) {
|
||||||
|
/* Prevent race conditions for accesses to shader->scratch_va and shader->bo, which
|
||||||
|
* can change when scratch_va is updated. Any accesses to shader->bo must also be inside
|
||||||
|
* the lock.
|
||||||
|
*
|
||||||
|
* TODO: This lock could be removed if the scratch address was passed via user SGPRs instead
|
||||||
|
* of the shader binary.
|
||||||
|
*/
|
||||||
|
if (!sctx->screen->info.has_scratch_base_registers)
|
||||||
|
simple_mtx_lock(&shader->selector->mutex);
|
||||||
|
|
||||||
/* Update max_seen_compute_scratch_bytes_per_wave and compute_tmpring_size. */
|
/* Update max_seen_compute_scratch_bytes_per_wave and compute_tmpring_size. */
|
||||||
ac_get_scratch_tmpring_size(&sctx->screen->info,
|
ac_get_scratch_tmpring_size(&sctx->screen->info,
|
||||||
config->scratch_bytes_per_wave,
|
config->scratch_bytes_per_wave,
|
||||||
@@ -503,6 +514,12 @@ static bool si_switch_compute_shader(struct si_context *sctx, struct si_compute
|
|||||||
radeon_add_to_buffer_list(sctx, &sctx->gfx_cs, shader->bo,
|
radeon_add_to_buffer_list(sctx, &sctx->gfx_cs, shader->bo,
|
||||||
RADEON_USAGE_READ | RADEON_PRIO_SHADER_BINARY);
|
RADEON_USAGE_READ | RADEON_PRIO_SHADER_BINARY);
|
||||||
|
|
||||||
|
/* shader->bo can't be used after this if the scratch address is inserted into the shader
|
||||||
|
* binary.
|
||||||
|
*/
|
||||||
|
if (config->scratch_bytes_per_wave && !sctx->screen->info.has_scratch_base_registers)
|
||||||
|
simple_mtx_unlock(&shader->selector->mutex);
|
||||||
|
|
||||||
if (sctx->gfx_level >= GFX12) {
|
if (sctx->gfx_level >= GFX12) {
|
||||||
unsigned rsrc3 = S_00B8A0_INST_PREF_SIZE_GFX12(si_get_shader_prefetch_size(shader));
|
unsigned rsrc3 = S_00B8A0_INST_PREF_SIZE_GFX12(si_get_shader_prefetch_size(shader));
|
||||||
|
|
||||||
@@ -1307,6 +1324,7 @@ void si_destroy_compute(struct si_compute *program)
|
|||||||
|
|
||||||
si_shader_destroy(&program->shader);
|
si_shader_destroy(&program->shader);
|
||||||
ralloc_free(program->sel.nir);
|
ralloc_free(program->sel.nir);
|
||||||
|
simple_mtx_destroy(&sel->mutex);
|
||||||
FREE(program);
|
FREE(program);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user