From 2c22e78619d90c128ca7f108bfe9bda7dbe4deca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Fri, 8 Mar 2024 16:10:52 +0100 Subject: [PATCH] zink: Separate the template from the wrapped surface Allow to better understand the case when needs_mutable is true, differenciate `base` from `surf` even if they are the same variable in most cases. Part-of: --- src/gallium/drivers/zink/zink_surface.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gallium/drivers/zink/zink_surface.c b/src/gallium/drivers/zink/zink_surface.c index c64c068de0e..e1f73ca1dc5 100644 --- a/src/gallium/drivers/zink/zink_surface.c +++ b/src/gallium/drivers/zink/zink_surface.c @@ -269,7 +269,9 @@ zink_get_surface(struct zink_context *ctx, /* wrap a surface for use as a framebuffer attachment */ static struct zink_ctx_surface * -wrap_surface(struct pipe_context *pctx, const struct pipe_surface *psurf) +wrap_surface(struct pipe_context *pctx, + struct pipe_surface *psurf, + const struct pipe_surface *templ) { struct zink_ctx_surface *csurf = CALLOC_STRUCT(zink_ctx_surface); if (!csurf) { @@ -277,9 +279,9 @@ wrap_surface(struct pipe_context *pctx, const struct pipe_surface *psurf) return NULL; } - csurf->base = *psurf; + csurf->base = *templ; pipe_reference_init(&csurf->base.reference, 1); - csurf->surf = (struct zink_surface*)psurf; + csurf->surf = zink_surface(psurf); csurf->base.context = pctx; return csurf; @@ -338,10 +340,9 @@ zink_create_surface(struct pipe_context *pctx, if (!psurf && !needs_mutable) return NULL; - struct zink_ctx_surface *csurf = wrap_surface(pctx, needs_mutable ? templ : psurf); + struct zink_ctx_surface *csurf = wrap_surface(pctx, needs_mutable ? NULL : psurf, needs_mutable ? templ : psurf); csurf->needs_mutable = needs_mutable; if (needs_mutable) { - csurf->surf = NULL; pipe_resource_reference(&csurf->base.texture, pres); init_pipe_surface_info(pctx, &csurf->base, templ, pres); } @@ -356,7 +357,7 @@ zink_create_surface(struct pipe_context *pctx, return NULL; ivci.image = transient->obj->image; struct zink_surface *tsurf = create_surface(pctx, &transient->base.b, templ, &ivci, true); - csurf->transient = wrap_surface(pctx, &tsurf->base); + csurf->transient = wrap_surface(pctx, &tsurf->base, &tsurf->base); if (!csurf->transient) { pipe_resource_reference((struct pipe_resource**)&transient, NULL); pipe_surface_release(pctx, &psurf);