From e31381ac2609ef06dfa5a230c38e7044009f5526 Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Sun, 14 Jun 2020 00:01:07 -0400 Subject: [PATCH] zink: combine all surface layout-setting for src/dst into util function we do a lot of src/dst layout-setting, so ensure that we use the same code everywhere to avoid cases where src==dst and we aren't setting GENERAL layout as we should Reviewed-by: Erik Faye-Lund Part-of: --- src/gallium/drivers/zink/zink_blit.c | 38 ++------------------------------ src/gallium/drivers/zink/zink_context.c | 11 +-------- src/gallium/drivers/zink/zink_resource.c | 34 ++++++++++++++++++++++++++++ src/gallium/drivers/zink/zink_resource.h | 3 +++ 4 files changed, 40 insertions(+), 46 deletions(-) diff --git a/src/gallium/drivers/zink/zink_blit.c b/src/gallium/drivers/zink/zink_blit.c index 8ec5c93..891ba59 100644 --- a/src/gallium/drivers/zink/zink_blit.c +++ b/src/gallium/drivers/zink/zink_blit.c @@ -31,13 +31,7 @@ blit_resolve(struct zink_context *ctx, const struct pipe_blit_info *info) zink_batch_reference_resoure(batch, src); zink_batch_reference_resoure(batch, dst); - if (src->layout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) - zink_resource_barrier(batch->cmdbuf, src, src->aspect, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); - - if (dst->layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) - zink_resource_barrier(batch->cmdbuf, dst, dst->aspect, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + zink_resource_setup_transfer_layouts(batch, src, dst); VkImageResolve region = {}; @@ -97,35 +91,7 @@ blit_native(struct zink_context *ctx, const struct pipe_blit_info *info) zink_batch_reference_resoure(batch, src); zink_batch_reference_resoure(batch, dst); - if (src == dst) { - /* The Vulkan 1.1 specification says the following about valid usage - * of vkCmdBlitImage: - * - * "srcImageLayout must be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR, - * VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL" - * - * and: - * - * "dstImageLayout must be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR, - * VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL" - * - * Since we cant have the same image in two states at the same time, - * we're effectively left with VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR or - * VK_IMAGE_LAYOUT_GENERAL. And since this isn't a present-related - * operation, VK_IMAGE_LAYOUT_GENERAL seems most appropriate. - */ - if (src->layout != VK_IMAGE_LAYOUT_GENERAL) - zink_resource_barrier(batch->cmdbuf, src, src->aspect, - VK_IMAGE_LAYOUT_GENERAL); - } else { - if (src->layout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) - zink_resource_barrier(batch->cmdbuf, src, src->aspect, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); - - if (dst->layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) - zink_resource_barrier(batch->cmdbuf, dst, dst->aspect, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - } + zink_resource_setup_transfer_layouts(batch, src, dst); VkImageBlit region = {}; region.srcSubresource.aspectMask = src->aspect; diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c index 46c9619..e05556c 100644 --- a/src/gallium/drivers/zink/zink_context.c +++ b/src/gallium/drivers/zink/zink_context.c @@ -962,16 +962,7 @@ zink_resource_copy_region(struct pipe_context *pctx, zink_batch_reference_resoure(batch, src); zink_batch_reference_resoure(batch, dst); - if (src->layout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) { - zink_resource_barrier(batch->cmdbuf, src, src->aspect, - VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); - } - - if (dst->layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { - zink_resource_barrier(batch->cmdbuf, dst, dst->aspect, - VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - } - + zink_resource_setup_transfer_layouts(batch, src, dst); vkCmdCopyImage(batch->cmdbuf, src->image, src->layout, dst->image, dst->layout, 1, ®ion); diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c index e0aa07d..89b9ca1 100644 --- a/src/gallium/drivers/zink/zink_resource.c +++ b/src/gallium/drivers/zink/zink_resource.c @@ -590,6 +590,40 @@ zink_resource_get_separate_stencil(struct pipe_resource *pres) } void +zink_resource_setup_transfer_layouts(struct zink_batch *batch, struct zink_resource *src, struct zink_resource *dst) +{ + if (src == dst) { + /* The Vulkan 1.1 specification says the following about valid usage + * of vkCmdBlitImage: + * + * "srcImageLayout must be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR, + * VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL" + * + * and: + * + * "dstImageLayout must be VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR, + * VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL or VK_IMAGE_LAYOUT_GENERAL" + * + * Since we cant have the same image in two states at the same time, + * we're effectively left with VK_IMAGE_LAYOUT_SHARED_PRESENT_KHR or + * VK_IMAGE_LAYOUT_GENERAL. And since this isn't a present-related + * operation, VK_IMAGE_LAYOUT_GENERAL seems most appropriate. + */ + if (src->layout != VK_IMAGE_LAYOUT_GENERAL) + zink_resource_barrier(batch->cmdbuf, src, src->aspect, + VK_IMAGE_LAYOUT_GENERAL); + } else { + if (src->layout != VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) + zink_resource_barrier(batch->cmdbuf, src, src->aspect, + VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); + + if (dst->layout != VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) + zink_resource_barrier(batch->cmdbuf, dst, dst->aspect, + VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); + } +} + +void zink_get_depth_stencil_resources(struct pipe_resource *res, struct zink_resource **out_z, struct zink_resource **out_s) diff --git a/src/gallium/drivers/zink/zink_resource.h b/src/gallium/drivers/zink/zink_resource.h index b6298b3..98ae7be 100644 --- a/src/gallium/drivers/zink/zink_resource.h +++ b/src/gallium/drivers/zink/zink_resource.h @@ -26,6 +26,7 @@ struct pipe_screen; struct sw_displaytarget; +struct zink_batch; #include "util/u_transfer.h" @@ -77,4 +78,6 @@ zink_get_depth_stencil_resources(struct pipe_resource *res, struct zink_resource **out_z, struct zink_resource **out_s); +void +zink_resource_setup_transfer_layouts(struct zink_batch *batch, struct zink_resource *src, struct zink_resource *dst); #endif -- 2.7.4