From 0accbe03e83b5b6400d4fa1180f2c5d9bb7a3657 Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Mon, 9 Jan 2023 10:29:28 -0800 Subject: [PATCH] gallium: Allow copy_region blits with matching formats. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the blit formats match and the resource formats match, then that's a memcpy whether or not the blit's view of the resource matches the resource's format. Improves perf of portal-2-v2's last frame on zink+anv by 1.33212% +/- 0.302829% (n=5), where there's a blit that is viewing the RGBA8_UNORM src/dst resources as RGBA8_SRGB. Reviewed-by: Mike Blumenkrantz Reviewed-by: Marek Olšák Part-of: --- src/gallium/auxiliary/util/u_surface.c | 8 +++++--- src/gallium/auxiliary/util/u_surface_test.cpp | 11 +++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/gallium/auxiliary/util/u_surface.c b/src/gallium/auxiliary/util/u_surface.c index af406e826ad..cd51fd34b4e 100644 --- a/src/gallium/auxiliary/util/u_surface.c +++ b/src/gallium/auxiliary/util/u_surface.c @@ -783,9 +783,11 @@ util_can_blit_via_copy_region(const struct pipe_blit_info *blit, } else { /* do loose format compatibility checking */ - if (blit->src.resource->format != blit->src.format || - blit->dst.resource->format != blit->dst.format || - !util_is_format_compatible(src_desc, dst_desc)) { + if ((blit->src.format != blit->dst.format || + src_desc != dst_desc) && + (blit->src.resource->format != blit->src.format || + blit->dst.resource->format != blit->dst.format || + !util_is_format_compatible(src_desc, dst_desc))) { return FALSE; } } diff --git a/src/gallium/auxiliary/util/u_surface_test.cpp b/src/gallium/auxiliary/util/u_surface_test.cpp index 27f1352fcc8..d647e7fbad9 100644 --- a/src/gallium/auxiliary/util/u_surface_test.cpp +++ b/src/gallium/auxiliary/util/u_surface_test.cpp @@ -48,6 +48,7 @@ TEST(util_can_blit_via_copy_region, formats) struct pipe_resource dst_rgba8_unorm = test_resource_with_format(PIPE_FORMAT_R8G8B8A8_UNORM); struct pipe_resource src_rgbx8_unorm = test_resource_with_format(PIPE_FORMAT_R8G8B8X8_UNORM); struct pipe_resource dst_rgbx8_unorm = test_resource_with_format(PIPE_FORMAT_R8G8B8X8_UNORM); + struct pipe_resource dst_rgba8_srgb = test_resource_with_format(PIPE_FORMAT_R8G8B8A8_SRGB); /* Same-format blit should pass */ struct pipe_blit_info rgba8_unorm_rgba8_unorm_blit = test_blit_with_formats(&src_rgba8_unorm, PIPE_FORMAT_R8G8B8A8_UNORM, @@ -68,4 +69,14 @@ TEST(util_can_blit_via_copy_region, formats) struct pipe_blit_info rgbx8_unorm_rgba8_unorm_blit = test_blit_with_formats(&src_rgbx8_unorm, PIPE_FORMAT_R8G8B8X8_UNORM, &dst_rgba8_unorm, PIPE_FORMAT_R8G8B8A8_UNORM); ASSERT_FALSE(util_can_blit_via_copy_region(&rgbx8_unorm_rgba8_unorm_blit, false, false)); + + /* If the RGBA8_UNORM resources are both viewed as sRGB, it's still a memcpy. */ + struct pipe_blit_info rgba8_srgb_rgba8_srgb_blit = test_blit_with_formats(&src_rgba8_unorm, PIPE_FORMAT_R8G8B8A8_SRGB, + &dst_rgba8_unorm, PIPE_FORMAT_R8G8B8A8_SRGB); + ASSERT_TRUE(util_can_blit_via_copy_region(&rgba8_srgb_rgba8_srgb_blit, false, false)); + + /* A memcpy blit can't be lowered to copy_region if copy_region would have mismatched resource formats. */ + struct pipe_blit_info non_memcpy_copy_region = test_blit_with_formats(&src_rgba8_unorm, PIPE_FORMAT_R8G8B8A8_UNORM, + &dst_rgba8_srgb, PIPE_FORMAT_R8G8B8A8_UNORM); + ASSERT_FALSE(util_can_blit_via_copy_region(&non_memcpy_copy_region, false, false)); }