vulkan: Update the cross-fade shader
authorBenjamin Otte <otte@redhat.com>
Sat, 20 May 2023 23:28:36 +0000 (01:28 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 4 Jun 2023 17:42:01 +0000 (19:42 +0200)
This also fixes it rendering weird things when the bounds of start and
end node don't match.

gsk/vulkan/gskvulkancrossfadepipeline.c
gsk/vulkan/gskvulkancrossfadepipelineprivate.h
gsk/vulkan/gskvulkanrenderpass.c
gsk/vulkan/resources/crossfade.frag
gsk/vulkan/resources/crossfade.vert

index 9763aa762f27260bfd25eac84539993fcc12b21a..514b6886d5bb5800f17e6602db1f570898486dc0 100644 (file)
@@ -12,10 +12,12 @@ typedef struct _GskVulkanCrossFadeInstance GskVulkanCrossFadeInstance;
 struct _GskVulkanCrossFadeInstance
 {
   float rect[4];
+  float start_rect[4];
+  float end_rect[4];
   float start_tex_rect[4];
   float end_tex_rect[4];
-  float start_tex_id;
-  float end_tex_id;
+  guint32 start_tex_id;
+  guint32 end_tex_id;
   float progress;
 };
 
@@ -42,28 +44,40 @@ gsk_vulkan_cross_fade_pipeline_get_input_state_create_info (GskVulkanPipeline *s
           .location = 1,
           .binding = 0,
           .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, start_tex_rect),
+          .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, start_rect),
       },
       {
           .location = 2,
           .binding = 0,
           .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, end_tex_rect),
+          .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, end_rect),
       },
       {
           .location = 3,
           .binding = 0,
+          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+          .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, start_tex_rect),
+      },
+      {
+          .location = 4,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+          .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, end_tex_rect),
+      },
+      {
+          .location = 5,
+          .binding = 0,
           .format = VK_FORMAT_R32_UINT,
           .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, start_tex_id),
       },
       {
-          .location = 4,
+          .location = 6,
           .binding = 0,
           .format = VK_FORMAT_R32_UINT,
           .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, end_tex_id),
       },
       {
-          .location = 5,
+          .location = 7,
           .binding = 0,
           .format = VK_FORMAT_R32_SFLOAT,
           .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, progress),
@@ -119,6 +133,8 @@ gsk_vulkan_cross_fade_pipeline_collect_vertex_data (GskVulkanCrossFadePipeline *
                                                     guint32                     end_tex_id,
                                                     const graphene_point_t     *offset,
                                                     const graphene_rect_t      *bounds,
+                                                    const graphene_rect_t      *start_bounds,
+                                                    const graphene_rect_t      *end_bounds,
                                                     const graphene_rect_t      *start_tex_rect,
                                                     const graphene_rect_t      *end_tex_rect,
                                                     double                      progress)
@@ -130,6 +146,16 @@ gsk_vulkan_cross_fade_pipeline_collect_vertex_data (GskVulkanCrossFadePipeline *
   instance->rect[2] = bounds->size.width;
   instance->rect[3] = bounds->size.height;
 
+  instance->start_rect[0] = start_bounds->origin.x + offset->x;
+  instance->start_rect[1] = start_bounds->origin.y + offset->y;
+  instance->start_rect[2] = start_bounds->size.width;
+  instance->start_rect[3] = start_bounds->size.height;
+
+  instance->end_rect[0] = end_bounds->origin.x + offset->x;
+  instance->end_rect[1] = end_bounds->origin.y + offset->y;
+  instance->end_rect[2] = end_bounds->size.width;
+  instance->end_rect[3] = end_bounds->size.height;
+
   instance->start_tex_rect[0] = start_tex_rect->origin.x;
   instance->start_tex_rect[1] = start_tex_rect->origin.y;
   instance->start_tex_rect[2] = start_tex_rect->size.width;
index f4249318cc44868652def5a3961521f7f7ac72db..858e6dcad49d3b87fa00e34bc560d0d7bc4d70de 100644 (file)
@@ -25,6 +25,8 @@ void                gsk_vulkan_cross_fade_pipeline_collect_vertex_data (GskVulka
                                                                         const graphene_rect_t      *bounds,
                                                                         const graphene_rect_t      *start_bounds,
                                                                         const graphene_rect_t      *end_bounds,
+                                                                        const graphene_rect_t      *start_tex_rect,
+                                                                        const graphene_rect_t      *end_tex_rect,
                                                                         double                      progress);
 gsize               gsk_vulkan_cross_fade_pipeline_draw                (GskVulkanCrossFadePipeline *pipeline,
                                                                         VkCommandBuffer             command_buffer,
index 975dc0cbff0d4f2aa5e01cfbe3ee35d44a68fac2..2c43de901514c9b397dda0b95d416fd71f6e9657 100644 (file)
@@ -1956,6 +1956,8 @@ gsk_vulkan_render_pass_collect_vertex_data (GskVulkanRenderPass *self,
                                                               op->render.descriptor_set_index2,
                                                               &op->render.offset,
                                                               &op->render.node->bounds,
+                                                              &gsk_cross_fade_node_get_start_child (op->render.node)->bounds,
+                                                              &gsk_cross_fade_node_get_end_child (op->render.node)->bounds,
                                                               &op->render.source_rect,
                                                               &op->render.source2_rect,
                                                               gsk_cross_fade_node_get_progress (op->render.node));
index 413663734658ea84c74e5abc3e36bbbd8b3c8a20..0b571c45e0b525f25d55b0b65e7d673bbcee3a0e 100644 (file)
@@ -2,20 +2,25 @@
 
 #include "common.frag.glsl"
 #include "clip.frag.glsl"
+#include "rect.frag.glsl"
 
 layout(location = 0) in vec2 inPos;
-layout(location = 1) in vec2 inStartTexCoord;
-layout(location = 2) in vec2 inEndTexCoord;
-layout(location = 3) flat in uint inStartTexId;
-layout(location = 4) flat in uint inEndTexId;
-layout(location = 5) in float inProgress;
+layout(location = 1) in Rect inStartRect;
+layout(location = 2) in Rect inEndRect;
+layout(location = 3) in vec2 inStartTexCoord;
+layout(location = 4) in vec2 inEndTexCoord;
+layout(location = 5) flat in uint inStartTexId;
+layout(location = 6) flat in uint inEndTexId;
+layout(location = 7) in float inProgress;
 
 layout(location = 0) out vec4 color;
 
 void main()
 {
-  vec4 start = texture (textures[inStartTexId], inStartTexCoord);
-  vec4 end = texture (textures[inEndTexId], inEndTexCoord);
+  float start_alpha = rect_coverage (inStartRect, inPos);
+  vec4 start = texture (textures[inStartTexId], inStartTexCoord) * start_alpha;
+  float end_alpha = rect_coverage (inEndRect, inPos);
+  vec4 end = texture (textures[inEndTexId], inEndTexCoord) * end_alpha;
 
-  color = clip (inPos, mix (start, end, inProgress));
+  color = clip_scaled (inPos, mix (start, end, inProgress));
 }
index ff3e73b6dfe2945e4511ccb173d473c7b62c49bd..a670fcef101275596ebf684e56a021b5933d79b4 100644 (file)
@@ -1,44 +1,35 @@
 #version 420 core
 
-#include "clip.vert.glsl"
+#include "common.vert.glsl"
+#include "rect.vert.glsl"
 
 layout(location = 0) in vec4 inRect;
-layout(location = 1) in vec4 inStartTexRect;
-layout(location = 2) in vec4 inEndTexRect;
-layout(location = 3) in uint inStartTexId;
-layout(location = 4) in uint inEndTexId;
-layout(location = 5) in float inProgress;
+layout(location = 1) in vec4 inStartRect;
+layout(location = 2) in vec4 inEndRect;
+layout(location = 3) in vec4 inStartTexRect;
+layout(location = 4) in vec4 inEndTexRect;
+layout(location = 5) in uint inStartTexId;
+layout(location = 6) in uint inEndTexId;
+layout(location = 7) in float inProgress;
 
 layout(location = 0) out vec2 outPos;
-layout(location = 1) out vec2 outStartTexCoord;
-layout(location = 2) out vec2 outEndTexCoord;
-layout(location = 3) flat out uint outStartTexId;
-layout(location = 4) flat out uint outEndTexId;
-layout(location = 5) flat out float outProgress;
-
-vec2 offsets[6] = { vec2(0.0, 0.0),
-                    vec2(1.0, 0.0),
-                    vec2(0.0, 1.0),
-                    vec2(0.0, 1.0),
-                    vec2(1.0, 0.0),
-                    vec2(1.0, 1.0) };
+layout(location = 1) flat out Rect outStartRect;
+layout(location = 2) flat out Rect outEndRect;
+layout(location = 3) out vec2 outStartTexCoord;
+layout(location = 4) out vec2 outEndTexCoord;
+layout(location = 5) flat out uint outStartTexId;
+layout(location = 6) flat out uint outEndTexId;
+layout(location = 7) flat out float outProgress;
 
 void main() {
-  vec4 rect = clip (inRect);
-  vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
-  gl_Position = push.mvp * vec4 (push.scale * pos, 0.0, 1.0);
+  Rect r = rect_from_gsk (inRect);
+  vec2 pos = set_position_from_rect (r);
 
   outPos = pos;
-
-  vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
-                      rect.zw / inRect.zw);
-  vec4 starttexrect = vec4(inStartTexRect.xy + inStartTexRect.zw * texrect.xy,
-                           inStartTexRect.zw * texrect.zw);
-  vec4 endtexrect = vec4(inEndTexRect.xy + inEndTexRect.zw * texrect.xy,
-                         inEndTexRect.zw * texrect.zw);
-
-  outStartTexCoord = starttexrect.xy + starttexrect.zw * offsets[gl_VertexIndex];
-  outEndTexCoord = endtexrect.xy + endtexrect.zw * offsets[gl_VertexIndex];
+  outStartRect = rect_from_gsk (inStartRect);
+  outEndRect = rect_from_gsk (inEndRect);
+  outStartTexCoord = scale_tex_coord (pos, r, inStartTexRect);
+  outEndTexCoord = scale_tex_coord (pos, r, inEndTexRect);
   outStartTexId = inStartTexId;
   outEndTexId = inEndTexId;
   outProgress = inProgress;