From 7ead021aa7a0ee014d345d8dc98d47f9a3b05b4d Mon Sep 17 00:00:00 2001 From: eladash Date: Wed, 8 May 2019 17:44:30 +0300 Subject: [PATCH] rsx: Fix 3d swizzled texture to linear conversation --- rpcs3/Emu/RSX/rsx_utils.h | 45 ++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/rpcs3/Emu/RSX/rsx_utils.h b/rpcs3/Emu/RSX/rsx_utils.h index b1a0ba6e27..2df2fdb843 100644 --- a/rpcs3/Emu/RSX/rsx_utils.h +++ b/rpcs3/Emu/RSX/rsx_utils.h @@ -215,24 +215,39 @@ namespace rsx } // Returns interleaved bits of X|Y|Z used as Z-order curve indices - static inline u32 calculate_z_index(u32 x, u32 y, u32 z) + static inline u32 calculate_z_index(u32 x, u32 y, u32 z, u32 log2_width, u32 log2_height, u32 log2_depth) { - //Result = X' | Y' | Z' which are x,y,z bits interleaved - u32 shift_size = 0; - u32 result = 0; + AUDIT(x < (1u << log2_width) && y < (1u << log2_height) && z < (1u << log2_depth)); - while (x | y | z) + // offset = X' | Y' | Z' which are x,y,z bits interleaved + u32 offset = 0; + u32 shift_count = 0; + do { - result |= (x & 0x1) << shift_size++; - result |= (y & 0x1) << shift_size++; - result |= (z & 0x1) << shift_size++; + if (log2_width) + { + offset |= (x & 0x1) << shift_count++; + x >>= 1; + log2_width--; + } - x >>= 1; - y >>= 1; - z >>= 1; + if (log2_height) + { + offset |= (y & 0x1) << shift_count++; + y >>= 1; + log2_height--; + } + + if (log2_depth) + { + offset |= (z & 0x1) << shift_count++; + z >>= 1; + log2_depth--; + } } + while (x | y | z); - return result; + return offset; } /* Note: What the ps3 calls swizzling in this case is actually z-ordering / morton ordering of pixels @@ -332,13 +347,17 @@ namespace rsx T *src = static_cast(input_pixels); T *dst = static_cast(output_pixels); + const u32 log2_w = ceil_log2(width); + const u32 log2_h = ceil_log2(height); + const u32 log2_d = ceil_log2(depth); + for (u32 z = 0; z < depth; ++z) { for (u32 y = 0; y < height; ++y) { for (u32 x = 0; x < width; ++x) { - *dst++ = src[calculate_z_index(x, y, z)]; + *dst++ = src[calculate_z_index(x, y, z, log2_w, log2_h, log2_d)]; } } }