diff options
| author | 2018-10-10 22:03:38 -0400 | |
|---|---|---|
| committer | 2018-10-13 15:25:15 -0400 | |
| commit | 736db284d2d98a0603620a205d90942810fa531f (patch) | |
| tree | 26cd3890f354eb4b88c30a1f78fb54d6551a7e3f /src/video_core/textures/decoders.cpp | |
| parent | Merge pull request #1409 from DarkLordZach/key-derivation (diff) | |
| download | yuzu-736db284d2d98a0603620a205d90942810fa531f.tar.gz yuzu-736db284d2d98a0603620a205d90942810fa531f.tar.xz yuzu-736db284d2d98a0603620a205d90942810fa531f.zip | |
Implement Fast 3D Swizzle
Diffstat (limited to 'src/video_core/textures/decoders.cpp')
| -rw-r--r-- | src/video_core/textures/decoders.cpp | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp index 0d2456b56..8ae6dcf9a 100644 --- a/src/video_core/textures/decoders.cpp +++ b/src/video_core/textures/decoders.cpp | |||
| @@ -98,11 +98,83 @@ static void FastSwizzleData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_ | |||
| 98 | } | 98 | } |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | void Fast3DProcessGobs(u8* swizzled_data, u8* unswizzled_data, bool unswizzle, const u32 x_start, | ||
| 102 | const u32 y_start, const u32 z_start, const u32 x_end, const u32 y_end, | ||
| 103 | const u32 z_end, const u32 tile_offset, const u32 xy_block_size, | ||
| 104 | const u32 layer_z, const u32 stride_x, const u32 bytes_per_pixel, | ||
| 105 | const u32 out_bytes_per_pixel) { | ||
| 106 | std::array<u8*, 2> data_ptrs; | ||
| 107 | u32 z_adress = tile_offset; | ||
| 108 | const u32 x_startb = x_start * bytes_per_pixel; | ||
| 109 | const u32 x_endb = x_end * bytes_per_pixel; | ||
| 110 | const u32 copy_size = 16; | ||
| 111 | const u32 gob_size = 64 * 8 * 1; | ||
| 112 | for (u32 z = z_start; z < z_end; z++) { | ||
| 113 | u32 y_adress = z_adress; | ||
| 114 | u32 pixel_base = layer_z * z + y_start * stride_x; | ||
| 115 | for (u32 y = y_start; y < y_end; y++) { | ||
| 116 | const auto& table = fast_swizzle_table[y % 8]; | ||
| 117 | for (u32 xb = x_startb; xb < x_endb; xb += copy_size) { | ||
| 118 | const u32 swizzle_offset{y_adress + table[(xb / 16) % 4]}; | ||
| 119 | const u32 out_x = xb * out_bytes_per_pixel / bytes_per_pixel; | ||
| 120 | const u32 pixel_index{out_x + pixel_base}; | ||
| 121 | data_ptrs[unswizzle] = swizzled_data + swizzle_offset; | ||
| 122 | data_ptrs[!unswizzle] = unswizzled_data + pixel_index; | ||
| 123 | std::memcpy(data_ptrs[0], data_ptrs[1], copy_size); | ||
| 124 | } | ||
| 125 | pixel_base += stride_x; | ||
| 126 | if ((y + 1) % 8 == 0) | ||
| 127 | y_adress += gob_size; | ||
| 128 | } | ||
| 129 | z_adress += xy_block_size; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | void Fast3DSwizzledData(u8* swizzled_data, u8* unswizzled_data, bool unswizzle, u32 width, | ||
| 134 | u32 height, u32 depth, u32 bytes_per_pixel, u32 out_bytes_per_pixel, | ||
| 135 | u32 block_height, u32 block_depth) { | ||
| 136 | auto div_ceil = [](u32 x, u32 y) { return ((x + y - 1) / y); }; | ||
| 137 | |||
| 138 | const u32 stride_x = width * out_bytes_per_pixel; | ||
| 139 | const u32 layer_z = height * stride_x; | ||
| 140 | const u32 gob_x_bytes = 64; | ||
| 141 | const u32 gob_elements_x = gob_x_bytes / bytes_per_pixel; | ||
| 142 | const u32 gob_elements_y = 8; | ||
| 143 | const u32 gob_elements_z = 1; | ||
| 144 | const u32 block_x_elements = gob_elements_x; | ||
| 145 | const u32 block_y_elements = gob_elements_y * block_height; | ||
| 146 | const u32 block_z_elements = gob_elements_z * block_depth; | ||
| 147 | const u32 blocks_on_x = div_ceil(width, block_x_elements); | ||
| 148 | const u32 blocks_on_y = div_ceil(height, block_y_elements); | ||
| 149 | const u32 blocks_on_z = div_ceil(depth, block_z_elements); | ||
| 150 | const u32 blocks = blocks_on_x * blocks_on_y * blocks_on_z; | ||
| 151 | const u32 gob_size = 64 * 8 * 1; | ||
| 152 | const u32 xy_block_size = gob_size * block_height; | ||
| 153 | const u32 block_size = xy_block_size * block_depth; | ||
| 154 | u32 tile_offset = 0; | ||
| 155 | for (u32 zb = 0; zb < blocks_on_z; zb++) { | ||
| 156 | const u32 z_start = zb * block_z_elements; | ||
| 157 | const u32 z_end = std::min(depth, z_start + block_z_elements); | ||
| 158 | for (u32 yb = 0; yb < blocks_on_y; yb++) { | ||
| 159 | const u32 y_start = yb * block_y_elements; | ||
| 160 | const u32 y_end = std::min(height, y_start + block_y_elements); | ||
| 161 | for (u32 xb = 0; xb < blocks_on_x; xb++) { | ||
| 162 | const u32 x_start = xb * block_x_elements; | ||
| 163 | const u32 x_end = std::min(width, x_start + block_x_elements); | ||
| 164 | Fast3DProcessGobs(swizzled_data, unswizzled_data, unswizzle, x_start, y_start, | ||
| 165 | z_start, x_end, y_end, z_end, tile_offset, xy_block_size, layer_z, | ||
| 166 | stride_x, bytes_per_pixel, out_bytes_per_pixel); | ||
| 167 | tile_offset += block_size; | ||
| 168 | } | ||
| 169 | } | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 101 | void CopySwizzledData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_per_pixel, | 173 | void CopySwizzledData(u32 width, u32 height, u32 bytes_per_pixel, u32 out_bytes_per_pixel, |
| 102 | u8* swizzled_data, u8* unswizzled_data, bool unswizzle, u32 block_height) { | 174 | u8* swizzled_data, u8* unswizzled_data, bool unswizzle, u32 block_height) { |
| 103 | if (bytes_per_pixel % 3 != 0 && (width * bytes_per_pixel) % 16 == 0) { | 175 | if (bytes_per_pixel % 3 != 0 && (width * bytes_per_pixel) % 16 == 0) { |
| 104 | FastSwizzleData(width, height, bytes_per_pixel, out_bytes_per_pixel, swizzled_data, | 176 | Fast3DSwizzledData(swizzled_data, unswizzled_data, unswizzle, width, height, 1U, |
| 105 | unswizzled_data, unswizzle, block_height); | 177 | bytes_per_pixel, out_bytes_per_pixel, block_height, 1U); |
| 106 | } else { | 178 | } else { |
| 107 | LegacySwizzleData(width, height, bytes_per_pixel, out_bytes_per_pixel, swizzled_data, | 179 | LegacySwizzleData(width, height, bytes_per_pixel, out_bytes_per_pixel, swizzled_data, |
| 108 | unswizzled_data, unswizzle, block_height); | 180 | unswizzled_data, unswizzle, block_height); |