2022-05-29 22:26:27 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2022-05-28 02:33:23 -04:00
|
|
|
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
|
|
|
|
2022-07-10 14:08:20 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <cstring> // for memset, strncpy
|
|
|
|
#include <processthreadsapi.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#elif defined(YUZU_UNIX)
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <cstdio>
|
2022-05-28 02:33:23 -04:00
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
|
|
|
#include "common/fs/fs.h"
|
|
|
|
#include "common/fs/path_util.h"
|
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "video_core/vulkan_common/vulkan_instance.h"
|
|
|
|
#include "video_core/vulkan_common/vulkan_library.h"
|
2022-07-10 14:08:20 -04:00
|
|
|
#include "yuzu/startup_checks.h"
|
2022-05-28 02:33:23 -04:00
|
|
|
#include "yuzu/uisettings.h"
|
|
|
|
|
2022-07-10 16:10:35 -04:00
|
|
|
void CheckVulkan() {
|
2022-05-28 02:33:23 -04:00
|
|
|
try {
|
|
|
|
Vulkan::vk::InstanceDispatch dld;
|
|
|
|
const Common::DynamicLibrary library = Vulkan::OpenLibrary();
|
|
|
|
const Vulkan::vk::Instance instance =
|
|
|
|
Vulkan::CreateInstance(library, dld, VK_API_VERSION_1_0);
|
|
|
|
|
|
|
|
} catch (const Vulkan::vk::Exception& exception) {
|
|
|
|
LOG_ERROR(Frontend, "Failed to initialize Vulkan: {}", exception.what());
|
|
|
|
}
|
|
|
|
}
|
2022-07-10 14:08:20 -04:00
|
|
|
|
2022-07-10 16:10:35 -04:00
|
|
|
bool StartupChecks(const char* arg0, bool* has_broken_vulkan) {
|
2022-07-10 14:08:20 -04:00
|
|
|
#ifdef _WIN32
|
|
|
|
const bool env_var_set = SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, "ON");
|
|
|
|
if (!env_var_set) {
|
2022-07-10 16:10:35 -04:00
|
|
|
std::fprintf(stderr, "SetEnvironmentVariableA failed to set %s, %d\n",
|
|
|
|
STARTUP_CHECK_ENV_VAR, GetLastError());
|
2022-07-10 14:08:20 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PROCESS_INFORMATION process_info;
|
2022-07-10 16:10:35 -04:00
|
|
|
std::memset(&process_info, '\0', sizeof(process_info));
|
|
|
|
|
|
|
|
if (!SpawnChild(arg0, &process_info)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait until the processs exits
|
|
|
|
DWORD exit_code = STILL_ACTIVE;
|
|
|
|
while (exit_code == STILL_ACTIVE) {
|
|
|
|
GetExitCodeProcess(process_info.hProcess, &exit_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
*has_broken_vulkan = (exit_code != 0);
|
|
|
|
|
|
|
|
CloseHandle(process_info.hProcess);
|
|
|
|
CloseHandle(process_info.hThread);
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
bool SpawnChild(const char* arg0, PROCESS_INFORMATION* pi) {
|
|
|
|
STARTUPINFOA startup_info;
|
2022-07-10 14:08:20 -04:00
|
|
|
|
|
|
|
std::memset(&startup_info, '\0', sizeof(startup_info));
|
|
|
|
startup_info.cb = sizeof(startup_info);
|
|
|
|
|
|
|
|
char p_name[255];
|
2022-07-10 16:10:35 -04:00
|
|
|
std::strncpy(p_name, arg0, 255);
|
2022-07-10 14:08:20 -04:00
|
|
|
|
|
|
|
// 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
|
2022-07-10 16:10:35 -04:00
|
|
|
pi // lpProcessInformation
|
2022-07-10 14:08:20 -04:00
|
|
|
);
|
|
|
|
if (!process_created) {
|
2022-07-10 16:10:35 -04:00
|
|
|
std::fprintf(stderr, "CreateProcessA failed, %d\n", GetLastError());
|
2022-07-10 14:08:20 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-07-10 16:10:35 -04:00
|
|
|
#endif
|