FileSystem: Swap vector for DynamicHeapArray

No point zeroing it out.
This commit is contained in:
Stenzek 2024-08-25 22:13:18 +10:00
parent 1af36dcdfb
commit 7efacbad36
No known key found for this signature in database
50 changed files with 145 additions and 117 deletions

View File

@ -1401,9 +1401,9 @@ s64 FileSystem::GetPathFileSize(const char* Path)
return sd.Size;
}
std::optional<std::vector<u8>> FileSystem::ReadBinaryFile(const char* filename, Error* error)
std::optional<DynamicHeapArray<u8>> FileSystem::ReadBinaryFile(const char* filename, Error* error)
{
std::optional<std::vector<u8>> ret;
std::optional<DynamicHeapArray<u8>> ret;
ManagedCFilePtr fp = OpenManagedCFile(filename, "rb", error);
if (!fp)
@ -1413,9 +1413,9 @@ std::optional<std::vector<u8>> FileSystem::ReadBinaryFile(const char* filename,
return ret;
}
std::optional<std::vector<u8>> FileSystem::ReadBinaryFile(std::FILE* fp, Error* error)
std::optional<DynamicHeapArray<u8>> FileSystem::ReadBinaryFile(std::FILE* fp, Error* error)
{
std::optional<std::vector<u8>> ret;
std::optional<DynamicHeapArray<u8>> ret;
if (FSeek64(fp, 0, SEEK_END) != 0) [[unlikely]]
{
@ -1445,7 +1445,7 @@ std::optional<std::vector<u8>> FileSystem::ReadBinaryFile(std::FILE* fp, Error*
return ret;
}
ret = std::vector<u8>(static_cast<size_t>(size));
ret = DynamicHeapArray<u8>(static_cast<size_t>(size));
if (size > 0 && std::fread(ret->data(), 1u, static_cast<size_t>(size), fp) != static_cast<size_t>(size)) [[unlikely]]
{
Error::SetErrno(error, "fread() failed: ", errno);

View File

@ -1,8 +1,9 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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
#include "heap_array.h"
#include "types.h"
#include <cstdio>
@ -171,8 +172,8 @@ private:
};
#endif
std::optional<std::vector<u8>> ReadBinaryFile(const char* filename, Error* error = nullptr);
std::optional<std::vector<u8>> ReadBinaryFile(std::FILE* fp, Error* error = nullptr);
std::optional<DynamicHeapArray<u8>> ReadBinaryFile(const char* filename, Error* error = nullptr);
std::optional<DynamicHeapArray<u8>> ReadBinaryFile(std::FILE* fp, Error* error = nullptr);
std::optional<std::string> ReadFileToString(const char* filename, Error* error = nullptr);
std::optional<std::string> ReadFileToString(std::FILE* fp, Error* error = nullptr);
bool WriteBinaryFile(const char* filename, const void* data, size_t data_length, Error* error = nullptr);

View File

@ -1,10 +1,8 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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
#include "common/assert.h"
#include <algorithm>
#include <cassert>
#include <cstdlib>
@ -117,18 +115,20 @@ private:
{
#ifdef _MSC_VER
m_data = static_cast<T*>(_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<void**>(&m_data), ALIGNMENT, SIZE * sizeof(T)) != 0)
Panic("Memory allocation failed.");
if (posix_memalign(reinterpret_cast<void**>(&m_data), ALIGNMENT, SIZE * sizeof(T)) != 0) [[unlikely]]
std::abort();
#endif
}
else
{
m_data = static_cast<T*>(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<T*>(_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<void**>(&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<T*>(std::realloc(prev_ptr, size * sizeof(T)));
assert(m_data);
if (!m_data) [[unlikely]]
Panic("Memory allocation failed.");
std::abort();
}
m_size = size;

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com> and contributors.
// 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 "bios.h"
#include "cpu_disasm.h"
@ -190,7 +190,7 @@ std::optional<BIOS::Image> 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<std::vector<u8>> data = FileSystem::ReadBinaryFile(fp.get(), error);
std::optional<DynamicHeapArray<u8>> data = FileSystem::ReadBinaryFile(fp.get(), error);
if (!data.has_value() || data->size() < BIOS_SIZE)
return ret;

View File

@ -1,10 +1,11 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>.
// 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
#include "types.h"
#include "common/heap_array.h"
#include "common/small_string.h"
#include <array>
@ -52,7 +53,7 @@ struct Image
{
const ImageInfo* info;
ImageInfo::Hash hash;
std::vector<u8> data;
DynamicHeapArray<u8> data;
};
#pragma pack(push, 1)

View File

@ -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<std::vector<u8>> exe_data = FileSystem::ReadBinaryFile(libps_path.c_str(), error);
okay = (exe_data.has_value() && InjectExecutable(exe_data.value(), false, error));
const std::optional<DynamicHeapArray<u8>> 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<std::vector<u8>> exe_data = FileSystem::ReadBinaryFile(System::GetExeOverride().c_str(), error);
okay = (exe_data.has_value() && InjectExecutable(exe_data.value(), true, error));
const std::optional<DynamicHeapArray<u8>> 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));
}

View File

@ -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"

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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 "memory_card_image.h"
#include "gpu_types.h"
@ -87,10 +87,10 @@ const T* GetFramePtr(const DataArray& data, u32 block, u32 frame)
}
static std::optional<u32> GetNextFreeBlock(const DataArray& data);
static bool ImportCardMCD(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error);
static bool ImportCardGME(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error);
static bool ImportCardVGS(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error);
static bool ImportCardPSX(DataArray* data, const char* filename, std::vector<u8> file_data, Error* error);
static bool ImportCardMCD(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error);
static bool ImportCardGME(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error);
static bool ImportCardVGS(DataArray* data, const char* filename, std::span<const u8> file_data, Error* error);
static bool ImportCardPSX(DataArray* data, const char* filename, std::span<const u8> 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<u8>& buffer, Error* error)
bool MemoryCardImage::WriteFile(DataArray* data, std::string_view filename, const std::span<const u8> 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<u8> file_data, Error* error)
bool MemoryCardImage::ImportCardMCD(DataArray* data, const char* filename, std::span<const u8> 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<u8> file_data, Error* error)
bool MemoryCardImage::ImportCardGME(DataArray* data, const char* filename, std::span<const u8> 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<u8> file_data, Error* error)
bool MemoryCardImage::ImportCardVGS(DataArray* data, const char* filename, std::span<const u8> 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<u8> file_data, Error* error)
bool MemoryCardImage::ImportCardPSX(DataArray* data, const char* filename, std::span<const u8> 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<u8> file_data, Error* error)
bool MemoryCardImage::ImportCard(DataArray* data, const char* filename, std::span<const u8> 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<std::vector<u8>> file_data = FileSystem::ReadBinaryFile(filename, error);
std::optional<DynamicHeapArray<u8>> 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<std::vector<u8>> blocks = FileSystem::ReadBinaryFile(filename, error);
std::optional<DynamicHeapArray<u8>> blocks = FileSystem::ReadBinaryFile(filename, error);
if (!blocks.has_value())
return false;

View File

@ -1,9 +1,10 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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
#include <array>
#include <span>
#include <string>
#include <string_view>
#include <vector>
@ -51,11 +52,11 @@ bool IsValid(const DataArray& data);
u32 GetFreeBlockCount(const DataArray& data);
std::vector<FileInfo> EnumerateFiles(const DataArray& data, bool include_deleted);
bool ReadFile(const DataArray& data, const FileInfo& fi, std::vector<u8>* buffer, Error* error);
bool WriteFile(DataArray* data, std::string_view filename, const std::vector<u8>& buffer, Error* error);
bool WriteFile(DataArray* data, std::string_view filename, std::span<const u8> 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<u8> file_data, Error* error);
bool ImportCard(DataArray* data, const char* filename, std::span<const u8> 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

View File

@ -1,5 +1,6 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team, Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: LGPL-3.0+
// SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.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"

View File

@ -1,8 +1,8 @@
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team, Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: LGPL-3.0+
// SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.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

View File

@ -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<std::vector<u8>> file_data(FileSystem::ReadBinaryFile(path, error));
std::optional<DynamicHeapArray<u8>> file_data(FileSystem::ReadBinaryFile(path, error));
if (!file_data.has_value() || file_data->empty())
return false;

View File

@ -900,12 +900,12 @@ bool System::GetGameDetailsFromImage(CDImage* cdi, std::string* out_id, GameHash
System::GameHash System::GetGameHashFromFile(const char* path)
{
const std::optional<std::vector<u8>> data = FileSystem::ReadBinaryFile(path);
const std::optional<DynamicHeapArray<u8>> 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)

View File

@ -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"

View File

@ -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"

View File

@ -1950,10 +1950,10 @@ bool Host::ResourceFileExists(std::string_view filename, bool allow_override)
return FileSystem::FileExists(path.c_str());
}
std::optional<std::vector<u8>> Host::ReadResourceFile(std::string_view filename, bool allow_override)
std::optional<DynamicHeapArray<u8>> Host::ReadResourceFile(std::string_view filename, bool allow_override)
{
const std::string path = QtHost::GetResourcePath(filename, allow_override);
std::optional<std::vector<u8>> ret(FileSystem::ReadBinaryFile(path.c_str()));
std::optional<DynamicHeapArray<u8>> ret(FileSystem::ReadBinaryFile(path.c_str()));
if (!ret.has_value())
ERROR_LOG("Failed to read resource file '{}'", filename);
return ret;

View File

@ -212,10 +212,10 @@ bool Host::ResourceFileExists(std::string_view filename, bool allow_override)
return FileSystem::FileExists(path.c_str());
}
std::optional<std::vector<u8>> Host::ReadResourceFile(std::string_view filename, bool allow_override)
std::optional<DynamicHeapArray<u8>> Host::ReadResourceFile(std::string_view filename, bool allow_override)
{
const std::string path(Path::Combine(EmuFolders::Resources, filename));
std::optional<std::vector<u8>> ret(FileSystem::ReadBinaryFile(path.c_str()));
std::optional<DynamicHeapArray<u8>> ret(FileSystem::ReadBinaryFile(path.c_str()));
if (!ret.has_value())
ERROR_LOG("Failed to read resource file '{}'", filename);
return ret;

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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 "assert.h"
#include "cd_image.h"
@ -78,7 +78,7 @@ bool CDImageMds::OpenAndParse(const char* filename, Error* error)
return false;
}
std::optional<std::vector<u8>> mds_data_opt(FileSystem::ReadBinaryFile(mds_fp));
std::optional<DynamicHeapArray<u8>> 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<u8>& mds = mds_data_opt.value();
const DynamicHeapArray<u8>& mds = mds_data_opt.value();
static constexpr char expected_signature[] = "MEDIA DESCRIPTOR";
if (std::memcmp(&mds[0], expected_signature, sizeof(expected_signature) - 1) != 0)
{

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// 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 "d3d11_device.h"
#include "core/host.h" // TODO: Remove me

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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

View File

@ -1,10 +1,11 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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 "d3d11_pipeline.h"
#include "d3d11_device.h"
#include "d3d_common.h"
#include "common/assert.h"
#include "common/error.h"
#include "common/hash_combine.h"

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// 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

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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 "d3d11_stream_buffer.h"
#include "d3d11_device.h"

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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

View File

@ -1,10 +1,11 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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 "d3d11_texture.h"
#include "d3d11_device.h"
#include "d3d_common.h"
#include "common/assert.h"
#include "common/log.h"
#include "common/string_util.h"

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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_builders.h"
#include "d3d12_device.h"

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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_descriptor_heap_manager.h"

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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<u8> s_pipeline_cache_data;
static DynamicHeapArray<u8> s_pipeline_cache_data;
#ifdef _DEBUG
#include "WinPixEventRuntime/pix3.h"
@ -268,7 +268,7 @@ void D3D12Device::DestroyDevice()
DestroyCommandLists();
m_pipeline_library.Reset();
std::vector<u8>().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<std::vector<u8>> data = FileSystem::ReadBinaryFile(filename.c_str());
std::optional<DynamicHeapArray<u8>> data = FileSystem::ReadBinaryFile(filename.c_str());
HRESULT hr =
m_device->CreatePipelineLibrary(data.has_value() ? data->data() : nullptr, data.has_value() ? data->size() : 0,

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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_pipeline.h"
#include "d3d12_builders.h"

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// 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 "gpu_device.h"

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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_stream_buffer.h"
#include "d3d12_device.h"

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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_texture.h"
#include "d3d12_builders.h"

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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 "d3d_common.h"
#include "gpu_device.h"

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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

View File

@ -1,8 +1,10 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR PolyForm-Strict-1.0.0)
#pragma once
#include "common/assert.h"
#include "gpu_device.h"
#include "gpu_texture.h"

View File

@ -1,10 +1,11 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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 "gpu_texture.h"
#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"

View File

@ -1,15 +1,15 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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
#include "common/types.h"
#include "common/heap_array.h"
#include <ctime>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
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<std::vector<u8>> ReadResourceFile(std::string_view filename, bool allow_override);
std::optional<DynamicHeapArray<u8>> ReadResourceFile(std::string_view filename, bool allow_override);
/// Reads a resource file file from the resources directory as a string.
std::optional<std::string> ReadResourceFileToString(std::string_view filename, bool allow_override);

View File

@ -1,8 +1,9 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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 "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<const unsigned char*>(buffer), buffer_size);
jpeg_mem_src(&info, static_cast<const unsigned char*>(buffer), static_cast<unsigned long>(buffer_size));
});
}
@ -763,7 +764,7 @@ bool WebPBufferSaver(const RGBA8Image& image, std::vector<u8>* buffer, u8 qualit
bool WebPFileLoader(RGBA8Image* image, std::string_view filename, std::FILE* fp)
{
std::optional<std::vector<u8>> data = FileSystem::ReadBinaryFile(fp);
std::optional<DynamicHeapArray<u8>> data = FileSystem::ReadBinaryFile(fp);
if (!data.has_value())
return false;

View File

@ -1,9 +1,8 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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
#include "common/assert.h"
#include "common/types.h"
#include <algorithm>

View File

@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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 "imgui_fullscreen.h"
#include "gpu_device.h"
@ -315,7 +315,7 @@ std::optional<RGBA8Image> ImGuiFullscreen::LoadTextureImage(std::string_view pat
}
else
{
std::optional<std::vector<u8>> data = Host::ReadResourceFile(path, true);
std::optional<DynamicHeapArray<u8>> data = Host::ReadResourceFile(path, true);
if (data.has_value())
{
image = RGBA8Image();

View File

@ -86,10 +86,10 @@ static ImFont* s_fixed_font;
static ImFont* s_medium_font;
static ImFont* s_large_font;
static std::vector<u8> s_standard_font_data;
static std::vector<u8> s_fixed_font_data;
static std::vector<u8> s_icon_fa_font_data;
static std::vector<u8> s_icon_pf_font_data;
static DynamicHeapArray<u8> s_standard_font_data;
static DynamicHeapArray<u8> s_fixed_font_data;
static DynamicHeapArray<u8> s_icon_fa_font_data;
static DynamicHeapArray<u8> 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<std::vector<u8>> font_data = s_font_path.empty() ?
Host::ReadResourceFile("fonts/Roboto-Regular.ttf", true) :
FileSystem::ReadBinaryFile(s_font_path.c_str());
std::optional<DynamicHeapArray<u8>> 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<std::vector<u8>> font_data = Host::ReadResourceFile("fonts/RobotoMono-Medium.ttf", true);
std::optional<DynamicHeapArray<u8>> 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<std::vector<u8>> font_data = Host::ReadResourceFile("fonts/fa-solid-900.ttf", true);
std::optional<DynamicHeapArray<u8>> 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<std::vector<u8>> font_data = Host::ReadResourceFile("fonts/promptfont.otf", true);
std::optional<DynamicHeapArray<u8>> font_data = Host::ReadResourceFile("fonts/promptfont.otf", true);
if (!font_data.has_value())
return false;

View File

@ -1,11 +1,12 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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 "media_capture.h"
#include "gpu_device.h"
#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"

View File

@ -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<std::vector<u8>> resdata = Host::ReadResourceFile(resource_name.c_str(), true);
if (std::optional<DynamicHeapArray<u8>> 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());

View File

@ -2244,7 +2244,7 @@ void VulkanDevice::FillPipelineCacheHeader(VK_PIPELINE_CACHE_HEADER* header)
bool VulkanDevice::ReadPipelineCache(const std::string& filename)
{
std::optional<std::vector<u8>> data;
std::optional<DynamicHeapArray<u8>> data;
auto fp = FileSystem::OpenManagedCFile(filename.c_str(), "rb");
if (fp)