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 a2aa040987
commit 707453b596
32 changed files with 112 additions and 84 deletions
+2 -2
View File
@@ -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)
{
+1
View File
@@ -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"
+1
View File
@@ -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"
+4 -4
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,
+1 -1
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
+3 -1
View File
@@ -1,8 +1,10 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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"
+1
View File
@@ -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"
+2 -2
View File
@@ -4,12 +4,12 @@
#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);
+3 -2
View File
@@ -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<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;
-1
View File
@@ -3,7 +3,6 @@
#pragma once
#include "common/assert.h"
#include "common/types.h"
#include <algorithm>
+1 -1
View File
@@ -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();
+11 -11
View File
@@ -1,5 +1,5 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// 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<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;
+1
View File
@@ -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"
+1 -1
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());
+1 -1
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)