DiligentEngine icon indicating copy to clipboard operation
DiligentEngine copied to clipboard

OpenXR support?

Open gigadude opened this issue 5 years ago • 2 comments

I'd like to add OpenXR support, opening this issue to discuss the right way to do that.

My first pass at the needed API changes for minimalist XR support:

IEngineFactory:

  • CreateOpenXRFactory(OpenXRCreateInfo* info, IOpenXRContext** ctx), called before CreateDeviceAndContextsXx to initialize the OpenXR instance and return the interface. IOpenXRContext will provide interfaces to the session lifecycle stuff, input bindings, layers, spaces etc.

ISwapChain:

  • Uint32 GetViewCount() to turn the number of views for the device (typically 2 for right, left eyes). Non-OpenXR apps will return 1.
  • OpenXRViewDesc GetOpenOpenXRViewDesc(Uint32 ViewIndex) to return the view descriptor for a given view.
  • Uint32 SelectOpenXRView(Uint32 ViewIndex) to make one of the views "current", the rest of the swapchain functions will reference the resources for that view (e,g, GetDesc, GetCurrentBackBufferRTV etc. will return parameters for the selected view). Returns the previously current view.
  • WaitFrame(FrameInfo* frame) maps to xrWaitFrame, ignored by non-XR apps.
  • BeginFrame(FrameInfo* frame) maps to xrBeginFrame, ignored by non-XR apps.
  • EndFrame(FrameInfo* frame) maps to xrEndFrame, ignored by non-XR apps. Present() will be ignored by XR apps.

The intent is to allow the same code to work in both XR and 2D mode by simply choosing to call or not call CreateOpenXRFactory.

gigadude avatar Nov 03 '20 20:11 gigadude

Hi! Thanks for looking into this. I am not very familiar with OpenXR, so please correct me where I am wrong. From my understanding, from the graphics point of view the only thing that connects XR application to rendering code is the swap chain. Core module only implements rendering functionality, it does not handle application-level tasks such input, app main loop, etc. So it seems that for the core module, what needs to be added is a new IEngineFactory method CreateXRSwapChain that will take the XR session and other required parameters.

Other application-specific logic does not belong to Core module. Instead, I think it should be added to tools module. There is a NativeAppBase, so probably there should be XRApp that will implement all logic like WaitFrame, BeginFrame, etc. What do you think?

TheMostDiligent avatar Nov 05 '20 03:11 TheMostDiligent

Gigadude how far have you gone with this?

madwax avatar Mar 14 '21 11:03 madwax