From 2bf037c7bb9a886297c6cf13b11092f7ca171817 Mon Sep 17 00:00:00 2001 From: CamilleLaVey Date: Sun, 16 Aug 2026 20:52:37 -0400 Subject: [PATCH] [TEST] Swizzling adjustment on the new fast path --- src/video_core/textures/decoders.cpp | 42 ++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp index 97458b80ca..4435ffe5f0 100644 --- a/src/video_core/textures/decoders.cpp +++ b/src/video_core/textures/decoders.cpp @@ -87,6 +87,34 @@ void SwizzleRow(std::span output, std::span input, u32 offset_zy, } } +template +void SwizzleRowPerPixel(std::span output, std::span input, u32 offset_zy, + u32 swizzled_y, u32 x_shift, u32 x, u32 num_bytes, u32 linear) { + u32 swizzled_x = pdep(x); + for (u32 byte = 0; byte < num_bytes; + byte += BYTES_PER_PIXEL, incrpdep(swizzled_x)) { + const u32 offset_x = ((x + byte) >> GOB_SIZE_X_SHIFT) << x_shift; + const u32 swizzled = offset_zy + offset_x + (swizzled_x | swizzled_y); + const u32 unswizzled = linear + byte; + + u8* const dst = &output[TO_LINEAR ? swizzled : unswizzled]; + const u8* const src = &input[TO_LINEAR ? unswizzled : swizzled]; + + std::memcpy(dst, src, BYTES_PER_PIXEL); + } +} + +template +void SwizzleRowDispatch(std::span output, std::span input, u32 offset_zy, + u32 swizzled_y, u32 x_shift, u32 x, u32 num_bytes, u32 linear) { + if constexpr (SWIZZLE_RUN_BYTES % BYTES_PER_PIXEL == 0) { + SwizzleRow(output, input, offset_zy, swizzled_y, x_shift, x, num_bytes, linear); + } else { + SwizzleRowPerPixel(output, input, offset_zy, swizzled_y, x_shift, + x, num_bytes, linear); + } +} + template void SwizzleImpl(std::span output, std::span input, u32 width, u32 height, u32 depth, u32 block_height, u32 block_depth, u32 stride) { @@ -121,9 +149,10 @@ void SwizzleImpl(std::span output, std::span input, u32 width, u32 const u32 offset_y = (block_y >> block_height) * block_size + ((block_y & block_height_mask) << GOB_SIZE_SHIFT); - SwizzleRow(output, input, offset_z + offset_y, swizzled_y, x_shift, - origin_x * BYTES_PER_PIXEL, width * BYTES_PER_PIXEL, - slice * pitch * height + line * pitch); + SwizzleRowDispatch( + output, input, offset_z + offset_y, swizzled_y, x_shift, + origin_x * BYTES_PER_PIXEL, width * BYTES_PER_PIXEL, + slice * pitch * height + line * pitch); } } } @@ -166,9 +195,10 @@ void SwizzleSubrectImpl(std::span output, std::span input, u32 wid const u32 offset_y = (block_y >> block_height) * block_size + ((block_y & block_height_mask) << GOB_SIZE_SHIFT); - SwizzleRow(output, input, offset_z + offset_y, swizzled_y, x_shift, - origin_x * BYTES_PER_PIXEL, extent_x * BYTES_PER_PIXEL, - slice * pitch * height + line * pitch); + SwizzleRowDispatch( + output, input, offset_z + offset_y, swizzled_y, x_shift, + origin_x * BYTES_PER_PIXEL, extent_x * BYTES_PER_PIXEL, + slice * pitch * height + line * pitch); } unprocessed_lines -= lines_in_y; if (unprocessed_lines == 0) {