From ee26b5f575dd4b03ba3f146ca8858298b2ff9d3a Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 25 May 2022 16:43:21 -0500 Subject: [PATCH] a/d3d: Split out some d3d11 stuff from generic --- src/xrt/auxiliary/d3d/CMakeLists.txt | 36 +++++++-------- src/xrt/auxiliary/d3d/d3d_d3d11_allocator.cpp | 5 ++- src/xrt/auxiliary/d3d/d3d_d3d11_bits.h | 44 +++++++++++++++++++ src/xrt/auxiliary/d3d/d3d_dxgi_formats.h | 19 -------- src/xrt/auxiliary/d3d/d3d_helpers.cpp | 3 ++ src/xrt/auxiliary/d3d/d3d_helpers.hpp | 7 +++ .../compositor/client/comp_d3d11_client.cpp | 2 +- src/xrt/state_trackers/oxr/oxr_d3d.cpp | 21 +++------ src/xrt/state_trackers/oxr/oxr_d3d11.cpp | 6 ++- src/xrt/state_trackers/oxr/oxr_objects.h | 4 +- 10 files changed, 89 insertions(+), 58 deletions(-) create mode 100644 src/xrt/auxiliary/d3d/d3d_d3d11_bits.h diff --git a/src/xrt/auxiliary/d3d/CMakeLists.txt b/src/xrt/auxiliary/d3d/CMakeLists.txt index dedc68549..82d1514cf 100644 --- a/src/xrt/auxiliary/d3d/CMakeLists.txt +++ b/src/xrt/auxiliary/d3d/CMakeLists.txt @@ -1,26 +1,22 @@ # Copyright 2019-2022, Collabora, Ltd. # SPDX-License-Identifier: BSL-1.0 +add_library(aux_d3d STATIC d3d_dxgi_formats.h d3d_helpers.cpp d3d_helpers.hpp) +target_link_libraries(aux_d3d PUBLIC aux-includes xrt-interfaces ${DXGI_LIBRARY} WIL::WIL) -add_library( - aux_d3d STATIC - d3d_d3d11_allocator.cpp - d3d_d3d11_allocator.h - d3d_d3d11_allocator.hpp - d3d_d3d11_fence.cpp - d3d_d3d11_fence.hpp - d3d_dxgi_formats.h - d3d_helpers.cpp - d3d_helpers.hpp - ) -target_link_libraries( - aux_d3d - PUBLIC - aux-includes - xrt-interfaces - ${DXGI_LIBRARY} - ${D3D11_LIBRARY} - WIL::WIL - ) # needed for format includes target_include_directories(aux_d3d PUBLIC ${Vulkan_INCLUDE_DIR}) + +if(XRT_HAVE_D3D11) + target_sources( + aux_d3d + PRIVATE + d3d_d3d11_bits.h + d3d_d3d11_allocator.cpp + d3d_d3d11_allocator.h + d3d_d3d11_allocator.hpp + d3d_d3d11_fence.cpp + d3d_d3d11_fence.hpp + ) + target_link_libraries(aux_d3d PUBLIC ${D3D11_LIBRARY}) +endif() diff --git a/src/xrt/auxiliary/d3d/d3d_d3d11_allocator.cpp b/src/xrt/auxiliary/d3d/d3d_d3d11_allocator.cpp index 00fa19024..6ea5968f8 100644 --- a/src/xrt/auxiliary/d3d/d3d_d3d11_allocator.cpp +++ b/src/xrt/auxiliary/d3d/d3d_d3d11_allocator.cpp @@ -2,7 +2,7 @@ // SPDX-License-Identifier: BSL-1.0 /*! * @file - * @brief D3D backed image buffer allocator. + * @brief D3D11 backed image buffer allocator. * @author Ryan Pavlik * @ingroup aux_d3d */ @@ -10,6 +10,7 @@ #include "d3d_d3d11_allocator.h" #include "d3d_d3d11_allocator.hpp" +#include "d3d_d3d11_bits.h" #include "d3d_dxgi_formats.h" #include "util/u_misc.h" @@ -90,7 +91,7 @@ try { xsci.height, xsci.array_size, xsci.mip_count, - d3d_convert_usage_bits_to_bind_flags(xsci.bits)}; + d3d_convert_usage_bits_to_d3d11_bind_flags(xsci.bits)}; desc.SampleDesc.Count = xsci.sample_count; desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_NTHANDLE; if (keyed_mutex) { diff --git a/src/xrt/auxiliary/d3d/d3d_d3d11_bits.h b/src/xrt/auxiliary/d3d/d3d_d3d11_bits.h new file mode 100644 index 000000000..7982abf98 --- /dev/null +++ b/src/xrt/auxiliary/d3d/d3d_d3d11_bits.h @@ -0,0 +1,44 @@ +// Copyright 2020-2022, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Usage bits for D3D11. + * @author Ryan Pavlik + * @ingroup aux_d3d + */ + +#pragma once + +#include "xrt/xrt_compositor.h" +#include "xrt/xrt_windows.h" + +#include "d3d11.h" + + +#ifdef __cplusplus +extern "C" { +#endif + + +static inline UINT +d3d_convert_usage_bits_to_d3d11_bind_flags(enum xrt_swapchain_usage_bits xsub) +{ + int ret = 0; + if ((xsub & XRT_SWAPCHAIN_USAGE_COLOR) != 0) { + ret |= D3D11_BIND_RENDER_TARGET; + } + if ((xsub & XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL) != 0) { + ret |= D3D11_BIND_DEPTH_STENCIL; + } + if ((xsub & XRT_SWAPCHAIN_USAGE_UNORDERED_ACCESS) != 0) { + ret |= D3D11_BIND_UNORDERED_ACCESS; + } + if ((xsub & XRT_SWAPCHAIN_USAGE_SAMPLED) != 0) { + ret |= D3D11_BIND_SHADER_RESOURCE; + } + return ret; +} + +#ifdef __cplusplus +} +#endif diff --git a/src/xrt/auxiliary/d3d/d3d_dxgi_formats.h b/src/xrt/auxiliary/d3d/d3d_dxgi_formats.h index 40af07aa6..2d87b27d9 100644 --- a/src/xrt/auxiliary/d3d/d3d_dxgi_formats.h +++ b/src/xrt/auxiliary/d3d/d3d_dxgi_formats.h @@ -96,25 +96,6 @@ d3d_dxgi_format_to_vk(DXGI_FORMAT format) } } -static inline UINT -d3d_convert_usage_bits_to_bind_flags(enum xrt_swapchain_usage_bits xsub) -{ - int ret = 0; - if ((xsub & XRT_SWAPCHAIN_USAGE_COLOR) != 0) { - ret |= D3D11_BIND_RENDER_TARGET; - } - if ((xsub & XRT_SWAPCHAIN_USAGE_DEPTH_STENCIL) != 0) { - ret |= D3D11_BIND_DEPTH_STENCIL; - } - if ((xsub & XRT_SWAPCHAIN_USAGE_UNORDERED_ACCESS) != 0) { - ret |= D3D11_BIND_UNORDERED_ACCESS; - } - if ((xsub & XRT_SWAPCHAIN_USAGE_SAMPLED) != 0) { - ret |= D3D11_BIND_SHADER_RESOURCE; - } - return ret; -} - #ifdef __cplusplus } #endif diff --git a/src/xrt/auxiliary/d3d/d3d_helpers.cpp b/src/xrt/auxiliary/d3d/d3d_helpers.cpp index 4968630da..76dd9f75a 100644 --- a/src/xrt/auxiliary/d3d/d3d_helpers.cpp +++ b/src/xrt/auxiliary/d3d/d3d_helpers.cpp @@ -99,6 +99,7 @@ getAdapterByLUID(const xrt_luid_t &luid, u_logging_level log_level) return ret; } +#ifdef XRT_HAVE_D3D11 HRESULT tryCreateD3D11Device(const wil::com_ptr &adapter, D3D_DRIVER_TYPE driver_type, @@ -141,4 +142,6 @@ createD3D11Device(const wil::com_ptr &adapter, u_logging_level log THROW_IF_FAILED(hr); return {device, context}; } +#endif // XRT_HAVE_D3D11 + } // namespace xrt::auxiliary::d3d diff --git a/src/xrt/auxiliary/d3d/d3d_helpers.hpp b/src/xrt/auxiliary/d3d/d3d_helpers.hpp index 97313ad72..6efe62d31 100644 --- a/src/xrt/auxiliary/d3d/d3d_helpers.hpp +++ b/src/xrt/auxiliary/d3d/d3d_helpers.hpp @@ -11,11 +11,16 @@ #include "xrt/xrt_defines.h" #include "xrt/xrt_compositor.h" +#include "xrt/xrt_config_have.h" #include "util/u_logging.h" #include + +#ifdef XRT_HAVE_D3D11 #include +#endif + #include #include @@ -50,6 +55,7 @@ getAdapterByIndex(uint16_t index, u_logging_level log_level = U_LOGGING_INFO); wil::com_ptr getAdapterByLUID(const xrt_luid_t &luid, u_logging_level log_level = U_LOGGING_INFO); +#ifdef XRT_HAVE_D3D11 /** * @brief Create a D3D11 Device object * @@ -62,5 +68,6 @@ getAdapterByLUID(const xrt_luid_t &luid, u_logging_level log_level = U_LOGGING_I */ std::pair, wil::com_ptr> createD3D11Device(const wil::com_ptr &adapter = nullptr, u_logging_level log_level = U_LOGGING_INFO); +#endif // XRT_HAVE_D3D11 } // namespace xrt::auxiliary::d3d diff --git a/src/xrt/compositor/client/comp_d3d11_client.cpp b/src/xrt/compositor/client/comp_d3d11_client.cpp index 3f73a86d7..2fce86648 100644 --- a/src/xrt/compositor/client/comp_d3d11_client.cpp +++ b/src/xrt/compositor/client/comp_d3d11_client.cpp @@ -17,7 +17,7 @@ #include "xrt/xrt_results.h" #include "xrt/xrt_vulkan_includes.h" #include "d3d/d3d_dxgi_formats.h" -#include "d3d/d3d_helpers.hpp" +#include "d3d/d3d_d3d11_helpers.hpp" #include "d3d/d3d_d3d11_allocator.hpp" #include "d3d/d3d_d3d11_fence.hpp" #include "util/u_misc.h" diff --git a/src/xrt/state_trackers/oxr/oxr_d3d.cpp b/src/xrt/state_trackers/oxr/oxr_d3d.cpp index 243e1bd2d..0820a94ec 100644 --- a/src/xrt/state_trackers/oxr/oxr_d3d.cpp +++ b/src/xrt/state_trackers/oxr/oxr_d3d.cpp @@ -9,7 +9,7 @@ #include "util/u_misc.h" #include "util/u_debug.h" -#include "d3d/d3d_helpers.hpp" +#include "d3d/d3d_dxgi_helpers.hpp" #include "oxr_objects.h" #include "oxr_logger.h" @@ -73,20 +73,13 @@ oxr_d3d_get_requirements(struct oxr_logger *log, } XrResult -oxr_d3d_check_device(struct oxr_logger *log, struct oxr_system *sys, IDXGIDevice *device) +oxr_d3d_check_luid(struct oxr_logger *log, struct oxr_system *sys, LUID *adapter_luid) { - try { - wil::com_ptr 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) { + if (adapter_luid->HighPart != sys->suggested_d3d_luid.HighPart || + adapter_luid->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; + return oxr_error(log, XR_ERROR_GRAPHICS_DEVICE_INVALID, + " supplied device does not match required LUID."); } - DEFAULT_CATCH(" failure checking adapter LUID") + return XR_SUCCESS; } diff --git a/src/xrt/state_trackers/oxr/oxr_d3d11.cpp b/src/xrt/state_trackers/oxr/oxr_d3d11.cpp index 1a49cd6fe..18d175a68 100644 --- a/src/xrt/state_trackers/oxr/oxr_d3d11.cpp +++ b/src/xrt/state_trackers/oxr/oxr_d3d11.cpp @@ -48,7 +48,11 @@ oxr_d3d11_check_device(struct oxr_logger *log, struct oxr_system *sys, ID3D11Dev try { wil::com_ptr dxgiDevice; THROW_IF_FAILED(device->QueryInterface(dxgiDevice.put())); - return oxr_d3d_check_device(log, sys, dxgiDevice.get()); + wil::com_ptr adapter; + THROW_IF_FAILED(dxgiDevice->GetAdapter(adapter.put())); + DXGI_ADAPTER_DESC desc{}; + adapter->GetDesc(&desc); + return oxr_d3d_check_luid(log, sys, &desc.AdapterLuid); } DEFAULT_CATCH(" failure checking adapter LUID") } diff --git a/src/xrt/state_trackers/oxr/oxr_objects.h b/src/xrt/state_trackers/oxr/oxr_objects.h index 6b620cb94..346f25c91 100644 --- a/src/xrt/state_trackers/oxr/oxr_objects.h +++ b/src/xrt/state_trackers/oxr/oxr_objects.h @@ -1206,14 +1206,16 @@ oxr_session_populate_egl(struct oxr_logger *log, */ #if defined(XRT_HAVE_D3D11) || defined(XRT_HAVE_D3D12) || defined(XRT_DOXYGEN) +/// Common GetRequirements call for D3D11 and D3D12 XrResult oxr_d3d_get_requirements(struct oxr_logger *log, struct oxr_system *sys, LUID *adapter_luid, D3D_FEATURE_LEVEL *min_feature_level); +/// Verify the provided LUID matches the expected one in @p sys XrResult -oxr_d3d_check_device(struct oxr_logger *log, struct oxr_system *sys, IDXGIDevice *device); +oxr_d3d_check_luid(struct oxr_logger *log, struct oxr_system *sys, LUID *adapter_luid); #endif /*