diff options
| author | 2019-04-11 17:14:55 -0300 | |
|---|---|---|
| committer | 2019-06-20 21:36:11 -0300 | |
| commit | bab21e8cb3df9c06e3c0a37a8fc68fed676f5d6e (patch) | |
| tree | 860ce1a40373ff6002506bef72f78022de7d022c /src/video_core/texture_cache.cpp | |
| parent | Merge pull request #2596 from FernandoS27/revert-2590 (diff) | |
| download | yuzu-bab21e8cb3df9c06e3c0a37a8fc68fed676f5d6e.tar.gz yuzu-bab21e8cb3df9c06e3c0a37a8fc68fed676f5d6e.tar.xz yuzu-bab21e8cb3df9c06e3c0a37a8fc68fed676f5d6e.zip | |
gl_texture_cache: Initial implementation
Diffstat (limited to 'src/video_core/texture_cache.cpp')
| -rw-r--r-- | src/video_core/texture_cache.cpp | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/src/video_core/texture_cache.cpp b/src/video_core/texture_cache.cpp index e96eba7cc..c42365a82 100644 --- a/src/video_core/texture_cache.cpp +++ b/src/video_core/texture_cache.cpp | |||
| @@ -163,7 +163,7 @@ u32 SurfaceParams::GetMipBlockHeight(u32 level) const { | |||
| 163 | return block_height; | 163 | return block_height; |
| 164 | } | 164 | } |
| 165 | const u32 height{GetMipHeight(level)}; | 165 | const u32 height{GetMipHeight(level)}; |
| 166 | const u32 default_block_height{GetDefaultBlockHeight(pixel_format)}; | 166 | const u32 default_block_height{GetDefaultBlockHeight()}; |
| 167 | const u32 blocks_in_y{(height + default_block_height - 1) / default_block_height}; | 167 | const u32 blocks_in_y{(height + default_block_height - 1) / default_block_height}; |
| 168 | u32 block_height = 16; | 168 | u32 block_height = 16; |
| 169 | while (block_height > 1 && blocks_in_y <= block_height * 4) { | 169 | while (block_height > 1 && blocks_in_y <= block_height * 4) { |
| @@ -205,6 +205,10 @@ std::size_t SurfaceParams::GetHostMipmapLevelOffset(u32 level) const { | |||
| 205 | return offset; | 205 | return offset; |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | std::size_t SurfaceParams::GetHostMipmapSize(u32 level) const { | ||
| 209 | return GetInnerMipmapMemorySize(level, true, true, false) * GetNumLayers(); | ||
| 210 | } | ||
| 211 | |||
| 208 | std::size_t SurfaceParams::GetGuestLayerSize() const { | 212 | std::size_t SurfaceParams::GetGuestLayerSize() const { |
| 209 | return GetInnerMemorySize(false, true, false); | 213 | return GetInnerMemorySize(false, true, false); |
| 210 | } | 214 | } |
| @@ -213,6 +217,22 @@ std::size_t SurfaceParams::GetHostLayerSize(u32 level) const { | |||
| 213 | return GetInnerMipmapMemorySize(level, true, IsLayered(), false); | 217 | return GetInnerMipmapMemorySize(level, true, IsLayered(), false); |
| 214 | } | 218 | } |
| 215 | 219 | ||
| 220 | u32 SurfaceParams::GetDefaultBlockWidth() const { | ||
| 221 | return VideoCore::Surface::GetDefaultBlockWidth(pixel_format); | ||
| 222 | } | ||
| 223 | |||
| 224 | u32 SurfaceParams::GetDefaultBlockHeight() const { | ||
| 225 | return VideoCore::Surface::GetDefaultBlockHeight(pixel_format); | ||
| 226 | } | ||
| 227 | |||
| 228 | u32 SurfaceParams::GetBitsPerPixel() const { | ||
| 229 | return VideoCore::Surface::GetFormatBpp(pixel_format); | ||
| 230 | } | ||
| 231 | |||
| 232 | u32 SurfaceParams::GetBytesPerPixel() const { | ||
| 233 | return VideoCore::Surface::GetBytesPerPixel(pixel_format); | ||
| 234 | } | ||
| 235 | |||
| 216 | bool SurfaceParams::IsFamiliar(const SurfaceParams& view_params) const { | 236 | bool SurfaceParams::IsFamiliar(const SurfaceParams& view_params) const { |
| 217 | if (std::tie(is_tiled, tile_width_spacing, pixel_format, component_type, type) != | 237 | if (std::tie(is_tiled, tile_width_spacing, pixel_format, component_type, type) != |
| 218 | std::tie(view_params.is_tiled, view_params.tile_width_spacing, view_params.pixel_format, | 238 | std::tie(view_params.is_tiled, view_params.tile_width_spacing, view_params.pixel_format, |
| @@ -257,7 +277,7 @@ void SurfaceParams::CalculateCachedValues() { | |||
| 257 | 277 | ||
| 258 | // ASTC is uncompressed in software, in emulated as RGBA8 | 278 | // ASTC is uncompressed in software, in emulated as RGBA8 |
| 259 | if (IsPixelFormatASTC(pixel_format)) { | 279 | if (IsPixelFormatASTC(pixel_format)) { |
| 260 | host_size_in_bytes = width * height * depth * 4; | 280 | host_size_in_bytes = static_cast<std::size_t>(width * height * depth) * 4ULL; |
| 261 | } else { | 281 | } else { |
| 262 | host_size_in_bytes = GetInnerMemorySize(true, false, false); | 282 | host_size_in_bytes = GetInnerMemorySize(true, false, false); |
| 263 | } | 283 | } |
| @@ -282,13 +302,11 @@ void SurfaceParams::CalculateCachedValues() { | |||
| 282 | std::size_t SurfaceParams::GetInnerMipmapMemorySize(u32 level, bool as_host_size, bool layer_only, | 302 | std::size_t SurfaceParams::GetInnerMipmapMemorySize(u32 level, bool as_host_size, bool layer_only, |
| 283 | bool uncompressed) const { | 303 | bool uncompressed) const { |
| 284 | const bool tiled{as_host_size ? false : is_tiled}; | 304 | const bool tiled{as_host_size ? false : is_tiled}; |
| 285 | const u32 tile_x{GetDefaultBlockWidth(pixel_format)}; | 305 | const u32 width{GetMipmapSize(uncompressed, GetMipWidth(level), GetDefaultBlockWidth())}; |
| 286 | const u32 tile_y{GetDefaultBlockHeight(pixel_format)}; | 306 | const u32 height{GetMipmapSize(uncompressed, GetMipHeight(level), GetDefaultBlockHeight())}; |
| 287 | const u32 width{GetMipmapSize(uncompressed, GetMipWidth(level), tile_x)}; | ||
| 288 | const u32 height{GetMipmapSize(uncompressed, GetMipHeight(level), tile_y)}; | ||
| 289 | const u32 depth{layer_only ? 1U : GetMipDepth(level)}; | 307 | const u32 depth{layer_only ? 1U : GetMipDepth(level)}; |
| 290 | return Tegra::Texture::CalculateSize(tiled, GetBytesPerPixel(pixel_format), width, height, | 308 | return Tegra::Texture::CalculateSize(tiled, GetBytesPerPixel(), width, height, depth, |
| 291 | depth, GetMipBlockHeight(level), GetMipBlockDepth(level)); | 309 | GetMipBlockHeight(level), GetMipBlockDepth(level)); |
| 292 | } | 310 | } |
| 293 | 311 | ||
| 294 | std::size_t SurfaceParams::GetInnerMemorySize(bool as_host_size, bool layer_only, | 312 | std::size_t SurfaceParams::GetInnerMemorySize(bool as_host_size, bool layer_only, |
| @@ -297,7 +315,7 @@ std::size_t SurfaceParams::GetInnerMemorySize(bool as_host_size, bool layer_only | |||
| 297 | for (u32 level = 0; level < num_levels; ++level) { | 315 | for (u32 level = 0; level < num_levels; ++level) { |
| 298 | size += GetInnerMipmapMemorySize(level, as_host_size, layer_only, uncompressed); | 316 | size += GetInnerMipmapMemorySize(level, as_host_size, layer_only, uncompressed); |
| 299 | } | 317 | } |
| 300 | if (!as_host_size && is_tiled) { | 318 | if (is_tiled && !as_host_size) { |
| 301 | size = Common::AlignUp(size, Tegra::Texture::GetGOBSize() * block_height * block_depth); | 319 | size = Common::AlignUp(size, Tegra::Texture::GetGOBSize() * block_height * block_depth); |
| 302 | } | 320 | } |
| 303 | return size; | 321 | return size; |
| @@ -309,6 +327,7 @@ std::map<u64, std::pair<u32, u32>> SurfaceParams::CreateViewOffsetMap() const { | |||
| 309 | case SurfaceTarget::Texture1D: | 327 | case SurfaceTarget::Texture1D: |
| 310 | case SurfaceTarget::Texture2D: | 328 | case SurfaceTarget::Texture2D: |
| 311 | case SurfaceTarget::Texture3D: { | 329 | case SurfaceTarget::Texture3D: { |
| 330 | // TODO(Rodrigo): Add layer iterations for 3D textures | ||
| 312 | constexpr u32 layer = 0; | 331 | constexpr u32 layer = 0; |
| 313 | for (u32 level = 0; level < num_levels; ++level) { | 332 | for (u32 level = 0; level < num_levels; ++level) { |
| 314 | const std::size_t offset{GetGuestMipmapLevelOffset(level)}; | 333 | const std::size_t offset{GetGuestMipmapLevelOffset(level)}; |