diff options
| author | 2019-11-19 18:29:17 -0500 | |
|---|---|---|
| committer | 2019-11-19 18:29:17 -0500 | |
| commit | b0819e2ffb8df3f4ec25186c7f2487790ab557e6 (patch) | |
| tree | 239818f90980fb8ee9a2201111aa81f169a9e6bb /src/video_core/texture_cache | |
| parent | Merge pull request #3123 from ReinUsesLisp/logging-return (diff) | |
| parent | format_lookup_table: Address feedback (diff) | |
| download | yuzu-b0819e2ffb8df3f4ec25186c7f2487790ab557e6.tar.gz yuzu-b0819e2ffb8df3f4ec25186c7f2487790ab557e6.tar.xz yuzu-b0819e2ffb8df3f4ec25186c7f2487790ab557e6.zip | |
Merge pull request #3086 from ReinUsesLisp/format-lookups
texture_cache: Use a flat table instead of switch for texture format lookups
Diffstat (limited to 'src/video_core/texture_cache')
| -rw-r--r-- | src/video_core/texture_cache/format_lookup_table.cpp | 208 | ||||
| -rw-r--r-- | src/video_core/texture_cache/format_lookup_table.h | 51 | ||||
| -rw-r--r-- | src/video_core/texture_cache/surface_params.cpp | 32 | ||||
| -rw-r--r-- | src/video_core/texture_cache/surface_params.h | 9 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 16 |
5 files changed, 287 insertions, 29 deletions
diff --git a/src/video_core/texture_cache/format_lookup_table.cpp b/src/video_core/texture_cache/format_lookup_table.cpp new file mode 100644 index 000000000..271e67533 --- /dev/null +++ b/src/video_core/texture_cache/format_lookup_table.cpp | |||
| @@ -0,0 +1,208 @@ | |||
| 1 | // Copyright 2019 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 "common/common_types.h" | ||
| 7 | #include "common/logging/log.h" | ||
| 8 | #include "video_core/texture_cache/format_lookup_table.h" | ||
| 9 | |||
| 10 | namespace VideoCommon { | ||
| 11 | |||
| 12 | using Tegra::Texture::ComponentType; | ||
| 13 | using Tegra::Texture::TextureFormat; | ||
| 14 | using VideoCore::Surface::PixelFormat; | ||
| 15 | |||
| 16 | namespace { | ||
| 17 | |||
| 18 | constexpr auto SNORM = ComponentType::SNORM; | ||
| 19 | constexpr auto UNORM = ComponentType::UNORM; | ||
| 20 | constexpr auto SINT = ComponentType::SINT; | ||
| 21 | constexpr auto UINT = ComponentType::UINT; | ||
| 22 | constexpr auto SNORM_FORCE_FP16 = ComponentType::SNORM_FORCE_FP16; | ||
| 23 | constexpr auto UNORM_FORCE_FP16 = ComponentType::UNORM_FORCE_FP16; | ||
| 24 | constexpr auto FLOAT = ComponentType::FLOAT; | ||
| 25 | constexpr bool C = false; // Normal color | ||
| 26 | constexpr bool S = true; // Srgb | ||
| 27 | |||
| 28 | struct Table { | ||
| 29 | constexpr Table(TextureFormat texture_format, bool is_srgb, ComponentType red_component, | ||
| 30 | ComponentType green_component, ComponentType blue_component, | ||
| 31 | ComponentType alpha_component, PixelFormat pixel_format) | ||
| 32 | : texture_format{texture_format}, pixel_format{pixel_format}, red_component{red_component}, | ||
| 33 | green_component{green_component}, blue_component{blue_component}, | ||
| 34 | alpha_component{alpha_component}, is_srgb{is_srgb} {} | ||
| 35 | |||
| 36 | TextureFormat texture_format; | ||
| 37 | PixelFormat pixel_format; | ||
| 38 | ComponentType red_component; | ||
| 39 | ComponentType green_component; | ||
| 40 | ComponentType blue_component; | ||
| 41 | ComponentType alpha_component; | ||
| 42 | bool is_srgb; | ||
| 43 | }; | ||
| 44 | constexpr std::array<Table, 74> DefinitionTable = {{ | ||
| 45 | {TextureFormat::A8R8G8B8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ABGR8U}, | ||
| 46 | {TextureFormat::A8R8G8B8, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::ABGR8S}, | ||
| 47 | {TextureFormat::A8R8G8B8, C, UINT, UINT, UINT, UINT, PixelFormat::ABGR8UI}, | ||
| 48 | {TextureFormat::A8R8G8B8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::RGBA8_SRGB}, | ||
| 49 | |||
| 50 | {TextureFormat::B5G6R5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::B5G6R5U}, | ||
| 51 | |||
| 52 | {TextureFormat::A2B10G10R10, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::A2B10G10R10U}, | ||
| 53 | |||
| 54 | {TextureFormat::A1B5G5R5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::A1B5G5R5U}, | ||
| 55 | |||
| 56 | {TextureFormat::A4B4G4R4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R4G4B4A4U}, | ||
| 57 | |||
| 58 | {TextureFormat::R8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R8U}, | ||
| 59 | {TextureFormat::R8, C, UINT, UINT, UINT, UINT, PixelFormat::R8UI}, | ||
| 60 | |||
| 61 | {TextureFormat::G8R8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::RG8U}, | ||
| 62 | {TextureFormat::G8R8, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::RG8S}, | ||
| 63 | |||
| 64 | {TextureFormat::R16_G16_B16_A16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::RGBA16U}, | ||
| 65 | {TextureFormat::R16_G16_B16_A16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RGBA16F}, | ||
| 66 | {TextureFormat::R16_G16_B16_A16, C, UINT, UINT, UINT, UINT, PixelFormat::RGBA16UI}, | ||
| 67 | |||
| 68 | {TextureFormat::R16_G16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RG16F}, | ||
| 69 | {TextureFormat::R16_G16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::RG16}, | ||
| 70 | {TextureFormat::R16_G16, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::RG16S}, | ||
| 71 | {TextureFormat::R16_G16, C, UINT, UINT, UINT, UINT, PixelFormat::RG16UI}, | ||
| 72 | {TextureFormat::R16_G16, C, SINT, SINT, SINT, SINT, PixelFormat::RG16I}, | ||
| 73 | |||
| 74 | {TextureFormat::R16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R16F}, | ||
| 75 | {TextureFormat::R16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R16U}, | ||
| 76 | {TextureFormat::R16, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::R16S}, | ||
| 77 | {TextureFormat::R16, C, UINT, UINT, UINT, UINT, PixelFormat::R16UI}, | ||
| 78 | {TextureFormat::R16, C, SINT, SINT, SINT, SINT, PixelFormat::R16I}, | ||
| 79 | |||
| 80 | {TextureFormat::BF10GF11RF11, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R11FG11FB10F}, | ||
| 81 | |||
| 82 | {TextureFormat::R32_G32_B32_A32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RGBA32F}, | ||
| 83 | {TextureFormat::R32_G32_B32_A32, C, UINT, UINT, UINT, UINT, PixelFormat::RGBA32UI}, | ||
| 84 | |||
| 85 | {TextureFormat::R32_G32_B32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RGB32F}, | ||
| 86 | |||
| 87 | {TextureFormat::R32_G32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RG32F}, | ||
| 88 | {TextureFormat::R32_G32, C, UINT, UINT, UINT, UINT, PixelFormat::RG32UI}, | ||
| 89 | |||
| 90 | {TextureFormat::R32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R32F}, | ||
| 91 | {TextureFormat::R32, C, UINT, UINT, UINT, UINT, PixelFormat::R32UI}, | ||
| 92 | |||
| 93 | {TextureFormat::E5B9G9R9_SHAREDEXP, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::E5B9G9R9F}, | ||
| 94 | |||
| 95 | {TextureFormat::ZF32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::Z32F}, | ||
| 96 | {TextureFormat::Z16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::Z16}, | ||
| 97 | {TextureFormat::S8Z24, C, UINT, UNORM, UNORM, UNORM, PixelFormat::S8Z24}, | ||
| 98 | {TextureFormat::ZF32_X24S8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::Z32FS8}, | ||
| 99 | |||
| 100 | {TextureFormat::DXT1, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT1}, | ||
| 101 | {TextureFormat::DXT1, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT1_SRGB}, | ||
| 102 | |||
| 103 | {TextureFormat::DXT23, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT23}, | ||
| 104 | {TextureFormat::DXT23, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT23_SRGB}, | ||
| 105 | |||
| 106 | {TextureFormat::DXT45, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT45}, | ||
| 107 | {TextureFormat::DXT45, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT45_SRGB}, | ||
| 108 | |||
| 109 | // TODO: Use a different pixel format for SNORM | ||
| 110 | {TextureFormat::DXN1, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXN1}, | ||
| 111 | {TextureFormat::DXN1, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::DXN1}, | ||
| 112 | |||
| 113 | {TextureFormat::DXN2, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXN2UNORM}, | ||
| 114 | {TextureFormat::DXN2, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::DXN2SNORM}, | ||
| 115 | |||
| 116 | {TextureFormat::BC7U, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC7U}, | ||
| 117 | {TextureFormat::BC7U, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC7U_SRGB}, | ||
| 118 | |||
| 119 | {TextureFormat::BC6H_SF16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::BC6H_SF16}, | ||
| 120 | {TextureFormat::BC6H_UF16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::BC6H_UF16}, | ||
| 121 | |||
| 122 | {TextureFormat::ASTC_2D_4X4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_4X4}, | ||
| 123 | {TextureFormat::ASTC_2D_4X4, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_4X4_SRGB}, | ||
| 124 | |||
| 125 | {TextureFormat::ASTC_2D_5X4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X4}, | ||
| 126 | {TextureFormat::ASTC_2D_5X4, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X4_SRGB}, | ||
| 127 | |||
| 128 | {TextureFormat::ASTC_2D_5X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X5}, | ||
| 129 | {TextureFormat::ASTC_2D_5X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X5_SRGB}, | ||
| 130 | |||
| 131 | {TextureFormat::ASTC_2D_8X8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X8}, | ||
| 132 | {TextureFormat::ASTC_2D_8X8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X8_SRGB}, | ||
| 133 | |||
| 134 | {TextureFormat::ASTC_2D_8X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X5}, | ||
| 135 | {TextureFormat::ASTC_2D_8X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X5_SRGB}, | ||
| 136 | |||
| 137 | {TextureFormat::ASTC_2D_10X8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X8}, | ||
| 138 | {TextureFormat::ASTC_2D_10X8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X8_SRGB}, | ||
| 139 | |||
| 140 | {TextureFormat::ASTC_2D_6X6, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X6}, | ||
| 141 | {TextureFormat::ASTC_2D_6X6, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X6_SRGB}, | ||
| 142 | |||
| 143 | {TextureFormat::ASTC_2D_10X10, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X10}, | ||
| 144 | {TextureFormat::ASTC_2D_10X10, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X10_SRGB}, | ||
| 145 | |||
| 146 | {TextureFormat::ASTC_2D_12X12, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_12X12}, | ||
| 147 | {TextureFormat::ASTC_2D_12X12, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_12X12_SRGB}, | ||
| 148 | |||
| 149 | {TextureFormat::ASTC_2D_8X6, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X6}, | ||
| 150 | {TextureFormat::ASTC_2D_8X6, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X6_SRGB}, | ||
| 151 | |||
| 152 | {TextureFormat::ASTC_2D_6X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X5}, | ||
| 153 | {TextureFormat::ASTC_2D_6X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X5_SRGB}, | ||
| 154 | }}; | ||
| 155 | |||
| 156 | } // Anonymous namespace | ||
| 157 | |||
| 158 | FormatLookupTable::FormatLookupTable() { | ||
| 159 | table.fill(static_cast<u8>(PixelFormat::Invalid)); | ||
| 160 | |||
| 161 | for (const auto& entry : DefinitionTable) { | ||
| 162 | table[CalculateIndex(entry.texture_format, entry.is_srgb != 0, entry.red_component, | ||
| 163 | entry.green_component, entry.blue_component, entry.alpha_component)] = | ||
| 164 | static_cast<u8>(entry.pixel_format); | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | PixelFormat FormatLookupTable::GetPixelFormat(TextureFormat format, bool is_srgb, | ||
| 169 | ComponentType red_component, | ||
| 170 | ComponentType green_component, | ||
| 171 | ComponentType blue_component, | ||
| 172 | ComponentType alpha_component) const noexcept { | ||
| 173 | const auto pixel_format = static_cast<PixelFormat>(table[CalculateIndex( | ||
| 174 | format, is_srgb, red_component, green_component, blue_component, alpha_component)]); | ||
| 175 | // [[likely]] | ||
| 176 | if (pixel_format != PixelFormat::Invalid) { | ||
| 177 | return pixel_format; | ||
| 178 | } | ||
| 179 | UNIMPLEMENTED_MSG("texture format={} srgb={} components={{{} {} {} {}}}", | ||
| 180 | static_cast<int>(format), is_srgb, static_cast<int>(red_component), | ||
| 181 | static_cast<int>(green_component), static_cast<int>(blue_component), | ||
| 182 | static_cast<int>(alpha_component)); | ||
| 183 | return PixelFormat::ABGR8U; | ||
| 184 | } | ||
| 185 | |||
| 186 | void FormatLookupTable::Set(TextureFormat format, bool is_srgb, ComponentType red_component, | ||
| 187 | ComponentType green_component, ComponentType blue_component, | ||
| 188 | ComponentType alpha_component, PixelFormat pixel_format) {} | ||
| 189 | |||
| 190 | std::size_t FormatLookupTable::CalculateIndex(TextureFormat format, bool is_srgb, | ||
| 191 | ComponentType red_component, | ||
| 192 | ComponentType green_component, | ||
| 193 | ComponentType blue_component, | ||
| 194 | ComponentType alpha_component) noexcept { | ||
| 195 | const auto format_index = static_cast<std::size_t>(format); | ||
| 196 | const auto red_index = static_cast<std::size_t>(red_component); | ||
| 197 | const auto green_index = static_cast<std::size_t>(red_component); | ||
| 198 | const auto blue_index = static_cast<std::size_t>(red_component); | ||
| 199 | const auto alpha_index = static_cast<std::size_t>(red_component); | ||
| 200 | const std::size_t srgb_index = is_srgb ? 1 : 0; | ||
| 201 | |||
| 202 | return format_index * PerFormat + | ||
| 203 | srgb_index * PerComponent * PerComponent * PerComponent * PerComponent + | ||
| 204 | alpha_index * PerComponent * PerComponent * PerComponent + | ||
| 205 | blue_index * PerComponent * PerComponent + green_index * PerComponent + red_index; | ||
| 206 | } | ||
| 207 | |||
| 208 | } // namespace VideoCommon | ||
diff --git a/src/video_core/texture_cache/format_lookup_table.h b/src/video_core/texture_cache/format_lookup_table.h new file mode 100644 index 000000000..aa77e0a5a --- /dev/null +++ b/src/video_core/texture_cache/format_lookup_table.h | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <limits> | ||
| 9 | #include "video_core/surface.h" | ||
| 10 | #include "video_core/textures/texture.h" | ||
| 11 | |||
| 12 | namespace VideoCommon { | ||
| 13 | |||
| 14 | class FormatLookupTable { | ||
| 15 | public: | ||
| 16 | explicit FormatLookupTable(); | ||
| 17 | |||
| 18 | VideoCore::Surface::PixelFormat GetPixelFormat( | ||
| 19 | Tegra::Texture::TextureFormat format, bool is_srgb, | ||
| 20 | Tegra::Texture::ComponentType red_component, Tegra::Texture::ComponentType green_component, | ||
| 21 | Tegra::Texture::ComponentType blue_component, | ||
| 22 | Tegra::Texture::ComponentType alpha_component) const noexcept; | ||
| 23 | |||
| 24 | private: | ||
| 25 | static_assert(VideoCore::Surface::MaxPixelFormat <= std::numeric_limits<u8>::max()); | ||
| 26 | |||
| 27 | static constexpr std::size_t NumTextureFormats = 128; | ||
| 28 | |||
| 29 | static constexpr std::size_t PerComponent = 8; | ||
| 30 | static constexpr std::size_t PerComponents2 = PerComponent * PerComponent; | ||
| 31 | static constexpr std::size_t PerComponents3 = PerComponents2 * PerComponent; | ||
| 32 | static constexpr std::size_t PerComponents4 = PerComponents3 * PerComponent; | ||
| 33 | static constexpr std::size_t PerFormat = PerComponents4 * 2; | ||
| 34 | |||
| 35 | static std::size_t CalculateIndex(Tegra::Texture::TextureFormat format, bool is_srgb, | ||
| 36 | Tegra::Texture::ComponentType red_component, | ||
| 37 | Tegra::Texture::ComponentType green_component, | ||
| 38 | Tegra::Texture::ComponentType blue_component, | ||
| 39 | Tegra::Texture::ComponentType alpha_component) noexcept; | ||
| 40 | |||
| 41 | void Set(Tegra::Texture::TextureFormat format, bool is_srgb, | ||
| 42 | Tegra::Texture::ComponentType red_component, | ||
| 43 | Tegra::Texture::ComponentType green_component, | ||
| 44 | Tegra::Texture::ComponentType blue_component, | ||
| 45 | Tegra::Texture::ComponentType alpha_component, | ||
| 46 | VideoCore::Surface::PixelFormat pixel_format); | ||
| 47 | |||
| 48 | std::array<u8, NumTextureFormats * PerFormat> table; | ||
| 49 | }; | ||
| 50 | |||
| 51 | } // namespace VideoCommon | ||
diff --git a/src/video_core/texture_cache/surface_params.cpp b/src/video_core/texture_cache/surface_params.cpp index 1e4d3fb79..858e17e08 100644 --- a/src/video_core/texture_cache/surface_params.cpp +++ b/src/video_core/texture_cache/surface_params.cpp | |||
| @@ -2,24 +2,23 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <map> | 5 | #include <algorithm> |
| 6 | #include <string> | ||
| 7 | #include <tuple> | ||
| 6 | 8 | ||
| 7 | #include "common/alignment.h" | 9 | #include "common/alignment.h" |
| 8 | #include "common/bit_util.h" | 10 | #include "common/bit_util.h" |
| 9 | #include "core/core.h" | 11 | #include "core/core.h" |
| 10 | #include "video_core/engines/shader_bytecode.h" | 12 | #include "video_core/engines/shader_bytecode.h" |
| 11 | #include "video_core/surface.h" | 13 | #include "video_core/surface.h" |
| 14 | #include "video_core/texture_cache/format_lookup_table.h" | ||
| 12 | #include "video_core/texture_cache/surface_params.h" | 15 | #include "video_core/texture_cache/surface_params.h" |
| 13 | 16 | ||
| 14 | namespace VideoCommon { | 17 | namespace VideoCommon { |
| 15 | 18 | ||
| 16 | using VideoCore::Surface::ComponentTypeFromDepthFormat; | ||
| 17 | using VideoCore::Surface::ComponentTypeFromRenderTarget; | ||
| 18 | using VideoCore::Surface::ComponentTypeFromTexture; | ||
| 19 | using VideoCore::Surface::PixelFormat; | 19 | using VideoCore::Surface::PixelFormat; |
| 20 | using VideoCore::Surface::PixelFormatFromDepthFormat; | 20 | using VideoCore::Surface::PixelFormatFromDepthFormat; |
| 21 | using VideoCore::Surface::PixelFormatFromRenderTargetFormat; | 21 | using VideoCore::Surface::PixelFormatFromRenderTargetFormat; |
| 22 | using VideoCore::Surface::PixelFormatFromTextureFormat; | ||
| 23 | using VideoCore::Surface::SurfaceTarget; | 22 | using VideoCore::Surface::SurfaceTarget; |
| 24 | using VideoCore::Surface::SurfaceTargetFromTextureType; | 23 | using VideoCore::Surface::SurfaceTargetFromTextureType; |
| 25 | using VideoCore::Surface::SurfaceType; | 24 | using VideoCore::Surface::SurfaceType; |
| @@ -69,7 +68,8 @@ constexpr u32 GetMipmapSize(bool uncompressed, u32 mip_size, u32 tile) { | |||
| 69 | 68 | ||
| 70 | } // Anonymous namespace | 69 | } // Anonymous namespace |
| 71 | 70 | ||
| 72 | SurfaceParams SurfaceParams::CreateForTexture(const Tegra::Texture::TICEntry& tic, | 71 | SurfaceParams SurfaceParams::CreateForTexture(const FormatLookupTable& lookup_table, |
| 72 | const Tegra::Texture::TICEntry& tic, | ||
| 73 | const VideoCommon::Shader::Sampler& entry) { | 73 | const VideoCommon::Shader::Sampler& entry) { |
| 74 | SurfaceParams params; | 74 | SurfaceParams params; |
| 75 | params.is_tiled = tic.IsTiled(); | 75 | params.is_tiled = tic.IsTiled(); |
| @@ -78,8 +78,8 @@ SurfaceParams SurfaceParams::CreateForTexture(const Tegra::Texture::TICEntry& ti | |||
| 78 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0, | 78 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0, |
| 79 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0, | 79 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0, |
| 80 | params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1; | 80 | params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1; |
| 81 | params.pixel_format = | 81 | params.pixel_format = lookup_table.GetPixelFormat( |
| 82 | PixelFormatFromTextureFormat(tic.format, tic.r_type.Value(), params.srgb_conversion); | 82 | tic.format, params.srgb_conversion, tic.r_type, tic.g_type, tic.b_type, tic.a_type); |
| 83 | params.type = GetFormatType(params.pixel_format); | 83 | params.type = GetFormatType(params.pixel_format); |
| 84 | if (entry.IsShadow() && params.type == SurfaceType::ColorTexture) { | 84 | if (entry.IsShadow() && params.type == SurfaceType::ColorTexture) { |
| 85 | switch (params.pixel_format) { | 85 | switch (params.pixel_format) { |
| @@ -99,7 +99,6 @@ SurfaceParams SurfaceParams::CreateForTexture(const Tegra::Texture::TICEntry& ti | |||
| 99 | } | 99 | } |
| 100 | params.type = GetFormatType(params.pixel_format); | 100 | params.type = GetFormatType(params.pixel_format); |
| 101 | } | 101 | } |
| 102 | params.component_type = ComponentTypeFromTexture(tic.r_type.Value()); | ||
| 103 | params.type = GetFormatType(params.pixel_format); | 102 | params.type = GetFormatType(params.pixel_format); |
| 104 | // TODO: on 1DBuffer we should use the tic info. | 103 | // TODO: on 1DBuffer we should use the tic info. |
| 105 | if (tic.IsBuffer()) { | 104 | if (tic.IsBuffer()) { |
| @@ -128,7 +127,8 @@ SurfaceParams SurfaceParams::CreateForTexture(const Tegra::Texture::TICEntry& ti | |||
| 128 | return params; | 127 | return params; |
| 129 | } | 128 | } |
| 130 | 129 | ||
| 131 | SurfaceParams SurfaceParams::CreateForImage(const Tegra::Texture::TICEntry& tic, | 130 | SurfaceParams SurfaceParams::CreateForImage(const FormatLookupTable& lookup_table, |
| 131 | const Tegra::Texture::TICEntry& tic, | ||
| 132 | const VideoCommon::Shader::Image& entry) { | 132 | const VideoCommon::Shader::Image& entry) { |
| 133 | SurfaceParams params; | 133 | SurfaceParams params; |
| 134 | params.is_tiled = tic.IsTiled(); | 134 | params.is_tiled = tic.IsTiled(); |
| @@ -137,10 +137,9 @@ SurfaceParams SurfaceParams::CreateForImage(const Tegra::Texture::TICEntry& tic, | |||
| 137 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0, | 137 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0, |
| 138 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0, | 138 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0, |
| 139 | params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1; | 139 | params.tile_width_spacing = params.is_tiled ? (1 << tic.tile_width_spacing.Value()) : 1; |
| 140 | params.pixel_format = | 140 | params.pixel_format = lookup_table.GetPixelFormat( |
| 141 | PixelFormatFromTextureFormat(tic.format, tic.r_type.Value(), params.srgb_conversion); | 141 | tic.format, params.srgb_conversion, tic.r_type, tic.g_type, tic.b_type, tic.a_type); |
| 142 | params.type = GetFormatType(params.pixel_format); | 142 | params.type = GetFormatType(params.pixel_format); |
| 143 | params.component_type = ComponentTypeFromTexture(tic.r_type.Value()); | ||
| 144 | params.type = GetFormatType(params.pixel_format); | 143 | params.type = GetFormatType(params.pixel_format); |
| 145 | params.target = ImageTypeToSurfaceTarget(entry.GetType()); | 144 | params.target = ImageTypeToSurfaceTarget(entry.GetType()); |
| 146 | // TODO: on 1DBuffer we should use the tic info. | 145 | // TODO: on 1DBuffer we should use the tic info. |
| @@ -181,7 +180,6 @@ SurfaceParams SurfaceParams::CreateForDepthBuffer( | |||
| 181 | params.block_depth = std::min(block_depth, 5U); | 180 | params.block_depth = std::min(block_depth, 5U); |
| 182 | params.tile_width_spacing = 1; | 181 | params.tile_width_spacing = 1; |
| 183 | params.pixel_format = PixelFormatFromDepthFormat(format); | 182 | params.pixel_format = PixelFormatFromDepthFormat(format); |
| 184 | params.component_type = ComponentTypeFromDepthFormat(format); | ||
| 185 | params.type = GetFormatType(params.pixel_format); | 183 | params.type = GetFormatType(params.pixel_format); |
| 186 | params.width = zeta_width; | 184 | params.width = zeta_width; |
| 187 | params.height = zeta_height; | 185 | params.height = zeta_height; |
| @@ -206,7 +204,6 @@ SurfaceParams SurfaceParams::CreateForFramebuffer(Core::System& system, std::siz | |||
| 206 | params.block_depth = config.memory_layout.block_depth; | 204 | params.block_depth = config.memory_layout.block_depth; |
| 207 | params.tile_width_spacing = 1; | 205 | params.tile_width_spacing = 1; |
| 208 | params.pixel_format = PixelFormatFromRenderTargetFormat(config.format); | 206 | params.pixel_format = PixelFormatFromRenderTargetFormat(config.format); |
| 209 | params.component_type = ComponentTypeFromRenderTarget(config.format); | ||
| 210 | params.type = GetFormatType(params.pixel_format); | 207 | params.type = GetFormatType(params.pixel_format); |
| 211 | if (params.is_tiled) { | 208 | if (params.is_tiled) { |
| 212 | params.pitch = 0; | 209 | params.pitch = 0; |
| @@ -236,7 +233,6 @@ SurfaceParams SurfaceParams::CreateForFermiCopySurface( | |||
| 236 | params.block_depth = params.is_tiled ? std::min(config.BlockDepth(), 5U) : 0, | 233 | params.block_depth = params.is_tiled ? std::min(config.BlockDepth(), 5U) : 0, |
| 237 | params.tile_width_spacing = 1; | 234 | params.tile_width_spacing = 1; |
| 238 | params.pixel_format = PixelFormatFromRenderTargetFormat(config.format); | 235 | params.pixel_format = PixelFormatFromRenderTargetFormat(config.format); |
| 239 | params.component_type = ComponentTypeFromRenderTarget(config.format); | ||
| 240 | params.type = GetFormatType(params.pixel_format); | 236 | params.type = GetFormatType(params.pixel_format); |
| 241 | params.width = config.width; | 237 | params.width = config.width; |
| 242 | params.height = config.height; | 238 | params.height = config.height; |
| @@ -355,10 +351,10 @@ std::size_t SurfaceParams::GetInnerMipmapMemorySize(u32 level, bool as_host_size | |||
| 355 | 351 | ||
| 356 | bool SurfaceParams::operator==(const SurfaceParams& rhs) const { | 352 | bool SurfaceParams::operator==(const SurfaceParams& rhs) const { |
| 357 | return std::tie(is_tiled, block_width, block_height, block_depth, tile_width_spacing, width, | 353 | return std::tie(is_tiled, block_width, block_height, block_depth, tile_width_spacing, width, |
| 358 | height, depth, pitch, num_levels, pixel_format, component_type, type, target) == | 354 | height, depth, pitch, num_levels, pixel_format, type, target) == |
| 359 | std::tie(rhs.is_tiled, rhs.block_width, rhs.block_height, rhs.block_depth, | 355 | std::tie(rhs.is_tiled, rhs.block_width, rhs.block_height, rhs.block_depth, |
| 360 | rhs.tile_width_spacing, rhs.width, rhs.height, rhs.depth, rhs.pitch, | 356 | rhs.tile_width_spacing, rhs.width, rhs.height, rhs.depth, rhs.pitch, |
| 361 | rhs.num_levels, rhs.pixel_format, rhs.component_type, rhs.type, rhs.target); | 357 | rhs.num_levels, rhs.pixel_format, rhs.type, rhs.target); |
| 362 | } | 358 | } |
| 363 | 359 | ||
| 364 | std::string SurfaceParams::TargetName() const { | 360 | std::string SurfaceParams::TargetName() const { |
diff --git a/src/video_core/texture_cache/surface_params.h b/src/video_core/texture_cache/surface_params.h index c58e7f8a4..709aa0dc2 100644 --- a/src/video_core/texture_cache/surface_params.h +++ b/src/video_core/texture_cache/surface_params.h | |||
| @@ -16,16 +16,20 @@ | |||
| 16 | 16 | ||
| 17 | namespace VideoCommon { | 17 | namespace VideoCommon { |
| 18 | 18 | ||
| 19 | class FormatLookupTable; | ||
| 20 | |||
| 19 | using VideoCore::Surface::SurfaceCompression; | 21 | using VideoCore::Surface::SurfaceCompression; |
| 20 | 22 | ||
| 21 | class SurfaceParams { | 23 | class SurfaceParams { |
| 22 | public: | 24 | public: |
| 23 | /// Creates SurfaceCachedParams from a texture configuration. | 25 | /// Creates SurfaceCachedParams from a texture configuration. |
| 24 | static SurfaceParams CreateForTexture(const Tegra::Texture::TICEntry& tic, | 26 | static SurfaceParams CreateForTexture(const FormatLookupTable& lookup_table, |
| 27 | const Tegra::Texture::TICEntry& tic, | ||
| 25 | const VideoCommon::Shader::Sampler& entry); | 28 | const VideoCommon::Shader::Sampler& entry); |
| 26 | 29 | ||
| 27 | /// Creates SurfaceCachedParams from an image configuration. | 30 | /// Creates SurfaceCachedParams from an image configuration. |
| 28 | static SurfaceParams CreateForImage(const Tegra::Texture::TICEntry& tic, | 31 | static SurfaceParams CreateForImage(const FormatLookupTable& lookup_table, |
| 32 | const Tegra::Texture::TICEntry& tic, | ||
| 29 | const VideoCommon::Shader::Image& entry); | 33 | const VideoCommon::Shader::Image& entry); |
| 30 | 34 | ||
| 31 | /// Creates SurfaceCachedParams for a depth buffer configuration. | 35 | /// Creates SurfaceCachedParams for a depth buffer configuration. |
| @@ -248,7 +252,6 @@ public: | |||
| 248 | u32 num_levels; | 252 | u32 num_levels; |
| 249 | u32 emulated_levels; | 253 | u32 emulated_levels; |
| 250 | VideoCore::Surface::PixelFormat pixel_format; | 254 | VideoCore::Surface::PixelFormat pixel_format; |
| 251 | VideoCore::Surface::ComponentType component_type; | ||
| 252 | VideoCore::Surface::SurfaceType type; | 255 | VideoCore::Surface::SurfaceType type; |
| 253 | VideoCore::Surface::SurfaceTarget target; | 256 | VideoCore::Surface::SurfaceTarget target; |
| 254 | 257 | ||
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 6a92b22d3..41309ebea 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -29,6 +29,7 @@ | |||
| 29 | #include "video_core/rasterizer_interface.h" | 29 | #include "video_core/rasterizer_interface.h" |
| 30 | #include "video_core/surface.h" | 30 | #include "video_core/surface.h" |
| 31 | #include "video_core/texture_cache/copy_params.h" | 31 | #include "video_core/texture_cache/copy_params.h" |
| 32 | #include "video_core/texture_cache/format_lookup_table.h" | ||
| 32 | #include "video_core/texture_cache/surface_base.h" | 33 | #include "video_core/texture_cache/surface_base.h" |
| 33 | #include "video_core/texture_cache/surface_params.h" | 34 | #include "video_core/texture_cache/surface_params.h" |
| 34 | #include "video_core/texture_cache/surface_view.h" | 35 | #include "video_core/texture_cache/surface_view.h" |
| @@ -96,7 +97,7 @@ public: | |||
| 96 | if (!gpu_addr) { | 97 | if (!gpu_addr) { |
| 97 | return {}; | 98 | return {}; |
| 98 | } | 99 | } |
| 99 | const auto params{SurfaceParams::CreateForTexture(tic, entry)}; | 100 | const auto params{SurfaceParams::CreateForTexture(format_lookup_table, tic, entry)}; |
| 100 | const auto [surface, view] = GetSurface(gpu_addr, params, true, false); | 101 | const auto [surface, view] = GetSurface(gpu_addr, params, true, false); |
| 101 | if (guard_samplers) { | 102 | if (guard_samplers) { |
| 102 | sampled_textures.push_back(surface); | 103 | sampled_textures.push_back(surface); |
| @@ -111,7 +112,7 @@ public: | |||
| 111 | if (!gpu_addr) { | 112 | if (!gpu_addr) { |
| 112 | return {}; | 113 | return {}; |
| 113 | } | 114 | } |
| 114 | const auto params{SurfaceParams::CreateForImage(tic, entry)}; | 115 | const auto params{SurfaceParams::CreateForImage(format_lookup_table, tic, entry)}; |
| 115 | const auto [surface, view] = GetSurface(gpu_addr, params, true, false); | 116 | const auto [surface, view] = GetSurface(gpu_addr, params, true, false); |
| 116 | if (guard_samplers) { | 117 | if (guard_samplers) { |
| 117 | sampled_textures.push_back(surface); | 118 | sampled_textures.push_back(surface); |
| @@ -485,15 +486,13 @@ private: | |||
| 485 | GetSiblingFormat(cr_params.pixel_format) == params.pixel_format) { | 486 | GetSiblingFormat(cr_params.pixel_format) == params.pixel_format) { |
| 486 | SurfaceParams new_params = params; | 487 | SurfaceParams new_params = params; |
| 487 | new_params.pixel_format = cr_params.pixel_format; | 488 | new_params.pixel_format = cr_params.pixel_format; |
| 488 | new_params.component_type = cr_params.component_type; | ||
| 489 | new_params.type = cr_params.type; | 489 | new_params.type = cr_params.type; |
| 490 | new_surface = GetUncachedSurface(gpu_addr, new_params); | 490 | new_surface = GetUncachedSurface(gpu_addr, new_params); |
| 491 | } else { | 491 | } else { |
| 492 | new_surface = GetUncachedSurface(gpu_addr, params); | 492 | new_surface = GetUncachedSurface(gpu_addr, params); |
| 493 | } | 493 | } |
| 494 | const auto& final_params = new_surface->GetSurfaceParams(); | 494 | const auto& final_params = new_surface->GetSurfaceParams(); |
| 495 | if (cr_params.type != final_params.type || | 495 | if (cr_params.type != final_params.type) { |
| 496 | (cr_params.component_type != final_params.component_type)) { | ||
| 497 | BufferCopy(current_surface, new_surface); | 496 | BufferCopy(current_surface, new_surface); |
| 498 | } else { | 497 | } else { |
| 499 | std::vector<CopyParams> bricks = current_surface->BreakDown(final_params); | 498 | std::vector<CopyParams> bricks = current_surface->BreakDown(final_params); |
| @@ -835,12 +834,11 @@ private: | |||
| 835 | } | 834 | } |
| 836 | } | 835 | } |
| 837 | 836 | ||
| 838 | const auto inherit_format = ([](SurfaceParams& to, TSurface from) { | 837 | const auto inherit_format = [](SurfaceParams& to, TSurface from) { |
| 839 | const SurfaceParams& params = from->GetSurfaceParams(); | 838 | const SurfaceParams& params = from->GetSurfaceParams(); |
| 840 | to.pixel_format = params.pixel_format; | 839 | to.pixel_format = params.pixel_format; |
| 841 | to.component_type = params.component_type; | ||
| 842 | to.type = params.type; | 840 | to.type = params.type; |
| 843 | }); | 841 | }; |
| 844 | // Now we got the cases where one or both is Depth and the other is not known | 842 | // Now we got the cases where one or both is Depth and the other is not known |
| 845 | if (!incomplete_src) { | 843 | if (!incomplete_src) { |
| 846 | inherit_format(src_params, deduced_src.surface); | 844 | inherit_format(src_params, deduced_src.surface); |
| @@ -956,6 +954,8 @@ private: | |||
| 956 | 954 | ||
| 957 | VideoCore::RasterizerInterface& rasterizer; | 955 | VideoCore::RasterizerInterface& rasterizer; |
| 958 | 956 | ||
| 957 | FormatLookupTable format_lookup_table; | ||
| 958 | |||
| 959 | u64 ticks{}; | 959 | u64 ticks{}; |
| 960 | 960 | ||
| 961 | // Guards the cache for protection conflicts. | 961 | // Guards the cache for protection conflicts. |