Join both Swizzle methods within one interface function

This commit is contained in:
FernandoS27 2018-09-21 11:42:34 -04:00
parent 41c6c4593a
commit d2dd1289bd

View file

@ -39,8 +39,9 @@ struct alignas(64) SwizzleTable {
constexpr auto legacy_swizzle_table = SwizzleTable<8, 64, 1>(); constexpr auto legacy_swizzle_table = SwizzleTable<8, 64, 1>();
constexpr auto fast_swizzle_table = SwizzleTable<8, 4, 16>(); constexpr auto fast_swizzle_table = SwizzleTable<8, 4, 16>();
void CopySwizzledData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_per_pixel, static void LegacySwizzleData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_per_pixel,
u8* swizzled_data, u8* unswizzled_data, bool unswizzle, u32 block_height) { u8* swizzled_data, u8* unswizzled_data, bool unswizzle,
u32 block_height) {
std::array<u8*, 2> data_ptrs; std::array<u8*, 2> data_ptrs;
const std::size_t stride = width * bytes_per_pixel; const std::size_t stride = width * bytes_per_pixel;
const std::size_t gobs_in_x = 64; const std::size_t gobs_in_x = 64;
@ -67,8 +68,9 @@ void CopySwizzledData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_
} }
} }
void FastSwizzleData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_per_pixel, static void FastSwizzleData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_per_pixel,
u8* swizzled_data, u8* unswizzled_data, bool unswizzle, u32 block_height) { u8* swizzled_data, u8* unswizzled_data, bool unswizzle,
u32 block_height) {
std::array<u8*, 2> data_ptrs; std::array<u8*, 2> data_ptrs;
const std::size_t stride{width * bytes_per_pixel}; const std::size_t stride{width * bytes_per_pixel};
const std::size_t gobs_in_x = 64; const std::size_t gobs_in_x = 64;
@ -96,6 +98,17 @@ void FastSwizzleData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_p
} }
} }
void CopySwizzledData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_per_pixel,
u8* swizzled_data, u8* unswizzled_data, bool unswizzle, u32 block_height) {
if (bytes_per_pixel % 3 != 0) {
FastSwizzleData(width, height, bytes_per_pixel, out_bytes_per_pixel, swizzled_data,
unswizzled_data, unswizzle, block_height);
} else {
LegacySwizzleData(width, height, bytes_per_pixel, out_bytes_per_pixel, swizzled_data,
unswizzled_data, unswizzle, block_height);
}
}
u32 BytesPerPixel(TextureFormat format) { u32 BytesPerPixel(TextureFormat format) {
switch (format) { switch (format) {
case TextureFormat::DXT1: case TextureFormat::DXT1:
@ -142,13 +155,8 @@ u32 BytesPerPixel(TextureFormat format) {
std::vector<u8> UnswizzleTexture(VAddr address, u32 tile_size, u32 bytes_per_pixel, u32 width, std::vector<u8> UnswizzleTexture(VAddr address, u32 tile_size, u32 bytes_per_pixel, u32 width,
u32 height, u32 block_height) { u32 height, u32 block_height) {
std::vector<u8> unswizzled_data(width * height * bytes_per_pixel); std::vector<u8> unswizzled_data(width * height * bytes_per_pixel);
if (bytes_per_pixel % 3 != 0) { CopySwizzledData(width / tile_size, height / tile_size, bytes_per_pixel, bytes_per_pixel,
FastSwizzleData(width / tile_size, height / tile_size, bytes_per_pixel, bytes_per_pixel, Memory::GetPointer(address), unswizzled_data.data(), true, block_height);
Memory::GetPointer(address), unswizzled_data.data(), true, block_height);
} else {
CopySwizzledData(width / tile_size, height / tile_size, bytes_per_pixel, bytes_per_pixel,
Memory::GetPointer(address), unswizzled_data.data(), true, block_height);
}
return unswizzled_data; return unswizzled_data;
} }