mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-03-03 05:06:31 +00:00
comp/renderer: Render subimage properties in layer shader.
This patch passes the offset and extent properties to the layer shader by extending the uniform. The fragment shader stage now also receives the transformation uniform, which contains a has_sub boolean to distinguish if the properties are set, so between projection and quad layers. To avoid color bleeding the subimage sampling happens on a global pixel coordinates basis as ivec2 using the GLSL texelFetch function. Projection layers will be sampled as before.
This commit is contained in:
parent
1e45e56746
commit
a27164ab43
src/xrt/compositor
|
@ -15,6 +15,9 @@
|
|||
struct layer_transformation
|
||||
{
|
||||
struct xrt_matrix_4x4 mvp;
|
||||
struct xrt_offset offset;
|
||||
struct xrt_size extent;
|
||||
bool has_sub;
|
||||
bool flip_y;
|
||||
};
|
||||
|
||||
|
|
|
@ -94,7 +94,8 @@ _init_descriptor_layout(struct comp_layer_renderer *self)
|
|||
.binding = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
||||
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
|
||||
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT |
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
},
|
||||
// quad texture
|
||||
{
|
||||
|
|
|
@ -501,12 +501,20 @@ comp_renderer_set_quad_layer(struct comp_renderer *r,
|
|||
|
||||
comp_layer_set_flip_y(r->lr->layers[layer], data->flip_y);
|
||||
|
||||
r->lr->layers[layer]->type = XRT_LAYER_QUAD;
|
||||
r->lr->layers[layer]->visibility = data->quad.visibility;
|
||||
r->lr->layers[layer]->flags = data->flags;
|
||||
r->lr->layers[layer]->view_space =
|
||||
|
||||
struct comp_render_layer *l = r->lr->layers[layer];
|
||||
l->type = XRT_LAYER_QUAD;
|
||||
l->visibility = data->quad.visibility;
|
||||
l->flags = data->flags;
|
||||
l->view_space =
|
||||
(data->flags & XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT) != 0;
|
||||
|
||||
for (uint32_t i = 0; i < 2; i++) {
|
||||
l->transformation[i].offset = data->quad.sub.rect.offset;
|
||||
l->transformation[i].extent = data->quad.sub.rect.extent;
|
||||
l->transformation[i].has_sub = true;
|
||||
}
|
||||
|
||||
r->c->vk.vkDeviceWaitIdle(r->c->vk.device);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,13 +6,24 @@
|
|||
|
||||
layout (location = 0) in vec2 uv;
|
||||
|
||||
layout (binding = 0, std140) uniform Transformation {
|
||||
mat4 mvp;
|
||||
ivec2 offset;
|
||||
ivec2 extent;
|
||||
bool has_sub;
|
||||
bool flip_y;
|
||||
} ubo;
|
||||
layout (binding = 1) uniform sampler2D image;
|
||||
|
||||
layout (location = 0) out vec4 out_color;
|
||||
|
||||
void main ()
|
||||
{
|
||||
vec4 texture_color = texture (image, uv);
|
||||
out_color = texture_color;
|
||||
if (ubo.has_sub) {
|
||||
ivec2 uv_sub = ubo.offset + ivec2(uv * ubo.extent);
|
||||
out_color = texelFetch(image, uv_sub, 0);
|
||||
} else {
|
||||
out_color = texture(image, uv);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,11 @@
|
|||
|
||||
#version 460
|
||||
|
||||
layout (binding = 0) uniform Transformation {
|
||||
layout (binding = 0, std140) uniform Transformation {
|
||||
mat4 mvp;
|
||||
ivec2 offset;
|
||||
ivec2 extent;
|
||||
bool has_sub;
|
||||
bool flip_y;
|
||||
} transformation;
|
||||
|
||||
|
|
Loading…
Reference in a new issue