vulkan_library.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. std::shared_ptr<Common::DynamicLibrary> OpenLibrary(
  10. [[maybe_unused]] Core::Frontend::GraphicsContext* context) {
  11. LOG_DEBUG(Render_Vulkan, "Looking for a Vulkan library");
  12. #if defined(ANDROID) && defined(ARCHITECTURE_arm64)
  13. // Android manages its Vulkan driver from the frontend.
  14. return context->GetDriverLibrary();
  15. #else
  16. auto library = std::make_shared<Common::DynamicLibrary>();
  17. #ifdef __APPLE__
  18. // Check if a path to a specific Vulkan library has been specified.
  19. char* const libvulkan_env = std::getenv("LIBVULKAN_PATH");
  20. if (!libvulkan_env || !library->Open(libvulkan_env)) {
  21. // Use the libvulkan.dylib from the application bundle.
  22. const auto filename =
  23. Common::FS::GetBundleDirectory() / "Contents/Frameworks/libvulkan.dylib";
  24. void(library->Open(Common::FS::PathToUTF8String(filename).c_str()));
  25. }
  26. #else
  27. std::string filename = Common::DynamicLibrary::GetVersionedFilename("vulkan", 1);
  28. LOG_DEBUG(Render_Vulkan, "Trying Vulkan library: {}", filename);
  29. if (!library->Open(filename.c_str())) {
  30. // Android devices may not have libvulkan.so.1, only libvulkan.so.
  31. filename = Common::DynamicLibrary::GetVersionedFilename("vulkan");
  32. LOG_DEBUG(Render_Vulkan, "Trying Vulkan library (second attempt): {}", filename);
  33. void(library->Open(filename.c_str()));
  34. }
  35. #endif
  36. return library;
  37. #endif
  38. }
  39. } // namespace Vulkan