summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/textures/decoders.cpp40
-rw-r--r--src/video_core/textures/decoders.h9
2 files changed, 49 insertions, 0 deletions
diff --git a/src/video_core/textures/decoders.cpp b/src/video_core/textures/decoders.cpp
index 18ab723f7..f1b40e7f5 100644
--- a/src/video_core/textures/decoders.cpp
+++ b/src/video_core/textures/decoders.cpp
@@ -237,6 +237,46 @@ std::vector<u8> UnswizzleTexture(VAddr address, u32 tile_size, u32 bytes_per_pix
237 return unswizzled_data; 237 return unswizzled_data;
238} 238}
239 239
240void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 swizzled_width,
241 u32 bytes_per_pixel, VAddr swizzled_data, VAddr unswizzled_data,
242 u32 block_height) {
243 const u32 image_width_in_gobs{(swizzled_width * bytes_per_pixel + 63) / 64};
244 for (u32 line = 0; line < subrect_height; ++line) {
245 const u32 gob_address_y =
246 (line / (8 * block_height)) * 512 * block_height * image_width_in_gobs +
247 (line % (8 * block_height) / 8) * 512;
248 const auto& table = legacy_swizzle_table[line % 8];
249 for (u32 x = 0; x < subrect_width; ++x) {
250 const u32 gob_address = gob_address_y + (x * bytes_per_pixel / 64) * 512 * block_height;
251 const u32 swizzled_offset = gob_address + table[(x * bytes_per_pixel) % 64];
252 const VAddr source_line = unswizzled_data + line * source_pitch + x * bytes_per_pixel;
253 const VAddr dest_addr = swizzled_data + swizzled_offset;
254
255 Memory::CopyBlock(dest_addr, source_line, bytes_per_pixel);
256 }
257 }
258}
259
260void UnswizzleSubrect(u32 subrect_width, u32 subrect_height, u32 dest_pitch, u32 swizzled_width,
261 u32 bytes_per_pixel, VAddr swizzled_data, VAddr unswizzled_data,
262 u32 block_height, u32 offset_x, u32 offset_y) {
263 for (u32 line = 0; line < subrect_height; ++line) {
264 const u32 y2 = line + offset_y;
265 const u32 gob_address_y =
266 (y2 / (8 * block_height)) * 512 * block_height + (y2 % (8 * block_height) / 8) * 512;
267 const auto& table = legacy_swizzle_table[y2 % 8];
268 for (u32 x = 0; x < subrect_width; ++x) {
269 const u32 x2 = (x + offset_x) * bytes_per_pixel;
270 const u32 gob_address = gob_address_y + (x2 / 64) * 512 * block_height;
271 const u32 swizzled_offset = gob_address + table[x2 % 64];
272 const VAddr dest_line = unswizzled_data + line * dest_pitch + x * bytes_per_pixel;
273 const VAddr source_addr = swizzled_data + swizzled_offset;
274
275 Memory::CopyBlock(dest_line, source_addr, bytes_per_pixel);
276 }
277 }
278}
279
240std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat format, u32 width, 280std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat format, u32 width,
241 u32 height) { 281 u32 height) {
242 std::vector<u8> rgba_data; 282 std::vector<u8> rgba_data;
diff --git a/src/video_core/textures/decoders.h b/src/video_core/textures/decoders.h
index aaf316947..4726f54a5 100644
--- a/src/video_core/textures/decoders.h
+++ b/src/video_core/textures/decoders.h
@@ -35,4 +35,13 @@ std::vector<u8> DecodeTexture(const std::vector<u8>& texture_data, TextureFormat
35std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth, 35std::size_t CalculateSize(bool tiled, u32 bytes_per_pixel, u32 width, u32 height, u32 depth,
36 u32 block_height, u32 block_depth); 36 u32 block_height, u32 block_depth);
37 37
38/// Copies an untiled subrectangle into a tiled surface.
39void SwizzleSubrect(u32 subrect_width, u32 subrect_height, u32 source_pitch, u32 swizzled_width,
40 u32 bytes_per_pixel, VAddr swizzled_data, VAddr unswizzled_data,
41 u32 block_height);
42/// Copies a tiled subrectangle into a linear surface.
43void UnswizzleSubrect(u32 subrect_width, u32 subrect_height, u32 dest_pitch, u32 swizzled_width,
44 u32 bytes_per_pixel, VAddr swizzled_data, VAddr unswizzled_data,
45 u32 block_height, u32 offset_x, u32 offset_y);
46
38} // namespace Tegra::Texture 47} // namespace Tegra::Texture