r300: stop using u_resource_vtbl::resource_destroy
authorMarek Olšák <marek.olsak@amd.com>
Wed, 5 May 2021 17:27:53 +0000 (13:27 -0400)
committerMarge Bot <eric+marge@anholt.net>
Fri, 21 May 2021 17:38:04 +0000 (17:38 +0000)
Acked-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10659>

src/gallium/drivers/r300/r300_resource.c
src/gallium/drivers/r300/r300_screen_buffer.c
src/gallium/drivers/r300/r300_screen_buffer.h
src/gallium/drivers/r300/r300_texture.c

index 3da5fef..b34a9b1 100644 (file)
@@ -54,5 +54,5 @@ void r300_init_screen_resource_functions(struct r300_screen *r300screen)
    r300screen->screen.resource_create = r300_resource_create;
    r300screen->screen.resource_from_handle = r300_texture_from_handle;
    r300screen->screen.resource_get_handle = r300_resource_get_handle;
-   r300screen->screen.resource_destroy = u_resource_destroy_vtbl;
+   r300screen->screen.resource_destroy = r300_resource_destroy;
 }
index 079e55d..7f6c15a 100644 (file)
@@ -50,17 +50,32 @@ void r300_upload_index_buffer(struct r300_context *r300,
     *start = index_offset / index_size;
 }
 
-static void r300_buffer_destroy(struct pipe_screen *screen,
-                               struct pipe_resource *buf)
+void r300_resource_destroy(struct pipe_screen *screen,
+                           struct pipe_resource *buf)
 {
-    struct r300_resource *rbuf = r300_resource(buf);
-
-    align_free(rbuf->malloced_buffer);
-
-    if (rbuf->buf)
-        pb_reference(&rbuf->buf, NULL);
-
-    FREE(rbuf);
+   if (buf->target == PIPE_BUFFER) {
+      struct r300_resource *rbuf = r300_resource(buf);
+
+      align_free(rbuf->malloced_buffer);
+
+      if (rbuf->buf)
+         pb_reference(&rbuf->buf, NULL);
+
+      FREE(rbuf);
+   } else {
+      struct r300_screen *rscreen = r300_screen(screen);
+      struct r300_resource* tex = (struct r300_resource*)buf;
+
+      if (tex->tex.cmask_dwords) {
+          mtx_lock(&rscreen->cmask_mutex);
+          if (buf == rscreen->cmask_resource) {
+              rscreen->cmask_resource = NULL;
+          }
+          mtx_unlock(&rscreen->cmask_mutex);
+      }
+      pb_reference(&tex->buf, NULL);
+      FREE(tex);
+   }
 }
 
 static void *
@@ -148,7 +163,7 @@ static void r300_buffer_transfer_unmap( struct pipe_context *pipe,
 
 static const struct u_resource_vtbl r300_buffer_vtbl =
 {
-   r300_buffer_destroy,                /* resource_destroy */
+   NULL,                               /* resource_destroy */
    r300_buffer_transfer_map,           /* transfer_map */
    r300_buffer_transfer_unmap,         /* transfer_unmap */
 };
index 14b849c..bd025df 100644 (file)
@@ -41,6 +41,9 @@ void r300_upload_index_buffer(struct r300_context *r300,
                              unsigned index_size, unsigned *start,
                              unsigned count, const uint8_t *ptr);
 
+void r300_resource_destroy(struct pipe_screen *screen,
+                           struct pipe_resource *buf);
+
 struct pipe_resource *r300_buffer_create(struct pipe_screen *screen,
                                         const struct pipe_resource *templ);
 
index 5d86be4..626856c 100644 (file)
@@ -1021,23 +1021,6 @@ static void r300_texture_setup_fb_state(struct r300_surface *surf)
     }
 }
 
-static void r300_texture_destroy(struct pipe_screen *screen,
-                                 struct pipe_resource* texture)
-{
-    struct r300_screen *rscreen = r300_screen(screen);
-    struct r300_resource* tex = (struct r300_resource*)texture;
-
-    if (tex->tex.cmask_dwords) {
-        mtx_lock(&rscreen->cmask_mutex);
-        if (texture == rscreen->cmask_resource) {
-            rscreen->cmask_resource = NULL;
-        }
-        mtx_unlock(&rscreen->cmask_mutex);
-    }
-    pb_reference(&tex->buf, NULL);
-    FREE(tex);
-}
-
 bool r300_resource_get_handle(struct pipe_screen* screen,
                               struct pipe_context *ctx,
                               struct pipe_resource *texture,
@@ -1059,7 +1042,7 @@ bool r300_resource_get_handle(struct pipe_screen* screen,
 
 static const struct u_resource_vtbl r300_texture_vtbl =
 {
-    r300_texture_destroy,           /* resource_destroy */
+    NULL,                           /* resource_destroy */
     r300_texture_transfer_map,      /* transfer_map */
     r300_texture_transfer_unmap,    /* transfer_unmap */
 };