From 667703d3e15a9889e7fa63dc5526233db2f3804b Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Sat, 3 Jun 2023 21:53:38 +0200 Subject: [PATCH] early-access version 3635 --- README.md | 2 +- src/core/CMakeLists.txt | 2 + src/core/file_sys/patch_manager.cpp | 5 +- src/core/file_sys/romfs.cpp | 3 +- src/core/file_sys/vfs_cached.cpp | 63 ++++++++++++++++++++ src/core/file_sys/vfs_cached.h | 31 ++++++++++ src/core/file_sys/vfs_vector.cpp | 19 ------ src/core/file_sys/vfs_vector.h | 4 -- src/video_core/buffer_cache/buffer_cache.h | 2 +- src/video_core/surface.cpp | 14 +---- src/video_core/surface.h | 2 +- src/video_core/texture_cache/texture_cache.h | 18 +++--- 12 files changed, 113 insertions(+), 52 deletions(-) create mode 100755 src/core/file_sys/vfs_cached.cpp create mode 100755 src/core/file_sys/vfs_cached.h diff --git a/README.md b/README.md index 2e1e1acc1..9d07a93ae 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 3634. +This is the source code for early-access 3635. ## Legal Notice diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index fe3477dfc..9da059e8c 100755 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -105,6 +105,8 @@ add_library(core STATIC file_sys/system_archive/time_zone_binary.h file_sys/vfs.cpp file_sys/vfs.h + file_sys/vfs_cached.cpp + file_sys/vfs_cached.h file_sys/vfs_concat.cpp file_sys/vfs_concat.h file_sys/vfs_layered.cpp diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp index 50bf4704b..1210e0b29 100755 --- a/src/core/file_sys/patch_manager.cpp +++ b/src/core/file_sys/patch_manager.cpp @@ -21,6 +21,7 @@ #include "core/file_sys/patch_manager.h" #include "core/file_sys/registered_cache.h" #include "core/file_sys/romfs.h" +#include "core/file_sys/vfs_cached.h" #include "core/file_sys/vfs_layered.h" #include "core/file_sys/vfs_vector.h" #include "core/hle/service/filesystem/filesystem.h" @@ -380,11 +381,11 @@ static void ApplyLayeredFS(VirtualFile& romfs, u64 title_id, ContentRecordType t auto romfs_dir = FindSubdirectoryCaseless(subdir, "romfs"); if (romfs_dir != nullptr) - layers.push_back(std::move(romfs_dir)); + layers.push_back(std::make_shared(romfs_dir)); auto ext_dir = FindSubdirectoryCaseless(subdir, "romfs_ext"); if (ext_dir != nullptr) - layers_ext.push_back(std::move(ext_dir)); + layers_ext.push_back(std::make_shared(ext_dir)); } // When there are no layers to apply, return early as there is no need to rebuild the RomFS diff --git a/src/core/file_sys/romfs.cpp b/src/core/file_sys/romfs.cpp index add207e15..da5e03659 100755 --- a/src/core/file_sys/romfs.cpp +++ b/src/core/file_sys/romfs.cpp @@ -9,6 +9,7 @@ #include "core/file_sys/fsmitm_romfsbuild.h" #include "core/file_sys/romfs.h" #include "core/file_sys/vfs.h" +#include "core/file_sys/vfs_cached.h" #include "core/file_sys/vfs_concat.h" #include "core/file_sys/vfs_offset.h" #include "core/file_sys/vfs_vector.h" @@ -132,7 +133,7 @@ VirtualDir ExtractRomFS(VirtualFile file, RomFSExtractionType type) { out = out->GetSubdirectories().front(); } - return out; + return std::make_shared(out); } VirtualFile CreateRomFS(VirtualDir dir, VirtualDir ext) { diff --git a/src/core/file_sys/vfs_cached.cpp b/src/core/file_sys/vfs_cached.cpp new file mode 100755 index 000000000..c3154ee81 --- /dev/null +++ b/src/core/file_sys/vfs_cached.cpp @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/file_sys/vfs_cached.h" +#include "core/file_sys/vfs_types.h" + +namespace FileSys { + +CachedVfsDirectory::CachedVfsDirectory(VirtualDir& source_dir) + : name(source_dir->GetName()), parent(source_dir->GetParentDirectory()) { + for (auto& dir : source_dir->GetSubdirectories()) { + dirs.emplace(dir->GetName(), std::make_shared(dir)); + } + for (auto& file : source_dir->GetFiles()) { + files.emplace(file->GetName(), file); + } +} + +CachedVfsDirectory::~CachedVfsDirectory() = default; + +VirtualFile CachedVfsDirectory::GetFile(std::string_view file_name) const { + auto it = files.find(file_name); + if (it != files.end()) { + return it->second; + } + + return nullptr; +} + +VirtualDir CachedVfsDirectory::GetSubdirectory(std::string_view dir_name) const { + auto it = dirs.find(dir_name); + if (it != dirs.end()) { + return it->second; + } + + return nullptr; +} + +std::vector CachedVfsDirectory::GetFiles() const { + std::vector out; + for (auto& [file_name, file] : files) { + out.push_back(file); + } + return out; +} + +std::vector CachedVfsDirectory::GetSubdirectories() const { + std::vector out; + for (auto& [dir_name, dir] : dirs) { + out.push_back(dir); + } + return out; +} + +std::string CachedVfsDirectory::GetName() const { + return name; +} + +VirtualDir CachedVfsDirectory::GetParentDirectory() const { + return parent; +} + +} // namespace FileSys diff --git a/src/core/file_sys/vfs_cached.h b/src/core/file_sys/vfs_cached.h new file mode 100755 index 000000000..113acac12 --- /dev/null +++ b/src/core/file_sys/vfs_cached.h @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include +#include "core/file_sys/vfs.h" + +namespace FileSys { + +class CachedVfsDirectory : public ReadOnlyVfsDirectory { +public: + CachedVfsDirectory(VirtualDir& source_directory); + + ~CachedVfsDirectory() override; + VirtualFile GetFile(std::string_view file_name) const override; + VirtualDir GetSubdirectory(std::string_view dir_name) const override; + std::vector GetFiles() const override; + std::vector GetSubdirectories() const override; + std::string GetName() const override; + VirtualDir GetParentDirectory() const override; + +private: + std::string name; + VirtualDir parent; + std::map> dirs; + std::map> files; +}; + +} // namespace FileSys diff --git a/src/core/file_sys/vfs_vector.cpp b/src/core/file_sys/vfs_vector.cpp index 8574e9b99..809d3c4ba 100755 --- a/src/core/file_sys/vfs_vector.cpp +++ b/src/core/file_sys/vfs_vector.cpp @@ -67,23 +67,6 @@ VectorVfsDirectory::VectorVfsDirectory(std::vector files_, VectorVfsDirectory::~VectorVfsDirectory() = default; -VirtualFile VectorVfsDirectory::GetFile(std::string_view file_name) const { - if (!optimized_file_index_built) { - optimized_file_index.clear(); - for (size_t i = 0; i < files.size(); i++) { - optimized_file_index.emplace(files[i]->GetName(), i); - } - optimized_file_index_built = true; - } - - const auto it = optimized_file_index.find(file_name); - if (it != optimized_file_index.end()) { - return files[it->second]; - } - - return nullptr; -} - std::vector VectorVfsDirectory::GetFiles() const { return files; } @@ -124,7 +107,6 @@ bool VectorVfsDirectory::DeleteSubdirectory(std::string_view subdir_name) { } bool VectorVfsDirectory::DeleteFile(std::string_view file_name) { - optimized_file_index_built = false; return FindAndRemoveVectorElement(files, file_name); } @@ -142,7 +124,6 @@ VirtualFile VectorVfsDirectory::CreateFile(std::string_view file_name) { } void VectorVfsDirectory::AddFile(VirtualFile file) { - optimized_file_index_built = false; files.push_back(std::move(file)); } diff --git a/src/core/file_sys/vfs_vector.h b/src/core/file_sys/vfs_vector.h index ee9f784ed..709a45a85 100755 --- a/src/core/file_sys/vfs_vector.h +++ b/src/core/file_sys/vfs_vector.h @@ -105,7 +105,6 @@ public: VirtualDir parent = nullptr); ~VectorVfsDirectory() override; - VirtualFile GetFile(std::string_view file_name) const override; std::vector GetFiles() const override; std::vector GetSubdirectories() const override; bool IsWritable() const override; @@ -127,9 +126,6 @@ private: VirtualDir parent; std::string name; - - mutable std::map> optimized_file_index; - mutable bool optimized_file_index_built{}; }; } // namespace FileSys diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index e276bc5ce..ea5318dc0 100755 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h @@ -34,7 +34,7 @@ BufferCache

::BufferCache(VideoCore::RasterizerInterface& rasterizer_, const s64 min_spacing_critical = device_memory - 512_MiB; const s64 mem_threshold = std::min(device_memory, TARGET_THRESHOLD); const s64 min_vacancy_expected = (6 * mem_threshold) / 10; - const s64 min_vacancy_critical = (2 * mem_threshold) / 10; + const s64 min_vacancy_critical = (3 * mem_threshold) / 10; minimum_memory = static_cast( std::max(std::min(device_memory - min_vacancy_expected, min_spacing_expected), DEFAULT_EXPECTED_MEMORY)); diff --git a/src/video_core/surface.cpp b/src/video_core/surface.cpp index 4cd54d492..9e0db1452 100755 --- a/src/video_core/surface.cpp +++ b/src/video_core/surface.cpp @@ -3,7 +3,6 @@ #include "common/common_types.h" #include "common/math_util.h" -#include "common/settings.h" #include "video_core/surface.h" namespace VideoCore::Surface { @@ -376,20 +375,11 @@ std::pair GetASTCBlockSize(PixelFormat format) { return {DefaultBlockWidth(format), DefaultBlockHeight(format)}; } -u64 TranscodedAstcSize(u64 base_size, PixelFormat format) { +u64 EstimatedDecompressedSize(u64 base_size, PixelFormat format) { constexpr u64 RGBA8_PIXEL_SIZE = 4; const u64 base_block_size = static_cast(DefaultBlockWidth(format)) * static_cast(DefaultBlockHeight(format)) * RGBA8_PIXEL_SIZE; - const u64 uncompressed_size = (base_size * base_block_size) / BytesPerBlock(format); - - switch (Settings::values.astc_recompression.GetValue()) { - case Settings::AstcRecompression::Bc1: - return uncompressed_size / 8; - case Settings::AstcRecompression::Bc3: - return uncompressed_size / 4; - default: - return uncompressed_size; - } + return (base_size * base_block_size) / BytesPerBlock(format); } } // namespace VideoCore::Surface diff --git a/src/video_core/surface.h b/src/video_core/surface.h index e0b06aaf9..562c65051 100755 --- a/src/video_core/surface.h +++ b/src/video_core/surface.h @@ -511,6 +511,6 @@ size_t PixelComponentSizeBitsInteger(PixelFormat format); std::pair GetASTCBlockSize(PixelFormat format); -u64 TranscodedAstcSize(u64 base_size, PixelFormat format); +u64 EstimatedDecompressedSize(u64 base_size, PixelFormat format); } // namespace VideoCore::Surface diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index d0bf48068..879bdf613 100755 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -53,7 +53,7 @@ TextureCache

::TextureCache(Runtime& runtime_, VideoCore::RasterizerInterface& const s64 min_spacing_critical = device_memory - 512_MiB; const s64 mem_threshold = std::min(device_memory, TARGET_THRESHOLD); const s64 min_vacancy_expected = (6 * mem_threshold) / 10; - const s64 min_vacancy_critical = (2 * mem_threshold) / 10; + const s64 min_vacancy_critical = (3 * mem_threshold) / 10; expected_memory = static_cast( std::max(std::min(device_memory - min_vacancy_expected, min_spacing_expected), DEFAULT_EXPECTED_MEMORY)); @@ -850,15 +850,11 @@ void TextureCache

::PopAsyncFlushes() { template ImageId TextureCache

::DmaImageId(const Tegra::DMA::ImageOperand& operand, bool is_upload) { const ImageInfo dst_info(operand); - const ImageId dst_id = FindDMAImage(dst_info, operand.address); - if (!dst_id) { - return NULL_IMAGE_ID; - } - auto& image = slot_images[dst_id]; - if (False(image.flags & ImageFlagBits::GpuModified)) { - // No need to waste time on an image that's synced with guest + const ImageId image_id = FindDMAImage(dst_info, operand.address); + if (!image_id) { return NULL_IMAGE_ID; } + auto& image = slot_images[image_id]; if (!is_upload && !image.info.dma_downloaded) { // Force a full sync. image.info.dma_downloaded = true; @@ -868,7 +864,7 @@ ImageId TextureCache

::DmaImageId(const Tegra::DMA::ImageOperand& operand, boo if (!base) { return NULL_IMAGE_ID; } - return dst_id; + return image_id; } template @@ -1908,7 +1904,7 @@ void TextureCache

::RegisterImage(ImageId image_id) { if ((IsPixelFormatASTC(image.info.format) && True(image.flags & ImageFlagBits::AcceleratedUpload)) || True(image.flags & ImageFlagBits::Converted)) { - tentative_size = TranscodedAstcSize(tentative_size, image.info.format); + tentative_size = EstimatedDecompressedSize(tentative_size, image.info.format); } total_used_memory += Common::AlignUp(tentative_size, 1024); image.lru_index = lru_cache.Insert(image_id, frame_tick); @@ -2077,7 +2073,7 @@ void TextureCache

::DeleteImage(ImageId image_id, bool immediate_delete) { if ((IsPixelFormatASTC(image.info.format) && True(image.flags & ImageFlagBits::AcceleratedUpload)) || True(image.flags & ImageFlagBits::Converted)) { - tentative_size = TranscodedAstcSize(tentative_size, image.info.format); + tentative_size = EstimatedDecompressedSize(tentative_size, image.info.format); } total_used_memory -= Common::AlignUp(tentative_size, 1024); const GPUVAddr gpu_addr = image.gpu_addr;