gallium: Allow copy_region blits with matching formats.

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 <michael.blumenkrantz@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20594>
This commit is contained in:
Emma Anholt
2023-01-09 10:29:28 -08:00
committed by Marge Bot
parent 673837bb8b
commit 0accbe03e8
2 changed files with 16 additions and 3 deletions

View File

@@ -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;
}
}

View File

@@ -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));
}