The open source OpenXR runtime

c/main: Refactor dispatch_graphics function

+43 -67
+43 -67
src/xrt/compositor/main/comp_renderer.c
··· 926 926 struct comp_target *ct = c->target; 927 927 928 928 struct render_gfx_target_resources *rtr = &r->rtr_array[r->acquired_buffer]; 929 - bool one_projection_layer_fast_path = c->base.slot.one_projection_layer_fast_path; 929 + bool fast_path = c->base.slot.one_projection_layer_fast_path; 930 930 931 - // Need to be begin for all paths. 932 - render_gfx_begin(rr); 931 + // Only used if fast_path is true. 932 + const struct comp_layer *layer = &c->base.slot.layers[0]; 933 933 934 - // No fast path, standard layer renderer path. 935 - if (!one_projection_layer_fast_path) { 936 - renderer_get_view_projection(r); 937 - comp_layer_renderer_draw( // 938 - r->lr, // 939 - c->nr.cmd, // 940 - &r->scratch_targets[0], // 941 - &r->scratch_targets[1]); // 934 + // Sanity check. 935 + assert(!fast_path || c->base.slot.layer_count >= 1); 942 936 943 - VkSampler clamp_to_border_black = r->c->nr.samplers.clamp_to_border_black; 944 - VkSampler src_samplers[2] = { 945 - clamp_to_border_black, 946 - clamp_to_border_black, 947 - }; 948 - VkImageView src_image_views[2] = { 949 - r->scratch.color[0].srgb_view, 950 - r->scratch.color[1].srgb_view, 951 - }; 937 + // Need to be begin for all paths. 938 + render_gfx_begin(rr); 952 939 953 - struct xrt_normalized_rect src_norm_rects[2] = { 954 - {.x = 0, .y = 0, .w = 1, .h = 1}, 955 - {.x = 0, .y = 0, .w = 1, .h = 1}, 956 - }; 957 - 958 - renderer_build_rendering(r, rr, rtr, src_samplers, src_image_views, src_norm_rects); 959 - 960 - // Make the command buffer usable. 961 - render_gfx_end(rr); 962 - 963 - renderer_submit_queue(r, rr->r->cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); 964 - 965 - // We mark afterwards to not include CPU time spent. 966 - comp_target_mark_submit(ct, c->frame.rendering.id, os_monotonic_get_ns()); 967 - 968 - return; 969 - } 970 - 971 - 972 - /* 973 - * Fast path. 974 - */ 975 - 976 - XRT_MAYBE_UNUSED const uint32_t layer_count = c->base.slot.layer_count; 977 - assert(layer_count >= 1); 978 - 979 - int i = 0; 980 - const struct comp_layer *layer = &c->base.slot.layers[i]; 981 940 982 - switch (layer->data.type) { 983 - case XRT_LAYER_STEREO_PROJECTION: { 941 + if (fast_path && layer->data.type == XRT_LAYER_STEREO_PROJECTION_DEPTH) { 942 + // Fast path. 984 943 const struct xrt_layer_stereo_projection_data *stereo = &layer->data.stereo; 985 944 const struct xrt_layer_projection_view_data *lvd = &stereo->l; 986 945 const struct xrt_layer_projection_view_data *rvd = &stereo->r; ··· 992 951 993 952 do_gfx_mesh_and_proj(r, rr, rtr, layer, lvd, rvd); 994 953 995 - // Make the command buffer usable. 996 - render_gfx_end(rr); 997 - 998 - renderer_submit_queue(r, rr->r->cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); 999 - 1000 - // We mark afterwards to not include CPU time spent. 1001 - comp_target_mark_submit(ct, c->frame.rendering.id, os_monotonic_get_ns()); 1002 - } break; 1003 - 1004 - case XRT_LAYER_STEREO_PROJECTION_DEPTH: { 954 + } else if (fast_path && layer->data.type == XRT_LAYER_STEREO_PROJECTION_DEPTH) { 955 + // Fast path. 1005 956 const struct xrt_layer_stereo_projection_depth_data *stereo = &layer->data.stereo_depth; 1006 957 const struct xrt_layer_projection_view_data *lvd = &stereo->l; 1007 958 const struct xrt_layer_projection_view_data *rvd = &stereo->r; ··· 1013 964 1014 965 do_gfx_mesh_and_proj(r, rr, rtr, layer, lvd, rvd); 1015 966 1016 - // Make the command buffer usable. 1017 - render_gfx_end(rr); 967 + } else { 968 + 969 + renderer_get_view_projection(r); 1018 970 1019 - renderer_submit_queue(r, rr->r->cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); 971 + comp_layer_renderer_draw( // 972 + r->lr, // 973 + c->nr.cmd, // 974 + &r->scratch_targets[0], // 975 + &r->scratch_targets[1]); // 976 + 977 + VkSampler clamp_to_border_black = r->c->nr.samplers.clamp_to_border_black; 978 + VkSampler src_samplers[2] = { 979 + clamp_to_border_black, 980 + clamp_to_border_black, 981 + }; 982 + VkImageView src_image_views[2] = { 983 + r->scratch.color[0].srgb_view, 984 + r->scratch.color[1].srgb_view, 985 + }; 1020 986 1021 - // We mark afterwards to not include CPU time spent. 1022 - comp_target_mark_submit(ct, c->frame.rendering.id, os_monotonic_get_ns()); 1023 - } break; 987 + struct xrt_normalized_rect src_norm_rects[2] = { 988 + {.x = 0, .y = 0, .w = 1, .h = 1}, 989 + {.x = 0, .y = 0, .w = 1, .h = 1}, 990 + }; 1024 991 1025 - default: COMP_ERROR(c, "Unhandled case: '%u'", layer->data.type); assert(false); 992 + renderer_build_rendering(r, rr, rtr, src_samplers, src_image_views, src_norm_rects); 1026 993 } 994 + 995 + // Make the command buffer submittable. 996 + render_gfx_end(rr); 997 + 998 + // Everything is ready, submit to the queue. 999 + renderer_submit_queue(r, rr->r->cmd, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT); 1000 + 1001 + // We mark afterwards to not include CPU time spent. 1002 + comp_target_mark_submit(ct, c->frame.rendering.id, os_monotonic_get_ns()); 1027 1003 } 1028 1004 1029 1005