diff --git a/src/xrt/compositor/render/render_interface.h b/src/xrt/compositor/render/render_interface.h index b21a4b014..51d6b902b 100644 --- a/src/xrt/compositor/render/render_interface.h +++ b/src/xrt/compositor/render/render_interface.h @@ -800,6 +800,12 @@ struct render_compute_layer_ubo_data { struct render_viewport_data view; + struct + { + uint32_t value; + uint32_t padding[3]; + } layer_count; + struct xrt_normalized_rect pre_transform; struct xrt_normalized_rect post_transforms[RENDER_MAX_LAYERS]; diff --git a/src/xrt/compositor/shaders/layer.comp b/src/xrt/compositor/shaders/layer.comp index 3e2410067..a49a171e0 100644 --- a/src/xrt/compositor/shaders/layer.comp +++ b/src/xrt/compositor/shaders/layer.comp @@ -31,6 +31,7 @@ layout(set = 0, binding = 2) uniform writeonly restrict image2D target; layout(set = 0, binding = 3, std140) uniform restrict Config { ivec4 view; + ivec4 layer_count; vec4 pre_transform; vec4 post_transform[RENDER_MAX_LAYERS]; @@ -232,33 +233,30 @@ vec4 do_quad(vec2 view_uv, uint layer) vec4 do_layers(vec2 view_uv) { vec4 accum = vec4(0, 0, 0, 0); - for (uint layer = 0; layer < RENDER_MAX_LAYERS; layer++) { - bool use_layer = false; + int layer_count = ubo.layer_count.x; + for (uint layer = 0; layer < layer_count; layer++) { vec4 rgba = vec4(0, 0, 0, 0); + switch (ubo.layer_type_and_unpremultiplied[layer].x) { case XRT_LAYER_STEREO_PROJECTION: case XRT_LAYER_STEREO_PROJECTION_DEPTH: rgba = do_projection(view_uv, layer); - use_layer = true; break; case XRT_LAYER_QUAD: rgba = do_quad(view_uv, layer); - use_layer = true; break; default: break; } - if (use_layer) { - if (ubo.layer_type_and_unpremultiplied[layer].y != 0) { - // Unpremultipled blend factor of src.a. - accum.rgb = mix(accum.rgb, rgba.rgb, rgba.a); - } else { - // Premultiplied blend factor of 1. - accum.rgb = (accum.rgb * (1 - rgba.a)) + rgba.rgb; - } - accum.a = rgba.a + accum.a * (1.0 - rgba.a); + if (ubo.layer_type_and_unpremultiplied[layer].y != 0) { + // Unpremultipled blend factor of src.a. + accum.rgb = mix(accum.rgb, rgba.rgb, rgba.a); + } else { + // Premultiplied blend factor of 1. + accum.rgb = (accum.rgb * (1 - rgba.a)) + rgba.rgb; } + accum.a = rgba.a + accum.a * (1.0 - rgba.a); } return accum; diff --git a/src/xrt/compositor/util/comp_render.c b/src/xrt/compositor/util/comp_render.c index 3b9f6b156..f77df0d21 100644 --- a/src/xrt/compositor/util/comp_render.c +++ b/src/xrt/compositor/util/comp_render.c @@ -514,6 +514,9 @@ comp_render_layer(struct render_compute *crc, cur_layer++; } + // Set the number of layers. + ubo_data->layer_count.value = cur_layer; + for (uint32_t i = cur_layer; i < RENDER_MAX_LAYERS; i++) { ubo_data->layer_type[i].val = UINT32_MAX; }