mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-29 18:08:29 +00:00
c/util: CS renderer improve consistency/similarity to GFX
Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2323>
This commit is contained in:
parent
7ec043eef0
commit
6c73d381cc
|
@ -54,8 +54,7 @@ get_layer_depth_image(const struct comp_layer *layer, uint32_t swapchain_index,
|
|||
}
|
||||
|
||||
static inline void
|
||||
do_cs_equirect2_layer(const struct xrt_layer_data *data,
|
||||
const struct comp_layer *layer,
|
||||
do_cs_equirect2_layer(const struct comp_layer *layer,
|
||||
const struct xrt_matrix_4x4 *eye_view_mat,
|
||||
const struct xrt_matrix_4x4 *world_view_mat,
|
||||
uint32_t view_index,
|
||||
|
@ -75,11 +74,11 @@ do_cs_equirect2_layer(const struct xrt_layer_data *data,
|
|||
|
||||
// Image to use.
|
||||
src_samplers[cur_image] = clamp_to_edge;
|
||||
src_image_views[cur_image] = get_image_view(image, data->flags, array_index);
|
||||
src_image_views[cur_image] = get_image_view(image, layer_data->flags, array_index);
|
||||
|
||||
// Used for Subimage and OpenGL flip.
|
||||
set_post_transform_rect( //
|
||||
data, // data
|
||||
layer_data, // data
|
||||
&eq2->sub.norm_rect, // src_norm_rect
|
||||
false, // invert_flip
|
||||
&ubo_data->post_transforms[cur_layer]); // out_norm_rect
|
||||
|
@ -92,7 +91,7 @@ do_cs_equirect2_layer(const struct xrt_layer_data *data,
|
|||
struct xrt_matrix_4x4 model_inv;
|
||||
math_matrix_4x4_inverse(&model, &model_inv);
|
||||
|
||||
const struct xrt_matrix_4x4 *v = is_layer_view_space(data) ? eye_view_mat : world_view_mat;
|
||||
const struct xrt_matrix_4x4 *v = is_layer_view_space(layer_data) ? eye_view_mat : world_view_mat;
|
||||
|
||||
struct xrt_matrix_4x4 v_inv;
|
||||
math_matrix_4x4_inverse(v, &v_inv);
|
||||
|
@ -117,8 +116,7 @@ do_cs_equirect2_layer(const struct xrt_layer_data *data,
|
|||
}
|
||||
|
||||
static inline void
|
||||
do_cs_projection_layer(const struct xrt_layer_data *data,
|
||||
const struct comp_layer *layer,
|
||||
do_cs_projection_layer(const struct comp_layer *layer,
|
||||
const struct xrt_pose *world_pose,
|
||||
uint32_t view_index,
|
||||
uint32_t cur_layer,
|
||||
|
@ -147,22 +145,22 @@ do_cs_projection_layer(const struct xrt_layer_data *data,
|
|||
|
||||
// Color
|
||||
src_samplers[cur_image] = clamp_to_border_black;
|
||||
src_image_views[cur_image] = get_image_view(image, data->flags, array_index);
|
||||
src_image_views[cur_image] = get_image_view(image, layer_data->flags, array_index);
|
||||
ubo_data->images_samplers[cur_layer + 0].images[0] = cur_image++;
|
||||
|
||||
// Depth
|
||||
if (data->type == XRT_LAYER_PROJECTION_DEPTH) {
|
||||
if (layer_data->type == XRT_LAYER_PROJECTION_DEPTH) {
|
||||
uint32_t d_array_index = dvd->sub.array_index;
|
||||
const struct comp_swapchain_image *d_image =
|
||||
get_layer_depth_image(layer, sc_array_index, dvd->sub.image_index);
|
||||
|
||||
src_samplers[cur_image] = clamp_to_edge; // Edge to keep depth stable at edges.
|
||||
src_image_views[cur_image] = get_image_view(d_image, data->flags, d_array_index);
|
||||
src_image_views[cur_image] = get_image_view(d_image, layer_data->flags, d_array_index);
|
||||
ubo_data->images_samplers[cur_layer + 0].images[1] = cur_image++;
|
||||
}
|
||||
|
||||
set_post_transform_rect( //
|
||||
data, // data
|
||||
layer_data, // data
|
||||
&vd->sub.norm_rect, // src_norm_rect
|
||||
false, // invert_flip
|
||||
&ubo_data->post_transforms[cur_layer]); // out_norm_rect
|
||||
|
@ -180,8 +178,7 @@ do_cs_projection_layer(const struct xrt_layer_data *data,
|
|||
}
|
||||
|
||||
static inline void
|
||||
do_cs_quad_layer(const struct xrt_layer_data *data,
|
||||
const struct comp_layer *layer,
|
||||
do_cs_quad_layer(const struct comp_layer *layer,
|
||||
const struct xrt_matrix_4x4 *eye_view_mat,
|
||||
const struct xrt_matrix_4x4 *world_view_mat,
|
||||
uint32_t view_index,
|
||||
|
@ -201,28 +198,28 @@ do_cs_quad_layer(const struct xrt_layer_data *data,
|
|||
|
||||
// Image to use.
|
||||
src_samplers[cur_image] = clamp_to_edge;
|
||||
src_image_views[cur_image] = get_image_view(image, data->flags, array_index);
|
||||
src_image_views[cur_image] = get_image_view(image, layer_data->flags, array_index);
|
||||
|
||||
// Set the normalized post transform values.
|
||||
struct xrt_normalized_rect post_transform = XRT_STRUCT_INIT;
|
||||
set_post_transform_rect( //
|
||||
data, // data
|
||||
layer_data, // data
|
||||
&q->sub.norm_rect, // src_norm_rect
|
||||
true, // invert_flip
|
||||
&post_transform); // out_norm_rect
|
||||
|
||||
// Is this layer viewspace or not.
|
||||
const struct xrt_matrix_4x4 *view_mat = is_layer_view_space(data) ? eye_view_mat : world_view_mat;
|
||||
const struct xrt_matrix_4x4 *view_mat = is_layer_view_space(layer_data) ? eye_view_mat : world_view_mat;
|
||||
|
||||
// Transform quad pose into view space.
|
||||
struct xrt_vec3 quad_position = XRT_STRUCT_INIT;
|
||||
math_matrix_4x4_transform_vec3(view_mat, &data->quad.pose.position, &quad_position);
|
||||
math_matrix_4x4_transform_vec3(view_mat, &layer_data->quad.pose.position, &quad_position);
|
||||
|
||||
// neutral quad layer faces +z, towards the user
|
||||
struct xrt_vec3 normal = (struct xrt_vec3){.x = 0, .y = 0, .z = 1};
|
||||
|
||||
// rotation of the quad normal in world space
|
||||
struct xrt_quat rotation = data->quad.pose.orientation;
|
||||
struct xrt_quat rotation = layer_data->quad.pose.orientation;
|
||||
math_quat_rotate_vec3(&rotation, &normal, &normal);
|
||||
|
||||
/*
|
||||
|
@ -239,19 +236,19 @@ do_cs_quad_layer(const struct xrt_layer_data *data,
|
|||
* normal_view_space = combined_normal [in view space] - plane_origin [in view space]
|
||||
*/
|
||||
struct xrt_vec3 normal_view_space = normal;
|
||||
math_vec3_accum(&data->quad.pose.position, &normal_view_space);
|
||||
math_vec3_accum(&layer_data->quad.pose.position, &normal_view_space);
|
||||
math_matrix_4x4_transform_vec3(view_mat, &normal_view_space, &normal_view_space);
|
||||
math_vec3_subtract(&quad_position, &normal_view_space);
|
||||
|
||||
struct xrt_vec3 scale = {1.f, 1.f, 1.f};
|
||||
struct xrt_matrix_4x4 plane_transform_view_space, inverse_quad_transform;
|
||||
math_matrix_4x4_model(&data->quad.pose, &scale, &plane_transform_view_space);
|
||||
math_matrix_4x4_model(&layer_data->quad.pose, &scale, &plane_transform_view_space);
|
||||
math_matrix_4x4_multiply(view_mat, &plane_transform_view_space, &plane_transform_view_space);
|
||||
math_matrix_4x4_inverse(&plane_transform_view_space, &inverse_quad_transform);
|
||||
|
||||
// Write all of the UBO data.
|
||||
ubo_data->post_transforms[cur_layer] = post_transform;
|
||||
ubo_data->quad_extent[cur_layer].val = data->quad.size;
|
||||
ubo_data->quad_extent[cur_layer].val = layer_data->quad.size;
|
||||
ubo_data->quad_position[cur_layer].val = quad_position;
|
||||
ubo_data->quad_normal[cur_layer].val = normal_view_space;
|
||||
ubo_data->inverse_quad_transform[cur_layer] = inverse_quad_transform;
|
||||
|
@ -263,8 +260,7 @@ do_cs_quad_layer(const struct xrt_layer_data *data,
|
|||
|
||||
|
||||
static inline void
|
||||
do_cs_cylinder_layer(const struct xrt_layer_data *data,
|
||||
const struct comp_layer *layer,
|
||||
do_cs_cylinder_layer(const struct comp_layer *layer,
|
||||
const struct xrt_matrix_4x4 *eye_view_mat,
|
||||
const struct xrt_matrix_4x4 *world_view_mat,
|
||||
uint32_t view_index,
|
||||
|
@ -284,7 +280,7 @@ do_cs_cylinder_layer(const struct xrt_layer_data *data,
|
|||
|
||||
// Image to use.
|
||||
src_samplers[cur_image] = clamp_to_edge;
|
||||
src_image_views[cur_image] = get_image_view(image, data->flags, array_index);
|
||||
src_image_views[cur_image] = get_image_view(image, layer_data->flags, array_index);
|
||||
|
||||
// Used for Subimage and OpenGL flip.
|
||||
set_post_transform_rect( //
|
||||
|
@ -560,7 +556,6 @@ comp_render_cs_layer(struct render_compute *crc,
|
|||
switch (data->type) {
|
||||
case XRT_LAYER_CYLINDER:
|
||||
do_cs_cylinder_layer( //
|
||||
data, // data
|
||||
layer, // layer
|
||||
&eye_view_mat, // eye_view_mat
|
||||
&world_view_mat, // world_view_mat
|
||||
|
@ -576,7 +571,6 @@ comp_render_cs_layer(struct render_compute *crc,
|
|||
break;
|
||||
case XRT_LAYER_EQUIRECT2:
|
||||
do_cs_equirect2_layer( //
|
||||
data, // data
|
||||
layer, // layer
|
||||
&eye_view_mat, // eye_view_mat
|
||||
&world_view_mat, // world_view_mat
|
||||
|
@ -593,7 +587,6 @@ comp_render_cs_layer(struct render_compute *crc,
|
|||
case XRT_LAYER_PROJECTION_DEPTH:
|
||||
case XRT_LAYER_PROJECTION: {
|
||||
do_cs_projection_layer( //
|
||||
data, // data
|
||||
layer, // layer
|
||||
world_pose, // world_pose
|
||||
view_index, // view_index
|
||||
|
@ -609,7 +602,6 @@ comp_render_cs_layer(struct render_compute *crc,
|
|||
} break;
|
||||
case XRT_LAYER_QUAD: {
|
||||
do_cs_quad_layer( //
|
||||
data, // data
|
||||
layer, // layer
|
||||
&eye_view_mat, // eye_view_mat
|
||||
&world_view_mat, // world_view_mat
|
||||
|
|
Loading…
Reference in a new issue