The open source OpenXR runtime
0
fork

Configure Feed

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

c/main: Use high-level scratch helper

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

+29 -71
+5 -10
src/xrt/compositor/main/comp_compositor.c
··· 1 1 // Copyright 2019-2024, Collabora, Ltd. 2 + // Copyright 2025, NVIDIA CORPORATION. 2 3 // SPDX-License-Identifier: BSL-1.0 3 4 /*! 4 5 * @file ··· 387 388 u_var_remove_root(c); 388 389 389 390 // Destroy any Vulkan resources, even if not used. 390 - for (uint32_t i = 0; i < ARRAY_SIZE(c->scratch.views); i++) { 391 - comp_scratch_single_images_free(&c->scratch.views[i], &c->base.vk); 392 - } 391 + chl_scratch_free_resources(&c->scratch, &c->nr); 393 392 394 393 // Destroy the scratch images fully, we initialized all of them. 395 - for (uint32_t i = 0; i < ARRAY_SIZE(c->scratch.views); i++) { 396 - comp_scratch_single_images_destroy(&c->scratch.views[i]); 397 - } 394 + chl_scratch_fini(&c->scratch); 398 395 399 396 // Make sure we are not holding onto any swapchains. 400 397 u_swapchain_debug_destroy(&c->debug.sc); ··· 1028 1025 u_swapchain_debug_init(&c->debug.sc); 1029 1026 1030 1027 // Init these before the renderer, not all might be used. 1031 - for (uint32_t i = 0; i < ARRAY_SIZE(c->scratch.views); i++) { 1032 - comp_scratch_single_images_init(&c->scratch.views[i]); 1033 - } 1028 + chl_scratch_init(&c->scratch); 1034 1029 1035 1030 c->frame_interval_ns = c->settings.nominal_frame_interval_ns; 1036 1031 ··· 1154 1149 for (uint32_t i = 0; i < view_count; i++) { 1155 1150 char tmp[64] = {0}; 1156 1151 snprintf(tmp, sizeof(tmp), "View[%u]", i); 1157 - u_var_add_native_images_debug(c, &c->scratch.views[i].unid, tmp); 1152 + u_var_add_native_images_debug(c, &c->scratch.views[i].cssi.unid, tmp); 1158 1153 } 1159 1154 1160 1155 #ifdef XRT_OS_ANDROID
+4 -5
src/xrt/compositor/main/comp_compositor.h
··· 1 1 // Copyright 2019-2024, Collabora, Ltd. 2 + // Copyright 2025, NVIDIA CORPORATION. 2 3 // SPDX-License-Identifier: BSL-1.0 3 4 /*! 4 5 * @file ··· 23 24 #include "util/comp_sync.h" 24 25 #include "util/comp_scratch.h" 25 26 #include "util/comp_swapchain.h" 27 + #include "util/comp_high_level_scratch.h" 26 28 27 29 #include "render/render_interface.h" 28 30 ··· 143 145 struct comp_frame rendering; 144 146 } frame; 145 147 146 - struct 147 - { 148 - // Per-view scratch images. 149 - struct comp_scratch_single_images views[2]; 150 - } scratch; 148 + // Scratch images for the renderer. 149 + struct chl_scratch scratch; 151 150 152 151 struct 153 152 {
+20 -56
src/xrt/compositor/main/comp_renderer.c
··· 105 105 106 106 struct comp_mirror_to_debug_gui mirror_to_debug_gui; 107 107 108 - //! Render pass for graphics pipeline rendering to the scratch buffer. 109 - struct render_gfx_render_pass scratch_render_pass; 110 - 111 - struct 112 - { 113 - struct 114 - { 115 - //! Targets for rendering to the scratch buffer. 116 - struct render_gfx_target_resources targets[COMP_SCRATCH_NUM_IMAGES]; 117 - } views[XRT_MAX_VIEWS]; 118 - } scratch; 119 - 120 108 //! @} 121 109 122 110 //! @name Image-dependent members ··· 182 170 U_ZERO(crss); 183 171 184 172 for (uint32_t i = 0; i < view_count; i++) { 185 - comp_scratch_single_images_get(&c->scratch.views[i], &crss->views[i].index); 173 + comp_scratch_single_images_get(&c->scratch.views[i].cssi, &crss->views[i].index); 186 174 } 187 175 } 188 176 ··· 194 182 195 183 for (uint32_t i = 0; i < view_count; i++) { 196 184 if (crss->views[i].used) { 197 - comp_scratch_single_images_done(&c->scratch.views[i]); 185 + comp_scratch_single_images_done(&c->scratch.views[i].cssi); 198 186 } else { 199 - comp_scratch_single_images_discard(&c->scratch.views[i]); 187 + comp_scratch_single_images_discard(&c->scratch.views[i].cssi); 200 188 } 201 189 } 202 190 } ··· 564 552 renderer_init(struct comp_renderer *r, struct comp_compositor *c, VkExtent2D scratch_extent) 565 553 { 566 554 COMP_TRACE_MARKER(); 567 - bool bret; 568 555 569 556 r->c = c; 570 557 r->settings = &c->settings; ··· 573 560 r->fenced_buffer = -1; 574 561 r->rtr_array = NULL; 575 562 576 - // Shared render pass between all scratch images. 577 - render_gfx_render_pass_init( // 578 - &r->scratch_render_pass, // rgrp 579 - &r->c->nr, // struct render_resources 580 - VK_FORMAT_R8G8B8A8_SRGB, // format 581 - VK_ATTACHMENT_LOAD_OP_CLEAR, // load_op 582 - VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); // final_layout 583 - 584 - for (uint32_t i = 0; i < c->nr.view_count; i++) { 585 - bret = 586 - comp_scratch_single_images_ensure_mutable(&r->c->scratch.views[i], &r->c->base.vk, scratch_extent); 587 - if (!bret) { 588 - COMP_ERROR(c, "comp_scratch_single_images_ensure: false"); 589 - assert(false && "Whelp, can't return an error. But should never really fail."); 590 - } 591 - 592 - for (uint32_t k = 0; k < COMP_SCRATCH_NUM_IMAGES; k++) { 593 - struct render_scratch_color_image *rsci = &c->scratch.views[i].images[k]; 594 - 595 - render_gfx_target_resources_init( // 596 - &r->scratch.views[i].targets[k], // 597 - &r->c->nr, // 598 - &r->scratch_render_pass, // 599 - rsci->srgb_view, // 600 - scratch_extent); // 601 - } 563 + // Setup the scratch images. 564 + bool bret = chl_scratch_ensure( // 565 + &c->scratch, // scratch 566 + &c->nr, // struct render_resources 567 + c->nr.view_count, // view_count 568 + scratch_extent, // extent 569 + VK_FORMAT_R8G8B8A8_SRGB); // format 570 + if (!bret) { 571 + COMP_ERROR(c, "chl_scratch_ensure: false"); 572 + assert(bret && "Whelp, can't return a error. But should never really fail."); 602 573 } 603 574 604 575 // Try to early-allocate these, in case we can. ··· 895 866 comp_mirror_fini(&r->mirror_to_debug_gui, vk); 896 867 897 868 // Do this after the layer renderer. 898 - for (uint32_t i = 0; i < r->c->nr.view_count; i++) { 899 - for (uint32_t k = 0; k < COMP_SCRATCH_NUM_IMAGES; k++) { 900 - render_gfx_target_resources_fini(&r->scratch.views[i].targets[k]); 901 - } 902 - } 903 - 904 - // Do this after the layer renderer and targert resources. 905 - render_gfx_render_pass_fini(&r->scratch_render_pass); 869 + chl_scratch_free_resources(&r->c->scratch, &r->c->nr); 906 870 } 907 871 908 872 ··· 972 936 uint32_t scratch_index = crss->views[i].index; 973 937 974 938 // The set of scratch images we are using for this view. 975 - struct comp_scratch_single_images *scratch_view = &c->scratch.views[i]; 939 + struct comp_scratch_single_images *scratch_view = &c->scratch.views[i].cssi; 976 940 977 941 // The render target resources for the scratch images. 978 - struct render_gfx_target_resources *rsci_rtr = &r->scratch.views[i].targets[scratch_index]; 942 + struct render_gfx_target_resources *rsci_rtr = &c->scratch.views[i].targets[scratch_index]; 979 943 980 944 // Scratch color image. 981 945 struct render_scratch_color_image *rsci = &scratch_view->images[scratch_index]; ··· 1099 1063 uint32_t scratch_index = crss->views[i].index; 1100 1064 1101 1065 // The set of scratch images we are using for this view. 1102 - struct comp_scratch_single_images *scratch_view = &c->scratch.views[i]; 1066 + struct comp_scratch_single_images *scratch_view = &c->scratch.views[i].cssi; 1103 1067 1104 1068 // Scratch color image. 1105 1069 struct render_scratch_color_image *rsci = &scratch_view->images[scratch_index]; ··· 1242 1206 if (c->peek) { 1243 1207 switch (comp_window_peek_get_eye(c->peek)) { 1244 1208 case COMP_WINDOW_PEEK_EYE_LEFT: { 1245 - struct comp_scratch_single_images *view = &c->scratch.views[0]; 1209 + struct comp_scratch_single_images *view = &c->scratch.views[0].cssi; 1246 1210 comp_window_peek_blit( // 1247 1211 c->peek, // 1248 1212 view->images[crss.views[0].index].image, // ··· 1250 1214 view->info.height); // 1251 1215 } break; 1252 1216 case COMP_WINDOW_PEEK_EYE_RIGHT: { 1253 - struct comp_scratch_single_images *view = &c->scratch.views[1]; 1217 + struct comp_scratch_single_images *view = &c->scratch.views[1].cssi; 1254 1218 comp_window_peek_blit( // 1255 1219 c->peek, // 1256 1220 view->images[crss.views[1].index].image, // ··· 1281 1245 comp_mirror_fixup_ui_state(&r->mirror_to_debug_gui, c); 1282 1246 if (comp_mirror_is_ready_and_active(&r->mirror_to_debug_gui, c, predicted_display_time_ns)) { 1283 1247 1284 - struct comp_scratch_single_images *view = &c->scratch.views[0]; 1248 + struct comp_scratch_single_images *view = &c->scratch.views[0].cssi; 1285 1249 struct render_scratch_color_image *rsci = &view->images[crss.views[0].index]; 1286 1250 VkExtent2D extent = {view->info.width, view->info.width}; 1287 1251