-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Beyley
wants to merge
40
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.
Open
GPU: OpenXR integration #11601
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 d8dfe52
openxr: Fix docs syntax
Beyley f1837f5
gpu: Clean up XR func return values
Beyley d55b0b9
gpu + openxr: Add SDL_XRGPUSupportsProperties
Beyley 6712ff9
openxr: Put structure base header for typedefs
Beyley 125748b
gpu: Attempt to fix d3d12 and metal GPU backends
Beyley fc38758
gpu: Fix d3d12 compilation, and probably metal compilation
Beyley eafbe9c
gpu: Wait for idle in VULKAN_DestroyXRSwapchain
Beyley 5ad6b79
gpu + openxr: Turn XR device creation into property
Beyley 6f70321
gpu: fix d3d12+metal PrepareDriver func defs
Beyley fed16d7
openxr: Add OpenXR sdk headers to repo
Beyley 56e4c0e
cmake: Make DXVK and OpenXR depend on SDL_GPU
Beyley 95c8233
cmake: Escape SDL_GPU_OPENXR_DYNAMIC in cmake script
Beyley da5026c
gpu: Fix uninitialized variable usage in OpenXR physical device init
Beyley 02d0e80
gpu: Fix uninitialized memory usage when checking OpenXR vulkan devic…
Beyley 3b5ddbe
gpu: Add property to specify form factor
Beyley 451af4d
gpu: Fix warning on GCC
Beyley 0882b0a
cmake: Make HAVE_GPU_OPENXR match rest of build config
Beyley d583a39
gpu/vulkan: Use props OpenXR version in PrepareDriver
Beyley a75107b
gpu/d3d12: Implement OpenXR session creation
Beyley 5de7279
gpu/d3d12: Initial buggy OpenXR swapchain support
Beyley 0597fb2
openxr: Remove hardcoded debug soname
Beyley 025c403
openxr: Add hint to specify the set of OpenXR loader sonames to try
Beyley 908967c
openxr: Expose Load/Unload library + xrInstanceProcAddress
Beyley e330f70
d3d12: Fix error logs
Beyley 3623c8e
openxr: Provide stub functions when OpenXR is disabled
Beyley d88fb9a
d3d12: Use picked feature level in device creation
Beyley 9a061cc
cmake: Disable GPU on unsupported platforms
Beyley 33a7cef
dynapi: fix OpenXR dynapi
Beyley 4d69dab
android: Add OpenXR files to android build
Beyley f85d407
cmake + openxr: Pick library name in C file, not cmake
Beyley e89ce1d
VisualC: Add OpenXR code
Beyley a29e2c3
android + VisualC: Add openxr include path
Beyley 3af8e4c
openxr: Look for the OpenXR loader without a version suffix aswell
Beyley 0595740
VisualC: Add khronos to include path
Beyley ffc34ba
VisualC: minor spelling mistake
Beyley 8452972
cmake: Fix order of sources
Beyley 0b74e42
build_config: Add OpenXR for android and windows build config
Beyley 4f3db73
gpu/d3d12: Remove unreachable code in GetAdapterByLuid
Beyley d64e41f
openxr: Update OpenXR SDK to 1.1.45
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 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 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 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 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 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 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 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 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 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 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 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.
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.