-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphicsTools: added OpenXR utilities
- Loading branch information
1 parent
59a0d8d
commit 0d022f5
Showing
7 changed files
with
450 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2024 Diligent Graphics LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* In no event and under no legal theory, whether in tort (including negligence), | ||
* contract, or otherwise, unless required by applicable law (such as deliberate | ||
* and grossly negligent acts) or agreed to in writing, shall any Contributor be | ||
* liable for any damages, including any direct, indirect, special, incidental, | ||
* or consequential damages of any character arising as a result of this License or | ||
* out of the use or inability to use the software (including but not limited to damages | ||
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and | ||
* all other commercial damages or losses), even if such Contributor has been advised | ||
* of the possibility of such damages. | ||
*/ | ||
|
||
#pragma once | ||
|
||
/// \file | ||
/// OpenXR utilities | ||
|
||
#include "../../GraphicsEngine/interface/RenderDevice.h" | ||
#include "../../GraphicsEngine/interface/DeviceContext.h" | ||
#include "../../Primitives/interface/DataBlob.h" | ||
|
||
DILIGENT_BEGIN_NAMESPACE(Diligent) | ||
|
||
#include "../../../Primitives/interface/DefineRefMacro.h" | ||
|
||
/// Prepares OpenXR graphics binding for the specified device and context. | ||
/// | ||
/// \param [in] pDevice - Pointer to the render device. | ||
/// \param [in] pContext - Pointer to the device context. | ||
/// \param [out] ppGraphicsBinding - Address of the memory location where the pointer to the data blob | ||
/// containing the graphics binding will be stored. | ||
/// | ||
/// \remarks The function returns the data blob that contains the OpenXR graphics binding structure | ||
/// (XrGraphicsBindingVulkanKHR, XrGraphicsBindingD3D11KHR, etc.). | ||
/// The data blob should be used to create the OpenXR session, for example: | ||
/// | ||
/// RefCntAutoPtr<IDataBlob> pGraphicsBinding; | ||
/// GetOpenXRGraphicsBinding(m_pDevice, m_pImmediateContext, &pGraphicsBinding); | ||
/// | ||
/// XrSessionCreateInfo sessionCI{XR_TYPE_SESSION_CREATE_INFO}; | ||
/// sessionCI.next = pGraphicsBinding->GetConstDataPtr(); | ||
/// sessionCI.systemId = m_SystemId; | ||
/// xrCreateSession(m_xrInstance, &sessionCI, &m_xrSession); | ||
/// | ||
void DILIGENT_GLOBAL_FUNCTION(GetOpenXRGraphicsBinding)(IRenderDevice* pDevice, | ||
IDeviceContext* pContext, | ||
IDataBlob** ppGraphicsBinding); | ||
|
||
#include "../../../Primitives/interface/UndefRefMacro.h" | ||
|
||
DILIGENT_END_NAMESPACE // namespace Diligent |
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,131 @@ | ||
/* | ||
* Copyright 2024 Diligent Graphics LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* In no event and under no legal theory, whether in tort (including negligence), | ||
* contract, or otherwise, unless required by applicable law (such as deliberate | ||
* and grossly negligent acts) or agreed to in writing, shall any Contributor be | ||
* liable for any damages, including any direct, indirect, special, incidental, | ||
* or consequential damages of any character arising as a result of this License or | ||
* out of the use or inability to use the software (including but not limited to damages | ||
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and | ||
* all other commercial damages or losses), even if such Contributor has been advised | ||
* of the possibility of such damages. | ||
*/ | ||
|
||
#include "OpenXRUtilities.h" | ||
|
||
#include "DebugUtilities.hpp" | ||
|
||
namespace Diligent | ||
{ | ||
|
||
#if DILIGENT_USE_OPENXR | ||
|
||
# if D3D11_SUPPORTED | ||
void GetOpenXRGraphicsBindingD3D11(IRenderDevice* pDevice, | ||
IDeviceContext* pContext, | ||
IDataBlob** ppGraphicsBinding); | ||
# endif | ||
|
||
# if D3D12_SUPPORTED | ||
void GetOpenXRGraphicsBindingD3D12(IRenderDevice* pDevice, | ||
IDeviceContext* pContext, | ||
IDataBlob** ppGraphicsBinding); | ||
# endif | ||
|
||
# if GL_SUPPORTED || GLES_SUPPORTED | ||
void GetOpenXRGraphicsBindingGL(IRenderDevice* pDevice, | ||
IDeviceContext* pContext, | ||
IDataBlob** ppGraphicsBinding); | ||
# endif | ||
|
||
# if VULKAN_SUPPORTED | ||
void GetOpenXRGraphicsBindingVk(IRenderDevice* pDevice, | ||
IDeviceContext* pContext, | ||
IDataBlob** ppGraphicsBinding); | ||
# endif | ||
|
||
#endif | ||
|
||
void GetOpenXRGraphicsBinding(IRenderDevice* pDevice, | ||
IDeviceContext* pContext, | ||
IDataBlob** ppGraphicsBinding) | ||
{ | ||
#if DILIGENT_USE_OPENXR | ||
if (pDevice == nullptr) | ||
{ | ||
UNEXPECTED("pDevice must not be null"); | ||
return; | ||
} | ||
|
||
if (pContext == nullptr) | ||
{ | ||
UNEXPECTED("pContext must not be null"); | ||
return; | ||
} | ||
|
||
if (ppGraphicsBinding == nullptr) | ||
{ | ||
UNEXPECTED("ppGraphicsBinding must not be null"); | ||
return; | ||
} | ||
|
||
RENDER_DEVICE_TYPE DevType = pDevice->GetDeviceInfo().Type; | ||
switch (DevType) | ||
{ | ||
# if D3D11_SUPPORTED | ||
case RENDER_DEVICE_TYPE_D3D11: | ||
GetOpenXRGraphicsBindingD3D11(pDevice, pContext, ppGraphicsBinding); | ||
break; | ||
# endif | ||
|
||
# if D3D12_SUPPORTED | ||
case RENDER_DEVICE_TYPE_D3D12: | ||
GetOpenXRGraphicsBindingD3D12(pDevice, pContext, ppGraphicsBinding); | ||
break; | ||
# endif | ||
|
||
# if GL_SUPPORTED || GLES_SUPPORTED | ||
case RENDER_DEVICE_TYPE_GL: | ||
case RENDER_DEVICE_TYPE_GLES: | ||
GetOpenXRGraphicsBindingGL(pDevice, pContext, ppGraphicsBinding); | ||
break; | ||
# endif | ||
|
||
# if VULKAN_SUPPORTED | ||
case RENDER_DEVICE_TYPE_VULKAN: | ||
GetOpenXRGraphicsBindingVk(pDevice, pContext, ppGraphicsBinding); | ||
break; | ||
# endif | ||
|
||
default: | ||
UNSUPPORTED("Unsupported device type"); | ||
} | ||
#else | ||
UNSUPPORTED("OpenXR is not supported"); | ||
#endif | ||
} | ||
|
||
} // namespace Diligent | ||
|
||
extern "C" | ||
{ | ||
void Diligent_GetOpenXRGraphicsBinding(Diligent::IRenderDevice* pDevice, | ||
Diligent::IDeviceContext* pContext, | ||
Diligent::IDataBlob** ppGraphicsBinding) | ||
{ | ||
Diligent::GetOpenXRGraphicsBinding(pDevice, pContext, ppGraphicsBinding); | ||
} | ||
} |
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,62 @@ | ||
/* | ||
* Copyright 2024 Diligent Graphics LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* In no event and under no legal theory, whether in tort (including negligence), | ||
* contract, or otherwise, unless required by applicable law (such as deliberate | ||
* and grossly negligent acts) or agreed to in writing, shall any Contributor be | ||
* liable for any damages, including any direct, indirect, special, incidental, | ||
* or consequential damages of any character arising as a result of this License or | ||
* out of the use or inability to use the software (including but not limited to damages | ||
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and | ||
* all other commercial damages or losses), even if such Contributor has been advised | ||
* of the possibility of such damages. | ||
*/ | ||
|
||
#include "OpenXRUtilities.h" | ||
|
||
#include "DebugUtilities.hpp" | ||
#include "DataBlobImpl.hpp" | ||
|
||
#include "WinHPreface.h" | ||
#include <d3d11.h> | ||
#include <atlbase.h> | ||
#include "WinHPostface.h" | ||
|
||
#include "RenderDeviceD3D11.h" | ||
|
||
#define XR_USE_GRAPHICS_API_D3D11 | ||
#include <openxr/openxr_platform.h> | ||
|
||
namespace Diligent | ||
{ | ||
|
||
void GetOpenXRGraphicsBindingD3D11(IRenderDevice* pDevice, | ||
IDeviceContext* pContext, | ||
IDataBlob** ppGraphicsBinding) | ||
{ | ||
RefCntAutoPtr<DataBlobImpl> pDataBlob{DataBlobImpl::Create(sizeof(XrGraphicsBindingD3D11KHR))}; | ||
|
||
RefCntAutoPtr<IRenderDeviceD3D11> pDeviceD3D11{pDevice, IID_RenderDeviceD3D11}; | ||
VERIFY_EXPR(pDeviceD3D11 != nullptr); | ||
|
||
XrGraphicsBindingD3D11KHR& Binding = *reinterpret_cast<XrGraphicsBindingD3D11KHR*>(pDataBlob->GetDataPtr()); | ||
Binding.type = XR_TYPE_GRAPHICS_BINDING_D3D11_KHR; | ||
Binding.next = nullptr; | ||
Binding.device = pDeviceD3D11->GetD3D11Device(); | ||
|
||
*ppGraphicsBinding = pDataBlob.Detach(); | ||
} | ||
|
||
} // namespace Diligent |
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,67 @@ | ||
/* | ||
* Copyright 2024 Diligent Graphics LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* In no event and under no legal theory, whether in tort (including negligence), | ||
* contract, or otherwise, unless required by applicable law (such as deliberate | ||
* and grossly negligent acts) or agreed to in writing, shall any Contributor be | ||
* liable for any damages, including any direct, indirect, special, incidental, | ||
* or consequential damages of any character arising as a result of this License or | ||
* out of the use or inability to use the software (including but not limited to damages | ||
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and | ||
* all other commercial damages or losses), even if such Contributor has been advised | ||
* of the possibility of such damages. | ||
*/ | ||
|
||
#include "OpenXRUtilities.h" | ||
|
||
#include "DebugUtilities.hpp" | ||
#include "DataBlobImpl.hpp" | ||
|
||
#include "WinHPreface.h" | ||
#include <d3d12.h> | ||
#include <atlbase.h> | ||
#include "WinHPostface.h" | ||
|
||
#include "RenderDeviceD3D12.h" | ||
#include "CommandQueueD3D12.h" | ||
|
||
|
||
#define XR_USE_GRAPHICS_API_D3D12 | ||
#include <openxr/openxr_platform.h> | ||
|
||
namespace Diligent | ||
{ | ||
|
||
void GetOpenXRGraphicsBindingD3D12(IRenderDevice* pDevice, | ||
IDeviceContext* pContext, | ||
IDataBlob** ppGraphicsBinding) | ||
{ | ||
RefCntAutoPtr<DataBlobImpl> pDataBlob{DataBlobImpl::Create(sizeof(XrGraphicsBindingD3D12KHR))}; | ||
|
||
RefCntAutoPtr<IRenderDeviceD3D12> pDeviceD3D12{pDevice, IID_RenderDeviceD3D12}; | ||
VERIFY_EXPR(pDeviceD3D12 != nullptr); | ||
RefCntAutoPtr<ICommandQueueD3D12> pQueueD3D12{pContext->LockCommandQueue(), IID_CommandQueueD3D12}; | ||
VERIFY_EXPR(pQueueD3D12 != nullptr); | ||
|
||
XrGraphicsBindingD3D12KHR& Binding = *reinterpret_cast<XrGraphicsBindingD3D12KHR*>(pDataBlob->GetDataPtr()); | ||
Binding.type = XR_TYPE_GRAPHICS_BINDING_D3D12_KHR; | ||
Binding.next = nullptr; | ||
Binding.device = pDeviceD3D12->GetD3D12Device(); | ||
Binding.queue = pQueueD3D12->GetD3D12CommandQueue(); | ||
|
||
*ppGraphicsBinding = pDataBlob.Detach(); | ||
} | ||
|
||
} // namespace Diligent |
Oops, something went wrong.