mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-01-06 07:06:00 +00:00
Merge pull request #748 from squidbus/vk-loading
vulkan: Better support for directly linking a Vulkan support library.
This commit is contained in:
commit
1bf9be89bf
|
@ -647,12 +647,17 @@ target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt toml11::to
|
||||||
target_link_libraries(shadps4 PRIVATE Boost::headers GPUOpen::VulkanMemoryAllocator sirit Vulkan::Headers xxHash::xxhash Zydis::Zydis glslang::SPIRV glslang::glslang SDL3::SDL3)
|
target_link_libraries(shadps4 PRIVATE Boost::headers GPUOpen::VulkanMemoryAllocator sirit Vulkan::Headers xxHash::xxhash Zydis::Zydis glslang::SPIRV glslang::glslang SDL3::SDL3)
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
# Reserve system-managed memory space.
|
option(USE_SYSTEM_VULKAN_LOADER "Enables using the system Vulkan loader instead of directly linking with MoltenVK. Useful for loading validation layers." OFF)
|
||||||
target_link_options(shadps4 PRIVATE -Wl,-no_pie,-no_fixup_chains,-no_huge,-pagezero_size,0x4000,-segaddr,TCB_SPACE,0x4000,-segaddr,GUEST_SYSTEM,0x400000,-image_base,0x20000000000)
|
if (USE_SYSTEM_VULKAN_LOADER)
|
||||||
|
target_compile_definitions(shadps4 PRIVATE USE_SYSTEM_VULKAN_LOADER=1)
|
||||||
|
else()
|
||||||
# Link MoltenVK for Vulkan support
|
# Link MoltenVK for Vulkan support
|
||||||
find_library(MOLTENVK MoltenVK REQUIRED)
|
find_library(MOLTENVK MoltenVK REQUIRED)
|
||||||
target_link_libraries(shadps4 PRIVATE ${MOLTENVK})
|
target_link_libraries(shadps4 PRIVATE ${MOLTENVK})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Reserve system-managed memory space.
|
||||||
|
target_link_options(shadps4 PRIVATE -Wl,-no_pie,-no_fixup_chains,-no_huge,-pagezero_size,0x4000,-segaddr,TCB_SPACE,0x4000,-segaddr,GUEST_SYSTEM,0x400000,-image_base,0x20000000000)
|
||||||
|
|
||||||
# Replacement for std::chrono::time_zone
|
# Replacement for std::chrono::time_zone
|
||||||
target_link_libraries(shadps4 PRIVATE date::date-tz)
|
target_link_libraries(shadps4 PRIVATE date::date-tz)
|
||||||
|
|
|
@ -3,6 +3,10 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(__APPLE__) && !USE_SYSTEM_VULKAN_LOADER
|
||||||
|
#define VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL 0
|
||||||
|
#endif
|
||||||
|
|
||||||
// Include vulkan-hpp header
|
// Include vulkan-hpp header
|
||||||
#define VK_ENABLE_BETA_EXTENSIONS
|
#define VK_ENABLE_BETA_EXTENSIONS
|
||||||
#define VK_NO_PROTOTYPES
|
#define VK_NO_PROTOTYPES
|
||||||
|
|
|
@ -47,13 +47,13 @@ std::string GetReadableVersion(u32 version) {
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
Instance::Instance(bool enable_validation, bool dump_command_buffers)
|
Instance::Instance(bool enable_validation, bool dump_command_buffers)
|
||||||
: instance{CreateInstance(dl, Frontend::WindowSystemType::Headless, enable_validation,
|
: instance{CreateInstance(Frontend::WindowSystemType::Headless, enable_validation,
|
||||||
dump_command_buffers)},
|
dump_command_buffers)},
|
||||||
physical_devices{instance->enumeratePhysicalDevices()} {}
|
physical_devices{instance->enumeratePhysicalDevices()} {}
|
||||||
|
|
||||||
Instance::Instance(Frontend::WindowSDL& window, s32 physical_device_index,
|
Instance::Instance(Frontend::WindowSDL& window, s32 physical_device_index,
|
||||||
bool enable_validation /*= false*/)
|
bool enable_validation /*= false*/)
|
||||||
: instance{CreateInstance(dl, window.getWindowInfo().type, enable_validation, false)},
|
: instance{CreateInstance(window.getWindowInfo().type, enable_validation, false)},
|
||||||
physical_devices{instance->enumeratePhysicalDevices()} {
|
physical_devices{instance->enumeratePhysicalDevices()} {
|
||||||
if (enable_validation) {
|
if (enable_validation) {
|
||||||
debug_callback = CreateDebugCallback(*instance);
|
debug_callback = CreateDebugCallback(*instance);
|
||||||
|
|
|
@ -17,12 +17,6 @@ class WindowSDL;
|
||||||
|
|
||||||
VK_DEFINE_HANDLE(VmaAllocator)
|
VK_DEFINE_HANDLE(VmaAllocator)
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#define VULKAN_LIBRARY_NAME "libMoltenVK.dylib"
|
|
||||||
#else
|
|
||||||
#define VULKAN_LIBRARY_NAME
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
|
|
||||||
class Instance {
|
class Instance {
|
||||||
|
@ -240,7 +234,6 @@ private:
|
||||||
vk::Format GetAlternativeFormat(const vk::Format format) const;
|
vk::Format GetAlternativeFormat(const vk::Format format) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vk::DynamicLoader dl{VULKAN_LIBRARY_NAME};
|
|
||||||
vk::UniqueInstance instance;
|
vk::UniqueInstance instance;
|
||||||
vk::PhysicalDevice physical_device;
|
vk::PhysicalDevice physical_device;
|
||||||
vk::UniqueDevice device;
|
vk::UniqueDevice device;
|
||||||
|
|
|
@ -20,6 +20,15 @@
|
||||||
#include "sdl_window.h"
|
#include "sdl_window.h"
|
||||||
#include "video_core/renderer_vulkan/vk_platform.h"
|
#include "video_core/renderer_vulkan/vk_platform.h"
|
||||||
|
|
||||||
|
#if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL
|
||||||
|
static vk::DynamicLoader dl;
|
||||||
|
#else
|
||||||
|
extern "C" {
|
||||||
|
VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance,
|
||||||
|
const char* pName);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
|
|
||||||
static const char* const VALIDATION_LAYER_NAME = "VK_LAYER_KHRONOS_validation";
|
static const char* const VALIDATION_LAYER_NAME = "VK_LAYER_KHRONOS_validation";
|
||||||
|
@ -186,12 +195,14 @@ std::vector<const char*> GetInstanceExtensions(Frontend::WindowSystemType window
|
||||||
return extensions;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::UniqueInstance CreateInstance(vk::DynamicLoader& dl, Frontend::WindowSystemType window_type,
|
vk::UniqueInstance CreateInstance(Frontend::WindowSystemType window_type, bool enable_validation,
|
||||||
bool enable_validation, bool dump_command_buffers) {
|
bool dump_command_buffers) {
|
||||||
LOG_INFO(Render_Vulkan, "Creating vulkan instance");
|
LOG_INFO(Render_Vulkan, "Creating vulkan instance");
|
||||||
|
|
||||||
|
#if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL
|
||||||
auto vkGetInstanceProcAddr =
|
auto vkGetInstanceProcAddr =
|
||||||
dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
dl.getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
|
||||||
|
#endif
|
||||||
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
|
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
|
||||||
|
|
||||||
const u32 available_version = VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion
|
const u32 available_version = VULKAN_HPP_DEFAULT_DISPATCHER.vkEnumerateInstanceVersion
|
||||||
|
@ -216,12 +227,19 @@ vk::UniqueInstance CreateInstance(vk::DynamicLoader& dl, Frontend::WindowSystemT
|
||||||
u32 num_layers = 0;
|
u32 num_layers = 0;
|
||||||
std::array<const char*, 2> layers;
|
std::array<const char*, 2> layers;
|
||||||
|
|
||||||
|
#if VULKAN_HPP_ENABLE_DYNAMIC_LOADER_TOOL
|
||||||
if (enable_validation) {
|
if (enable_validation) {
|
||||||
layers[num_layers++] = VALIDATION_LAYER_NAME;
|
layers[num_layers++] = VALIDATION_LAYER_NAME;
|
||||||
}
|
}
|
||||||
if (dump_command_buffers) {
|
if (dump_command_buffers) {
|
||||||
layers[num_layers++] = API_DUMP_LAYER_NAME;
|
layers[num_layers++] = API_DUMP_LAYER_NAME;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (enable_validation || dump_command_buffers) {
|
||||||
|
LOG_WARNING(Render_Vulkan,
|
||||||
|
"Skipping loading Vulkan layers as dynamic loading is not enabled.");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
vk::Bool32 enable_sync =
|
vk::Bool32 enable_sync =
|
||||||
enable_validation && Config::vkValidationSyncEnabled() ? vk::True : vk::False;
|
enable_validation && Config::vkValidationSyncEnabled() ? vk::True : vk::False;
|
||||||
|
|
|
@ -21,8 +21,8 @@ constexpr u32 TargetVulkanApiVersion = VK_API_VERSION_1_2;
|
||||||
|
|
||||||
vk::SurfaceKHR CreateSurface(vk::Instance instance, const Frontend::WindowSDL& emu_window);
|
vk::SurfaceKHR CreateSurface(vk::Instance instance, const Frontend::WindowSDL& emu_window);
|
||||||
|
|
||||||
vk::UniqueInstance CreateInstance(vk::DynamicLoader& dl, Frontend::WindowSystemType window_type,
|
vk::UniqueInstance CreateInstance(Frontend::WindowSystemType window_type, bool enable_validation,
|
||||||
bool enable_validation, bool dump_command_buffers);
|
bool dump_command_buffers);
|
||||||
|
|
||||||
vk::UniqueDebugUtilsMessengerEXT CreateDebugCallback(vk::Instance instance);
|
vk::UniqueDebugUtilsMessengerEXT CreateDebugCallback(vk::Instance instance);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue