mesa/st: create new surfaces before destroying old ones when updating attachments
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 31 Aug 2021 18:37:31 +0000 (14:37 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 1 Sep 2021 15:43:48 +0000 (15:43 +0000)
try to avoid patterns that would destroy surfaces for drivers that cache them for
deduplication purposes

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12651>

src/mesa/state_tracker/st_cb_fbo.c

index 43f1c3f..5ffc234 100644 (file)
@@ -466,9 +466,11 @@ st_regen_renderbuffer_surface(struct st_context *st,
    surf_tmpl.u.tex.first_layer = surf->u.tex.first_layer;
    surf_tmpl.u.tex.last_layer = surf->u.tex.last_layer;
 
+   /* create -> destroy to avoid blowing up cached surfaces */
+   surf = pipe->create_surface(pipe, resource, &surf_tmpl);
    pipe_surface_release(pipe, psurf);
+   *psurf = surf;
 
-   *psurf = pipe->create_surface(pipe, resource, &surf_tmpl);
    strb->surface = *psurf;
 }
 
@@ -569,9 +571,10 @@ st_update_renderbuffer_surface(struct st_context *st,
       surf_tmpl.u.tex.first_layer = first_layer;
       surf_tmpl.u.tex.last_layer = last_layer;
 
+      /* create -> destroy to avoid blowing up cached surfaces */
+      struct pipe_surface *surf = pipe->create_surface(pipe, resource, &surf_tmpl);
       pipe_surface_release(pipe, psurf);
-
-      *psurf = pipe->create_surface(pipe, resource, &surf_tmpl);
+      *psurf = surf;
    }
    strb->surface = *psurf;
 }