Monado OpenXR Runtime
d3d_d3d12_helpers.hpp
Go to the documentation of this file.
1// Copyright 2022, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Misc D3D12 helper routines.
6 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
7 * @ingroup aux_d3d
8 */
9
10#pragma once
11
12#include "xrt/xrt_defines.h"
13#include "xrt/xrt_compositor.h"
14
15#include "util/u_logging.h"
16
17#include <dxgi.h>
18#include <d3d12.h>
19
20#include <wil/com.h>
21
22#include <utility>
23
24
25namespace xrt::auxiliary::d3d::d3d12 {
26
27
28/**
29 * @brief Create a D3D12 Device object
30 *
31 * @param adapter optional: adapter to create on.
32 * @param log_level The level to compare against for internal log messages
33 *
34 * @throws wil::ResultException in case of error
35 *
36 * @return wil::com_ptr<ID3D12Device>
37 */
38wil::com_ptr<ID3D12Device>
39createDevice(const wil::com_ptr<IDXGIAdapter> &adapter = nullptr, u_logging_level log_level = U_LOGGING_INFO);
40
41/**
42 * @brief Create command lists for a resource transitioning to/from app control
43 *
44 * @param device D3D12 device
45 * @param command_allocator
46 * @param resource image
47 * @param bits Swapchain usage bits
48 * @param[out] out_acquire_command_list Command list to populate for xrAcquireSwapchainImage
49 * @param[out] out_release_command_list Command list to populate for xrReleaseSwapchainImage
50 * @return HRESULT
51 */
52HRESULT
53createCommandLists(ID3D12Device &device,
54 ID3D12CommandAllocator &command_allocator,
55 ID3D12Resource &resource,
57 wil::com_ptr<ID3D12CommandList> out_acquire_command_list,
58 wil::com_ptr<ID3D12CommandList> out_release_command_list);
59
60/**
61 * @brief Create a command list for image resource copying
62 *
63 * @param device D3D12 device
64 * @param command_allocator
65 * @param resource_src Source image
66 * @param resource_dst Destination image
67 * @param src_resource_state
68 * @param dst_resource_state
69 * @param[out] out_copy_command_list Command list output
70 * @return HRESULT
71 */
72HRESULT
73createCommandListImageCopy(ID3D12Device &device,
74 ID3D12CommandAllocator &command_allocator,
75 ID3D12Resource &resource_src,
76 ID3D12Resource &resource_dst,
77 D3D12_RESOURCE_STATES src_resource_state,
78 D3D12_RESOURCE_STATES dst_resource_state,
79 wil::com_ptr<ID3D12CommandList> &out_copy_command_list);
80
81/**
82 * Imports an image into D3D12 from a handle.
83 *
84 * @param device D3D12 device
85 * @param h handle corresponding to a shared image
86 *
87 * @throw std::logic_error if the handle is invalid, wil exceptions if the operation failed.
88 */
89wil::com_ptr<ID3D12Resource>
90importImage(ID3D12Device &device, HANDLE h);
91
92/**
93 * Imports a fence into D3D12 from a handle.
94 *
95 * @param device D3D12 device
96 * @param h handle corresponding to a shared fence
97 *
98 * @throw std::logic_error if the handle is invalid, wil exceptions if the operation failed.
99 */
100wil::com_ptr<ID3D12Fence1>
101importFence(ID3D12Device &device, HANDLE h);
102
103} // namespace xrt::auxiliary::d3d::d3d12
std::pair< wil::com_ptr< ID3D11Device >, wil::com_ptr< ID3D11DeviceContext > > createDevice(const wil::com_ptr< IDXGIAdapter > &adapter, u_logging_level log_level)
Create a D3D11 Device object.
Definition: d3d_d3d11_helpers.cpp:36
HRESULT createCommandLists(ID3D12Device &device, ID3D12CommandAllocator &command_allocator, ID3D12Resource &resource, enum xrt_swapchain_usage_bits bits, wil::com_ptr< ID3D12CommandList > out_acquire_command_list, wil::com_ptr< ID3D12CommandList > out_release_command_list)
Create command lists for a resource transitioning to/from app control.
Definition: d3d_d3d12_helpers.cpp:40
wil::com_ptr< ID3D12Resource > importImage(ID3D12Device &device, HANDLE h)
Imports an image into D3D12 from a handle.
Definition: d3d_d3d12_helpers.cpp:148
HRESULT createCommandListImageCopy(ID3D12Device &device, ID3D12CommandAllocator &command_allocator, ID3D12Resource &resource_src, ID3D12Resource &resource_dst, D3D12_RESOURCE_STATES src_resource_state, D3D12_RESOURCE_STATES dst_resource_state, wil::com_ptr< ID3D12CommandList > &out_copy_command_list)
Create a command list for image resource copying.
Definition: d3d_d3d12_helpers.cpp:83
wil::com_ptr< ID3D12Fence1 > importFence(ID3D12Device &device, HANDLE h)
Imports a fence into D3D12 from a handle.
Definition: d3d_d3d12_helpers.cpp:161
u_logging_level
Logging level enum.
Definition: u_logging.h:43
@ U_LOGGING_INFO
Info messages: not very verbose, not indicating a problem.
Definition: u_logging.h:46
xrt_swapchain_usage_bits
Usage of the swapchain images.
Definition: xrt_compositor.h:506
Basic logging functionality.
Header declaring XRT graphics interfaces.
Common defines and enums for XRT.