xrt: Make xrt_compositor::create_swapchain return xrt_result_t

This commit is contained in:
Jakob Bornecrantz 2020-07-16 15:01:06 +01:00 committed by Jakob Bornecrantz
parent 727e3bc2a6
commit b93017911e
9 changed files with 85 additions and 52 deletions

View file

@ -249,11 +249,13 @@ vk_format_to_gl(int64_t format)
} }
} }
static struct xrt_swapchain * static xrt_result_t
client_gl_swapchain_create(struct xrt_compositor *xc, client_gl_swapchain_create(struct xrt_compositor *xc,
struct xrt_swapchain_create_info *info) struct xrt_swapchain_create_info *info,
struct xrt_swapchain **out_xsc)
{ {
struct client_gl_compositor *c = client_gl_compositor(xc); struct client_gl_compositor *c = client_gl_compositor(xc);
xrt_result_t xret = XRT_SUCCESS;
if (info->array_size > 1) { if (info->array_size > 1) {
const char *version_str = (const char *)glGetString(GL_VERSION); const char *version_str = (const char *)glGetString(GL_VERSION);
@ -262,25 +264,27 @@ client_gl_swapchain_create(struct xrt_compositor *xc,
"%s - only one array layer is supported with " "%s - only one array layer is supported with "
"OpenGL ES 2\n", "OpenGL ES 2\n",
__func__); __func__);
return NULL; return XRT_ERROR_OPENGL;
} }
} }
int64_t vk_format = gl_format_to_vk(info->format); int64_t vk_format = gl_format_to_vk(info->format);
if (vk_format == 0) { if (vk_format == 0) {
fprintf(stderr, "%s - Invalid format!\n", __func__); fprintf(stderr, "%s - Invalid format!\n", __func__);
return NULL; return XRT_ERROR_VULKAN;
} }
struct xrt_swapchain_create_info vk_info = *info; struct xrt_swapchain_create_info xinfo = *info;
vk_info.format = vk_format; xinfo.format = vk_format;
struct xrt_swapchain_native *xscn = struct xrt_swapchain_native *xscn = NULL;
xrt_comp_native_create_swapchain(c->xcn, &vk_info); xret = xrt_comp_native_create_swapchain(c->xcn, &xinfo, &xscn);
if (xscn == NULL) { if (xret != XRT_SUCCESS) {
return NULL; return xret;
} }
assert(xscn != NULL);
struct xrt_swapchain *xsc = &xscn->base; struct xrt_swapchain *xsc = &xscn->base;
struct client_gl_swapchain *sc = struct client_gl_swapchain *sc =
@ -333,7 +337,8 @@ client_gl_swapchain_create(struct xrt_compositor *xc,
: GL_TEXTURE_2D_ARRAY, : GL_TEXTURE_2D_ARRAY,
prev_texture); prev_texture);
return &sc->base.base; *out_xsc = &sc->base.base;
return XRT_SUCCESS;
} }
static xrt_result_t static xrt_result_t

View file

@ -284,25 +284,29 @@ client_vk_compositor_layer_commit(struct xrt_compositor *xc, int64_t frame_id)
return xrt_comp_layer_commit(&c->xcn->base, frame_id); return xrt_comp_layer_commit(&c->xcn->base, frame_id);
} }
static struct xrt_swapchain * static xrt_result_t
client_vk_swapchain_create(struct xrt_compositor *xc, client_vk_swapchain_create(struct xrt_compositor *xc,
struct xrt_swapchain_create_info *info) struct xrt_swapchain_create_info *info,
struct xrt_swapchain **out_xsc)
{ {
struct client_vk_compositor *c = client_vk_compositor(xc); struct client_vk_compositor *c = client_vk_compositor(xc);
VkCommandBuffer cmd_buffer; VkCommandBuffer cmd_buffer;
VkResult ret; VkResult ret;
xrt_result_t xret;
struct xrt_swapchain_native *xscn = struct xrt_swapchain_native *xscn = NULL;
xrt_comp_native_create_swapchain(c->xcn, info); xret = xrt_comp_native_create_swapchain(c->xcn, info, &xscn);
if (xscn == NULL) { if (xret != XRT_SUCCESS) {
return NULL; return xret;
} }
assert(xscn != NULL);
struct xrt_swapchain *xsc = &xscn->base; struct xrt_swapchain *xsc = &xscn->base;
ret = vk_init_cmd_buffer(&c->vk, &cmd_buffer); ret = vk_init_cmd_buffer(&c->vk, &cmd_buffer);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
return NULL; return XRT_ERROR_VULKAN;
} }
VkImageSubresourceRange subresource_range = { VkImageSubresourceRange subresource_range = {
@ -331,7 +335,7 @@ client_vk_swapchain_create(struct xrt_compositor *xc,
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
return NULL; return XRT_ERROR_VULKAN;
} }
/* /*
@ -348,7 +352,7 @@ client_vk_swapchain_create(struct xrt_compositor *xc,
ret = vk_submit_cmd_buffer(&c->vk, cmd_buffer); ret = vk_submit_cmd_buffer(&c->vk, cmd_buffer);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
return NULL; return XRT_ERROR_FAILED_TO_SUBMIT_VULKAN_COMMANDS;
} }
// Prerecord command buffers for swapchain image ownership/layout // Prerecord command buffers for swapchain image ownership/layout
@ -356,11 +360,11 @@ client_vk_swapchain_create(struct xrt_compositor *xc,
for (uint32_t i = 0; i < xsc->num_images; i++) { for (uint32_t i = 0; i < xsc->num_images; i++) {
ret = vk_init_cmd_buffer(&c->vk, &sc->acquire[i]); ret = vk_init_cmd_buffer(&c->vk, &sc->acquire[i]);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
return NULL; return XRT_ERROR_VULKAN;
} }
ret = vk_init_cmd_buffer(&c->vk, &sc->release[i]); ret = vk_init_cmd_buffer(&c->vk, &sc->release[i]);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
return NULL; return XRT_ERROR_VULKAN;
} }
VkImageSubresourceRange subresource_range = { VkImageSubresourceRange subresource_range = {
@ -425,17 +429,19 @@ client_vk_swapchain_create(struct xrt_compositor *xc,
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
VK_ERROR(vk, "vkEndCommandBuffer: %s", VK_ERROR(vk, "vkEndCommandBuffer: %s",
vk_result_string(ret)); vk_result_string(ret));
return NULL; return XRT_ERROR_VULKAN;
} }
ret = c->vk.vkEndCommandBuffer(sc->release[i]); ret = c->vk.vkEndCommandBuffer(sc->release[i]);
if (ret != VK_SUCCESS) { if (ret != VK_SUCCESS) {
VK_ERROR(vk, "vkEndCommandBuffer: %s", VK_ERROR(vk, "vkEndCommandBuffer: %s",
vk_result_string(ret)); vk_result_string(ret));
return NULL; return XRT_ERROR_VULKAN;
} }
} }
return &sc->base.base; *out_xsc = &sc->base.base;
return XRT_SUCCESS;
} }
struct client_vk_compositor * struct client_vk_compositor *

View file

@ -271,9 +271,10 @@ comp_compositor_garbage_collect(struct comp_compositor *c);
* *
* @public @memberof comp_compositor * @public @memberof comp_compositor
*/ */
struct xrt_swapchain * xrt_result_t
comp_swapchain_create(struct xrt_compositor *xc, comp_swapchain_create(struct xrt_compositor *xc,
struct xrt_swapchain_create_info *info); struct xrt_swapchain_create_info *info,
struct xrt_swapchain **out_xsc);
/*! /*!
* Swapchain destruct is delayed until it is safe to destroy them, this function * Swapchain destruct is delayed until it is safe to destroy them, this function

View file

@ -221,9 +221,10 @@ err_image:
* *
*/ */
struct xrt_swapchain * xrt_result_t
comp_swapchain_create(struct xrt_compositor *xc, comp_swapchain_create(struct xrt_compositor *xc,
struct xrt_swapchain_create_info *info) struct xrt_swapchain_create_info *info,
struct xrt_swapchain **out_xsc)
{ {
struct comp_compositor *c = comp_compositor(xc); struct comp_compositor *c = comp_compositor(xc);
VkCommandBuffer cmd_buffer; VkCommandBuffer cmd_buffer;
@ -259,7 +260,7 @@ comp_swapchain_create(struct xrt_compositor *xc,
//! @todo memory leak of image fds and swapchain //! @todo memory leak of image fds and swapchain
// see // see
// https://gitlab.freedesktop.org/monado/monado/issues/20 // https://gitlab.freedesktop.org/monado/monado/issues/20
return NULL; return XRT_ERROR_VULKAN;
} }
vk_create_sampler(&c->vk, &sc->images[i].sampler); vk_create_sampler(&c->vk, &sc->images[i].sampler);
@ -332,7 +333,8 @@ comp_swapchain_create(struct xrt_compositor *xc,
vk_submit_cmd_buffer(&c->vk, cmd_buffer); vk_submit_cmd_buffer(&c->vk, cmd_buffer);
return &sc->base.base; *out_xsc = &sc->base.base;
return XRT_SUCCESS;
} }
static void static void

View file

@ -425,8 +425,9 @@ struct xrt_compositor
/*! /*!
* Create a swapchain with a set of images. * Create a swapchain with a set of images.
*/ */
struct xrt_swapchain *(*create_swapchain)( xrt_result_t (*create_swapchain)(struct xrt_compositor *xc,
struct xrt_compositor *xc, struct xrt_swapchain_create_info *info); struct xrt_swapchain_create_info *info,
struct xrt_swapchain **out_xsc);
/*! /*!
* Poll events from this compositor. * Poll events from this compositor.
@ -548,11 +549,12 @@ struct xrt_compositor
* *
* @public @memberof xrt_compositor * @public @memberof xrt_compositor
*/ */
static inline struct xrt_swapchain * static inline xrt_result_t
xrt_comp_create_swapchain(struct xrt_compositor *xc, xrt_comp_create_swapchain(struct xrt_compositor *xc,
struct xrt_swapchain_create_info *info) struct xrt_swapchain_create_info *info,
struct xrt_swapchain **out_xsc)
{ {
return xc->create_swapchain(xc, info); return xc->create_swapchain(xc, info, out_xsc);
} }
/*! /*!
@ -916,12 +918,17 @@ struct xrt_compositor_native
* *
* @public @memberof xrt_compositor_native * @public @memberof xrt_compositor_native
*/ */
static inline struct xrt_swapchain_native * static inline xrt_result_t
xrt_comp_native_create_swapchain(struct xrt_compositor_native *xcn, xrt_comp_native_create_swapchain(struct xrt_compositor_native *xcn,
struct xrt_swapchain_create_info *info) struct xrt_swapchain_create_info *info,
struct xrt_swapchain_native **out_xscn)
{ {
struct xrt_swapchain *xsc = xrt_comp_create_swapchain(&xcn->base, info); struct xrt_swapchain *xsc = NULL;
return (struct xrt_swapchain_native *)xsc; xrt_result_t ret = xrt_comp_create_swapchain(&xcn->base, info, &xsc);
if (ret == XRT_SUCCESS) {
*out_xscn = (struct xrt_swapchain_native *)xsc;
}
return ret;
} }
/*! /*!

View file

@ -14,5 +14,7 @@ typedef enum xrt_result
XRT_SUCCESS = 0, XRT_SUCCESS = 0,
XRT_ERROR_IPC_FAILURE = -1, XRT_ERROR_IPC_FAILURE = -1,
XRT_ERROR_NO_IMAGE_AVAILABLE = -2, XRT_ERROR_NO_IMAGE_AVAILABLE = -2,
XRT_ERROR_FAILED_TO_SUBMIT_VULKAN_COMMANDS = -3, XRT_ERROR_VULKAN = -3,
XRT_ERROR_OPENGL = -4,
XRT_ERROR_FAILED_TO_SUBMIT_VULKAN_COMMANDS = -5,
} xrt_result_t; } xrt_result_t;

View file

@ -164,9 +164,10 @@ ipc_compositor_swapchain_release_image(struct xrt_swapchain *xsc,
* *
*/ */
static struct xrt_swapchain * static xrt_result_t
ipc_compositor_swapchain_create(struct xrt_compositor *xc, ipc_compositor_swapchain_create(struct xrt_compositor *xc,
struct xrt_swapchain_create_info *info) struct xrt_swapchain_create_info *info,
struct xrt_swapchain **out_xsc)
{ {
struct ipc_client_compositor *icc = ipc_client_compositor(xc); struct ipc_client_compositor *icc = ipc_client_compositor(xc);
@ -184,7 +185,7 @@ ipc_compositor_swapchain_create(struct xrt_compositor *xc,
remote_fds, // fds remote_fds, // fds
IPC_MAX_SWAPCHAIN_FDS); // fds IPC_MAX_SWAPCHAIN_FDS); // fds
if (r != XRT_SUCCESS) { if (r != XRT_SUCCESS) {
return NULL; return r;
} }
struct ipc_client_swapchain *ics = struct ipc_client_swapchain *ics =
@ -202,7 +203,8 @@ ipc_compositor_swapchain_create(struct xrt_compositor *xc,
ics->base.images[i].size = size; ics->base.images[i].size = size;
} }
return &ics->base.base; *out_xsc = &ics->base.base;
return XRT_SUCCESS;
} }
static xrt_result_t static xrt_result_t

View file

@ -280,6 +280,8 @@ ipc_handle_swapchain_create(volatile struct ipc_client_state *ics,
xrt_graphics_buffer_handle_t *out_handles, xrt_graphics_buffer_handle_t *out_handles,
uint32_t *out_num_handles) uint32_t *out_num_handles)
{ {
xrt_result_t xret = XRT_SUCCESS;
// Our handle is just the index for now. // Our handle is just the index for now.
uint32_t index = 0; uint32_t index = 0;
for (; index < IPC_MAX_CLIENT_SWAPCHAINS; index++) { for (; index < IPC_MAX_CLIENT_SWAPCHAINS; index++) {
@ -293,12 +295,16 @@ ipc_handle_swapchain_create(volatile struct ipc_client_state *ics,
return XRT_ERROR_IPC_FAILURE; return XRT_ERROR_IPC_FAILURE;
} }
// create the swapchain
struct xrt_swapchain *xsc = NULL;
xret = xrt_comp_create_swapchain(ics->xc, info, &xsc);
if (xret != XRT_SUCCESS) {
return xret;
}
// It's now safe to increment the number of swapchains. // It's now safe to increment the number of swapchains.
ics->num_swapchains++; ics->num_swapchains++;
// create the swapchain
struct xrt_swapchain *xsc = xrt_comp_create_swapchain(ics->xc, info);
uint32_t num_images = xsc->num_images; uint32_t num_images = xsc->num_images;
IPC_SPEW(ics->server, "IPC: Created swapchain %d\n", index); IPC_SPEW(ics->server, "IPC: Created swapchain %d\n", index);

View file

@ -198,6 +198,8 @@ oxr_create_swapchain(struct oxr_logger *log,
const XrSwapchainCreateInfo *createInfo, const XrSwapchainCreateInfo *createInfo,
struct oxr_swapchain **out_swapchain) struct oxr_swapchain **out_swapchain)
{ {
xrt_result_t xret = XRT_SUCCESS;
struct xrt_swapchain_create_info info; struct xrt_swapchain_create_info info;
info.create = convert_create_flags(createInfo->createFlags); info.create = convert_create_flags(createInfo->createFlags);
info.bits = convert_usage_bits(createInfo->usageFlags); info.bits = convert_usage_bits(createInfo->usageFlags);
@ -209,13 +211,13 @@ oxr_create_swapchain(struct oxr_logger *log,
info.array_size = createInfo->arraySize; info.array_size = createInfo->arraySize;
info.mip_count = createInfo->mipCount; info.mip_count = createInfo->mipCount;
struct xrt_swapchain *xsc = struct xrt_swapchain *xsc = NULL;
xrt_comp_create_swapchain(sess->compositor, &info); xret = xrt_comp_create_swapchain(sess->compositor, &info, &xsc);
if (xret != XRT_SUCCESS) {
if (xsc == NULL) {
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, return oxr_error(log, XR_ERROR_RUNTIME_FAILURE,
"Failed to create swapchain"); "Failed to create swapchain");
} }
assert(xsc != NULL);
struct oxr_swapchain *sc = NULL; struct oxr_swapchain *sc = NULL;
OXR_ALLOCATE_HANDLE_OR_RETURN(log, sc, OXR_XR_DEBUG_SWAPCHAIN, OXR_ALLOCATE_HANDLE_OR_RETURN(log, sc, OXR_XR_DEBUG_SWAPCHAIN,