aboutsummaryrefslogtreecommitdiff
path: root/src/video_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/buffer_cache/buffer_cache.h4
-rw-r--r--src/video_core/gpu.cpp12
-rw-r--r--src/video_core/gpu.h2
-rw-r--r--src/video_core/rasterizer_accelerated.cpp6
-rw-r--r--src/video_core/rasterizer_accelerated.h12
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.cpp153
-rw-r--r--src/video_core/renderer_opengl/gl_shader_disk_cache.h11
-rw-r--r--src/video_core/vulkan_common/nsight_aftermath_tracker.cpp47
-rw-r--r--src/video_core/vulkan_common/nsight_aftermath_tracker.h3
-rw-r--r--src/video_core/vulkan_common/vulkan_library.cpp8
-rw-r--r--src/video_core/vulkan_common/vulkan_memory_allocator.cpp67
-rw-r--r--src/video_core/vulkan_common/vulkan_memory_allocator.h7
12 files changed, 183 insertions, 149 deletions
diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h
index de971041f..9e6b87960 100644
--- a/src/video_core/buffer_cache/buffer_cache.h
+++ b/src/video_core/buffer_cache/buffer_cache.h
@@ -596,7 +596,7 @@ void BufferCache<P>::PopAsyncFlushes() {
runtime.CopyBuffer(download_staging.buffer, slot_buffers[buffer_id], copies);
}
runtime.Finish();
- for (const auto [copy, buffer_id] : downloads) {
+ for (const auto& [copy, buffer_id] : downloads) {
const Buffer& buffer = slot_buffers[buffer_id];
const VAddr cpu_addr = buffer.CpuAddr() + copy.src_offset;
// Undo the modified offset
@@ -606,7 +606,7 @@ void BufferCache<P>::PopAsyncFlushes() {
}
} else {
const std::span<u8> immediate_buffer = ImmediateBuffer(largest_copy);
- for (const auto [copy, buffer_id] : downloads) {
+ for (const auto& [copy, buffer_id] : downloads) {
Buffer& buffer = slot_buffers[buffer_id];
buffer.ImmediateDownload(copy.src_offset, immediate_buffer.subspan(0, copy.size));
const VAddr cpu_addr = buffer.CpuAddr() + copy.src_offset;
diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp
index 37f7b24e1..35cc561be 100644
--- a/src/video_core/gpu.cpp
+++ b/src/video_core/gpu.cpp
@@ -104,7 +104,13 @@ void GPU::WaitFence(u32 syncpoint_id, u32 value) {
}
MICROPROFILE_SCOPE(GPU_wait);
std::unique_lock lock{sync_mutex};
- sync_cv.wait(lock, [=, this] { return syncpoints.at(syncpoint_id).load() >= value; });
+ sync_cv.wait(lock, [=, this] {
+ if (shutting_down.load(std::memory_order_relaxed)) {
+ // We're shutting down, ensure no threads continue to wait for the next syncpoint
+ return true;
+ }
+ return syncpoints.at(syncpoint_id).load() >= value;
+ });
}
void GPU::IncrementSyncPoint(const u32 syncpoint_id) {
@@ -523,6 +529,10 @@ void GPU::TriggerCpuInterrupt(const u32 syncpoint_id, const u32 value) const {
}
void GPU::ShutDown() {
+ // Signal that threads should no longer block on syncpoint fences
+ shutting_down.store(true, std::memory_order_relaxed);
+ sync_cv.notify_all();
+
gpu_thread.ShutDown();
}
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h
index 29a867863..a8e98e51b 100644
--- a/src/video_core/gpu.h
+++ b/src/video_core/gpu.h
@@ -389,6 +389,8 @@ private:
std::unique_ptr<Engines::KeplerMemory> kepler_memory;
/// Shader build notifier
std::unique_ptr<VideoCore::ShaderNotify> shader_notify;
+ /// When true, we are about to shut down emulation session, so terminate outstanding tasks
+ std::atomic_bool shutting_down{};
std::array<std::atomic<u32>, Service::Nvidia::MaxSyncPoints> syncpoints{};
diff --git a/src/video_core/rasterizer_accelerated.cpp b/src/video_core/rasterizer_accelerated.cpp
index 62d84c0f8..6decd2546 100644
--- a/src/video_core/rasterizer_accelerated.cpp
+++ b/src/video_core/rasterizer_accelerated.cpp
@@ -18,10 +18,10 @@ RasterizerAccelerated::~RasterizerAccelerated() = default;
void RasterizerAccelerated::UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {
const auto page_end = Common::DivCeil(addr + size, Core::Memory::PAGE_SIZE);
for (auto page = addr >> Core::Memory::PAGE_BITS; page != page_end; ++page) {
- auto& count = cached_pages.at(page >> 3).Count(page);
+ auto& count = cached_pages.at(page >> 2).Count(page);
if (delta > 0) {
- ASSERT_MSG(count < UINT8_MAX, "Count may overflow!");
+ ASSERT_MSG(count < UINT16_MAX, "Count may overflow!");
} else if (delta < 0) {
ASSERT_MSG(count > 0, "Count may underflow!");
} else {
@@ -29,7 +29,7 @@ void RasterizerAccelerated::UpdatePagesCachedCount(VAddr addr, u64 size, int del
}
// Adds or subtracts 1, as count is a unsigned 8-bit value
- count += static_cast<u8>(delta);
+ count += static_cast<u16>(delta);
// Assume delta is either -1 or 1
if (count == 0) {
diff --git a/src/video_core/rasterizer_accelerated.h b/src/video_core/rasterizer_accelerated.h
index 9227a4adc..ea879bfdd 100644
--- a/src/video_core/rasterizer_accelerated.h
+++ b/src/video_core/rasterizer_accelerated.h
@@ -29,20 +29,20 @@ private:
public:
CacheEntry() = default;
- std::atomic_uint8_t& Count(std::size_t page) {
- return values[page & 7];
+ std::atomic_uint16_t& Count(std::size_t page) {
+ return values[page & 3];
}
- const std::atomic_uint8_t& Count(std::size_t page) const {
- return values[page & 7];
+ const std::atomic_uint16_t& Count(std::size_t page) const {
+ return values[page & 3];
}
private:
- std::array<std::atomic_uint8_t, 8> values{};
+ std::array<std::atomic_uint16_t, 4> values{};
};
static_assert(sizeof(CacheEntry) == 8, "CacheEntry should be 8 bytes!");
- std::array<CacheEntry, 0x800000> cached_pages;
+ std::array<CacheEntry, 0x1000000> cached_pages;
Core::Memory::Memory& cpu_memory;
};
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 <fmt/format.h>
#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<u8, 64>;
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<BoundSamplerEntry> flat_bound_samplers(num_bound_samplers);
std::vector<SeparateSamplerEntry> flat_separate_samplers(num_separate_samplers);
std::vector<BindlessSamplerEntry> 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<u32>(type)) != 1 ||
- file.WriteObject(static_cast<u32>(code.size())) != 1 ||
- file.WriteObject(static_cast<u32>(code_b.size())) != 1) {
+ if (!file.WriteObject(static_cast<u32>(type)) ||
+ !file.WriteObject(static_cast<u32>(code.size())) ||
+ !file.WriteObject(static_cast<u32>(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<u8>(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<u32>(keys.size())) != 1 ||
- file.WriteObject(static_cast<u32>(bound_samplers.size())) != 1 ||
- file.WriteObject(static_cast<u32>(separate_samplers.size())) != 1 ||
- file.WriteObject(static_cast<u32>(bindless_samplers.size())) != 1) {
+ if (!file.WriteObject(unique_identifier) || !file.WriteObject(bound_buffer) ||
+ !file.WriteObject(static_cast<u8>(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<u32>(keys.size())) ||
+ !file.WriteObject(static_cast<u32>(bound_samplers.size())) ||
+ !file.WriteObject(static_cast<u32>(separate_samplers.size())) ||
+ !file.WriteObject(static_cast<u32>(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<std::vector<ShaderDiskCacheEntry>> 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<std::vector<ShaderDiskCacheEntry>> 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<std::vector<ShaderDiskCacheEntry>> ShaderDiskCacheOpenGL::LoadTran
// Version is valid, load the shaders
std::vector<ShaderDiskCacheEntry> entries;
- while (file.Tell() < file.GetSize()) {
+ while (static_cast<u64>(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<ShaderDiskCachePrecompiled> 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<std::vector<ShaderDiskCachePrecompiled>> ShaderDiskCacheOpenGL::Lo
Common::FS::IOFile& file) {
// Read compressed file from disk and decompress to virtual precompiled cache file
std::vector<u8> compressed(file.GetSize());
- file.ReadBytes(compressed.data(), compressed.size());
+ if (file.Read(compressed) != file.GetSize()) {
+ return std::nullopt;
+ }
const std::vector<u8> decompressed = Common::Compression::DecompressDataZSTD(compressed);
SaveArrayToPrecompiled(decompressed.data(), decompressed.size());
precompiled_cache_virtual_file_offset = 0;
@@ -321,9 +314,9 @@ std::optional<std::vector<ShaderDiskCachePrecompiled>> 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<u8> 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 <filesystem>
#include <optional>
#include <string>
#include <tuple>
@@ -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 <mutex>
+#include <span>
#include <string>
#include <string_view>
#include <utility>
@@ -12,9 +13,10 @@
#include <fmt/format.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/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<u32>& 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<const char*>(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<const u8*>(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<const u8*>(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 <filesystem>
#include <mutex>
#include <string>
#include <vector>
@@ -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 <string>
#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);
diff --git a/src/video_core/vulkan_common/vulkan_memory_allocator.cpp b/src/video_core/vulkan_common/vulkan_memory_allocator.cpp
index fa37aa79a..5edd06ebc 100644
--- a/src/video_core/vulkan_common/vulkan_memory_allocator.cpp
+++ b/src/video_core/vulkan_common/vulkan_memory_allocator.cpp
@@ -53,6 +53,18 @@ struct Range {
UNREACHABLE_MSG("Invalid memory usage={}", usage);
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
}
+
+constexpr VkExportMemoryAllocateInfo EXPORT_ALLOCATE_INFO{
+ .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO,
+ .pNext = nullptr,
+#ifdef _WIN32
+ .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT,
+#elif __unix__
+ .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT,
+#else
+ .handleTypes = 0,
+#endif
+};
} // Anonymous namespace
class MemoryAllocation {
@@ -131,7 +143,7 @@ public:
/// Returns whether this allocation is compatible with the arguments.
[[nodiscard]] bool IsCompatible(VkMemoryPropertyFlags flags, u32 type_mask) const {
- return (flags & property_flags) && (type_mask & shifted_memory_type) != 0;
+ return (flags & property_flags) == property_flags && (type_mask & shifted_memory_type) != 0;
}
private:
@@ -217,14 +229,18 @@ MemoryAllocator::~MemoryAllocator() = default;
MemoryCommit MemoryAllocator::Commit(const VkMemoryRequirements& requirements, MemoryUsage usage) {
// Find the fastest memory flags we can afford with the current requirements
- const VkMemoryPropertyFlags flags = MemoryPropertyFlags(requirements.memoryTypeBits, usage);
+ const u32 type_mask = requirements.memoryTypeBits;
+ const VkMemoryPropertyFlags usage_flags = MemoryUsagePropertyFlags(usage);
+ const VkMemoryPropertyFlags flags = MemoryPropertyFlags(type_mask, usage_flags);
if (std::optional<MemoryCommit> commit = TryCommit(requirements, flags)) {
return std::move(*commit);
}
// Commit has failed, allocate more memory.
- // TODO(Rodrigo): Handle out of memory situations in some way like flushing to guest memory.
- AllocMemory(flags, requirements.memoryTypeBits, AllocationChunkSize(requirements.size));
-
+ const u64 chunk_size = AllocationChunkSize(requirements.size);
+ if (!TryAllocMemory(flags, type_mask, chunk_size)) {
+ // TODO(Rodrigo): Handle out of memory situations in some way like flushing to guest memory.
+ throw vk::Exception(VK_ERROR_OUT_OF_DEVICE_MEMORY);
+ }
// Commit again, this time it won't fail since there's a fresh allocation above.
// If it does, there's a bug.
return TryCommit(requirements, flags).value();
@@ -242,26 +258,25 @@ MemoryCommit MemoryAllocator::Commit(const vk::Image& image, MemoryUsage usage)
return commit;
}
-void MemoryAllocator::AllocMemory(VkMemoryPropertyFlags flags, u32 type_mask, u64 size) {
+bool MemoryAllocator::TryAllocMemory(VkMemoryPropertyFlags flags, u32 type_mask, u64 size) {
const u32 type = FindType(flags, type_mask).value();
- const VkExportMemoryAllocateInfo export_allocate_info{
- .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO,
- .pNext = nullptr,
-#ifdef _WIN32
- .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT,
-#elif __unix__
- .handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT,
-#else
- .handleTypes = 0,
-#endif
- };
- vk::DeviceMemory memory = device.GetLogical().AllocateMemory({
+ vk::DeviceMemory memory = device.GetLogical().TryAllocateMemory({
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
- .pNext = export_allocations ? &export_allocate_info : nullptr,
+ .pNext = export_allocations ? &EXPORT_ALLOCATE_INFO : nullptr,
.allocationSize = size,
.memoryTypeIndex = type,
});
+ if (!memory) {
+ if ((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0) {
+ // Try to allocate non device local memory
+ return TryAllocMemory(flags & ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, type_mask, size);
+ } else {
+ // RIP
+ return false;
+ }
+ }
allocations.push_back(std::make_unique<MemoryAllocation>(std::move(memory), flags, size, type));
+ return true;
}
std::optional<MemoryCommit> MemoryAllocator::TryCommit(const VkMemoryRequirements& requirements,
@@ -274,24 +289,24 @@ std::optional<MemoryCommit> MemoryAllocator::TryCommit(const VkMemoryRequirement
return commit;
}
}
+ if ((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0) {
+ // Look for non device local commits on failure
+ return TryCommit(requirements, flags & ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
+ }
return std::nullopt;
}
-VkMemoryPropertyFlags MemoryAllocator::MemoryPropertyFlags(u32 type_mask, MemoryUsage usage) const {
- return MemoryPropertyFlags(type_mask, MemoryUsagePropertyFlags(usage));
-}
-
VkMemoryPropertyFlags MemoryAllocator::MemoryPropertyFlags(u32 type_mask,
VkMemoryPropertyFlags flags) const {
if (FindType(flags, type_mask)) {
// Found a memory type with those requirements
return flags;
}
- if (flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) {
+ if ((flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) != 0) {
// Remove host cached bit in case it's not supported
return MemoryPropertyFlags(type_mask, flags & ~VK_MEMORY_PROPERTY_HOST_CACHED_BIT);
}
- if (flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
+ if ((flags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) != 0) {
// Remove device local, if it's not supported by the requested resource
return MemoryPropertyFlags(type_mask, flags & ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
}
@@ -302,7 +317,7 @@ VkMemoryPropertyFlags MemoryAllocator::MemoryPropertyFlags(u32 type_mask,
std::optional<u32> MemoryAllocator::FindType(VkMemoryPropertyFlags flags, u32 type_mask) const {
for (u32 type_index = 0; type_index < properties.memoryTypeCount; ++type_index) {
const VkMemoryPropertyFlags type_flags = properties.memoryTypes[type_index].propertyFlags;
- if ((type_mask & (1U << type_index)) && (type_flags & flags)) {
+ if ((type_mask & (1U << type_index)) != 0 && (type_flags & flags) == flags) {
// The type matches in type and in the wanted properties.
return type_index;
}
diff --git a/src/video_core/vulkan_common/vulkan_memory_allocator.h b/src/video_core/vulkan_common/vulkan_memory_allocator.h
index d1ce29450..db12d02f4 100644
--- a/src/video_core/vulkan_common/vulkan_memory_allocator.h
+++ b/src/video_core/vulkan_common/vulkan_memory_allocator.h
@@ -101,16 +101,13 @@ public:
MemoryCommit Commit(const vk::Image& image, MemoryUsage usage);
private:
- /// Allocates a chunk of memory.
- void AllocMemory(VkMemoryPropertyFlags flags, u32 type_mask, u64 size);
+ /// Tries to allocate a chunk of memory.
+ bool TryAllocMemory(VkMemoryPropertyFlags flags, u32 type_mask, u64 size);
/// Tries to allocate a memory commit.
std::optional<MemoryCommit> TryCommit(const VkMemoryRequirements& requirements,
VkMemoryPropertyFlags flags);
- /// Returns the fastest compatible memory property flags from a wanted usage.
- VkMemoryPropertyFlags MemoryPropertyFlags(u32 type_mask, MemoryUsage usage) const;
-
/// Returns the fastest compatible memory property flags from the wanted flags.
VkMemoryPropertyFlags MemoryPropertyFlags(u32 type_mask, VkMemoryPropertyFlags flags) const;