Mesa (main): radeonsi: stop using u_resource_vtbl::resource_destroy
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri May 21 18:27:24 UTC 2021
Module: Mesa
Branch: main
Commit: b04044b3509c67f14fe482593eede12ae66abb54
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b04044b3509c67f14fe482593eede12ae66abb54
Author: Marek Olšák <marek.olsak at amd.com>
Date: Wed May 5 13:11:27 2021 -0400
radeonsi: stop using u_resource_vtbl::resource_destroy
Acked-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10659>
---
src/gallium/drivers/radeonsi/si_buffer.c | 34 ++++++++++++++++------
src/gallium/drivers/radeonsi/si_pipe.h | 19 +++++++++++++
src/gallium/drivers/radeonsi/si_texture.c | 47 ++-----------------------------
3 files changed, 48 insertions(+), 52 deletions(-)
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);
+ } 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);
- threaded_resource_deinit(buf);
- util_range_destroy(&buffer->valid_buffer_range);
- radeon_bo_reference(((struct si_screen*)screen)->ws, &buffer->buf, NULL);
- FREE(buffer);
+ 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 */
};
More information about the mesa-commit
mailing list