summaryrefslogtreecommitdiff
path: root/src/video_core/textures/decoders.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2019-06-13 16:41:16 -0400
committerGravatar ReinUsesLisp2019-06-20 21:38:34 -0300
commit7232a1ed16e46715c29d781fb143bdf799090bec (patch)
treeb3be910260ee9c0e3eb67fa007f81c9296a60d72 /src/video_core/textures/decoders.cpp
parenttexture_cache: Use siblings textures on Rebuild and fix possible error on bli... (diff)
downloadyuzu-7232a1ed16e46715c29d781fb143bdf799090bec.tar.gz
yuzu-7232a1ed16e46715c29d781fb143bdf799090bec.tar.xz
yuzu-7232a1ed16e46715c29d781fb143bdf799090bec.zip
decoders: correct block calculation
Diffstat (limited to 'src/video_core/textures/decoders.cpp')
-rw-r--r--src/video_core/textures/decoders.cpp34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp
index f45fd175a..9a2f4198a 100644
--- a/src/video_core/textures/decoders.cpp
+++ b/src/video_core/textures/decoders.cpp
@@ -256,19 +256,18 @@ std::vector<u8> UnswizzleTexture(u8* address, u32 tile_size_x, u32 tile_size_y,
256} 256}
257 257
258void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 swizzled_width, 258void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 swizzled_width,
259 u32 bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data, u32 block_height) { 259 u32 bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data, u32 block_height_bit) {
260 const u32 block_height_size{1U << block_height}; 260 const u32 block_height = 1U << block_height_bit;
261 const u32 image_width_in_gobs{(swizzled_width * bytes_per_pixel + (gob_size_x - 1)) / 261 const u32 image_width_in_gobs{(swizzled_width * bytes_per_pixel + (gob_size_x - 1)) /
262 gob_size_x}; 262 gob_size_x};
263 for (u32 line = 0; line < subrect_height; ++line) { 263 for (u32 line = 0; line < subrect_height; ++line) {
264 const u32 gob_address_y = 264 const u32 gob_address_y =
265 (line / (gob_size_y * block_height_size)) * gob_size * block_height_size * 265 (line / (gob_size_y * block_height)) * gob_size * block_height * image_width_in_gobs +
266 image_width_in_gobs + 266 ((line % (gob_size_y * block_height)) / gob_size_y) * gob_size;
267 ((line % (gob_size_y * block_height_size)) / gob_size_y) * gob_size;
268 const auto& table = legacy_swizzle_table[line % gob_size_y]; 267 const auto& table = legacy_swizzle_table[line % gob_size_y];
269 for (u32 x = 0; x < subrect_width; ++x) { 268 for (u32 x = 0; x < subrect_width; ++x) {
270 const u32 gob_address = 269 const u32 gob_address =
271 gob_address_y + (x * bytes_per_pixel / gob_size_x) * gob_size * block_height_size; 270 gob_address_y + (x * bytes_per_pixel / gob_size_x) * gob_size * block_height;
272 const u32 swizzled_offset = gob_address + table[(x * bytes_per_pixel) % gob_size_x]; 271 const u32 swizzled_offset = gob_address + table[(x * bytes_per_pixel) % gob_size_x];
273 u8* source_line = unswizzled_data + line * source_pitch + x * bytes_per_pixel; 272 u8* source_line = unswizzled_data + line * source_pitch + x * bytes_per_pixel;
274 u8* dest_addr = swizzled_data + swizzled_offset; 273 u8* dest_addr = swizzled_data + swizzled_offset;
@@ -279,19 +278,17 @@ void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32
279} 278}
280 279
281void UnswizzleSubrect(u32 subrect_width, u32 subrect_height, u32 dest_pitch, u32 swizzled_width, 280void UnswizzleSubrect(u32 subrect_width, u32 subrect_height, u32 dest_pitch, u32 swizzled_width,
282 u32 bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data, u32 block_height, 281 u32 bytes_per_pixel, u8* swizzled_data, u8* unswizzled_data, u32 block_height_bit,
283 u32 offset_x, u32 offset_y) { 282 u32 offset_x, u32 offset_y) {
284 const u32 block_height_size{1U << block_height}; 283 const u32 block_height = 1U << block_height_bit;
285 for (u32 line = 0; line < subrect_height; ++line) { 284 for (u32 line = 0; line < subrect_height; ++line) {
286 const u32 y2 = line + offset_y; 285 const u32 y2 = line + offset_y;
287 const u32 gob_address_y = 286 const u32 gob_address_y = (y2 / (gob_size_y * block_height)) * gob_size * block_height +
288 (y2 / (gob_size_y * block_height_size)) * gob_size * block_height_size + 287 ((y2 % (gob_size_y * block_height)) / gob_size_y) * gob_size;
289 ((y2 % (gob_size_y * block_height_size)) / gob_size_y) * gob_size;
290 const auto& table = legacy_swizzle_table[y2 % gob_size_y]; 288 const auto& table = legacy_swizzle_table[y2 % gob_size_y];
291 for (u32 x = 0; x < subrect_width; ++x) { 289 for (u32 x = 0; x < subrect_width; ++x) {
292 const u32 x2 = (x + offset_x) * bytes_per_pixel; 290 const u32 x2 = (x + offset_x) * bytes_per_pixel;
293 const u32 gob_address = 291 const u32 gob_address = gob_address_y + (x2 / gob_size_x) * gob_size * block_height;
294 gob_address_y + (x2 / gob_size_x) * gob_size * block_height_size;
295 const u32 swizzled_offset = gob_address + table[x2 % gob_size_x]; 292 const u32 swizzled_offset = gob_address + table[x2 % gob_size_x];
296 u8* dest_line = unswizzled_data + line * dest_pitch + x * bytes_per_pixel; 293 u8* dest_line = unswizzled_data + line * dest_pitch + x * bytes_per_pixel;
297 u8* source_addr = swizzled_data + swizzled_offset; 294 u8* source_addr = swizzled_data + swizzled_offset;
@@ -302,20 +299,19 @@ void UnswizzleSubrect(u32 subrect_width, u32 subrect_height, u32 dest_pitch, u32
302} 299}
303 300
304void SwizzleKepler(const u32 width, const u32 height, const u32 dst_x, const u32 dst_y, 301void SwizzleKepler(const u32 width, const u32 height, const u32 dst_x, const u32 dst_y,
305 const u32 block_height, const std::size_t copy_size, const u8* source_data, 302 const u32 block_height_bit, const std::size_t copy_size, const u8* source_data,
306 u8* swizzle_data) { 303 u8* swizzle_data) {
307 const u32 block_height_size{1U << block_height}; 304 const u32 block_height = 1U << block_height_bit;
308 const u32 image_width_in_gobs{(width + gob_size_x - 1) / gob_size_x}; 305 const u32 image_width_in_gobs{(width + gob_size_x - 1) / gob_size_x};
309 std::size_t count = 0; 306 std::size_t count = 0;
310 for (std::size_t y = dst_y; y < height && count < copy_size; ++y) { 307 for (std::size_t y = dst_y; y < height && count < copy_size; ++y) {
311 const std::size_t gob_address_y = 308 const std::size_t gob_address_y =
312 (y / (gob_size_y * block_height_size)) * gob_size * block_height_size * 309 (y / (gob_size_y * block_height)) * gob_size * block_height * image_width_in_gobs +
313 image_width_in_gobs + 310 ((y % (gob_size_y * block_height)) / gob_size_y) * gob_size;
314 ((y % (gob_size_y * block_height_size)) / gob_size_y) * gob_size;
315 const auto& table = legacy_swizzle_table[y % gob_size_y]; 311 const auto& table = legacy_swizzle_table[y % gob_size_y];
316 for (std::size_t x = dst_x; x < width && count < copy_size; ++x) { 312 for (std::size_t x = dst_x; x < width && count < copy_size; ++x) {
317 const std::size_t gob_address = 313 const std::size_t gob_address =
318 gob_address_y + (x / gob_size_x) * gob_size * block_height_size; 314 gob_address_y + (x / gob_size_x) * gob_size * block_height;
319 const std::size_t swizzled_offset = gob_address + table[x % gob_size_x]; 315 const std::size_t swizzled_offset = gob_address + table[x % gob_size_x];
320 const u8* source_line = source_data + count; 316 const u8* source_line = source_data + count;
321 u8* dest_addr = swizzle_data + swizzled_offset; 317 u8* dest_addr = swizzle_data + swizzled_offset;