From 52f790289d37605ad6bac0bd89101945a4315019 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 24 Mar 2023 16:15:20 +0000 Subject: [PATCH] st/oxr: Swapchain destroy was the same for all APIs --- src/xrt/state_trackers/oxr/oxr_swapchain.c | 29 +++++++++++++++++++ .../state_trackers/oxr/oxr_swapchain_d3d11.c | 25 ++-------------- .../state_trackers/oxr/oxr_swapchain_d3d12.c | 25 ++-------------- src/xrt/state_trackers/oxr/oxr_swapchain_gl.c | 24 ++------------- src/xrt/state_trackers/oxr/oxr_swapchain_vk.c | 25 ++-------------- 5 files changed, 37 insertions(+), 91 deletions(-) diff --git a/src/xrt/state_trackers/oxr/oxr_swapchain.c b/src/xrt/state_trackers/oxr/oxr_swapchain.c index 72d640f29..e95360e59 100644 --- a/src/xrt/state_trackers/oxr/oxr_swapchain.c +++ b/src/xrt/state_trackers/oxr/oxr_swapchain.c @@ -173,6 +173,34 @@ release_image(struct oxr_logger *log, struct oxr_swapchain *sc, const XrSwapchai return oxr_session_success_result(sc->sess); } +static XrResult +destroy(struct oxr_logger *log, struct oxr_swapchain *sc) +{ + // Release any waited image. + if (sc->waited.yes) { + sc->release_image(log, sc, NULL); + } + + // Release any acquired images. + XrSwapchainImageWaitInfo waitInfo = {0}; + while (!u_index_fifo_is_empty(&sc->acquired.fifo)) { + sc->wait_image(log, sc, &waitInfo); + sc->release_image(log, sc, NULL); + } + + // Drop our reference, does NULL checking. + xrt_swapchain_reference(&sc->swapchain, NULL); + + return XR_SUCCESS; +} + + +/* + * + * Handle function. + * + */ + static XrResult destroy_handle(struct oxr_logger *log, struct oxr_handle_base *hb) { @@ -236,6 +264,7 @@ oxr_create_swapchain(struct oxr_logger *log, sc->acquire_image = acquire_image; sc->wait_image = wait_image; sc->release_image = release_image; + sc->destroy = destroy; sc->is_static = (createInfo->createFlags & XR_SWAPCHAIN_CREATE_STATIC_IMAGE_BIT) != 0; *out_swapchain = sc; diff --git a/src/xrt/state_trackers/oxr/oxr_swapchain_d3d11.c b/src/xrt/state_trackers/oxr/oxr_swapchain_d3d11.c index 9a68881d2..499063e96 100644 --- a/src/xrt/state_trackers/oxr/oxr_swapchain_d3d11.c +++ b/src/xrt/state_trackers/oxr/oxr_swapchain_d3d11.c @@ -1,4 +1,4 @@ -// Copyright 2019-2021, Collabora, Ltd. +// Copyright 2019-2023, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -18,27 +18,6 @@ #include "oxr_logger.h" -static XrResult -oxr_swapchain_d3d11_destroy(struct oxr_logger *log, struct oxr_swapchain *sc) -{ - // Release any waited image. - if (sc->waited.yes) { - sc->release_image(log, sc, NULL); - } - - // Release any acquired images. - XrSwapchainImageWaitInfo waitInfo = {0}; - while (!u_index_fifo_is_empty(&sc->acquired.fifo)) { - sc->wait_image(log, sc, &waitInfo); - sc->release_image(log, sc, NULL); - } - - // Drop our reference, does NULL checking. - xrt_swapchain_reference(&sc->swapchain, NULL); - - return XR_SUCCESS; -} - static XrResult oxr_swapchain_d3d11_enumerate_images(struct oxr_logger *log, struct oxr_swapchain *sc, @@ -69,7 +48,7 @@ oxr_swapchain_d3d11_create(struct oxr_logger *log, return ret; } - sc->destroy = oxr_swapchain_d3d11_destroy; + // Set our API specific function(s). sc->enumerate_images = oxr_swapchain_d3d11_enumerate_images; *out_swapchain = sc; diff --git a/src/xrt/state_trackers/oxr/oxr_swapchain_d3d12.c b/src/xrt/state_trackers/oxr/oxr_swapchain_d3d12.c index 12bda159f..7944e22d5 100644 --- a/src/xrt/state_trackers/oxr/oxr_swapchain_d3d12.c +++ b/src/xrt/state_trackers/oxr/oxr_swapchain_d3d12.c @@ -1,4 +1,4 @@ -// Copyright 2019-2022, Collabora, Ltd. +// Copyright 2019-2023, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -19,27 +19,6 @@ #include "oxr_api_verify.h" -static XrResult -oxr_swapchain_d3d12_destroy(struct oxr_logger *log, struct oxr_swapchain *sc) -{ - // Release any waited image. - if (sc->waited.yes) { - sc->release_image(log, sc, NULL); - } - - // Release any acquired images. - XrSwapchainImageWaitInfo waitInfo = {0}; - while (!u_index_fifo_is_empty(&sc->acquired.fifo)) { - sc->wait_image(log, sc, &waitInfo); - sc->release_image(log, sc, NULL); - } - - // Drop our reference, does NULL checking. - xrt_swapchain_reference(&sc->swapchain, NULL); - - return XR_SUCCESS; -} - static XrResult oxr_swapchain_d3d12_enumerate_images(struct oxr_logger *log, struct oxr_swapchain *sc, @@ -77,7 +56,7 @@ oxr_swapchain_d3d12_create(struct oxr_logger *log, return ret; } - sc->destroy = oxr_swapchain_d3d12_destroy; + // Set our API specific function(s). sc->enumerate_images = oxr_swapchain_d3d12_enumerate_images; *out_swapchain = sc; diff --git a/src/xrt/state_trackers/oxr/oxr_swapchain_gl.c b/src/xrt/state_trackers/oxr/oxr_swapchain_gl.c index 7f089771b..31e3b1f72 100644 --- a/src/xrt/state_trackers/oxr/oxr_swapchain_gl.c +++ b/src/xrt/state_trackers/oxr/oxr_swapchain_gl.c @@ -1,4 +1,4 @@ -// Copyright 2019-2022, Collabora, Ltd. +// Copyright 2019-2023, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -19,26 +19,6 @@ #if defined(XR_USE_GRAPHICS_API_OPENGL) || defined(XR_USE_GRAPHICS_API_OPENGL_ES) -static XrResult -oxr_swapchain_gl_destroy(struct oxr_logger *log, struct oxr_swapchain *sc) -{ - // Release any waited image. - if (sc->waited.yes) { - sc->release_image(log, sc, NULL); - } - - // Release any acquired images. - XrSwapchainImageWaitInfo waitInfo = {0}; - while (!u_index_fifo_is_empty(&sc->acquired.fifo)) { - sc->wait_image(log, sc, &waitInfo); - sc->release_image(log, sc, NULL); - } - - // Drop our reference, does NULL checking. - xrt_swapchain_reference(&sc->swapchain, NULL); - - return XR_SUCCESS; -} #if defined(XR_USE_GRAPHICS_API_OPENGL) static XrResult @@ -113,7 +93,7 @@ oxr_swapchain_gl_create(struct oxr_logger *log, return ret; } - sc->destroy = oxr_swapchain_gl_destroy; + // Set our API specific function(s). sc->enumerate_images = oxr_swapchain_gl_enumerate_images; *out_swapchain = sc; diff --git a/src/xrt/state_trackers/oxr/oxr_swapchain_vk.c b/src/xrt/state_trackers/oxr/oxr_swapchain_vk.c index 802813a91..6bc40860f 100644 --- a/src/xrt/state_trackers/oxr/oxr_swapchain_vk.c +++ b/src/xrt/state_trackers/oxr/oxr_swapchain_vk.c @@ -1,4 +1,4 @@ -// Copyright 2019-2022, Collabora, Ltd. +// Copyright 2019-2023, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -16,27 +16,6 @@ #include "oxr_logger.h" -static XrResult -oxr_swapchain_vk_destroy(struct oxr_logger *log, struct oxr_swapchain *sc) -{ - // Release any waited image. - if (sc->waited.yes) { - sc->release_image(log, sc, NULL); - } - - // Release any acquired images. - XrSwapchainImageWaitInfo waitInfo = {0}; - while (!u_index_fifo_is_empty(&sc->acquired.fifo)) { - sc->wait_image(log, sc, &waitInfo); - sc->release_image(log, sc, NULL); - } - - // Drop our reference, does NULL checking. - xrt_swapchain_reference(&sc->swapchain, NULL); - - return XR_SUCCESS; -} - static XrResult oxr_swapchain_vk_enumerate_images(struct oxr_logger *log, struct oxr_swapchain *sc, @@ -67,7 +46,7 @@ oxr_swapchain_vk_create(struct oxr_logger *log, return ret; } - sc->destroy = oxr_swapchain_vk_destroy; + // Set our API specific function(s). sc->enumerate_images = oxr_swapchain_vk_enumerate_images; *out_swapchain = sc;