1
1
Fork 0
forked from suyu/suyu

yuzu: Check Vulkan on startup with a child

This commit is contained in:
lat9nq 2022-07-10 14:08:20 -04:00
parent 568a0ac397
commit 4f15d9ed6f
3 changed files with 78 additions and 1 deletions

View file

@ -3853,6 +3853,21 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) {
#endif #endif
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
#ifdef _WIN32
char variable_contents[32];
const DWORD startup_check_var =
GetEnvironmentVariable(STARTUP_CHECK_ENV_VAR, variable_contents, 32);
if (startup_check_var != 0) {
std::fprintf(stderr, "perform statup checks\n");
CheckVulkan();
return 0;
} else {
std::fprintf(stderr, "%d\n", StartupChecks());
}
#elif YUZU_UNIX
#error "Unimplemented"
#endif
Common::DetachedTasks detached_tasks; Common::DetachedTasks detached_tasks;
MicroProfileOnThreadCreate("Frontend"); MicroProfileOnThreadCreate("Frontend");
SCOPE_EXIT({ MicroProfileShutdown(); }); SCOPE_EXIT({ MicroProfileShutdown(); });

View file

@ -3,6 +3,15 @@
#include "video_core/vulkan_common/vulkan_wrapper.h" #include "video_core/vulkan_common/vulkan_wrapper.h"
#ifdef _WIN32
#include <cstring> // for memset, strncpy
#include <processthreadsapi.h>
#include <windows.h>
#elif defined(YUZU_UNIX)
#include <unistd.h>
#endif
#include <cstdio>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
#include "common/fs/fs.h" #include "common/fs/fs.h"
@ -10,7 +19,7 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "video_core/vulkan_common/vulkan_instance.h" #include "video_core/vulkan_common/vulkan_instance.h"
#include "video_core/vulkan_common/vulkan_library.h" #include "video_core/vulkan_common/vulkan_library.h"
#include "yuzu/check_vulkan.h" #include "yuzu/startup_checks.h"
#include "yuzu/uisettings.h" #include "yuzu/uisettings.h"
constexpr char TEMP_FILE_NAME[] = "vulkan_check"; constexpr char TEMP_FILE_NAME[] = "vulkan_check";
@ -51,3 +60,53 @@ bool CheckVulkan() {
std::filesystem::remove(temp_file_loc); std::filesystem::remove(temp_file_loc);
return true; return true;
} }
bool StartupChecks() {
#ifdef _WIN32
const bool env_var_set = SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, "ON");
if (!env_var_set) {
LOG_ERROR(Frontend, "SetEnvironmentVariableA failed to set {}, {}", STARTUP_CHECK_ENV_VAR,
GetLastError());
return false;
}
STARTUPINFOA startup_info;
PROCESS_INFORMATION process_info;
std::memset(&startup_info, '\0', sizeof(startup_info));
std::memset(&process_info, '\0', sizeof(process_info));
startup_info.cb = sizeof(startup_info);
char p_name[255];
std::strncpy(p_name, "yuzu.exe", 255);
// TODO: use argv[0] instead of yuzu.exe
const bool process_created = CreateProcessA(nullptr, // lpApplicationName
p_name, // lpCommandLine
nullptr, // lpProcessAttributes
nullptr, // lpThreadAttributes
false, // bInheritHandles
0, // dwCreationFlags
nullptr, // lpEnvironment
nullptr, // lpCurrentDirectory
&startup_info, // lpStartupInfo
&process_info // lpProcessInformation
);
if (!process_created) {
LOG_ERROR(Frontend, "CreateProcessA failed, {}", GetLastError());
return false;
}
// wait until the processs exits
DWORD exit_code = STILL_ACTIVE;
while (exit_code == STILL_ACTIVE) {
GetExitCodeProcess(process_info.hProcess, &exit_code);
}
std::fprintf(stderr, "exit code: %d\n", exit_code);
CloseHandle(process_info.hProcess);
CloseHandle(process_info.hThread);
#endif
return true;
}

View file

@ -3,4 +3,7 @@
#pragma once #pragma once
constexpr char STARTUP_CHECK_ENV_VAR[] = "YUZU_DO_STARTUP_CHECKS";
bool CheckVulkan(); bool CheckVulkan();
bool StartupChecks();