diff options
| author | 2018-09-20 23:48:24 -0400 | |
|---|---|---|
| committer | 2018-09-21 10:57:12 -0400 | |
| commit | 68aaa83836af2b582204c264670086ea94a2ee58 (patch) | |
| tree | a4b244400c039ee7f4bc5521a5d6b41573d00b40 /src | |
| parent | Improved fast swizzle and removed restrictions to it (diff) | |
| download | yuzu-68aaa83836af2b582204c264670086ea94a2ee58.tar.gz yuzu-68aaa83836af2b582204c264670086ea94a2ee58.tar.xz yuzu-68aaa83836af2b582204c264670086ea94a2ee58.zip | |
Improved Legacy Swizzler to be better documented and work better
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/textures/decoders.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp index 225c999dc..89d218bc7 100644 --- a/src/video_core/textures/decoders.cpp +++ b/src/video_core/textures/decoders.cpp | |||
| @@ -14,17 +14,12 @@ namespace Tegra::Texture { | |||
| 14 | 14 | ||
| 15 | /** | 15 | /** |
| 16 | * Calculates the offset of an (x, y) position within a swizzled texture. | 16 | * Calculates the offset of an (x, y) position within a swizzled texture. |
| 17 | * Taken from the Tegra X1 TRM. | 17 | * Taken from the Tegra X1 Technical Reference Manual. pages 1187-1188 |
| 18 | */ | 18 | */ |
| 19 | static u32 GetSwizzleOffset(u32 x, u32 y, u32 image_width, u32 bytes_per_pixel, u32 block_height) { | 19 | static u32 GetSwizzleOffset(u32 x, u32 y, u32 bytes_per_pixel, u32 gob_address) { |
| 20 | // Round up to the next gob | 20 | // Round up to the next gob |
| 21 | const u32 image_width_in_gobs{(image_width * bytes_per_pixel + 63) / 64}; | ||
| 22 | |||
| 23 | u32 GOB_address = 0 + (y / (8 * block_height)) * 512 * block_height * image_width_in_gobs + | ||
| 24 | (x * bytes_per_pixel / 64) * 512 * block_height + | ||
| 25 | (y % (8 * block_height) / 8) * 512; | ||
| 26 | x *= bytes_per_pixel; | 21 | x *= bytes_per_pixel; |
| 27 | u32 address = GOB_address + ((x % 64) / 32) * 256 + ((y % 8) / 2) * 64 + ((x % 32) / 16) * 32 + | 22 | u32 address = gob_address + ((x % 64) / 32) * 256 + ((y % 8) / 2) * 64 + ((x % 32) / 16) * 32 + |
| 28 | (y % 2) * 16 + (x % 16); | 23 | (y % 2) * 16 + (x % 16); |
| 29 | 24 | ||
| 30 | return address; | 25 | return address; |
| @@ -32,21 +27,31 @@ static u32 GetSwizzleOffset(u32 x, u32 y, u32 image_width, u32 bytes_per_pixel, | |||
| 32 | 27 | ||
| 33 | void CopySwizzledData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_per_pixel, | 28 | void CopySwizzledData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_per_pixel, |
| 34 | u8* swizzled_data, u8* unswizzled_data, bool unswizzle, u32 block_height) { | 29 | u8* swizzled_data, u8* unswizzled_data, bool unswizzle, u32 block_height) { |
| 35 | u8* data_ptrs[2]; | 30 | std::array<u8*, 2> data_ptrs; |
| 31 | const u32 stride = width * bytes_per_pixel; | ||
| 32 | const u32 gobs_in_x = 64; | ||
| 33 | const u32 gobs_in_y = 8; | ||
| 34 | const u32 gobs_size = gobs_in_x * gobs_in_y; | ||
| 35 | const u32 image_width_in_gobs{(stride + gobs_in_x - 1) / gobs_in_x}; | ||
| 36 | for (unsigned y = 0; y < height; ++y) { | 36 | for (unsigned y = 0; y < height; ++y) { |
| 37 | const u32 gob_y_address = | ||
| 38 | (y / (gobs_in_y * block_height)) * gobs_size * block_height * image_width_in_gobs + | ||
| 39 | (y % (gobs_in_y * block_height) / gobs_in_y) * gobs_size; | ||
| 37 | for (unsigned x = 0; x < width; ++x) { | 40 | for (unsigned x = 0; x < width; ++x) { |
| 38 | u32 swizzle_offset = GetSwizzleOffset(x, y, width, bytes_per_pixel, block_height); | 41 | const u32 gob_address = |
| 39 | u32 pixel_index = (x + y * width) * out_bytes_per_pixel; | 42 | gob_y_address + (x * bytes_per_pixel / gobs_in_x) * gobs_size * block_height; |
| 43 | const u32 swizzle_offset = GetSwizzleOffset(x, y, bytes_per_pixel, gob_address); | ||
| 44 | const u32 pixel_index = (x + y * width) * out_bytes_per_pixel; | ||
| 40 | 45 | ||
| 41 | data_ptrs[unswizzle] = swizzled_data + swizzle_offset; | 46 | data_ptrs[unswizzle] = swizzled_data + swizzle_offset; |
| 42 | data_ptrs[!unswizzle] = &unswizzled_data[pixel_index]; | 47 | data_ptrs[!unswizzle] = unswizzled_data + pixel_index; |
| 43 | 48 | ||
| 44 | std::memcpy(data_ptrs[0], data_ptrs[1], bytes_per_pixel); | 49 | std::memcpy(data_ptrs[0], data_ptrs[1], bytes_per_pixel); |
| 45 | } | 50 | } |
| 46 | } | 51 | } |
| 47 | } | 52 | } |
| 48 | 53 | ||
| 49 | //This table represents the internal swizzle of a gob. | 54 | // This table represents the internal swizzle of a gob. |
| 50 | template <std::size_t N, std::size_t M> | 55 | template <std::size_t N, std::size_t M> |
| 51 | struct alignas(64) SwizzleTable { | 56 | struct alignas(64) SwizzleTable { |
| 52 | constexpr SwizzleTable() { | 57 | constexpr SwizzleTable() { |
| @@ -72,7 +77,7 @@ void FastSwizzleData(u32 width, u32 height, u32 bytes_per_pixel, u8* swizzled_da | |||
| 72 | const std::size_t stride{width * bytes_per_pixel}; | 77 | const std::size_t stride{width * bytes_per_pixel}; |
| 73 | const std::size_t gobs_in_x = 64; | 78 | const std::size_t gobs_in_x = 64; |
| 74 | const std::size_t gobs_in_y = 8; | 79 | const std::size_t gobs_in_y = 8; |
| 75 | const std::size_t gobs_size = gobs_in_x*gobs_in_y; | 80 | const std::size_t gobs_size = gobs_in_x * gobs_in_y; |
| 76 | const std::size_t image_width_in_gobs{(stride + gobs_in_x - 1) / gobs_in_x}; | 81 | const std::size_t image_width_in_gobs{(stride + gobs_in_x - 1) / gobs_in_x}; |
| 77 | const std::size_t copy_size{16}; | 82 | const std::size_t copy_size{16}; |
| 78 | for (std::size_t y = 0; y < height; ++y) { | 83 | for (std::size_t y = 0; y < height; ++y) { |
| @@ -83,7 +88,8 @@ void FastSwizzleData(u32 width, u32 height, u32 bytes_per_pixel, u8* swizzled_da | |||
| 83 | const auto& table = swizzle_table[y % gobs_in_y]; | 88 | const auto& table = swizzle_table[y % gobs_in_y]; |
| 84 | for (std::size_t xb = 0; xb < stride; xb += copy_size) { | 89 | for (std::size_t xb = 0; xb < stride; xb += copy_size) { |
| 85 | const std::size_t truncated_copy = std::min(copy_size, stride - xb); | 90 | const std::size_t truncated_copy = std::min(copy_size, stride - xb); |
| 86 | const std::size_t gob_address{initial_gob + (xb / gobs_in_x) * gobs_size * block_height}; | 91 | const std::size_t gob_address{initial_gob + |
| 92 | (xb / gobs_in_x) * gobs_size * block_height}; | ||
| 87 | const std::size_t swizzle_offset{gob_address + table[(xb / 16) % 4]}; | 93 | const std::size_t swizzle_offset{gob_address + table[(xb / 16) % 4]}; |
| 88 | const std::size_t pixel_index{xb + pixel_base}; | 94 | const std::size_t pixel_index{xb + pixel_base}; |
| 89 | data_ptrs[unswizzle] = swizzled_data + swizzle_offset; | 95 | data_ptrs[unswizzle] = swizzled_data + swizzle_offset; |