From 25663827ba57005d7a388b1a69d73200a83601eb Mon Sep 17 00:00:00 2001 From: Triang3l Date: Sun, 17 Jul 2022 16:37:49 +0300 Subject: [PATCH] [GPU] Trace viewer Android content URI loading --- src/xenia/gpu/trace_dump.cc | 3 ++- src/xenia/gpu/trace_reader.cc | 14 ++++++++++++-- src/xenia/gpu/trace_reader.h | 4 ++-- src/xenia/gpu/trace_viewer.cc | 25 +++++++++++++++---------- src/xenia/gpu/trace_viewer.h | 4 ++-- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/xenia/gpu/trace_dump.cc b/src/xenia/gpu/trace_dump.cc index ec4e85cea..4cf774c42 100644 --- a/src/xenia/gpu/trace_dump.cc +++ b/src/xenia/gpu/trace_dump.cc @@ -10,6 +10,7 @@ #include "xenia/gpu/trace_dump.h" #include "third_party/stb/stb_image_write.h" +#include "xenia/base/filesystem.h" #include "xenia/base/logging.h" #include "xenia/base/profiling.h" #include "xenia/base/string.h" @@ -109,7 +110,7 @@ bool TraceDump::Setup() { bool TraceDump::Load(const std::filesystem::path& trace_file_path) { trace_file_path_ = trace_file_path; - if (!player_->Open(trace_file_path_)) { + if (!player_->Open(xe::path_to_utf8(trace_file_path_))) { XELOGE("Could not load trace file"); return false; } diff --git a/src/xenia/gpu/trace_reader.cc b/src/xenia/gpu/trace_reader.cc index 6c20c79ec..5d535ad8a 100644 --- a/src/xenia/gpu/trace_reader.cc +++ b/src/xenia/gpu/trace_reader.cc @@ -16,6 +16,7 @@ #include "xenia/base/logging.h" #include "xenia/base/mapped_memory.h" #include "xenia/base/math.h" +#include "xenia/base/platform.h" #include "xenia/gpu/packet_disassembler.h" #include "xenia/gpu/trace_protocol.h" #include "xenia/memory.h" @@ -23,10 +24,19 @@ namespace xe { namespace gpu { -bool TraceReader::Open(const std::filesystem::path& path) { +bool TraceReader::Open(const std::string_view path) { Close(); - mmap_ = MappedMemory::Open(path, MappedMemory::Mode::kRead); + mmap_.reset(); +#if XE_PLATFORM_ANDROID + if (xe::filesystem::IsAndroidContentUri(path)) { + mmap_ = + MappedMemory::OpenForAndroidContentUri(path, MappedMemory::Mode::kRead); + } +#endif // XE_PLATFORM_ANDROID + if (!mmap_) { + mmap_ = MappedMemory::Open(xe::to_path(path), MappedMemory::Mode::kRead); + } if (!mmap_) { return false; } diff --git a/src/xenia/gpu/trace_reader.h b/src/xenia/gpu/trace_reader.h index 7ee65a283..d021915d9 100644 --- a/src/xenia/gpu/trace_reader.h +++ b/src/xenia/gpu/trace_reader.h @@ -10,7 +10,7 @@ #ifndef XENIA_GPU_TRACE_READER_H_ #define XENIA_GPU_TRACE_READER_H_ -#include +#include #include #include "xenia/base/mapped_memory.h" @@ -99,7 +99,7 @@ class TraceReader { const Frame* frame(int n) const { return &frames_[n]; } int frame_count() const { return int(frames_.size()); } - bool Open(const std::filesystem::path& path); + bool Open(const std::string_view path); void Close(); diff --git a/src/xenia/gpu/trace_viewer.cc b/src/xenia/gpu/trace_viewer.cc index 7485dd6b0..5d5978fd1 100644 --- a/src/xenia/gpu/trace_viewer.cc +++ b/src/xenia/gpu/trace_viewer.cc @@ -10,13 +10,16 @@ #include "xenia/gpu/trace_viewer.h" #include +#include #include "third_party/half/include/half.hpp" #include "third_party/imgui/imgui.h" #include "xenia/base/assert.h" #include "xenia/base/clock.h" +#include "xenia/base/filesystem.h" #include "xenia/base/logging.h" #include "xenia/base/math.h" +#include "xenia/base/platform.h" #include "xenia/base/string.h" #include "xenia/base/system.h" #include "xenia/base/threading.h" @@ -38,7 +41,8 @@ #include "xenia/ui/windowed_app_context.h" #include "xenia/xbox.h" -DEFINE_path(target_trace_file, "", "Specifies the trace file to load.", "GPU"); +DEFINE_string(target_trace_file, "", "Specifies the trace file to load.", + "GPU"); namespace xe { namespace gpu { @@ -62,9 +66,13 @@ TraceViewer::TraceViewer(xe::ui::WindowedAppContext& app_context, TraceViewer::~TraceViewer() = default; bool TraceViewer::OnInitialize() { - std::filesystem::path path = cvars::target_trace_file; + std::string path = cvars::target_trace_file; // If no path passed, ask the user. + // On Android, however, there's no synchronous file picker, and the trace file + // must be picked externally and provided to the trace viewer activity via the + // intent. +#if !XE_PLATFORM_ANDROID if (path.empty()) { auto file_picker = xe::ui::FilePicker::Create(); file_picker->set_mode(ui::FilePicker::Mode::kOpen); @@ -78,10 +86,11 @@ bool TraceViewer::OnInitialize() { if (file_picker->Show()) { auto selected_files = file_picker->selected_files(); if (!selected_files.empty()) { - path = selected_files[0]; + path = xe::path_to_utf8(selected_files[0]); } } } +#endif // !XE_PLATFORM_ANDROID if (path.empty()) { xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Warning, @@ -89,15 +98,12 @@ bool TraceViewer::OnInitialize() { return false; } - // Normalize the path and make absolute. - auto abs_path = std::filesystem::absolute(path); - if (!Setup()) { xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Error, "Unable to setup trace viewer"); return false; } - if (!Load(std::move(abs_path))) { + if (!Load(path)) { xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Error, "Unable to load trace file; not found?"); return false; @@ -179,9 +185,8 @@ void TraceViewer::TraceViewerDialog::OnDraw(ImGuiIO& io) { trace_viewer_.DrawUI(); } -bool TraceViewer::Load(const std::filesystem::path& trace_file_path) { - auto file_name = trace_file_path.filename(); - window_->SetTitle("Xenia GPU Trace Viewer: " + xe::path_to_utf8(file_name)); +bool TraceViewer::Load(const std::string_view trace_file_path) { + window_->SetTitle("Xenia GPU Trace Viewer: " + std::string(trace_file_path)); if (!player_->Open(trace_file_path)) { XELOGE("Could not load trace file"); diff --git a/src/xenia/gpu/trace_viewer.h b/src/xenia/gpu/trace_viewer.h index 8ef0e9b86..b41b18aca 100644 --- a/src/xenia/gpu/trace_viewer.h +++ b/src/xenia/gpu/trace_viewer.h @@ -10,7 +10,7 @@ #ifndef XENIA_GPU_TRACE_VIEWER_H_ #define XENIA_GPU_TRACE_VIEWER_H_ -#include +#include #include "xenia/emulator.h" #include "xenia/gpu/shader.h" @@ -95,7 +95,7 @@ class TraceViewer : public xe::ui::WindowedApp { kHostDisasm, }; - bool Load(const std::filesystem::path& trace_file_path); + bool Load(const std::string_view trace_file_path); void DrawUI(); void DrawControllerUI();