morton.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <array>
  5. #include <cstring>
  6. #include "common/assert.h"
  7. #include "common/common_types.h"
  8. #include "core/memory.h"
  9. #include "video_core/morton.h"
  10. #include "video_core/surface.h"
  11. #include "video_core/textures/decoders.h"
  12. namespace VideoCore {
  13. using Surface::GetBytesPerPixel;
  14. using Surface::PixelFormat;
  15. using MortonCopyFn = void (*)(u32, u32, u32, u32, u32, u32, u8*, VAddr);
  16. using ConversionArray = std::array<MortonCopyFn, Surface::MaxPixelFormat>;
  17. template <bool morton_to_linear, PixelFormat format>
  18. static void MortonCopy(u32 stride, u32 block_height, u32 height, u32 block_depth, u32 depth,
  19. u32 tile_width_spacing, u8* buffer, VAddr addr) {
  20. constexpr u32 bytes_per_pixel = GetBytesPerPixel(format);
  21. // With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual
  22. // pixel values.
  23. const u32 tile_size_x{GetDefaultBlockWidth(format)};
  24. const u32 tile_size_y{GetDefaultBlockHeight(format)};
  25. if constexpr (morton_to_linear) {
  26. Tegra::Texture::UnswizzleTexture(buffer, addr, tile_size_x, tile_size_y, bytes_per_pixel,
  27. stride, height, depth, block_height, block_depth,
  28. tile_width_spacing);
  29. } else {
  30. Tegra::Texture::CopySwizzledData(
  31. (stride + tile_size_x - 1) / tile_size_x, (height + tile_size_y - 1) / tile_size_y,
  32. depth, bytes_per_pixel, bytes_per_pixel, Memory::GetPointer(addr), buffer, false,
  33. block_height, block_depth, tile_width_spacing);
  34. }
  35. }
  36. static constexpr ConversionArray morton_to_linear_fns = {
  37. MortonCopy<true, PixelFormat::ABGR8U>,
  38. MortonCopy<true, PixelFormat::ABGR8S>,
  39. MortonCopy<true, PixelFormat::ABGR8UI>,
  40. MortonCopy<true, PixelFormat::B5G6R5U>,
  41. MortonCopy<true, PixelFormat::A2B10G10R10U>,
  42. MortonCopy<true, PixelFormat::A1B5G5R5U>,
  43. MortonCopy<true, PixelFormat::R8U>,
  44. MortonCopy<true, PixelFormat::R8UI>,
  45. MortonCopy<true, PixelFormat::RGBA16F>,
  46. MortonCopy<true, PixelFormat::RGBA16U>,
  47. MortonCopy<true, PixelFormat::RGBA16UI>,
  48. MortonCopy<true, PixelFormat::R11FG11FB10F>,
  49. MortonCopy<true, PixelFormat::RGBA32UI>,
  50. MortonCopy<true, PixelFormat::DXT1>,
  51. MortonCopy<true, PixelFormat::DXT23>,
  52. MortonCopy<true, PixelFormat::DXT45>,
  53. MortonCopy<true, PixelFormat::DXN1>,
  54. MortonCopy<true, PixelFormat::DXN2UNORM>,
  55. MortonCopy<true, PixelFormat::DXN2SNORM>,
  56. MortonCopy<true, PixelFormat::BC7U>,
  57. MortonCopy<true, PixelFormat::BC6H_UF16>,
  58. MortonCopy<true, PixelFormat::BC6H_SF16>,
  59. MortonCopy<true, PixelFormat::ASTC_2D_4X4>,
  60. MortonCopy<true, PixelFormat::BGRA8>,
  61. MortonCopy<true, PixelFormat::RGBA32F>,
  62. MortonCopy<true, PixelFormat::RG32F>,
  63. MortonCopy<true, PixelFormat::R32F>,
  64. MortonCopy<true, PixelFormat::R16F>,
  65. MortonCopy<true, PixelFormat::R16U>,
  66. MortonCopy<true, PixelFormat::R16S>,
  67. MortonCopy<true, PixelFormat::R16UI>,
  68. MortonCopy<true, PixelFormat::R16I>,
  69. MortonCopy<true, PixelFormat::RG16>,
  70. MortonCopy<true, PixelFormat::RG16F>,
  71. MortonCopy<true, PixelFormat::RG16UI>,
  72. MortonCopy<true, PixelFormat::RG16I>,
  73. MortonCopy<true, PixelFormat::RG16S>,
  74. MortonCopy<true, PixelFormat::RGB32F>,
  75. MortonCopy<true, PixelFormat::RGBA8_SRGB>,
  76. MortonCopy<true, PixelFormat::RG8U>,
  77. MortonCopy<true, PixelFormat::RG8S>,
  78. MortonCopy<true, PixelFormat::RG32UI>,
  79. MortonCopy<true, PixelFormat::R32UI>,
  80. MortonCopy<true, PixelFormat::ASTC_2D_8X8>,
  81. MortonCopy<true, PixelFormat::ASTC_2D_8X5>,
  82. MortonCopy<true, PixelFormat::ASTC_2D_5X4>,
  83. MortonCopy<true, PixelFormat::BGRA8_SRGB>,
  84. MortonCopy<true, PixelFormat::DXT1_SRGB>,
  85. MortonCopy<true, PixelFormat::DXT23_SRGB>,
  86. MortonCopy<true, PixelFormat::DXT45_SRGB>,
  87. MortonCopy<true, PixelFormat::BC7U_SRGB>,
  88. MortonCopy<true, PixelFormat::ASTC_2D_4X4_SRGB>,
  89. MortonCopy<true, PixelFormat::ASTC_2D_8X8_SRGB>,
  90. MortonCopy<true, PixelFormat::ASTC_2D_8X5_SRGB>,
  91. MortonCopy<true, PixelFormat::ASTC_2D_5X4_SRGB>,
  92. MortonCopy<true, PixelFormat::ASTC_2D_5X5>,
  93. MortonCopy<true, PixelFormat::ASTC_2D_5X5_SRGB>,
  94. MortonCopy<true, PixelFormat::ASTC_2D_10X8>,
  95. MortonCopy<true, PixelFormat::ASTC_2D_10X8_SRGB>,
  96. MortonCopy<true, PixelFormat::Z32F>,
  97. MortonCopy<true, PixelFormat::Z16>,
  98. MortonCopy<true, PixelFormat::Z24S8>,
  99. MortonCopy<true, PixelFormat::S8Z24>,
  100. MortonCopy<true, PixelFormat::Z32FS8>,
  101. };
  102. static constexpr ConversionArray linear_to_morton_fns = {
  103. MortonCopy<false, PixelFormat::ABGR8U>,
  104. MortonCopy<false, PixelFormat::ABGR8S>,
  105. MortonCopy<false, PixelFormat::ABGR8UI>,
  106. MortonCopy<false, PixelFormat::B5G6R5U>,
  107. MortonCopy<false, PixelFormat::A2B10G10R10U>,
  108. MortonCopy<false, PixelFormat::A1B5G5R5U>,
  109. MortonCopy<false, PixelFormat::R8U>,
  110. MortonCopy<false, PixelFormat::R8UI>,
  111. MortonCopy<false, PixelFormat::RGBA16F>,
  112. MortonCopy<false, PixelFormat::RGBA16U>,
  113. MortonCopy<false, PixelFormat::RGBA16UI>,
  114. MortonCopy<false, PixelFormat::R11FG11FB10F>,
  115. MortonCopy<false, PixelFormat::RGBA32UI>,
  116. MortonCopy<false, PixelFormat::DXT1>,
  117. MortonCopy<false, PixelFormat::DXT23>,
  118. MortonCopy<false, PixelFormat::DXT45>,
  119. MortonCopy<false, PixelFormat::DXN1>,
  120. MortonCopy<false, PixelFormat::DXN2UNORM>,
  121. MortonCopy<false, PixelFormat::DXN2SNORM>,
  122. MortonCopy<false, PixelFormat::BC7U>,
  123. MortonCopy<false, PixelFormat::BC6H_UF16>,
  124. MortonCopy<false, PixelFormat::BC6H_SF16>,
  125. // TODO(Subv): Swizzling ASTC formats are not supported
  126. nullptr,
  127. MortonCopy<false, PixelFormat::BGRA8>,
  128. MortonCopy<false, PixelFormat::RGBA32F>,
  129. MortonCopy<false, PixelFormat::RG32F>,
  130. MortonCopy<false, PixelFormat::R32F>,
  131. MortonCopy<false, PixelFormat::R16F>,
  132. MortonCopy<false, PixelFormat::R16U>,
  133. MortonCopy<false, PixelFormat::R16S>,
  134. MortonCopy<false, PixelFormat::R16UI>,
  135. MortonCopy<false, PixelFormat::R16I>,
  136. MortonCopy<false, PixelFormat::RG16>,
  137. MortonCopy<false, PixelFormat::RG16F>,
  138. MortonCopy<false, PixelFormat::RG16UI>,
  139. MortonCopy<false, PixelFormat::RG16I>,
  140. MortonCopy<false, PixelFormat::RG16S>,
  141. MortonCopy<false, PixelFormat::RGB32F>,
  142. MortonCopy<false, PixelFormat::RGBA8_SRGB>,
  143. MortonCopy<false, PixelFormat::RG8U>,
  144. MortonCopy<false, PixelFormat::RG8S>,
  145. MortonCopy<false, PixelFormat::RG32UI>,
  146. MortonCopy<false, PixelFormat::R32UI>,
  147. nullptr,
  148. nullptr,
  149. nullptr,
  150. MortonCopy<false, PixelFormat::BGRA8_SRGB>,
  151. MortonCopy<false, PixelFormat::DXT1_SRGB>,
  152. MortonCopy<false, PixelFormat::DXT23_SRGB>,
  153. MortonCopy<false, PixelFormat::DXT45_SRGB>,
  154. MortonCopy<false, PixelFormat::BC7U_SRGB>,
  155. nullptr,
  156. nullptr,
  157. nullptr,
  158. nullptr,
  159. nullptr,
  160. nullptr,
  161. nullptr,
  162. nullptr,
  163. MortonCopy<false, PixelFormat::Z32F>,
  164. MortonCopy<false, PixelFormat::Z16>,
  165. MortonCopy<false, PixelFormat::Z24S8>,
  166. MortonCopy<false, PixelFormat::S8Z24>,
  167. MortonCopy<false, PixelFormat::Z32FS8>,
  168. };
  169. static MortonCopyFn GetSwizzleFunction(MortonSwizzleMode mode, Surface::PixelFormat format) {
  170. switch (mode) {
  171. case MortonSwizzleMode::MortonToLinear:
  172. return morton_to_linear_fns[static_cast<std::size_t>(format)];
  173. case MortonSwizzleMode::LinearToMorton:
  174. return linear_to_morton_fns[static_cast<std::size_t>(format)];
  175. }
  176. UNREACHABLE();
  177. return morton_to_linear_fns[static_cast<std::size_t>(format)];
  178. }
  179. static u32 MortonInterleave128(u32 x, u32 y) {
  180. // 128x128 Z-Order coordinate from 2D coordinates
  181. static constexpr u32 xlut[] = {
  182. 0x0000, 0x0001, 0x0002, 0x0003, 0x0008, 0x0009, 0x000a, 0x000b, 0x0040, 0x0041, 0x0042,
  183. 0x0043, 0x0048, 0x0049, 0x004a, 0x004b, 0x0800, 0x0801, 0x0802, 0x0803, 0x0808, 0x0809,
  184. 0x080a, 0x080b, 0x0840, 0x0841, 0x0842, 0x0843, 0x0848, 0x0849, 0x084a, 0x084b, 0x1000,
  185. 0x1001, 0x1002, 0x1003, 0x1008, 0x1009, 0x100a, 0x100b, 0x1040, 0x1041, 0x1042, 0x1043,
  186. 0x1048, 0x1049, 0x104a, 0x104b, 0x1800, 0x1801, 0x1802, 0x1803, 0x1808, 0x1809, 0x180a,
  187. 0x180b, 0x1840, 0x1841, 0x1842, 0x1843, 0x1848, 0x1849, 0x184a, 0x184b, 0x2000, 0x2001,
  188. 0x2002, 0x2003, 0x2008, 0x2009, 0x200a, 0x200b, 0x2040, 0x2041, 0x2042, 0x2043, 0x2048,
  189. 0x2049, 0x204a, 0x204b, 0x2800, 0x2801, 0x2802, 0x2803, 0x2808, 0x2809, 0x280a, 0x280b,
  190. 0x2840, 0x2841, 0x2842, 0x2843, 0x2848, 0x2849, 0x284a, 0x284b, 0x3000, 0x3001, 0x3002,
  191. 0x3003, 0x3008, 0x3009, 0x300a, 0x300b, 0x3040, 0x3041, 0x3042, 0x3043, 0x3048, 0x3049,
  192. 0x304a, 0x304b, 0x3800, 0x3801, 0x3802, 0x3803, 0x3808, 0x3809, 0x380a, 0x380b, 0x3840,
  193. 0x3841, 0x3842, 0x3843, 0x3848, 0x3849, 0x384a, 0x384b, 0x0000, 0x0001, 0x0002, 0x0003,
  194. 0x0008, 0x0009, 0x000a, 0x000b, 0x0040, 0x0041, 0x0042, 0x0043, 0x0048, 0x0049, 0x004a,
  195. 0x004b, 0x0800, 0x0801, 0x0802, 0x0803, 0x0808, 0x0809, 0x080a, 0x080b, 0x0840, 0x0841,
  196. 0x0842, 0x0843, 0x0848, 0x0849, 0x084a, 0x084b, 0x1000, 0x1001, 0x1002, 0x1003, 0x1008,
  197. 0x1009, 0x100a, 0x100b, 0x1040, 0x1041, 0x1042, 0x1043, 0x1048, 0x1049, 0x104a, 0x104b,
  198. 0x1800, 0x1801, 0x1802, 0x1803, 0x1808, 0x1809, 0x180a, 0x180b, 0x1840, 0x1841, 0x1842,
  199. 0x1843, 0x1848, 0x1849, 0x184a, 0x184b, 0x2000, 0x2001, 0x2002, 0x2003, 0x2008, 0x2009,
  200. 0x200a, 0x200b, 0x2040, 0x2041, 0x2042, 0x2043, 0x2048, 0x2049, 0x204a, 0x204b, 0x2800,
  201. 0x2801, 0x2802, 0x2803, 0x2808, 0x2809, 0x280a, 0x280b, 0x2840, 0x2841, 0x2842, 0x2843,
  202. 0x2848, 0x2849, 0x284a, 0x284b, 0x3000, 0x3001, 0x3002, 0x3003, 0x3008, 0x3009, 0x300a,
  203. 0x300b, 0x3040, 0x3041, 0x3042, 0x3043, 0x3048, 0x3049, 0x304a, 0x304b, 0x3800, 0x3801,
  204. 0x3802, 0x3803, 0x3808, 0x3809, 0x380a, 0x380b, 0x3840, 0x3841, 0x3842, 0x3843, 0x3848,
  205. 0x3849, 0x384a, 0x384b, 0x0000, 0x0001, 0x0002, 0x0003, 0x0008, 0x0009, 0x000a, 0x000b,
  206. 0x0040, 0x0041, 0x0042, 0x0043, 0x0048, 0x0049, 0x004a, 0x004b, 0x0800, 0x0801, 0x0802,
  207. 0x0803, 0x0808, 0x0809, 0x080a, 0x080b, 0x0840, 0x0841, 0x0842, 0x0843, 0x0848, 0x0849,
  208. 0x084a, 0x084b, 0x1000, 0x1001, 0x1002, 0x1003, 0x1008, 0x1009, 0x100a, 0x100b, 0x1040,
  209. 0x1041, 0x1042, 0x1043, 0x1048, 0x1049, 0x104a, 0x104b, 0x1800, 0x1801, 0x1802, 0x1803,
  210. 0x1808, 0x1809, 0x180a, 0x180b, 0x1840, 0x1841, 0x1842, 0x1843, 0x1848, 0x1849, 0x184a,
  211. 0x184b, 0x2000, 0x2001, 0x2002, 0x2003, 0x2008, 0x2009, 0x200a, 0x200b, 0x2040, 0x2041,
  212. 0x2042, 0x2043, 0x2048, 0x2049, 0x204a, 0x204b, 0x2800, 0x2801, 0x2802, 0x2803, 0x2808,
  213. 0x2809, 0x280a, 0x280b, 0x2840, 0x2841, 0x2842, 0x2843, 0x2848, 0x2849, 0x284a, 0x284b,
  214. 0x3000, 0x3001, 0x3002, 0x3003, 0x3008, 0x3009, 0x300a, 0x300b, 0x3040, 0x3041, 0x3042,
  215. 0x3043, 0x3048, 0x3049, 0x304a, 0x304b, 0x3800, 0x3801, 0x3802, 0x3803, 0x3808, 0x3809,
  216. 0x380a, 0x380b, 0x3840, 0x3841, 0x3842, 0x3843, 0x3848, 0x3849, 0x384a, 0x384b,
  217. };
  218. static constexpr u32 ylut[] = {
  219. 0x0000, 0x0004, 0x0010, 0x0014, 0x0020, 0x0024, 0x0030, 0x0034, 0x0080, 0x0084, 0x0090,
  220. 0x0094, 0x00a0, 0x00a4, 0x00b0, 0x00b4, 0x0100, 0x0104, 0x0110, 0x0114, 0x0120, 0x0124,
  221. 0x0130, 0x0134, 0x0180, 0x0184, 0x0190, 0x0194, 0x01a0, 0x01a4, 0x01b0, 0x01b4, 0x0200,
  222. 0x0204, 0x0210, 0x0214, 0x0220, 0x0224, 0x0230, 0x0234, 0x0280, 0x0284, 0x0290, 0x0294,
  223. 0x02a0, 0x02a4, 0x02b0, 0x02b4, 0x0300, 0x0304, 0x0310, 0x0314, 0x0320, 0x0324, 0x0330,
  224. 0x0334, 0x0380, 0x0384, 0x0390, 0x0394, 0x03a0, 0x03a4, 0x03b0, 0x03b4, 0x0400, 0x0404,
  225. 0x0410, 0x0414, 0x0420, 0x0424, 0x0430, 0x0434, 0x0480, 0x0484, 0x0490, 0x0494, 0x04a0,
  226. 0x04a4, 0x04b0, 0x04b4, 0x0500, 0x0504, 0x0510, 0x0514, 0x0520, 0x0524, 0x0530, 0x0534,
  227. 0x0580, 0x0584, 0x0590, 0x0594, 0x05a0, 0x05a4, 0x05b0, 0x05b4, 0x0600, 0x0604, 0x0610,
  228. 0x0614, 0x0620, 0x0624, 0x0630, 0x0634, 0x0680, 0x0684, 0x0690, 0x0694, 0x06a0, 0x06a4,
  229. 0x06b0, 0x06b4, 0x0700, 0x0704, 0x0710, 0x0714, 0x0720, 0x0724, 0x0730, 0x0734, 0x0780,
  230. 0x0784, 0x0790, 0x0794, 0x07a0, 0x07a4, 0x07b0, 0x07b4, 0x0000, 0x0004, 0x0010, 0x0014,
  231. 0x0020, 0x0024, 0x0030, 0x0034, 0x0080, 0x0084, 0x0090, 0x0094, 0x00a0, 0x00a4, 0x00b0,
  232. 0x00b4, 0x0100, 0x0104, 0x0110, 0x0114, 0x0120, 0x0124, 0x0130, 0x0134, 0x0180, 0x0184,
  233. 0x0190, 0x0194, 0x01a0, 0x01a4, 0x01b0, 0x01b4, 0x0200, 0x0204, 0x0210, 0x0214, 0x0220,
  234. 0x0224, 0x0230, 0x0234, 0x0280, 0x0284, 0x0290, 0x0294, 0x02a0, 0x02a4, 0x02b0, 0x02b4,
  235. 0x0300, 0x0304, 0x0310, 0x0314, 0x0320, 0x0324, 0x0330, 0x0334, 0x0380, 0x0384, 0x0390,
  236. 0x0394, 0x03a0, 0x03a4, 0x03b0, 0x03b4, 0x0400, 0x0404, 0x0410, 0x0414, 0x0420, 0x0424,
  237. 0x0430, 0x0434, 0x0480, 0x0484, 0x0490, 0x0494, 0x04a0, 0x04a4, 0x04b0, 0x04b4, 0x0500,
  238. 0x0504, 0x0510, 0x0514, 0x0520, 0x0524, 0x0530, 0x0534, 0x0580, 0x0584, 0x0590, 0x0594,
  239. 0x05a0, 0x05a4, 0x05b0, 0x05b4, 0x0600, 0x0604, 0x0610, 0x0614, 0x0620, 0x0624, 0x0630,
  240. 0x0634, 0x0680, 0x0684, 0x0690, 0x0694, 0x06a0, 0x06a4, 0x06b0, 0x06b4, 0x0700, 0x0704,
  241. 0x0710, 0x0714, 0x0720, 0x0724, 0x0730, 0x0734, 0x0780, 0x0784, 0x0790, 0x0794, 0x07a0,
  242. 0x07a4, 0x07b0, 0x07b4, 0x0000, 0x0004, 0x0010, 0x0014, 0x0020, 0x0024, 0x0030, 0x0034,
  243. 0x0080, 0x0084, 0x0090, 0x0094, 0x00a0, 0x00a4, 0x00b0, 0x00b4, 0x0100, 0x0104, 0x0110,
  244. 0x0114, 0x0120, 0x0124, 0x0130, 0x0134, 0x0180, 0x0184, 0x0190, 0x0194, 0x01a0, 0x01a4,
  245. 0x01b0, 0x01b4, 0x0200, 0x0204, 0x0210, 0x0214, 0x0220, 0x0224, 0x0230, 0x0234, 0x0280,
  246. 0x0284, 0x0290, 0x0294, 0x02a0, 0x02a4, 0x02b0, 0x02b4, 0x0300, 0x0304, 0x0310, 0x0314,
  247. 0x0320, 0x0324, 0x0330, 0x0334, 0x0380, 0x0384, 0x0390, 0x0394, 0x03a0, 0x03a4, 0x03b0,
  248. 0x03b4, 0x0400, 0x0404, 0x0410, 0x0414, 0x0420, 0x0424, 0x0430, 0x0434, 0x0480, 0x0484,
  249. 0x0490, 0x0494, 0x04a0, 0x04a4, 0x04b0, 0x04b4, 0x0500, 0x0504, 0x0510, 0x0514, 0x0520,
  250. 0x0524, 0x0530, 0x0534, 0x0580, 0x0584, 0x0590, 0x0594, 0x05a0, 0x05a4, 0x05b0, 0x05b4,
  251. 0x0600, 0x0604, 0x0610, 0x0614, 0x0620, 0x0624, 0x0630, 0x0634, 0x0680, 0x0684, 0x0690,
  252. 0x0694, 0x06a0, 0x06a4, 0x06b0, 0x06b4, 0x0700, 0x0704, 0x0710, 0x0714, 0x0720, 0x0724,
  253. 0x0730, 0x0734, 0x0780, 0x0784, 0x0790, 0x0794, 0x07a0, 0x07a4, 0x07b0, 0x07b4,
  254. };
  255. return xlut[x % 128] + ylut[y % 128];
  256. }
  257. static u32 GetMortonOffset128(u32 x, u32 y, u32 bytes_per_pixel) {
  258. // Calculates the offset of the position of the pixel in Morton order
  259. // Framebuffer images are split into 128x128 tiles.
  260. constexpr u32 block_height = 128;
  261. const u32 coarse_x = x & ~127;
  262. const u32 i = MortonInterleave128(x, y);
  263. const u32 offset = coarse_x * block_height;
  264. return (i + offset) * bytes_per_pixel;
  265. }
  266. void MortonSwizzle(MortonSwizzleMode mode, Surface::PixelFormat format, u32 stride,
  267. u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing,
  268. u8* buffer, VAddr addr) {
  269. GetSwizzleFunction(mode, format)(stride, block_height, height, block_depth, depth,
  270. tile_width_spacing, buffer, addr);
  271. }
  272. void MortonCopyPixels128(MortonSwizzleMode mode, u32 width, u32 height, u32 bytes_per_pixel,
  273. u32 linear_bytes_per_pixel, u8* morton_data, u8* linear_data) {
  274. const bool morton_to_linear = mode == MortonSwizzleMode::MortonToLinear;
  275. u8* data_ptrs[2];
  276. for (u32 y = 0; y < height; ++y) {
  277. for (u32 x = 0; x < width; ++x) {
  278. const u32 coarse_y = y & ~127;
  279. const u32 morton_offset =
  280. GetMortonOffset128(x, y, bytes_per_pixel) + coarse_y * width * bytes_per_pixel;
  281. const u32 linear_pixel_index = (x + y * width) * linear_bytes_per_pixel;
  282. data_ptrs[morton_to_linear ? 1 : 0] = morton_data + morton_offset;
  283. data_ptrs[morton_to_linear ? 0 : 1] = &linear_data[linear_pixel_index];
  284. std::memcpy(data_ptrs[0], data_ptrs[1], bytes_per_pixel);
  285. }
  286. }
  287. }
  288. } // namespace VideoCore