diff --git a/src/xrt/compositor/util/comp_scratch.c b/src/xrt/compositor/util/comp_scratch.c index 716be02f6..e7830bbf7 100644 --- a/src/xrt/compositor/util/comp_scratch.c +++ b/src/xrt/compositor/util/comp_scratch.c @@ -1,5 +1,5 @@ // Copyright 2019-2024, Collabora, Ltd. -// Copyright 2024-2025, NVIDIA CORPORATION. +// Copyright 2024-2026, NVIDIA CORPORATION. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -253,17 +253,6 @@ tmp_take(struct tmp *t, U_ZERO(&t->vkic); } -static inline void -tmp_destroy(struct tmp *t, struct vk_bundle *vk) -{ - vk_ic_destroy(vk, &t->vkic); - for (uint32_t i = 0; i < COMP_SCRATCH_NUM_IMAGES; i++) { - u_graphics_buffer_unref(&t->handles[i]); - D(ImageView, t->srgb_views[i]); - D(ImageView, t->unorm_views[i]); - } -} - /* * @@ -423,162 +412,3 @@ comp_scratch_single_images_destroy(struct comp_scratch_single_images *cssi) { u_native_images_debug_destroy(&cssi->unid); } - - -/* - * - * 'Exported' stereo functions. - * - */ - -void -comp_scratch_stereo_images_init(struct comp_scratch_stereo_images *cssi) -{ - // Just to be sure. - U_ZERO(cssi); - - indices_init(&cssi->indices); - - u_native_images_debug_init(&cssi->views[0].unid); - u_native_images_debug_init(&cssi->views[1].unid); - - for (uint32_t view = 0; view < 2; view++) { - for (uint32_t i = 0; i < COMP_SCRATCH_NUM_IMAGES; i++) { - cssi->views[view].native_images[i].handle = XRT_GRAPHICS_BUFFER_HANDLE_INVALID; - } - } -} - -bool -comp_scratch_stereo_images_ensure(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk, VkExtent2D extent) -{ - const VkFormat srgb_format = VK_FORMAT_R8G8B8A8_SRGB; - const VkFormat unorm_format = VK_FORMAT_R8G8B8A8_UNORM; - - if (cssi->info.width == extent.width && cssi->info.height == extent.height) { - // Our work here is done! - return true; - } - - // Get info we need to share with. - struct xrt_swapchain_create_info info = XRT_STRUCT_INIT; - fill_info(extent, srgb_format, unorm_format, &info); - - struct tmp ts[2]; // Is initialized in function. - if (!tmp_init_and_create(&ts[0], vk, &info, srgb_format, unorm_format)) { - VK_ERROR(vk, "Failed to allocate images for view 0"); - return false; - } - - if (!tmp_init_and_create(&ts[1], vk, &info, srgb_format, unorm_format)) { - VK_ERROR(vk, "Failed to allocate images for view 1"); - goto err_destroy; - } - - // Clear old information, we haven't touched this struct yet. - comp_scratch_stereo_images_free(cssi, vk); - - for (uint32_t view = 0; view < 2; view++) { - struct render_scratch_color_image images[COMP_SCRATCH_NUM_IMAGES]; - - tmp_take(&ts[view], cssi->views[view].native_images, images); - - // Deal with SoA vs AoS. - for (uint32_t i = 0; i < COMP_SCRATCH_NUM_IMAGES; i++) { - cssi->rsis[i].extent = extent; - cssi->rsis[i].color[view] = images[i]; - } - } - - // Generate new unique id for caching and set info. - cssi->limited_unique_id = u_limited_unique_id_get(); - cssi->info = info; - - return true; - -err_destroy: - tmp_destroy(&ts[0], vk); - tmp_destroy(&ts[1], vk); - - return false; -} - -void -comp_scratch_stereo_images_free(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk) -{ - // Make sure nothing refers to the images. - u_native_images_debug_clear(&cssi->views[0].unid); - u_native_images_debug_clear(&cssi->views[1].unid); - - for (uint32_t view = 0; view < 2; view++) { - for (uint32_t i = 0; i < COMP_SCRATCH_NUM_IMAGES; i++) { - // Organised into views, then native images. - u_graphics_buffer_unref(&cssi->views[view].native_images[i].handle); - - // Organised into scratch images, then views. - D(ImageView, cssi->rsis[i].color[view].srgb_view); - D(ImageView, cssi->rsis[i].color[view].unorm_view); - D(Image, cssi->rsis[i].color[view].image); - DF(Memory, cssi->rsis[i].color[view].device_memory); - } - } - - // Clear info, so ensure will recreate. - U_ZERO(&cssi->info); - - // Clear unique id so to force recreate. - cssi->limited_unique_id.data = 0; - - // Clear indices. - indices_init(&cssi->indices); -} - -void -comp_scratch_stereo_images_get(struct comp_scratch_stereo_images *cssi, uint32_t *out_index) -{ - indices_get(&cssi->indices, out_index); -} - -void -comp_scratch_stereo_images_done(struct comp_scratch_stereo_images *cssi) -{ - uint32_t last = indices_done(&cssi->indices); - - assert(cssi->info.width > 0); - assert(cssi->info.height > 0); - - for (uint32_t view = 0; view < 2; view++) { - u_native_images_debug_set( // - &cssi->views[view].unid, // - cssi->limited_unique_id, // - cssi->views[view].native_images, // - COMP_SCRATCH_NUM_IMAGES, // - &cssi->info, // - last, // - false); // - } -} - -void -comp_scratch_stereo_images_discard(struct comp_scratch_stereo_images *cssi) -{ - indices_discard(&cssi->indices); - - u_native_images_debug_clear(&cssi->views[0].unid); - u_native_images_debug_clear(&cssi->views[1].unid); -} - -void -comp_scratch_stereo_images_clear_debug(struct comp_scratch_stereo_images *cssi) -{ - u_native_images_debug_clear(&cssi->views[0].unid); - u_native_images_debug_clear(&cssi->views[1].unid); -} - -void -comp_scratch_stereo_images_destroy(struct comp_scratch_stereo_images *cssi) -{ - // Make sure nothing refers to the images. - u_native_images_debug_destroy(&cssi->views[0].unid); - u_native_images_debug_destroy(&cssi->views[1].unid); -} diff --git a/src/xrt/compositor/util/comp_scratch.h b/src/xrt/compositor/util/comp_scratch.h index 137cf0544..e95f0f1c8 100644 --- a/src/xrt/compositor/util/comp_scratch.h +++ b/src/xrt/compositor/util/comp_scratch.h @@ -1,5 +1,5 @@ // Copyright 2019-2024, Collabora, Ltd. -// Copyright 2024-2025, NVIDIA CORPORATION. +// Copyright 2024-2026, NVIDIA CORPORATION. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -246,66 +246,6 @@ void comp_scratch_single_images_destroy(struct comp_scratch_single_images *cssi); -/* - * - * Stereo. - * - */ - -/*! - * Holds scartch images for a stereo views, designed to work with render code. - * Also manages @ref xrt_image_native and @ref u_native_images_debug to - * facilitate easy debugging. - * - * @ingroup comp_util - */ -struct comp_scratch_stereo_images -{ - struct render_scratch_images rsis[COMP_SCRATCH_NUM_IMAGES]; - - struct xrt_swapchain_create_info info; - - //! Keeping track of indices. - struct comp_scratch_indices indices; - - struct - { - //! Debug output for each view. - struct u_native_images_debug unid; - - //! Count always equals to the number of rsis. - struct xrt_image_native native_images[COMP_SCRATCH_NUM_IMAGES]; - } views[2]; - - //! Process unique id, used for caching. - xrt_limited_unique_id_t limited_unique_id; -}; - -void -comp_scratch_stereo_images_init(struct comp_scratch_stereo_images *cssi); - -bool -comp_scratch_stereo_images_ensure(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk, VkExtent2D extent); - -void -comp_scratch_stereo_images_free(struct comp_scratch_stereo_images *cssi, struct vk_bundle *vk); - -void -comp_scratch_stereo_images_get(struct comp_scratch_stereo_images *cssi, uint32_t *out_index); - -void -comp_scratch_stereo_images_done(struct comp_scratch_stereo_images *cssi); - -void -comp_scratch_stereo_images_discard(struct comp_scratch_stereo_images *cssi); - -void -comp_scratch_stereo_images_clear_debug(struct comp_scratch_stereo_images *cssi); - -void -comp_scratch_stereo_images_destroy(struct comp_scratch_stereo_images *cssi); - - #ifdef __cplusplus } #endif