check_vulkan.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "video_core/vulkan_common/vulkan_wrapper.h"
  2. #include <exception>
  3. #include <filesystem>
  4. #include <fstream>
  5. #include "common/fs/fs.h"
  6. #include "common/fs/path_util.h"
  7. #include "common/logging/log.h"
  8. #include "video_core/vulkan_common/vulkan_instance.h"
  9. #include "video_core/vulkan_common/vulkan_library.h"
  10. #include "yuzu/check_vulkan.h"
  11. #include "yuzu/uisettings.h"
  12. constexpr char TEMP_FILE_NAME[] = "vulkan_check";
  13. bool CheckVulkan() {
  14. if (UISettings::values.has_broken_vulkan) {
  15. return true;
  16. }
  17. LOG_DEBUG(Frontend, "Checking presence of Vulkan");
  18. const auto fs_config_loc = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir);
  19. const auto temp_file_loc = fs_config_loc / TEMP_FILE_NAME;
  20. if (std::filesystem::exists(temp_file_loc)) {
  21. LOG_WARNING(Frontend, "Detected recovery from previous failed Vulkan initialization");
  22. UISettings::values.has_broken_vulkan = true;
  23. std::filesystem::remove(temp_file_loc);
  24. return false;
  25. }
  26. std::ofstream temp_file_handle(temp_file_loc);
  27. temp_file_handle.close();
  28. try {
  29. Vulkan::vk::InstanceDispatch dld;
  30. const Common::DynamicLibrary library = Vulkan::OpenLibrary();
  31. const Vulkan::vk::Instance instance =
  32. Vulkan::CreateInstance(library, dld, VK_API_VERSION_1_0);
  33. } catch (const Vulkan::vk::Exception& exception) {
  34. LOG_ERROR(Frontend, "Failed to initialize Vulkan: {}", exception.what());
  35. UISettings::values.has_broken_vulkan = true;
  36. return false;
  37. }
  38. std::filesystem::remove(temp_file_loc);
  39. return true;
  40. }