From a03d1421b81fe5fd7d26611ab68d9cf05c2fb47d Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 7 Apr 2023 19:10:46 +0100 Subject: [PATCH] c/client: Respect native compositor's extra usage bits --- .../compositor/client/comp_d3d11_client.cpp | 4 +++ .../compositor/client/comp_d3d12_client.cpp | 4 +++ src/xrt/compositor/client/comp_gl_client.c | 35 +++++++++++++------ src/xrt/compositor/client/comp_vk_client.c | 21 ++++++++--- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/src/xrt/compositor/client/comp_d3d11_client.cpp b/src/xrt/compositor/client/comp_d3d11_client.cpp index af206a3b8..a68c9c234 100644 --- a/src/xrt/compositor/client/comp_d3d11_client.cpp +++ b/src/xrt/compositor/client/comp_d3d11_client.cpp @@ -389,7 +389,11 @@ try { struct xrt_swapchain_create_info xinfo = *info; struct xrt_swapchain_create_info vkinfo = *info; + + // Update the create info. + xinfo.bits = (enum xrt_swapchain_usage_bits)(xsccp.extra_bits | xinfo.bits); vkinfo.format = vk_format; + vkinfo.bits = (enum xrt_swapchain_usage_bits)(xsccp.extra_bits | vkinfo.bits); std::unique_ptr sc = std::make_unique(); sc->data = std::make_unique(c->log_level); diff --git a/src/xrt/compositor/client/comp_d3d12_client.cpp b/src/xrt/compositor/client/comp_d3d12_client.cpp index dc94f7077..7f6333f84 100644 --- a/src/xrt/compositor/client/comp_d3d12_client.cpp +++ b/src/xrt/compositor/client/comp_d3d12_client.cpp @@ -425,7 +425,11 @@ try { struct xrt_swapchain_create_info xinfo = *info; struct xrt_swapchain_create_info vkinfo = *info; + + // Update the create info. + xinfo.bits = (enum xrt_swapchain_usage_bits)(xsccp.extra_bits | xinfo.bits); vkinfo.format = vk_format; + vkinfo.bits = (enum xrt_swapchain_usage_bits)(xsccp.extra_bits | vkinfo.bits); std::unique_ptr sc = std::make_unique(); sc->data = std::make_unique(c->log_level); diff --git a/src/xrt/compositor/client/comp_gl_client.c b/src/xrt/compositor/client/comp_gl_client.c index 29f24370a..5d4823dfa 100644 --- a/src/xrt/compositor/client/comp_gl_client.c +++ b/src/xrt/compositor/client/comp_gl_client.c @@ -416,8 +416,23 @@ client_gl_swapchain_create(struct xrt_compositor *xc, struct xrt_swapchain **out_xsc) { struct client_gl_compositor *c = client_gl_compositor(xc); + struct xrt_swapchain_create_properties xsccp = {0}; xrt_result_t xret = XRT_SUCCESS; + // Do before getting the context, not using ourselves. + xret = xrt_comp_get_swapchain_create_properties(xc, info, &xsccp); + if (xret != XRT_SUCCESS) { + U_LOG_E("Failed to get create properties: %u", xret); + return xret; + } + + // Check before setting the context. + int64_t vk_format = gl_format_to_vk(info->format); + if (vk_format == 0) { + U_LOG_E("Invalid format!"); + return XRT_ERROR_SWAPCHAIN_FORMAT_UNSUPPORTED; + } + xret = client_gl_compositor_context_begin(xc); if (xret != XRT_SUCCESS) { return xret; @@ -432,18 +447,16 @@ client_gl_swapchain_create(struct xrt_compositor *xc, } } - int64_t vk_format = gl_format_to_vk(info->format); - if (vk_format == 0) { - U_LOG_E("Invalid format!"); - client_gl_compositor_context_end(xc); - return XRT_ERROR_SWAPCHAIN_FORMAT_UNSUPPORTED; - } - struct xrt_swapchain_create_info xinfo = *info; - xinfo.format = vk_format; - struct xrt_swapchain_native *xscn = NULL; // Has to be NULL. - xret = xrt_comp_native_create_swapchain(c->xcn, &xinfo, &xscn); + struct xrt_swapchain_create_info vkinfo = *info; + // Update the create info. + xinfo.bits |= xsccp.extra_bits; + vkinfo.format = vk_format; + vkinfo.bits |= xsccp.extra_bits; + + struct xrt_swapchain_native *xscn = NULL; // Has to be NULL. + xret = xrt_comp_native_create_swapchain(c->xcn, &vkinfo, &xscn); if (xret != XRT_SUCCESS) { client_gl_compositor_context_end(xc); @@ -462,7 +475,7 @@ client_gl_swapchain_create(struct xrt_compositor *xc, struct xrt_swapchain *xsc = &xscn->base; struct client_gl_swapchain *sc = NULL; - if (NULL == c->create_swapchain(xc, info, xscn, &sc)) { + if (NULL == c->create_swapchain(xc, &xinfo, xscn, &sc)) { // Drop our reference, does NULL checking. xrt_swapchain_reference(&xsc, NULL); client_gl_compositor_context_end(xc); diff --git a/src/xrt/compositor/client/comp_vk_client.c b/src/xrt/compositor/client/comp_vk_client.c index 911e3abb0..122971583 100644 --- a/src/xrt/compositor/client/comp_vk_client.c +++ b/src/xrt/compositor/client/comp_vk_client.c @@ -614,8 +614,19 @@ client_vk_swapchain_create(struct xrt_compositor *xc, VkResult ret; xrt_result_t xret; + struct xrt_swapchain_create_properties xsccp = XRT_STRUCT_INIT; + xret = xrt_comp_get_swapchain_create_properties(&c->xcn->base, info, &xsccp); + if (xret != XRT_SUCCESS) { + VK_ERROR(vk, "Failed to get create properties: %u", xret); + return xret; + } + + // Update the create info. + struct xrt_swapchain_create_info xinfo = *info; + xinfo.bits |= xsccp.extra_bits; + struct xrt_swapchain_native *xscn = NULL; // Has to be NULL. - xret = xrt_comp_native_create_swapchain(c->xcn, info, &xscn); + xret = xrt_comp_native_create_swapchain(c->xcn, &xinfo, &xscn); if (xret != XRT_SUCCESS) { return xret; @@ -624,9 +635,9 @@ client_vk_swapchain_create(struct xrt_compositor *xc, struct xrt_swapchain *xsc = &xscn->base; - VkAccessFlags barrier_access_mask = vk_csci_get_barrier_access_mask(info->bits); - VkImageLayout barrier_optimal_layout = vk_csci_get_barrier_optimal_layout(info->format); - VkImageAspectFlags barrier_aspect_mask = vk_csci_get_barrier_aspect_mask(info->format); + VkAccessFlags barrier_access_mask = vk_csci_get_barrier_access_mask(xinfo.bits); + VkImageLayout barrier_optimal_layout = vk_csci_get_barrier_optimal_layout(xinfo.format); + VkImageAspectFlags barrier_aspect_mask = vk_csci_get_barrier_aspect_mask(xinfo.format); struct client_vk_swapchain *sc = U_TYPED_CALLOC(struct client_vk_swapchain); sc->base.base.destroy = client_vk_swapchain_destroy; @@ -639,7 +650,7 @@ client_vk_swapchain_create(struct xrt_compositor *xc, sc->xscn = xscn; for (uint32_t i = 0; i < xsc->image_count; i++) { - ret = vk_create_image_from_native(vk, info, &xscn->images[i], &sc->base.images[i], &sc->mems[i]); + ret = vk_create_image_from_native(vk, &xinfo, &xscn->images[i], &sc->base.images[i], &sc->mems[i]); if (ret != VK_SUCCESS) { return XRT_ERROR_VULKAN;