mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 04:36:07 +00:00
st/oxr: Split out some code that is d3d-version independent
This commit is contained in:
parent
c5c4f9f45a
commit
79dffbf3f6
|
@ -69,10 +69,14 @@ if(XRT_HAVE_EGL)
|
||||||
target_sources(st_oxr PRIVATE oxr_session_gfx_egl.c)
|
target_sources(st_oxr PRIVATE oxr_session_gfx_egl.c)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(XRT_HAVE_D3D11 OR XRT_HAVE_D3D12)
|
||||||
|
target_sources(st_oxr PRIVATE oxr_d3d.cpp)
|
||||||
|
target_link_libraries(st_oxr PRIVATE aux_d3d)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(XRT_HAVE_D3D11)
|
if(XRT_HAVE_D3D11)
|
||||||
target_compile_definitions(st_oxr PRIVATE XR_USE_GRAPHICS_API_D3D11)
|
target_compile_definitions(st_oxr PRIVATE XR_USE_GRAPHICS_API_D3D11)
|
||||||
target_sources(st_oxr PRIVATE oxr_session_gfx_d3d11.c oxr_swapchain_d3d11.c oxr_d3d11.cpp)
|
target_sources(st_oxr PRIVATE oxr_session_gfx_d3d11.c oxr_swapchain_d3d11.c oxr_d3d11.cpp)
|
||||||
target_link_libraries(st_oxr PRIVATE aux_d3d)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(ANDROID)
|
if(ANDROID)
|
||||||
|
|
92
src/xrt/state_trackers/oxr/oxr_d3d.cpp
Normal file
92
src/xrt/state_trackers/oxr/oxr_d3d.cpp
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
// Copyright 2021-2022, Collabora, Ltd.
|
||||||
|
// SPDX-License-Identifier: BSL-1.0
|
||||||
|
/*!
|
||||||
|
* @file
|
||||||
|
* @brief D3D 11 and 12 shared routines
|
||||||
|
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
|
||||||
|
* @ingroup oxr_main
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "util/u_misc.h"
|
||||||
|
#include "util/u_debug.h"
|
||||||
|
#include "d3d/d3d_helpers.hpp"
|
||||||
|
|
||||||
|
#include "oxr_objects.h"
|
||||||
|
#include "oxr_logger.h"
|
||||||
|
|
||||||
|
#include <dxgi1_6.h>
|
||||||
|
#include <wil/com.h>
|
||||||
|
#include <wil/result.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define DEFAULT_CATCH(MSG) \
|
||||||
|
catch (wil::ResultException const &e) \
|
||||||
|
{ \
|
||||||
|
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, MSG ": %s", e.what()); \
|
||||||
|
} \
|
||||||
|
catch (std::exception const &e) \
|
||||||
|
{ \
|
||||||
|
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, MSG ": %s", e.what()); \
|
||||||
|
} \
|
||||||
|
catch (...) \
|
||||||
|
{ \
|
||||||
|
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, MSG); \
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace xrt::auxiliary::d3d;
|
||||||
|
|
||||||
|
XrResult
|
||||||
|
oxr_d3d_get_requirements(struct oxr_logger *log,
|
||||||
|
struct oxr_system *sys,
|
||||||
|
LUID *adapter_luid,
|
||||||
|
D3D_FEATURE_LEVEL *min_feature_level)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (sys->xsysc->info.client_d3d_deviceLUID_valid) {
|
||||||
|
sys->suggested_d3d_luid =
|
||||||
|
reinterpret_cast<const LUID &>(sys->xsysc->info.client_d3d_deviceLUID);
|
||||||
|
if (nullptr == getAdapterByLUID(sys->xsysc->info.client_d3d_deviceLUID, U_LOGGING_INFO)) {
|
||||||
|
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE,
|
||||||
|
" failure enumerating adapter for LUID specified for use.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
auto adapter = getAdapterByIndex(0, U_LOGGING_INFO);
|
||||||
|
if (adapter == nullptr) {
|
||||||
|
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, " failure enumerating adapter LUIDs.");
|
||||||
|
}
|
||||||
|
DXGI_ADAPTER_DESC desc{};
|
||||||
|
THROW_IF_FAILED(adapter->GetDesc(&desc));
|
||||||
|
sys->suggested_d3d_luid = desc.AdapterLuid;
|
||||||
|
}
|
||||||
|
sys->suggested_d3d_luid_valid = true;
|
||||||
|
*adapter_luid = sys->suggested_d3d_luid;
|
||||||
|
//! @todo implement better?
|
||||||
|
*min_feature_level = D3D_FEATURE_LEVEL_11_0;
|
||||||
|
|
||||||
|
return XR_SUCCESS;
|
||||||
|
}
|
||||||
|
DEFAULT_CATCH(" failure determining adapter LUID")
|
||||||
|
}
|
||||||
|
|
||||||
|
XrResult
|
||||||
|
oxr_d3d_check_device(struct oxr_logger *log, struct oxr_system *sys, IDXGIDevice *device)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
wil::com_ptr<IDXGIAdapter> adapter;
|
||||||
|
THROW_IF_FAILED(device->GetAdapter(adapter.put()));
|
||||||
|
DXGI_ADAPTER_DESC desc{};
|
||||||
|
adapter->GetDesc(&desc);
|
||||||
|
if (desc.AdapterLuid.HighPart != sys->suggested_d3d_luid.HighPart ||
|
||||||
|
desc.AdapterLuid.LowPart != sys->suggested_d3d_luid.LowPart) {
|
||||||
|
|
||||||
|
return oxr_error(log, XR_ERROR_GRAPHICS_DEVICE_INVALID,
|
||||||
|
" supplied device does not match required LUID.");
|
||||||
|
}
|
||||||
|
return XR_SUCCESS;
|
||||||
|
}
|
||||||
|
DEFAULT_CATCH(" failure checking adapter LUID")
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2021, Collabora, Ltd.
|
// Copyright 2021-2022, Collabora, Ltd.
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
// SPDX-License-Identifier: BSL-1.0
|
||||||
/*!
|
/*!
|
||||||
* @file
|
* @file
|
||||||
|
@ -7,12 +7,6 @@
|
||||||
* @ingroup oxr_main
|
* @ingroup oxr_main
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "xrt/xrt_gfx_d3d11.h"
|
|
||||||
|
|
||||||
#include "util/u_misc.h"
|
|
||||||
#include "util/u_debug.h"
|
|
||||||
#include "d3d/d3d_helpers.hpp"
|
|
||||||
|
|
||||||
#include "oxr_objects.h"
|
#include "oxr_objects.h"
|
||||||
#include "oxr_logger.h"
|
#include "oxr_logger.h"
|
||||||
|
|
||||||
|
@ -39,39 +33,13 @@
|
||||||
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, MSG); \
|
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, MSG); \
|
||||||
}
|
}
|
||||||
|
|
||||||
using namespace xrt::auxiliary::d3d;
|
|
||||||
|
|
||||||
XrResult
|
XrResult
|
||||||
oxr_d3d11_get_requirements(struct oxr_logger *log,
|
oxr_d3d11_get_requirements(struct oxr_logger *log,
|
||||||
struct oxr_system *sys,
|
struct oxr_system *sys,
|
||||||
XrGraphicsRequirementsD3D11KHR *graphicsRequirements)
|
XrGraphicsRequirementsD3D11KHR *graphicsRequirements)
|
||||||
{
|
{
|
||||||
try {
|
return oxr_d3d_get_requirements(log, sys, &graphicsRequirements->adapterLuid,
|
||||||
|
&graphicsRequirements->minFeatureLevel);
|
||||||
if (sys->xsysc->info.client_d3d_deviceLUID_valid) {
|
|
||||||
sys->suggested_d3d_luid =
|
|
||||||
reinterpret_cast<const LUID &>(sys->xsysc->info.client_d3d_deviceLUID);
|
|
||||||
if (nullptr == getAdapterByLUID(sys->xsysc->info.client_d3d_deviceLUID, U_LOGGING_INFO)) {
|
|
||||||
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE,
|
|
||||||
" failure enumerating adapter for LUID specified for use.");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
auto adapter = getAdapterByIndex(0, U_LOGGING_INFO);
|
|
||||||
if (adapter == nullptr) {
|
|
||||||
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, " failure enumerating adapter LUIDs.");
|
|
||||||
}
|
|
||||||
DXGI_ADAPTER_DESC desc{};
|
|
||||||
THROW_IF_FAILED(adapter->GetDesc(&desc));
|
|
||||||
sys->suggested_d3d_luid = desc.AdapterLuid;
|
|
||||||
}
|
|
||||||
sys->suggested_d3d_luid_valid = true;
|
|
||||||
graphicsRequirements->adapterLuid = sys->suggested_d3d_luid;
|
|
||||||
//! @todo implement better?
|
|
||||||
graphicsRequirements->minFeatureLevel = D3D_FEATURE_LEVEL_11_0;
|
|
||||||
|
|
||||||
return XR_SUCCESS;
|
|
||||||
}
|
|
||||||
DEFAULT_CATCH(" failure determining adapter LUID")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XrResult
|
XrResult
|
||||||
|
@ -80,17 +48,7 @@ oxr_d3d11_check_device(struct oxr_logger *log, struct oxr_system *sys, ID3D11Dev
|
||||||
try {
|
try {
|
||||||
wil::com_ptr<IDXGIDevice> dxgiDevice;
|
wil::com_ptr<IDXGIDevice> dxgiDevice;
|
||||||
THROW_IF_FAILED(device->QueryInterface(dxgiDevice.put()));
|
THROW_IF_FAILED(device->QueryInterface(dxgiDevice.put()));
|
||||||
wil::com_ptr<IDXGIAdapter> adapter;
|
return oxr_d3d_check_device(log, sys, dxgiDevice.get());
|
||||||
THROW_IF_FAILED(dxgiDevice->GetAdapter(adapter.put()));
|
|
||||||
DXGI_ADAPTER_DESC desc{};
|
|
||||||
adapter->GetDesc(&desc);
|
|
||||||
if (desc.AdapterLuid.HighPart != sys->suggested_d3d_luid.HighPart ||
|
|
||||||
desc.AdapterLuid.LowPart != sys->suggested_d3d_luid.LowPart) {
|
|
||||||
|
|
||||||
return oxr_error(log, XR_ERROR_GRAPHICS_DEVICE_INVALID,
|
|
||||||
" supplied device does not match required LUID.");
|
|
||||||
}
|
|
||||||
return XR_SUCCESS;
|
|
||||||
}
|
}
|
||||||
DEFAULT_CATCH(" failure checking adapter LUID")
|
DEFAULT_CATCH(" failure checking adapter LUID")
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "xrt/xrt_vulkan_includes.h"
|
#include "xrt/xrt_vulkan_includes.h"
|
||||||
#include "xrt/xrt_openxr_includes.h"
|
#include "xrt/xrt_openxr_includes.h"
|
||||||
#include "xrt/xrt_config_os.h"
|
#include "xrt/xrt_config_os.h"
|
||||||
|
#include "xrt/xrt_config_have.h"
|
||||||
|
|
||||||
#include "os/os_threading.h"
|
#include "os/os_threading.h"
|
||||||
|
|
||||||
|
@ -27,6 +28,11 @@
|
||||||
#include "oxr_extension_support.h"
|
#include "oxr_extension_support.h"
|
||||||
#include "oxr_subaction.h"
|
#include "oxr_subaction.h"
|
||||||
|
|
||||||
|
#if defined(XRT_HAVE_D3D11) || defined(XRT_HAVE_D3D12)
|
||||||
|
#include <dxgi.h>
|
||||||
|
#include <d3dcommon.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef XRT_FEATURE_RENDERDOC
|
#ifdef XRT_FEATURE_RENDERDOC
|
||||||
#include "renderdoc_app.h"
|
#include "renderdoc_app.h"
|
||||||
#ifndef XRT_OS_WINDOWS
|
#ifndef XRT_OS_WINDOWS
|
||||||
|
@ -1109,6 +1115,22 @@ oxr_session_populate_egl(struct oxr_logger *log,
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* D3D version independent routines, located in oxr_d3d.cpp
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(XRT_HAVE_D3D11) || defined(XRT_HAVE_D3D12) || defined(XRT_DOXYGEN)
|
||||||
|
XrResult
|
||||||
|
oxr_d3d_get_requirements(struct oxr_logger *log,
|
||||||
|
struct oxr_system *sys,
|
||||||
|
LUID *adapter_luid,
|
||||||
|
D3D_FEATURE_LEVEL *min_feature_level);
|
||||||
|
|
||||||
|
XrResult
|
||||||
|
oxr_d3d_check_device(struct oxr_logger *log, struct oxr_system *sys, IDXGIDevice *device);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue