diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/textures/decoders.cpp | 70 |
1 files changed, 33 insertions, 37 deletions
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp index 19f30b1b5..7040d9bf5 100644 --- a/src/video_core/textures/decoders.cpp +++ b/src/video_core/textures/decoders.cpp | |||
| @@ -37,8 +37,14 @@ struct alignas(64) SwizzleTable { | |||
| 37 | std::array<std::array<u16, M>, N> values{}; | 37 | std::array<std::array<u16, M>, N> values{}; |
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| 40 | constexpr auto legacy_swizzle_table = SwizzleTable<8, 64, 1>(); | 40 | constexpr u32 gob_size_x = 64; |
| 41 | constexpr auto fast_swizzle_table = SwizzleTable<8, 4, 16>(); | 41 | constexpr u32 gob_size_y = 8; |
| 42 | constexpr u32 gob_size_z = 1; | ||
| 43 | constexpr u32 gob_size = gob_size_x * gob_size_y * gob_size_z; | ||
| 44 | constexpr u32 fast_swizzle_align = 16; | ||
| 45 | |||
| 46 | constexpr auto legacy_swizzle_table = SwizzleTable<gob_size_y, gob_size_x, gob_size_z>(); | ||
| 47 | constexpr auto fast_swizzle_table = SwizzleTable<gob_size_y, 4, fast_swizzle_align>(); | ||
| 42 | 48 | ||
| 43 | /** | 49 | /** |
| 44 | * This function manages ALL the GOBs(Group of Bytes) Inside a single block. | 50 | * This function manages ALL the GOBs(Group of Bytes) Inside a single block. |
| @@ -52,10 +58,7 @@ void PreciseProcessBlock(u8* const swizzled_data, u8* const unswizzled_data, con | |||
| 52 | const u32 bytes_per_pixel, const u32 out_bytes_per_pixel) { | 58 | const u32 bytes_per_pixel, const u32 out_bytes_per_pixel) { |
| 53 | std::array<u8*, 2> data_ptrs; | 59 | std::array<u8*, 2> data_ptrs; |
| 54 | u32 z_address = tile_offset; | 60 | u32 z_address = tile_offset; |
| 55 | const u32 gob_size_x = 64; | 61 | |
| 56 | const u32 gob_size_y = 8; | ||
| 57 | const u32 gob_size_z = 1; | ||
| 58 | const u32 gob_size = gob_size_x * gob_size_y * gob_size_z; | ||
| 59 | for (u32 z = z_start; z < z_end; z++) { | 62 | for (u32 z = z_start; z < z_end; z++) { |
| 60 | u32 y_address = z_address; | 63 | u32 y_address = z_address; |
| 61 | u32 pixel_base = layer_z * z + y_start * stride_x; | 64 | u32 pixel_base = layer_z * z + y_start * stride_x; |
| @@ -90,23 +93,19 @@ void FastProcessBlock(u8* const swizzled_data, u8* const unswizzled_data, const | |||
| 90 | u32 z_address = tile_offset; | 93 | u32 z_address = tile_offset; |
| 91 | const u32 x_startb = x_start * bytes_per_pixel; | 94 | const u32 x_startb = x_start * bytes_per_pixel; |
| 92 | const u32 x_endb = x_end * bytes_per_pixel; | 95 | const u32 x_endb = x_end * bytes_per_pixel; |
| 93 | constexpr u32 copy_size = 16; | 96 | |
| 94 | constexpr u32 gob_size_x = 64; | ||
| 95 | constexpr u32 gob_size_y = 8; | ||
| 96 | constexpr u32 gob_size_z = 1; | ||
| 97 | const u32 gob_size = gob_size_x * gob_size_y * gob_size_z; | ||
| 98 | for (u32 z = z_start; z < z_end; z++) { | 97 | for (u32 z = z_start; z < z_end; z++) { |
| 99 | u32 y_address = z_address; | 98 | u32 y_address = z_address; |
| 100 | u32 pixel_base = layer_z * z + y_start * stride_x; | 99 | u32 pixel_base = layer_z * z + y_start * stride_x; |
| 101 | for (u32 y = y_start; y < y_end; y++) { | 100 | for (u32 y = y_start; y < y_end; y++) { |
| 102 | const auto& table = fast_swizzle_table[y % gob_size_y]; | 101 | const auto& table = fast_swizzle_table[y % gob_size_y]; |
| 103 | for (u32 xb = x_startb; xb < x_endb; xb += copy_size) { | 102 | for (u32 xb = x_startb; xb < x_endb; xb += fast_swizzle_align) { |
| 104 | const u32 swizzle_offset{y_address + table[(xb / copy_size) % 4]}; | 103 | const u32 swizzle_offset{y_address + table[(xb / fast_swizzle_align) % 4]}; |
| 105 | const u32 out_x = xb * out_bytes_per_pixel / bytes_per_pixel; | 104 | const u32 out_x = xb * out_bytes_per_pixel / bytes_per_pixel; |
| 106 | const u32 pixel_index{out_x + pixel_base}; | 105 | const u32 pixel_index{out_x + pixel_base}; |
| 107 | data_ptrs[unswizzle] = swizzled_data + swizzle_offset; | 106 | data_ptrs[unswizzle] = swizzled_data + swizzle_offset; |
| 108 | data_ptrs[!unswizzle] = unswizzled_data + pixel_index; | 107 | data_ptrs[!unswizzle] = unswizzled_data + pixel_index; |
| 109 | std::memcpy(data_ptrs[0], data_ptrs[1], copy_size); | 108 | std::memcpy(data_ptrs[0], data_ptrs[1], fast_swizzle_align); |
| 110 | } | 109 | } |
| 111 | pixel_base += stride_x; | 110 | pixel_base += stride_x; |
| 112 | if ((y + 1) % gob_size_y == 0) | 111 | if ((y + 1) % gob_size_y == 0) |
| @@ -132,17 +131,15 @@ void SwizzledData(u8* const swizzled_data, u8* const unswizzled_data, const bool | |||
| 132 | auto div_ceil = [](const u32 x, const u32 y) { return ((x + y - 1) / y); }; | 131 | auto div_ceil = [](const u32 x, const u32 y) { return ((x + y - 1) / y); }; |
| 133 | const u32 stride_x = width * out_bytes_per_pixel; | 132 | const u32 stride_x = width * out_bytes_per_pixel; |
| 134 | const u32 layer_z = height * stride_x; | 133 | const u32 layer_z = height * stride_x; |
| 135 | constexpr u32 gob_x_bytes = 64; | 134 | const u32 gob_elements_x = gob_size_x / bytes_per_pixel; |
| 136 | const u32 gob_elements_x = gob_x_bytes / bytes_per_pixel; | 135 | constexpr u32 gob_elements_y = gob_size_y; |
| 137 | constexpr u32 gob_elements_y = 8; | 136 | constexpr u32 gob_elements_z = gob_size_z; |
| 138 | constexpr u32 gob_elements_z = 1; | ||
| 139 | const u32 block_x_elements = gob_elements_x; | 137 | const u32 block_x_elements = gob_elements_x; |
| 140 | const u32 block_y_elements = gob_elements_y * block_height; | 138 | const u32 block_y_elements = gob_elements_y * block_height; |
| 141 | const u32 block_z_elements = gob_elements_z * block_depth; | 139 | const u32 block_z_elements = gob_elements_z * block_depth; |
| 142 | const u32 blocks_on_x = div_ceil(width, block_x_elements); | 140 | const u32 blocks_on_x = div_ceil(width, block_x_elements); |
| 143 | const u32 blocks_on_y = div_ceil(height, block_y_elements); | 141 | const u32 blocks_on_y = div_ceil(height, block_y_elements); |
| 144 | const u32 blocks_on_z = div_ceil(depth, block_z_elements); | 142 | const u32 blocks_on_z = div_ceil(depth, block_z_elements); |
| 145 | constexpr u32 gob_size = gob_x_bytes * gob_elements_y * gob_elements_z; | ||
| 146 | const u32 xy_block_size = gob_size * block_height; | 143 | const u32 xy_block_size = gob_size * block_height; |
| 147 | const u32 block_size = xy_block_size * block_depth; | 144 | const u32 block_size = xy_block_size * block_depth; |
| 148 | u32 tile_offset = 0; | 145 | u32 tile_offset = 0; |
| @@ -173,7 +170,7 @@ void SwizzledData(u8* const swizzled_data, u8* const unswizzled_data, const bool | |||
| 173 | void CopySwizzledData(u32 width, u32 height, u32 depth, u32 bytes_per_pixel, | 170 | void CopySwizzledData(u32 width, u32 height, u32 depth, u32 bytes_per_pixel, |
| 174 | u32 out_bytes_per_pixel, u8* const swizzled_data, u8* const unswizzled_data, | 171 | u32 out_bytes_per_pixel, u8* const swizzled_data, u8* const unswizzled_data, |
| 175 | bool unswizzle, u32 block_height, u32 block_depth) { | 172 | bool unswizzle, u32 block_height, u32 block_depth) { |
| 176 | if (bytes_per_pixel % 3 != 0 && (width * bytes_per_pixel) % 16 == 0) { | 173 | if (bytes_per_pixel % 3 != 0 && (width * bytes_per_pixel) % fast_swizzle_align == 0) { |
| 177 | SwizzledData<true>(swizzled_data, unswizzled_data, unswizzle, width, height, depth, | 174 | SwizzledData<true>(swizzled_data, unswizzled_data, unswizzle, width, height, depth, |
| 178 | bytes_per_pixel, out_bytes_per_pixel, block_height, block_depth); | 175 | bytes_per_pixel, out_bytes_per_pixel, block_height, block_depth); |
| 179 | } else { | 176 | } else { |
| @@ -243,15 +240,17 @@ std::vector<u8> UnswizzleTexture(VAddr address, u32 tile_size_x, u32 tile_size_y | |||
| 243 | void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 swizzled_width, | 240 | void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 swizzled_width, |
| 244 | u32 bytes_per_pixel, VAddr swizzled_data, VAddr unswizzled_data, | 241 | u32 bytes_per_pixel, VAddr swizzled_data, VAddr unswizzled_data, |
| 245 | u32 block_height) { | 242 | u32 block_height) { |
| 246 | const u32 image_width_in_gobs{(swizzled_width * bytes_per_pixel + 63) / 64}; | 243 | const u32 image_width_in_gobs{(swizzled_width * bytes_per_pixel + (gob_size_x - 1)) / |
| 244 | gob_size_x}; | ||
| 247 | for (u32 line = 0; line < subrect_height; ++line) { | 245 | for (u32 line = 0; line < subrect_height; ++line) { |
| 248 | const u32 gob_address_y = | 246 | const u32 gob_address_y = |
| 249 | (line / (8 * block_height)) * 512 * block_height * image_width_in_gobs + | 247 | (line / (gob_size_y * block_height)) * gob_size * block_height * image_width_in_gobs + |
| 250 | (line % (8 * block_height) / 8) * 512; | 248 | ((line % (gob_size_y * block_height)) / gob_size_y) * gob_size; |
| 251 | const auto& table = legacy_swizzle_table[line % 8]; | 249 | const auto& table = legacy_swizzle_table[line % gob_size_y]; |
| 252 | for (u32 x = 0; x < subrect_width; ++x) { | 250 | for (u32 x = 0; x < subrect_width; ++x) { |
| 253 | const u32 gob_address = gob_address_y + (x * bytes_per_pixel / 64) * 512 * block_height; | 251 | const u32 gob_address = |
| 254 | const u32 swizzled_offset = gob_address + table[(x * bytes_per_pixel) % 64]; | 252 | gob_address_y + (x * bytes_per_pixel / gob_size_x) * gob_size * block_height; |
| 253 | const u32 swizzled_offset = gob_address + table[(x * bytes_per_pixel) % gob_size_x]; | ||
| 255 | const VAddr source_line = unswizzled_data + line * source_pitch + x * bytes_per_pixel; | 254 | const VAddr source_line = unswizzled_data + line * source_pitch + x * bytes_per_pixel; |
| 256 | const VAddr dest_addr = swizzled_data + swizzled_offset; | 255 | const VAddr dest_addr = swizzled_data + swizzled_offset; |
| 257 | 256 | ||
| @@ -265,13 +264,13 @@ void UnswizzleSubrect(u32 subrect_width, u32 subrect_height, u32 dest_pitch, u32 | |||
| 265 | u32 block_height, u32 offset_x, u32 offset_y) { | 264 | u32 block_height, u32 offset_x, u32 offset_y) { |
| 266 | for (u32 line = 0; line < subrect_height; ++line) { | 265 | for (u32 line = 0; line < subrect_height; ++line) { |
| 267 | const u32 y2 = line + offset_y; | 266 | const u32 y2 = line + offset_y; |
| 268 | const u32 gob_address_y = | 267 | const u32 gob_address_y = (y2 / (gob_size_y * block_height)) * gob_size * block_height + |
| 269 | (y2 / (8 * block_height)) * 512 * block_height + (y2 % (8 * block_height) / 8) * 512; | 268 | ((y2 % (gob_size_y * block_height)) / gob_size_y) * gob_size; |
| 270 | const auto& table = legacy_swizzle_table[y2 % 8]; | 269 | const auto& table = legacy_swizzle_table[y2 % gob_size_y]; |
| 271 | for (u32 x = 0; x < subrect_width; ++x) { | 270 | for (u32 x = 0; x < subrect_width; ++x) { |
| 272 | const u32 x2 = (x + offset_x) * bytes_per_pixel; | 271 | const u32 x2 = (x + offset_x) * bytes_per_pixel; |
| 273 | const u32 gob_address = gob_address_y + (x2 / 64) * 512 * block_height; | 272 | const u32 gob_address = gob_address_y + (x2 / gob_size_x) * gob_size * block_height; |
| 274 | const u32 swizzled_offset = gob_address + table[x2 % 64]; | 273 | const u32 swizzled_offset = gob_address + table[x2 % gob_size_x]; |
| 275 | const VAddr dest_line = unswizzled_data + line * dest_pitch + x * bytes_per_pixel; | 274 | const VAddr dest_line = unswizzled_data + line * dest_pitch + x * bytes_per_pixel; |
| 276 | const VAddr source_addr = swizzled_data + swizzled_offset; | 275 | const VAddr source_addr = swizzled_data + swizzled_offset; |
| 277 | 276 | ||
| @@ -325,12 +324,9 @@ std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat | |||
| 325 | std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, | 324 | std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, |
| 326 | u32 block_height, u32 block_depth) { | 325 | u32 block_height, u32 block_depth) { |
| 327 | if (tiled) { | 326 | if (tiled) { |
| 328 | constexpr u32 gobs_in_x = 64; | 327 | const u32 aligned_width = Common::AlignUp(width * bytes_per_pixel, gob_size_x); |
| 329 | constexpr u32 gobs_in_y = 8; | 328 | const u32 aligned_height = Common::AlignUp(height, gob_size_y * block_height); |
| 330 | constexpr u32 gobs_in_z = 1; | 329 | const u32 aligned_depth = Common::AlignUp(depth, gob_size_z * block_depth); |
| 331 | const u32 aligned_width = Common::AlignUp(width * bytes_per_pixel, gobs_in_x); | ||
| 332 | const u32 aligned_height = Common::AlignUp(height, gobs_in_y * block_height); | ||
| 333 | const u32 aligned_depth = Common::AlignUp(depth, gobs_in_z * block_depth); | ||
| 334 | return aligned_width * aligned_height * aligned_depth; | 330 | return aligned_width * aligned_height * aligned_depth; |
| 335 | } else { | 331 | } else { |
| 336 | return width * height * depth * bytes_per_pixel; | 332 | return width * height * depth * bytes_per_pixel; |