From 1859f191c3815934615f00995443b0f7404b97b1 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 14 Jun 2023 08:49:57 -0400 Subject: [PATCH] zink: wrap format mismatch checks for blit/surface no functional changes Part-of: --- src/gallium/drivers/zink/zink_blit.c | 4 ++-- src/gallium/drivers/zink/zink_context.c | 4 ++-- src/gallium/drivers/zink/zink_format.h | 6 ++++++ src/gallium/drivers/zink/zink_surface.c | 3 ++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/gallium/drivers/zink/zink_blit.c b/src/gallium/drivers/zink/zink_blit.c index 5f39a9b..ac9ea05 100644 --- a/src/gallium/drivers/zink/zink_blit.c +++ b/src/gallium/drivers/zink/zink_blit.c @@ -418,9 +418,9 @@ zink_blit(struct pipe_context *pctx, zink_select_draw_vbo(ctx); } zink_blit_begin(ctx, ZINK_BLIT_SAVE_FB | ZINK_BLIT_SAVE_FS | ZINK_BLIT_SAVE_TEXTURES); - if (!zink_is_swapchain(src) && info->src.format != info->src.resource->format) + if (!zink_is_swapchain(src) && zink_format_needs_mutable(info->src.format, info->src.resource->format)) zink_resource_object_init_mutable(ctx, src); - if (!zink_is_swapchain(dst) && info->dst.format != info->dst.resource->format) + if (!zink_is_swapchain(dst) && zink_format_needs_mutable(info->dst.format, info->dst.resource->format)) zink_resource_object_init_mutable(ctx, dst); zink_blit_barriers(ctx, src, dst, whole); ctx->blitting = true; diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 427954d..dde801c 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -1771,7 +1771,7 @@ create_image_surface(struct zink_context *ctx, const struct pipe_image_view *vie break; default: break; } - if (!res->obj->dt && view->resource->format != view->format) + if (!res->obj->dt && zink_format_needs_mutable(view->resource->format, view->format)) /* mutable not set by default */ zink_resource_object_init_mutable(ctx, res); VkImageViewCreateInfo ivci = create_ivci(screen, res, &tmpl, target); @@ -2035,7 +2035,7 @@ zink_set_sampler_views(struct pipe_context *pctx, if (!ctx->unordered_blitting) res->obj->unordered_read = false; } else { - if (!res->obj->dt && res->base.b.format != b->image_view->base.format) + if (!res->obj->dt && zink_format_needs_mutable(res->base.b.format, b->image_view->base.format)) /* mutable not set by default */ zink_resource_object_init_mutable(ctx, res); if (res->obj != b->image_view->obj) { diff --git a/src/gallium/drivers/zink/zink_format.h b/src/gallium/drivers/zink/zink_format.h index c0fa84d..1fff06d 100644 --- a/src/gallium/drivers/zink/zink_format.h +++ b/src/gallium/drivers/zink/zink_format.h @@ -50,4 +50,10 @@ void zink_format_clamp_channel_color(const struct util_format_description *desc, union pipe_color_union *dst, const union pipe_color_union *src, unsigned i); void zink_format_clamp_channel_srgb(const struct util_format_description *desc, union pipe_color_union *dst, const union pipe_color_union *src, unsigned i); + +static inline bool +zink_format_needs_mutable(enum pipe_format a, enum pipe_format b) +{ + return a != b; +} #endif diff --git a/src/gallium/drivers/zink/zink_surface.c b/src/gallium/drivers/zink/zink_surface.c index 95e351d..cd26426 100644 --- a/src/gallium/drivers/zink/zink_surface.c +++ b/src/gallium/drivers/zink/zink_surface.c @@ -23,6 +23,7 @@ #include "zink_context.h" #include "zink_framebuffer.h" +#include "zink_format.h" #include "zink_resource.h" #include "zink_screen.h" #include "zink_surface.h" @@ -285,7 +286,7 @@ zink_create_surface(struct pipe_context *pctx, bool is_array = templ->u.tex.last_layer != templ->u.tex.first_layer; bool needs_mutable = false; enum pipe_texture_target target_2d[] = {PIPE_TEXTURE_2D, PIPE_TEXTURE_2D_ARRAY}; - if (!res->obj->dt && pres->format != templ->format) { + if (!res->obj->dt && zink_format_needs_mutable(pres->format, templ->format)) { /* mutable not set by default */ needs_mutable = !(res->base.b.bind & ZINK_BIND_MUTABLE); /* -- 2.7.4