diff options
author | Mai M <mathew1800@gmail.com> | 2022-05-09 04:56:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-09 04:56:01 +0200 |
commit | 2123594ce2fb7d03b4a86967885d35204801bc49 (patch) | |
tree | 34262dd08e3a9c064b0d17294c459b6912aa5132 /src/video_core/macro | |
parent | Merge pull request #8319 from liamwhite/macro-warn (diff) | |
parent | VideoCore: Add option to dump the macros. (diff) | |
download | yuzu-2123594ce2fb7d03b4a86967885d35204801bc49.tar yuzu-2123594ce2fb7d03b4a86967885d35204801bc49.tar.gz yuzu-2123594ce2fb7d03b4a86967885d35204801bc49.tar.bz2 yuzu-2123594ce2fb7d03b4a86967885d35204801bc49.tar.lz yuzu-2123594ce2fb7d03b4a86967885d35204801bc49.tar.xz yuzu-2123594ce2fb7d03b4a86967885d35204801bc49.tar.zst yuzu-2123594ce2fb7d03b4a86967885d35204801bc49.zip |
Diffstat (limited to 'src/video_core/macro')
-rw-r--r-- | src/video_core/macro/macro.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/video_core/macro/macro.cpp b/src/video_core/macro/macro.cpp index a033d03be..86393c49c 100644 --- a/src/video_core/macro/macro.cpp +++ b/src/video_core/macro/macro.cpp @@ -2,11 +2,15 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include <cstring> +#include <fstream> #include <optional> +#include <span> #include <boost/container_hash/hash.hpp> #include "common/assert.h" +#include "common/fs/fs.h" +#include "common/fs/path_util.h" #include "common/settings.h" #include "video_core/macro/macro.h" #include "video_core/macro/macro_hle.h" @@ -15,6 +19,23 @@ namespace Tegra { +static void Dump(u64 hash, std::span<const u32> code) { + const auto base_dir{Common::FS::GetYuzuPath(Common::FS::YuzuPath::DumpDir)}; + const auto macro_dir{base_dir / "macros"}; + if (!Common::FS::CreateDir(base_dir) || !Common::FS::CreateDir(macro_dir)) { + LOG_ERROR(Common_Filesystem, "Failed to create macro dump directories"); + return; + } + const auto name{macro_dir / fmt::format("{:016x}.macro", hash)}; + std::fstream macro_file(name, std::ios::out | std::ios::binary); + if (!macro_file) { + LOG_ERROR(Common_Filesystem, "Unable to open or create file at {}", + Common::FS::PathToUTF8String(name)); + return; + } + macro_file.write(reinterpret_cast<const char*>(code.data()), code.size_bytes()); +} + MacroEngine::MacroEngine(Engines::Maxwell3D& maxwell3d) : hle_macros{std::make_unique<Tegra::HLEMacro>(maxwell3d)} {} @@ -54,6 +75,9 @@ void MacroEngine::Execute(u32 method, const std::vector<u32>& parameters) { if (!mid_method.has_value()) { cache_info.lle_program = Compile(macro_code->second); cache_info.hash = boost::hash_value(macro_code->second); + if (Settings::values.dump_macros) { + Dump(cache_info.hash, macro_code->second); + } } else { const auto& macro_cached = uploaded_macro_code[mid_method.value()]; const auto rebased_method = method - mid_method.value(); @@ -63,6 +87,9 @@ void MacroEngine::Execute(u32 method, const std::vector<u32>& parameters) { code.size() * sizeof(u32)); cache_info.hash = boost::hash_value(code); cache_info.lle_program = Compile(code); + if (Settings::values.dump_macros) { + Dump(cache_info.hash, code); + } } if (auto hle_program = hle_macros->GetHLEProgram(cache_info.hash)) { |