The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

c/util: Extract comp_layer_accum, formerly comp_layer_slot, and reduce coupling.

The "secret" the implementation is hiding is how calls and layers
turn into a single structure. Not a great secret but functionality
that is needed.

c/util: Use comp_layer_accum in comp_base and derived implmentations.

c/util: zero the other swapchains.

c/util: Inline two functions.

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2317>

authored by

Rylie Pavlik and committed by
Marge Bot
338d8554 9f6f6c6d

+462 -152
+2
doc/changes/compositor/mr.2317.md
··· 1 + - Add: New `comp_layer_accum` helper, factored out from `comp_base`, that collects layers and swapchains for a frame. 2 + - Change: Modify `comp_base` to use `comp_layer_accum` helper, instead of inlining that code. Users of `comp_base` will need to update their code accordingly.
+2
src/xrt/compositor/CMakeLists.txt
··· 146 146 comp_util STATIC 147 147 util/comp_base.h 148 148 util/comp_base.c 149 + util/comp_layer_accum.h 150 + util/comp_layer_accum.c 149 151 util/comp_render.h 150 152 util/comp_render_cs.c 151 153 util/comp_render_gfx.c
+5 -9
src/xrt/compositor/main/comp_compositor.c
··· 264 264 static bool 265 265 can_do_one_projection_layer_fast_path(struct comp_compositor *c) 266 266 { 267 - if (c->base.slot.layer_count != 1) { 267 + if (c->base.layer_accum.layer_count != 1) { 268 268 return false; 269 269 } 270 270 271 - struct comp_layer *layer = &c->base.slot.layers[0]; 271 + struct comp_layer *layer = &c->base.layer_accum.layers[0]; 272 272 enum xrt_layer_type type = layer->data.type; 273 273 274 274 // Handled by the distortion shader. 275 - if (type != XRT_LAYER_PROJECTION && // 276 - type != XRT_LAYER_PROJECTION_DEPTH) { 277 - return false; 278 - } 279 - 280 - return true; 275 + return type == XRT_LAYER_PROJECTION || // 276 + type == XRT_LAYER_PROJECTION_DEPTH; 281 277 } 282 278 283 279 static XRT_CHECK_RESULT xrt_result_t ··· 298 294 !c->mirroring_to_debug_gui && // 299 295 !c->debug.disable_fast_path && // 300 296 can_do_one_projection_layer_fast_path(c); // 301 - c->base.slot.one_projection_layer_fast_path = fast_path; 297 + c->base.frame_params.one_projection_layer_fast_path = fast_path; 302 298 303 299 304 300 u_graphics_sync_unref(&sync_handle);
+9 -9
src/xrt/compositor/main/comp_renderer.c
··· 348 348 out_eye[i] = eye_pose; 349 349 350 350 // For remote rendering targets. 351 - r->c->base.slot.fovs[i] = fov; 352 - r->c->base.slot.poses[i] = result.pose; 351 + r->c->base.frame_params.fovs[i] = fov; 352 + r->c->base.frame_params.poses[i] = result.pose; 353 353 } 354 354 } 355 355 ··· 856 856 VkResult ret; 857 857 858 858 // Basics 859 - const struct comp_layer *layers = c->base.slot.layers; 860 - uint32_t layer_count = c->base.slot.layer_count; 861 - bool fast_path = c->base.slot.one_projection_layer_fast_path; 859 + const struct comp_layer *layers = c->base.layer_accum.layers; 860 + uint32_t layer_count = c->base.layer_accum.layer_count; 861 + bool fast_path = c->base.frame_params.one_projection_layer_fast_path; 862 862 bool do_timewarp = !c->debug.atw_off; 863 863 864 864 // Resources for the distortion render target. 865 865 struct render_gfx_target_resources *rtr = &r->rtr_array[r->acquired_buffer]; 866 866 867 867 // Consistency check. 868 - assert(!fast_path || c->base.slot.layer_count >= 1); 868 + assert(!fast_path || c->base.layer_accum.layer_count >= 1); 869 869 870 870 // Viewport information. 871 871 struct render_viewport_data viewport_datas[XRT_MAX_VIEWS]; ··· 982 982 VkResult ret; 983 983 984 984 // Basics 985 - const struct comp_layer *layers = c->base.slot.layers; 986 - uint32_t layer_count = c->base.slot.layer_count; 987 - bool fast_path = c->base.slot.one_projection_layer_fast_path; 985 + const struct comp_layer *layers = c->base.layer_accum.layers; 986 + uint32_t layer_count = c->base.layer_accum.layer_count; 987 + bool fast_path = c->base.frame_params.one_projection_layer_fast_path; 988 988 bool do_timewarp = !c->debug.atw_off; 989 989 990 990 // Device view information.
+1 -1
src/xrt/compositor/null/null_compositor.c
··· 425 425 struct null_compositor *c = null_compositor(xc); 426 426 NULL_TRACE(c, "LAYER_COMMIT"); 427 427 428 - int64_t frame_id = c->base.slot.data.frame_id; 428 + int64_t frame_id = c->base.layer_accum.data.frame_id; 429 429 430 430 /* 431 431 * The null compositor doesn't render any frames, but needs to do
+22 -57
src/xrt/compositor/util/comp_base.c
··· 1 - // Copyright 2019-2023, Collabora, Ltd. 1 + // Copyright 2019-2024, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file 5 5 * @brief Helper implementation for native compositors. 6 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 7 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com> 8 + * @author Rylie Pavlik <rylie.pavlik@collabora.com> 8 9 * @ingroup comp_util 9 10 */ 10 11 12 + #include "util/comp_layer_accum.h" 13 + #include "util/comp_sync.h" 11 14 #include "util/u_wait.h" 12 15 #include "util/u_trace_marker.h" 13 16 ··· 21 24 * 22 25 */ 23 26 24 - static xrt_result_t 25 - do_single_layer(struct xrt_compositor *xc, 26 - struct xrt_device *xdev, 27 - struct xrt_swapchain *xsc, 28 - const struct xrt_layer_data *data) 29 - { 30 - struct comp_base *cb = comp_base(xc); 31 - 32 - uint32_t layer_id = cb->slot.layer_count; 33 - 34 - struct comp_layer *layer = &cb->slot.layers[layer_id]; 35 - layer->sc_array[0] = comp_swapchain(xsc); 36 - layer->sc_array[1] = NULL; 37 - layer->data = *data; 38 - 39 - cb->slot.layer_count++; 40 - 41 - return XRT_SUCCESS; 42 - } 43 - 44 27 45 28 /* 46 29 * ··· 48 31 * 49 32 */ 50 33 34 + //! Delegates to code in `comp_swapchain` 51 35 static xrt_result_t 52 36 base_get_swapchain_create_properties(struct xrt_compositor *xc, 53 37 const struct xrt_swapchain_create_info *info, ··· 56 40 return comp_swapchain_get_create_properties(info, xsccp); 57 41 } 58 42 43 + //! Delegates to code in `comp_swapchain` 59 44 static xrt_result_t 60 45 base_create_swapchain(struct xrt_compositor *xc, 61 46 const struct xrt_swapchain_create_info *info, ··· 73 58 return comp_swapchain_create(&cb->vk, &cb->cscs, info, &xsccp, out_xsc); 74 59 } 75 60 61 + //! Delegates to code in `comp_swapchain` 76 62 static xrt_result_t 77 63 base_import_swapchain(struct xrt_compositor *xc, 78 64 const struct xrt_swapchain_create_info *info, ··· 85 71 return comp_swapchain_import(&cb->vk, &cb->cscs, info, native_images, image_count, out_xsc); 86 72 } 87 73 74 + //! Delegates to code in `comp_sync` 88 75 static xrt_result_t 89 76 base_import_fence(struct xrt_compositor *xc, xrt_graphics_sync_handle_t handle, struct xrt_compositor_fence **out_xcf) 90 77 { ··· 93 80 return comp_fence_import(&cb->vk, handle, out_xcf); 94 81 } 95 82 83 + //! Delegates to code in `comp_semaphore` 96 84 static xrt_result_t 97 85 base_create_semaphore(struct xrt_compositor *xc, 98 86 xrt_graphics_sync_handle_t *out_handle, ··· 107 95 base_layer_begin(struct xrt_compositor *xc, const struct xrt_layer_frame_data *data) 108 96 { 109 97 struct comp_base *cb = comp_base(xc); 110 - 111 - cb->slot.data = *data; 112 - cb->slot.layer_count = 0; 113 - 114 - return XRT_SUCCESS; 98 + return comp_layer_accum_begin(&cb->layer_accum, data); 115 99 } 116 100 117 101 static xrt_result_t ··· 121 105 const struct xrt_layer_data *data) 122 106 { 123 107 struct comp_base *cb = comp_base(xc); 124 - 125 - uint32_t layer_id = cb->slot.layer_count; 126 - 127 - struct comp_layer *layer = &cb->slot.layers[layer_id]; 128 - assert(ARRAY_SIZE(layer->sc_array) >= data->view_count); 129 - for (uint32_t i = 0; i < data->view_count; ++i) { 130 - layer->sc_array[i] = comp_swapchain(xsc[i]); 131 - } 132 - layer->data = *data; 133 - 134 - cb->slot.layer_count++; 135 - 136 - return XRT_SUCCESS; 108 + return comp_layer_accum_projection(&cb->layer_accum, xsc, data); 137 109 } 138 110 139 111 static xrt_result_t ··· 144 116 const struct xrt_layer_data *data) 145 117 { 146 118 struct comp_base *cb = comp_base(xc); 147 - 148 - uint32_t layer_id = cb->slot.layer_count; 149 - 150 - struct comp_layer *layer = &cb->slot.layers[layer_id]; 151 - for (uint32_t i = 0; i < data->view_count; ++i) { 152 - layer->sc_array[i] = comp_swapchain(xsc[i]); 153 - layer->sc_array[i + data->view_count] = comp_swapchain(d_xsc[i]); 154 - } 155 - layer->data = *data; 156 - 157 - cb->slot.layer_count++; 158 - 159 - return XRT_SUCCESS; 119 + return comp_layer_accum_projection_depth(&cb->layer_accum, xsc, d_xsc, data); 160 120 } 161 121 162 122 static xrt_result_t ··· 165 125 struct xrt_swapchain *xsc, 166 126 const struct xrt_layer_data *data) 167 127 { 168 - return do_single_layer(xc, xdev, xsc, data); 128 + struct comp_base *cb = comp_base(xc); 129 + return comp_layer_accum_quad(&cb->layer_accum, xsc, data); 169 130 } 170 131 171 132 static xrt_result_t ··· 174 135 struct xrt_swapchain *xsc, 175 136 const struct xrt_layer_data *data) 176 137 { 177 - return do_single_layer(xc, xdev, xsc, data); 138 + struct comp_base *cb = comp_base(xc); 139 + return comp_layer_accum_cube(&cb->layer_accum, xsc, data); 178 140 } 179 141 180 142 static xrt_result_t ··· 183 145 struct xrt_swapchain *xsc, 184 146 const struct xrt_layer_data *data) 185 147 { 186 - return do_single_layer(xc, xdev, xsc, data); 148 + struct comp_base *cb = comp_base(xc); 149 + return comp_layer_accum_cylinder(&cb->layer_accum, xsc, data); 187 150 } 188 151 189 152 static xrt_result_t ··· 192 155 struct xrt_swapchain *xsc, 193 156 const struct xrt_layer_data *data) 194 157 { 195 - return do_single_layer(xc, xdev, xsc, data); 158 + struct comp_base *cb = comp_base(xc); 159 + return comp_layer_accum_equirect1(&cb->layer_accum, xsc, data); 196 160 } 197 161 198 162 static xrt_result_t ··· 201 165 struct xrt_swapchain *xsc, 202 166 const struct xrt_layer_data *data) 203 167 { 204 - return do_single_layer(xc, xdev, xsc, data); 168 + struct comp_base *cb = comp_base(xc); 169 + return comp_layer_accum_equirect2(&cb->layer_accum, xsc, data); 205 170 } 206 171 207 172 static xrt_result_t
+11 -38
src/xrt/compositor/util/comp_base.h
··· 1 - // Copyright 2019-2023, Collabora, Ltd. 1 + // Copyright 2019-2024, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file 5 5 * @brief Helper implementation for native compositors. 6 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 7 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com> 8 + * @author Rylie Pavlik <rylie.pavlik@collabora.com> 8 9 * @ingroup comp_util 9 10 */ 10 11 11 12 #pragma once 12 13 13 - #include "util/comp_sync.h" 14 14 #include "util/comp_swapchain.h" 15 + #include "util/comp_layer_accum.h" 15 16 16 17 17 18 #ifdef __cplusplus 18 19 extern "C" { 19 20 #endif 20 - 21 - #define COMP_MAX_LAYERS 16 22 21 23 22 /*! 24 - * A single layer. 23 + * Additional per-frame parameters. 25 24 * 26 - * @ingroup comp_util 27 - * @see comp_layer_slot 28 - */ 29 - struct comp_layer 30 - { 31 - /*! 32 - * Up to four compositor swapchains referenced per layer. 33 - * 34 - * Unused elements should be set to null. 35 - */ 36 - struct comp_swapchain *sc_array[XRT_MAX_VIEWS * 2]; 37 - 38 - /*! 39 - * All basic (trivially-serializable) data associated with a layer. 40 - */ 41 - struct xrt_layer_data data; 42 - }; 43 - 44 - /*! 45 - * A stack of layers. 25 + * Independent of graphics API, swapchain implementation, etc. 46 26 * 47 27 * @ingroup comp_util 48 - * @see comp_base 49 28 */ 50 - struct comp_layer_slot 29 + struct comp_frame_params 51 30 { 52 - //! The per frame data. 53 - struct xrt_layer_frame_data data; 54 - 55 - //! All of the layers. 56 - struct comp_layer layers[COMP_MAX_LAYERS]; 57 - 58 - //! Number of submitted layers. 59 - uint32_t layer_count; 60 - 61 31 //! Special case one layer projection/projection-depth fast-path. 62 32 bool one_projection_layer_fast_path; 63 33 ··· 108 78 //! Swapchain garbage collector, used by swapchain, child class needs to call. 109 79 struct comp_swapchain_shared cscs; 110 80 111 - //! We only need to track a single slot. 112 - struct comp_layer_slot slot; 81 + //! Collect layers for a single frame. 82 + struct comp_layer_accum layer_accum; 83 + 84 + //! Parameters for a single frame. 85 + struct comp_frame_params frame_params; 113 86 }; 114 87 115 88
+129
src/xrt/compositor/util/comp_layer_accum.c
··· 1 + // Copyright 2019-2024, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Re-assemble a collection of composition layers submitted for a frame. 6 + * 7 + * @author Rylie Pavlik <rylie.pavlik@collabora.com> 8 + * @author Jakob Bornecrantz <jakob@collabora.com> 9 + * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com> 10 + * @ingroup comp_util 11 + */ 12 + 13 + #include "comp_layer_accum.h" 14 + #include "util/u_misc.h" 15 + #include "xrt/xrt_compositor.h" 16 + #include "xrt/xrt_limits.h" 17 + 18 + // Shared implementation of accumulating a layer with only a single swapchain image. 19 + static xrt_result_t 20 + push_single_swapchain_layer(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data) 21 + { 22 + uint32_t layer_id = cla->layer_count; 23 + 24 + struct comp_layer *layer = &cla->layers[layer_id]; 25 + U_ZERO_ARRAY(layer->sc_array); 26 + layer->sc_array[0] = xsc; 27 + layer->data = *data; 28 + 29 + cla->layer_count++; 30 + 31 + return XRT_SUCCESS; 32 + } 33 + 34 + struct xrt_swapchain * 35 + comp_layer_get_swapchain(const struct comp_layer *cl, uint32_t swapchain_index) 36 + { 37 + 38 + return cl->sc_array[swapchain_index]; 39 + } 40 + 41 + struct xrt_swapchain * 42 + comp_layer_get_depth_swapchain(const struct comp_layer *cl, uint32_t swapchain_index) 43 + { 44 + 45 + assert(cl->data.type == XRT_LAYER_PROJECTION_DEPTH); 46 + return cl->sc_array[XRT_MAX_VIEWS + swapchain_index]; 47 + } 48 + 49 + xrt_result_t 50 + comp_layer_accum_begin(struct comp_layer_accum *cla, const struct xrt_layer_frame_data *data) 51 + { 52 + cla->data = *data; 53 + cla->layer_count = 0; 54 + 55 + return XRT_SUCCESS; 56 + } 57 + 58 + xrt_result_t 59 + comp_layer_accum_projection(struct comp_layer_accum *cla, 60 + struct xrt_swapchain *xsc[XRT_MAX_VIEWS], 61 + const struct xrt_layer_data *data) 62 + { 63 + 64 + uint32_t layer_id = cla->layer_count; 65 + 66 + struct comp_layer *layer = &cla->layers[layer_id]; 67 + assert(ARRAY_SIZE(layer->sc_array) >= data->view_count); 68 + U_ZERO_ARRAY(layer->sc_array); 69 + for (uint32_t i = 0; i < data->view_count; ++i) { 70 + layer->sc_array[i] = xsc[i]; 71 + } 72 + layer->data = *data; 73 + 74 + cla->layer_count++; 75 + 76 + return XRT_SUCCESS; 77 + } 78 + 79 + xrt_result_t 80 + comp_layer_accum_projection_depth(struct comp_layer_accum *cla, 81 + struct xrt_swapchain *xsc[XRT_MAX_VIEWS], 82 + struct xrt_swapchain *d_xsc[XRT_MAX_VIEWS], 83 + const struct xrt_layer_data *data) 84 + { 85 + 86 + uint32_t layer_id = cla->layer_count; 87 + 88 + struct comp_layer *layer = &cla->layers[layer_id]; 89 + U_ZERO_ARRAY(layer->sc_array); 90 + for (uint32_t i = 0; i < data->view_count; ++i) { 91 + layer->sc_array[i] = xsc[i]; 92 + layer->sc_array[i + data->view_count] = d_xsc[i]; 93 + } 94 + layer->data = *data; 95 + 96 + cla->layer_count++; 97 + 98 + return XRT_SUCCESS; 99 + } 100 + 101 + xrt_result_t 102 + comp_layer_accum_quad(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data) 103 + { 104 + return push_single_swapchain_layer(cla, xsc, data); 105 + } 106 + 107 + xrt_result_t 108 + comp_layer_accum_cube(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data) 109 + { 110 + return push_single_swapchain_layer(cla, xsc, data); 111 + } 112 + 113 + xrt_result_t 114 + comp_layer_accum_cylinder(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data) 115 + { 116 + return push_single_swapchain_layer(cla, xsc, data); 117 + } 118 + 119 + xrt_result_t 120 + comp_layer_accum_equirect1(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data) 121 + { 122 + return push_single_swapchain_layer(cla, xsc, data); 123 + } 124 + 125 + xrt_result_t 126 + comp_layer_accum_equirect2(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data) 127 + { 128 + return push_single_swapchain_layer(cla, xsc, data); 129 + }
+212
src/xrt/compositor/util/comp_layer_accum.h
··· 1 + // Copyright 2019-2024, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Re-assemble a collection of composition layers submitted for a frame. 6 + * 7 + * @author Rylie Pavlik <rylie.pavlik@collabora.com> 8 + * @author Jakob Bornecrantz <jakob@collabora.com> 9 + * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com> 10 + * @ingroup comp_util 11 + */ 12 + 13 + #pragma once 14 + 15 + #include "xrt/xrt_compositor.h" 16 + #include "xrt/xrt_limits.h" 17 + #include "xrt/xrt_results.h" 18 + #include <assert.h> 19 + #include <stdint.h> 20 + 21 + #define COMP_MAX_LAYERS 16 22 + 23 + 24 + #ifdef __cplusplus 25 + extern "C" { 26 + #endif 27 + 28 + struct xrt_swapchain; 29 + 30 + /*! 31 + * A single layer in a @ref comp_layer_accum. 32 + * 33 + * Independent of graphics API, swapchain implementation, etc. 34 + * 35 + * @ingroup comp_util 36 + * @see comp_layer_accum 37 + */ 38 + struct comp_layer 39 + { 40 + /*! 41 + * Up to two compositor swapchains referenced per view (color and depth) for a layer. 42 + * 43 + * Unused elements should be set to null. 44 + */ 45 + struct xrt_swapchain *sc_array[XRT_MAX_VIEWS * 2]; 46 + 47 + /*! 48 + * All basic (trivially-serializable) data associated with a layer. 49 + */ 50 + struct xrt_layer_data data; 51 + }; 52 + 53 + 54 + /*! 55 + * Get a (color) swapchain associated with a layer. 56 + * 57 + * @param cla self 58 + * @param swapchain_index index of swapchain - typically this is 0 for most layers, the view index for projection. 59 + 60 + * @public @memberof comp_layer 61 + */ 62 + struct xrt_swapchain * 63 + comp_layer_get_swapchain(const struct comp_layer *cl, uint32_t swapchain_index); 64 + 65 + 66 + /*! 67 + * Get a depth swapchain associated with a (projection with depth) layer 68 + * 69 + * @param cla self 70 + * @param swapchain_index index of **color** swapchain - typically this is the view index. 71 + * 72 + * @public @memberof comp_layer 73 + */ 74 + struct xrt_swapchain * 75 + comp_layer_get_depth_swapchain(const struct comp_layer *cl, uint32_t swapchain_index); 76 + 77 + 78 + 79 + /*! 80 + * Collect a stack of layers - one frame's worth. 81 + * 82 + * Independent of graphics API, swapchain implementation, etc. 83 + * 84 + * Used to turn the step by step "one call per layer" compositor API back 85 + * into a single structure per frame. 86 + * 87 + * @ingroup comp_util 88 + * @see comp_layer 89 + */ 90 + struct comp_layer_accum 91 + { 92 + //! The per frame data, supplied by `begin`. 93 + struct xrt_layer_frame_data data; 94 + 95 + //! All of the layers. 96 + struct comp_layer layers[COMP_MAX_LAYERS]; 97 + 98 + //! Number of submitted layers. 99 + uint32_t layer_count; 100 + }; 101 + 102 + /*! 103 + * Reset all layer data and reset count to 0. 104 + * 105 + * Call at the beginning of a frame. 106 + * 107 + * @public @memberof comp_layer_accum 108 + */ 109 + xrt_result_t 110 + comp_layer_accum_begin(struct comp_layer_accum *cla, const struct xrt_layer_frame_data *data); 111 + 112 + /*! 113 + * Accumulate swapchains and data for a projection layer for a frame. 114 + * 115 + * @public @memberof comp_layer_accum 116 + */ 117 + xrt_result_t 118 + comp_layer_accum_projection(struct comp_layer_accum *cla, 119 + struct xrt_swapchain *xsc[XRT_MAX_VIEWS], 120 + const struct xrt_layer_data *data); 121 + 122 + /*! 123 + * Accumulate swapchains and data for a projection layer (with depth image) for a frame. 124 + * 125 + * @public @memberof comp_layer_accum 126 + */ 127 + xrt_result_t 128 + comp_layer_accum_projection_depth(struct comp_layer_accum *cla, 129 + struct xrt_swapchain *xsc[XRT_MAX_VIEWS], 130 + struct xrt_swapchain *d_xsc[XRT_MAX_VIEWS], 131 + const struct xrt_layer_data *data); 132 + /*! 133 + * Accumulate swapchain and data for a quad layer for a frame. 134 + * 135 + * @public @memberof comp_layer_accum 136 + */ 137 + xrt_result_t 138 + comp_layer_accum_quad(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data); 139 + 140 + 141 + /*! 142 + * Accumulate swapchain and data for a cube layer for a frame. 143 + * 144 + * @public @memberof comp_layer_accum 145 + */ 146 + xrt_result_t 147 + comp_layer_accum_cube(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data); 148 + 149 + 150 + /*! 151 + * Accumulate swapchain and data for a cylinder layer for a frame. 152 + * 153 + * @public @memberof comp_layer_accum 154 + */ 155 + xrt_result_t 156 + comp_layer_accum_cylinder(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data); 157 + 158 + 159 + /*! 160 + * Accumulate swapchain and data for an equirect(1) layer for a frame. 161 + * 162 + * @public @memberof comp_layer_accum 163 + */ 164 + xrt_result_t 165 + comp_layer_accum_equirect1(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data); 166 + 167 + 168 + /*! 169 + * Accumulate swapchain and data for an equirect2 layer for a frame. 170 + * 171 + * @public @memberof comp_layer_accum 172 + */ 173 + xrt_result_t 174 + comp_layer_accum_equirect2(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data); 175 + 176 + 177 + /*! 178 + * Get a (color) swapchain associated with a layer. 179 + * 180 + * @param cla self 181 + * @param layer_index index of layer 182 + * @param swapchain_index index of swapchain - typically this is 0 for most layers, the view index for projection. 183 + 184 + * @public @memberof comp_layer_accum 185 + */ 186 + inline struct xrt_swapchain * 187 + comp_layer_accum_get_swapchain(const struct comp_layer_accum *cla, uint32_t layer_index, uint32_t swapchain_index) 188 + { 189 + assert(layer_index < cla->layer_count); 190 + return cla->layers[layer_index].sc_array[swapchain_index]; 191 + } 192 + 193 + /*! 194 + * Get a depth swapchain associated with a (projection with depth) layer 195 + * 196 + * @param cla self 197 + * @param layer_index index of layer 198 + * @param swapchain_index index of **color** swapchain - typically this is the view index. 199 + * 200 + * @public @memberof comp_layer_accum 201 + */ 202 + inline struct xrt_swapchain * 203 + comp_layer_accum_get_depth_swapchain(const struct comp_layer_accum *cla, uint32_t layer_index, uint32_t swapchain_index) 204 + { 205 + assert(layer_index < cla->layer_count); 206 + assert(cla->layers[layer_index].data.type == XRT_LAYER_PROJECTION_DEPTH); 207 + return cla->layers[layer_index].sc_array[XRT_MAX_VIEWS + swapchain_index]; 208 + } 209 + 210 + #ifdef __cplusplus 211 + } 212 + #endif
+40 -20
src/xrt/compositor/util/comp_render_cs.c
··· 6 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 7 * @author Christoph Haag <christoph.haag@collabora.com> 8 8 * @author Fernando Velazquez Innella <finnella@magicleap.com> 9 + * @author Rylie Pavlik <rylie.pavlik@collabora.com> 9 10 * @ingroup comp_main 10 11 */ 11 12 13 + #include "util/comp_layer_accum.h" 12 14 #include "xrt/xrt_compositor.h" 13 15 14 16 #include "os/os_time.h" ··· 34 36 * 35 37 */ 36 38 39 + static inline const struct comp_swapchain_image * 40 + get_layer_image(const struct comp_layer *layer, uint32_t swapchain_index, uint32_t image_index) 41 + { 42 + 43 + const struct comp_swapchain *sc = (struct comp_swapchain *)(comp_layer_get_swapchain(layer, swapchain_index)); 44 + return &sc->images[image_index]; 45 + } 46 + 47 + static inline const struct comp_swapchain_image * 48 + get_layer_depth_image(const struct comp_layer *layer, uint32_t swapchain_index, uint32_t image_index) 49 + { 50 + 51 + const struct comp_swapchain *sc = 52 + (struct comp_swapchain *)(comp_layer_get_depth_swapchain(layer, swapchain_index)); 53 + return &sc->images[image_index]; 54 + } 55 + 37 56 static inline void 38 57 do_cs_equirect2_layer(const struct xrt_layer_data *data, 39 58 const struct comp_layer *layer, ··· 49 68 struct render_compute_layer_ubo_data *ubo_data, 50 69 uint32_t *out_cur_image) 51 70 { 52 - const struct xrt_layer_equirect2_data *eq2 = &data->equirect2; 53 - 54 - const struct comp_swapchain_image *image = &layer->sc_array[0]->images[eq2->sub.image_index]; 55 - uint32_t array_index = eq2->sub.array_index; 71 + const struct xrt_layer_data *layer_data = &layer->data; 72 + const struct xrt_layer_equirect2_data *eq2 = &layer_data->equirect2; 73 + const uint32_t array_index = eq2->sub.array_index; 74 + const struct comp_swapchain_image *image = get_layer_image(layer, 0, eq2->sub.image_index); 56 75 57 76 // Image to use. 58 77 src_samplers[cur_image] = clamp_to_edge; ··· 112 131 bool do_timewarp, 113 132 uint32_t *out_cur_image) 114 133 { 134 + const struct xrt_layer_data *layer_data = &layer->data; 115 135 const struct xrt_layer_projection_view_data *vd = NULL; 116 136 const struct xrt_layer_depth_data *dvd = NULL; 117 137 118 - if (data->type == XRT_LAYER_PROJECTION) { 119 - view_index_to_projection_data(view_index, data, &vd); 138 + if (layer_data->type == XRT_LAYER_PROJECTION) { 139 + view_index_to_projection_data(view_index, layer_data, &vd); 120 140 } else { 121 - view_index_to_depth_data(view_index, data, &vd, &dvd); 141 + view_index_to_depth_data(view_index, layer_data, &vd, &dvd); 122 142 } 123 143 124 144 uint32_t sc_array_index = is_view_index_right(view_index) ? 1 : 0; 125 145 uint32_t array_index = vd->sub.array_index; 126 - const struct comp_swapchain_image *image = &layer->sc_array[sc_array_index]->images[vd->sub.image_index]; 146 + const struct comp_swapchain_image *image = get_layer_image(layer, sc_array_index, vd->sub.image_index); 127 147 128 148 // Color 129 149 src_samplers[cur_image] = clamp_to_border_black; ··· 134 154 if (data->type == XRT_LAYER_PROJECTION_DEPTH) { 135 155 uint32_t d_array_index = dvd->sub.array_index; 136 156 const struct comp_swapchain_image *d_image = 137 - &layer->sc_array[sc_array_index + 2]->images[dvd->sub.image_index]; 157 + get_layer_depth_image(layer, sc_array_index, dvd->sub.image_index); 138 158 139 159 src_samplers[cur_image] = clamp_to_edge; // Edge to keep depth stable at edges. 140 160 src_image_views[cur_image] = get_image_view(d_image, data->flags, d_array_index); ··· 174 194 struct render_compute_layer_ubo_data *ubo_data, 175 195 uint32_t *out_cur_image) 176 196 { 177 - const struct xrt_layer_quad_data *q = &data->quad; 178 - 179 - const struct comp_swapchain_image *image = &layer->sc_array[0]->images[q->sub.image_index]; 180 - uint32_t array_index = q->sub.array_index; 197 + const struct xrt_layer_data *layer_data = &layer->data; 198 + const struct xrt_layer_quad_data *q = &layer_data->quad; 199 + const uint32_t array_index = q->sub.array_index; 200 + const struct comp_swapchain_image *image = get_layer_image(layer, 0, q->sub.image_index); 181 201 182 202 // Image to use. 183 203 src_samplers[cur_image] = clamp_to_edge; ··· 257 277 struct render_compute_layer_ubo_data *ubo_data, 258 278 uint32_t *out_cur_image) 259 279 { 260 - const struct xrt_layer_cylinder_data *c = &data->cylinder; 261 - 262 - const struct comp_swapchain_image *image = &layer->sc_array[0]->images[c->sub.image_index]; 263 - uint32_t array_index = c->sub.array_index; 280 + const struct xrt_layer_data *layer_data = &layer->data; 281 + const struct xrt_layer_cylinder_data *c = &layer_data->cylinder; 282 + const uint32_t array_index = c->sub.array_index; 283 + const struct comp_swapchain_image *image = get_layer_image(layer, 0, c->sub.image_index); 264 284 265 285 // Image to use. 266 286 src_samplers[cur_image] = clamp_to_edge; ··· 268 288 269 289 // Used for Subimage and OpenGL flip. 270 290 set_post_transform_rect( // 271 - data, // data 291 + layer_data, // data 272 292 &c->sub.norm_rect, // src_norm_rect 273 293 false, // invert_flip 274 294 &ubo_data->post_transforms[cur_layer]); // out_norm_rect ··· 284 304 struct xrt_matrix_4x4 model_inv; 285 305 math_matrix_4x4_inverse(&model, &model_inv); 286 306 287 - const struct xrt_matrix_4x4 *v = is_layer_view_space(data) ? eye_view_mat : world_view_mat; 307 + const struct xrt_matrix_4x4 *v = is_layer_view_space(layer_data) ? eye_view_mat : world_view_mat; 288 308 289 309 struct xrt_matrix_4x4 v_inv; 290 310 math_matrix_4x4_inverse(v, &v_inv); ··· 413 433 struct xrt_normalized_rect src_norm_rect; 414 434 VkImageView src_image_view; 415 435 uint32_t array_index = vds[i]->sub.array_index; 416 - const struct comp_swapchain_image *image = &layer->sc_array[i]->images[vds[i]->sub.image_index]; 436 + const struct comp_swapchain_image *image = get_layer_image(layer, i, vds[i]->sub.image_index); 417 437 418 438 // Gather data. 419 439 world_pose = d->views[i].world_pose;
+24 -13
src/xrt/compositor/util/comp_render_gfx.c
··· 4 4 * @file 5 5 * @brief Compositor gfx rendering code. 6 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @author Rylie Pavlik <rylie.pavlik@collabora.com> 7 8 * @ingroup comp_util 8 9 */ 9 10 10 11 #include "xrt/xrt_compositor.h" 12 + #include "util/comp_swapchain.h" 11 13 12 14 #include "math/m_api.h" 13 15 #include "math/m_mathinclude.h" ··· 217 219 * 218 220 */ 219 221 222 + static inline const struct comp_swapchain_image * 223 + get_layer_image(const struct comp_layer *layer, uint32_t swapchain_index, uint32_t image_index) 224 + { 225 + 226 + const struct comp_swapchain *sc = (struct comp_swapchain *)(comp_layer_get_swapchain(layer, swapchain_index)); 227 + return &sc->images[image_index]; 228 + } 229 + 220 230 static inline void 221 231 add_layer(struct gfx_layer_view_state *state, const struct xrt_layer_data *data, VkDescriptorSet descriptor_set) 222 232 { ··· 236 246 { 237 247 const struct xrt_layer_data *layer_data = &layer->data; 238 248 const struct xrt_layer_cylinder_data *c = &layer_data->cylinder; 249 + const uint32_t array_index = c->sub.array_index; 250 + const struct comp_swapchain_image *image = get_layer_image(layer, 0, c->sub.image_index); 251 + 239 252 struct vk_bundle *vk = rr->r->vk; 240 253 VkResult ret; 241 - 242 - const uint32_t array_index = c->sub.array_index; 243 - const struct comp_swapchain_image *image = &layer->sc_array[0]->images[c->sub.image_index]; 244 254 245 255 // Color 246 256 VkSampler src_sampler = clamp_to_edge; // WIP: Is this correct? ··· 300 310 { 301 311 const struct xrt_layer_data *layer_data = &layer->data; 302 312 const struct xrt_layer_equirect2_data *eq2 = &layer_data->equirect2; 313 + const uint32_t array_index = eq2->sub.array_index; 314 + const struct comp_swapchain_image *image = get_layer_image(layer, 0, eq2->sub.image_index); 315 + 303 316 struct vk_bundle *vk = rr->r->vk; 304 317 VkResult ret; 305 318 306 - const uint32_t array_index = eq2->sub.array_index; 307 - const struct comp_swapchain_image *image = &layer->sc_array[0]->images[eq2->sub.image_index]; 308 - 309 319 // Color 310 320 VkSampler src_sampler = clamp_to_edge; 311 321 VkImageView src_image_view = get_image_view(image, layer_data->flags, array_index); ··· 365 375 const struct xrt_layer_data *layer_data = &layer->data; 366 376 const struct xrt_layer_projection_view_data *vd = NULL; 367 377 const struct xrt_layer_depth_data *dvd = NULL; 368 - struct vk_bundle *vk = rr->r->vk; 369 - VkResult ret; 370 378 371 379 if (layer_data->type == XRT_LAYER_PROJECTION) { 372 380 view_index_to_projection_data(view_index, layer_data, &vd); ··· 376 384 377 385 uint32_t sc_array_index = is_view_index_right(view_index) ? 1 : 0; 378 386 uint32_t array_index = vd->sub.array_index; 379 - const struct comp_swapchain_image *image = &layer->sc_array[sc_array_index]->images[vd->sub.image_index]; 387 + const struct comp_swapchain_image *image = get_layer_image(layer, sc_array_index, vd->sub.image_index); 380 388 389 + struct vk_bundle *vk = rr->r->vk; 390 + VkResult ret; 381 391 // Color 382 392 VkSampler src_sampler = clamp_to_border_black; 383 393 VkImageView src_image_view = get_image_view(image, layer_data->flags, array_index); ··· 426 436 { 427 437 const struct xrt_layer_data *layer_data = &layer->data; 428 438 const struct xrt_layer_quad_data *q = &layer_data->quad; 439 + const uint32_t array_index = q->sub.array_index; 440 + const struct comp_swapchain_image *image = get_layer_image(layer, 0, q->sub.image_index); 441 + 429 442 struct vk_bundle *vk = rr->r->vk; 430 443 VkResult ret; 431 - 432 - const uint32_t array_index = q->sub.array_index; 433 - const struct comp_swapchain_image *image = &layer->sc_array[0]->images[q->sub.image_index]; 434 444 435 445 // Color 436 446 VkSampler src_sampler = clamp_to_edge; ··· 762 772 struct gfx_mesh_data md = XRT_STRUCT_INIT; 763 773 for (uint32_t i = 0; i < d->view_count; i++) { 764 774 const uint32_t array_index = vds[i]->sub.array_index; 765 - const struct comp_swapchain_image *image = &layer->sc_array[i]->images[vds[i]->sub.image_index]; 775 + 776 + const struct comp_swapchain_image *image = get_layer_image(layer, 0, vds[i]->sub.image_index); 766 777 767 778 struct xrt_pose src_pose; 768 779 struct xrt_fov src_fov;
+1 -1
src/xrt/targets/sdl_test/sdl_compositor.c
··· 433 433 434 434 struct sdl_program *sp = from_comp(xc); 435 435 struct sdl_compositor *c = &sp->c; 436 - int64_t frame_id = c->base.slot.data.frame_id; 436 + int64_t frame_id = c->base.layer_accum.data.frame_id; 437 437 438 438 SC_TRACE(c, "LAYER_COMMIT"); 439 439
+4 -4
src/xrt/targets/sdl_test/sdl_program.cpp
··· 112 112 // Nothing for now. 113 113 } 114 114 115 - if (spp.c.base.slot.layer_count == 0) { 115 + if (spp.c.base.layer_accum.layer_count == 0) { 116 116 glClearColor(0.2f, 0.2f, 0.2f, 0.0f); 117 117 glClear(GL_COLOR_BUFFER_BIT); 118 - } else if (spp.c.base.slot.layers[0].data.type == XRT_LAYER_PROJECTION || 119 - spp.c.base.slot.layers[0].data.type == XRT_LAYER_PROJECTION_DEPTH) { 118 + } else if (spp.c.base.layer_accum.layers[0].data.type == XRT_LAYER_PROJECTION || 119 + spp.c.base.layer_accum.layers[0].data.type == XRT_LAYER_PROJECTION_DEPTH) { 120 120 121 - auto &l = spp.c.base.slot.layers[0]; 121 + auto &l = spp.c.base.layer_accum.layers[0]; 122 122 auto &ssc = *(sdl_swapchain *)l.sc_array[0]; 123 123 GLuint tex = ssc.textures[l.data.proj.v[0].sub.image_index]; 124 124