diff options
Diffstat (limited to 'src/video_core/texture_cache')
| -rw-r--r-- | src/video_core/texture_cache/format_lookup_table.cpp | 214 | ||||
| -rw-r--r-- | src/video_core/texture_cache/format_lookup_table.h | 51 | ||||
| -rw-r--r-- | src/video_core/texture_cache/surface_params.cpp | 20 | ||||
| -rw-r--r-- | src/video_core/texture_cache/surface_params.h | 8 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 7 |
5 files changed, 288 insertions, 12 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..ee050cc31 --- /dev/null +++ b/src/video_core/texture_cache/format_lookup_table.cpp | |||
| @@ -0,0 +1,214 @@ | |||
| 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 | static constexpr auto SNORM = ComponentType::SNORM; | ||
| 19 | static constexpr auto UNORM = ComponentType::UNORM; | ||
| 20 | static constexpr auto SINT = ComponentType::SINT; | ||
| 21 | static constexpr auto UINT = ComponentType::UINT; | ||
| 22 | static constexpr auto SNORM_FORCE_FP16 = ComponentType::SNORM_FORCE_FP16; | ||
| 23 | static constexpr auto UNORM_FORCE_FP16 = ComponentType::UNORM_FORCE_FP16; | ||
| 24 | static constexpr auto FLOAT = ComponentType::FLOAT; | ||
| 25 | static constexpr bool C = false; // Normal color | ||
| 26 | static 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{static_cast<u32>(texture_format)}, | ||
| 33 | pixel_format{static_cast<u32>(pixel_format)}, red_component{static_cast<u32>( | ||
| 34 | red_component)}, | ||
| 35 | green_component{static_cast<u32>(green_component)}, blue_component{static_cast<u32>( | ||
| 36 | blue_component)}, | ||
| 37 | alpha_component{static_cast<u32>(alpha_component)}, is_srgb{is_srgb ? 1U : 0U} {} | ||
| 38 | |||
| 39 | u32 texture_format : 8; | ||
| 40 | u32 pixel_format : 8; | ||
| 41 | u32 red_component : 3; | ||
| 42 | u32 green_component : 3; | ||
| 43 | u32 blue_component : 3; | ||
| 44 | u32 alpha_component : 3; | ||
| 45 | u32 is_srgb : 1; | ||
| 46 | }; | ||
| 47 | constexpr std::array<Table, 74> DefinitionTable = {{ | ||
| 48 | {TextureFormat::A8R8G8B8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ABGR8U}, | ||
| 49 | {TextureFormat::A8R8G8B8, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::ABGR8S}, | ||
| 50 | {TextureFormat::A8R8G8B8, C, UINT, UINT, UINT, UINT, PixelFormat::ABGR8UI}, | ||
| 51 | {TextureFormat::A8R8G8B8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::RGBA8_SRGB}, | ||
| 52 | |||
| 53 | {TextureFormat::B5G6R5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::B5G6R5U}, | ||
| 54 | |||
| 55 | {TextureFormat::A2B10G10R10, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::A2B10G10R10U}, | ||
| 56 | |||
| 57 | {TextureFormat::A1B5G5R5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::A1B5G5R5U}, | ||
| 58 | |||
| 59 | {TextureFormat::A4B4G4R4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R4G4B4A4U}, | ||
| 60 | |||
| 61 | {TextureFormat::R8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R8U}, | ||
| 62 | {TextureFormat::R8, C, UINT, UINT, UINT, UINT, PixelFormat::R8UI}, | ||
| 63 | |||
| 64 | {TextureFormat::G8R8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::RG8U}, | ||
| 65 | {TextureFormat::G8R8, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::RG8S}, | ||
| 66 | |||
| 67 | {TextureFormat::R16_G16_B16_A16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::RGBA16U}, | ||
| 68 | {TextureFormat::R16_G16_B16_A16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RGBA16F}, | ||
| 69 | {TextureFormat::R16_G16_B16_A16, C, UINT, UINT, UINT, UINT, PixelFormat::RGBA16UI}, | ||
| 70 | |||
| 71 | {TextureFormat::R16_G16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RG16F}, | ||
| 72 | {TextureFormat::R16_G16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::RG16}, | ||
| 73 | {TextureFormat::R16_G16, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::RG16S}, | ||
| 74 | {TextureFormat::R16_G16, C, UINT, UINT, UINT, UINT, PixelFormat::RG16UI}, | ||
| 75 | {TextureFormat::R16_G16, C, SINT, SINT, SINT, SINT, PixelFormat::RG16I}, | ||
| 76 | |||
| 77 | {TextureFormat::R16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R16F}, | ||
| 78 | {TextureFormat::R16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::R16U}, | ||
| 79 | {TextureFormat::R16, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::R16S}, | ||
| 80 | {TextureFormat::R16, C, UINT, UINT, UINT, UINT, PixelFormat::R16UI}, | ||
| 81 | {TextureFormat::R16, C, SINT, SINT, SINT, SINT, PixelFormat::R16I}, | ||
| 82 | |||
| 83 | {TextureFormat::BF10GF11RF11, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R11FG11FB10F}, | ||
| 84 | |||
| 85 | {TextureFormat::R32_G32_B32_A32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RGBA32F}, | ||
| 86 | {TextureFormat::R32_G32_B32_A32, C, UINT, UINT, UINT, UINT, PixelFormat::RGBA32UI}, | ||
| 87 | |||
| 88 | {TextureFormat::R32_G32_B32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RGB32F}, | ||
| 89 | |||
| 90 | {TextureFormat::R32_G32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::RG32F}, | ||
| 91 | {TextureFormat::R32_G32, C, UINT, UINT, UINT, UINT, PixelFormat::RG32UI}, | ||
| 92 | |||
| 93 | {TextureFormat::R32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::R32F}, | ||
| 94 | {TextureFormat::R32, C, UINT, UINT, UINT, UINT, PixelFormat::R32UI}, | ||
| 95 | |||
| 96 | {TextureFormat::E5B9G9R9_SHAREDEXP, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::E5B9G9R9F}, | ||
| 97 | |||
| 98 | {TextureFormat::ZF32, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::Z32F}, | ||
| 99 | {TextureFormat::Z16, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::Z16}, | ||
| 100 | {TextureFormat::S8Z24, C, UINT, UNORM, UNORM, UNORM, PixelFormat::S8Z24}, | ||
| 101 | {TextureFormat::ZF32_X24S8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::Z32FS8}, | ||
| 102 | |||
| 103 | {TextureFormat::DXT1, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT1}, | ||
| 104 | {TextureFormat::DXT1, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT1_SRGB}, | ||
| 105 | |||
| 106 | {TextureFormat::DXT23, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT23}, | ||
| 107 | {TextureFormat::DXT23, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT23_SRGB}, | ||
| 108 | |||
| 109 | {TextureFormat::DXT45, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT45}, | ||
| 110 | {TextureFormat::DXT45, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXT45_SRGB}, | ||
| 111 | |||
| 112 | // TODO: Use a different pixel format for SNORM | ||
| 113 | {TextureFormat::DXN1, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXN1}, | ||
| 114 | {TextureFormat::DXN1, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::DXN1}, | ||
| 115 | |||
| 116 | {TextureFormat::DXN2, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::DXN2UNORM}, | ||
| 117 | {TextureFormat::DXN2, C, SNORM, SNORM, SNORM, SNORM, PixelFormat::DXN2SNORM}, | ||
| 118 | |||
| 119 | {TextureFormat::BC7U, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC7U}, | ||
| 120 | {TextureFormat::BC7U, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::BC7U_SRGB}, | ||
| 121 | |||
| 122 | {TextureFormat::BC6H_SF16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::BC6H_SF16}, | ||
| 123 | {TextureFormat::BC6H_UF16, C, FLOAT, FLOAT, FLOAT, FLOAT, PixelFormat::BC6H_UF16}, | ||
| 124 | |||
| 125 | {TextureFormat::ASTC_2D_4X4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_4X4}, | ||
| 126 | {TextureFormat::ASTC_2D_4X4, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_4X4_SRGB}, | ||
| 127 | |||
| 128 | {TextureFormat::ASTC_2D_5X4, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X4}, | ||
| 129 | {TextureFormat::ASTC_2D_5X4, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X4_SRGB}, | ||
| 130 | |||
| 131 | {TextureFormat::ASTC_2D_5X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X5}, | ||
| 132 | {TextureFormat::ASTC_2D_5X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_5X5_SRGB}, | ||
| 133 | |||
| 134 | {TextureFormat::ASTC_2D_8X8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X8}, | ||
| 135 | {TextureFormat::ASTC_2D_8X8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X8_SRGB}, | ||
| 136 | |||
| 137 | {TextureFormat::ASTC_2D_8X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X5}, | ||
| 138 | {TextureFormat::ASTC_2D_8X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X5_SRGB}, | ||
| 139 | |||
| 140 | {TextureFormat::ASTC_2D_10X8, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X8}, | ||
| 141 | {TextureFormat::ASTC_2D_10X8, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X8_SRGB}, | ||
| 142 | |||
| 143 | {TextureFormat::ASTC_2D_6X6, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X6}, | ||
| 144 | {TextureFormat::ASTC_2D_6X6, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X6_SRGB}, | ||
| 145 | |||
| 146 | {TextureFormat::ASTC_2D_10X10, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X10}, | ||
| 147 | {TextureFormat::ASTC_2D_10X10, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_10X10_SRGB}, | ||
| 148 | |||
| 149 | {TextureFormat::ASTC_2D_12X12, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_12X12}, | ||
| 150 | {TextureFormat::ASTC_2D_12X12, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_12X12_SRGB}, | ||
| 151 | |||
| 152 | {TextureFormat::ASTC_2D_8X6, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X6}, | ||
| 153 | {TextureFormat::ASTC_2D_8X6, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_8X6_SRGB}, | ||
| 154 | |||
| 155 | {TextureFormat::ASTC_2D_6X5, C, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X5}, | ||
| 156 | {TextureFormat::ASTC_2D_6X5, S, UNORM, UNORM, UNORM, UNORM, PixelFormat::ASTC_2D_6X5_SRGB}, | ||
| 157 | }}; | ||
| 158 | |||
| 159 | } // Anonymous namespace | ||
| 160 | |||
| 161 | FormatLookupTable::FormatLookupTable() { | ||
| 162 | table.fill(static_cast<u8>(PixelFormat::Invalid)); | ||
| 163 | |||
| 164 | for (const auto entry : DefinitionTable) { | ||
| 165 | table[CalculateIndex(static_cast<TextureFormat>(entry.texture_format), entry.is_srgb != 0, | ||
| 166 | static_cast<ComponentType>(entry.red_component), | ||
| 167 | static_cast<ComponentType>(entry.green_component), | ||
| 168 | static_cast<ComponentType>(entry.blue_component), | ||
| 169 | static_cast<ComponentType>(entry.alpha_component))] = | ||
| 170 | static_cast<u8>(entry.pixel_format); | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | PixelFormat FormatLookupTable::GetPixelFormat(TextureFormat format, bool is_srgb, | ||
| 175 | ComponentType red_component, | ||
| 176 | ComponentType green_component, | ||
| 177 | ComponentType blue_component, | ||
| 178 | ComponentType alpha_component) const noexcept { | ||
| 179 | const auto pixel_format = static_cast<PixelFormat>(table[CalculateIndex( | ||
| 180 | format, is_srgb, red_component, green_component, blue_component, alpha_component)]); | ||
| 181 | // [[likely]] | ||
| 182 | if (pixel_format != PixelFormat::Invalid) { | ||
| 183 | return pixel_format; | ||
| 184 | } | ||
| 185 | UNIMPLEMENTED_MSG("texture format={} srgb={} components={{{} {} {} {}}}", | ||
| 186 | static_cast<int>(format), is_srgb, static_cast<int>(red_component), | ||
| 187 | static_cast<int>(green_component), static_cast<int>(blue_component), | ||
| 188 | static_cast<int>(alpha_component)); | ||
| 189 | return PixelFormat::ABGR8U; | ||
| 190 | } | ||
| 191 | |||
| 192 | void FormatLookupTable::Set(TextureFormat format, bool is_srgb, ComponentType red_component, | ||
| 193 | ComponentType green_component, ComponentType blue_component, | ||
| 194 | ComponentType alpha_component, PixelFormat pixel_format) {} | ||
| 195 | |||
| 196 | std::size_t FormatLookupTable::CalculateIndex(TextureFormat format, bool is_srgb, | ||
| 197 | ComponentType red_component, | ||
| 198 | ComponentType green_component, | ||
| 199 | ComponentType blue_component, | ||
| 200 | ComponentType alpha_component) noexcept { | ||
| 201 | const auto format_index = static_cast<std::size_t>(format); | ||
| 202 | const auto red_index = static_cast<std::size_t>(red_component); | ||
| 203 | const auto green_index = static_cast<std::size_t>(red_component); | ||
| 204 | const auto blue_index = static_cast<std::size_t>(red_component); | ||
| 205 | const auto alpha_index = static_cast<std::size_t>(red_component); | ||
| 206 | const std::size_t srgb_index = is_srgb ? 1 : 0; | ||
| 207 | |||
| 208 | return format_index * PerFormat + | ||
| 209 | srgb_index * PerComponent * PerComponent * PerComponent * PerComponent + | ||
| 210 | alpha_index * PerComponent * PerComponent * PerComponent + | ||
| 211 | blue_index * PerComponent * PerComponent + green_index * PerComponent + red_index; | ||
| 212 | } | ||
| 213 | |||
| 214 | } // 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..8da7481cd --- /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 <numeric> | ||
| 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 04b5e8ba3..858e17e08 100644 --- a/src/video_core/texture_cache/surface_params.cpp +++ b/src/video_core/texture_cache/surface_params.cpp | |||
| @@ -2,13 +2,16 @@ | |||
| 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 { |
| @@ -16,7 +19,6 @@ namespace VideoCommon { | |||
| 16 | using VideoCore::Surface::PixelFormat; | 19 | using VideoCore::Surface::PixelFormat; |
| 17 | using VideoCore::Surface::PixelFormatFromDepthFormat; | 20 | using VideoCore::Surface::PixelFormatFromDepthFormat; |
| 18 | using VideoCore::Surface::PixelFormatFromRenderTargetFormat; | 21 | using VideoCore::Surface::PixelFormatFromRenderTargetFormat; |
| 19 | using VideoCore::Surface::PixelFormatFromTextureFormat; | ||
| 20 | using VideoCore::Surface::SurfaceTarget; | 22 | using VideoCore::Surface::SurfaceTarget; |
| 21 | using VideoCore::Surface::SurfaceTargetFromTextureType; | 23 | using VideoCore::Surface::SurfaceTargetFromTextureType; |
| 22 | using VideoCore::Surface::SurfaceType; | 24 | using VideoCore::Surface::SurfaceType; |
| @@ -66,7 +68,8 @@ constexpr u32 GetMipmapSize(bool uncompressed, u32 mip_size, u32 tile) { | |||
| 66 | 68 | ||
| 67 | } // Anonymous namespace | 69 | } // Anonymous namespace |
| 68 | 70 | ||
| 69 | SurfaceParams SurfaceParams::CreateForTexture(const Tegra::Texture::TICEntry& tic, | 71 | SurfaceParams SurfaceParams::CreateForTexture(const FormatLookupTable& lookup_table, |
| 72 | const Tegra::Texture::TICEntry& tic, | ||
| 70 | const VideoCommon::Shader::Sampler& entry) { | 73 | const VideoCommon::Shader::Sampler& entry) { |
| 71 | SurfaceParams params; | 74 | SurfaceParams params; |
| 72 | params.is_tiled = tic.IsTiled(); | 75 | params.is_tiled = tic.IsTiled(); |
| @@ -75,8 +78,8 @@ SurfaceParams SurfaceParams::CreateForTexture(const Tegra::Texture::TICEntry& ti | |||
| 75 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0, | 78 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0, |
| 76 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0, | 79 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0, |
| 77 | 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; |
| 78 | params.pixel_format = | 81 | params.pixel_format = lookup_table.GetPixelFormat( |
| 79 | 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); |
| 80 | params.type = GetFormatType(params.pixel_format); | 83 | params.type = GetFormatType(params.pixel_format); |
| 81 | if (entry.IsShadow() && params.type == SurfaceType::ColorTexture) { | 84 | if (entry.IsShadow() && params.type == SurfaceType::ColorTexture) { |
| 82 | switch (params.pixel_format) { | 85 | switch (params.pixel_format) { |
| @@ -124,7 +127,8 @@ SurfaceParams SurfaceParams::CreateForTexture(const Tegra::Texture::TICEntry& ti | |||
| 124 | return params; | 127 | return params; |
| 125 | } | 128 | } |
| 126 | 129 | ||
| 127 | SurfaceParams SurfaceParams::CreateForImage(const Tegra::Texture::TICEntry& tic, | 130 | SurfaceParams SurfaceParams::CreateForImage(const FormatLookupTable& lookup_table, |
| 131 | const Tegra::Texture::TICEntry& tic, | ||
| 128 | const VideoCommon::Shader::Image& entry) { | 132 | const VideoCommon::Shader::Image& entry) { |
| 129 | SurfaceParams params; | 133 | SurfaceParams params; |
| 130 | params.is_tiled = tic.IsTiled(); | 134 | params.is_tiled = tic.IsTiled(); |
| @@ -133,8 +137,8 @@ SurfaceParams SurfaceParams::CreateForImage(const Tegra::Texture::TICEntry& tic, | |||
| 133 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0, | 137 | params.block_height = params.is_tiled ? tic.BlockHeight() : 0, |
| 134 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0, | 138 | params.block_depth = params.is_tiled ? tic.BlockDepth() : 0, |
| 135 | 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; |
| 136 | params.pixel_format = | 140 | params.pixel_format = lookup_table.GetPixelFormat( |
| 137 | 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); |
| 138 | params.type = GetFormatType(params.pixel_format); | 142 | params.type = GetFormatType(params.pixel_format); |
| 139 | params.type = GetFormatType(params.pixel_format); | 143 | params.type = GetFormatType(params.pixel_format); |
| 140 | params.target = ImageTypeToSurfaceTarget(entry.GetType()); | 144 | params.target = ImageTypeToSurfaceTarget(entry.GetType()); |
diff --git a/src/video_core/texture_cache/surface_params.h b/src/video_core/texture_cache/surface_params.h index a84058869..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. |
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 8074cc945..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); |
| @@ -953,6 +954,8 @@ private: | |||
| 953 | 954 | ||
| 954 | VideoCore::RasterizerInterface& rasterizer; | 955 | VideoCore::RasterizerInterface& rasterizer; |
| 955 | 956 | ||
| 957 | FormatLookupTable format_lookup_table; | ||
| 958 | |||
| 956 | u64 ticks{}; | 959 | u64 ticks{}; |
| 957 | 960 | ||
| 958 | // Guards the cache for protection conflicts. | 961 | // Guards the cache for protection conflicts. |