gallium: add a destructor param to surface refcounting functions

these functions should no longer be used by serious drivers. for those that
do use them, they now need to pass their own destructor function

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40462>
This commit is contained in:
Mike Blumenkrantz 2026-03-16 12:25:23 -04:00 committed by Marge Bot
parent 639c356894
commit 0615a276ca
7 changed files with 43 additions and 35 deletions

View file

@ -135,8 +135,12 @@ pipe_reference(struct pipe_reference *dst, struct pipe_reference *src)
debug_describe_reference);
}
/* TODO: delete surface refcounting functions */
typedef void (*pipe_surface_destroy_func)(struct pipe_context*, struct pipe_surface*);
static inline void
pipe_surface_reference(struct pipe_surface **dst, struct pipe_surface *src)
pipe_surface_reference(struct pipe_surface **dst, struct pipe_surface *src,
pipe_surface_destroy_func surface_destroy)
{
struct pipe_surface *old_dst = *dst;
@ -144,7 +148,7 @@ pipe_surface_reference(struct pipe_surface **dst, struct pipe_surface *src)
src ? &src->reference : NULL,
(debug_reference_descriptor)
debug_describe_surface))
old_dst->context->surface_destroy(old_dst->context, old_dst);
surface_destroy(old_dst->context, old_dst);
*dst = src;
}
@ -155,7 +159,8 @@ pipe_surface_reference(struct pipe_surface **dst, struct pipe_surface *src)
* that's shared by multiple contexts.
*/
static inline void
pipe_surface_unref(struct pipe_context *pipe, struct pipe_surface **ptr)
pipe_surface_unref(struct pipe_context *pipe, struct pipe_surface **ptr,
pipe_surface_destroy_func surface_destroy)
{
struct pipe_surface *old = *ptr;
@ -163,7 +168,7 @@ pipe_surface_unref(struct pipe_context *pipe, struct pipe_surface **ptr)
NULL,
(debug_reference_descriptor)
debug_describe_surface))
pipe->surface_destroy(pipe, old);
surface_destroy(pipe, old);
*ptr = NULL;
}

View file

@ -139,7 +139,7 @@ static void
delete_surface(set_entry *entry)
{
struct pipe_surface *surf = (struct pipe_surface *)entry->key;
pipe_surface_reference(&surf, NULL);
pipe_surface_reference(&surf, NULL, (pipe_surface_destroy_func)d3d12_surface_destroy);
}
static void

View file

@ -528,7 +528,7 @@ void r300_decompress_zmask_locked(struct r300_context *r300)
r300->context.set_framebuffer_state(&r300->context, &saved_fb);
util_unreference_framebuffer_state(&saved_fb);
pipe_surface_reference(&r300->locked_zbuffer, NULL);
pipe_surface_reference(&r300->locked_zbuffer, NULL, r300_surface_destroy);
}
bool r300_is_blit_supported(enum pipe_format format)
@ -691,7 +691,7 @@ static void r300_resource_copy_region(struct pipe_context *pipe,
false, false, 0, NULL);
r300_blitter_end(r300);
pipe_surface_reference(&dst_view, NULL);
pipe_surface_reference(&dst_view, NULL, r300_surface_destroy);
pipe_sampler_view_reference(&src_view, NULL);
}

View file

@ -17,6 +17,7 @@
#include "r300_emit.h"
#include "r300_screen.h"
#include "r300_screen_buffer.h"
#include "r300_texture.h"
#include "compiler/radeon_regalloc.h"
#include <inttypes.h>
@ -47,7 +48,7 @@ static void r300_release_referenced_objects(struct r300_context *r300)
/* Manually-created vertex buffers. */
pipe_vertex_buffer_unreference(&r300->dummy_vb);
pipe_surface_reference(&r300->locked_zbuffer, NULL);
pipe_surface_reference(&r300->locked_zbuffer, NULL, r300_surface_destroy);
radeon_bo_reference(r300->rws, &r300->vbo, NULL);
r300->context.delete_depth_stencil_alpha_state(&r300->context,

View file

@ -1016,13 +1016,13 @@ r300_framebuffer_init(struct pipe_context *pctx, const struct pipe_framebuffer_s
struct pipe_surface *psurf = fb->cbufs[i].texture ? r300_create_surface(pctx, fb->cbufs[i].texture, &fb->cbufs[i]) : NULL;
if (cbufs[i])
pipe_surface_unref(pctx, &cbufs[i]);
pipe_surface_unref(pctx, &cbufs[i], r300_surface_destroy);
cbufs[i] = psurf;
}
for (unsigned i = fb->nr_cbufs; i < PIPE_MAX_COLOR_BUFS; i++) {
if (cbufs[i])
pipe_surface_unref(pctx, &cbufs[i]);
pipe_surface_unref(pctx, &cbufs[i], r300_surface_destroy);
cbufs[i] = NULL;
}
@ -1030,16 +1030,16 @@ r300_framebuffer_init(struct pipe_context *pctx, const struct pipe_framebuffer_s
return;
struct pipe_surface *zsurf = fb->zsbuf.texture ? r300_create_surface(pctx, fb->zsbuf.texture, &fb->zsbuf) : NULL;
if (*zsbuf)
pipe_surface_unref(pctx, zsbuf);
pipe_surface_unref(pctx, zsbuf, r300_surface_destroy);
*zsbuf = zsurf;
} else {
for (unsigned i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
if (cbufs[i])
pipe_surface_unref(pctx, &cbufs[i]);
pipe_surface_unref(pctx, &cbufs[i], r300_surface_destroy);
cbufs[i] = NULL;
}
if (*zsbuf)
pipe_surface_unref(pctx, zsbuf);
pipe_surface_unref(pctx, zsbuf, r300_surface_destroy);
*zsbuf = NULL;
}
}
@ -1079,7 +1079,7 @@ r300_set_framebuffer_state(struct pipe_context* pipe,
}
} else {
/* We don't bind another zbuffer, so lock the current one. */
pipe_surface_reference(&r300->locked_zbuffer, r300->fb_zsbuf);
pipe_surface_reference(&r300->locked_zbuffer, r300->fb_zsbuf, r300_surface_destroy);
}
} else if (r300->locked_zbuffer) {
/* We have a locked zbuffer now, what are we gonna do? */
@ -1146,7 +1146,7 @@ r300_set_framebuffer_state(struct pipe_context* pipe,
r300_set_blend_color(pipe, &((struct r300_blend_color_state*)r300->blend_color_state.state)->state);
if (unlock_zbuffer) {
pipe_surface_reference(&r300->locked_zbuffer, NULL);
pipe_surface_reference(&r300->locked_zbuffer, NULL, r300_surface_destroy);
}
r300_mark_fb_state_dirty(r300, R300_CHANGED_FB_STATE);

View file

@ -243,14 +243,14 @@ emit_fb_vgpu10(struct svga_context *svga)
} else if (svga_surface(svga->state.hw_clear.rtv[i]) != hwfb->cbufs[i] &&
svga->state.hw_clear.rtv[i]) {
/* Free the alternate surface view when it is unbound. */
pipe_surface_unref(&svga->pipe, &svga->state.hw_clear.rtv[i]);
pipe_surface_unref(&svga->pipe, &svga->state.hw_clear.rtv[i], svga_surface_destroy);
}
svga_surface_reference(&hwfb->cbufs[i], currfb->cbufs[i]);
}
}
svga->state.hw_clear.num_rendertargets = last_rtv + 1;
for (unsigned i = 0; i < num_color; i++) {
pipe_surface_reference(&svga->state.hw_clear.rtv[i], rtv[i]);
pipe_surface_reference(&svga->state.hw_clear.rtv[i], rtv[i], svga_surface_destroy);
}
hwfb->base.nr_cbufs = currfb->base.nr_cbufs;
@ -261,11 +261,11 @@ emit_fb_vgpu10(struct svga_context *svga)
} else if (svga_surface(svga->state.hw_clear.dsv) != hwfb->zsbuf &&
svga->state.hw_clear.dsv) {
/* Free the alternate surface view when it is unbound. */
pipe_surface_unref(&svga->pipe, &svga->state.hw_clear.dsv);
pipe_surface_unref(&svga->pipe, &svga->state.hw_clear.dsv, svga_surface_destroy);
}
svga_surface_reference(&hwfb->zsbuf, currfb->zsbuf);
}
pipe_surface_reference(&svga->state.hw_clear.dsv, dsv);
pipe_surface_reference(&svga->state.hw_clear.dsv, dsv, svga_surface_destroy);
}
return PIPE_OK;

View file

@ -60,22 +60,6 @@ struct svga_surface
};
static inline void
svga_surface_reference(struct svga_surface **dst,
struct svga_surface *src)
{
pipe_surface_reference((struct pipe_surface **) dst,
(struct pipe_surface *) src);
}
static inline void
svga_surface_unref(struct pipe_context *pipe,
struct svga_surface **s)
{
pipe_surface_unref(pipe, (struct pipe_surface **) s);
}
static inline bool
svga_surface_equal(const struct svga_surface *s1, const struct svga_surface *s2)
@ -185,4 +169,22 @@ svga_resource_type(enum pipe_texture_target target)
}
}
static inline void
svga_surface_reference(struct svga_surface **dst,
struct svga_surface *src)
{
pipe_surface_reference((struct pipe_surface **) dst,
(struct pipe_surface *) src,
svga_surface_destroy);
}
static inline void
svga_surface_unref(struct pipe_context *pipe,
struct svga_surface **s)
{
pipe_surface_unref(pipe, (struct pipe_surface **) s, svga_surface_destroy);
}
#endif