-
Notifications
You must be signed in to change notification settings - Fork 2.1k
GPU: OpenXR integration #11601
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
Draft
Beyley
wants to merge
41
commits into
libsdl-org:main
Choose a base branch
from
Beyley:openxr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
GPU: OpenXR integration #11601
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
c24684c
gpu + openxr: Implement initial OpenXR support
Beyley e806f82
openxr: Fix docs syntax
Beyley cfbe815
gpu: Clean up XR func return values
Beyley 7221240
gpu + openxr: Add SDL_XRGPUSupportsProperties
Beyley 7eef00e
openxr: Put structure base header for typedefs
Beyley 77517b1
gpu: Attempt to fix d3d12 and metal GPU backends
Beyley c6c31f8
gpu: Fix d3d12 compilation, and probably metal compilation
Beyley 49ad40c
gpu: Wait for idle in VULKAN_DestroyXRSwapchain
Beyley 2ead74d
gpu + openxr: Turn XR device creation into property
Beyley bf5530c
gpu: fix d3d12+metal PrepareDriver func defs
Beyley 968dfaf
openxr: Add OpenXR sdk headers to repo
Beyley 3aeb7e3
cmake: Make DXVK and OpenXR depend on SDL_GPU
Beyley beece41
cmake: Escape SDL_GPU_OPENXR_DYNAMIC in cmake script
Beyley 210a1a6
gpu: Fix uninitialized variable usage in OpenXR physical device init
Beyley ee3121c
gpu: Fix uninitialized memory usage when checking OpenXR vulkan devic…
Beyley 229de57
gpu: Add property to specify form factor
Beyley 99e2d86
gpu: Fix warning on GCC
Beyley 8c72eb4
cmake: Make HAVE_GPU_OPENXR match rest of build config
Beyley d908081
gpu/vulkan: Use props OpenXR version in PrepareDriver
Beyley bc012a5
gpu/d3d12: Implement OpenXR session creation
Beyley 178b21b
gpu/d3d12: Initial buggy OpenXR swapchain support
Beyley 00cc157
openxr: Remove hardcoded debug soname
Beyley e66e3c3
openxr: Add hint to specify the set of OpenXR loader sonames to try
Beyley e1d49ce
openxr: Expose Load/Unload library + xrInstanceProcAddress
Beyley 1336aee
d3d12: Fix error logs
Beyley 23c8f72
openxr: Provide stub functions when OpenXR is disabled
Beyley 4cecdd6
d3d12: Use picked feature level in device creation
Beyley 4f783c3
cmake: Disable GPU on unsupported platforms
Beyley 12df40c
dynapi: fix OpenXR dynapi
Beyley ea60761
android: Add OpenXR files to android build
Beyley 523c88b
cmake + openxr: Pick library name in C file, not cmake
Beyley 543e41e
VisualC: Add OpenXR code
Beyley 2ad7798
android + VisualC: Add openxr include path
Beyley 14ac59f
openxr: Look for the OpenXR loader without a version suffix aswell
Beyley 0684bd3
VisualC: Add khronos to include path
Beyley 8c3b127
VisualC: minor spelling mistake
Beyley 7e9f5f4
cmake: Fix order of sources
Beyley c5d2ef8
build_config: Add OpenXR for android and windows build config
Beyley 7e8a52f
gpu/d3d12: Remove unreachable code in GetAdapterByLuid
Beyley ee37c68
openxr: Update OpenXR SDK to 1.1.45
Beyley f516f20
gpu+vulkan: WIP color target usage flags for OpenXR swapchains
Beyley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
andSDL_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
andwingdk.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)There was a problem hiding this comment.
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.
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.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.