Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU: OpenXR integration #11601

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
6bdef3e
gpu + openxr: Implement initial OpenXR support
Beyley Sep 29, 2024
d8dfe52
openxr: Fix docs syntax
Beyley Dec 22, 2024
f1837f5
gpu: Clean up XR func return values
Beyley Dec 22, 2024
d55b0b9
gpu + openxr: Add SDL_XRGPUSupportsProperties
Beyley Dec 22, 2024
6712ff9
openxr: Put structure base header for typedefs
Beyley Dec 23, 2024
125748b
gpu: Attempt to fix d3d12 and metal GPU backends
Beyley Dec 23, 2024
fc38758
gpu: Fix d3d12 compilation, and probably metal compilation
Beyley Dec 23, 2024
eafbe9c
gpu: Wait for idle in VULKAN_DestroyXRSwapchain
Beyley Dec 23, 2024
5ad6b79
gpu + openxr: Turn XR device creation into property
Beyley Dec 24, 2024
6f70321
gpu: fix d3d12+metal PrepareDriver func defs
Beyley Dec 24, 2024
fed16d7
openxr: Add OpenXR sdk headers to repo
Beyley Dec 24, 2024
56e4c0e
cmake: Make DXVK and OpenXR depend on SDL_GPU
Beyley Dec 24, 2024
95c8233
cmake: Escape SDL_GPU_OPENXR_DYNAMIC in cmake script
Beyley Dec 24, 2024
da5026c
gpu: Fix uninitialized variable usage in OpenXR physical device init
Beyley Dec 24, 2024
02d0e80
gpu: Fix uninitialized memory usage when checking OpenXR vulkan devic…
Beyley Dec 24, 2024
3b5ddbe
gpu: Add property to specify form factor
Beyley Dec 24, 2024
451af4d
gpu: Fix warning on GCC
Beyley Dec 24, 2024
0882b0a
cmake: Make HAVE_GPU_OPENXR match rest of build config
Beyley Dec 24, 2024
d583a39
gpu/vulkan: Use props OpenXR version in PrepareDriver
Beyley Jan 10, 2025
a75107b
gpu/d3d12: Implement OpenXR session creation
Beyley Jan 10, 2025
5de7279
gpu/d3d12: Initial buggy OpenXR swapchain support
Beyley Jan 10, 2025
0597fb2
openxr: Remove hardcoded debug soname
Beyley Jan 22, 2025
025c403
openxr: Add hint to specify the set of OpenXR loader sonames to try
Beyley Jan 23, 2025
908967c
openxr: Expose Load/Unload library + xrInstanceProcAddress
Beyley Jan 23, 2025
e330f70
d3d12: Fix error logs
Beyley Jan 23, 2025
3623c8e
openxr: Provide stub functions when OpenXR is disabled
Beyley Jan 23, 2025
d88fb9a
d3d12: Use picked feature level in device creation
Beyley Jan 24, 2025
9a061cc
cmake: Disable GPU on unsupported platforms
Beyley Jan 24, 2025
33a7cef
dynapi: fix OpenXR dynapi
Beyley Jan 24, 2025
4d69dab
android: Add OpenXR files to android build
Beyley Jan 24, 2025
f85d407
cmake + openxr: Pick library name in C file, not cmake
Beyley Jan 24, 2025
e89ce1d
VisualC: Add OpenXR code
Beyley Jan 24, 2025
a29e2c3
android + VisualC: Add openxr include path
Beyley Jan 24, 2025
3af8e4c
openxr: Look for the OpenXR loader without a version suffix aswell
Beyley Jan 24, 2025
0595740
VisualC: Add khronos to include path
Beyley Jan 24, 2025
ffc34ba
VisualC: minor spelling mistake
Beyley Jan 24, 2025
8452972
cmake: Fix order of sources
Beyley Jan 24, 2025
0b74e42
build_config: Add OpenXR for android and windows build config
Beyley Jan 24, 2025
4f3db73
gpu/d3d12: Remove unreachable code in GetAdapterByLuid
Beyley Jan 24, 2025
d64e41f
openxr: Update OpenXR SDK to 1.1.45
Beyley Feb 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include $(CLEAR_VARS)

LOCAL_MODULE := SDL3

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/include/build_config $(LOCAL_PATH)/src
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/include/build_config $(LOCAL_PATH)/src $(LOCAL_PATH)/src/video/khronos

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include

Expand Down Expand Up @@ -39,6 +39,7 @@ LOCAL_SRC_FILES := \
$(wildcard $(LOCAL_PATH)/src/io/generic/*.c) \
$(wildcard $(LOCAL_PATH)/src/gpu/*.c) \
$(wildcard $(LOCAL_PATH)/src/gpu/vulkan/*.c) \
$(wildcard $(LOCAL_PATH)/src/gpu/xr/*.c) \
$(wildcard $(LOCAL_PATH)/src/haptic/*.c) \
$(wildcard $(LOCAL_PATH)/src/haptic/android/*.c) \
$(wildcard $(LOCAL_PATH)/src/haptic/dummy/*.c) \
Expand Down
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ if(VITA OR PSP OR PS2 OR N3DS OR RISCOS)
set(SDL_SHARED_AVAILABLE OFF)
endif()

set(SDL_GPU_DEFAULT ON)
if(RISCOS OR N3DS OR PS2 OR PSP OR VITA OR EMSCRIPTEN)
set(SDL_GPU_DEFAULT OFF)
endif()

if((RISCOS OR UNIX_SYS) AND NOT (LINUX OR NETBSD OR OPENBSD))
set(SDL_OSS_DEFAULT ON)
else()
Expand Down Expand Up @@ -384,7 +389,8 @@ set_option(SDL_LIBUDEV "Enable libudev support" ON)
set_option(SDL_ASAN "Use AddressSanitizer to detect memory errors" OFF)
set_option(SDL_CCACHE "Use Ccache to speed up build" OFF)
set_option(SDL_CLANG_TIDY "Run clang-tidy static analysis" OFF)
set_option(SDL_GPU_DXVK "Build SDL_GPU with DXVK support" OFF)
dep_option(SDL_GPU_DXVK "Build SDL_GPU with DXVK support" OFF SDL_GPU OFF)
dep_option(SDL_GPU_OPENXR "Build SDL_GPU with OpenXR support" ON SDL_GPU OFF)

set(SDL_VENDOR_INFO "" CACHE STRING "Vendor name and/or version to add to SDL_REVISION")

Expand Down Expand Up @@ -1162,6 +1168,7 @@ sdl_glob_sources(
"${SDL3_SOURCE_DIR}/src/io/generic/*.c"
"${SDL3_SOURCE_DIR}/src/filesystem/*.c"
"${SDL3_SOURCE_DIR}/src/gpu/*.c"
"${SDL3_SOURCE_DIR}/src/gpu/xr/*.c"
"${SDL3_SOURCE_DIR}/src/joystick/*.c"
"${SDL3_SOURCE_DIR}/src/haptic/*.c"
"${SDL3_SOURCE_DIR}/src/hidapi/*.c"
Expand Down Expand Up @@ -3021,6 +3028,9 @@ if(SDL_GPU)
set(SDL_VIDEO_RENDER_GPU 1)
set(HAVE_RENDER_GPU TRUE)
endif()
if(SDL_GPU_OPENXR)
set(HAVE_GPU_OPENXR 1)
endif()
endif()

# Dummies
Expand Down
12 changes: 10 additions & 2 deletions VisualC-GDK/SDL/SDL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Gaming.Xbox.XboxOne.x64'" />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Gaming.Desktop.x64'">
<IncludePath>$(ProjectDir)../../src;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)../../src;$(ProjectDir)../../src/video/khronos;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Gaming.Desktop.x64'">
<IncludePath>$(ProjectDir)../../src;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)../../src;$(ProjectDir)../../src/video/khronos;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Gaming.Desktop.x64'">
<Midl>
Expand Down Expand Up @@ -558,6 +558,12 @@
<ClInclude Include="..\..\src\video\dummy\SDL_nullframebuffer_c.h" />
<ClInclude Include="..\..\src\video\dummy\SDL_nullvideo.h" />
<ClInclude Include="..\..\src\video\gdk\SDL_gdktextinput.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr_platform.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr_reflection.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr_reflection_parent_structs.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr_loader_negotiation.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr_platform_defines.h" />
<ClInclude Include="..\..\src\video\khronos\vulkan\vk_icd.h" />
<ClInclude Include="..\..\src\video\khronos\vulkan\vk_layer.h" />
<ClInclude Include="..\..\src\video\khronos\vulkan\vk_platform.h" />
Expand Down Expand Up @@ -894,6 +900,8 @@
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Gaming.Xbox.XboxOne.x64'">CompileAsCpp</CompileAs>
</ClCompile>
<ClCompile Include="..\..\src\gpu\vulkan\SDL_gpu_vulkan.c" />
<ClCompile Include="..\..\src\gpu\xr\SDL_gpu_openxr.c" />
<ClCompile Include="..\..\src\gpu\xr\SDL_openxrdyn.c" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\src\core\windows\version.rc" />
Expand Down
16 changes: 12 additions & 4 deletions VisualC/SDL/SDL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@
<LibraryPath Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>$(ProjectDir)/../../src;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)/../../src;$(ProjectDir)../../src/video/khronos;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>$(ProjectDir)/../../src;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)/../../src;$(ProjectDir)../../src/video/khronos;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>$(ProjectDir)/../../src;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)/../../src;$(ProjectDir)../../src/video/khronos;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>$(ProjectDir)/../../src;$(IncludePath)</IncludePath>
<IncludePath>$(ProjectDir)/../../src;$(ProjectDir)../../src/video/khronos;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<PreBuildEvent>
Expand Down Expand Up @@ -423,6 +423,8 @@
<ClCompile Include="..\..\src\gpu\SDL_gpu.c" />
<ClCompile Include="..\..\src\gpu\d3d12\SDL_gpu_d3d12.c" />
<ClCompile Include="..\..\src\gpu\vulkan\SDL_gpu_vulkan.c" />
<ClCompile Include="..\..\src\gpu\xr\SDL_gpu_openxr.c" />
<ClCompile Include="..\..\src\gpu\xr\SDL_openxrdyn.c" />
<ClCompile Include="..\..\src\io\generic\SDL_asyncio_generic.c" />
<ClCompile Include="..\..\src\io\SDL_asyncio.c" />
<ClCompile Include="..\..\src\main\generic\SDL_sysmain_callbacks.c" />
Expand Down Expand Up @@ -452,6 +454,12 @@
<ClInclude Include="..\..\src\video\dummy\SDL_nullevents_c.h" />
<ClInclude Include="..\..\src\video\dummy\SDL_nullframebuffer_c.h" />
<ClInclude Include="..\..\src\video\dummy\SDL_nullvideo.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr_platform.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr_reflection.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr_reflection_parent_structs.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr_loader_negotiation.h" />
<ClInclude Include="..\..\src\video\khronos\openxr\openxr_platform_defines.h" />
<ClInclude Include="..\..\src\video\khronos\vulkan\vk_icd.h" />
<ClInclude Include="..\..\src\video\khronos\vulkan\vk_layer.h" />
<ClInclude Include="..\..\src\video\khronos\vulkan\vk_platform.h" />
Expand Down
14 changes: 14 additions & 0 deletions include/SDL3/SDL_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,20 @@ extern SDL_DECLSPEC SDL_GPUDevice * SDLCALL SDL_CreateGPUDeviceWithProperties(
#define SDL_PROP_GPU_DEVICE_CREATE_SHADERS_METALLIB_BOOLEAN "SDL.gpu.device.create.shaders.metallib"
#define SDL_PROP_GPU_DEVICE_CREATE_D3D12_SEMANTIC_NAME_STRING "SDL.gpu.device.create.d3d12.semantic"

#define SDL_PROP_GPU_DEVICE_CREATE_XR_ENABLE "SDL.gpu.device.create.xr.enable"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_INSTANCE_OUT "SDL.gpu.device.create.xr.instance_out"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_SYSTEM_ID_OUT "SDL.gpu.device.create.xr.system_id_out"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_VERSION "SDL.gpu.device.create.xr.version"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_FORM_FACTOR "SDL.gpu.device.create.xr.form_factor"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_EXTENSION_COUNT "SDL.gpu.device.create.xr.extensions.count"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_EXTENSION_NAMES "SDL.gpu.device.create.xr.extensions.names"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_LAYER_COUNT "SDL.gpu.device.create.xr.layers.count"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_LAYER_NAMES "SDL.gpu.device.create.xr.layers.names"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_APPLICATION_NAME "SDL.gpu.device.create.xr.application.name"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_APPLICATION_VERSION "SDL.gpu.device.create.xr.application.version"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_ENGINE_NAME "SDL.gpu.device.create.xr.engine.name"
#define SDL_PROP_GPU_DEVICE_CREATE_XR_ENGINE_VERSION "SDL.gpu.device.create.xr.engine.version"

/**
* Destroys a GPU context previously returned by SDL_CreateGPUDevice.
*
Expand Down
14 changes: 14 additions & 0 deletions include/SDL3/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,20 @@ extern "C" {
*/
#define SDL_HINT_GPU_DRIVER "SDL_GPU_DRIVER"

/**
* A variable that specifies which library names to look for when loading the OpenXR loader
*
* By default, SDL will try the system default name, but on some platforms like Windows,
* debug builds of the OpenXR loader have a different name, and are not always directly compatible with release applications.
* Setting this hint allows you to compensate for this difference in your app when applicable.
*
* This variable accepts a comma-separated list of library names to check.
*
* This hint should be set before the OpenXR loader is loaded.
* For example, creating an OpenXR GPU device will load the OpenXR lodaer.
*/
#define SDL_HINT_OPENXR_SONAMES "SDL_OPENXR_SONAMES"

/**
* A variable to control whether SDL_hid_enumerate() enumerates all HID
* devices or only controllers.
Expand Down
186 changes: 186 additions & 0 deletions include/SDL3/SDL_openxr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2024 Sam Lantinga <[email protected]>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

/**
* # CategoryOpenXR
*
* Functions for creating OpenXR handles for SDL_gpu contexts.
*
* For the most part, OpenXR operates independent of SDL, but
* the graphics initialization depends on direct support from SDL_gpu.
*
*/

#ifndef SDL_openxr_h_
#define SDL_openxr_h_

#include <SDL3/SDL_stdinc.h>
#include <SDL3/SDL_gpu.h>

#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif

#if defined(OPENXR_H_)
#define NO_SDL_OPENXR_TYPEDEFS 1
#endif /* OPENXR_H_ */

#if !defined(NO_SDL_OPENXR_TYPEDEFS)
#define XR_NULL_HANDLE 0

#if !defined(XR_DEFINE_HANDLE)
#define XR_DEFINE_HANDLE(object) typedef Uint64 object;
#endif /* XR_DEFINE_HANDLE */

typedef enum XrStructureType {
XR_TYPE_SESSION_CREATE_INFO = 8,
XR_TYPE_SWAPCHAIN_CREATE_INFO = 9,
} XrStructureType;

XR_DEFINE_HANDLE(XrInstance)
XR_DEFINE_HANDLE(XrSystemId)
XR_DEFINE_HANDLE(XrSession)
XR_DEFINE_HANDLE(XrSwapchain)

typedef struct {
XrStructureType type;
const void* next;
} XrSessionCreateInfo;
typedef struct {
XrStructureType type;
const void* next;
} XrSwapchainCreateInfo;

typedef enum XrResult {
XR_ERROR_FUNCTION_UNSUPPORTED = -7,
XR_ERROR_HANDLE_INVALID = -12,
} XrResult;

#define PFN_xrGetInstanceProcAddr SDL_FunctionPointer
#endif /* NO_SDL_OPENXR_TYPEDEFS */

/**
* Creates an OpenXR session. The OpenXR system ID is pulled from the passed GPU context.
*
* \param device a GPU context.
* \param createinfo the create info for the OpenXR session, sans the system ID.
* \param session an OpenXR session created for the given **device**.
* \returns the result of the call.
*
* \sa SDL_CreateGPUDeviceWithProperties
*/
extern SDL_DECLSPEC XrResult SDLCALL SDL_CreateGPUXRSession(
SDL_GPUDevice *device,
const XrSessionCreateInfo *createinfo,
XrSession *session);

/**
* Creates an OpenXR swapchain.
*
* \param device a GPU context.
* \param session an OpenXR session created for the given **device**.
* \param createinfo the create info for the OpenXR swapchain, sans the format.
* \param textureFormat a pointer to store the format of the created swapchain.
* \param swapchain a pointer to store the created OpenXR swapchain.
* \param textures a pointer to store the list of created swapchain images.
* \returns the result of the call.
*
* \sa SDL_CreateGPUDeviceWithProperties
* \sa SDL_CreateGPUXRSession
* \sa SDL_DestroyGPUXRSwapchain
*/

/* TODO: figure out then document what usageFlags are actually possible to be supported by SDL_gpu */
extern SDL_DECLSPEC XrResult SDLCALL SDL_CreateGPUXRSwapchain(
SDL_GPUDevice *device,
XrSession session,
const XrSwapchainCreateInfo *createinfo,
SDL_GPUTextureFormat *textureFormat,
XrSwapchain *swapchain,
SDL_GPUTexture ***textures);

/**
* Destroys and OpenXR swapchain previously returned by SDL_CreateGPUXRSwapchain.
*
* \param device a GPU context.
* \param swapchain a swapchain previously returned by SDL_CreateGPUXRSwapchain.
* \param swapchainImages an array of swapchain images returned by the same call to SDL_CreateGPUXRSwapchain.
* \returns the result of the call.
*
* \sa SDL_CreateGPUDeviceWithProperties
* \sa SDL_CreateGPUXRSession
* \sa SDL_CreateGPUXRSwapchain
*/
extern SDL_DECLSPEC XrResult SDLCALL SDL_DestroyGPUXRSwapchain(SDL_GPUDevice *device, XrSwapchain swapchain, SDL_GPUTexture **swapchainImages);

/**
* Dynamically load the OpenXR loader. This can be called at any time.
*
* SDL keeps a reference count of the OpenXR loader, calling this function multiple
* times will increment that count, rather than loading the library multiple times.
*
* If not called, this will be implicitly called when creating a GPU device with OpenXR.
*
* This function will use the platform default OpenXR loader name,
* unless the `SDL_HINT_OPENXR_SONAMES` hint is set.
*
* \returns whether the call succeeded or not.
*
* \threadsafety This function is not thread safe.
*
* \sa SDL_HINT_OPENXR_SONAMES
*/
extern SDL_DECLSPEC bool SDLCALL SDL_OpenXR_LoadLibrary(void);

/**
* Unload the OpenXR loader previously loaded by SDL_OpenXR_LoadLibrary.
*
* SDL keeps a reference count of the OpenXR loader, calling this function will decrement that count.
* Once the reference count reaches zero, the library is unloaded.
*
* \threadsafety This function is not thread safe.
*/
extern SDL_DECLSPEC void SDLCALL SDL_OpenXR_UnloadLibrary(void);

/**
* Get the address of the `xrGetInstanceProcAddr` function.
*
* This should be called after either calling SDL_OpenXR_LoadLibrary() or
* creating an OpenXR SDL_GPUDevice.
*
* The actual type of the returned function pointer is PFN_xrGetInstanceProcAddr,
* but that isn't always available. You should include the OpenXR headers before this header,
* or cast the return value of this function to the correct type.
*
* \returns the function pointer for `xrGetInstanceProcAddr` or NULL on
* failure; call SDL_GetError() for more information.
*/
extern SDL_DECLSPEC PFN_xrGetInstanceProcAddr SDLCALL SDL_OpenXR_GetXrGetInstanceProcAddr(void);

/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include <SDL3/SDL_close_code.h>

#endif /* SDL_openxr_h_ */
1 change: 1 addition & 0 deletions include/build_config/SDL_build_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@
#cmakedefine SDL_GPU_D3D12 1
#cmakedefine SDL_GPU_VULKAN 1
#cmakedefine SDL_GPU_METAL 1
#cmakedefine HAVE_GPU_OPENXR 1
Copy link
Contributor

@madebr madebr Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to add this to SDL_build_config_android.h and SDL_build_config_windows.h.

Does SDL_build_config_macos.h/ios.h also need it? Or doesn't this work on top of MoltenVK?

I'm not sure about SDL_build_config_xbox.h and wingdk.h. You're adding a d3d12 backend here, so it can work. But loading shared libraries will not work (on xbox) (but I'm not a specialist, so don't quote me)

Copy link
Author

@Beyley Beyley Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added it for the Windows and Android build configs.

Does SDL_build_config_macos.h/ios.h also need it?

For now, it's not necessary per-se.

Theoretically the openxrdyn bits should work fine as-is on MacOS/iOS (assuming you can dynamically load on iOS, I've never written for that platform), and once someone writes OpenXR support into the Metal backend (MoltenVK does not work due to missing extensions last I heard), it should just kick into action.

I'm not sure about SDL_build_config_xbox.h and wingdk.h. You're adding a d3d12 backend here, so it can work.

afaik, there's no OpenXR loader or headset for the Xbox, so it probably shouldnt have it. It'd just be dead weight on that platform.

I've heard secondhand for the PS5 there is an OpenXR compatibility layer allowing you to develop using it for the PSVR2 on PS5, but I dont have the developer credentials to actually see what that looks like, or much of anything about it. So if someone comes around wanting SDL_gpu OpenXR support on PS5, I'm not sure how well the current code would be suited to support that. Ideally someone with PS5 developer credentials comes around and gives pointers for what would need to be changed before merging to make that path more accessible in the future.


/* Enable system power support */
#cmakedefine SDL_POWER_ANDROID 1
Expand Down
1 change: 1 addition & 0 deletions include/build_config/SDL_build_config_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
#define SDL_VIDEO_RENDER_VULKAN 1
#define SDL_GPU_VULKAN 1
#define SDL_VIDEO_RENDER_GPU 1
#define HAVE_GPU_OPENXR 1
#endif

/* Enable system power support */
Expand Down
1 change: 1 addition & 0 deletions include/build_config/SDL_build_config_windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ typedef unsigned int uintptr_t;
#define SDL_GPU_D3D12 1
#define SDL_GPU_VULKAN 1
#define SDL_VIDEO_RENDER_GPU 1
#define HAVE_GPU_OPENXR 1

/* Enable system power support */
#define SDL_POWER_WINDOWS 1
Expand Down
1 change: 1 addition & 0 deletions src/SDL_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
#undef SDL_GPU_D3D12
#undef SDL_GPU_METAL
#undef SDL_GPU_VULKAN
#undef HAVE_GPU_OPENXR
#undef SDL_VIDEO_RENDER_GPU
#endif // SDL_GPU_DISABLED

Expand Down
Loading