From 42c47ef465ab43c94cbea2991ac8af6503d559c1 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 30 Jun 2021 09:25:57 -0400 Subject: [PATCH] zink: move get_framebuffer() to zink_framebuffer.c Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/zink/zink_context.c | 53 ++--------------------------- src/gallium/drivers/zink/zink_framebuffer.c | 47 +++++++++++++++++++++++++ src/gallium/drivers/zink/zink_framebuffer.h | 2 ++ 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 797b22d..f5311a3 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -43,7 +43,6 @@ #include "util/u_debug.h" #include "util/format_srgb.h" #include "util/format/u_format.h" -#include "util/u_framebuffer.h" #include "util/u_helpers.h" #include "util/u_inlines.h" #include "util/u_thread.h" @@ -1613,52 +1612,6 @@ get_render_pass(struct zink_context *ctx) return rp; } -static struct zink_framebuffer * -get_framebuffer(struct zink_context *ctx) -{ - struct zink_screen *screen = zink_screen(ctx->base.screen); - struct pipe_surface *attachments[PIPE_MAX_COLOR_BUFS + 1] = {0}; - - struct zink_framebuffer_state state = {0}; - for (int i = 0; i < ctx->fb_state.nr_cbufs; i++) { - struct pipe_surface *psurf = ctx->fb_state.cbufs[i]; - state.attachments[i] = psurf ? zink_surface(psurf)->image_view : VK_NULL_HANDLE; - attachments[i] = psurf; - } - - state.num_attachments = ctx->fb_state.nr_cbufs; - if (ctx->fb_state.zsbuf) { - struct pipe_surface *psurf = ctx->fb_state.zsbuf; - state.attachments[state.num_attachments] = psurf ? zink_surface(psurf)->image_view : VK_NULL_HANDLE; - attachments[state.num_attachments++] = psurf; - } - - state.width = MAX2(ctx->fb_state.width, 1); - state.height = MAX2(ctx->fb_state.height, 1); - state.layers = MAX2(util_framebuffer_get_num_layers(&ctx->fb_state), 1); - state.samples = ctx->fb_state.samples; - - struct zink_framebuffer *fb; - simple_mtx_lock(&screen->framebuffer_mtx); - struct hash_entry *entry = _mesa_hash_table_search(&screen->framebuffer_cache, &state); - if (entry) { - fb = (void*)entry->data; - struct zink_framebuffer *fb_ref = NULL; - /* this gains 1 ref every time we reuse it */ - zink_framebuffer_reference(screen, &fb_ref, fb); - } else { - /* this adds 1 extra ref on creation because all newly-created framebuffers are - * going to be bound; necessary to handle framebuffers which have no "real" attachments - * and are only using null surfaces since the only ref they get is the extra one here - */ - fb = zink_create_framebuffer(ctx, &state, attachments); - _mesa_hash_table_insert(&screen->framebuffer_cache, &fb->state, fb); - } - simple_mtx_unlock(&screen->framebuffer_mtx); - - return fb; -} - static void setup_framebuffer(struct zink_context *ctx) { @@ -2068,11 +2021,11 @@ zink_set_framebuffer_state(struct pipe_context *pctx, if (ctx->fb_state.width != w || ctx->fb_state.height != h) ctx->scissor_changed = true; rebind_fb_state(ctx, NULL, true); - /* get_framebuffer adds a ref if the fb is reused or created; + /* zink_get_framebuffer adds a ref if the fb is reused or created; * always do get_framebuffer first to avoid deleting the same fb * we're about to use */ - struct zink_framebuffer *fb = get_framebuffer(ctx); + struct zink_framebuffer *fb = zink_get_framebuffer(ctx); if (ctx->framebuffer) { struct zink_screen *screen = zink_screen(pctx->screen); simple_mtx_lock(&screen->framebuffer_mtx); @@ -2087,7 +2040,7 @@ zink_set_framebuffer_state(struct pipe_context *pctx, } /* a framebuffer loses 1 ref every time we unset it; * we do NOT add refs here, as the ref has already been added in - * get_framebuffer() + * zink_get_framebuffer() */ if (zink_framebuffer_reference(screen, &ctx->framebuffer, NULL) && he) _mesa_hash_table_remove(&screen->framebuffer_cache, he); diff --git a/src/gallium/drivers/zink/zink_framebuffer.c b/src/gallium/drivers/zink/zink_framebuffer.c index b409fab..a96c2e3 100644 --- a/src/gallium/drivers/zink/zink_framebuffer.c +++ b/src/gallium/drivers/zink/zink_framebuffer.c @@ -28,6 +28,7 @@ #include "zink_screen.h" #include "zink_surface.h" +#include "util/u_framebuffer.h" #include "util/u_memory.h" #include "util/u_string.h" @@ -142,3 +143,49 @@ debug_describe_zink_framebuffer(char* buf, const struct zink_framebuffer *ptr) { sprintf(buf, "zink_framebuffer"); } + +struct zink_framebuffer * +zink_get_framebuffer(struct zink_context *ctx) +{ + struct zink_screen *screen = zink_screen(ctx->base.screen); + struct pipe_surface *attachments[PIPE_MAX_COLOR_BUFS + 1] = {0}; + + struct zink_framebuffer_state state = {0}; + for (int i = 0; i < ctx->fb_state.nr_cbufs; i++) { + struct pipe_surface *psurf = ctx->fb_state.cbufs[i]; + state.attachments[i] = psurf ? zink_surface(psurf)->image_view : VK_NULL_HANDLE; + attachments[i] = psurf; + } + + state.num_attachments = ctx->fb_state.nr_cbufs; + if (ctx->fb_state.zsbuf) { + struct pipe_surface *psurf = ctx->fb_state.zsbuf; + state.attachments[state.num_attachments] = psurf ? zink_surface(psurf)->image_view : VK_NULL_HANDLE; + attachments[state.num_attachments++] = psurf; + } + + state.width = MAX2(ctx->fb_state.width, 1); + state.height = MAX2(ctx->fb_state.height, 1); + state.layers = MAX2(util_framebuffer_get_num_layers(&ctx->fb_state), 1); + state.samples = ctx->fb_state.samples; + + struct zink_framebuffer *fb; + simple_mtx_lock(&screen->framebuffer_mtx); + struct hash_entry *entry = _mesa_hash_table_search(&screen->framebuffer_cache, &state); + if (entry) { + fb = (void*)entry->data; + struct zink_framebuffer *fb_ref = NULL; + /* this gains 1 ref every time we reuse it */ + zink_framebuffer_reference(screen, &fb_ref, fb); + } else { + /* this adds 1 extra ref on creation because all newly-created framebuffers are + * going to be bound; necessary to handle framebuffers which have no "real" attachments + * and are only using null surfaces since the only ref they get is the extra one here + */ + fb = zink_create_framebuffer(ctx, &state, attachments); + _mesa_hash_table_insert(&screen->framebuffer_cache, &fb->state, fb); + } + simple_mtx_unlock(&screen->framebuffer_mtx); + + return fb; +} diff --git a/src/gallium/drivers/zink/zink_framebuffer.h b/src/gallium/drivers/zink/zink_framebuffer.h index 73212cc..f2a23e4 100644 --- a/src/gallium/drivers/zink/zink_framebuffer.h +++ b/src/gallium/drivers/zink/zink_framebuffer.h @@ -87,4 +87,6 @@ zink_framebuffer_reference(struct zink_screen *screen, return ret; } +struct zink_framebuffer * +zink_get_framebuffer(struct zink_context *ctx); #endif -- 2.7.4