Skip to content

Commit

Permalink
Improve NX Vulkan support.
Browse files Browse the repository at this point in the history
This change was developed using publicly available information found in Vulkan headers and official documentation. No proprietary NX resources were used.
  • Loading branch information
kalmard0 committed Sep 30, 2024
1 parent f8b2061 commit 2947c52
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/renderer_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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_
Expand Down
10 changes: 10 additions & 0 deletions src/renderer_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vulkan-local/vulkan.h>
#include <vulkan-local/vulkan_beta.h>

Expand Down Expand Up @@ -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); \
Expand Down

0 comments on commit 2947c52

Please sign in to comment.