From facb048cdbbe1acffb41cdfbebc9042c1d539cd4 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Fri, 27 Jun 2025 17:41:24 +0200 Subject: [PATCH] nouveau: move util_framebuffer_init into the driver It will get cleaned up later. Maybe. Also stop setting the context or the reference. It's all dead code now. Part-of: --- src/gallium/drivers/nouveau/nouveau_context.h | 45 +++++++++++++++++++ .../drivers/nouveau/nv30/nv30_context.c | 2 +- .../drivers/nouveau/nv30/nv30_context.h | 3 +- .../drivers/nouveau/nv30/nv30_miptree.c | 21 ++++++--- .../drivers/nouveau/nv30/nv30_resource.c | 2 - .../drivers/nouveau/nv30/nv30_resource.h | 9 ++-- src/gallium/drivers/nouveau/nv30/nv30_state.c | 2 +- .../drivers/nouveau/nv50/nv50_context.h | 3 +- .../drivers/nouveau/nv50/nv50_miptree.c | 1 - .../drivers/nouveau/nv50/nv50_resource.c | 21 +++++---- .../drivers/nouveau/nv50/nv50_resource.h | 6 +++ .../drivers/nouveau/nv50/nv50_surface.c | 2 +- .../drivers/nouveau/nvc0/nvc0_context.c | 2 +- .../drivers/nouveau/nvc0/nvc0_context.h | 3 +- .../drivers/nouveau/nvc0/nvc0_miptree.c | 1 - .../drivers/nouveau/nvc0/nvc0_resource.c | 16 ++++--- .../drivers/nouveau/nvc0/nvc0_resource.h | 6 +++ src/gallium/drivers/nouveau/nvc0/nvc0_state.c | 2 +- .../drivers/nouveau/nvc0/nvc0_surface.c | 2 +- 19 files changed, 108 insertions(+), 41 deletions(-) diff --git a/src/gallium/drivers/nouveau/nouveau_context.h b/src/gallium/drivers/nouveau/nouveau_context.h index 7e7851c397f..5d6ab8bb54e 100644 --- a/src/gallium/drivers/nouveau/nouveau_context.h +++ b/src/gallium/drivers/nouveau/nouveau_context.h @@ -119,4 +119,49 @@ nouveau_context_update_frame_stats(struct nouveau_context *nv) } } +static inline void +nv_framebuffer_init(struct pipe_context *pctx, + const struct pipe_framebuffer_state *fb, + struct pipe_surface **cbufs, + struct pipe_surface **zsbuf, + struct pipe_surface *(*create)(struct pipe_context *pipe, + struct pipe_resource *pt, + const struct pipe_surface *tmpl), + void (*del)(struct pipe_context *pipe, struct pipe_surface *ps)) +{ + if (fb) { + for (unsigned i = 0; i < fb->nr_cbufs; i++) { + if (cbufs[i] && pipe_surface_equal(&fb->cbufs[i], cbufs[i])) + continue; + + struct pipe_surface *psurf = fb->cbufs[i].texture ? create(pctx, fb->cbufs[i].texture, &fb->cbufs[i]) : NULL; + if (cbufs[i]) + del(pctx, cbufs[i]); + cbufs[i] = psurf; + } + + for (unsigned i = fb->nr_cbufs; i < PIPE_MAX_COLOR_BUFS; i++) { + if (cbufs[i]) + del(pctx, cbufs[i]); + cbufs[i] = NULL; + } + + if (*zsbuf && pipe_surface_equal(&fb->zsbuf, *zsbuf)) + return; + struct pipe_surface *zsurf = fb->zsbuf.texture ? create(pctx, fb->zsbuf.texture, &fb->zsbuf) : NULL; + if (*zsbuf) + del(pctx, *zsbuf); + *zsbuf = zsurf; + } else { + for (unsigned i = 0; i < PIPE_MAX_COLOR_BUFS; i++) { + if (cbufs[i]) + del(pctx, cbufs[i]); + cbufs[i] = NULL; + } + if (*zsbuf) + del(pctx, *zsbuf); + *zsbuf = NULL; + } +} + #endif diff --git a/src/gallium/drivers/nouveau/nv30/nv30_context.c b/src/gallium/drivers/nouveau/nv30/nv30_context.c index 7a7b1abdece..bf7b35c94d7 100644 --- a/src/gallium/drivers/nouveau/nv30/nv30_context.c +++ b/src/gallium/drivers/nouveau/nv30/nv30_context.c @@ -162,7 +162,7 @@ nv30_context_destroy(struct pipe_context *pipe) if (nv30->blit_fp) pipe_resource_reference(&nv30->blit_fp, NULL); - util_framebuffer_init(pipe, NULL, nv30->fb_cbufs, &nv30->fb_zsbuf); + nv30_framebuffer_init(pipe, NULL, nv30->fb_cbufs, &nv30->fb_zsbuf); util_unreference_framebuffer_state(&nv30->framebuffer); nouveau_bufctx_del(&nv30->bufctx); diff --git a/src/gallium/drivers/nouveau/nv30/nv30_context.h b/src/gallium/drivers/nouveau/nv30/nv30_context.h index 5ec05a0accd..c132df61838 100644 --- a/src/gallium/drivers/nouveau/nv30/nv30_context.h +++ b/src/gallium/drivers/nouveau/nv30/nv30_context.h @@ -99,7 +99,8 @@ struct nv30_context { unsigned dirty_samplers; } fragprog; - PIPE_FB_SURFACES; //STOP USING THIS + struct pipe_surface *fb_cbufs[PIPE_MAX_COLOR_BUFS]; + struct pipe_surface *fb_zsbuf; struct pipe_framebuffer_state framebuffer; struct pipe_blend_color blend_colour; struct pipe_stencil_ref stencil_ref; diff --git a/src/gallium/drivers/nouveau/nv30/nv30_miptree.c b/src/gallium/drivers/nouveau/nv30/nv30_miptree.c index 25157001dd1..b4a9fce219b 100644 --- a/src/gallium/drivers/nouveau/nv30/nv30_miptree.c +++ b/src/gallium/drivers/nouveau/nv30/nv30_miptree.c @@ -541,7 +541,7 @@ nv30_miptree_from_handle(struct pipe_screen *pscreen, return &mt->base.base; } -struct pipe_surface * +static struct pipe_surface * nv30_miptree_surface_new(struct pipe_context *pipe, struct pipe_resource *pt, const struct pipe_surface *tmpl) @@ -556,7 +556,6 @@ nv30_miptree_surface_new(struct pipe_context *pipe, return NULL; ps = &ns->base; - pipe_reference_init(&ps->reference, 1); pipe_resource_reference(&ps->texture, pt); ps->context = pipe; ps->format = tmpl->format; @@ -576,11 +575,19 @@ nv30_miptree_surface_new(struct pipe_context *pipe, return ps; } -void +static void nv30_miptree_surface_del(struct pipe_context *pipe, struct pipe_surface *ps) { - struct nv30_surface *ns = nv30_surface(ps); - - pipe_resource_reference(&ps->texture, NULL); - FREE(ns); + FREE(ps); +} + +void +nv30_framebuffer_init(struct pipe_context *pctx, + const struct pipe_framebuffer_state *fb, + struct pipe_surface **cbufs, + struct pipe_surface **zsbuf) +{ + return nv_framebuffer_init(pctx, fb, cbufs, zsbuf, + nv30_miptree_surface_new, + nv30_miptree_surface_del); } diff --git a/src/gallium/drivers/nouveau/nv30/nv30_resource.c b/src/gallium/drivers/nouveau/nv30/nv30_resource.c index f4e66fa4458..49937a33303 100644 --- a/src/gallium/drivers/nouveau/nv30/nv30_resource.c +++ b/src/gallium/drivers/nouveau/nv30/nv30_resource.c @@ -99,8 +99,6 @@ nv30_resource_init(struct pipe_context *pipe) pipe->texture_unmap = nv30_miptree_transfer_unmap; pipe->buffer_subdata = u_default_buffer_subdata; pipe->texture_subdata = u_default_texture_subdata; - pipe->create_surface = nv30_miptree_surface_new; - pipe->surface_destroy = nv30_miptree_surface_del; pipe->resource_copy_region = nv30_resource_copy_region; pipe->blit = nv30_blit; pipe->flush_resource = nv30_flush_resource; diff --git a/src/gallium/drivers/nouveau/nv30/nv30_resource.h b/src/gallium/drivers/nouveau/nv30/nv30_resource.h index 7dcc19952af..67e51d29040 100644 --- a/src/gallium/drivers/nouveau/nv30/nv30_resource.h +++ b/src/gallium/drivers/nouveau/nv30/nv30_resource.h @@ -51,12 +51,11 @@ struct pipe_resource * nv30_miptree_from_handle(struct pipe_screen *, const struct pipe_resource *, struct winsys_handle *); -struct pipe_surface * -nv30_miptree_surface_new(struct pipe_context *, struct pipe_resource *, - const struct pipe_surface *); - void -nv30_miptree_surface_del(struct pipe_context *, struct pipe_surface *); +nv30_framebuffer_init(struct pipe_context *pctx, + const struct pipe_framebuffer_state *fb, + struct pipe_surface **cbufs, + struct pipe_surface **zsbuf); bool nv30_miptree_get_handle(struct pipe_screen *pscreen, diff --git a/src/gallium/drivers/nouveau/nv30/nv30_state.c b/src/gallium/drivers/nouveau/nv30/nv30_state.c index 7d27f9e37ea..7350d1efa3f 100644 --- a/src/gallium/drivers/nouveau/nv30/nv30_state.c +++ b/src/gallium/drivers/nouveau/nv30/nv30_state.c @@ -399,7 +399,7 @@ nv30_set_framebuffer_state(struct pipe_context *pipe, debug_printf("Mismatched color and zeta formats, ignoring zeta.\n"); } } - util_framebuffer_init(pipe, &nv30->framebuffer, nv30->fb_cbufs, &nv30->fb_zsbuf); + nv30_framebuffer_init(pipe, &nv30->framebuffer, nv30->fb_cbufs, &nv30->fb_zsbuf); } static void diff --git a/src/gallium/drivers/nouveau/nv50/nv50_context.h b/src/gallium/drivers/nouveau/nv50/nv50_context.h index dab04db8b6d..2280622c890 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_context.h +++ b/src/gallium/drivers/nouveau/nv50/nv50_context.h @@ -195,7 +195,8 @@ struct nv50_context { */ uint32_t so_used[4]; - PIPE_FB_SURFACES; //STOP USING THIS + struct pipe_surface *fb_cbufs[PIPE_MAX_COLOR_BUFS]; + struct pipe_surface *fb_zsbuf; struct pipe_framebuffer_state framebuffer; struct pipe_blend_color blend_colour; struct pipe_stencil_ref stencil_ref; diff --git a/src/gallium/drivers/nouveau/nv50/nv50_miptree.c b/src/gallium/drivers/nouveau/nv50/nv50_miptree.c index 1ca932b5bef..3cb093a181d 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_miptree.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_miptree.c @@ -500,7 +500,6 @@ nv50_miptree_surface_new(struct pipe_context *pipe, struct nv50_surface *ns = nv50_surface_from_miptree(mt, templ); if (!ns) return NULL; - ns->base.context = pipe; if (ns->base.first_layer) { const unsigned l = ns->base.level; diff --git a/src/gallium/drivers/nouveau/nv50/nv50_resource.c b/src/gallium/drivers/nouveau/nv50/nv50_resource.c index 00ede66a7d7..5cae6883d9c 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_resource.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_resource.c @@ -3,6 +3,7 @@ #include "util/u_inlines.h" #include "util/format/u_format.h" +#include "nouveau_context.h" #include "nouveau_screen.h" #include "nv50/nv50_resource.h" @@ -40,14 +41,6 @@ nv50_resource_from_handle(struct pipe_screen * screen, return nv50_miptree_from_handle(screen, templ, whandle); } -static struct pipe_surface * -nv50_surface_create(struct pipe_context *pipe, - struct pipe_resource *pres, - const struct pipe_surface *templ) -{ - return nv50_miptree_surface_new(pipe, pres, templ); -} - void nv50_surface_destroy(struct pipe_context *pipe, struct pipe_surface *ps) { @@ -58,6 +51,17 @@ nv50_surface_destroy(struct pipe_context *pipe, struct pipe_surface *ps) FREE(s); } +void +nv50_framebuffer_init(struct pipe_context *pctx, + const struct pipe_framebuffer_state *fb, + struct pipe_surface **cbufs, + struct pipe_surface **zsbuf) +{ + return nv_framebuffer_init(pctx, fb, cbufs, zsbuf, + nv50_miptree_surface_new, + nv50_surface_destroy); +} + void nv50_invalidate_resource(struct pipe_context *pipe, struct pipe_resource *res) { @@ -142,7 +146,6 @@ nv50_init_resource_functions(struct pipe_context *pcontext) pcontext->texture_unmap = nv50_miptree_transfer_unmap; pcontext->buffer_subdata = u_default_buffer_subdata; pcontext->texture_subdata = u_default_texture_subdata; - pcontext->create_surface = nv50_surface_create; pcontext->surface_destroy = nv50_surface_destroy; pcontext->invalidate_resource = nv50_invalidate_resource; } diff --git a/src/gallium/drivers/nouveau/nv50/nv50_resource.h b/src/gallium/drivers/nouveau/nv50/nv50_resource.h index d7132149a25..11e3d42fb02 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_resource.h +++ b/src/gallium/drivers/nouveau/nv50/nv50_resource.h @@ -156,6 +156,12 @@ nv50_surface_from_miptree(struct nv50_miptree *mt, void nv50_surface_destroy(struct pipe_context *, struct pipe_surface *); +void +nv50_framebuffer_init(struct pipe_context *pctx, + const struct pipe_framebuffer_state *fb, + struct pipe_surface **cbufs, + struct pipe_surface **zsbuf); + void nv50_invalidate_resource(struct pipe_context *, struct pipe_resource *); diff --git a/src/gallium/drivers/nouveau/nv50/nv50_surface.c b/src/gallium/drivers/nouveau/nv50/nv50_surface.c index aeca450005c..dbb0d048c91 100644 --- a/src/gallium/drivers/nouveau/nv50/nv50_surface.c +++ b/src/gallium/drivers/nouveau/nv50/nv50_surface.c @@ -1298,7 +1298,7 @@ nv50_blitctx_post_blit(struct nv50_blitctx *blit) struct nv50_context *nv50 = blit->nv50; int s; - pipe_surface_reference(&nv50->fb_cbufs[0], NULL); + nv50_surface_destroy(&nv50->base.pipe, nv50->fb_cbufs[0]); nv50->framebuffer.width = blit->saved.fb.width; nv50->framebuffer.height = blit->saved.fb.height; diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c index 4078a5c4294..c1bf83e9f3a 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.c @@ -195,7 +195,7 @@ nvc0_context_unreference_resources(struct nvc0_context *nvc0) nouveau_bufctx_del(&nvc0->bufctx); nouveau_bufctx_del(&nvc0->bufctx_cp); - util_framebuffer_init(&nvc0->base.pipe, NULL, nvc0->fb_cbufs, &nvc0->fb_zsbuf); + nvc0_framebuffer_init(&nvc0->base.pipe, NULL, nvc0->fb_cbufs, &nvc0->fb_zsbuf); util_unreference_framebuffer_state(&nvc0->framebuffer); for (i = 0; i < nvc0->num_vtxbufs; ++i) diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h index cdff8cbcfea..2ba1dca2594 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_context.h +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_context.h @@ -237,7 +237,8 @@ struct nvc0_context { struct list_head tex_head; struct list_head img_head; - PIPE_FB_SURFACES; //STOP USING THIS + struct pipe_surface *fb_cbufs[PIPE_MAX_COLOR_BUFS]; + struct pipe_surface *fb_zsbuf; struct pipe_framebuffer_state framebuffer; bool sample_locations_enabled; uint8_t sample_locations[2 * 4 * 8]; diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_miptree.c b/src/gallium/drivers/nouveau/nvc0/nvc0_miptree.c index e93d66c71b6..26c1df0222b 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_miptree.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_miptree.c @@ -585,6 +585,5 @@ nvc0_miptree_surface_new(struct pipe_context *pipe, struct nv50_surface *ns = nv50_surface_from_miptree(nv50_miptree(pt), templ); if (!ns) return NULL; - ns->base.context = pipe; return &ns->base; } diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c index 3a8d6201ce2..98339c09928 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.c @@ -2,6 +2,7 @@ #include "pipe/p_context.h" #include "nvc0/nvc0_resource.h" +#include "nouveau_context.h" #include "nouveau_screen.h" @@ -126,12 +127,15 @@ nvc0_resource_from_handle(struct pipe_screen * screen, } } -static struct pipe_surface * -nvc0_surface_create(struct pipe_context *pipe, - struct pipe_resource *pres, - const struct pipe_surface *templ) +void +nvc0_framebuffer_init(struct pipe_context *pctx, + const struct pipe_framebuffer_state *fb, + struct pipe_surface **cbufs, + struct pipe_surface **zsbuf) { - return nvc0_miptree_surface_new(pipe, pres, templ); + return nv_framebuffer_init(pctx, fb, cbufs, zsbuf, + nvc0_miptree_surface_new, + nv50_surface_destroy); } static struct pipe_resource * @@ -155,8 +159,6 @@ nvc0_init_resource_functions(struct pipe_context *pcontext) pcontext->texture_unmap = nvc0_miptree_transfer_unmap; pcontext->buffer_subdata = u_default_buffer_subdata; pcontext->texture_subdata = u_default_texture_subdata; - pcontext->create_surface = nvc0_surface_create; - pcontext->surface_destroy = nv50_surface_destroy; pcontext->invalidate_resource = nv50_invalidate_resource; } diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.h b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.h index a281d427c94..247c3aafc26 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_resource.h +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_resource.h @@ -65,6 +65,12 @@ nvc0_miptree_surface_new(struct pipe_context *, struct pipe_resource *, const struct pipe_surface *templ); +void +nvc0_framebuffer_init(struct pipe_context *pctx, + const struct pipe_framebuffer_state *fb, + struct pipe_surface **cbufs, + struct pipe_surface **zsbuf); + unsigned nvc0_mt_zslice_offset(const struct nv50_miptree *, unsigned l, unsigned z); diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c index c15890e8048..f63f4f81327 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_state.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_state.c @@ -910,7 +910,7 @@ nvc0_set_framebuffer_state(struct pipe_context *pipe, nouveau_bufctx_reset(nvc0->bufctx_3d, NVC0_BIND_3D_FB); - util_framebuffer_init(pipe, fb, nvc0->fb_cbufs, &nvc0->fb_zsbuf); + nvc0_framebuffer_init(pipe, fb, nvc0->fb_cbufs, &nvc0->fb_zsbuf); util_copy_framebuffer_state(&nvc0->framebuffer, fb); nvc0->dirty_3d |= NVC0_NEW_3D_FRAMEBUFFER | NVC0_NEW_3D_SAMPLE_LOCATIONS | diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c b/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c index 8e9e3bb3a11..23f4493d194 100644 --- a/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c +++ b/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c @@ -1165,7 +1165,7 @@ nvc0_blitctx_post_blit(struct nvc0_blitctx *blit) struct nvc0_context *nvc0 = blit->nvc0; int s; - pipe_surface_reference(&nvc0->fb_cbufs[0], NULL); + nv50_surface_destroy(&nvc0->base.pipe, nvc0->fb_cbufs[0]); nvc0->framebuffer.width = blit->saved.fb.width; nvc0->framebuffer.height = blit->saved.fb.height;