From 707453b5962c76a922ce7a52e604e004fac09640 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 25 Aug 2024 22:13:18 +1000 Subject: [PATCH] FileSystem: Swap vector for DynamicHeapArray No point zeroing it out. --- src/common/file_system.cpp | 10 ++--- src/common/file_system.h | 5 ++- src/common/heap_array.h | 24 ++++++----- src/core/bios.cpp | 2 +- src/core/bios.h | 3 +- src/core/bus.cpp | 8 ++-- src/core/gdb_server.cpp | 1 + src/core/memory_card_image.cpp | 52 +++++++++++++++--------- src/core/memory_card_image.h | 5 ++- src/core/pine_server.cpp | 4 +- src/core/pine_server.h | 6 +-- src/core/psf_loader.cpp | 2 +- src/core/system.cpp | 4 +- src/duckstation-qt/autoupdaterdialog.cpp | 1 + src/duckstation-qt/gamelistmodel.cpp | 1 + src/duckstation-qt/qthost.cpp | 4 +- src/duckstation-regtest/regtest_host.cpp | 4 +- src/util/cd_image_mds.cpp | 4 +- src/util/d3d11_pipeline.cpp | 1 + src/util/d3d11_texture.cpp | 1 + src/util/d3d12_device.cpp | 8 ++-- src/util/d3d12_device.h | 2 +- src/util/gpu_framebuffer_manager.h | 4 +- src/util/gpu_texture.cpp | 1 + src/util/host.h | 4 +- src/util/image.cpp | 5 ++- src/util/image.h | 1 - src/util/imgui_fullscreen.cpp | 2 +- src/util/imgui_manager.cpp | 22 +++++----- src/util/media_capture.cpp | 1 + src/util/postprocessing_shader_fx.cpp | 2 +- src/util/vulkan_device.cpp | 2 +- 32 files changed, 112 insertions(+), 84 deletions(-) diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index 79613628e..5212287e7 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -1401,9 +1401,9 @@ s64 FileSystem::GetPathFileSize(const char* Path) return sd.Size; } -std::optional> FileSystem::ReadBinaryFile(const char* filename, Error* error) +std::optional> FileSystem::ReadBinaryFile(const char* filename, Error* error) { - std::optional> ret; + std::optional> ret; ManagedCFilePtr fp = OpenManagedCFile(filename, "rb", error); if (!fp) @@ -1413,9 +1413,9 @@ std::optional> FileSystem::ReadBinaryFile(const char* filename, return ret; } -std::optional> FileSystem::ReadBinaryFile(std::FILE* fp, Error* error) +std::optional> FileSystem::ReadBinaryFile(std::FILE* fp, Error* error) { - std::optional> ret; + std::optional> ret; if (FSeek64(fp, 0, SEEK_END) != 0) [[unlikely]] { @@ -1445,7 +1445,7 @@ std::optional> FileSystem::ReadBinaryFile(std::FILE* fp, Error* return ret; } - ret = std::vector(static_cast(size)); + ret = DynamicHeapArray(static_cast(size)); if (size > 0 && std::fread(ret->data(), 1u, static_cast(size), fp) != static_cast(size)) [[unlikely]] { Error::SetErrno(error, "fread() failed: ", errno); diff --git a/src/common/file_system.h b/src/common/file_system.h index 0a4ebb16d..f4f9303f2 100644 --- a/src/common/file_system.h +++ b/src/common/file_system.h @@ -3,6 +3,7 @@ #pragma once +#include "heap_array.h" #include "types.h" #include @@ -171,8 +172,8 @@ private: }; #endif -std::optional> ReadBinaryFile(const char* filename, Error* error = nullptr); -std::optional> ReadBinaryFile(std::FILE* fp, Error* error = nullptr); +std::optional> ReadBinaryFile(const char* filename, Error* error = nullptr); +std::optional> ReadBinaryFile(std::FILE* fp, Error* error = nullptr); std::optional ReadFileToString(const char* filename, Error* error = nullptr); std::optional ReadFileToString(std::FILE* fp, Error* error = nullptr); bool WriteBinaryFile(const char* filename, const void* data, size_t data_length, Error* error = nullptr); diff --git a/src/common/heap_array.h b/src/common/heap_array.h index 9075a982a..3e0befc99 100644 --- a/src/common/heap_array.h +++ b/src/common/heap_array.h @@ -3,8 +3,6 @@ #pragma once -#include "common/assert.h" - #include #include #include @@ -117,18 +115,20 @@ private: { #ifdef _MSC_VER m_data = static_cast(_aligned_malloc(SIZE * sizeof(T), ALIGNMENT)); - if (!m_data) - Panic("Memory allocation failed."); + assert(m_data); + if (!m_data) [[unlikely]] + std::abort(); #else - if (posix_memalign(reinterpret_cast(&m_data), ALIGNMENT, SIZE * sizeof(T)) != 0) - Panic("Memory allocation failed."); + if (posix_memalign(reinterpret_cast(&m_data), ALIGNMENT, SIZE * sizeof(T)) != 0) [[unlikely]] + std::abort(); #endif } else { m_data = static_cast(std::malloc(SIZE * sizeof(T))); - if (!m_data) - Panic("Memory allocation failed."); + assert(m_data); + if (!m_data) [[unlikely]] + std::abort(); } } void deallocate() @@ -377,11 +377,12 @@ private: { #ifdef _MSC_VER m_data = static_cast(_aligned_realloc(prev_ptr, size * sizeof(T), alignment)); + assert(m_data); if (!m_data) [[unlikely]] - Panic("Memory allocation failed."); + std::abort(); #else if (posix_memalign(reinterpret_cast(&m_data), alignment, size * sizeof(T)) != 0) [[unlikely]] - Panic("Memory allocation failed."); + std::abort(); if (prev_ptr) { @@ -393,8 +394,9 @@ private: else { m_data = static_cast(std::realloc(prev_ptr, size * sizeof(T))); + assert(m_data); if (!m_data) [[unlikely]] - Panic("Memory allocation failed."); + std::abort(); } m_size = size; diff --git a/src/core/bios.cpp b/src/core/bios.cpp index fc69686f3..39302a624 100644 --- a/src/core/bios.cpp +++ b/src/core/bios.cpp @@ -190,7 +190,7 @@ std::optional BIOS::LoadImageFromFile(const char* filename, Error* } // We want to hash the whole file. That means reading the whole thing in, if it's a larger BIOS (PS2). - std::optional> data = FileSystem::ReadBinaryFile(fp.get(), error); + std::optional> data = FileSystem::ReadBinaryFile(fp.get(), error); if (!data.has_value() || data->size() < BIOS_SIZE) return ret; diff --git a/src/core/bios.h b/src/core/bios.h index 59ce9dbc3..86bfbe75f 100644 --- a/src/core/bios.h +++ b/src/core/bios.h @@ -5,6 +5,7 @@ #include "types.h" +#include "common/heap_array.h" #include "common/small_string.h" #include @@ -52,7 +53,7 @@ struct Image { const ImageInfo* info; ImageInfo::Hash hash; - std::vector data; + DynamicHeapArray data; }; #pragma pack(push, 1) diff --git a/src/core/bus.cpp b/src/core/bus.cpp index c06c7356c..91246ae28 100644 --- a/src/core/bus.cpp +++ b/src/core/bus.cpp @@ -1034,15 +1034,15 @@ bool Bus::SideloadEXE(const std::string& path, Error* error) if (const std::string libps_path = Path::BuildRelativePath(path, "libps.exe"); FileSystem::FileExists(libps_path.c_str())) { - const std::optional> exe_data = FileSystem::ReadBinaryFile(libps_path.c_str(), error); - okay = (exe_data.has_value() && InjectExecutable(exe_data.value(), false, error)); + const std::optional> exe_data = FileSystem::ReadBinaryFile(libps_path.c_str(), error); + okay = (exe_data.has_value() && InjectExecutable(exe_data->cspan(), false, error)); if (!okay) Error::AddPrefix(error, "Failed to load libps.exe: "); } if (okay) { - const std::optional> exe_data = FileSystem::ReadBinaryFile(System::GetExeOverride().c_str(), error); - okay = (exe_data.has_value() && InjectExecutable(exe_data.value(), true, error)); + const std::optional> exe_data = FileSystem::ReadBinaryFile(System::GetExeOverride().c_str(), error); + okay = (exe_data.has_value() && InjectExecutable(exe_data->cspan(), true, error)); if (!okay) Error::AddPrefixFmt(error, "Failed to load {}: ", Path::GetFileName(path)); } diff --git a/src/core/gdb_server.cpp b/src/core/gdb_server.cpp index aebbfe3ba..59282107d 100644 --- a/src/core/gdb_server.cpp +++ b/src/core/gdb_server.cpp @@ -7,6 +7,7 @@ #include "cpu_core_private.h" #include "system.h" +#include "common/assert.h" #include "common/log.h" #include "common/small_string.h" #include "common/string_util.h" diff --git a/src/core/memory_card_image.cpp b/src/core/memory_card_image.cpp index 2c44082e9..0beedde81 100644 --- a/src/core/memory_card_image.cpp +++ b/src/core/memory_card_image.cpp @@ -87,10 +87,10 @@ const T* GetFramePtr(const DataArray& data, u32 block, u32 frame) } static std::optional GetNextFreeBlock(const DataArray& data); -static bool ImportCardMCD(DataArray* data, const char* filename, std::vector file_data, Error* error); -static bool ImportCardGME(DataArray* data, const char* filename, std::vector file_data, Error* error); -static bool ImportCardVGS(DataArray* data, const char* filename, std::vector file_data, Error* error); -static bool ImportCardPSX(DataArray* data, const char* filename, std::vector file_data, Error* error); +static bool ImportCardMCD(DataArray* data, const char* filename, std::span file_data, Error* error); +static bool ImportCardGME(DataArray* data, const char* filename, std::span file_data, Error* error); +static bool ImportCardVGS(DataArray* data, const char* filename, std::span file_data, Error* error); +static bool ImportCardPSX(DataArray* data, const char* filename, std::span file_data, Error* error); static bool ImportSaveWithDirectoryFrame(DataArray* data, const char* filename, const FILESYSTEM_STAT_DATA& sd, Error* error); static bool ImportRawSave(DataArray* data, const char* filename, const FILESYSTEM_STAT_DATA& sd, Error* error); @@ -324,7 +324,7 @@ bool MemoryCardImage::ReadFile(const DataArray& data, const FileInfo& fi, std::v return true; } -bool MemoryCardImage::WriteFile(DataArray* data, std::string_view filename, const std::vector& buffer, Error* error) +bool MemoryCardImage::WriteFile(DataArray* data, std::string_view filename, const std::span buffer, Error* error) { if (buffer.empty()) { @@ -481,7 +481,7 @@ bool MemoryCardImage::UndeleteFile(DataArray* data, const FileInfo& fi) return true; } -bool MemoryCardImage::ImportCardMCD(DataArray* data, const char* filename, std::vector file_data, Error* error) +bool MemoryCardImage::ImportCardMCD(DataArray* data, const char* filename, std::span file_data, Error* error) { if (file_data.size() != DATA_SIZE) { @@ -494,7 +494,7 @@ bool MemoryCardImage::ImportCardMCD(DataArray* data, const char* filename, std:: return true; } -bool MemoryCardImage::ImportCardGME(DataArray* data, const char* filename, std::vector file_data, Error* error) +bool MemoryCardImage::ImportCardGME(DataArray* data, const char* filename, std::span file_data, Error* error) { #pragma pack(push, 1) struct GMEHeader @@ -529,15 +529,27 @@ bool MemoryCardImage::ImportCardGME(DataArray* data, const char* filename, std:: { WARNING_LOG("GME memory card '{}' is too small (got {} expected {}), padding with zeroes", filename, file_data.size(), expected_size); - file_data.resize(expected_size); + if (file_data.size() > sizeof(GMEHeader)) + { + const size_t present = file_data.size() - sizeof(GMEHeader); + std::memcpy(data->data(), file_data.data() + sizeof(GMEHeader), present); + std::memset(data->data() + present, 0, DATA_SIZE - present); + } + else + { + std::memset(data->data(), 0, DATA_SIZE); + } + } + else + { + // we don't actually care about the header, just skip over it + std::memcpy(data->data(), file_data.data() + sizeof(GMEHeader), DATA_SIZE); } - // we don't actually care about the header, just skip over it - std::memcpy(data->data(), file_data.data() + sizeof(GMEHeader), DATA_SIZE); return true; } -bool MemoryCardImage::ImportCardVGS(DataArray* data, const char* filename, std::vector file_data, Error* error) +bool MemoryCardImage::ImportCardVGS(DataArray* data, const char* filename, std::span file_data, Error* error) { constexpr u32 HEADER_SIZE = 64; constexpr u32 EXPECTED_SIZE = HEADER_SIZE + DATA_SIZE; @@ -560,7 +572,7 @@ bool MemoryCardImage::ImportCardVGS(DataArray* data, const char* filename, std:: return true; } -bool MemoryCardImage::ImportCardPSX(DataArray* data, const char* filename, std::vector file_data, Error* error) +bool MemoryCardImage::ImportCardPSX(DataArray* data, const char* filename, std::span file_data, Error* error) { constexpr u32 HEADER_SIZE = 256; constexpr u32 EXPECTED_SIZE = HEADER_SIZE + DATA_SIZE; @@ -583,7 +595,7 @@ bool MemoryCardImage::ImportCardPSX(DataArray* data, const char* filename, std:: return true; } -bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, std::vector file_data, Error* error) +bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, std::span file_data, Error* error) { const std::string_view extension = Path::GetExtension(filename); if (extension.empty()) @@ -597,19 +609,19 @@ bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, std::vec StringUtil::EqualNoCase(extension, "psm") || StringUtil::EqualNoCase(extension, "ps") || StringUtil::EqualNoCase(extension, "ddf")) { - return ImportCardMCD(data, filename, std::move(file_data), error); + return ImportCardMCD(data, filename, file_data, error); } else if (StringUtil::EqualNoCase(extension, "gme")) { - return ImportCardGME(data, filename, std::move(file_data), error); + return ImportCardGME(data, filename, file_data, error); } else if (StringUtil::EqualNoCase(extension, "mem") || StringUtil::EqualNoCase(extension, "vgs")) { - return ImportCardVGS(data, filename, std::move(file_data), error); + return ImportCardVGS(data, filename, file_data, error); } else if (StringUtil::EqualNoCase(extension, "psx")) { - return ImportCardPSX(data, filename, std::move(file_data), error); + return ImportCardPSX(data, filename, file_data, error); } else { @@ -620,11 +632,11 @@ bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, std::vec bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, Error* error) { - std::optional> file_data = FileSystem::ReadBinaryFile(filename, error); + std::optional> file_data = FileSystem::ReadBinaryFile(filename, error); if (!file_data.has_value()) return false; - return ImportCard(data, filename, std::move(file_data.value()), error); + return ImportCard(data, filename, file_data->cspan(), error); } bool MemoryCardImage::ExportSave(DataArray* data, const FileInfo& fi, const char* filename, Error* error) @@ -724,7 +736,7 @@ bool MemoryCardImage::ImportRawSave(DataArray* data, const char* filename, const if (save_name.length() > DirectoryFrame::FILE_NAME_LENGTH) save_name.erase(DirectoryFrame::FILE_NAME_LENGTH); - std::optional> blocks = FileSystem::ReadBinaryFile(filename, error); + std::optional> blocks = FileSystem::ReadBinaryFile(filename, error); if (!blocks.has_value()) return false; diff --git a/src/core/memory_card_image.h b/src/core/memory_card_image.h index 0f254c1b0..6a0398547 100644 --- a/src/core/memory_card_image.h +++ b/src/core/memory_card_image.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include #include @@ -51,11 +52,11 @@ bool IsValid(const DataArray& data); u32 GetFreeBlockCount(const DataArray& data); std::vector EnumerateFiles(const DataArray& data, bool include_deleted); bool ReadFile(const DataArray& data, const FileInfo& fi, std::vector* buffer, Error* error); -bool WriteFile(DataArray* data, std::string_view filename, const std::vector& buffer, Error* error); +bool WriteFile(DataArray* data, std::string_view filename, std::span buffer, Error* error); bool DeleteFile(DataArray* data, const FileInfo& fi, bool clear_sectors); bool UndeleteFile(DataArray* data, const FileInfo& fi); bool ImportCard(DataArray* data, const char* filename, Error* error); -bool ImportCard(DataArray* data, const char* filename, std::vector file_data, Error* error); +bool ImportCard(DataArray* data, const char* filename, std::span file_data, Error* error); bool ExportSave(DataArray* data, const FileInfo& fi, const char* filename, Error* error); bool ImportSave(DataArray* data, const char* filename, Error* error); } // namespace MemoryCardImage diff --git a/src/core/pine_server.cpp b/src/core/pine_server.cpp index 0adb50e75..1d5720696 100644 --- a/src/core/pine_server.cpp +++ b/src/core/pine_server.cpp @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team, Connor McLaughlin -// SPDX-License-Identifier: LGPL-3.0+ +// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) +// NOTE: File has been rewritten completely compared to the original, only the enums remain. #include "pine_server.h" #include "cpu_core.h" @@ -11,6 +12,7 @@ #include "util/sockets.h" +#include "common/assert.h" #include "common/binary_reader_writer.h" #include "common/error.h" #include "common/file_system.h" diff --git a/src/core/pine_server.h b/src/core/pine_server.h index 4f2f1842c..c234b16eb 100644 --- a/src/core/pine_server.h +++ b/src/core/pine_server.h @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team, Connor McLaughlin -// SPDX-License-Identifier: LGPL-3.0+ +// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) -/* A reference client implementation for interfacing with PINE is available - * here: https://code.govanify.com/govanify/pine/ */ +// A reference client implementation for interfacing with PINE is available here: +// https://code.govanify.com/govanify/pine/ #pragma once diff --git a/src/core/psf_loader.cpp b/src/core/psf_loader.cpp index 8ed3fcd97..c4fc37e60 100644 --- a/src/core/psf_loader.cpp +++ b/src/core/psf_loader.cpp @@ -69,7 +69,7 @@ float PSFLoader::File::GetTagFloat(const char* tag_name, float default_value) co bool PSFLoader::File::Load(const char* path, Error* error) { - std::optional> file_data(FileSystem::ReadBinaryFile(path, error)); + std::optional> file_data(FileSystem::ReadBinaryFile(path, error)); if (!file_data.has_value() || file_data->empty()) return false; diff --git a/src/core/system.cpp b/src/core/system.cpp index 628121553..d5c14fff5 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -900,12 +900,12 @@ bool System::GetGameDetailsFromImage(CDImage* cdi, std::string* out_id, GameHash System::GameHash System::GetGameHashFromFile(const char* path) { - const std::optional> data = FileSystem::ReadBinaryFile(path); + const std::optional> data = FileSystem::ReadBinaryFile(path); if (!data) return 0; const std::string display_name = FileSystem::GetDisplayNameFromPath(path); - return GetGameHashFromBuffer(display_name, data.value(), IsoReader::ISOPrimaryVolumeDescriptor{}, 0); + return GetGameHashFromBuffer(display_name, data->cspan(), IsoReader::ISOPrimaryVolumeDescriptor{}, 0); } std::string System::GetExecutableNameForImage(IsoReader& iso, bool strip_subdirectories) diff --git a/src/duckstation-qt/autoupdaterdialog.cpp b/src/duckstation-qt/autoupdaterdialog.cpp index 44b860589..5c0e7fff0 100644 --- a/src/duckstation-qt/autoupdaterdialog.cpp +++ b/src/duckstation-qt/autoupdaterdialog.cpp @@ -11,6 +11,7 @@ #include "util/http_downloader.h" +#include "common/assert.h" #include "common/error.h" #include "common/file_system.h" #include "common/log.h" diff --git a/src/duckstation-qt/gamelistmodel.cpp b/src/duckstation-qt/gamelistmodel.cpp index ce7d1e71c..99bd8f613 100644 --- a/src/duckstation-qt/gamelistmodel.cpp +++ b/src/duckstation-qt/gamelistmodel.cpp @@ -7,6 +7,7 @@ #include "core/system.h" +#include "common/assert.h" #include "common/file_system.h" #include "common/path.h" #include "common/string_util.h" diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index c5dfd43c8..83bd51aff 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -1950,10 +1950,10 @@ bool Host::ResourceFileExists(std::string_view filename, bool allow_override) return FileSystem::FileExists(path.c_str()); } -std::optional> Host::ReadResourceFile(std::string_view filename, bool allow_override) +std::optional> Host::ReadResourceFile(std::string_view filename, bool allow_override) { const std::string path = QtHost::GetResourcePath(filename, allow_override); - std::optional> ret(FileSystem::ReadBinaryFile(path.c_str())); + std::optional> ret(FileSystem::ReadBinaryFile(path.c_str())); if (!ret.has_value()) ERROR_LOG("Failed to read resource file '{}'", filename); return ret; diff --git a/src/duckstation-regtest/regtest_host.cpp b/src/duckstation-regtest/regtest_host.cpp index 705fce6f1..78de0df27 100644 --- a/src/duckstation-regtest/regtest_host.cpp +++ b/src/duckstation-regtest/regtest_host.cpp @@ -212,10 +212,10 @@ bool Host::ResourceFileExists(std::string_view filename, bool allow_override) return FileSystem::FileExists(path.c_str()); } -std::optional> Host::ReadResourceFile(std::string_view filename, bool allow_override) +std::optional> Host::ReadResourceFile(std::string_view filename, bool allow_override) { const std::string path(Path::Combine(EmuFolders::Resources, filename)); - std::optional> ret(FileSystem::ReadBinaryFile(path.c_str())); + std::optional> ret(FileSystem::ReadBinaryFile(path.c_str())); if (!ret.has_value()) ERROR_LOG("Failed to read resource file '{}'", filename); return ret; diff --git a/src/util/cd_image_mds.cpp b/src/util/cd_image_mds.cpp index 3c9d72454..23aaaa22d 100644 --- a/src/util/cd_image_mds.cpp +++ b/src/util/cd_image_mds.cpp @@ -78,7 +78,7 @@ bool CDImageMds::OpenAndParse(const char* filename, Error* error) return false; } - std::optional> mds_data_opt(FileSystem::ReadBinaryFile(mds_fp)); + std::optional> mds_data_opt(FileSystem::ReadBinaryFile(mds_fp)); std::fclose(mds_fp); if (!mds_data_opt.has_value() || mds_data_opt->size() < 0x54) { @@ -95,7 +95,7 @@ bool CDImageMds::OpenAndParse(const char* filename, Error* error) return false; } - const std::vector& mds = mds_data_opt.value(); + const DynamicHeapArray& mds = mds_data_opt.value(); static constexpr char expected_signature[] = "MEDIA DESCRIPTOR"; if (std::memcmp(&mds[0], expected_signature, sizeof(expected_signature) - 1) != 0) { diff --git a/src/util/d3d11_pipeline.cpp b/src/util/d3d11_pipeline.cpp index f39d8f927..d8d293cf9 100644 --- a/src/util/d3d11_pipeline.cpp +++ b/src/util/d3d11_pipeline.cpp @@ -5,6 +5,7 @@ #include "d3d11_device.h" #include "d3d_common.h" +#include "common/assert.h" #include "common/error.h" #include "common/hash_combine.h" diff --git a/src/util/d3d11_texture.cpp b/src/util/d3d11_texture.cpp index b015d572e..66f36cce1 100644 --- a/src/util/d3d11_texture.cpp +++ b/src/util/d3d11_texture.cpp @@ -5,6 +5,7 @@ #include "d3d11_device.h" #include "d3d_common.h" +#include "common/assert.h" #include "common/log.h" #include "common/string_util.h" diff --git a/src/util/d3d12_device.cpp b/src/util/d3d12_device.cpp index 7c4089ea4..f37ef4f74 100644 --- a/src/util/d3d12_device.cpp +++ b/src/util/d3d12_device.cpp @@ -1,5 +1,5 @@ // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin -// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) +// SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0) #include "d3d12_device.h" #include "d3d12_builders.h" @@ -60,7 +60,7 @@ static std::mutex s_instance_mutex; static constexpr GPUTexture::Format s_swap_chain_format = GPUTexture::Format::RGBA8; // We just need to keep this alive, never reference it. -static std::vector s_pipeline_cache_data; +static DynamicHeapArray s_pipeline_cache_data; #ifdef _DEBUG #include "WinPixEventRuntime/pix3.h" @@ -268,7 +268,7 @@ void D3D12Device::DestroyDevice() DestroyCommandLists(); m_pipeline_library.Reset(); - std::vector().swap(s_pipeline_cache_data); + s_pipeline_cache_data.deallocate(); m_fence.Reset(); if (m_fence_event != NULL) { @@ -285,7 +285,7 @@ void D3D12Device::DestroyDevice() bool D3D12Device::ReadPipelineCache(const std::string& filename) { - std::optional> data = FileSystem::ReadBinaryFile(filename.c_str()); + std::optional> data = FileSystem::ReadBinaryFile(filename.c_str()); HRESULT hr = m_device->CreatePipelineLibrary(data.has_value() ? data->data() : nullptr, data.has_value() ? data->size() : 0, diff --git a/src/util/d3d12_device.h b/src/util/d3d12_device.h index 697dcd82b..495d3b723 100644 --- a/src/util/d3d12_device.h +++ b/src/util/d3d12_device.h @@ -1,5 +1,5 @@ // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin -// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) +// SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0) #pragma once diff --git a/src/util/gpu_framebuffer_manager.h b/src/util/gpu_framebuffer_manager.h index 6fb7b910b..5663637dd 100644 --- a/src/util/gpu_framebuffer_manager.h +++ b/src/util/gpu_framebuffer_manager.h @@ -1,8 +1,10 @@ -// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once +#include "common/assert.h" + #include "gpu_device.h" #include "gpu_texture.h" diff --git a/src/util/gpu_texture.cpp b/src/util/gpu_texture.cpp index 95669d26d..af8191f85 100644 --- a/src/util/gpu_texture.cpp +++ b/src/util/gpu_texture.cpp @@ -5,6 +5,7 @@ #include "gpu_device.h" #include "common/align.h" +#include "common/assert.h" #include "common/bitutils.h" #include "common/log.h" #include "common/string_util.h" diff --git a/src/util/host.h b/src/util/host.h index 8028975a2..19a730f66 100644 --- a/src/util/host.h +++ b/src/util/host.h @@ -4,12 +4,12 @@ #pragma once #include "common/types.h" +#include "common/heap_array.h" #include #include #include #include -#include namespace Host { /// Returns true if the specified resource file exists. @@ -17,7 +17,7 @@ bool ResourceFileExists(std::string_view filename, bool allow_override); /// Reads a file from the resources directory of the application. /// This may be outside of the "normal" filesystem on platforms such as Mac. -std::optional> ReadResourceFile(std::string_view filename, bool allow_override); +std::optional> ReadResourceFile(std::string_view filename, bool allow_override); /// Reads a resource file file from the resources directory as a string. std::optional ReadResourceFileToString(std::string_view filename, bool allow_override); diff --git a/src/util/image.cpp b/src/util/image.cpp index 336ea6ab8..419164027 100644 --- a/src/util/image.cpp +++ b/src/util/image.cpp @@ -3,6 +3,7 @@ #include "image.h" +#include "common/assert.h" #include "common/bitutils.h" #include "common/fastjmp.h" #include "common/file_system.h" @@ -518,7 +519,7 @@ static bool WrapJPEGDecompress(RGBA8Image* image, T setup_func) bool JPEGBufferLoader(RGBA8Image* image, const void* buffer, size_t buffer_size) { return WrapJPEGDecompress(image, [buffer, buffer_size](jpeg_decompress_struct& info) { - jpeg_mem_src(&info, static_cast(buffer), buffer_size); + jpeg_mem_src(&info, static_cast(buffer), static_cast(buffer_size)); }); } @@ -763,7 +764,7 @@ bool WebPBufferSaver(const RGBA8Image& image, std::vector* buffer, u8 qualit bool WebPFileLoader(RGBA8Image* image, std::string_view filename, std::FILE* fp) { - std::optional> data = FileSystem::ReadBinaryFile(fp); + std::optional> data = FileSystem::ReadBinaryFile(fp); if (!data.has_value()) return false; diff --git a/src/util/image.h b/src/util/image.h index adb2266cc..91bd3602c 100644 --- a/src/util/image.h +++ b/src/util/image.h @@ -3,7 +3,6 @@ #pragma once -#include "common/assert.h" #include "common/types.h" #include diff --git a/src/util/imgui_fullscreen.cpp b/src/util/imgui_fullscreen.cpp index 2d04b425d..4390148a0 100644 --- a/src/util/imgui_fullscreen.cpp +++ b/src/util/imgui_fullscreen.cpp @@ -315,7 +315,7 @@ std::optional ImGuiFullscreen::LoadTextureImage(std::string_view pat } else { - std::optional> data = Host::ReadResourceFile(path, true); + std::optional> data = Host::ReadResourceFile(path, true); if (data.has_value()) { image = RGBA8Image(); diff --git a/src/util/imgui_manager.cpp b/src/util/imgui_manager.cpp index 294c83206..ce6421074 100644 --- a/src/util/imgui_manager.cpp +++ b/src/util/imgui_manager.cpp @@ -1,5 +1,5 @@ // SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin -// SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0) +// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #include "imgui_manager.h" #include "gpu_device.h" @@ -86,10 +86,10 @@ static ImFont* s_fixed_font; static ImFont* s_medium_font; static ImFont* s_large_font; -static std::vector s_standard_font_data; -static std::vector s_fixed_font_data; -static std::vector s_icon_fa_font_data; -static std::vector s_icon_pf_font_data; +static DynamicHeapArray s_standard_font_data; +static DynamicHeapArray s_fixed_font_data; +static DynamicHeapArray s_icon_fa_font_data; +static DynamicHeapArray s_icon_pf_font_data; static float s_window_width; static float s_window_height; @@ -482,9 +482,9 @@ bool ImGuiManager::LoadFontData() { if (s_standard_font_data.empty()) { - std::optional> font_data = s_font_path.empty() ? - Host::ReadResourceFile("fonts/Roboto-Regular.ttf", true) : - FileSystem::ReadBinaryFile(s_font_path.c_str()); + std::optional> font_data = s_font_path.empty() ? + Host::ReadResourceFile("fonts/Roboto-Regular.ttf", true) : + FileSystem::ReadBinaryFile(s_font_path.c_str()); if (!font_data.has_value()) return false; @@ -493,7 +493,7 @@ bool ImGuiManager::LoadFontData() if (s_fixed_font_data.empty()) { - std::optional> font_data = Host::ReadResourceFile("fonts/RobotoMono-Medium.ttf", true); + std::optional> font_data = Host::ReadResourceFile("fonts/RobotoMono-Medium.ttf", true); if (!font_data.has_value()) return false; @@ -502,7 +502,7 @@ bool ImGuiManager::LoadFontData() if (s_icon_fa_font_data.empty()) { - std::optional> font_data = Host::ReadResourceFile("fonts/fa-solid-900.ttf", true); + std::optional> font_data = Host::ReadResourceFile("fonts/fa-solid-900.ttf", true); if (!font_data.has_value()) return false; @@ -511,7 +511,7 @@ bool ImGuiManager::LoadFontData() if (s_icon_pf_font_data.empty()) { - std::optional> font_data = Host::ReadResourceFile("fonts/promptfont.otf", true); + std::optional> font_data = Host::ReadResourceFile("fonts/promptfont.otf", true); if (!font_data.has_value()) return false; diff --git a/src/util/media_capture.cpp b/src/util/media_capture.cpp index bd5043adc..3de04ac89 100644 --- a/src/util/media_capture.cpp +++ b/src/util/media_capture.cpp @@ -6,6 +6,7 @@ #include "host.h" #include "common/align.h" +#include "common/assert.h" #include "common/dynamic_library.h" #include "common/error.h" #include "common/file_system.h" diff --git a/src/util/postprocessing_shader_fx.cpp b/src/util/postprocessing_shader_fx.cpp index 3b3921566..a76c32c15 100644 --- a/src/util/postprocessing_shader_fx.cpp +++ b/src/util/postprocessing_shader_fx.cpp @@ -1108,7 +1108,7 @@ bool PostProcessing::ReShadeFXShader::CreatePasses(GPUTexture::Format backbuffer { // Might be a base file/resource instead. const std::string resource_name = Path::Combine("shaders/reshade/Textures", source); - if (std::optional> resdata = Host::ReadResourceFile(resource_name.c_str(), true); + if (std::optional> resdata = Host::ReadResourceFile(resource_name.c_str(), true); !resdata.has_value() || !image.LoadFromBuffer(resource_name.c_str(), resdata->data(), resdata->size())) { Error::SetString(error, fmt::format("Failed to load image '{}' (from '{}')", source, image_path).c_str()); diff --git a/src/util/vulkan_device.cpp b/src/util/vulkan_device.cpp index 907bf6519..a2b830c77 100644 --- a/src/util/vulkan_device.cpp +++ b/src/util/vulkan_device.cpp @@ -2244,7 +2244,7 @@ void VulkanDevice::FillPipelineCacheHeader(VK_PIPELINE_CACHE_HEADER* header) bool VulkanDevice::ReadPipelineCache(const std::string& filename) { - std::optional> data; + std::optional> data; auto fp = FileSystem::OpenManagedCFile(filename.c_str(), "rb"); if (fp)