mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-04 11:58:10 +02:00
radeonsi: move si_compute::global_buffers to si_context
si_set_global_binding is a context function, but it touches the bound compute program. As radeonsi also advertizes PIPE_CAP_SHAREABLE_SHADERS this function is supposed to be safe when the same compute state object is bound to multiple contexts at once. In order to fix this data race global_buffers is moved to si_context so it becomes context private data instead. Cc: mesa-stable Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31672>
This commit is contained in:
parent
fad599a619
commit
1798597637
3 changed files with 21 additions and 20 deletions
|
|
@ -351,25 +351,24 @@ static void si_set_global_binding(struct pipe_context *ctx, unsigned first, unsi
|
|||
{
|
||||
unsigned i;
|
||||
struct si_context *sctx = (struct si_context *)ctx;
|
||||
struct si_compute *program = sctx->cs_shader_state.program;
|
||||
|
||||
if (first + n > program->max_global_buffers) {
|
||||
unsigned old_max = program->max_global_buffers;
|
||||
program->max_global_buffers = first + n;
|
||||
program->global_buffers = realloc(
|
||||
program->global_buffers, program->max_global_buffers * sizeof(program->global_buffers[0]));
|
||||
if (!program->global_buffers) {
|
||||
if (first + n > sctx->max_global_buffers) {
|
||||
unsigned old_max = sctx->max_global_buffers;
|
||||
sctx->max_global_buffers = first + n;
|
||||
sctx->global_buffers = realloc(
|
||||
sctx->global_buffers, sctx->max_global_buffers * sizeof(sctx->global_buffers[0]));
|
||||
if (!sctx->global_buffers) {
|
||||
fprintf(stderr, "radeonsi: failed to allocate compute global_buffers\n");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&program->global_buffers[old_max], 0,
|
||||
(program->max_global_buffers - old_max) * sizeof(program->global_buffers[0]));
|
||||
memset(&sctx->global_buffers[old_max], 0,
|
||||
(sctx->max_global_buffers - old_max) * sizeof(sctx->global_buffers[0]));
|
||||
}
|
||||
|
||||
if (!resources) {
|
||||
for (i = 0; i < n; i++) {
|
||||
pipe_resource_reference(&program->global_buffers[first + i], NULL);
|
||||
pipe_resource_reference(&sctx->global_buffers[first + i], NULL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -377,7 +376,7 @@ static void si_set_global_binding(struct pipe_context *ctx, unsigned first, unsi
|
|||
for (i = 0; i < n; i++) {
|
||||
uint64_t va;
|
||||
uint32_t offset;
|
||||
pipe_resource_reference(&program->global_buffers[first + i], resources[i]);
|
||||
pipe_resource_reference(&sctx->global_buffers[first + i], resources[i]);
|
||||
va = si_resource(resources[i])->gpu_address;
|
||||
offset = util_le32_to_cpu(*handles[i]);
|
||||
va += offset;
|
||||
|
|
@ -1257,8 +1256,8 @@ static void si_launch_grid(struct pipe_context *ctx, const struct pipe_grid_info
|
|||
return;
|
||||
|
||||
/* Global buffers */
|
||||
for (i = 0; i < program->max_global_buffers; i++) {
|
||||
struct si_resource *buffer = si_resource(program->global_buffers[i]);
|
||||
for (i = 0; i < sctx->max_global_buffers; i++) {
|
||||
struct si_resource *buffer = si_resource(sctx->global_buffers[i]);
|
||||
if (!buffer) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -1323,10 +1322,6 @@ void si_destroy_compute(struct si_compute *program)
|
|||
util_queue_fence_destroy(&sel->ready);
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < program->max_global_buffers; i++)
|
||||
pipe_resource_reference(&program->global_buffers[i], NULL);
|
||||
FREE(program->global_buffers);
|
||||
|
||||
si_shader_destroy(&program->shader);
|
||||
ralloc_free(program->sel.nir);
|
||||
simple_mtx_destroy(&sel->mutex);
|
||||
|
|
|
|||
|
|
@ -279,6 +279,11 @@ static void si_destroy_context(struct pipe_context *context)
|
|||
if (sctx->no_velems_state)
|
||||
sctx->b.delete_vertex_elements_state(&sctx->b, sctx->no_velems_state);
|
||||
|
||||
if (sctx->global_buffers) {
|
||||
sctx->b.set_global_binding(&sctx->b, 0, sctx->max_global_buffers, NULL, NULL);
|
||||
FREE(sctx->global_buffers);
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < ARRAY_SIZE(sctx->cs_fmask_expand); i++) {
|
||||
for (unsigned j = 0; j < ARRAY_SIZE(sctx->cs_fmask_expand[i]); j++) {
|
||||
if (sctx->cs_fmask_expand[i][j]) {
|
||||
|
|
|
|||
|
|
@ -671,9 +671,6 @@ struct si_compute {
|
|||
|
||||
unsigned ir_type;
|
||||
unsigned input_size;
|
||||
|
||||
int max_global_buffers;
|
||||
struct pipe_resource **global_buffers;
|
||||
};
|
||||
|
||||
struct si_sampler_view {
|
||||
|
|
@ -1109,6 +1106,10 @@ struct si_context {
|
|||
bool bo_list_add_all_resident_resources;
|
||||
bool bo_list_add_all_compute_resources;
|
||||
|
||||
/* tracked buffers for OpenCL */
|
||||
int max_global_buffers;
|
||||
struct pipe_resource **global_buffers;
|
||||
|
||||
/* other shader resources */
|
||||
struct pipe_constant_buffer null_const_buf; /* used for set_constant_buffer(NULL) on GFX7 */
|
||||
struct pipe_resource *esgs_ring;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue