From badbef7bbad0044f0d53b042930cdc4f95cc4b51 Mon Sep 17 00:00:00 2001 From: Daniel Kalmar Date: Mon, 30 Sep 2024 23:03:39 +0200 Subject: [PATCH] Improve NX Vulkan support. This change was developed using publicly available information found in Vulkan headers and official documentation. No proprietary NX resources were used. --- src/renderer_vk.cpp | 26 ++++++++++++++++++++++++++ src/renderer_vk.h | 10 ++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index b36f3be3a1..ca95e04503 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -1172,6 +1172,7 @@ VK_IMPORT_DEVICE setGraphicsDebuggerPresent(NULL != m_renderDocDll); +#if defined(VK_NO_PROTOTYPES) m_vulkan1Dll = bx::dlopen( #if BX_PLATFORM_WINDOWS "vulkan-1.dll" @@ -1203,6 +1204,21 @@ VK_IMPORT #undef VK_IMPORT_FUNC +#else // VK_NO_PROTOTYPES + + vkGetInstanceProcAddr = ::vkGetInstanceProcAddr; + vkGetDeviceProcAddr = ::vkGetDeviceProcAddr; +#define VK_IMPORT_FUNC(_optional, _func) \ + if (NULL == _func) { \ + _func = (PFN_##_func)vkGetInstanceProcAddr(NULL, #_func); \ + BX_TRACE("\t%p " #_func, _func); \ + imported &= _optional || NULL != _func; \ + } while(0) + +VK_IMPORT +#undef VK_IMPORT_FUNC +#endif // VK_NO_PROTOTYPES + if (!imported) { BX_TRACE("Init error: Failed to load shared library functions."); @@ -7022,6 +7038,16 @@ VK_DESTROY result = vkCreateMacOSSurfaceMVK(instance, &sci, allocatorCb, &m_surface); } } +#elif BX_PLATFORM_NX + if (NULL != vkCreateViSurfaceNN) + { + VkViSurfaceCreateInfoNN sci; + sci.sType = VK_STRUCTURE_TYPE_VI_SURFACE_CREATE_INFO_NN; + sci.pNext = NULL; + sci.flags = 0; + sci.window = m_nwh; + result = vkCreateViSurfaceNN(instance, &sci, allocatorCb, &m_surface); + } #else # error "Figure out KHR surface..." #endif // BX_PLATFORM_ diff --git a/src/renderer_vk.h b/src/renderer_vk.h index b138ba9eb6..1d39b8d862 100644 --- a/src/renderer_vk.h +++ b/src/renderer_vk.h @@ -31,13 +31,19 @@ # define VK_USE_PLATFORM_MACOS_MVK # define KHR_SURFACE_EXTENSION_NAME VK_MVK_MACOS_SURFACE_EXTENSION_NAME # define VK_IMPORT_INSTANCE_PLATFORM VK_IMPORT_INSTANCE_MACOS +#elif BX_PLATFORM_NX +# define VK_USE_PLATFORM_VI_NN +# define KHR_SURFACE_EXTENSION_NAME VK_NN_VI_SURFACE_EXTENSION_NAME +# define VK_IMPORT_INSTANCE_PLATFORM VK_IMPORT_INSTANCE_NX #else # define KHR_SURFACE_EXTENSION_NAME "" # define VK_IMPORT_INSTANCE_PLATFORM #endif // BX_PLATFORM_* #define VK_NO_STDINT_H +#if !BX_PLATFORM_NX #define VK_NO_PROTOTYPES +#endif #include #include @@ -102,6 +108,10 @@ /* VK_MVK_macos_surface */ \ VK_IMPORT_INSTANCE_FUNC(true, vkCreateMacOSSurfaceMVK); \ +#define VK_IMPORT_INSTANCE_NX \ + /* VK_NN_vi_surface */ \ + VK_IMPORT_INSTANCE_FUNC(true, vkCreateViSurfaceNN); \ + #define VK_IMPORT_INSTANCE \ VK_IMPORT_INSTANCE_FUNC(false, vkDestroyInstance); \ VK_IMPORT_INSTANCE_FUNC(false, vkEnumeratePhysicalDevices); \