From b7dbdae304a1ff09da6a32b90ad45f8c162c5705 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sun, 1 Oct 2023 21:07:04 +0100 Subject: [PATCH] c/main: Refactor vertex rot getting in renderer --- src/xrt/compositor/main/comp_renderer.c | 69 ++++++++++++++----------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/src/xrt/compositor/main/comp_renderer.c b/src/xrt/compositor/main/comp_renderer.c index 3924c1721..67d94c1a8 100644 --- a/src/xrt/compositor/main/comp_renderer.c +++ b/src/xrt/compositor/main/comp_renderer.c @@ -215,6 +215,40 @@ calc_viewport_data(struct comp_renderer *r, *out_r_viewport_data = r_viewport_data; } +static void +calc_vertex_rot_data(struct comp_renderer *r, struct xrt_matrix_2x2 out_vertex_rots[2]) +{ + bool pre_rotate = false; + if (r->c->target->surface_transform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR || + r->c->target->surface_transform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) { + COMP_SPEW(r->c, "Swapping width and height, since we are pre rotating"); + pre_rotate = true; + } + + const struct xrt_matrix_2x2 rotation_90_cw = {{ + .vecs = + { + {0, 1}, + {-1, 0}, + }, + }}; + + for (uint32_t i = 0; i < 2; i++) { + // Get the view. + struct xrt_view *v = &r->c->xdev->hmd->views[i]; + + // Copy data. + struct xrt_matrix_2x2 rot = v->rot; + + // Should we rotate. + if (pre_rotate) { + m_mat2x2_multiply(&rot, &rotation_90_cw, &rot); + } + + out_vertex_rots[i] = rot; + } +} + static void calc_pose_data(struct comp_renderer *r, struct xrt_fov out_fovs[2], @@ -298,28 +332,18 @@ renderer_build_rendering(struct comp_renderer *r, { COMP_TRACE_MARKER(); - struct comp_compositor *c = r->c; - /* * Rendering */ - bool pre_rotate = false; - if (r->c->target->surface_transform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR || - r->c->target->surface_transform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) { - COMP_SPEW(c, "Swapping width and height, since we are pre rotating"); - pre_rotate = true; - } - struct render_viewport_data l_viewport_data; struct render_viewport_data r_viewport_data; calc_viewport_data(r, &l_viewport_data, &r_viewport_data); - struct xrt_view *l_v = &r->c->xdev->hmd->views[0]; - struct xrt_view *r_v = &r->c->xdev->hmd->views[1]; - + struct xrt_matrix_2x2 vertex_rots[2]; + calc_vertex_rot_data(r, vertex_rots); /* @@ -328,32 +352,15 @@ renderer_build_rendering(struct comp_renderer *r, struct render_gfx_mesh_ubo_data distortion_data[2] = { { - .vertex_rot = l_v->rot, + .vertex_rot = vertex_rots[0], .post_transform = src_norm_rects[0], }, { - .vertex_rot = r_v->rot, + .vertex_rot = vertex_rots[1], .post_transform = src_norm_rects[1], }, }; - const struct xrt_matrix_2x2 rotation_90_cw = {{ - .vecs = - { - {0, 1}, - {-1, 0}, - }, - }}; - - if (pre_rotate) { - m_mat2x2_multiply(&distortion_data[0].vertex_rot, // - &rotation_90_cw, // - &distortion_data[0].vertex_rot); // - m_mat2x2_multiply(&distortion_data[1].vertex_rot, // - &rotation_90_cw, // - &distortion_data[1].vertex_rot); // - } - render_gfx_update_distortion(rr, // 0, // view_index src_samplers[0], //