mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
comp+ipc: Respect view space layer flag
This commit is contained in:
parent
abf8d5b8bd
commit
65dcc82e3a
|
@ -357,9 +357,7 @@ compositor_layer_commit(struct xrt_compositor *xc)
|
|||
struct xrt_layer_quad_data *quad = &layer->data.quad;
|
||||
struct comp_swapchain_image *image;
|
||||
image = &layer->scs[0]->images[quad->sub.image_index];
|
||||
comp_renderer_set_quad_layer(c->r, image, &quad->pose,
|
||||
&quad->size, data->flip_y,
|
||||
i, quad->sub.array_index);
|
||||
comp_renderer_set_quad_layer(c->r, i, image, data);
|
||||
} break;
|
||||
case XRT_LAYER_STEREO_PROJECTION: {
|
||||
struct xrt_layer_stereo_projection_data *stereo =
|
||||
|
@ -371,10 +369,8 @@ compositor_layer_commit(struct xrt_compositor *xc)
|
|||
right =
|
||||
&layer->scs[1]->images[stereo->r.sub.image_index];
|
||||
|
||||
comp_renderer_set_projection_layer(
|
||||
c->r, left, right, data->flip_y, i,
|
||||
stereo->l.sub.array_index,
|
||||
stereo->r.sub.array_index);
|
||||
comp_renderer_set_projection_layer(c->r, i, left, right,
|
||||
data);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,6 +162,7 @@ _init(struct comp_render_layer *self,
|
|||
self->type = type;
|
||||
|
||||
self->visible = true;
|
||||
self->view_space = true;
|
||||
|
||||
math_matrix_4x4_identity(&self->model_matrix);
|
||||
|
||||
|
@ -202,7 +203,8 @@ comp_layer_draw(struct comp_render_layer *self,
|
|||
VkPipelineLayout pipeline_layout,
|
||||
VkCommandBuffer cmd_buffer,
|
||||
const struct vk_buffer *vertex_buffer,
|
||||
const struct xrt_matrix_4x4 *vp)
|
||||
const struct xrt_matrix_4x4 *vp_world,
|
||||
const struct xrt_matrix_4x4 *vp_eye)
|
||||
{
|
||||
if (!self->visible)
|
||||
return;
|
||||
|
@ -210,6 +212,9 @@ comp_layer_draw(struct comp_render_layer *self,
|
|||
self->vk->vkCmdBindPipeline(cmd_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
pipeline);
|
||||
|
||||
// Is this layer viewspace or not.
|
||||
const struct xrt_matrix_4x4 *vp = self->view_space ? vp_eye : vp_world;
|
||||
|
||||
switch (self->type) {
|
||||
case XRT_LAYER_STEREO_PROJECTION:
|
||||
_update_mvp_matrix(self, eye, &proj_scale);
|
||||
|
|
|
@ -23,6 +23,7 @@ struct comp_render_layer
|
|||
struct vk_bundle *vk;
|
||||
|
||||
bool visible;
|
||||
bool view_space;
|
||||
|
||||
enum xrt_layer_type type;
|
||||
|
||||
|
@ -47,7 +48,8 @@ comp_layer_draw(struct comp_render_layer *self,
|
|||
VkPipelineLayout pipeline_layout,
|
||||
VkCommandBuffer cmd_buffer,
|
||||
const struct vk_buffer *vertex_buffer,
|
||||
const struct xrt_matrix_4x4 *vp);
|
||||
const struct xrt_matrix_4x4 *vp_world,
|
||||
const struct xrt_matrix_4x4 *vp_eye);
|
||||
|
||||
void
|
||||
comp_layer_set_model_matrix(struct comp_render_layer *self,
|
||||
|
|
|
@ -381,14 +381,18 @@ _render_eye(struct comp_layer_renderer *self,
|
|||
VkCommandBuffer cmd_buffer,
|
||||
VkPipelineLayout pipeline_layout)
|
||||
{
|
||||
struct xrt_matrix_4x4 vp;
|
||||
struct xrt_matrix_4x4 vp_world;
|
||||
struct xrt_matrix_4x4 vp_eye;
|
||||
math_matrix_4x4_multiply(&self->mat_projection[eye],
|
||||
&self->mat_view[eye], &vp);
|
||||
&self->mat_world_view[eye], &vp_world);
|
||||
math_matrix_4x4_multiply(&self->mat_projection[eye],
|
||||
&self->mat_eye_view[eye], &vp_eye);
|
||||
|
||||
for (uint32_t i = 0; i < self->num_layers; i++)
|
||||
for (uint32_t i = 0; i < self->num_layers; i++) {
|
||||
comp_layer_draw(self->layers[i], eye, self->pipeline,
|
||||
pipeline_layout, cmd_buffer,
|
||||
&self->vertex_buffer, &vp);
|
||||
&self->vertex_buffer, &vp_world, &vp_eye);
|
||||
}
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -484,7 +488,8 @@ _init(struct comp_layer_renderer *self,
|
|||
|
||||
for (uint32_t i = 0; i < 2; i++) {
|
||||
math_matrix_4x4_identity(&self->mat_projection[i]);
|
||||
math_matrix_4x4_identity(&self->mat_view[i]);
|
||||
math_matrix_4x4_identity(&self->mat_world_view[i]);
|
||||
math_matrix_4x4_identity(&self->mat_eye_view[i]);
|
||||
}
|
||||
|
||||
if (!_init_render_pass(vk, format,
|
||||
|
@ -649,7 +654,7 @@ comp_layer_renderer_destroy(struct comp_layer_renderer *self)
|
|||
void
|
||||
comp_layer_renderer_set_fov(struct comp_layer_renderer *self,
|
||||
const struct xrt_fov *fov,
|
||||
uint32_t view_id)
|
||||
uint32_t eye)
|
||||
{
|
||||
const float tan_left = tanf(fov->angle_left);
|
||||
const float tan_right = tanf(fov->angle_right);
|
||||
|
@ -670,7 +675,7 @@ comp_layer_renderer_set_fov(struct comp_layer_renderer *self,
|
|||
const float a43 = -(self->far * self->near) / (self->far - self->near);
|
||||
|
||||
// clang-format off
|
||||
self->mat_projection[view_id] = (struct xrt_matrix_4x4) {
|
||||
self->mat_projection[eye] = (struct xrt_matrix_4x4) {
|
||||
.v = {
|
||||
a11, 0, 0, 0,
|
||||
0, a22, 0, 0,
|
||||
|
@ -683,8 +688,10 @@ comp_layer_renderer_set_fov(struct comp_layer_renderer *self,
|
|||
|
||||
void
|
||||
comp_layer_renderer_set_pose(struct comp_layer_renderer *self,
|
||||
const struct xrt_pose *pose,
|
||||
uint32_t view_id)
|
||||
const struct xrt_pose *eye_pose,
|
||||
const struct xrt_pose *world_pose,
|
||||
uint32_t eye)
|
||||
{
|
||||
math_matrix_4x4_view_from_pose(pose, &self->mat_view[view_id]);
|
||||
math_matrix_4x4_view_from_pose(eye_pose, &self->mat_eye_view[eye]);
|
||||
math_matrix_4x4_view_from_pose(world_pose, &self->mat_world_view[eye]);
|
||||
}
|
||||
|
|
|
@ -42,7 +42,8 @@ struct comp_layer_renderer
|
|||
VkPipelineLayout pipeline_layout;
|
||||
VkPipelineCache pipeline_cache;
|
||||
|
||||
struct xrt_matrix_4x4 mat_view[2];
|
||||
struct xrt_matrix_4x4 mat_world_view[2];
|
||||
struct xrt_matrix_4x4 mat_eye_view[2];
|
||||
struct xrt_matrix_4x4 mat_projection[2];
|
||||
|
||||
struct vk_buffer vertex_buffer;
|
||||
|
@ -68,12 +69,13 @@ comp_layer_renderer_draw(struct comp_layer_renderer *self);
|
|||
void
|
||||
comp_layer_renderer_set_fov(struct comp_layer_renderer *self,
|
||||
const struct xrt_fov *fov,
|
||||
uint32_t view_id);
|
||||
uint32_t eye);
|
||||
|
||||
void
|
||||
comp_layer_renderer_set_pose(struct comp_layer_renderer *self,
|
||||
const struct xrt_pose *pose,
|
||||
uint32_t view_id);
|
||||
const struct xrt_pose *eye_pose,
|
||||
const struct xrt_pose *world_pose,
|
||||
uint32_t eye);
|
||||
|
||||
void
|
||||
comp_layer_renderer_allocate_layers(struct comp_layer_renderer *self,
|
||||
|
|
|
@ -416,15 +416,15 @@ _get_view_projection(struct comp_renderer *r)
|
|||
|
||||
comp_layer_renderer_set_fov(r->lr, &fov, i);
|
||||
|
||||
struct xrt_pose view_pose;
|
||||
struct xrt_pose eye_pose;
|
||||
xrt_device_get_view_pose(r->c->xdev, &eye_relation, i,
|
||||
&view_pose);
|
||||
&eye_pose);
|
||||
|
||||
struct xrt_pose pose;
|
||||
math_pose_openxr_locate(&view_pose, &relation.pose,
|
||||
&base_space_pose, &pose);
|
||||
struct xrt_pose world_pose;
|
||||
math_pose_openxr_locate(&eye_pose, &relation.pose,
|
||||
&base_space_pose, &world_pose);
|
||||
|
||||
comp_layer_renderer_set_pose(r->lr, &pose, i);
|
||||
comp_layer_renderer_set_pose(r->lr, &eye_pose, &world_pose, i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -474,44 +474,48 @@ renderer_init(struct comp_renderer *r)
|
|||
|
||||
void
|
||||
comp_renderer_set_quad_layer(struct comp_renderer *r,
|
||||
struct comp_swapchain_image *image,
|
||||
struct xrt_pose *pose,
|
||||
struct xrt_vec2 *size,
|
||||
bool flip_y,
|
||||
uint32_t layer,
|
||||
uint32_t array_index)
|
||||
struct comp_swapchain_image *image,
|
||||
struct xrt_layer_data *data)
|
||||
{
|
||||
comp_layer_update_descriptors(r->lr->layers[layer], image->sampler,
|
||||
image->views[array_index]);
|
||||
image->views[data->quad.sub.array_index]);
|
||||
|
||||
struct xrt_matrix_4x4 model_matrix;
|
||||
math_matrix_4x4_quad_model(pose, size, &model_matrix);
|
||||
math_matrix_4x4_quad_model(&data->quad.pose, &data->quad.size,
|
||||
&model_matrix);
|
||||
|
||||
comp_layer_set_model_matrix(r->lr->layers[layer], &model_matrix);
|
||||
|
||||
comp_layer_set_flip_y(r->lr->layers[layer], data->flip_y);
|
||||
|
||||
r->lr->layers[layer]->type = XRT_LAYER_QUAD;
|
||||
comp_layer_set_flip_y(r->lr->layers[layer], flip_y);
|
||||
r->lr->layers[layer]->view_space =
|
||||
(data->flags & XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT) != 0;
|
||||
|
||||
r->c->vk.vkDeviceWaitIdle(r->c->vk.device);
|
||||
}
|
||||
|
||||
void
|
||||
comp_renderer_set_projection_layer(struct comp_renderer *r,
|
||||
uint32_t layer,
|
||||
struct comp_swapchain_image *left_image,
|
||||
struct comp_swapchain_image *right_image,
|
||||
bool flip_y,
|
||||
uint32_t layer,
|
||||
uint32_t left_array_index,
|
||||
uint32_t right_array_index)
|
||||
struct xrt_layer_data *data)
|
||||
{
|
||||
uint32_t left_array_index = data->stereo.l.sub.array_index;
|
||||
uint32_t right_array_index = data->stereo.r.sub.array_index;
|
||||
|
||||
comp_layer_update_stereo_descriptors(
|
||||
r->lr->layers[layer], left_image->sampler, right_image->sampler,
|
||||
left_image->views[left_array_index],
|
||||
right_image->views[right_array_index]);
|
||||
|
||||
comp_layer_set_flip_y(r->lr->layers[layer], flip_y);
|
||||
comp_layer_set_flip_y(r->lr->layers[layer], data->flip_y);
|
||||
|
||||
r->lr->layers[layer]->type = XRT_LAYER_STEREO_PROJECTION;
|
||||
r->lr->layers[layer]->view_space =
|
||||
(data->flags & XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT) != 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -56,22 +56,16 @@ comp_renderer_draw(struct comp_renderer *r);
|
|||
|
||||
void
|
||||
comp_renderer_set_projection_layer(struct comp_renderer *r,
|
||||
uint32_t layer,
|
||||
struct comp_swapchain_image *left_image,
|
||||
struct comp_swapchain_image *right_image,
|
||||
bool flip_y,
|
||||
uint32_t layer,
|
||||
uint32_t left_array_index,
|
||||
uint32_t right_array_index);
|
||||
struct xrt_layer_data *data);
|
||||
|
||||
void
|
||||
comp_renderer_set_quad_layer(struct comp_renderer *r,
|
||||
struct comp_swapchain_image *image,
|
||||
struct xrt_pose *pose,
|
||||
struct xrt_vec2 *size,
|
||||
bool flip_y,
|
||||
uint32_t layer,
|
||||
uint32_t array_index);
|
||||
|
||||
struct comp_swapchain_image *image,
|
||||
struct xrt_layer_data *data);
|
||||
|
||||
void
|
||||
comp_renderer_allocate_layers(struct comp_renderer *self, uint32_t num_layers);
|
||||
|
|
|
@ -540,12 +540,12 @@ _update_projection_layer(struct comp_compositor *c,
|
|||
l = &cl->images[layer->data.stereo.l.sub.image_index];
|
||||
r = &cr->images[layer->data.stereo.r.sub.image_index];
|
||||
|
||||
|
||||
// Cast away volatile.
|
||||
struct xrt_layer_data *data = (struct xrt_layer_data *)&layer->data;
|
||||
|
||||
//! @todo we are ignoring subrect here!
|
||||
// (and perhaps can simplify by re-using some structs?)
|
||||
comp_renderer_set_projection_layer(
|
||||
c->r, l, r, layer->data.flip_y, i,
|
||||
layer->data.stereo.l.sub.array_index,
|
||||
layer->data.stereo.r.sub.array_index);
|
||||
comp_renderer_set_projection_layer(c->r, i, l, r, data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -567,14 +567,11 @@ _update_quad_layer(struct comp_compositor *c,
|
|||
struct comp_swapchain_image *image = NULL;
|
||||
image = &sc->images[layer->data.quad.sub.image_index];
|
||||
|
||||
struct xrt_pose pose = layer->data.quad.pose;
|
||||
struct xrt_vec2 size = layer->data.quad.size;
|
||||
// Cast away volatile.
|
||||
struct xrt_layer_data *data = (struct xrt_layer_data *)&layer->data;
|
||||
|
||||
//! @todo we are ignoring subrect here!
|
||||
// (and perhaps can simplify by re-using some structs?)
|
||||
comp_renderer_set_quad_layer(c->r, image, &pose, &size,
|
||||
layer->data.flip_y, i,
|
||||
layer->data.quad.sub.array_index);
|
||||
comp_renderer_set_quad_layer(c->r, i, image, data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue