Monado OpenXR Runtime
comp_d3d12_client.cpp File Reference

D3D12 client side glue to compositor implementation. More...

#include "comp_d3d12_client.h"
#include "comp_d3d_common.hpp"
#include "xrt/xrt_compositor.h"
#include "xrt/xrt_config_os.h"
#include "xrt/xrt_handles.h"
#include "xrt/xrt_deleters.hpp"
#include "xrt/xrt_results.h"
#include "xrt/xrt_vulkan_includes.h"
#include "d3d/d3d_dxgi_formats.h"
#include "d3d/d3d_d3d12_helpers.hpp"
#include "d3d/d3d_d3d12_fence.hpp"
#include "d3d/d3d_d3d12_bits.h"
#include "d3d/d3d_d3d12_allocator.hpp"
#include "util/u_misc.h"
#include "util/u_pretty_print.h"
#include "util/u_time.h"
#include "util/u_logging.h"
#include "util/u_debug.h"
#include "util/u_handles.h"
#include "util/u_win32_com_guard.hpp"
#include <d3d12.h>
#include <wil/resource.h>
#include <wil/com.h>
#include <wil/result_macros.h>
#include <assert.h>
#include <memory>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <chrono>
#include <array>
Include dependency graph for comp_d3d12_client.cpp:

Data Structures

class  client_d3d12_compositor
 Wraps the real compositor providing a D3D12 based interface. More...
 
struct  client_d3d12_swapchain_data
 Split out from client_d3d12_swapchain to ensure that it is standard layout, std::vector for instance is not standard layout. More...
 
struct  client_d3d12_swapchain
 Wraps the real compositor swapchain providing a D3D12 based interface. More...
 

Macros

#define D3D_SPEW(c, ...)   U_LOG_IFL_T(c->log_level, __VA_ARGS__);
 Spew level logging. More...
 
#define D3D_DEBUG(c, ...)   U_LOG_IFL_D(c->log_level, __VA_ARGS__);
 Debug level logging. More...
 
#define D3D_INFO(c, ...)   U_LOG_IFL_I(c->log_level, __VA_ARGS__);
 Info level logging. More...
 
#define D3D_WARN(c, ...)   U_LOG_IFL_W(c->log_level, __VA_ARGS__);
 Warn level logging. More...
 
#define D3D_ERROR(c, ...)   U_LOG_IFL_E(c->log_level, __VA_ARGS__);
 Error level logging. More...
 

Typedefs

using unique_compositor_semaphore_ref = std::unique_ptr< struct xrt_compositor_semaphore, xrt::deleters::reference_deleter< struct xrt_compositor_semaphore, xrt_compositor_semaphore_reference > >
 
using unique_swapchain_ref = std::unique_ptr< struct xrt_swapchain, xrt::deleters::reference_deleter< struct xrt_swapchain, xrt_swapchain_reference > >
 

Functions

 DEBUG_GET_ONCE_BOOL_OPTION (barriers, "D3D12_COMPOSITOR_BARRIERS", false)
 
 DEBUG_GET_ONCE_BOOL_OPTION (compositor_copy, "D3D12_COMPOSITOR_COPY", true)
 
static DWORD convertTimeoutToWindowsMilliseconds (int64_t timeout_ns)
 
static bool isPowerOfTwo (uint32_t n)
 
static uint32_t nextPowerOfTwo (uint32_t n)
 
template<size_t N>
static bool formatMessage (DWORD err, char(&buf)[N])
 
static xrt_result_t client_d3d12_swapchain_barrier_to_app (client_d3d12_swapchain *sc, uint32_t index)
 
static xrt_result_t client_d3d12_swapchain_barrier_to_compositor (client_d3d12_swapchain *sc, uint32_t index)
 
static void client_d3d12_swapchain_scale_rect (struct xrt_swapchain *xsc, xrt_normalized_rect *inOutRect)
 
static xrt_result_t client_d3d12_swapchain_acquire_image (struct xrt_swapchain *xsc, uint32_t *out_index)
 
static xrt_result_t client_d3d12_swapchain_wait_image (struct xrt_swapchain *xsc, int64_t timeout_ns, uint32_t index)
 
static xrt_result_t client_d3d12_swapchain_barrier_image (struct xrt_swapchain *xsc, enum xrt_barrier_direction direction, uint32_t index)
 
static xrt_result_t client_d3d12_swapchain_release_image (struct xrt_swapchain *xsc, uint32_t index)
 
static xrt_result_t client_d3d12_swapchain_release_image_copy (struct xrt_swapchain *xsc, uint32_t index)
 
static void client_d3d12_swapchain_destroy (struct xrt_swapchain *xsc)
 
xrt_result_t client_d3d12_create_swapchain (struct xrt_compositor *xc, const struct xrt_swapchain_create_info *info, struct xrt_swapchain **out_xsc)
 
static xrt_result_t client_d3d12_compositor_passthrough_create (struct xrt_compositor *xc, const struct xrt_passthrough_create_info *info)
 
static xrt_result_t client_d3d12_compositor_passthrough_layer_create (struct xrt_compositor *xc, const struct xrt_passthrough_layer_create_info *info)
 
static xrt_result_t client_d3d12_compositor_passthrough_destroy (struct xrt_compositor *xc)
 
static xrt_result_t client_d3d12_compositor_begin_session (struct xrt_compositor *xc, const struct xrt_begin_session_info *info)
 
static xrt_result_t client_d3d12_compositor_end_session (struct xrt_compositor *xc)
 
static xrt_result_t client_d3d12_compositor_wait_frame (struct xrt_compositor *xc, int64_t *out_frame_id, int64_t *predicted_display_time, int64_t *predicted_display_period)
 
static xrt_result_t client_d3d12_compositor_begin_frame (struct xrt_compositor *xc, int64_t frame_id)
 
static xrt_result_t client_d3d12_compositor_discard_frame (struct xrt_compositor *xc, int64_t frame_id)
 
static xrt_result_t client_d3d12_compositor_layer_begin (struct xrt_compositor *xc, const struct xrt_layer_frame_data *data)
 
static xrt_result_t client_d3d12_compositor_layer_projection (struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc[XRT_MAX_VIEWS], const struct xrt_layer_data *data)
 
static xrt_result_t client_d3d12_compositor_layer_projection_depth (struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc[XRT_MAX_VIEWS], struct xrt_swapchain *d_xsc[XRT_MAX_VIEWS], const struct xrt_layer_data *data)
 
static xrt_result_t client_d3d12_compositor_layer_quad (struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
 
static xrt_result_t client_d3d12_compositor_layer_cube (struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
 
static xrt_result_t client_d3d12_compositor_layer_cylinder (struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
 
static xrt_result_t client_d3d12_compositor_layer_equirect1 (struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
 
static xrt_result_t client_d3d12_compositor_layer_equirect2 (struct xrt_compositor *xc, struct xrt_device *xdev, struct xrt_swapchain *xsc, const struct xrt_layer_data *data)
 
static xrt_result_t client_d3d12_compositor_layer_passthrough (struct xrt_compositor *xc, struct xrt_device *xdev, const struct xrt_layer_data *data)
 
static xrt_result_t client_d3d12_compositor_layer_commit (struct xrt_compositor *xc, xrt_graphics_sync_handle_t sync_handle)
 
static xrt_result_t client_d3d12_compositor_get_swapchain_create_properties (struct xrt_compositor *xc, const struct xrt_swapchain_create_info *info, struct xrt_swapchain_create_properties *xsccp)
 
static void client_d3d12_compositor_destroy (struct xrt_compositor *xc)
 
static void client_d3d12_compositor_init_try_timeline_semaphores (struct client_d3d12_compositor *c)
 
static void client_d3d12_compositor_init_try_internal_blocking (struct client_d3d12_compositor *c)
 
struct xrt_compositor_d3d12client_d3d12_compositor_create (struct xrt_compositor_native *xcn, ID3D12Device *device, ID3D12CommandQueue *queue)
 

Variables

static constexpr auto kFenceTimeout = 500ms
 
static constexpr size_t kErrorBufSize = 256
 

Detailed Description

Macro Definition Documentation

◆ D3D_DEBUG

#define D3D_DEBUG (   c,
  ... 
)    U_LOG_IFL_D(c->log_level, __VA_ARGS__);
related

Debug level logging.

◆ D3D_ERROR

#define D3D_ERROR (   c,
  ... 
)    U_LOG_IFL_E(c->log_level, __VA_ARGS__);
related

Error level logging.

◆ D3D_INFO

#define D3D_INFO (   c,
  ... 
)    U_LOG_IFL_I(c->log_level, __VA_ARGS__);
related

Info level logging.

◆ D3D_SPEW

#define D3D_SPEW (   c,
  ... 
)    U_LOG_IFL_T(c->log_level, __VA_ARGS__);
related

Spew level logging.

◆ D3D_WARN

#define D3D_WARN (   c,
  ... 
)    U_LOG_IFL_W(c->log_level, __VA_ARGS__);
related

Warn level logging.

Function Documentation

◆ client_d3d12_create_swapchain()

xrt_result_t client_d3d12_create_swapchain ( struct xrt_compositor xc,
const struct xrt_swapchain_create_info info,
struct xrt_swapchain **  out_xsc 
)

◆ client_d3d12_swapchain_wait_image()

static xrt_result_t client_d3d12_swapchain_wait_image ( struct xrt_swapchain xsc,
int64_t  timeout_ns,
uint32_t  index 
)
static