vulkan_library.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <string>
  4. #include "common/dynamic_library.h"
  5. #include "common/fs/path_util.h"
  6. #include "common/logging/log.h"
  7. #include "video_core/vulkan_common/vulkan_library.h"
  8. namespace Vulkan {
  9. Common::DynamicLibrary OpenLibrary() {
  10. LOG_DEBUG(Render_Vulkan, "Looking for a Vulkan library");
  11. Common::DynamicLibrary library;
  12. #ifdef __APPLE__
  13. // Check if a path to a specific Vulkan library has been specified.
  14. char* const libvulkan_env = std::getenv("LIBVULKAN_PATH");
  15. if (!libvulkan_env || !library.Open(libvulkan_env)) {
  16. // Use the libvulkan.dylib from the application bundle.
  17. const auto filename =
  18. Common::FS::GetBundleDirectory() / "Contents/Frameworks/libvulkan.dylib";
  19. void(library.Open(Common::FS::PathToUTF8String(filename).c_str()));
  20. }
  21. #else
  22. std::string filename = Common::DynamicLibrary::GetVersionedFilename("vulkan", 1);
  23. LOG_DEBUG(Render_Vulkan, "Trying Vulkan library: {}", filename);
  24. if (!library.Open(filename.c_str())) {
  25. // Android devices may not have libvulkan.so.1, only libvulkan.so.
  26. filename = Common::DynamicLibrary::GetVersionedFilename("vulkan");
  27. LOG_DEBUG(Render_Vulkan, "Trying Vulkan library (second attempt): {}", filename);
  28. void(library.Open(filename.c_str()));
  29. }
  30. #endif
  31. return library;
  32. }
  33. } // namespace Vulkan