2023-02-27 18:30:39 +00:00
|
|
|
// Copyright 2020-2023, Collabora, Ltd.
|
2020-04-11 10:09:24 +00:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
2020-05-27 21:09:32 +00:00
|
|
|
* @brief Shared default implementation of the instance with compositor.
|
2020-04-11 10:09:24 +00:00
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
*/
|
|
|
|
|
2023-02-27 18:30:39 +00:00
|
|
|
#include "xrt/xrt_space.h"
|
2022-05-07 12:21:13 +00:00
|
|
|
#include "xrt/xrt_system.h"
|
2022-06-18 14:32:32 +00:00
|
|
|
#include "xrt/xrt_config_build.h"
|
2022-05-07 12:21:13 +00:00
|
|
|
|
2022-07-28 20:29:02 +00:00
|
|
|
#include "os/os_time.h"
|
|
|
|
|
2022-05-20 10:13:58 +00:00
|
|
|
#include "util/u_debug.h"
|
2021-06-14 18:11:45 +00:00
|
|
|
#include "util/u_trace_marker.h"
|
2022-05-07 12:21:13 +00:00
|
|
|
#include "util/u_system_helpers.h"
|
2021-06-14 18:11:45 +00:00
|
|
|
|
2023-03-03 20:42:33 +00:00
|
|
|
#ifdef XRT_MODULE_COMPOSITOR_MAIN
|
2022-11-13 23:12:38 +00:00
|
|
|
#include "main/comp_main_interface.h"
|
|
|
|
#endif
|
|
|
|
|
2020-05-27 21:09:32 +00:00
|
|
|
#include "target_instance_parts.h"
|
2020-05-26 21:46:11 +00:00
|
|
|
|
2022-05-07 12:21:13 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
2021-06-14 18:11:45 +00:00
|
|
|
|
2023-03-03 20:42:33 +00:00
|
|
|
#ifdef XRT_MODULE_COMPOSITOR_MAIN
|
2022-05-20 10:13:58 +00:00
|
|
|
#define USE_NULL_DEFAULT (false)
|
|
|
|
#else
|
|
|
|
#define USE_NULL_DEFAULT (true)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DEBUG_GET_ONCE_BOOL_OPTION(use_null, "XRT_COMPOSITOR_NULL", USE_NULL_DEFAULT)
|
|
|
|
|
|
|
|
xrt_result_t
|
|
|
|
null_compositor_create_system(struct xrt_device *xdev, struct xrt_system_compositor **out_xsysc);
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-06-14 18:11:45 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Internal functions.
|
|
|
|
*
|
|
|
|
*/
|
2020-04-11 10:09:24 +00:00
|
|
|
|
2022-05-07 12:21:13 +00:00
|
|
|
static xrt_result_t
|
|
|
|
t_instance_create_system(struct xrt_instance *xinst,
|
|
|
|
struct xrt_system_devices **out_xsysd,
|
2023-02-27 18:30:39 +00:00
|
|
|
struct xrt_space_overseer **out_xso,
|
2022-05-07 12:21:13 +00:00
|
|
|
struct xrt_system_compositor **out_xsysc)
|
|
|
|
{
|
2022-11-20 13:11:18 +00:00
|
|
|
XRT_TRACE_MARKER();
|
|
|
|
|
2022-05-07 12:21:13 +00:00
|
|
|
assert(out_xsysd != NULL);
|
|
|
|
assert(*out_xsysd == NULL);
|
2023-02-27 18:30:39 +00:00
|
|
|
assert(out_xso != NULL);
|
|
|
|
assert(*out_xso == NULL);
|
2022-05-07 12:21:13 +00:00
|
|
|
assert(out_xsysc == NULL || *out_xsysc == NULL);
|
|
|
|
|
|
|
|
struct xrt_system_compositor *xsysc = NULL;
|
2023-02-27 18:30:39 +00:00
|
|
|
struct xrt_space_overseer *xso = NULL;
|
2022-05-07 12:21:13 +00:00
|
|
|
struct xrt_system_devices *xsysd = NULL;
|
|
|
|
xrt_result_t xret = XRT_SUCCESS;
|
|
|
|
|
2023-02-27 18:30:39 +00:00
|
|
|
xret = u_system_devices_create_from_prober(xinst, &xsysd, &xso);
|
2022-05-07 12:21:13 +00:00
|
|
|
if (xret != XRT_SUCCESS) {
|
|
|
|
return xret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Early out if we only want devices.
|
|
|
|
if (out_xsysc == NULL) {
|
|
|
|
*out_xsysd = xsysd;
|
|
|
|
return XRT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct xrt_device *head = xsysd->roles.head;
|
|
|
|
|
2022-05-20 10:13:58 +00:00
|
|
|
bool use_null = debug_get_bool_option_use_null();
|
|
|
|
|
2023-03-03 20:42:33 +00:00
|
|
|
#ifdef XRT_MODULE_COMPOSITOR_NULL
|
2022-05-20 10:13:58 +00:00
|
|
|
if (use_null) {
|
|
|
|
xret = null_compositor_create_system(head, &xsysc);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (use_null) {
|
|
|
|
U_LOG_E("The null compositor is not compiled in!");
|
|
|
|
xret = XRT_ERROR_VULKAN;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-03-03 20:42:33 +00:00
|
|
|
#ifdef XRT_MODULE_COMPOSITOR_MAIN
|
2022-05-20 10:13:58 +00:00
|
|
|
if (xret == XRT_SUCCESS && xsysc == NULL) {
|
2022-12-09 18:24:32 +00:00
|
|
|
xret = comp_main_create_system_compositor(head, NULL, &xsysc);
|
2022-05-20 10:13:58 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (!use_null) {
|
|
|
|
U_LOG_E("Explicitly didn't request the null compositor, but the main compositor hasn't been built!");
|
|
|
|
xret = XRT_ERROR_VULKAN;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-05-07 12:21:13 +00:00
|
|
|
if (xret != XRT_SUCCESS) {
|
2023-02-27 18:30:39 +00:00
|
|
|
xrt_space_overseer_destroy(&xso);
|
2022-05-07 12:21:13 +00:00
|
|
|
xrt_system_devices_destroy(&xsysd);
|
|
|
|
return xret;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_xsysd = xsysd;
|
2023-02-27 18:30:39 +00:00
|
|
|
*out_xso = xso;
|
2022-05-07 12:21:13 +00:00
|
|
|
*out_xsysc = xsysc;
|
|
|
|
|
|
|
|
return xret;
|
|
|
|
}
|
|
|
|
|
2021-06-14 18:11:45 +00:00
|
|
|
|
2020-04-11 10:09:24 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Exported function(s).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-05-17 17:45:53 +00:00
|
|
|
xrt_result_t
|
2022-04-12 21:20:11 +00:00
|
|
|
xrt_instance_create(struct xrt_instance_info *ii, struct xrt_instance **out_xinst)
|
2020-04-11 10:09:24 +00:00
|
|
|
{
|
|
|
|
struct xrt_prober *xp = NULL;
|
|
|
|
|
2021-06-14 18:11:45 +00:00
|
|
|
u_trace_marker_init();
|
|
|
|
|
2022-11-20 13:11:18 +00:00
|
|
|
XRT_TRACE_MARKER();
|
|
|
|
|
2020-05-26 21:46:11 +00:00
|
|
|
int ret = xrt_prober_create_with_lists(&xp, &target_lists);
|
2020-04-11 10:09:24 +00:00
|
|
|
if (ret < 0) {
|
2022-05-17 17:45:53 +00:00
|
|
|
return XRT_ERROR_PROBER_CREATION_FAILED;
|
2020-04-11 10:09:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct t_instance *tinst = U_TYPED_CALLOC(struct t_instance);
|
2022-05-07 12:21:13 +00:00
|
|
|
tinst->base.create_system = t_instance_create_system;
|
2020-04-11 10:09:24 +00:00
|
|
|
tinst->base.get_prober = t_instance_get_prober;
|
|
|
|
tinst->base.destroy = t_instance_destroy;
|
|
|
|
tinst->xp = xp;
|
|
|
|
|
2022-07-28 20:29:02 +00:00
|
|
|
tinst->base.startup_timestamp = os_monotonic_get_ns();
|
|
|
|
|
2020-04-11 10:09:24 +00:00
|
|
|
*out_xinst = &tinst->base;
|
|
|
|
|
2022-05-17 17:45:53 +00:00
|
|
|
return XRT_SUCCESS;
|
2020-04-11 10:09:24 +00:00
|
|
|
}
|