diff --git a/src/xrt/compositor/render/render_interface.h b/src/xrt/compositor/render/render_interface.h index bcc7e30ce..5db279a21 100644 --- a/src/xrt/compositor/render/render_interface.h +++ b/src/xrt/compositor/render/render_interface.h @@ -1,4 +1,5 @@ // Copyright 2019-2023, Collabora, Ltd. +// Copyright 2025, NVIDIA CORPORATION. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -1207,27 +1208,39 @@ struct render_compute_layer_ubo_data struct { uint32_t value; - uint32_t padding[3]; + uint32_t padding[3]; // Padding up to a vec4. } layer_count; struct xrt_normalized_rect pre_transform; struct xrt_normalized_rect post_transforms[RENDER_MAX_LAYERS]; - //! std140 uvec2, corresponds to enum xrt_layer_type and unpremultiplied alpha. + /*! + * Corresponds to enum xrt_layer_type and unpremultiplied alpha. + * + * std140 uvec2, because it is an array it gets padded to vec4. + */ struct { - uint32_t val; - uint32_t unpremultiplied; - uint32_t padding[XRT_MAX_VIEWS]; - } layer_type[RENDER_MAX_LAYERS]; + uint32_t layer_type; + uint32_t unpremultiplied_alpha; + uint32_t _padding0; + uint32_t _padding1; + } layer_data[RENDER_MAX_LAYERS]; - //! Which image/sampler(s) correspond to each layer. + /*! + * Which image/sampler(s) correspond to each layer. + * + * std140 uvec2, because it is an array it gets padded to vec4. + */ struct { - uint32_t images[XRT_MAX_VIEWS]; + uint32_t color_image_index; + uint32_t depth_image_index; + //! @todo Implement separated samplers and images (and change to samplers[2]) - uint32_t padding[XRT_MAX_VIEWS]; - } images_samplers[RENDER_MAX_LAYERS]; + uint32_t _padding0; + uint32_t _padding1; + } image_info[RENDER_MAX_LAYERS]; //! Shared between cylinder and equirect2. struct xrt_matrix_4x4 mv_inverse[RENDER_MAX_LAYERS]; diff --git a/src/xrt/compositor/shaders/layer.comp b/src/xrt/compositor/shaders/layer.comp index acdb9c8ff..ead30cac4 100644 --- a/src/xrt/compositor/shaders/layer.comp +++ b/src/xrt/compositor/shaders/layer.comp @@ -11,6 +11,27 @@ #include "layer_defines.inc.glsl" +struct layer_data +{ + uint layer_type; + uint unpremultiplied_alpha; + + // This struct is used in an array, gets padded to vec4. + uint _padding0; + uint _padding1; +}; + +struct image_info +{ + uint color_image_index; + uint depth_image_index; + + // This struct is used in an array, gets padded to vec4. + uint _padding0; + uint _padding1; +}; + + const float PI = acos(-1); // Should we do timewarp. @@ -34,11 +55,11 @@ layout(set = 0, binding = 3, std140) uniform restrict Config vec4 pre_transform; vec4 post_transform[RENDER_MAX_LAYERS]; - // corresponds to enum xrt_layer_type - uvec2 layer_type_and_unpremultiplied[RENDER_MAX_LAYERS]; + // Per-layer data. + layer_data layer_data[RENDER_MAX_LAYERS]; // which image/sampler(s) correspond to each layer - ivec2 images_samplers[RENDER_MAX_LAYERS]; + image_info image_info[RENDER_MAX_LAYERS]; // shared between cylinder and equirect2 mat4 mv_inverse[RENDER_MAX_LAYERS]; @@ -220,7 +241,7 @@ vec4 do_cylinder(vec2 view_uv, uint layer) vec2 uv_sub = fma(sample_point, ubo.post_transform[layer].zw, ubo.post_transform[layer].xy); - uint index = ubo.images_samplers[layer].x; + uint index = ubo.image_info[layer].color_image_index; #ifdef DEBUG out_color += texture(source[index], uv_sub) / 2.f; #else @@ -319,7 +340,7 @@ vec4 do_equirect2(vec2 view_uv, uint layer) vec2 uv_sub = fma(sample_point, ubo.post_transform[layer].zw, ubo.post_transform[layer].xy); - uint index = ubo.images_samplers[layer].x; + uint index = ubo.image_info[layer].color_image_index; #ifdef DEBUG out_color += texture(source[index], uv_sub) / 2.0; #else @@ -335,7 +356,7 @@ vec4 do_equirect2(vec2 view_uv, uint layer) vec4 do_projection(vec2 view_uv, uint layer) { - uint source_image_index = ubo.images_samplers[layer].x; + uint source_image_index = ubo.image_info[layer].color_image_index; // Do any transformation needed. vec2 uv = transform_uv(view_uv, layer); @@ -367,7 +388,7 @@ vec3 get_direction(vec2 uv) vec4 do_quad(vec2 view_uv, uint layer) { - uint source_image_index = ubo.images_samplers[layer].x; + uint source_image_index = ubo.image_info[layer].color_image_index; // center point of the plane in view space. vec3 quad_position = ubo.quad_position[layer].xyz; @@ -453,7 +474,7 @@ vec4 do_layers(vec2 view_uv) for (uint layer = 0; layer < layer_count; layer++) { vec4 rgba = vec4(0, 0, 0, 0); - switch (ubo.layer_type_and_unpremultiplied[layer].x) { + switch (ubo.layer_data[layer].layer_type) { case LAYER_COMP_TYPE_QUAD: rgba = do_quad(view_uv, layer); break; @@ -469,7 +490,7 @@ vec4 do_layers(vec2 view_uv) default: break; } - if (ubo.layer_type_and_unpremultiplied[layer].y != 0) { + if (ubo.layer_data[layer].unpremultiplied_alpha != 0) { // Unpremultipled blend factor of src.a. accum.rgb = mix(accum.rgb, rgba.rgb, rgba.a); } else { diff --git a/src/xrt/compositor/util/comp_render_cs.c b/src/xrt/compositor/util/comp_render_cs.c index 6b8ed8b30..a0cc735a1 100644 --- a/src/xrt/compositor/util/comp_render_cs.c +++ b/src/xrt/compositor/util/comp_render_cs.c @@ -136,7 +136,7 @@ do_cs_cylinder_layer(const struct comp_layer *layer, ubo_data->cylinder_data[cur_layer].central_angle = c->central_angle; ubo_data->cylinder_data[cur_layer].aspect_ratio = c->aspect_ratio; - ubo_data->images_samplers[cur_layer].images[0] = cur_image; + ubo_data->image_info[cur_layer].color_image_index = cur_image; cur_image++; *out_cur_image = cur_image; @@ -199,7 +199,7 @@ do_cs_equirect2_layer(const struct comp_layer *layer, ubo_data->eq2_data[cur_layer].upper_vertical_angle = eq2->upper_vertical_angle; ubo_data->eq2_data[cur_layer].lower_vertical_angle = eq2->lower_vertical_angle; - ubo_data->images_samplers[cur_layer].images[0] = cur_image; + ubo_data->image_info[cur_layer].color_image_index = cur_image; cur_image++; *out_cur_image = cur_image; @@ -237,7 +237,7 @@ do_cs_projection_layer(const struct comp_layer *layer, // Color src_samplers[cur_image] = clamp_to_border_black; 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++; + ubo_data->image_info[cur_layer + 0].color_image_index = cur_image++; // Depth if (layer_data->type == XRT_LAYER_PROJECTION_DEPTH) { @@ -247,7 +247,7 @@ do_cs_projection_layer(const struct comp_layer *layer, src_samplers[cur_image] = clamp_to_edge; // Edge to keep depth stable at edges. 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++; + ubo_data->image_info[cur_layer + 0].depth_image_index = cur_image++; } set_post_transform_rect( // @@ -346,7 +346,7 @@ do_cs_quad_layer(const struct comp_layer *layer, 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; - ubo_data->images_samplers[cur_layer].images[0] = cur_image; + ubo_data->image_info[cur_layer].color_image_index = cur_image; cur_image++; *out_cur_image = cur_image; @@ -683,8 +683,8 @@ comp_render_cs_layer(struct render_compute *render, continue; } - ubo_data->layer_type[cur_layer].val = xrt_layer_to_cs_layer_type(data); - ubo_data->layer_type[cur_layer].unpremultiplied = is_layer_unpremultiplied(data); + ubo_data->layer_data[cur_layer].layer_type = xrt_layer_to_cs_layer_type(data); + ubo_data->layer_data[cur_layer].unpremultiplied_alpha = is_layer_unpremultiplied(data); // Finally okay to increment the current layer. cur_layer++; @@ -694,7 +694,7 @@ comp_render_cs_layer(struct render_compute *render, ubo_data->layer_count.value = cur_layer; for (uint32_t i = cur_layer; i < RENDER_MAX_LAYERS; i++) { - ubo_data->layer_type[i].val = LAYER_COMP_TYPE_NOOP; // Explicit no-op. + ubo_data->layer_data[i].layer_type = LAYER_COMP_TYPE_NOOP; // Explicit no-op. } //! @todo: If Vulkan 1.2, use VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT and skip this