mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2026-06-16 21:13:16 +00:00
178 lines
6.5 KiB
Diff
178 lines
6.5 KiB
Diff
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
index 6a7645a..6e6e887 100644
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -8,10 +8,16 @@ if(APPLE)
|
|
endif()
|
|
|
|
string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "Linux" IS_LINUX)
|
|
+string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} "iOS" IS_IOS)
|
|
+if(IS_LINUX OR IS_IOS)
|
|
+ set(IS_SDL_VULKAN_PLATFORM ON)
|
|
+else()
|
|
+ set(IS_SDL_VULKAN_PLATFORM OFF)
|
|
+endif()
|
|
|
|
# Project options
|
|
include(CMakeDependentOption)
|
|
-cmake_dependent_option(SDL_VULKAN_ENABLED "Enable SDL Vulkan integration" OFF IS_LINUX OFF)
|
|
+cmake_dependent_option(SDL_VULKAN_ENABLED "Enable SDL Vulkan integration" OFF IS_SDL_VULKAN_PLATFORM OFF)
|
|
cmake_dependent_option(D3D12_AGILITY_SDK_ENABLED "Enable D3D12 Agility SDK" OFF WIN32 OFF)
|
|
option(PLUME_BUILD_EXAMPLES "Build example applications" OFF)
|
|
|
|
@@ -50,7 +56,7 @@ set(PLUME_SOURCES
|
|
)
|
|
|
|
# Platform-specific files
|
|
-if(APPLE)
|
|
+if(APPLE AND NOT IS_IOS)
|
|
list(APPEND PLUME_SOURCES
|
|
plume_metal.cpp
|
|
plume_metal.h
|
|
@@ -94,7 +100,7 @@ if(D3D12_AGILITY_SDK_ENABLED)
|
|
endif()
|
|
|
|
# Platform-specific includes
|
|
-if(APPLE)
|
|
+if(APPLE AND NOT IS_IOS)
|
|
target_include_directories(plume PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/contrib/metal-cpp
|
|
)
|
|
diff --git a/plume_vulkan.cpp b/plume_vulkan.cpp
|
|
index 9103ca8..63de1cc 100644
|
|
--- a/plume_vulkan.cpp
|
|
+++ b/plume_vulkan.cpp
|
|
@@ -8,6 +8,9 @@
|
|
#define VMA_IMPLEMENTATION
|
|
#define VOLK_IMPLEMENTATION
|
|
|
|
+#if defined(__APPLE__) && defined(SDL_VULKAN_ENABLED)
|
|
+#include "plume_volk_rename_ios.h"
|
|
+#endif
|
|
#include "plume_vulkan.h"
|
|
|
|
#include <algorithm>
|
|
@@ -19,6 +22,10 @@
|
|
# include "render/plume_dlss.h"
|
|
#endif
|
|
|
|
+#if defined(__APPLE__) && defined(SDL_VULKAN_ENABLED)
|
|
+extern "C" VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL mvkGetInstanceProcAddr(VkInstance instance, const char *pName) __asm("_vkGetInstanceProcAddr");
|
|
+#endif
|
|
+
|
|
#ifndef NDEBUG
|
|
# define VULKAN_VALIDATION_LAYER_ENABLED
|
|
# define VULKAN_OBJECT_NAMES_ENABLED
|
|
@@ -88,6 +95,19 @@ namespace plume {
|
|
VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME,
|
|
};
|
|
|
|
+ static std::unordered_set<std::string> getRequiredDeviceExtensions(uint32_t apiVersion) {
|
|
+ std::unordered_set<std::string> extensions = RequiredDeviceExtensions;
|
|
+
|
|
+ // MoltenVK and other Vulkan 1.2+ implementations expose these as core features
|
|
+ // and no longer enumerate them as separate device extensions.
|
|
+ if (apiVersion >= VK_API_VERSION_1_2) {
|
|
+ extensions.erase(VK_KHR_BUFFER_DEVICE_ADDRESS_EXTENSION_NAME);
|
|
+ extensions.erase(VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME);
|
|
+ }
|
|
+
|
|
+ return extensions;
|
|
+ }
|
|
+
|
|
// Common functions.
|
|
|
|
static uint32_t roundUp(uint32_t value, uint32_t powerOf2Alignment) {
|
|
@@ -2112,6 +2132,12 @@ namespace plume {
|
|
fprintf(stderr, "vkCreateXlibSurfaceKHR failed with error code 0x%X.\n", res);
|
|
return;
|
|
}
|
|
+# elif defined(__APPLE__) && defined(SDL_VULKAN_ENABLED)
|
|
+ VulkanInterface *renderInterface = commandQueue->device->renderInterface;
|
|
+ if (!SDL_Vulkan_CreateSurface(renderWindow, renderInterface->instance, &surface)) {
|
|
+ fprintf(stderr, "SDL_Vulkan_CreateSurface failed: %s.\n", SDL_GetError());
|
|
+ return;
|
|
+ }
|
|
# elif defined(__APPLE__)
|
|
assert(renderWindow.window != 0);
|
|
assert(renderWindow.view != 0);
|
|
@@ -2443,7 +2469,7 @@ namespace plume {
|
|
// The attributes width and height members do not include the border.
|
|
dstWidth = attributes.width;
|
|
dstHeight = attributes.height;
|
|
-# elif defined(__APPLE__)
|
|
+# elif defined(__APPLE__) && !defined(SDL_VULKAN_ENABLED)
|
|
CocoaWindowAttributes attributes;
|
|
windowWrapper->getWindowAttributes(&attributes);
|
|
dstWidth = attributes.width;
|
|
@@ -3754,6 +3780,10 @@ namespace plume {
|
|
return;
|
|
}
|
|
|
|
+ VkPhysicalDeviceProperties selectedDeviceProperties;
|
|
+ vkGetPhysicalDeviceProperties(physicalDevice, &selectedDeviceProperties);
|
|
+ const std::unordered_set<std::string> requiredDeviceExtensions = getRequiredDeviceExtensions(selectedDeviceProperties.apiVersion);
|
|
+
|
|
// Check for extensions.
|
|
uint32_t extensionCount;
|
|
vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &extensionCount, nullptr);
|
|
@@ -3761,7 +3791,7 @@ namespace plume {
|
|
std::vector<VkExtensionProperties> availableExtensions(extensionCount);
|
|
vkEnumerateDeviceExtensionProperties(physicalDevice, nullptr, &extensionCount, availableExtensions.data());
|
|
|
|
- std::unordered_set<std::string> missingRequiredExtensions = RequiredDeviceExtensions;
|
|
+ std::unordered_set<std::string> missingRequiredExtensions = requiredDeviceExtensions;
|
|
std::unordered_set<std::string> supportedOptionalExtensions;
|
|
# if DLSS_ENABLED
|
|
const std::unordered_set<std::string> dlssExtensions = DLSS::getRequiredDeviceExtensionsVulkan(this);
|
|
@@ -3969,7 +3999,7 @@ namespace plume {
|
|
}
|
|
|
|
std::vector<const char *> enabledExtensions;
|
|
- for (const std::string &extension : RequiredDeviceExtensions) {
|
|
+ for (const std::string &extension : requiredDeviceExtensions) {
|
|
enabledExtensions.push_back(extension.c_str());
|
|
}
|
|
|
|
@@ -4398,11 +4428,16 @@ namespace plume {
|
|
#else
|
|
VulkanInterface::VulkanInterface() {
|
|
#endif
|
|
- VkResult res = volkInitialize();
|
|
+ VkResult res = VK_SUCCESS;
|
|
+#if defined(__APPLE__) && defined(SDL_VULKAN_ENABLED)
|
|
+ volkInitializeCustom(mvkGetInstanceProcAddr);
|
|
+#else
|
|
+ res = volkInitialize();
|
|
if (res != VK_SUCCESS) {
|
|
fprintf(stderr, "volkInitialize failed with error code 0x%X.\n", res);
|
|
return;
|
|
}
|
|
+#endif
|
|
|
|
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
|
appInfo.pApplicationName = "plume";
|
|
diff --git a/plume_vulkan.h b/plume_vulkan.h
|
|
index 73022bb..9d89adf 100644
|
|
--- a/plume_vulkan.h
|
|
+++ b/plume_vulkan.h
|
|
@@ -22,8 +22,10 @@
|
|
#define VK_USE_PLATFORM_XLIB_KHR
|
|
#elif defined(__APPLE__)
|
|
#define VK_USE_PLATFORM_METAL_EXT
|
|
+#ifndef SDL_VULKAN_ENABLED
|
|
#include "plume_apple.h"
|
|
#endif
|
|
+#endif
|
|
|
|
// For VK_KHR_portability_subset
|
|
#define VK_ENABLE_BETA_EXTENSIONS
|
|
@@ -226,7 +228,7 @@ namespace plume {
|
|
VulkanCommandQueue *commandQueue = nullptr;
|
|
VkSurfaceKHR surface = VK_NULL_HANDLE;
|
|
RenderWindow renderWindow = {};
|
|
-#if defined(__APPLE__)
|
|
+#if defined(__APPLE__) && !defined(SDL_VULKAN_ENABLED)
|
|
std::unique_ptr<CocoaWindow> windowWrapper;
|
|
#endif
|
|
uint32_t textureCount = 0;
|