diff options
Diffstat (limited to 'src/video_core/morton.cpp')
| -rw-r--r-- | src/video_core/morton.cpp | 250 |
1 files changed, 0 insertions, 250 deletions
diff --git a/src/video_core/morton.cpp b/src/video_core/morton.cpp index 9da9fb4ff..e69de29bb 100644 --- a/src/video_core/morton.cpp +++ b/src/video_core/morton.cpp | |||
| @@ -1,250 +0,0 @@ | |||
| 1 | // Copyright 2018 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <array> | ||
| 6 | #include <cstring> | ||
| 7 | #include "common/assert.h" | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "video_core/morton.h" | ||
| 10 | #include "video_core/surface.h" | ||
| 11 | #include "video_core/textures/decoders.h" | ||
| 12 | |||
| 13 | namespace VideoCore { | ||
| 14 | |||
| 15 | using Surface::GetBytesPerPixel; | ||
| 16 | using Surface::PixelFormat; | ||
| 17 | |||
| 18 | using MortonCopyFn = void (*)(u32, u32, u32, u32, u32, u32, u8*, u8*); | ||
| 19 | using ConversionArray = std::array<MortonCopyFn, Surface::MaxPixelFormat>; | ||
| 20 | |||
| 21 | template <bool morton_to_linear, PixelFormat format> | ||
| 22 | static void MortonCopy(u32 stride, u32 block_height, u32 height, u32 block_depth, u32 depth, | ||
| 23 | u32 tile_width_spacing, u8* buffer, u8* addr) { | ||
| 24 | constexpr u32 bytes_per_pixel = GetBytesPerPixel(format); | ||
| 25 | |||
| 26 | // With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual | ||
| 27 | // pixel values. | ||
| 28 | constexpr u32 tile_size_x{GetDefaultBlockWidth(format)}; | ||
| 29 | constexpr u32 tile_size_y{GetDefaultBlockHeight(format)}; | ||
| 30 | |||
| 31 | if constexpr (morton_to_linear) { | ||
| 32 | Tegra::Texture::UnswizzleTexture(buffer, addr, tile_size_x, tile_size_y, bytes_per_pixel, | ||
| 33 | stride, height, depth, block_height, block_depth, | ||
| 34 | tile_width_spacing); | ||
| 35 | } else { | ||
| 36 | Tegra::Texture::CopySwizzledData((stride + tile_size_x - 1) / tile_size_x, | ||
| 37 | (height + tile_size_y - 1) / tile_size_y, depth, | ||
| 38 | bytes_per_pixel, bytes_per_pixel, addr, buffer, false, | ||
| 39 | block_height, block_depth, tile_width_spacing); | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | static constexpr ConversionArray morton_to_linear_fns = { | ||
| 44 | MortonCopy<true, PixelFormat::A8B8G8R8_UNORM>, | ||
| 45 | MortonCopy<true, PixelFormat::A8B8G8R8_SNORM>, | ||
| 46 | MortonCopy<true, PixelFormat::A8B8G8R8_SINT>, | ||
| 47 | MortonCopy<true, PixelFormat::A8B8G8R8_UINT>, | ||
| 48 | MortonCopy<true, PixelFormat::R5G6B5_UNORM>, | ||
| 49 | MortonCopy<true, PixelFormat::B5G6R5_UNORM>, | ||
| 50 | MortonCopy<true, PixelFormat::A1R5G5B5_UNORM>, | ||
| 51 | MortonCopy<true, PixelFormat::A2B10G10R10_UNORM>, | ||
| 52 | MortonCopy<true, PixelFormat::A2B10G10R10_UINT>, | ||
| 53 | MortonCopy<true, PixelFormat::A1B5G5R5_UNORM>, | ||
| 54 | MortonCopy<true, PixelFormat::R8_UNORM>, | ||
| 55 | MortonCopy<true, PixelFormat::R8_SNORM>, | ||
| 56 | MortonCopy<true, PixelFormat::R8_SINT>, | ||
| 57 | MortonCopy<true, PixelFormat::R8_UINT>, | ||
| 58 | MortonCopy<true, PixelFormat::R16G16B16A16_FLOAT>, | ||
| 59 | MortonCopy<true, PixelFormat::R16G16B16A16_UNORM>, | ||
| 60 | MortonCopy<true, PixelFormat::R16G16B16A16_SNORM>, | ||
| 61 | MortonCopy<true, PixelFormat::R16G16B16A16_SINT>, | ||
| 62 | MortonCopy<true, PixelFormat::R16G16B16A16_UINT>, | ||
| 63 | MortonCopy<true, PixelFormat::B10G11R11_FLOAT>, | ||
| 64 | MortonCopy<true, PixelFormat::R32G32B32A32_UINT>, | ||
| 65 | MortonCopy<true, PixelFormat::BC1_RGBA_UNORM>, | ||
| 66 | MortonCopy<true, PixelFormat::BC2_UNORM>, | ||
| 67 | MortonCopy<true, PixelFormat::BC3_UNORM>, | ||
| 68 | MortonCopy<true, PixelFormat::BC4_UNORM>, | ||
| 69 | MortonCopy<true, PixelFormat::BC4_SNORM>, | ||
| 70 | MortonCopy<true, PixelFormat::BC5_UNORM>, | ||
| 71 | MortonCopy<true, PixelFormat::BC5_SNORM>, | ||
| 72 | MortonCopy<true, PixelFormat::BC7_UNORM>, | ||
| 73 | MortonCopy<true, PixelFormat::BC6H_UFLOAT>, | ||
| 74 | MortonCopy<true, PixelFormat::BC6H_SFLOAT>, | ||
| 75 | MortonCopy<true, PixelFormat::ASTC_2D_4X4_UNORM>, | ||
| 76 | MortonCopy<true, PixelFormat::B8G8R8A8_UNORM>, | ||
| 77 | MortonCopy<true, PixelFormat::R32G32B32A32_FLOAT>, | ||
| 78 | MortonCopy<true, PixelFormat::R32G32B32A32_SINT>, | ||
| 79 | MortonCopy<true, PixelFormat::R32G32_FLOAT>, | ||
| 80 | MortonCopy<true, PixelFormat::R32G32_SINT>, | ||
| 81 | MortonCopy<true, PixelFormat::R32_FLOAT>, | ||
| 82 | MortonCopy<true, PixelFormat::R16_FLOAT>, | ||
| 83 | MortonCopy<true, PixelFormat::R16_UNORM>, | ||
| 84 | MortonCopy<true, PixelFormat::R16_SNORM>, | ||
| 85 | MortonCopy<true, PixelFormat::R16_UINT>, | ||
| 86 | MortonCopy<true, PixelFormat::R16_SINT>, | ||
| 87 | MortonCopy<true, PixelFormat::R16G16_UNORM>, | ||
| 88 | MortonCopy<true, PixelFormat::R16G16_FLOAT>, | ||
| 89 | MortonCopy<true, PixelFormat::R16G16_UINT>, | ||
| 90 | MortonCopy<true, PixelFormat::R16G16_SINT>, | ||
| 91 | MortonCopy<true, PixelFormat::R16G16_SNORM>, | ||
| 92 | MortonCopy<true, PixelFormat::R32G32B32_FLOAT>, | ||
| 93 | MortonCopy<true, PixelFormat::A8B8G8R8_SRGB>, | ||
| 94 | MortonCopy<true, PixelFormat::R8G8_UNORM>, | ||
| 95 | MortonCopy<true, PixelFormat::R8G8_SNORM>, | ||
| 96 | MortonCopy<true, PixelFormat::R8G8_SINT>, | ||
| 97 | MortonCopy<true, PixelFormat::R8G8_UINT>, | ||
| 98 | MortonCopy<true, PixelFormat::R32G32_UINT>, | ||
| 99 | MortonCopy<true, PixelFormat::R16G16B16X16_FLOAT>, | ||
| 100 | MortonCopy<true, PixelFormat::R32_UINT>, | ||
| 101 | MortonCopy<true, PixelFormat::R32_SINT>, | ||
| 102 | MortonCopy<true, PixelFormat::ASTC_2D_8X8_UNORM>, | ||
| 103 | MortonCopy<true, PixelFormat::ASTC_2D_8X5_UNORM>, | ||
| 104 | MortonCopy<true, PixelFormat::ASTC_2D_5X4_UNORM>, | ||
| 105 | MortonCopy<true, PixelFormat::B8G8R8A8_SRGB>, | ||
| 106 | MortonCopy<true, PixelFormat::BC1_RGBA_SRGB>, | ||
| 107 | MortonCopy<true, PixelFormat::BC2_SRGB>, | ||
| 108 | MortonCopy<true, PixelFormat::BC3_SRGB>, | ||
| 109 | MortonCopy<true, PixelFormat::BC7_SRGB>, | ||
| 110 | MortonCopy<true, PixelFormat::A4B4G4R4_UNORM>, | ||
| 111 | MortonCopy<true, PixelFormat::ASTC_2D_4X4_SRGB>, | ||
| 112 | MortonCopy<true, PixelFormat::ASTC_2D_8X8_SRGB>, | ||
| 113 | MortonCopy<true, PixelFormat::ASTC_2D_8X5_SRGB>, | ||
| 114 | MortonCopy<true, PixelFormat::ASTC_2D_5X4_SRGB>, | ||
| 115 | MortonCopy<true, PixelFormat::ASTC_2D_5X5_UNORM>, | ||
| 116 | MortonCopy<true, PixelFormat::ASTC_2D_5X5_SRGB>, | ||
| 117 | MortonCopy<true, PixelFormat::ASTC_2D_10X8_UNORM>, | ||
| 118 | MortonCopy<true, PixelFormat::ASTC_2D_10X8_SRGB>, | ||
| 119 | MortonCopy<true, PixelFormat::ASTC_2D_6X6_UNORM>, | ||
| 120 | MortonCopy<true, PixelFormat::ASTC_2D_6X6_SRGB>, | ||
| 121 | MortonCopy<true, PixelFormat::ASTC_2D_10X10_UNORM>, | ||
| 122 | MortonCopy<true, PixelFormat::ASTC_2D_10X10_SRGB>, | ||
| 123 | MortonCopy<true, PixelFormat::ASTC_2D_12X12_UNORM>, | ||
| 124 | MortonCopy<true, PixelFormat::ASTC_2D_12X12_SRGB>, | ||
| 125 | MortonCopy<true, PixelFormat::ASTC_2D_8X6_UNORM>, | ||
| 126 | MortonCopy<true, PixelFormat::ASTC_2D_8X6_SRGB>, | ||
| 127 | MortonCopy<true, PixelFormat::ASTC_2D_6X5_UNORM>, | ||
| 128 | MortonCopy<true, PixelFormat::ASTC_2D_6X5_SRGB>, | ||
| 129 | MortonCopy<true, PixelFormat::E5B9G9R9_FLOAT>, | ||
| 130 | MortonCopy<true, PixelFormat::D32_FLOAT>, | ||
| 131 | MortonCopy<true, PixelFormat::D16_UNORM>, | ||
| 132 | MortonCopy<true, PixelFormat::D24_UNORM_S8_UINT>, | ||
| 133 | MortonCopy<true, PixelFormat::S8_UINT_D24_UNORM>, | ||
| 134 | MortonCopy<true, PixelFormat::D32_FLOAT_S8_UINT>, | ||
| 135 | }; | ||
| 136 | |||
| 137 | static constexpr ConversionArray linear_to_morton_fns = { | ||
| 138 | MortonCopy<false, PixelFormat::A8B8G8R8_UNORM>, | ||
| 139 | MortonCopy<false, PixelFormat::A8B8G8R8_SNORM>, | ||
| 140 | MortonCopy<false, PixelFormat::A8B8G8R8_SINT>, | ||
| 141 | MortonCopy<false, PixelFormat::A8B8G8R8_UINT>, | ||
| 142 | MortonCopy<false, PixelFormat::R5G6B5_UNORM>, | ||
| 143 | MortonCopy<false, PixelFormat::B5G6R5_UNORM>, | ||
| 144 | MortonCopy<false, PixelFormat::A1R5G5B5_UNORM>, | ||
| 145 | MortonCopy<false, PixelFormat::A2B10G10R10_UNORM>, | ||
| 146 | MortonCopy<false, PixelFormat::A2B10G10R10_UINT>, | ||
| 147 | MortonCopy<false, PixelFormat::A1B5G5R5_UNORM>, | ||
| 148 | MortonCopy<false, PixelFormat::R8_UNORM>, | ||
| 149 | MortonCopy<false, PixelFormat::R8_SNORM>, | ||
| 150 | MortonCopy<false, PixelFormat::R8_SINT>, | ||
| 151 | MortonCopy<false, PixelFormat::R8_UINT>, | ||
| 152 | MortonCopy<false, PixelFormat::R16G16B16A16_FLOAT>, | ||
| 153 | MortonCopy<false, PixelFormat::R16G16B16A16_SNORM>, | ||
| 154 | MortonCopy<false, PixelFormat::R16G16B16A16_SINT>, | ||
| 155 | MortonCopy<false, PixelFormat::R16G16B16A16_UNORM>, | ||
| 156 | MortonCopy<false, PixelFormat::R16G16B16A16_UINT>, | ||
| 157 | MortonCopy<false, PixelFormat::B10G11R11_FLOAT>, | ||
| 158 | MortonCopy<false, PixelFormat::R32G32B32A32_UINT>, | ||
| 159 | MortonCopy<false, PixelFormat::BC1_RGBA_UNORM>, | ||
| 160 | MortonCopy<false, PixelFormat::BC2_UNORM>, | ||
| 161 | MortonCopy<false, PixelFormat::BC3_UNORM>, | ||
| 162 | MortonCopy<false, PixelFormat::BC4_UNORM>, | ||
| 163 | MortonCopy<false, PixelFormat::BC4_SNORM>, | ||
| 164 | MortonCopy<false, PixelFormat::BC5_UNORM>, | ||
| 165 | MortonCopy<false, PixelFormat::BC5_SNORM>, | ||
| 166 | MortonCopy<false, PixelFormat::BC7_UNORM>, | ||
| 167 | MortonCopy<false, PixelFormat::BC6H_UFLOAT>, | ||
| 168 | MortonCopy<false, PixelFormat::BC6H_SFLOAT>, | ||
| 169 | // TODO(Subv): Swizzling ASTC formats are not supported | ||
| 170 | nullptr, | ||
| 171 | MortonCopy<false, PixelFormat::B8G8R8A8_UNORM>, | ||
| 172 | MortonCopy<false, PixelFormat::R32G32B32A32_FLOAT>, | ||
| 173 | MortonCopy<false, PixelFormat::R32G32B32A32_SINT>, | ||
| 174 | MortonCopy<false, PixelFormat::R32G32_FLOAT>, | ||
| 175 | MortonCopy<false, PixelFormat::R32G32_SINT>, | ||
| 176 | MortonCopy<false, PixelFormat::R32_FLOAT>, | ||
| 177 | MortonCopy<false, PixelFormat::R16_FLOAT>, | ||
| 178 | MortonCopy<false, PixelFormat::R16_UNORM>, | ||
| 179 | MortonCopy<false, PixelFormat::R16_SNORM>, | ||
| 180 | MortonCopy<false, PixelFormat::R16_UINT>, | ||
| 181 | MortonCopy<false, PixelFormat::R16_SINT>, | ||
| 182 | MortonCopy<false, PixelFormat::R16G16_UNORM>, | ||
| 183 | MortonCopy<false, PixelFormat::R16G16_FLOAT>, | ||
| 184 | MortonCopy<false, PixelFormat::R16G16_UINT>, | ||
| 185 | MortonCopy<false, PixelFormat::R16G16_SINT>, | ||
| 186 | MortonCopy<false, PixelFormat::R16G16_SNORM>, | ||
| 187 | MortonCopy<false, PixelFormat::R32G32B32_FLOAT>, | ||
| 188 | MortonCopy<false, PixelFormat::A8B8G8R8_SRGB>, | ||
| 189 | MortonCopy<false, PixelFormat::R8G8_UNORM>, | ||
| 190 | MortonCopy<false, PixelFormat::R8G8_SNORM>, | ||
| 191 | MortonCopy<false, PixelFormat::R8G8_SINT>, | ||
| 192 | MortonCopy<false, PixelFormat::R8G8_UINT>, | ||
| 193 | MortonCopy<false, PixelFormat::R32G32_UINT>, | ||
| 194 | MortonCopy<false, PixelFormat::R16G16B16X16_FLOAT>, | ||
| 195 | MortonCopy<false, PixelFormat::R32_UINT>, | ||
| 196 | MortonCopy<false, PixelFormat::R32_SINT>, | ||
| 197 | nullptr, | ||
| 198 | nullptr, | ||
| 199 | nullptr, | ||
| 200 | MortonCopy<false, PixelFormat::B8G8R8A8_SRGB>, | ||
| 201 | MortonCopy<false, PixelFormat::BC1_RGBA_SRGB>, | ||
| 202 | MortonCopy<false, PixelFormat::BC2_SRGB>, | ||
| 203 | MortonCopy<false, PixelFormat::BC3_SRGB>, | ||
| 204 | MortonCopy<false, PixelFormat::BC7_SRGB>, | ||
| 205 | MortonCopy<false, PixelFormat::A4B4G4R4_UNORM>, | ||
| 206 | nullptr, | ||
| 207 | nullptr, | ||
| 208 | nullptr, | ||
| 209 | nullptr, | ||
| 210 | nullptr, | ||
| 211 | nullptr, | ||
| 212 | nullptr, | ||
| 213 | nullptr, | ||
| 214 | nullptr, | ||
| 215 | nullptr, | ||
| 216 | nullptr, | ||
| 217 | nullptr, | ||
| 218 | nullptr, | ||
| 219 | nullptr, | ||
| 220 | nullptr, | ||
| 221 | nullptr, | ||
| 222 | nullptr, | ||
| 223 | nullptr, | ||
| 224 | MortonCopy<false, PixelFormat::E5B9G9R9_FLOAT>, | ||
| 225 | MortonCopy<false, PixelFormat::D32_FLOAT>, | ||
| 226 | MortonCopy<false, PixelFormat::D16_UNORM>, | ||
| 227 | MortonCopy<false, PixelFormat::D24_UNORM_S8_UINT>, | ||
| 228 | MortonCopy<false, PixelFormat::S8_UINT_D24_UNORM>, | ||
| 229 | MortonCopy<false, PixelFormat::D32_FLOAT_S8_UINT>, | ||
| 230 | }; | ||
| 231 | |||
| 232 | static MortonCopyFn GetSwizzleFunction(MortonSwizzleMode mode, Surface::PixelFormat format) { | ||
| 233 | switch (mode) { | ||
| 234 | case MortonSwizzleMode::MortonToLinear: | ||
| 235 | return morton_to_linear_fns[static_cast<std::size_t>(format)]; | ||
| 236 | case MortonSwizzleMode::LinearToMorton: | ||
| 237 | return linear_to_morton_fns[static_cast<std::size_t>(format)]; | ||
| 238 | } | ||
| 239 | UNREACHABLE(); | ||
| 240 | return morton_to_linear_fns[static_cast<std::size_t>(format)]; | ||
| 241 | } | ||
| 242 | |||
| 243 | void MortonSwizzle(MortonSwizzleMode mode, Surface::PixelFormat format, u32 stride, | ||
| 244 | u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing, | ||
| 245 | u8* buffer, u8* addr) { | ||
| 246 | GetSwizzleFunction(mode, format)(stride, block_height, height, block_depth, depth, | ||
| 247 | tile_width_spacing, buffer, addr); | ||
| 248 | } | ||
| 249 | |||
| 250 | } // namespace VideoCore | ||