radeonsi: move buffer reallocation to a separate function

to be used later

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33482>
This commit is contained in:
Marek Olšák 2025-01-07 20:59:35 -05:00 committed by Marge Bot
parent 0f9c972453
commit 356f5b2d2e
3 changed files with 28 additions and 13 deletions

View file

@ -279,7 +279,9 @@ void si_replace_buffer_storage(struct pipe_context *ctx, struct pipe_resource *d
radeon_bo_reference(sctx->screen->ws, &sdst->buf, ssrc->buf);
sdst->gpu_address = ssrc->gpu_address;
sdst->b.b.usage = ssrc->b.b.usage;
sdst->b.b.bind = ssrc->b.b.bind;
sdst->domains = ssrc->domains;
sdst->flags = ssrc->flags;
assert(sdst->bo_size == ssrc->bo_size);
@ -291,6 +293,28 @@ void si_replace_buffer_storage(struct pipe_context *ctx, struct pipe_resource *d
util_idalloc_mt_free(&sctx->screen->buffer_ids, delete_buffer_id);
}
bool si_reallocate_buffer_change_flags(struct si_context *sctx, struct pipe_resource *buf,
unsigned usage, unsigned bind)
{
struct pipe_resource templ = *buf;
templ.usage = usage;
templ.bind = bind;
struct pipe_resource *new_buf = sctx->b.screen->resource_create(sctx->b.screen, &templ);
if (!new_buf)
return false;
/* Copy the old buffer contents to the new one. */
struct pipe_box box;
u_box_1d(0, new_buf->width0, &box);
sctx->b.resource_copy_region(&sctx->b, new_buf, 0, 0, 0, 0, buf, 0, &box);
/* Move the new buffer storage to the old pipe_resource. */
si_replace_buffer_storage(&sctx->b, buf, new_buf, 0, 0, 0);
pipe_resource_reference(&new_buf, NULL);
return true;
}
static void si_invalidate_resource(struct pipe_context *ctx, struct pipe_resource *resource)
{
struct si_context *sctx = (struct si_context *)ctx;

View file

@ -1440,6 +1440,8 @@ struct pipe_resource *si_buffer_from_winsys_buffer(struct pipe_screen *screen,
void si_replace_buffer_storage(struct pipe_context *ctx, struct pipe_resource *dst,
struct pipe_resource *src, unsigned num_rebinds,
uint32_t rebind_mask, uint32_t delete_buffer_id);
bool si_reallocate_buffer_change_flags(struct si_context *sctx, struct pipe_resource *buf,
unsigned usage, unsigned bind);
void si_init_screen_buffer_functions(struct si_screen *sscreen);
void si_init_buffer_functions(struct si_context *sctx);

View file

@ -874,25 +874,14 @@ static bool si_texture_get_handle(struct pipe_screen *screen, struct pipe_contex
assert(!res->b.is_shared);
/* Allocate a new buffer with PIPE_BIND_SHARED. */
struct pipe_resource templ = res->b.b;
templ.bind |= PIPE_BIND_SHARED;
struct pipe_resource *newb = screen->resource_create(screen, &templ);
if (!newb) {
if (!si_reallocate_buffer_change_flags(sctx, &res->b.b, res->b.b.usage,
res->b.b.bind | PIPE_BIND_SHARED)) {
if (!ctx)
si_put_aux_context_flush(&sscreen->aux_context.general);
return false;
}
/* Copy the old buffer contents to the new one. */
struct pipe_box box;
u_box_1d(0, newb->width0, &box);
sctx->b.resource_copy_region(&sctx->b, newb, 0, 0, 0, 0, &res->b.b, 0, &box);
flush = true;
/* Move the new buffer storage to the old pipe_resource. */
si_replace_buffer_storage(&sctx->b, &res->b.b, newb, 0, 0, 0);
pipe_resource_reference(&newb, NULL);
assert(res->b.b.bind & PIPE_BIND_SHARED);
assert(res->flags & RADEON_FLAG_NO_SUBALLOC);
}