2013-01-11 09:23:08 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* Xenia : Xbox 360 Emulator Research Project *
|
|
|
|
******************************************************************************
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
* Copyright 2022 Ben Vanik. All rights reserved. *
|
2013-01-11 09:23:08 +00:00
|
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
#include <atomic>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <thread>
|
|
|
|
#include <vector>
|
|
|
|
|
2019-08-03 13:12:37 +00:00
|
|
|
#include "xenia/app/discord/discord_presence.h"
|
2015-07-17 08:15:12 +00:00
|
|
|
#include "xenia/app/emulator_window.h"
|
2022-02-24 21:37:32 +00:00
|
|
|
#include "xenia/base/assert.h"
|
2019-04-17 19:49:29 +00:00
|
|
|
#include "xenia/base/cvar.h"
|
2016-06-19 01:42:28 +00:00
|
|
|
#include "xenia/base/debugging.h"
|
2015-05-02 10:42:51 +00:00
|
|
|
#include "xenia/base/logging.h"
|
2021-08-28 16:38:24 +00:00
|
|
|
#include "xenia/base/platform.h"
|
2015-11-07 19:25:53 +00:00
|
|
|
#include "xenia/base/profiling.h"
|
2016-06-19 01:42:28 +00:00
|
|
|
#include "xenia/base/threading.h"
|
2019-04-17 19:49:47 +00:00
|
|
|
#include "xenia/config.h"
|
2015-09-21 04:31:05 +00:00
|
|
|
#include "xenia/debug/ui/debug_window.h"
|
2015-02-01 06:49:47 +00:00
|
|
|
#include "xenia/emulator.h"
|
2024-02-10 21:38:21 +00:00
|
|
|
#include "xenia/kernel/xam/xam_module.h"
|
2015-06-27 03:27:36 +00:00
|
|
|
#include "xenia/ui/file_picker.h"
|
2021-08-28 16:38:24 +00:00
|
|
|
#include "xenia/ui/window.h"
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
#include "xenia/ui/window_listener.h"
|
2021-08-28 16:38:24 +00:00
|
|
|
#include "xenia/ui/windowed_app.h"
|
|
|
|
#include "xenia/ui/windowed_app_context.h"
|
2018-05-23 09:33:39 +00:00
|
|
|
#include "xenia/vfs/devices/host_path_device.h"
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2015-11-08 23:02:24 +00:00
|
|
|
// Available audio systems:
|
|
|
|
#include "xenia/apu/nop/nop_audio_system.h"
|
2022-07-11 18:45:57 +00:00
|
|
|
#if !XE_PLATFORM_ANDROID
|
2019-10-27 23:18:43 +00:00
|
|
|
#include "xenia/apu/sdl/sdl_audio_system.h"
|
2022-07-11 18:45:57 +00:00
|
|
|
#endif // !XE_PLATFORM_ANDROID
|
2015-11-08 23:02:24 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
|
|
|
#include "xenia/apu/xaudio2/xaudio2_audio_system.h"
|
|
|
|
#endif // XE_PLATFORM_WIN32
|
|
|
|
|
|
|
|
// Available graphics systems:
|
2016-08-04 14:50:13 +00:00
|
|
|
#include "xenia/gpu/null/null_graphics_system.h"
|
2016-02-21 03:02:28 +00:00
|
|
|
#include "xenia/gpu/vulkan/vulkan_graphics_system.h"
|
2018-07-18 09:02:00 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
|
|
|
#include "xenia/gpu/d3d12/d3d12_graphics_system.h"
|
|
|
|
#endif // XE_PLATFORM_WIN32
|
2015-11-08 23:02:24 +00:00
|
|
|
|
|
|
|
// Available input drivers:
|
|
|
|
#include "xenia/hid/nop/nop_hid.h"
|
2022-07-11 18:45:57 +00:00
|
|
|
#if !XE_PLATFORM_ANDROID
|
2019-10-19 15:10:19 +00:00
|
|
|
#include "xenia/hid/sdl/sdl_hid.h"
|
2022-07-11 18:45:57 +00:00
|
|
|
#endif // !XE_PLATFORM_ANDROID
|
2015-11-08 23:02:24 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
|
|
|
#include "xenia/hid/winkey/winkey_hid.h"
|
|
|
|
#include "xenia/hid/xinput/xinput_hid.h"
|
|
|
|
#endif // XE_PLATFORM_WIN32
|
|
|
|
|
2019-10-27 23:18:43 +00:00
|
|
|
DEFINE_string(apu, "any", "Audio system. Use: [any, nop, sdl, xaudio2]", "APU");
|
2020-08-22 20:31:52 +00:00
|
|
|
DEFINE_string(gpu, "any", "Graphics system. Use: [any, d3d12, vulkan, null]",
|
|
|
|
"GPU");
|
2019-10-19 15:10:19 +00:00
|
|
|
DEFINE_string(hid, "any", "Input system. Use: [any, nop, sdl, winkey, xinput]",
|
2019-08-04 03:53:58 +00:00
|
|
|
"HID");
|
2015-11-08 23:02:24 +00:00
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
DEFINE_path(
|
2020-03-13 06:42:29 +00:00
|
|
|
storage_root, "",
|
|
|
|
"Root path for persistent internal data storage (config, etc.), or empty "
|
|
|
|
"to use the path preferred for the OS, such as the documents folder, or "
|
|
|
|
"the emulator executable directory if portable.txt is present in it.",
|
|
|
|
"Storage");
|
2020-03-02 15:37:11 +00:00
|
|
|
DEFINE_path(
|
2020-03-13 06:42:29 +00:00
|
|
|
content_root, "",
|
|
|
|
"Root path for guest content storage (saves, etc.), or empty to use the "
|
|
|
|
"content folder under the storage root.",
|
|
|
|
"Storage");
|
2020-12-07 19:23:54 +00:00
|
|
|
DEFINE_path(
|
|
|
|
cache_root, "",
|
|
|
|
"Root path for files used to speed up certain parts of the emulator or the "
|
|
|
|
"game. These files may be persistent, but they can be deleted without "
|
|
|
|
"major side effects such as progress loss. If empty, the cache folder "
|
|
|
|
"under the storage root, or, if available, the cache directory preferred "
|
|
|
|
"for the OS, will be used.",
|
|
|
|
"Storage");
|
2018-11-22 00:04:43 +00:00
|
|
|
|
2019-08-04 03:53:58 +00:00
|
|
|
DEFINE_bool(mount_scratch, false, "Enable scratch mount", "Storage");
|
2024-08-31 19:46:43 +00:00
|
|
|
|
|
|
|
DEFINE_bool(mount_cache, true, "Enable cache mount", "Storage");
|
|
|
|
UPDATE_from_bool(mount_cache, 2024, 8, 31, 20, false);
|
2019-04-17 19:49:29 +00:00
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
DEFINE_transient_path(target, "",
|
|
|
|
"Specifies the target .xex or .iso to execute.",
|
|
|
|
"General");
|
2022-08-31 17:01:19 +00:00
|
|
|
DEFINE_transient_bool(portable, true,
|
2020-08-07 21:04:53 +00:00
|
|
|
"Specifies if Xenia should run in portable mode.",
|
|
|
|
"General");
|
|
|
|
|
2019-04-17 19:49:29 +00:00
|
|
|
DECLARE_bool(debug);
|
2018-05-23 09:33:39 +00:00
|
|
|
|
2019-08-03 13:12:37 +00:00
|
|
|
DEFINE_bool(discord, true, "Enable Discord rich presence", "General");
|
|
|
|
|
2024-06-28 18:27:44 +00:00
|
|
|
DECLARE_bool(widescreen);
|
|
|
|
|
2014-12-21 06:17:57 +00:00
|
|
|
namespace xe {
|
2015-07-17 08:15:12 +00:00
|
|
|
namespace app {
|
2014-12-21 06:17:57 +00:00
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
class EmulatorApp final : public xe::ui::WindowedApp {
|
2019-08-03 22:01:34 +00:00
|
|
|
public:
|
2021-08-28 16:38:24 +00:00
|
|
|
static std::unique_ptr<xe::ui::WindowedApp> Create(
|
|
|
|
xe::ui::WindowedAppContext& app_context) {
|
|
|
|
return std::unique_ptr<xe::ui::WindowedApp>(new EmulatorApp(app_context));
|
2019-08-03 22:01:34 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
~EmulatorApp();
|
2019-08-03 21:42:38 +00:00
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
bool OnInitialize() override;
|
2019-08-03 22:01:34 +00:00
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
protected:
|
|
|
|
void OnDestroy() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <typename T, typename... Args>
|
|
|
|
class Factory {
|
|
|
|
private:
|
|
|
|
struct Creator {
|
|
|
|
std::string name;
|
|
|
|
std::function<bool()> is_available;
|
|
|
|
std::function<std::unique_ptr<T>(Args...)> instantiate;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<Creator> creators_;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Add(const std::string_view name, std::function<bool()> is_available,
|
|
|
|
std::function<std::unique_ptr<T>(Args...)> instantiate) {
|
|
|
|
creators_.push_back({std::string(name), is_available, instantiate});
|
|
|
|
}
|
|
|
|
|
|
|
|
void Add(const std::string_view name,
|
|
|
|
std::function<std::unique_ptr<T>(Args...)> instantiate) {
|
|
|
|
auto always_available = []() { return true; };
|
|
|
|
Add(name, always_available, instantiate);
|
2019-08-03 21:42:38 +00:00
|
|
|
}
|
2019-08-03 22:01:34 +00:00
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
template <typename DT>
|
|
|
|
void Add(const std::string_view name) {
|
|
|
|
Add(name, DT::IsAvailable, [](Args... args) {
|
|
|
|
return std::make_unique<DT>(std::forward<Args>(args)...);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<T> Create(const std::string_view name, Args... args) {
|
|
|
|
if (!name.empty() && name != "any") {
|
|
|
|
auto it = std::find_if(
|
|
|
|
creators_.cbegin(), creators_.cend(),
|
|
|
|
[&name](const auto& f) { return name.compare(f.name) == 0; });
|
|
|
|
if (it != creators_.cend() && (*it).is_available()) {
|
|
|
|
return (*it).instantiate(std::forward<Args>(args)...);
|
2019-08-03 22:01:34 +00:00
|
|
|
}
|
2021-08-28 16:38:24 +00:00
|
|
|
return nullptr;
|
|
|
|
} else {
|
|
|
|
for (const auto& creator : creators_) {
|
|
|
|
if (!creator.is_available()) continue;
|
|
|
|
auto instance = creator.instantiate(std::forward<Args>(args)...);
|
|
|
|
if (!instance) continue;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2019-08-03 22:01:34 +00:00
|
|
|
}
|
2021-08-28 16:38:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<T>> CreateAll(const std::string_view name,
|
|
|
|
Args... args) {
|
|
|
|
std::vector<std::unique_ptr<T>> instances;
|
|
|
|
if (!name.empty() && name != "any") {
|
|
|
|
auto it = std::find_if(
|
|
|
|
creators_.cbegin(), creators_.cend(),
|
|
|
|
[&name](const auto& f) { return name.compare(f.name) == 0; });
|
|
|
|
if (it != creators_.cend() && (*it).is_available()) {
|
|
|
|
auto instance = (*it).instantiate(std::forward<Args>(args)...);
|
|
|
|
if (instance) {
|
|
|
|
instances.emplace_back(std::move(instance));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (const auto& creator : creators_) {
|
|
|
|
if (!creator.is_available()) continue;
|
|
|
|
auto instance = creator.instantiate(std::forward<Args>(args)...);
|
|
|
|
if (instance) {
|
|
|
|
instances.emplace_back(std::move(instance));
|
|
|
|
}
|
2019-08-03 22:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-28 16:38:24 +00:00
|
|
|
return instances;
|
2019-08-03 22:01:34 +00:00
|
|
|
}
|
2021-08-28 16:38:24 +00:00
|
|
|
};
|
|
|
|
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
class DebugWindowClosedListener final : public xe::ui::WindowListener {
|
|
|
|
public:
|
|
|
|
explicit DebugWindowClosedListener(EmulatorApp& emulator_app)
|
|
|
|
: emulator_app_(emulator_app) {}
|
|
|
|
|
|
|
|
void OnClosing(xe::ui::UIEvent& e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
EmulatorApp& emulator_app_;
|
|
|
|
};
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
explicit EmulatorApp(xe::ui::WindowedAppContext& app_context);
|
|
|
|
|
|
|
|
static std::unique_ptr<apu::AudioSystem> CreateAudioSystem(
|
|
|
|
cpu::Processor* processor);
|
|
|
|
static std::unique_ptr<gpu::GraphicsSystem> CreateGraphicsSystem();
|
|
|
|
static std::vector<std::unique_ptr<hid::InputDriver>> CreateInputDrivers(
|
|
|
|
ui::Window* window);
|
|
|
|
|
|
|
|
void EmulatorThread();
|
|
|
|
void ShutdownEmulatorThreadFromUIThread();
|
|
|
|
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
DebugWindowClosedListener debug_window_closed_listener_;
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
std::unique_ptr<Emulator> emulator_;
|
|
|
|
std::unique_ptr<EmulatorWindow> emulator_window_;
|
|
|
|
|
|
|
|
// Created on demand, used by the emulator.
|
|
|
|
std::unique_ptr<xe::debug::ui::DebugWindow> debug_window_;
|
|
|
|
|
|
|
|
// Refreshing the emulator - placed after its dependencies.
|
|
|
|
std::atomic<bool> emulator_thread_quit_requested_;
|
|
|
|
std::unique_ptr<xe::threading::Event> emulator_thread_event_;
|
|
|
|
std::thread emulator_thread_;
|
2019-08-03 21:42:38 +00:00
|
|
|
};
|
|
|
|
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
void EmulatorApp::DebugWindowClosedListener::OnClosing(xe::ui::UIEvent& e) {
|
|
|
|
EmulatorApp* emulator_app = &emulator_app_;
|
|
|
|
emulator_app->emulator_->processor()->set_debug_listener(nullptr);
|
|
|
|
emulator_app->debug_window_.reset();
|
|
|
|
}
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
EmulatorApp::EmulatorApp(xe::ui::WindowedAppContext& app_context)
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
: xe::ui::WindowedApp(app_context, "xenia", "[Path to .iso/.xex]"),
|
|
|
|
debug_window_closed_listener_(*this) {
|
2021-08-28 16:38:24 +00:00
|
|
|
AddPositionalOption("target");
|
|
|
|
}
|
|
|
|
|
|
|
|
EmulatorApp::~EmulatorApp() {
|
|
|
|
// Should be shut down from OnDestroy if OnInitialize has ever been done, but
|
|
|
|
// for the most safety as a running thread may be destroyed only after
|
|
|
|
// joining.
|
|
|
|
ShutdownEmulatorThreadFromUIThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<apu::AudioSystem> EmulatorApp::CreateAudioSystem(
|
|
|
|
cpu::Processor* processor) {
|
2019-08-03 23:10:49 +00:00
|
|
|
Factory<apu::AudioSystem, cpu::Processor*> factory;
|
2015-11-08 23:02:24 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
2019-08-03 23:10:49 +00:00
|
|
|
factory.Add<apu::xaudio2::XAudio2AudioSystem>("xaudio2");
|
2015-11-08 23:02:24 +00:00
|
|
|
#endif // XE_PLATFORM_WIN32
|
2022-07-11 18:45:57 +00:00
|
|
|
#if !XE_PLATFORM_ANDROID
|
2019-10-27 23:18:43 +00:00
|
|
|
factory.Add<apu::sdl::SDLAudioSystem>("sdl");
|
2022-07-11 18:45:57 +00:00
|
|
|
#endif // !XE_PLATFORM_ANDROID
|
2019-08-03 23:10:49 +00:00
|
|
|
factory.Add<apu::nop::NopAudioSystem>("nop");
|
2019-08-03 22:01:34 +00:00
|
|
|
return factory.Create(cvars::apu, processor);
|
2015-11-08 23:02:24 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
std::unique_ptr<gpu::GraphicsSystem> EmulatorApp::CreateGraphicsSystem() {
|
2022-07-03 17:39:44 +00:00
|
|
|
// While Vulkan is supported by a large variety of operating systems (Windows,
|
|
|
|
// GNU/Linux, Android, also via the MoltenVK translation layer on top of Metal
|
|
|
|
// on macOS and iOS), please don't remove platform-specific GPU backends from
|
|
|
|
// Xenia.
|
|
|
|
//
|
|
|
|
// Regardless of the operating system, having multiple options provides more
|
|
|
|
// stability to users. In case of driver issues, users may try switching
|
|
|
|
// between the available backends. For example, in June 2022, on Nvidia Ampere
|
|
|
|
// (RTX 30xx), Xenia had synchronization issues that resulted in flickering,
|
|
|
|
// most prominently in 4D5307E6, on Direct3D 12 - but the same issue was not
|
|
|
|
// reproducible in the Vulkan backend, however, it used ImageSampleExplicitLod
|
|
|
|
// with explicit gradients for cubemaps, which triggered a different driver
|
|
|
|
// bug on Nvidia (every 1 out of 2x2 pixels receiving junk).
|
|
|
|
//
|
|
|
|
// Specifically on Microsoft platforms, there are a few reasons why supporting
|
|
|
|
// Direct3D 12 is desirable rather than limiting Xenia to Vulkan only:
|
|
|
|
// - Wider hardware support for Direct3D 12 on x86 Windows desktops.
|
|
|
|
// Direct3D 12 requires the minimum of Nvidia Fermi, or, with a pre-2021
|
|
|
|
// driver version, Intel HD Graphics 4200. Vulkan, however, is supported
|
|
|
|
// only starting with Nvidia Kepler and a much more recent Intel UHD
|
|
|
|
// Graphics generation.
|
|
|
|
// - Wider hardware support on other kinds of Microsoft devices. The Xbox One
|
|
|
|
// and the Xbox Series X|S only support Direct3D as the GPU API in their UWP
|
|
|
|
// runtime, and only version 12 can be granted expanded resource access.
|
|
|
|
// Qualcomm, as of June 2022, also doesn't provide a Vulkan implementation
|
|
|
|
// for their Arm-based Windows devices, while Direct3D 12 is available.
|
|
|
|
// - Both older Intel GPUs and the Xbox One apparently, as well as earlier
|
|
|
|
// Windows 10 versions, also require Shader Model 5.1 DXBC shaders rather
|
|
|
|
// than Shader Model 6 DXIL ones, so a DXBC shader translator should be
|
|
|
|
// available in Xenia too, a DXIL one doesn't fully replace it.
|
|
|
|
// - As of June 2022, AMD also refuses to implement the
|
|
|
|
// VK_EXT_fragment_shader_interlock Vulkan extension in their drivers, as
|
|
|
|
// well as its OpenGL counterpart, which is heavily utilized for accurate
|
|
|
|
// support of Xenos render target formats that don't have PC equivalents
|
|
|
|
// (8_8_8_8_GAMMA, 2_10_10_10_FLOAT, 16_16 and 16_16_16_16 with -32 to 32
|
|
|
|
// range, D24FS8) with correct blending. Direct3D 12, however, requires
|
|
|
|
// support for similar functionality (rasterizer-ordered views) on the
|
|
|
|
// feature level 12_1, and the AMD driver implements it on Direct3D, as well
|
|
|
|
// as raster order groups in their Metal driver.
|
|
|
|
//
|
|
|
|
// Additionally, different host GPU APIs receive feature support at different
|
|
|
|
// paces. VK_EXT_fragment_shader_interlock first appeared in 2019, for
|
|
|
|
// instance, while Xenia had been taking advantage of rasterizer-ordered views
|
|
|
|
// on Direct3D 12 for over half a year at that point (they have existed in
|
|
|
|
// Direct3D 12 since the first version).
|
|
|
|
//
|
|
|
|
// MoltenVK on top Metal also has its flaws and limitations. Metal, for
|
|
|
|
// instance, as of June 2022, doesn't provide a switch for primitive restart,
|
|
|
|
// while Vulkan does - so MoltenVK is not completely transparent to Xenia,
|
|
|
|
// many of its issues that may be not very obvious (unlike when the Metal API
|
|
|
|
// is used directly) should be taken into account in Xenia. Also, as of June
|
|
|
|
// 2022, MoltenVK translates SPIR-V shaders into the C++-based Metal Shading
|
|
|
|
// Language rather than AIR directly, which likely massively increases
|
|
|
|
// pipeline object creation time - and Xenia translates shaders and creates
|
|
|
|
// pipelines when they're first actually used for a draw command by the game,
|
|
|
|
// thus it can't precompile anything that hasn't ever been encountered before
|
|
|
|
// there's already no time to waste.
|
|
|
|
//
|
|
|
|
// Very old hardware (Direct3D 10 level) is also not supported by most Vulkan
|
|
|
|
// drivers. However, in the future, Xenia may be ported to it using the
|
|
|
|
// Direct3D 11 API with the feature level 10_1 or 10_0. OpenGL, however, had
|
|
|
|
// been lagging behind Direct3D prior to versions 4.x, and didn't receive
|
|
|
|
// compute shaders until a 4.2 extension (while 4.2 already corresponds
|
|
|
|
// roughly to Direct3D 11 features) - and replacing Xenia compute shaders with
|
|
|
|
// transform feedback / stream output is not always trivial (in particular,
|
|
|
|
// will need to rely on GL_ARB_transform_feedback3 for skipping over memory
|
|
|
|
// locations that shouldn't be overwritten).
|
|
|
|
//
|
|
|
|
// For maintainability, as much implementation code as possible should be
|
|
|
|
// placed in `xe::gpu` and shared between the backends rather than duplicated
|
|
|
|
// between them.
|
2019-08-03 23:10:49 +00:00
|
|
|
Factory<gpu::GraphicsSystem> factory;
|
2018-07-18 09:02:00 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
2019-08-03 23:10:49 +00:00
|
|
|
factory.Add<gpu::d3d12::D3D12GraphicsSystem>("d3d12");
|
2018-07-18 09:02:00 +00:00
|
|
|
#endif // XE_PLATFORM_WIN32
|
2022-07-03 16:49:11 +00:00
|
|
|
factory.Add<gpu::vulkan::VulkanGraphicsSystem>("vulkan");
|
2019-08-03 23:10:49 +00:00
|
|
|
factory.Add<gpu::null::NullGraphicsSystem>("null");
|
2019-08-03 22:01:34 +00:00
|
|
|
return factory.Create(cvars::gpu);
|
2015-11-08 23:02:24 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
std::vector<std::unique_ptr<hid::InputDriver>> EmulatorApp::CreateInputDrivers(
|
2015-11-08 23:02:24 +00:00
|
|
|
ui::Window* window) {
|
2019-08-04 01:07:19 +00:00
|
|
|
std::vector<std::unique_ptr<hid::InputDriver>> drivers;
|
|
|
|
if (cvars::hid.compare("nop") == 0) {
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
drivers.emplace_back(
|
|
|
|
xe::hid::nop::Create(window, EmulatorWindow::kZOrderHidInput));
|
2019-08-04 01:07:19 +00:00
|
|
|
} else {
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
Factory<hid::InputDriver, ui::Window*, size_t> factory;
|
2015-11-08 23:02:24 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
2019-08-04 01:07:19 +00:00
|
|
|
factory.Add("xinput", xe::hid::xinput::Create);
|
2020-11-28 16:01:26 +00:00
|
|
|
#endif // XE_PLATFORM_WIN32
|
2022-07-11 18:45:57 +00:00
|
|
|
#if !XE_PLATFORM_ANDROID
|
2020-11-28 16:01:26 +00:00
|
|
|
factory.Add("sdl", xe::hid::sdl::Create);
|
2022-07-11 18:45:57 +00:00
|
|
|
#endif // !XE_PLATFORM_ANDROID
|
2020-11-28 16:01:26 +00:00
|
|
|
#if XE_PLATFORM_WIN32
|
2019-08-04 01:47:39 +00:00
|
|
|
// WinKey input driver should always be the last input driver added!
|
|
|
|
factory.Add("winkey", xe::hid::winkey::Create);
|
2015-11-08 23:02:24 +00:00
|
|
|
#endif // XE_PLATFORM_WIN32
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
for (auto& driver : factory.CreateAll(cvars::hid, window,
|
|
|
|
EmulatorWindow::kZOrderHidInput)) {
|
2019-08-04 01:07:19 +00:00
|
|
|
if (XSUCCEEDED(driver->Setup())) {
|
|
|
|
drivers.emplace_back(std::move(driver));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (drivers.empty()) {
|
|
|
|
// Fallback to nop if none created.
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
drivers.emplace_back(
|
|
|
|
xe::hid::nop::Create(window, EmulatorWindow::kZOrderHidInput));
|
2015-11-08 23:02:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return drivers;
|
|
|
|
}
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
bool EmulatorApp::OnInitialize() {
|
use Sleep(0) instead of SwitchToThread, should waste less power and help the os with scheduling.
PM4 buffer handling made a virtual member of commandprocessor, place the implementation/declaration into reusable macro files. this is probably the biggest boost here.
Optimized SET_CONSTANT/ LOAD_CONSTANT pm4 ops based on the register range they start writing at, this was also a nice boost
Expose X64 extension flags to code outside of x64 backend, so we can detect and use things like avx512, xop, avx2, etc in normal code
Add freelists for HIR structures to try to reduce the number of last level cache misses during optimization (currently disabled... fixme later)
Analyzed PGO feedback and reordered branches, uninlined functions, moved code out into different functions based on info from it in the PM4 functions, this gave like a 2% boost at best.
Added support for the db16cyc opcode, which is used often in xb360 spinlocks. before it was just being translated to nop, now on x64 we translate it to _mm_pause but may change that in the future to reduce cpu time wasted
texture util - all our divisors were powers of 2, instead we look up a shift. this made texture scaling slightly faster, more so on intel processors which seem to be worse at int divs. GetGuestTextureLayout is now a little faster, although it is still one of the heaviest functions in the emulator when scaling is on.
xe_unlikely_mutex was not a good choice for the guest clock lock, (running theory) on intel processors another thread may take a significant time to update the clock? maybe because of the uint64 division? really not sure, but switched it to xe_mutex. This fixed audio stutter that i had introduced to 1 or 2 games, fixed performance on that n64 rare game with the monkeys.
Took another crack at DMA implementation, another failure.
Instead of passing as a parameter, keep the ringbuffer reader as the first member of commandprocessor so it can be accessed through this
Added macro for noalias
Applied noalias to Memory::LookupHeap. This reduced the size of the executable by 7 kb.
Reworked kernel shim template, this shaved like 100kb off the exe and eliminated the indirect calls from the shim to the actual implementation. We still unconditionally generate string representations of kernel calls though :(, unless it is kHighFrequency
Add nvapi extensions support, currently unused. Will use CPUVISIBLE memory at some point
Inserted prefetches in a few places based on feedback from vtune.
Add native implementation of SHA int8 if all elements are the same
Vectorized comparisons for SetViewport, SetScissorRect
Vectorized ranged comparisons for WriteRegister
Add XE_MSVC_ASSUME
Move FormatInfo::name out of the structure, instead look up the name in a different table. Debug related data and critical runtime data are best kept apart
Templated UpdateSystemConstantValues based on ROV/RTV and primitive_polygonal
Add ArchFloatMask functions, these are for storing the results of floating point comparisons without doing costly float->int pipeline transfers (vucomiss/setb)
Use floatmasks in UpdateSystemConstantValues for checking if dirty, only transfer to int at end of function.
Instead of dirty |= (x == y) in UpdateSystemConstantValues, now we do dirty_u32 |= (x^y). if any of them are not equal, dirty_u32 will be nz, else if theyre all equal it will be zero. This is more friendly to register renaming and the lack of dependencies on EFLAGS lets the compiler reorder better
Add PrefetchSamplerParameters to D3D12TextureCache
use PrefetchSamplerParameters in UpdateBindings to eliminate cache misses that vtune detected
Add PrefetchTextureBinding to D3D12TextureCache
Prefetch texture bindings to get rid of more misses vtune detected (more accesses out of order with random strides)
Rewrote DMAC, still terrible though and have disabled it for now.
Replace tiny memcmp of 6 U64 in render_target_cache with inline loop, msvc fails to make it a loop and instead does a thunk to their memcmp function, which is optimized for larger sizes
PrefetchTextureBinding in AreActiveTextureSRVKeysUpToDate
Replace memcmp calls for pipelinedescription with handwritten cmp
Directly write some registers that dont have special handling in PM4 functions
Changed EstimateMaxY to try to eliminate mispredictions that vtune was reporting, msvc ended up turning the changed code into a series of blends
in ExecutePacketType3_EVENT_WRITE_EXT, instead of writing extents to an array on the stack and then doing xe_copy_and_swap_16 of the data to its dest, pre-swap each constant and then store those. msvc manages to unroll that into wider stores
stop logging XE_SWAP every time we receive XE_SWAP, stop logging the start and end of each viz query
Prefetch watch nodes in FireWatches based on feedback from vtune
Removed dead code from texture_info.cc
NOINLINE on GpuSwap, PGO builds did it so we should too.
2022-09-11 21:14:48 +00:00
|
|
|
#if XE_ARCH_AMD64 == 1
|
|
|
|
amd64::InitFeatureFlags();
|
|
|
|
#endif
|
2014-05-28 20:59:43 +00:00
|
|
|
Profiler::Initialize();
|
2021-08-28 16:38:24 +00:00
|
|
|
Profiler::ThreadEnter("Main");
|
2014-05-28 05:54:40 +00:00
|
|
|
|
2020-03-13 06:42:29 +00:00
|
|
|
// Figure out where internal files and content should go.
|
2020-03-02 15:37:11 +00:00
|
|
|
std::filesystem::path storage_root = cvars::storage_root;
|
2020-03-13 06:42:29 +00:00
|
|
|
if (storage_root.empty()) {
|
|
|
|
storage_root = xe::filesystem::GetExecutableFolder();
|
2020-08-07 21:04:53 +00:00
|
|
|
if (!cvars::portable &&
|
|
|
|
!std::filesystem::exists(storage_root / "portable.txt")) {
|
2020-03-13 06:42:29 +00:00
|
|
|
storage_root = xe::filesystem::GetUserFolder();
|
2020-11-21 13:26:26 +00:00
|
|
|
#if defined(XE_PLATFORM_WIN32) || defined(XE_PLATFORM_GNU_LINUX)
|
2020-03-02 15:37:11 +00:00
|
|
|
storage_root = storage_root / "Xenia";
|
2018-11-22 00:04:43 +00:00
|
|
|
#else
|
2020-12-07 19:23:54 +00:00
|
|
|
// TODO(Triang3l): Point to the app's external storage "files" directory
|
|
|
|
// on Android.
|
2020-03-13 06:42:29 +00:00
|
|
|
#warning Unhandled platform for the data root.
|
2020-03-02 15:37:11 +00:00
|
|
|
storage_root = storage_root / "Xenia";
|
2018-11-22 00:04:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2020-03-02 15:37:11 +00:00
|
|
|
storage_root = std::filesystem::absolute(storage_root);
|
2024-12-13 18:04:31 +00:00
|
|
|
XELOGI("Storage root: {}", storage_root);
|
2019-04-17 19:49:47 +00:00
|
|
|
|
2020-03-13 06:42:29 +00:00
|
|
|
config::SetupConfig(storage_root);
|
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
std::filesystem::path content_root = cvars::content_root;
|
2020-03-13 06:42:29 +00:00
|
|
|
if (content_root.empty()) {
|
2020-03-02 15:37:11 +00:00
|
|
|
content_root = storage_root / "content";
|
2020-04-12 21:06:17 +00:00
|
|
|
} else {
|
|
|
|
// If content root isn't an absolute path, then it should be relative to the
|
|
|
|
// storage root.
|
|
|
|
if (!content_root.is_absolute()) {
|
|
|
|
content_root = storage_root / content_root;
|
|
|
|
}
|
2020-03-13 06:42:29 +00:00
|
|
|
}
|
2020-03-02 15:37:11 +00:00
|
|
|
content_root = std::filesystem::absolute(content_root);
|
2024-12-13 18:04:31 +00:00
|
|
|
XELOGI("Content root: {}", content_root);
|
2018-11-22 00:04:43 +00:00
|
|
|
|
2020-12-07 19:23:54 +00:00
|
|
|
std::filesystem::path cache_root = cvars::cache_root;
|
|
|
|
if (cache_root.empty()) {
|
2023-10-21 16:28:14 +00:00
|
|
|
cache_root = storage_root / "cache_host";
|
2020-12-07 19:23:54 +00:00
|
|
|
// TODO(Triang3l): Point to the app's external storage "cache" directory on
|
|
|
|
// Android.
|
|
|
|
} else {
|
|
|
|
// If content root isn't an absolute path, then it should be relative to the
|
|
|
|
// storage root.
|
|
|
|
if (!cache_root.is_absolute()) {
|
|
|
|
cache_root = storage_root / cache_root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cache_root = std::filesystem::absolute(cache_root);
|
2024-12-13 18:04:31 +00:00
|
|
|
XELOGI("Host cache root: {}", cache_root);
|
2020-12-07 19:23:54 +00:00
|
|
|
|
2019-09-08 21:02:04 +00:00
|
|
|
if (cvars::discord) {
|
|
|
|
discord::DiscordPresence::Initialize();
|
|
|
|
discord::DiscordPresence::NotPlaying();
|
|
|
|
}
|
|
|
|
|
2015-07-13 05:03:47 +00:00
|
|
|
// Create the emulator but don't initialize so we can setup the window.
|
2021-08-28 16:38:24 +00:00
|
|
|
emulator_ =
|
2020-12-07 19:23:54 +00:00
|
|
|
std::make_unique<Emulator>("", storage_root, content_root, cache_root);
|
2015-07-13 05:03:47 +00:00
|
|
|
|
2024-10-16 05:41:58 +00:00
|
|
|
// Determine window size based on user setting.
|
|
|
|
auto res = xe::gpu::GraphicsSystem::GetInternalDisplayResolution();
|
2024-06-28 18:27:44 +00:00
|
|
|
|
2015-07-13 05:03:47 +00:00
|
|
|
// Main emulator display window.
|
2024-06-28 18:27:44 +00:00
|
|
|
emulator_window_ = EmulatorWindow::Create(emulator_.get(), app_context(),
|
2024-10-16 05:41:58 +00:00
|
|
|
res.first, res.second);
|
2021-08-28 16:38:24 +00:00
|
|
|
if (!emulator_window_) {
|
|
|
|
XELOGE("Failed to create the main emulator window");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the emulator and run its loop in a separate thread.
|
|
|
|
emulator_thread_quit_requested_.store(false, std::memory_order_relaxed);
|
|
|
|
emulator_thread_event_ = xe::threading::Event::CreateAutoResetEvent(false);
|
2022-02-24 21:37:32 +00:00
|
|
|
assert_not_null(emulator_thread_event_);
|
2021-08-28 16:38:24 +00:00
|
|
|
emulator_thread_ = std::thread(&EmulatorApp::EmulatorThread, this);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmulatorApp::OnDestroy() {
|
|
|
|
ShutdownEmulatorThreadFromUIThread();
|
|
|
|
|
|
|
|
if (cvars::discord) {
|
|
|
|
discord::DiscordPresence::Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
Profiler::Dump();
|
|
|
|
// The profiler needs to shut down before the graphics context.
|
|
|
|
Profiler::Shutdown();
|
|
|
|
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
// Write all cvar overrides to the config.
|
|
|
|
config::SaveConfig();
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
// TODO(DrChat): Remove this code and do a proper exit.
|
|
|
|
XELOGI("Cheap-skate exit!");
|
|
|
|
std::quick_exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmulatorApp::EmulatorThread() {
|
|
|
|
assert_not_null(emulator_thread_event_);
|
|
|
|
|
|
|
|
xe::threading::set_name("Emulator");
|
|
|
|
Profiler::ThreadEnter("Emulator");
|
2015-07-13 05:03:47 +00:00
|
|
|
|
|
|
|
// Setup and initialize all subsystems. If we can't do something
|
|
|
|
// (unsupported system, memory issues, etc) this will fail early.
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
X_STATUS result = emulator_->Setup(
|
2022-07-06 20:28:06 +00:00
|
|
|
emulator_window_->window(), emulator_window_->imgui_drawer(), true,
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
CreateAudioSystem, CreateGraphicsSystem, CreateInputDrivers);
|
2013-10-24 03:42:24 +00:00
|
|
|
if (XFAILED(result)) {
|
2020-02-28 20:30:48 +00:00
|
|
|
XELOGE("Failed to setup emulator: {:08X}", result);
|
2021-08-28 16:38:24 +00:00
|
|
|
app_context().RequestDeferredQuit();
|
|
|
|
return;
|
2013-02-01 13:37:42 +00:00
|
|
|
}
|
|
|
|
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
app_context().CallInUIThread(
|
|
|
|
[this]() { emulator_window_->SetupGraphicsSystemPresenterPainting(); });
|
|
|
|
|
2019-04-17 19:49:29 +00:00
|
|
|
if (cvars::mount_scratch) {
|
2018-05-23 09:33:39 +00:00
|
|
|
auto scratch_device = std::make_unique<xe::vfs::HostPathDevice>(
|
2020-03-02 15:37:11 +00:00
|
|
|
"\\SCRATCH", "scratch", false);
|
2018-05-23 09:33:39 +00:00
|
|
|
if (!scratch_device->Initialize()) {
|
|
|
|
XELOGE("Unable to scan scratch path");
|
|
|
|
} else {
|
2021-08-28 16:38:24 +00:00
|
|
|
if (!emulator_->file_system()->RegisterDevice(
|
|
|
|
std::move(scratch_device))) {
|
2018-05-23 09:33:39 +00:00
|
|
|
XELOGE("Unable to register scratch path");
|
|
|
|
} else {
|
2021-08-28 16:38:24 +00:00
|
|
|
emulator_->file_system()->RegisterSymbolicLink("scratch:", "\\SCRATCH");
|
2018-05-23 09:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 19:49:29 +00:00
|
|
|
if (cvars::mount_cache) {
|
2018-05-23 09:33:39 +00:00
|
|
|
auto cache0_device =
|
2020-03-02 15:37:11 +00:00
|
|
|
std::make_unique<xe::vfs::HostPathDevice>("\\CACHE0", "cache0", false);
|
2018-05-23 09:33:39 +00:00
|
|
|
if (!cache0_device->Initialize()) {
|
|
|
|
XELOGE("Unable to scan cache0 path");
|
|
|
|
} else {
|
2021-08-28 16:38:24 +00:00
|
|
|
if (!emulator_->file_system()->RegisterDevice(std::move(cache0_device))) {
|
2018-05-23 09:33:39 +00:00
|
|
|
XELOGE("Unable to register cache0 path");
|
|
|
|
} else {
|
2021-08-28 16:38:24 +00:00
|
|
|
emulator_->file_system()->RegisterSymbolicLink("cache0:", "\\CACHE0");
|
2018-05-23 09:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto cache1_device =
|
2020-03-02 15:37:11 +00:00
|
|
|
std::make_unique<xe::vfs::HostPathDevice>("\\CACHE1", "cache1", false);
|
2018-05-23 09:33:39 +00:00
|
|
|
if (!cache1_device->Initialize()) {
|
|
|
|
XELOGE("Unable to scan cache1 path");
|
|
|
|
} else {
|
2021-08-28 16:38:24 +00:00
|
|
|
if (!emulator_->file_system()->RegisterDevice(std::move(cache1_device))) {
|
2018-05-23 09:33:39 +00:00
|
|
|
XELOGE("Unable to register cache1 path");
|
|
|
|
} else {
|
2021-08-28 16:38:24 +00:00
|
|
|
emulator_->file_system()->RegisterSymbolicLink("cache1:", "\\CACHE1");
|
2018-05-23 09:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-05 03:48:33 +00:00
|
|
|
|
|
|
|
// Some (older?) games try accessing cache:\ too
|
|
|
|
// NOTE: this must be registered _after_ the cache0/cache1 devices, due to
|
|
|
|
// substring/start_with logic inside VirtualFileSystem::ResolvePath, else
|
|
|
|
// accesses to those devices will go here instead
|
|
|
|
auto cache_device =
|
|
|
|
std::make_unique<xe::vfs::HostPathDevice>("\\CACHE", "cache", false);
|
|
|
|
if (!cache_device->Initialize()) {
|
|
|
|
XELOGE("Unable to scan cache path");
|
|
|
|
} else {
|
2021-08-28 16:38:24 +00:00
|
|
|
if (!emulator_->file_system()->RegisterDevice(std::move(cache_device))) {
|
2021-07-05 03:48:33 +00:00
|
|
|
XELOGE("Unable to register cache path");
|
|
|
|
} else {
|
2021-08-28 16:38:24 +00:00
|
|
|
emulator_->file_system()->RegisterSymbolicLink("cache:", "\\CACHE");
|
2021-07-05 03:48:33 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-23 09:33:39 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 04:31:05 +00:00
|
|
|
// Set a debug handler.
|
|
|
|
// This will respond to debugging requests so we can open the debug UI.
|
2019-04-17 19:49:29 +00:00
|
|
|
if (cvars::debug) {
|
2021-08-28 16:38:24 +00:00
|
|
|
emulator_->processor()->set_debug_listener_request_handler(
|
|
|
|
[this](xe::cpu::Processor* processor) {
|
|
|
|
if (debug_window_) {
|
|
|
|
return debug_window_.get();
|
2017-12-15 02:35:44 +00:00
|
|
|
}
|
2021-08-28 16:38:24 +00:00
|
|
|
app_context().CallInUIThreadSynchronous([this]() {
|
|
|
|
debug_window_ = xe::debug::ui::DebugWindow::Create(emulator_.get(),
|
|
|
|
app_context());
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
debug_window_->window()->AddListener(
|
|
|
|
&debug_window_closed_listener_);
|
2017-12-15 02:35:44 +00:00
|
|
|
});
|
2021-08-28 16:38:24 +00:00
|
|
|
// If failed to enqueue the UI thread call, this will just be null.
|
|
|
|
return debug_window_.get();
|
2015-09-21 04:31:05 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
emulator_->on_launch.AddListener([&](auto title_id, const auto& game_title) {
|
2019-08-03 13:12:37 +00:00
|
|
|
if (cvars::discord) {
|
|
|
|
discord::DiscordPresence::PlayingTitle(
|
2020-03-02 15:37:11 +00:00
|
|
|
game_title.empty() ? "Unknown Title" : std::string(game_title));
|
2019-08-03 13:12:37 +00:00
|
|
|
}
|
2021-08-28 16:38:24 +00:00
|
|
|
app_context().CallInUIThread([this]() { emulator_window_->UpdateTitle(); });
|
|
|
|
emulator_thread_event_->Set();
|
2016-06-19 01:42:28 +00:00
|
|
|
});
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
emulator_->on_shader_storage_initialization.AddListener(
|
|
|
|
[this](bool initializing) {
|
|
|
|
app_context().CallInUIThread([this, initializing]() {
|
|
|
|
emulator_window_->SetInitializingShaderStorage(initializing);
|
|
|
|
});
|
2020-03-21 16:21:00 +00:00
|
|
|
});
|
|
|
|
|
2020-10-09 19:02:32 +00:00
|
|
|
emulator_->on_patch_apply.AddListener([this]() {
|
|
|
|
app_context().CallInUIThread([this]() { emulator_window_->UpdateTitle(); });
|
|
|
|
});
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
emulator_->on_terminate.AddListener([]() {
|
2019-08-03 13:12:37 +00:00
|
|
|
if (cvars::discord) {
|
|
|
|
discord::DiscordPresence::NotPlaying();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
// Enable emulator input now that the emulator is properly loaded.
|
2021-08-28 16:38:24 +00:00
|
|
|
app_context().CallInUIThread(
|
[UI] Image post-processing and full presentation/window rework
[GPU] Add FXAA post-processing
[UI] Add FidelityFX FSR and CAS post-processing
[UI] Add blue noise dithering from 10bpc to 8bpc
[GPU] Apply the DC PWL gamma ramp closer to the spec, supporting fully white color
[UI] Allow the GPU CP thread to present on the host directly, bypassing the UI thread OS paint event
[UI] Allow variable refresh rate (or tearing)
[UI] Present the newest frame (restart) on DXGI
[UI] Replace GraphicsContext with a far more advanced Presenter with more coherent surface connection and UI overlay state management
[UI] Connect presentation to windows via the Surface class, not native window handles
[Vulkan] Switch to simpler Vulkan setup with no instance/device separation due to interdependencies and to pass fewer objects around
[Vulkan] Lower the minimum required Vulkan version to 1.0
[UI/GPU] Various cleanup, mainly ComPtr usage
[UI] Support per-monitor DPI awareness v2 on Windows
[UI] DPI-scale Dear ImGui
[UI] Replace the remaining non-detachable window delegates with unified window event and input listeners
[UI] Allow listeners to safely destroy or close the window, and to register/unregister listeners without use-after-free and the ABA problem
[UI] Explicit Z ordering of input listeners and UI overlays, top-down for input, bottom-up for drawing
[UI] Add explicit window lifecycle phases
[UI] Replace Window virtual functions with explicit desired state, its application, actual state, its feedback
[UI] GTK: Apply the initial size to the drawing area
[UI] Limit internal UI frame rate to that of the monitor
[UI] Hide the cursor using a timer instead of polling due to no repeated UI thread paints with GPU CP thread presentation, and only within the window
2022-01-29 10:22:03 +00:00
|
|
|
[this]() { emulator_window_->OnEmulatorInitialized(); });
|
2017-07-01 19:36:16 +00:00
|
|
|
|
2014-12-21 06:17:57 +00:00
|
|
|
// Grab path from the flag or unnamed argument.
|
2020-03-02 15:37:11 +00:00
|
|
|
std::filesystem::path path;
|
2019-04-17 19:49:29 +00:00
|
|
|
if (!cvars::target.empty()) {
|
2020-03-02 15:37:11 +00:00
|
|
|
path = cvars::target;
|
2015-06-27 03:27:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!path.empty()) {
|
2014-12-21 06:17:57 +00:00
|
|
|
// Normalize the path and make absolute.
|
2020-03-02 15:37:11 +00:00
|
|
|
auto abs_path = std::filesystem::absolute(path);
|
2023-03-06 07:31:05 +00:00
|
|
|
|
2023-07-10 19:41:44 +00:00
|
|
|
result = app_context().CallInUIThread(
|
|
|
|
[this, abs_path]() { return emulator_window_->RunTitle(abs_path); });
|
2014-12-21 06:17:57 +00:00
|
|
|
if (XFAILED(result)) {
|
2020-03-02 15:37:11 +00:00
|
|
|
xe::FatalError(fmt::format("Failed to launch target: {:08X}", result));
|
2021-08-28 16:38:24 +00:00
|
|
|
app_context().RequestDeferredQuit();
|
|
|
|
return;
|
2014-12-21 06:17:57 +00:00
|
|
|
}
|
2016-06-19 01:42:28 +00:00
|
|
|
}
|
2013-01-13 08:34:08 +00:00
|
|
|
|
2024-02-10 21:38:21 +00:00
|
|
|
auto xam = emulator_->kernel_state()->GetKernelModule<kernel::xam::XamModule>(
|
|
|
|
"xam.xex");
|
|
|
|
|
|
|
|
if (xam) {
|
|
|
|
xam->LoadLoaderData();
|
|
|
|
|
|
|
|
if (xam->loader_data().launch_data_present) {
|
|
|
|
const std::filesystem::path host_path = xam->loader_data().host_path;
|
|
|
|
app_context().CallInUIThread([this, host_path]() {
|
|
|
|
return emulator_window_->RunTitle(host_path);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
// Now, we're going to use this thread to drive events related to emulation.
|
|
|
|
while (!emulator_thread_quit_requested_.load(std::memory_order_relaxed)) {
|
|
|
|
xe::threading::Wait(emulator_thread_event_.get(), false);
|
2024-06-16 07:16:10 +00:00
|
|
|
emulator_->WaitUntilExit();
|
2015-02-20 15:47:06 +00:00
|
|
|
}
|
2021-08-28 16:38:24 +00:00
|
|
|
}
|
2014-12-21 06:17:57 +00:00
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
void EmulatorApp::ShutdownEmulatorThreadFromUIThread() {
|
|
|
|
// TODO(Triang3l): Proper shutdown of the emulator (relying on std::quick_exit
|
|
|
|
// for now) - currently WaitUntilExit loops forever otherwise (plus possibly
|
|
|
|
// lots of other things not shutting down correctly now). Some parts of the
|
|
|
|
// code call the regular std::exit, which seems to be calling destructors (at
|
|
|
|
// least on Linux), so the entire join is currently commented out.
|
|
|
|
#if 0
|
|
|
|
// Same thread as the one created it, to make sure there's zero possibility of
|
|
|
|
// a race with the creation of the emulator thread.
|
|
|
|
assert_true(app_context().IsInUIThread());
|
|
|
|
emulator_thread_quit_requested_.store(true, std::memory_order_relaxed);
|
|
|
|
if (!emulator_thread_.joinable()) {
|
|
|
|
return;
|
2019-08-03 13:12:37 +00:00
|
|
|
}
|
2021-08-28 16:38:24 +00:00
|
|
|
emulator_thread_event_->Set();
|
|
|
|
emulator_thread_.join();
|
|
|
|
#endif
|
2013-01-11 09:23:08 +00:00
|
|
|
}
|
2014-08-16 23:34:04 +00:00
|
|
|
|
2015-07-17 08:15:12 +00:00
|
|
|
} // namespace app
|
2014-12-21 06:17:57 +00:00
|
|
|
} // namespace xe
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
XE_DEFINE_WINDOWED_APP(xenia, xe::app::EmulatorApp::Create);
|