mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 04:36:07 +00:00
c/render: Optimize layer shader
This commit is contained in:
parent
bd38e90b51
commit
141e598295
|
@ -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];
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue