[GPU] Trace viewer Android content URI loading

This commit is contained in:
Triang3l 2022-07-17 16:37:49 +03:00
parent 624f2b2d9e
commit 25663827ba
5 changed files with 33 additions and 17 deletions

View File

@ -10,6 +10,7 @@
#include "xenia/gpu/trace_dump.h" #include "xenia/gpu/trace_dump.h"
#include "third_party/stb/stb_image_write.h" #include "third_party/stb/stb_image_write.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/logging.h" #include "xenia/base/logging.h"
#include "xenia/base/profiling.h" #include "xenia/base/profiling.h"
#include "xenia/base/string.h" #include "xenia/base/string.h"
@ -109,7 +110,7 @@ bool TraceDump::Setup() {
bool TraceDump::Load(const std::filesystem::path& trace_file_path) { bool TraceDump::Load(const std::filesystem::path& trace_file_path) {
trace_file_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"); XELOGE("Could not load trace file");
return false; return false;
} }

View File

@ -16,6 +16,7 @@
#include "xenia/base/logging.h" #include "xenia/base/logging.h"
#include "xenia/base/mapped_memory.h" #include "xenia/base/mapped_memory.h"
#include "xenia/base/math.h" #include "xenia/base/math.h"
#include "xenia/base/platform.h"
#include "xenia/gpu/packet_disassembler.h" #include "xenia/gpu/packet_disassembler.h"
#include "xenia/gpu/trace_protocol.h" #include "xenia/gpu/trace_protocol.h"
#include "xenia/memory.h" #include "xenia/memory.h"
@ -23,10 +24,19 @@
namespace xe { namespace xe {
namespace gpu { namespace gpu {
bool TraceReader::Open(const std::filesystem::path& path) { bool TraceReader::Open(const std::string_view path) {
Close(); 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_) { if (!mmap_) {
return false; return false;
} }

View File

@ -10,7 +10,7 @@
#ifndef XENIA_GPU_TRACE_READER_H_ #ifndef XENIA_GPU_TRACE_READER_H_
#define XENIA_GPU_TRACE_READER_H_ #define XENIA_GPU_TRACE_READER_H_
#include <string> #include <string_view>
#include <vector> #include <vector>
#include "xenia/base/mapped_memory.h" #include "xenia/base/mapped_memory.h"
@ -99,7 +99,7 @@ class TraceReader {
const Frame* frame(int n) const { return &frames_[n]; } const Frame* frame(int n) const { return &frames_[n]; }
int frame_count() const { return int(frames_.size()); } int frame_count() const { return int(frames_.size()); }
bool Open(const std::filesystem::path& path); bool Open(const std::string_view path);
void Close(); void Close();

View File

@ -10,13 +10,16 @@
#include "xenia/gpu/trace_viewer.h" #include "xenia/gpu/trace_viewer.h"
#include <cinttypes> #include <cinttypes>
#include <string>
#include "third_party/half/include/half.hpp" #include "third_party/half/include/half.hpp"
#include "third_party/imgui/imgui.h" #include "third_party/imgui/imgui.h"
#include "xenia/base/assert.h" #include "xenia/base/assert.h"
#include "xenia/base/clock.h" #include "xenia/base/clock.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/logging.h" #include "xenia/base/logging.h"
#include "xenia/base/math.h" #include "xenia/base/math.h"
#include "xenia/base/platform.h"
#include "xenia/base/string.h" #include "xenia/base/string.h"
#include "xenia/base/system.h" #include "xenia/base/system.h"
#include "xenia/base/threading.h" #include "xenia/base/threading.h"
@ -38,7 +41,8 @@
#include "xenia/ui/windowed_app_context.h" #include "xenia/ui/windowed_app_context.h"
#include "xenia/xbox.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 xe {
namespace gpu { namespace gpu {
@ -62,9 +66,13 @@ TraceViewer::TraceViewer(xe::ui::WindowedAppContext& app_context,
TraceViewer::~TraceViewer() = default; TraceViewer::~TraceViewer() = default;
bool TraceViewer::OnInitialize() { 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. // 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()) { if (path.empty()) {
auto file_picker = xe::ui::FilePicker::Create(); auto file_picker = xe::ui::FilePicker::Create();
file_picker->set_mode(ui::FilePicker::Mode::kOpen); file_picker->set_mode(ui::FilePicker::Mode::kOpen);
@ -78,10 +86,11 @@ bool TraceViewer::OnInitialize() {
if (file_picker->Show()) { if (file_picker->Show()) {
auto selected_files = file_picker->selected_files(); auto selected_files = file_picker->selected_files();
if (!selected_files.empty()) { if (!selected_files.empty()) {
path = selected_files[0]; path = xe::path_to_utf8(selected_files[0]);
} }
} }
} }
#endif // !XE_PLATFORM_ANDROID
if (path.empty()) { if (path.empty()) {
xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Warning, xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Warning,
@ -89,15 +98,12 @@ bool TraceViewer::OnInitialize() {
return false; return false;
} }
// Normalize the path and make absolute.
auto abs_path = std::filesystem::absolute(path);
if (!Setup()) { if (!Setup()) {
xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Error, xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Error,
"Unable to setup trace viewer"); "Unable to setup trace viewer");
return false; return false;
} }
if (!Load(std::move(abs_path))) { if (!Load(path)) {
xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Error, xe::ShowSimpleMessageBox(xe::SimpleMessageBoxType::Error,
"Unable to load trace file; not found?"); "Unable to load trace file; not found?");
return false; return false;
@ -179,9 +185,8 @@ void TraceViewer::TraceViewerDialog::OnDraw(ImGuiIO& io) {
trace_viewer_.DrawUI(); trace_viewer_.DrawUI();
} }
bool TraceViewer::Load(const std::filesystem::path& trace_file_path) { bool TraceViewer::Load(const std::string_view trace_file_path) {
auto file_name = trace_file_path.filename(); window_->SetTitle("Xenia GPU Trace Viewer: " + std::string(trace_file_path));
window_->SetTitle("Xenia GPU Trace Viewer: " + xe::path_to_utf8(file_name));
if (!player_->Open(trace_file_path)) { if (!player_->Open(trace_file_path)) {
XELOGE("Could not load trace file"); XELOGE("Could not load trace file");

View File

@ -10,7 +10,7 @@
#ifndef XENIA_GPU_TRACE_VIEWER_H_ #ifndef XENIA_GPU_TRACE_VIEWER_H_
#define XENIA_GPU_TRACE_VIEWER_H_ #define XENIA_GPU_TRACE_VIEWER_H_
#include <string> #include <string_view>
#include "xenia/emulator.h" #include "xenia/emulator.h"
#include "xenia/gpu/shader.h" #include "xenia/gpu/shader.h"
@ -95,7 +95,7 @@ class TraceViewer : public xe::ui::WindowedApp {
kHostDisasm, kHostDisasm,
}; };
bool Load(const std::filesystem::path& trace_file_path); bool Load(const std::string_view trace_file_path);
void DrawUI(); void DrawUI();
void DrawControllerUI(); void DrawControllerUI();