diff --git a/src/gallium/drivers/radeonsi/si_buffer.c b/src/gallium/drivers/radeonsi/si_buffer.c index d64debe10b1..b351353a4e9 100644 --- a/src/gallium/drivers/radeonsi/si_buffer.c +++ b/src/gallium/drivers/radeonsi/si_buffer.c @@ -218,14 +218,32 @@ bool si_alloc_resource(struct si_screen *sscreen, struct si_resource *res) return true; } -static void si_buffer_destroy(struct pipe_screen *screen, struct pipe_resource *buf) +static void si_resource_destroy(struct pipe_screen *screen, struct pipe_resource *buf) { - struct si_resource *buffer = si_resource(buf); + if (buf->target == PIPE_BUFFER) { + struct si_resource *buffer = si_resource(buf); - threaded_resource_deinit(buf); - util_range_destroy(&buffer->valid_buffer_range); - radeon_bo_reference(((struct si_screen*)screen)->ws, &buffer->buf, NULL); - FREE(buffer); + threaded_resource_deinit(buf); + util_range_destroy(&buffer->valid_buffer_range); + radeon_bo_reference(((struct si_screen*)screen)->ws, &buffer->buf, NULL); + FREE(buffer); + } else if (buf->flags & SI_RESOURCE_AUX_PLANE) { + struct si_auxiliary_texture *tex = (struct si_auxiliary_texture *)buf; + + radeon_bo_reference(((struct si_screen*)screen)->ws, &tex->buffer, NULL); + FREE(tex); + } else { + struct si_texture *tex = (struct si_texture *)buf; + struct si_resource *resource = &tex->buffer; + + si_texture_reference(&tex->flushed_depth_texture, NULL); + + if (tex->cmask_buffer != &tex->buffer) { + si_resource_reference(&tex->cmask_buffer, NULL); + } + radeon_bo_reference(((struct si_screen*)screen)->ws, &resource->buf, NULL); + FREE(tex); + } } /* Reallocate the buffer a update all resource bindings where the buffer is @@ -551,7 +569,7 @@ static void si_buffer_subdata(struct pipe_context *ctx, struct pipe_resource *bu } static const struct u_resource_vtbl si_buffer_vtbl = { - si_buffer_destroy, /* resource_destroy */ + NULL, /* resource_destroy */ si_buffer_transfer_map, /* transfer_map */ si_buffer_transfer_unmap, /* transfer_unmap */ }; @@ -721,7 +739,7 @@ static bool si_resource_commit(struct pipe_context *pctx, struct pipe_resource * void si_init_screen_buffer_functions(struct si_screen *sscreen) { sscreen->b.resource_create = si_resource_create; - sscreen->b.resource_destroy = u_resource_destroy_vtbl; + sscreen->b.resource_destroy = si_resource_destroy; sscreen->b.resource_from_user_memory = si_buffer_from_user_memory; } diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h index 398b88fec60..09bcf4d3982 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.h +++ b/src/gallium/drivers/radeonsi/si_pipe.h @@ -137,6 +137,7 @@ extern "C" { (((x) >> SI_RESOURCE_FLAG_MICRO_TILE_MODE_SHIFT) & 0x3) #define SI_RESOURCE_FLAG_UNCACHED (PIPE_RESOURCE_FLAG_DRV_PRIV << 12) #define SI_RESOURCE_FLAG_DRIVER_INTERNAL (PIPE_RESOURCE_FLAG_DRV_PRIV << 13) +#define SI_RESOURCE_AUX_PLANE (PIPE_RESOURCE_FLAG_DRV_PRIV << 14) enum si_has_gs { GS_OFF, @@ -394,6 +395,24 @@ struct si_texture { unsigned framebuffers_bound; }; +/* State trackers create separate textures in a next-chain for extra planes + * even if those are planes created purely for modifiers. Because the linking + * of the chain happens outside of the driver, and NULL is interpreted as + * failure, let's create some dummy texture structs. We could use these + * later to use the offsets for linking if we really wanted to. + * + * For now just create a dummy struct and completely ignore it. + * + * Potentially in the future we could store stride/offset and use it during + * creation, though we might want to change how linking is done first. + */ +struct si_auxiliary_texture { + struct threaded_resource b; + struct pb_buffer *buffer; + uint32_t offset; + uint32_t stride; +}; + struct si_surface { struct pipe_surface base; diff --git a/src/gallium/drivers/radeonsi/si_texture.c b/src/gallium/drivers/radeonsi/si_texture.c index 3a6b9caf64c..696cbbc11ff 100644 --- a/src/gallium/drivers/radeonsi/si_texture.c +++ b/src/gallium/drivers/radeonsi/si_texture.c @@ -784,20 +784,6 @@ static bool si_texture_get_handle(struct pipe_screen *screen, struct pipe_contex return sscreen->ws->buffer_get_handle(sscreen->ws, res->buf, whandle); } -static void si_texture_destroy(struct pipe_screen *screen, struct pipe_resource *ptex) -{ - struct si_texture *tex = (struct si_texture *)ptex; - struct si_resource *resource = &tex->buffer; - - si_texture_reference(&tex->flushed_depth_texture, NULL); - - if (tex->cmask_buffer != &tex->buffer) { - si_resource_reference(&tex->cmask_buffer, NULL); - } - radeon_bo_reference(((struct si_screen*)screen)->ws, &resource->buf, NULL); - FREE(tex); -} - static const struct u_resource_vtbl si_texture_vtbl; void si_print_texture_info(struct si_screen *sscreen, struct si_texture *tex, @@ -1445,36 +1431,8 @@ si_texture_create_with_modifiers(struct pipe_screen *screen, return si_texture_create_with_modifier(screen, templ, modifier); } -/* State trackers create separate textures in a next-chain for extra planes - * even if those are planes created purely for modifiers. Because the linking - * of the chain happens outside of the driver, and NULL is interpreted as - * failure, let's create some dummy texture structs. We could use these - * later to use the offsets for linking if we really wanted to. - * - * For now just create a dummy struct and completely ignore it. - * - * Potentially in the future we could store stride/offset and use it during - * creation, though we might want to change how linking is done first. - */ - -struct si_auxiliary_texture { - struct threaded_resource b; - struct pb_buffer *buffer; - uint32_t offset; - uint32_t stride; -}; - -static void si_auxiliary_texture_destroy(struct pipe_screen *screen, - struct pipe_resource *ptex) -{ - struct si_auxiliary_texture *tex = (struct si_auxiliary_texture *)ptex; - - radeon_bo_reference(((struct si_screen*)screen)->ws, &tex->buffer, NULL); - FREE(ptex); -} - static const struct u_resource_vtbl si_auxiliary_texture_vtbl = { - si_auxiliary_texture_destroy, /* resource_destroy */ + NULL, /* resource_destroy */ NULL, /* transfer_map */ NULL, /* transfer_unmap */ }; @@ -1625,6 +1583,7 @@ static struct pipe_resource *si_texture_from_handle(struct pipe_screen *screen, if (!tex) return NULL; tex->b.b = *templ; + tex->b.b.flags |= SI_RESOURCE_AUX_PLANE; tex->b.vtbl = &si_auxiliary_texture_vtbl; tex->stride = whandle->stride; tex->offset = whandle->offset; @@ -1960,7 +1919,7 @@ static void si_texture_transfer_unmap(struct pipe_context *ctx, struct pipe_tran } static const struct u_resource_vtbl si_texture_vtbl = { - si_texture_destroy, /* resource_destroy */ + NULL, /* resource_destroy */ si_texture_transfer_map, /* transfer_map */ si_texture_transfer_unmap, /* transfer_unmap */ };