From 9764c13d6d2977903f407761b27d847c0056e1c4 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Wed, 30 Dec 2020 02:25:23 -0300 Subject: video_core: Rewrite the texture cache The current texture cache has several points that hurt maintainability and performance. It's easy to break unrelated parts of the cache when doing minor changes. The cache can easily forget valuable information about the cached textures by CPU writes or simply by its normal usage.The current texture cache has several points that hurt maintainability and performance. It's easy to break unrelated parts of the cache when doing minor changes. The cache can easily forget valuable information about the cached textures by CPU writes or simply by its normal usage. This commit aims to address those issues. --- src/video_core/morton.cpp | 250 ---------------------------------------------- 1 file changed, 250 deletions(-) (limited to 'src/video_core/morton.cpp') 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 @@ -// Copyright 2018 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include -#include -#include "common/assert.h" -#include "common/common_types.h" -#include "video_core/morton.h" -#include "video_core/surface.h" -#include "video_core/textures/decoders.h" - -namespace VideoCore { - -using Surface::GetBytesPerPixel; -using Surface::PixelFormat; - -using MortonCopyFn = void (*)(u32, u32, u32, u32, u32, u32, u8*, u8*); -using ConversionArray = std::array; - -template -static void MortonCopy(u32 stride, u32 block_height, u32 height, u32 block_depth, u32 depth, - u32 tile_width_spacing, u8* buffer, u8* addr) { - constexpr u32 bytes_per_pixel = GetBytesPerPixel(format); - - // With the BCn formats (DXT and DXN), each 4x4 tile is swizzled instead of just individual - // pixel values. - constexpr u32 tile_size_x{GetDefaultBlockWidth(format)}; - constexpr u32 tile_size_y{GetDefaultBlockHeight(format)}; - - if constexpr (morton_to_linear) { - Tegra::Texture::UnswizzleTexture(buffer, addr, tile_size_x, tile_size_y, bytes_per_pixel, - stride, height, depth, block_height, block_depth, - tile_width_spacing); - } else { - Tegra::Texture::CopySwizzledData((stride + tile_size_x - 1) / tile_size_x, - (height + tile_size_y - 1) / tile_size_y, depth, - bytes_per_pixel, bytes_per_pixel, addr, buffer, false, - block_height, block_depth, tile_width_spacing); - } -} - -static constexpr ConversionArray morton_to_linear_fns = { - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, -}; - -static constexpr ConversionArray linear_to_morton_fns = { - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - // TODO(Subv): Swizzling ASTC formats are not supported - nullptr, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - nullptr, - nullptr, - nullptr, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, - MortonCopy, -}; - -static MortonCopyFn GetSwizzleFunction(MortonSwizzleMode mode, Surface::PixelFormat format) { - switch (mode) { - case MortonSwizzleMode::MortonToLinear: - return morton_to_linear_fns[static_cast(format)]; - case MortonSwizzleMode::LinearToMorton: - return linear_to_morton_fns[static_cast(format)]; - } - UNREACHABLE(); - return morton_to_linear_fns[static_cast(format)]; -} - -void MortonSwizzle(MortonSwizzleMode mode, Surface::PixelFormat format, u32 stride, - u32 block_height, u32 height, u32 block_depth, u32 depth, u32 tile_width_spacing, - u8* buffer, u8* addr) { - GetSwizzleFunction(mode, format)(stride, block_height, height, block_depth, depth, - tile_width_spacing, buffer, addr); -} - -} // namespace VideoCore -- cgit v1.2.3