a/d3d: Split out some d3d11 stuff from generic

This commit is contained in:
Ryan Pavlik 2022-05-25 16:43:21 -05:00
parent 79f86ff0e3
commit ee26b5f575
10 changed files with 89 additions and 58 deletions

View file

@ -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()

View file

@ -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 <ryan.pavlik@collabora.com>
* @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) {

View file

@ -0,0 +1,44 @@
// Copyright 2020-2022, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Usage bits for D3D11.
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
* @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

View file

@ -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

View file

@ -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<IDXGIAdapter> &adapter,
D3D_DRIVER_TYPE driver_type,
@ -141,4 +142,6 @@ createD3D11Device(const wil::com_ptr<IDXGIAdapter> &adapter, u_logging_level log
THROW_IF_FAILED(hr);
return {device, context};
}
#endif // XRT_HAVE_D3D11
} // namespace xrt::auxiliary::d3d

View file

@ -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 <dxgi.h>
#ifdef XRT_HAVE_D3D11
#include <d3d11.h>
#endif
#include <wil/com.h>
#include <utility>
@ -50,6 +55,7 @@ getAdapterByIndex(uint16_t index, u_logging_level log_level = U_LOGGING_INFO);
wil::com_ptr<IDXGIAdapter>
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<ID3D11Device>, wil::com_ptr<ID3D11DeviceContext>>
createD3D11Device(const wil::com_ptr<IDXGIAdapter> &adapter = nullptr, u_logging_level log_level = U_LOGGING_INFO);
#endif // XRT_HAVE_D3D11
} // namespace xrt::auxiliary::d3d

View file

@ -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"

View file

@ -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<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) {
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;
}

View file

@ -48,7 +48,11 @@ oxr_d3d11_check_device(struct oxr_logger *log, struct oxr_system *sys, ID3D11Dev
try {
wil::com_ptr<IDXGIDevice> dxgiDevice;
THROW_IF_FAILED(device->QueryInterface(dxgiDevice.put()));
return oxr_d3d_check_device(log, sys, dxgiDevice.get());
wil::com_ptr<IDXGIAdapter> 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")
}

View file

@ -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
/*