diff options
| author | 2022-07-10 14:08:20 -0400 | |
|---|---|---|
| committer | 2022-07-10 14:08:20 -0400 | |
| commit | 4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688 (patch) | |
| tree | 78795445528ff6f9c96874e8ef461f5f5e6ae871 | |
| parent | yuzu: Rename check_vulkan to startup_checks (diff) | |
| download | yuzu-4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688.tar.gz yuzu-4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688.tar.xz yuzu-4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688.zip | |
yuzu: Check Vulkan on startup with a child
Diffstat (limited to '')
| -rw-r--r-- | src/yuzu/main.cpp | 15 | ||||
| -rw-r--r-- | src/yuzu/startup_checks.cpp | 61 | ||||
| -rw-r--r-- | src/yuzu/startup_checks.h | 3 |
3 files changed, 78 insertions, 1 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 64be8bf61..f2e449560 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -3853,6 +3853,21 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) { | |||
| 3853 | #endif | 3853 | #endif |
| 3854 | 3854 | ||
| 3855 | int main(int argc, char* argv[]) { | 3855 | int main(int argc, char* argv[]) { |
| 3856 | #ifdef _WIN32 | ||
| 3857 | char variable_contents[32]; | ||
| 3858 | const DWORD startup_check_var = | ||
| 3859 | GetEnvironmentVariable(STARTUP_CHECK_ENV_VAR, variable_contents, 32); | ||
| 3860 | if (startup_check_var != 0) { | ||
| 3861 | std::fprintf(stderr, "perform statup checks\n"); | ||
| 3862 | CheckVulkan(); | ||
| 3863 | return 0; | ||
| 3864 | } else { | ||
| 3865 | std::fprintf(stderr, "%d\n", StartupChecks()); | ||
| 3866 | } | ||
| 3867 | #elif YUZU_UNIX | ||
| 3868 | #error "Unimplemented" | ||
| 3869 | #endif | ||
| 3870 | |||
| 3856 | Common::DetachedTasks detached_tasks; | 3871 | Common::DetachedTasks detached_tasks; |
| 3857 | MicroProfileOnThreadCreate("Frontend"); | 3872 | MicroProfileOnThreadCreate("Frontend"); |
| 3858 | SCOPE_EXIT({ MicroProfileShutdown(); }); | 3873 | SCOPE_EXIT({ MicroProfileShutdown(); }); |
diff --git a/src/yuzu/startup_checks.cpp b/src/yuzu/startup_checks.cpp index e6d66ab34..cfd14a6d5 100644 --- a/src/yuzu/startup_checks.cpp +++ b/src/yuzu/startup_checks.cpp | |||
| @@ -3,6 +3,15 @@ | |||
| 3 | 3 | ||
| 4 | #include "video_core/vulkan_common/vulkan_wrapper.h" | 4 | #include "video_core/vulkan_common/vulkan_wrapper.h" |
| 5 | 5 | ||
| 6 | #ifdef _WIN32 | ||
| 7 | #include <cstring> // for memset, strncpy | ||
| 8 | #include <processthreadsapi.h> | ||
| 9 | #include <windows.h> | ||
| 10 | #elif defined(YUZU_UNIX) | ||
| 11 | #include <unistd.h> | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #include <cstdio> | ||
| 6 | #include <filesystem> | 15 | #include <filesystem> |
| 7 | #include <fstream> | 16 | #include <fstream> |
| 8 | #include "common/fs/fs.h" | 17 | #include "common/fs/fs.h" |
| @@ -10,7 +19,7 @@ | |||
| 10 | #include "common/logging/log.h" | 19 | #include "common/logging/log.h" |
| 11 | #include "video_core/vulkan_common/vulkan_instance.h" | 20 | #include "video_core/vulkan_common/vulkan_instance.h" |
| 12 | #include "video_core/vulkan_common/vulkan_library.h" | 21 | #include "video_core/vulkan_common/vulkan_library.h" |
| 13 | #include "yuzu/check_vulkan.h" | 22 | #include "yuzu/startup_checks.h" |
| 14 | #include "yuzu/uisettings.h" | 23 | #include "yuzu/uisettings.h" |
| 15 | 24 | ||
| 16 | constexpr char TEMP_FILE_NAME[] = "vulkan_check"; | 25 | constexpr char TEMP_FILE_NAME[] = "vulkan_check"; |
| @@ -51,3 +60,53 @@ bool CheckVulkan() { | |||
| 51 | std::filesystem::remove(temp_file_loc); | 60 | std::filesystem::remove(temp_file_loc); |
| 52 | return true; | 61 | return true; |
| 53 | } | 62 | } |
| 63 | |||
| 64 | bool StartupChecks() { | ||
| 65 | #ifdef _WIN32 | ||
| 66 | const bool env_var_set = SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, "ON"); | ||
| 67 | if (!env_var_set) { | ||
| 68 | LOG_ERROR(Frontend, "SetEnvironmentVariableA failed to set {}, {}", STARTUP_CHECK_ENV_VAR, | ||
| 69 | GetLastError()); | ||
| 70 | return false; | ||
| 71 | } | ||
| 72 | |||
| 73 | STARTUPINFOA startup_info; | ||
| 74 | PROCESS_INFORMATION process_info; | ||
| 75 | |||
| 76 | std::memset(&startup_info, '\0', sizeof(startup_info)); | ||
| 77 | std::memset(&process_info, '\0', sizeof(process_info)); | ||
| 78 | startup_info.cb = sizeof(startup_info); | ||
| 79 | |||
| 80 | char p_name[255]; | ||
| 81 | std::strncpy(p_name, "yuzu.exe", 255); | ||
| 82 | |||
| 83 | // TODO: use argv[0] instead of yuzu.exe | ||
| 84 | const bool process_created = CreateProcessA(nullptr, // lpApplicationName | ||
| 85 | p_name, // lpCommandLine | ||
| 86 | nullptr, // lpProcessAttributes | ||
| 87 | nullptr, // lpThreadAttributes | ||
| 88 | false, // bInheritHandles | ||
| 89 | 0, // dwCreationFlags | ||
| 90 | nullptr, // lpEnvironment | ||
| 91 | nullptr, // lpCurrentDirectory | ||
| 92 | &startup_info, // lpStartupInfo | ||
| 93 | &process_info // lpProcessInformation | ||
| 94 | ); | ||
| 95 | if (!process_created) { | ||
| 96 | LOG_ERROR(Frontend, "CreateProcessA failed, {}", GetLastError()); | ||
| 97 | return false; | ||
| 98 | } | ||
| 99 | |||
| 100 | // wait until the processs exits | ||
| 101 | DWORD exit_code = STILL_ACTIVE; | ||
| 102 | while (exit_code == STILL_ACTIVE) { | ||
| 103 | GetExitCodeProcess(process_info.hProcess, &exit_code); | ||
| 104 | } | ||
| 105 | |||
| 106 | std::fprintf(stderr, "exit code: %d\n", exit_code); | ||
| 107 | |||
| 108 | CloseHandle(process_info.hProcess); | ||
| 109 | CloseHandle(process_info.hThread); | ||
| 110 | #endif | ||
| 111 | return true; | ||
| 112 | } | ||
diff --git a/src/yuzu/startup_checks.h b/src/yuzu/startup_checks.h index e4ea93582..98bd5f4bf 100644 --- a/src/yuzu/startup_checks.h +++ b/src/yuzu/startup_checks.h | |||
| @@ -3,4 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | constexpr char STARTUP_CHECK_ENV_VAR[] = "YUZU_DO_STARTUP_CHECKS"; | ||
| 7 | |||
| 6 | bool CheckVulkan(); | 8 | bool CheckVulkan(); |
| 9 | bool StartupChecks(); | ||