From b9ca7bef3f35fe990871c2bf6931fbfd5f5d117e Mon Sep 17 00:00:00 2001 From: Steveice10 <1269164+Steveice10@users.noreply.github.com> Date: Tue, 17 Jan 2023 03:42:47 -0800 Subject: [PATCH] rasterizer_cache: Handle texture swizzle case with unaligned offsets in same tile. (#23) --- src/video_core/rasterizer_cache/texture_codec.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/video_core/rasterizer_cache/texture_codec.h b/src/video_core/rasterizer_cache/texture_codec.h index 6eb64d486..da42ac0d6 100644 --- a/src/video_core/rasterizer_cache/texture_codec.h +++ b/src/video_core/rasterizer_cache/texture_codec.h @@ -308,13 +308,16 @@ static constexpr void MortonCopy(u32 width, u32 height, u32 start_offset, u32 en LinearNextTile(); } - const u32 buffer_end = tiled_offset + aligned_end_offset - aligned_start_offset; - while (tiled_offset < buffer_end) { - auto linear_data = linear_buffer.subspan(linear_offset, linear_tile_stride); - auto tiled_data = tiled_buffer.subspan(tiled_offset, tile_size); - MortonCopyTile(width, tiled_data, linear_data); - tiled_offset += tile_size; - LinearNextTile(); + // If the copy spans multiple tiles, copy the fully aligned tiles in between. + if (aligned_start_offset < aligned_end_offset) { + const u32 buffer_end = tiled_offset + aligned_end_offset - aligned_start_offset; + while (tiled_offset < buffer_end) { + auto linear_data = linear_buffer.subspan(linear_offset, linear_tile_stride); + auto tiled_data = tiled_buffer.subspan(tiled_offset, tile_size); + MortonCopyTile(width, tiled_data, linear_data); + tiled_offset += tile_size; + LinearNextTile(); + } } // If during a texture download the end coordinate is not tile aligned, swizzle