From 4d159efef560a375a1a1e1c9fc3708124b32e000 Mon Sep 17 00:00:00 2001 From: DrChat Date: Tue, 19 Dec 2017 16:37:59 -0600 Subject: [PATCH] [GPU] Run TraceDump headless, and drop the GL4 trace dumper --- src/xenia/gpu/gl4/gl4_trace_dump_main.cc | 40 ------- src/xenia/gpu/gl4/premake5.lua | 51 +-------- src/xenia/gpu/trace_dump.cc | 129 ++++------------------- 3 files changed, 23 insertions(+), 197 deletions(-) delete mode 100644 src/xenia/gpu/gl4/gl4_trace_dump_main.cc diff --git a/src/xenia/gpu/gl4/gl4_trace_dump_main.cc b/src/xenia/gpu/gl4/gl4_trace_dump_main.cc deleted file mode 100644 index 18f873e66..000000000 --- a/src/xenia/gpu/gl4/gl4_trace_dump_main.cc +++ /dev/null @@ -1,40 +0,0 @@ -/** - ****************************************************************************** - * Xenia : Xbox 360 Emulator Research Project * - ****************************************************************************** - * Copyright 2015 Ben Vanik. All rights reserved. * - * Released under the BSD license - see LICENSE in the root for more details. * - ****************************************************************************** - */ - -#include "xenia/base/logging.h" -#include "xenia/base/main.h" -#include "xenia/gpu/gl4/gl4_command_processor.h" -#include "xenia/gpu/gl4/gl4_graphics_system.h" -#include "xenia/gpu/trace_dump.h" - -namespace xe { -namespace gpu { -namespace gl4 { - -using namespace xe::gpu::xenos; - -class GL4TraceDump : public TraceDump { - public: - std::unique_ptr CreateGraphicsSystem() override { - return std::unique_ptr(new GL4GraphicsSystem()); - } -}; - -int trace_dump_main(const std::vector& args) { - GL4TraceDump trace_dump; - return trace_dump.Main(args); -} - -} // namespace gl4 -} // namespace gpu -} // namespace xe - -DEFINE_ENTRY_POINT(L"xenia-gpu-gl4-trace-dump", - L"xenia-gpu-gl4-trace-dump some.trace", - xe::gpu::gl4::trace_dump_main); diff --git a/src/xenia/gpu/gl4/premake5.lua b/src/xenia/gpu/gl4/premake5.lua index 2786de17b..64fb97d78 100644 --- a/src/xenia/gpu/gl4/premake5.lua +++ b/src/xenia/gpu/gl4/premake5.lua @@ -76,53 +76,4 @@ project("xenia-gpu-gl4-trace-viewer") "1>scratch/stdout-trace-viewer.txt", }) end - -group("src") -project("xenia-gpu-gl4-trace-dump") - uuid("5d47299d-f37d-46b4-af48-f4e54b9e5662") - kind("ConsoleApp") - language("C++") - links({ - "gflags", - "glew", - "imgui", - "xenia-apu", - "xenia-apu-nop", - "xenia-apu-xaudio2", - "xenia-base", - "xenia-core", - "xenia-cpu", - "xenia-cpu-backend-x64", - "xenia-gpu", - "xenia-gpu-gl4", - "xenia-hid-nop", - "xenia-hid-winkey", - "xenia-hid-xinput", - "xenia-kernel", - "xenia-ui", - "xenia-ui-gl", - "xenia-vfs", - }) - defines({ - "GLEW_STATIC=1", - "GLEW_MX=1", - }) - includedirs({ - project_root.."/third_party/gflags/src", - }) - files({ - "gl4_trace_dump_main.cc", - "../../base/main_"..platform_suffix..".cc", - }) - - filter("platforms:Windows") - -- Only create the .user file if it doesn't already exist. - local user_file = project_root.."/build/xenia-gpu-gl4-trace-dump.vcxproj.user" - if not os.isfile(user_file) then - debugdir(project_root) - debugargs({ - "--flagfile=scratch/flags.txt", - "2>&1", - "1>scratch/stdout-trace-dump.txt", - }) - end + \ No newline at end of file diff --git a/src/xenia/gpu/trace_dump.cc b/src/xenia/gpu/trace_dump.cc index 58f32af2b..eb826bd19 100644 --- a/src/xenia/gpu/trace_dump.cc +++ b/src/xenia/gpu/trace_dump.cc @@ -56,28 +56,11 @@ int TraceDump::Main(const std::vector& args) { if (args.size() >= 3) { output_path = args[2]; } - } else { - // Open a file chooser and ask the user. - auto file_picker = xe::ui::FilePicker::Create(); - file_picker->set_mode(ui::FilePicker::Mode::kOpen); - file_picker->set_type(ui::FilePicker::Type::kFile); - file_picker->set_multi_selection(false); - file_picker->set_title(L"Select Trace File"); - file_picker->set_extensions({ - {L"Supported Files", L"*.xtr"}, - {L"All Files (*.*)", L"*.*"}, - }); - if (file_picker->Show()) { - auto selected_files = file_picker->selected_files(); - if (!selected_files.empty()) { - path = selected_files[0]; - } - } } if (path.empty()) { - xe::FatalError("No trace file specified"); - return 1; + XELOGE("No trace file specified"); + return 5; } // Normalize the path and make absolute. @@ -85,12 +68,12 @@ int TraceDump::Main(const std::vector& args) { XELOGI("Loading trace file %ls...", abs_path.c_str()); if (!Setup()) { - xe::FatalError("Unable to setup trace dump tool"); - return 1; + XELOGE("Unable to setup trace dump tool"); + return 4; } if (!Load(std::move(abs_path))) { - xe::FatalError("Unable to load trace file; not found?"); - return 1; + XELOGE("Unable to load trace file; not found?"); + return 5; } // Root file name for outputs. @@ -119,43 +102,16 @@ int TraceDump::Main(const std::vector& args) { } bool TraceDump::Setup() { - // Main display window. - loop_ = ui::Loop::Create(); - window_ = xe::ui::Window::Create(loop_.get(), L"xenia-gpu-trace-dump"); - loop_->PostSynchronous([&]() { - xe::threading::set_name("Win32 Loop"); - if (!window_->Initialize()) { - xe::FatalError("Failed to initialize main window"); - return; - } - }); - window_->on_closed.AddListener([&](xe::ui::UIEvent* e) { - loop_->Quit(); - XELOGI("User-initiated death!"); - exit(1); - }); - loop_->on_quit.AddListener([&](xe::ui::UIEvent* e) { window_.reset(); }); - window_->Resize(1280, 720); - // Create the emulator but don't initialize so we can setup the window. emulator_ = std::make_unique(L""); - X_STATUS result = - emulator_->Setup(window_.get(), nullptr, - [this]() { return CreateGraphicsSystem(); }, nullptr); + X_STATUS result = emulator_->Setup( + nullptr, nullptr, [this]() { return CreateGraphicsSystem(); }, nullptr); if (XFAILED(result)) { XELOGE("Failed to setup emulator: %.8X", result); return false; } memory_ = emulator_->memory(); graphics_system_ = emulator_->graphics_system(); - - window_->on_key_char.AddListener([&](xe::ui::KeyEvent* e) { - if (e->key_code() == 0x74 /* VK_F5 */) { - graphics_system_->ClearCaches(); - e->set_handled(true); - } - }); - player_ = std::make_unique(loop_.get(), graphics_system_); return true; } @@ -172,67 +128,26 @@ bool TraceDump::Load(std::wstring trace_file_path) { } int TraceDump::Run() { - loop_->PostSynchronous([&]() { - player_->SeekFrame(0); - player_->SeekCommand( - static_cast(player_->current_frame()->commands.size() - 1)); - }); - - auto file_name = xe::find_name_from_path(trace_file_path_); - std::wstring title = std::wstring(L"Xenia GPU Trace Dump: ") + file_name; - while (player_->is_playing_trace()) { - // Update titlebar status. - if (player_->is_playing_trace()) { - int percent = - static_cast(player_->playback_percent() / 10000.0 * 100.0); - window_->set_title(title + xe::format_string(L" (%d%%)", percent)); - } - - xe::threading::Sleep(std::chrono::milliseconds(1)); - } - - window_->set_title(title); + player_->SeekFrame(0); + player_->SeekCommand( + static_cast(player_->current_frame()->commands.size() - 1)); player_->WaitOnPlayback(); - xe::threading::Fence capture_fence; + // Capture. int result = 0; - loop_->PostDelayed( - [&]() { - // Capture. - auto raw_image = graphics_system_->Capture(); - if (!raw_image) { - // Failed to capture anything. - result = -1; - capture_fence.Signal(); - return; - } + auto raw_image = graphics_system_->Capture(); + if (raw_image) { + // Save framebuffer png. + std::string png_path = xe::to_string(base_output_path_ + L".png"); + stbi_write_png(png_path.c_str(), static_cast(raw_image->width), + static_cast(raw_image->height), 4, + raw_image->data.data(), static_cast(raw_image->stride)); + } else { + result = 1; + } - // Save framebuffer png. - std::string png_path = xe::to_string(base_output_path_ + L".png"); - stbi_write_png(png_path.c_str(), static_cast(raw_image->width), - static_cast(raw_image->height), 4, - raw_image->data.data(), - static_cast(raw_image->stride)); - - result = 0; - capture_fence.Signal(); - }, - 50); - - capture_fence.Wait(); - - // Profiler must exit before the window is closed. - Profiler::Shutdown(); - - // Wait until we are exited. - loop_->Quit(); - loop_->AwaitQuit(); - - window_.reset(); - loop_.reset(); player_.reset(); emulator_.reset(); - return result; }