2014-08-16 23:34:04 +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. *
|
2014-08-16 23:34:04 +00:00
|
|
|
* Released under the BSD license - see LICENSE in the root for more details. *
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <cstring>
|
2016-01-01 20:46:26 +00:00
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
#include "xenia/base/cvar.h"
|
2015-08-30 01:06:30 +00:00
|
|
|
#include "xenia/base/logging.h"
|
2021-08-28 16:38:24 +00:00
|
|
|
#include "xenia/base/main_win.h"
|
2015-07-14 03:49:29 +00:00
|
|
|
#include "xenia/base/platform_win.h"
|
2015-05-02 10:42:51 +00:00
|
|
|
#include "xenia/base/string.h"
|
2014-08-16 23:34:04 +00:00
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
// Autogenerated by `xb premake`.
|
|
|
|
#include "build/version.h"
|
2018-12-16 05:36:07 +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
|
|
|
// For RequestWin32MMCSS.
|
|
|
|
#include <dwmapi.h>
|
|
|
|
// For RequestWin32HighResolutionTimer.
|
2020-03-02 15:37:11 +00:00
|
|
|
#include <winternl.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
|
|
|
DEFINE_bool(win32_high_resolution_timer, true,
|
|
|
|
"Requests high-resolution timer from the NT kernel", "Win32");
|
|
|
|
DEFINE_bool(
|
|
|
|
win32_mmcss, true,
|
|
|
|
"Opt in the Multimedia Class Scheduler Service (MMCSS) scheduling for "
|
|
|
|
"prioritized access to CPU resources",
|
|
|
|
"Win32");
|
2018-05-22 22:31:30 +00:00
|
|
|
|
2015-05-02 10:42:51 +00:00
|
|
|
namespace xe {
|
2014-08-16 23:34:04 +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
|
|
|
static void RequestWin32HighResolutionTimer() {
|
|
|
|
HMODULE ntdll_module = GetModuleHandleW(L"ntdll.dll");
|
|
|
|
if (!ntdll_module) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
NTSTATUS (NTAPI* nt_query_timer_resolution)(OUT PULONG MinimumResolution,
|
|
|
|
OUT PULONG MaximumResolution,
|
|
|
|
OUT PULONG CurrentResolution);
|
|
|
|
NTSTATUS (NTAPI* nt_set_timer_resolution)(IN ULONG DesiredResolution,
|
|
|
|
IN BOOLEAN SetResolution,
|
|
|
|
OUT PULONG CurrentResolution);
|
|
|
|
// clang-format on
|
|
|
|
nt_query_timer_resolution =
|
|
|
|
reinterpret_cast<decltype(nt_query_timer_resolution)>(
|
|
|
|
GetProcAddress(ntdll_module, "NtQueryTimerResolution"));
|
|
|
|
nt_set_timer_resolution = reinterpret_cast<decltype(nt_set_timer_resolution)>(
|
|
|
|
GetProcAddress(ntdll_module, "NtSetTimerResolution"));
|
|
|
|
if (!nt_query_timer_resolution || !nt_set_timer_resolution) {
|
2018-05-22 21:41:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG minimum_resolution, maximum_resolution, current_resolution;
|
[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
|
|
|
nt_query_timer_resolution(&minimum_resolution, &maximum_resolution,
|
|
|
|
¤t_resolution);
|
|
|
|
nt_set_timer_resolution(maximum_resolution, TRUE, ¤t_resolution);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RequestWin32MMCSS() {
|
|
|
|
HMODULE dwmapi_module = LoadLibraryW(L"dwmapi.dll");
|
|
|
|
if (!dwmapi_module) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// clang-format off
|
|
|
|
HRESULT (STDAPICALLTYPE* dwm_enable_mmcss)(BOOL fEnableMMCSS);
|
|
|
|
// clang-format on
|
|
|
|
dwm_enable_mmcss = reinterpret_cast<decltype(dwm_enable_mmcss)>(
|
|
|
|
GetProcAddress(dwmapi_module, "DwmEnableMMCSS"));
|
|
|
|
if (dwm_enable_mmcss) {
|
|
|
|
dwm_enable_mmcss(TRUE);
|
|
|
|
}
|
|
|
|
FreeLibrary(dwmapi_module);
|
2018-05-22 21:41:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
bool ParseWin32LaunchArguments(
|
|
|
|
bool transparent_options, const std::string_view positional_usage,
|
|
|
|
const std::vector<std::string>& positional_options,
|
|
|
|
std::vector<std::string>* args_out) {
|
2015-08-01 06:48:24 +00:00
|
|
|
auto command_line = GetCommandLineW();
|
2020-03-02 15:37:11 +00:00
|
|
|
|
|
|
|
int wargc;
|
|
|
|
wchar_t** wargv = CommandLineToArgvW(command_line, &wargc);
|
|
|
|
if (!wargv) {
|
|
|
|
return false;
|
2015-08-01 06:48:24 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 22:08:59 +00:00
|
|
|
// Convert all args to narrow, as cxxopts doesn't support wchar.
|
2020-03-02 15:37:11 +00:00
|
|
|
int argc = wargc;
|
|
|
|
char** argv = reinterpret_cast<char**>(alloca(sizeof(char*) * argc));
|
|
|
|
for (int n = 0; n < argc; n++) {
|
|
|
|
size_t len = std::wcstombs(nullptr, wargv[n], 0);
|
|
|
|
argv[n] = reinterpret_cast<char*>(alloca(sizeof(char) * (len + 1)));
|
|
|
|
std::wcstombs(argv[n], wargv[n], len + 1);
|
2014-08-16 23:34:04 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 15:37:11 +00:00
|
|
|
LocalFree(wargv);
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
if (!transparent_options) {
|
|
|
|
cvar::ParseLaunchArguments(argc, argv, positional_usage,
|
|
|
|
positional_options);
|
2021-05-25 00:21:42 +00:00
|
|
|
}
|
2014-08-16 23:34:04 +00:00
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
if (args_out) {
|
|
|
|
args_out->clear();
|
|
|
|
for (int n = 0; n < argc; n++) {
|
|
|
|
args_out->push_back(std::string(argv[n]));
|
|
|
|
}
|
2020-03-02 15:37:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
int InitializeWin32App(const std::string_view app_name) {
|
2015-08-30 01:06:30 +00:00
|
|
|
// Initialize logging. Needs parsed FLAGS.
|
2021-08-28 16:38:24 +00:00
|
|
|
xe::InitializeLogging(app_name);
|
2019-04-20 06:31:38 +00:00
|
|
|
|
2015-12-27 19:53:37 +00:00
|
|
|
// Print version info.
|
2021-08-08 15:20:51 +00:00
|
|
|
XELOGI(
|
|
|
|
"Build: "
|
|
|
|
#ifdef XE_BUILD_IS_PR
|
|
|
|
"PR#" XE_BUILD_PR_NUMBER " " XE_BUILD_PR_REPO " " XE_BUILD_PR_BRANCH
|
|
|
|
"@" XE_BUILD_PR_COMMIT_SHORT " against "
|
|
|
|
#endif
|
|
|
|
XE_BUILD_BRANCH "@" XE_BUILD_COMMIT_SHORT " on " XE_BUILD_DATE);
|
2015-12-27 19:53:37 +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
|
|
|
// Request high-performance timing and scheduling.
|
|
|
|
if (cvars::win32_high_resolution_timer) {
|
|
|
|
RequestWin32HighResolutionTimer();
|
|
|
|
}
|
|
|
|
if (cvars::win32_mmcss) {
|
|
|
|
RequestWin32MMCSS();
|
2018-12-16 04:56:36 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
return 0;
|
2014-08-16 23:34:04 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
void ShutdownWin32App() { xe::ShutdownLogging(); }
|
2019-04-20 06:31:38 +00:00
|
|
|
|
2021-08-28 16:38:24 +00:00
|
|
|
} // namespace xe
|