From 065867e2c24e9856c360fc2d6b9a86c92aedc43e Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Tue, 25 May 2021 19:32:56 -0400 Subject: common: fs: Rework the Common Filesystem interface to make use of std::filesystem (#6270) * common: fs: fs_types: Create filesystem types Contains various filesystem types used by the Common::FS library * common: fs: fs_util: Add std::string to std::u8string conversion utility * common: fs: path_util: Add utlity functions for paths Contains various utility functions for getting or manipulating filesystem paths used by the Common::FS library * common: fs: file: Rewrite the IOFile implementation * common: fs: Reimplement Common::FS library using std::filesystem * common: fs: fs_paths: Add fs_paths to replace common_paths * common: fs: path_util: Add the rest of the path functions * common: Remove the previous Common::FS implementation * general: Remove unused fs includes * string_util: Remove unused function and include * nvidia_flags: Migrate to the new Common::FS library * settings: Migrate to the new Common::FS library * logging: backend: Migrate to the new Common::FS library * core: Migrate to the new Common::FS library * perf_stats: Migrate to the new Common::FS library * reporter: Migrate to the new Common::FS library * telemetry_session: Migrate to the new Common::FS library * key_manager: Migrate to the new Common::FS library * bis_factory: Migrate to the new Common::FS library * registered_cache: Migrate to the new Common::FS library * xts_archive: Migrate to the new Common::FS library * service: acc: Migrate to the new Common::FS library * applets/profile: Migrate to the new Common::FS library * applets/web: Migrate to the new Common::FS library * service: filesystem: Migrate to the new Common::FS library * loader: Migrate to the new Common::FS library * gl_shader_disk_cache: Migrate to the new Common::FS library * nsight_aftermath_tracker: Migrate to the new Common::FS library * vulkan_library: Migrate to the new Common::FS library * configure_debug: Migrate to the new Common::FS library * game_list_worker: Migrate to the new Common::FS library * config: Migrate to the new Common::FS library * configure_filesystem: Migrate to the new Common::FS library * configure_per_game_addons: Migrate to the new Common::FS library * configure_profile_manager: Migrate to the new Common::FS library * configure_ui: Migrate to the new Common::FS library * input_profiles: Migrate to the new Common::FS library * yuzu_cmd: config: Migrate to the new Common::FS library * yuzu_cmd: Migrate to the new Common::FS library * vfs_real: Migrate to the new Common::FS library * vfs: Migrate to the new Common::FS library * vfs_libzip: Migrate to the new Common::FS library * service: bcat: Migrate to the new Common::FS library * yuzu: main: Migrate to the new Common::FS library * vfs_real: Delete the contents of an existing file in CreateFile Current usages of CreateFile expect to delete the contents of an existing file, retain this behavior for now. * input_profiles: Don't iterate the input profile dir if it does not exist Silences an error produced in the log if the directory does not exist. * game_list_worker: Skip parsing file if the returned VfsFile is nullptr Prevents crashes in GetLoader when the virtual file is nullptr * common: fs: Validate paths for path length * service: filesystem: Open the mod load directory as read only --- .../renderer_opengl/gl_shader_disk_cache.cpp | 153 ++++++++++----------- .../renderer_opengl/gl_shader_disk_cache.h | 11 +- .../vulkan_common/nsight_aftermath_tracker.cpp | 47 ++++--- .../vulkan_common/nsight_aftermath_tracker.h | 3 +- src/video_core/vulkan_common/vulkan_library.cpp | 8 +- 5 files changed, 116 insertions(+), 106 deletions(-) (limited to 'src/video_core') diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp index dbcb751cb..0deb86517 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -7,9 +7,10 @@ #include #include "common/assert.h" -#include "common/common_paths.h" #include "common/common_types.h" -#include "common/file_util.h" +#include "common/fs/file.h" +#include "common/fs/fs.h" +#include "common/fs/path_util.h" #include "common/logging/log.h" #include "common/scm_rev.h" #include "common/settings.h" @@ -26,11 +27,7 @@ using Tegra::Engines::ShaderType; using VideoCommon::Shader::BindlessSamplerMap; using VideoCommon::Shader::BoundSamplerMap; using VideoCommon::Shader::KeyMap; - -namespace { - using VideoCommon::Shader::SeparateSamplerKey; - using ShaderCacheVersionHash = std::array; struct ConstBufferKey { @@ -58,6 +55,8 @@ struct BindlessSamplerEntry { Tegra::Engines::SamplerDescriptor sampler; }; +namespace { + constexpr u32 NativeVersion = 21; ShaderCacheVersionHash GetShaderCacheVersionHash() { @@ -74,22 +73,20 @@ ShaderDiskCacheEntry::ShaderDiskCacheEntry() = default; ShaderDiskCacheEntry::~ShaderDiskCacheEntry() = default; bool ShaderDiskCacheEntry::Load(Common::FS::IOFile& file) { - if (file.ReadBytes(&type, sizeof(u32)) != sizeof(u32)) { + if (!file.ReadObject(type)) { return false; } u32 code_size; u32 code_size_b; - if (file.ReadBytes(&code_size, sizeof(u32)) != sizeof(u32) || - file.ReadBytes(&code_size_b, sizeof(u32)) != sizeof(u32)) { + if (!file.ReadObject(code_size) || !file.ReadObject(code_size_b)) { return false; } code.resize(code_size); code_b.resize(code_size_b); - - if (file.ReadArray(code.data(), code_size) != code_size) { + if (file.Read(code) != code_size) { return false; } - if (HasProgramA() && file.ReadArray(code_b.data(), code_size_b) != code_size_b) { + if (HasProgramA() && file.Read(code_b) != code_size_b) { return false; } @@ -99,13 +96,12 @@ bool ShaderDiskCacheEntry::Load(Common::FS::IOFile& file) { u32 num_bound_samplers; u32 num_separate_samplers; u32 num_bindless_samplers; - if (file.ReadArray(&unique_identifier, 1) != 1 || file.ReadArray(&bound_buffer, 1) != 1 || - file.ReadArray(&is_texture_handler_size_known, 1) != 1 || - file.ReadArray(&texture_handler_size_value, 1) != 1 || - file.ReadArray(&graphics_info, 1) != 1 || file.ReadArray(&compute_info, 1) != 1 || - file.ReadArray(&num_keys, 1) != 1 || file.ReadArray(&num_bound_samplers, 1) != 1 || - file.ReadArray(&num_separate_samplers, 1) != 1 || - file.ReadArray(&num_bindless_samplers, 1) != 1) { + if (!file.ReadObject(unique_identifier) || !file.ReadObject(bound_buffer) || + !file.ReadObject(is_texture_handler_size_known) || + !file.ReadObject(texture_handler_size_value) || !file.ReadObject(graphics_info) || + !file.ReadObject(compute_info) || !file.ReadObject(num_keys) || + !file.ReadObject(num_bound_samplers) || !file.ReadObject(num_separate_samplers) || + !file.ReadObject(num_bindless_samplers)) { return false; } if (is_texture_handler_size_known) { @@ -116,13 +112,10 @@ bool ShaderDiskCacheEntry::Load(Common::FS::IOFile& file) { std::vector flat_bound_samplers(num_bound_samplers); std::vector flat_separate_samplers(num_separate_samplers); std::vector flat_bindless_samplers(num_bindless_samplers); - if (file.ReadArray(flat_keys.data(), flat_keys.size()) != flat_keys.size() || - file.ReadArray(flat_bound_samplers.data(), flat_bound_samplers.size()) != - flat_bound_samplers.size() || - file.ReadArray(flat_separate_samplers.data(), flat_separate_samplers.size()) != - flat_separate_samplers.size() || - file.ReadArray(flat_bindless_samplers.data(), flat_bindless_samplers.size()) != - flat_bindless_samplers.size()) { + if (file.Read(flat_keys) != flat_keys.size() || + file.Read(flat_bound_samplers) != flat_bound_samplers.size() || + file.Read(flat_separate_samplers) != flat_separate_samplers.size() || + file.Read(flat_bindless_samplers) != flat_bindless_samplers.size()) { return false; } for (const auto& entry : flat_keys) { @@ -145,26 +138,25 @@ bool ShaderDiskCacheEntry::Load(Common::FS::IOFile& file) { } bool ShaderDiskCacheEntry::Save(Common::FS::IOFile& file) const { - if (file.WriteObject(static_cast(type)) != 1 || - file.WriteObject(static_cast(code.size())) != 1 || - file.WriteObject(static_cast(code_b.size())) != 1) { + if (!file.WriteObject(static_cast(type)) || + !file.WriteObject(static_cast(code.size())) || + !file.WriteObject(static_cast(code_b.size()))) { return false; } - if (file.WriteArray(code.data(), code.size()) != code.size()) { + if (file.Write(code) != code.size()) { return false; } - if (HasProgramA() && file.WriteArray(code_b.data(), code_b.size()) != code_b.size()) { + if (HasProgramA() && file.Write(code_b) != code_b.size()) { return false; } - if (file.WriteObject(unique_identifier) != 1 || file.WriteObject(bound_buffer) != 1 || - file.WriteObject(static_cast(texture_handler_size.has_value())) != 1 || - file.WriteObject(texture_handler_size.value_or(0)) != 1 || - file.WriteObject(graphics_info) != 1 || file.WriteObject(compute_info) != 1 || - file.WriteObject(static_cast(keys.size())) != 1 || - file.WriteObject(static_cast(bound_samplers.size())) != 1 || - file.WriteObject(static_cast(separate_samplers.size())) != 1 || - file.WriteObject(static_cast(bindless_samplers.size())) != 1) { + if (!file.WriteObject(unique_identifier) || !file.WriteObject(bound_buffer) || + !file.WriteObject(static_cast(texture_handler_size.has_value())) || + !file.WriteObject(texture_handler_size.value_or(0)) || !file.WriteObject(graphics_info) || + !file.WriteObject(compute_info) || !file.WriteObject(static_cast(keys.size())) || + !file.WriteObject(static_cast(bound_samplers.size())) || + !file.WriteObject(static_cast(separate_samplers.size())) || + !file.WriteObject(static_cast(bindless_samplers.size()))) { return false; } @@ -197,13 +189,10 @@ bool ShaderDiskCacheEntry::Save(Common::FS::IOFile& file) const { BindlessSamplerEntry{address.first, address.second, sampler}); } - return file.WriteArray(flat_keys.data(), flat_keys.size()) == flat_keys.size() && - file.WriteArray(flat_bound_samplers.data(), flat_bound_samplers.size()) == - flat_bound_samplers.size() && - file.WriteArray(flat_separate_samplers.data(), flat_separate_samplers.size()) == - flat_separate_samplers.size() && - file.WriteArray(flat_bindless_samplers.data(), flat_bindless_samplers.size()) == - flat_bindless_samplers.size(); + return file.Write(flat_keys) == flat_keys.size() && + file.Write(flat_bound_samplers) == flat_bound_samplers.size() && + file.Write(flat_separate_samplers) == flat_separate_samplers.size() && + file.Write(flat_bindless_samplers) == flat_bindless_samplers.size(); } ShaderDiskCacheOpenGL::ShaderDiskCacheOpenGL() = default; @@ -221,7 +210,8 @@ std::optional> ShaderDiskCacheOpenGL::LoadTran return std::nullopt; } - Common::FS::IOFile file(GetTransferablePath(), "rb"); + Common::FS::IOFile file{GetTransferablePath(), Common::FS::FileAccessMode::Read, + Common::FS::FileType::BinaryFile}; if (!file.IsOpen()) { LOG_INFO(Render_OpenGL, "No transferable shader cache found"); is_usable = true; @@ -229,7 +219,7 @@ std::optional> ShaderDiskCacheOpenGL::LoadTran } u32 version{}; - if (file.ReadBytes(&version, sizeof(version)) != sizeof(version)) { + if (!file.ReadObject(version)) { LOG_ERROR(Render_OpenGL, "Failed to get transferable cache version, skipping it"); return std::nullopt; } @@ -249,7 +239,7 @@ std::optional> ShaderDiskCacheOpenGL::LoadTran // Version is valid, load the shaders std::vector entries; - while (file.Tell() < file.GetSize()) { + while (static_cast(file.Tell()) < file.GetSize()) { ShaderDiskCacheEntry& entry = entries.emplace_back(); if (!entry.Load(file)) { LOG_ERROR(Render_OpenGL, "Failed to load transferable raw entry, skipping"); @@ -266,7 +256,8 @@ std::vector ShaderDiskCacheOpenGL::LoadPrecompiled() return {}; } - Common::FS::IOFile file(GetPrecompiledPath(), "rb"); + Common::FS::IOFile file{GetPrecompiledPath(), Common::FS::FileAccessMode::Read, + Common::FS::FileType::BinaryFile}; if (!file.IsOpen()) { LOG_INFO(Render_OpenGL, "No precompiled shader cache found"); return {}; @@ -286,7 +277,9 @@ std::optional> ShaderDiskCacheOpenGL::Lo Common::FS::IOFile& file) { // Read compressed file from disk and decompress to virtual precompiled cache file std::vector compressed(file.GetSize()); - file.ReadBytes(compressed.data(), compressed.size()); + if (file.Read(compressed) != file.GetSize()) { + return std::nullopt; + } const std::vector decompressed = Common::Compression::DecompressDataZSTD(compressed); SaveArrayToPrecompiled(decompressed.data(), decompressed.size()); precompiled_cache_virtual_file_offset = 0; @@ -321,9 +314,9 @@ std::optional> ShaderDiskCacheOpenGL::Lo } void ShaderDiskCacheOpenGL::InvalidateTransferable() { - if (!Common::FS::Delete(GetTransferablePath())) { + if (!Common::FS::RemoveFile(GetTransferablePath())) { LOG_ERROR(Render_OpenGL, "Failed to invalidate transferable file={}", - GetTransferablePath()); + Common::FS::PathToUTF8String(GetTransferablePath())); } InvalidatePrecompiled(); } @@ -332,8 +325,9 @@ void ShaderDiskCacheOpenGL::InvalidatePrecompiled() { // Clear virtaul precompiled cache file precompiled_cache_virtual_file.Resize(0); - if (!Common::FS::Delete(GetPrecompiledPath())) { - LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath()); + if (!Common::FS::RemoveFile(GetPrecompiledPath())) { + LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", + Common::FS::PathToUTF8String(GetPrecompiledPath())); } } @@ -398,16 +392,18 @@ Common::FS::IOFile ShaderDiskCacheOpenGL::AppendTransferableFile() const { const auto transferable_path{GetTransferablePath()}; const bool existed = Common::FS::Exists(transferable_path); - Common::FS::IOFile file(transferable_path, "ab"); + Common::FS::IOFile file{transferable_path, Common::FS::FileAccessMode::Append, + Common::FS::FileType::BinaryFile}; if (!file.IsOpen()) { - LOG_ERROR(Render_OpenGL, "Failed to open transferable cache in path={}", transferable_path); + LOG_ERROR(Render_OpenGL, "Failed to open transferable cache in path={}", + Common::FS::PathToUTF8String(transferable_path)); return {}; } if (!existed || file.GetSize() == 0) { // If the file didn't exist, write its version - if (file.WriteObject(NativeVersion) != 1) { + if (!file.WriteObject(NativeVersion)) { LOG_ERROR(Render_OpenGL, "Failed to write transferable cache version in path={}", - transferable_path); + Common::FS::PathToUTF8String(transferable_path)); return {}; } } @@ -429,51 +425,54 @@ void ShaderDiskCacheOpenGL::SaveVirtualPrecompiledFile() { const std::vector compressed = Common::Compression::CompressDataZSTDDefault(uncompressed.data(), uncompressed.size()); - const auto precompiled_path{GetPrecompiledPath()}; - Common::FS::IOFile file(precompiled_path, "wb"); + const auto precompiled_path = GetPrecompiledPath(); + Common::FS::IOFile file{precompiled_path, Common::FS::FileAccessMode::Write, + Common::FS::FileType::BinaryFile}; if (!file.IsOpen()) { - LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", precompiled_path); + LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", + Common::FS::PathToUTF8String(precompiled_path)); return; } - if (file.WriteBytes(compressed.data(), compressed.size()) != compressed.size()) { + if (file.Write(compressed) != compressed.size()) { LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}", - precompiled_path); + Common::FS::PathToUTF8String(precompiled_path)); } } bool ShaderDiskCacheOpenGL::EnsureDirectories() const { - const auto CreateDir = [](const std::string& dir) { + const auto CreateDir = [](const std::filesystem::path& dir) { if (!Common::FS::CreateDir(dir)) { - LOG_ERROR(Render_OpenGL, "Failed to create directory={}", dir); + LOG_ERROR(Render_OpenGL, "Failed to create directory={}", + Common::FS::PathToUTF8String(dir)); return false; } return true; }; - return CreateDir(Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir)) && + return CreateDir(Common::FS::GetYuzuPath(Common::FS::YuzuPath::ShaderDir)) && CreateDir(GetBaseDir()) && CreateDir(GetTransferableDir()) && CreateDir(GetPrecompiledDir()); } -std::string ShaderDiskCacheOpenGL::GetTransferablePath() const { - return Common::FS::SanitizePath(GetTransferableDir() + DIR_SEP_CHR + GetTitleID() + ".bin"); +std::filesystem::path ShaderDiskCacheOpenGL::GetTransferablePath() const { + return GetTransferableDir() / fmt::format("{}.bin", GetTitleID()); } -std::string ShaderDiskCacheOpenGL::GetPrecompiledPath() const { - return Common::FS::SanitizePath(GetPrecompiledDir() + DIR_SEP_CHR + GetTitleID() + ".bin"); +std::filesystem::path ShaderDiskCacheOpenGL::GetPrecompiledPath() const { + return GetPrecompiledDir() / fmt::format("{}.bin", GetTitleID()); } -std::string ShaderDiskCacheOpenGL::GetTransferableDir() const { - return GetBaseDir() + DIR_SEP "transferable"; +std::filesystem::path ShaderDiskCacheOpenGL::GetTransferableDir() const { + return GetBaseDir() / "transferable"; } -std::string ShaderDiskCacheOpenGL::GetPrecompiledDir() const { - return GetBaseDir() + DIR_SEP "precompiled"; +std::filesystem::path ShaderDiskCacheOpenGL::GetPrecompiledDir() const { + return GetBaseDir() / "precompiled"; } -std::string ShaderDiskCacheOpenGL::GetBaseDir() const { - return Common::FS::GetUserPath(Common::FS::UserPath::ShaderDir) + DIR_SEP "opengl"; +std::filesystem::path ShaderDiskCacheOpenGL::GetBaseDir() const { + return Common::FS::GetYuzuPath(Common::FS::YuzuPath::ShaderDir) / "opengl"; } std::string ShaderDiskCacheOpenGL::GetTitleID() const { diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.h b/src/video_core/renderer_opengl/gl_shader_disk_cache.h index aef841c1d..f8bc23868 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -108,19 +109,19 @@ private: bool EnsureDirectories() const; /// Gets current game's transferable file path - std::string GetTransferablePath() const; + std::filesystem::path GetTransferablePath() const; /// Gets current game's precompiled file path - std::string GetPrecompiledPath() const; + std::filesystem::path GetPrecompiledPath() const; /// Get user's transferable directory path - std::string GetTransferableDir() const; + std::filesystem::path GetTransferableDir() const; /// Get user's precompiled directory path - std::string GetPrecompiledDir() const; + std::filesystem::path GetPrecompiledDir() const; /// Get user's shader directory path - std::string GetBaseDir() const; + std::filesystem::path GetBaseDir() const; /// Get current game's title id std::string GetTitleID() const; diff --git a/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp b/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp index 7a9d00d4f..f0ee76519 100644 --- a/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp +++ b/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp @@ -5,6 +5,7 @@ #ifdef HAS_NSIGHT_AFTERMATH #include +#include #include #include #include @@ -12,9 +13,10 @@ #include -#include "common/common_paths.h" #include "common/common_types.h" -#include "common/file_util.h" +#include "common/fs/file.h" +#include "common/fs/fs.h" +#include "common/fs/path_util.h" #include "common/logging/log.h" #include "common/scope_exit.h" #include "video_core/vulkan_common/nsight_aftermath_tracker.h" @@ -46,9 +48,9 @@ NsightAftermathTracker::NsightAftermathTracker() { LOG_ERROR(Render_Vulkan, "Failed to load Nsight Aftermath function pointers"); return; } - dump_dir = Common::FS::GetUserPath(Common::FS::UserPath::LogDir) + "gpucrash"; + dump_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::LogDir) / "gpucrash"; - void(Common::FS::DeleteDirRecursively(dump_dir)); + void(Common::FS::RemoveDirRecursively(dump_dir)); if (!Common::FS::CreateDir(dump_dir)) { LOG_ERROR(Render_Vulkan, "Failed to create Nsight Aftermath dump directory"); return; @@ -60,7 +62,8 @@ NsightAftermathTracker::NsightAftermathTracker() { LOG_ERROR(Render_Vulkan, "GFSDK_Aftermath_EnableGpuCrashDumps failed"); return; } - LOG_INFO(Render_Vulkan, "Nsight Aftermath dump directory is \"{}\"", dump_dir); + LOG_INFO(Render_Vulkan, "Nsight Aftermath dump directory is \"{}\"", + Common::FS::PathToUTF8String(dump_dir)); initialized = true; } @@ -89,12 +92,15 @@ void NsightAftermathTracker::SaveShader(const std::vector& spirv) const { return; } - Common::FS::IOFile file(fmt::format("{}/source_{:016x}.spv", dump_dir, hash.hash), "wb"); + const auto shader_file = dump_dir / fmt::format("source_{:016x}.spv", hash.hash); + + Common::FS::IOFile file{shader_file, Common::FS::FileAccessMode::Write, + Common::FS::FileType::BinaryFile}; if (!file.IsOpen()) { LOG_ERROR(Render_Vulkan, "Failed to dump SPIR-V module with hash={:016x}", hash.hash); return; } - if (file.WriteArray(spirv.data(), spirv.size()) != spirv.size()) { + if (file.Write(spirv) != spirv.size()) { LOG_ERROR(Render_Vulkan, "Failed to write SPIR-V module with hash={:016x}", hash.hash); return; } @@ -129,22 +135,24 @@ void NsightAftermathTracker::OnGpuCrashDumpCallback(const void* gpu_crash_dump, return; } - const std::string base_name = [this] { + std::filesystem::path base_name = [this] { const int id = dump_id++; if (id == 0) { - return fmt::format("{}/crash.nv-gpudmp", dump_dir); + return dump_dir / "crash.nv-gpudmp"; } else { - return fmt::format("{}/crash_{}.nv-gpudmp", dump_dir, id); + return dump_dir / fmt::format("crash_{}.nv-gpudmp", id); } }(); std::string_view dump_view(static_cast(gpu_crash_dump), gpu_crash_dump_size); - if (Common::FS::WriteStringToFile(false, base_name, dump_view) != gpu_crash_dump_size) { + if (Common::FS::WriteStringToFile(base_name, Common::FS::FileType::BinaryFile, dump_view) != + gpu_crash_dump_size) { LOG_ERROR(Render_Vulkan, "Failed to write dump file"); return; } const std::string_view json_view(json.data(), json.size()); - if (Common::FS::WriteStringToFile(true, base_name + ".json", json_view) != json.size()) { + if (Common::FS::WriteStringToFile(base_name.concat(".json"), Common::FS::FileType::TextFile, + json_view) != json.size()) { LOG_ERROR(Render_Vulkan, "Failed to write JSON"); return; } @@ -161,16 +169,17 @@ void NsightAftermathTracker::OnShaderDebugInfoCallback(const void* shader_debug_ return; } - const std::string path = - fmt::format("{}/shader_{:016x}{:016x}.nvdbg", dump_dir, identifier.id[0], identifier.id[1]); - Common::FS::IOFile file(path, "wb"); + const auto path = + dump_dir / fmt::format("shader_{:016x}{:016x}.nvdbg", identifier.id[0], identifier.id[1]); + Common::FS::IOFile file{path, Common::FS::FileAccessMode::Write, + Common::FS::FileType::BinaryFile}; if (!file.IsOpen()) { - LOG_ERROR(Render_Vulkan, "Failed to create file {}", path); + LOG_ERROR(Render_Vulkan, "Failed to create file {}", Common::FS::PathToUTF8String(path)); return; } - if (file.WriteBytes(static_cast(shader_debug_info), shader_debug_info_size) != - shader_debug_info_size) { - LOG_ERROR(Render_Vulkan, "Failed to write file {}", path); + if (file.WriteSpan(std::span(static_cast(shader_debug_info), + shader_debug_info_size)) != shader_debug_info_size) { + LOG_ERROR(Render_Vulkan, "Failed to write file {}", Common::FS::PathToUTF8String(path)); return; } } diff --git a/src/video_core/vulkan_common/nsight_aftermath_tracker.h b/src/video_core/vulkan_common/nsight_aftermath_tracker.h index 1ce8d4e8e..4fe2b14d9 100644 --- a/src/video_core/vulkan_common/nsight_aftermath_tracker.h +++ b/src/video_core/vulkan_common/nsight_aftermath_tracker.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -54,7 +55,7 @@ private: mutable std::mutex mutex; - std::string dump_dir; + std::filesystem::path dump_dir; int dump_id = 0; bool initialized = false; diff --git a/src/video_core/vulkan_common/vulkan_library.cpp b/src/video_core/vulkan_common/vulkan_library.cpp index 557871d81..22833fa56 100644 --- a/src/video_core/vulkan_common/vulkan_library.cpp +++ b/src/video_core/vulkan_common/vulkan_library.cpp @@ -6,7 +6,7 @@ #include #include "common/dynamic_library.h" -#include "common/file_util.h" +#include "common/fs/path_util.h" #include "video_core/vulkan_common/vulkan_library.h" namespace Vulkan { @@ -18,9 +18,9 @@ Common::DynamicLibrary OpenLibrary() { char* const libvulkan_env = std::getenv("LIBVULKAN_PATH"); if (!libvulkan_env || !library.Open(libvulkan_env)) { // Use the libvulkan.dylib from the application bundle. - const std::string filename = - Common::FS::GetBundleDirectory() + "/Contents/Frameworks/libvulkan.dylib"; - void(library.Open(filename.c_str())); + const auto filename = + Common::FS::GetBundleDirectory() / "Contents/Frameworks/libvulkan.dylib"; + void(library.Open(Common::FS::PathToUTF8String(filename).c_str())); } #else std::string filename = Common::DynamicLibrary::GetVersionedFilename("vulkan", 1); -- cgit v1.2.3