[gtk+/wip/matthiasc/text-node] wip: add a mask shader



commit fca1a9244eecda1b6df09e098dc6ff66b866352a
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Sep 9 12:15:38 2017 -0400

    wip: add a mask shader
    
    It doesn't work yet.

 gsk/gskrendernodeimpl.c                         |   24 ++++-
 gsk/gskrendernodeprivate.h                      |    2 +
 gsk/gskvulkanmaskpipeline.c                     |  132 +++++++++++++++++++++++
 gsk/gskvulkanmaskpipelineprivate.h              |   32 ++++++
 gsk/gskvulkanrender.c                           |    4 +
 gsk/gskvulkanrenderpass.c                       |   80 ++++++++++++--
 gsk/gskvulkanrenderprivate.h                    |    3 +
 gsk/meson.build                                 |    1 +
 gsk/resources/vulkan/mask-clip-rounded.frag.spv |  Bin 0 -> 8392 bytes
 gsk/resources/vulkan/mask-clip-rounded.vert.spv |  Bin 0 -> 5016 bytes
 gsk/resources/vulkan/mask-clip.frag.spv         |  Bin 0 -> 1484 bytes
 gsk/resources/vulkan/mask-clip.vert.spv         |  Bin 0 -> 5016 bytes
 gsk/resources/vulkan/mask.frag                  |   16 +++
 gsk/resources/vulkan/mask.frag.spv              |  Bin 0 -> 1484 bytes
 gsk/resources/vulkan/mask.vert                  |   38 +++++++
 gsk/resources/vulkan/mask.vert.spv              |  Bin 0 -> 3284 bytes
 gsk/resources/vulkan/meson.build                |    2 +
 17 files changed, 322 insertions(+), 12 deletions(-)
---
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 2474468..6174b2a 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -3814,8 +3814,8 @@ struct _GskTextNode
   PangoGlyphString *glyphs;
   cairo_surface_t *surface;
 
-  gboolean has_color;
   GdkRGBA color;
+  gboolean has_color;
   double x;
   double y;
   double ink_rect_y;
@@ -4107,7 +4107,6 @@ gsk_text_node_new (PangoFont        *font,
 {
   GskTextNode *self;
   PangoRectangle ink_rect;
-  cairo_t *cr;
 
   pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
   pango_extents_to_pixels (&ink_rect, NULL);
@@ -4124,7 +4123,6 @@ gsk_text_node_new (PangoFont        *font,
   self->y = y;
   self->ink_rect_y = ink_rect.y;
   self->ink_rect_height = ink_rect.height;
-
   self->has_color = font_has_color_glyphs (font);
 
   graphene_rect_init (&self->render_node.bounds,
@@ -4136,7 +4134,9 @@ gsk_text_node_new (PangoFont        *font,
   self->surface = find_cached_surface (font, glyphs);
   if (!self->surface)
     {
-      self->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, //self->has_color ? 
CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_A8,
+      cairo_t *cr;
+
+      self->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                                                   ink_rect.x + ink_rect.width,
                                                   ink_rect.height);
       cr = cairo_create (self->surface);
@@ -4157,6 +4157,22 @@ gsk_text_node_get_surface (GskRenderNode *node)
   return self->surface;
 }
 
+gboolean
+gsk_text_node_get_has_color (GskRenderNode *node)
+{
+  GskTextNode *self = (GskTextNode *) node;
+
+  return self->has_color;
+}
+
+const GdkRGBA *
+gsk_text_node_get_color (GskRenderNode *node)
+{
+  GskTextNode *self = (GskTextNode *) node;
+
+  return &self->color;
+}
+
 /*** GSK_BLUR_NODE ***/
 
 typedef struct _GskBlurNode GskBlurNode;
diff --git a/gsk/gskrendernodeprivate.h b/gsk/gskrendernodeprivate.h
index a0b0429..f2fd507 100644
--- a/gsk/gskrendernodeprivate.h
+++ b/gsk/gskrendernodeprivate.h
@@ -82,6 +82,8 @@ cairo_surface_t *gsk_cairo_node_get_surface (GskRenderNode *node);
 GskTexture *gsk_texture_node_get_texture (GskRenderNode *node);
 
 cairo_surface_t *gsk_text_node_get_surface (GskRenderNode *node);
+gboolean gsk_text_node_get_has_color (GskRenderNode *node);
+const GdkRGBA *gsk_text_node_get_color (GskRenderNode *node);
 
 const GdkRGBA *gsk_color_node_peek_color (GskRenderNode *node);
 
diff --git a/gsk/gskvulkanmaskpipeline.c b/gsk/gskvulkanmaskpipeline.c
new file mode 100644
index 0000000..8272aa5
--- /dev/null
+++ b/gsk/gskvulkanmaskpipeline.c
@@ -0,0 +1,132 @@
+#include "config.h"
+
+#include "gskvulkanmaskpipelineprivate.h"
+
+struct _GskVulkanMaskPipeline
+{
+  GObject parent_instance;
+};
+
+typedef struct _GskVulkanMaskInstance GskVulkanMaskInstance;
+
+struct _GskVulkanMaskInstance
+{
+  float rect[4];
+  float tex_rect[4];
+  float color[4];
+};
+
+G_DEFINE_TYPE (GskVulkanMaskPipeline, gsk_vulkan_mask_pipeline, GSK_TYPE_VULKAN_PIPELINE)
+
+static const VkPipelineVertexInputStateCreateInfo *
+gsk_vulkan_mask_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
+{
+  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
+      {
+          .binding = 0,
+          .stride = sizeof (GskVulkanMaskInstance),
+          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
+      }
+  };
+  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
+      {
+          .location = 0,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+          .offset = G_STRUCT_OFFSET (GskVulkanMaskInstance, rect),
+      },
+      {
+          .location = 1,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+          .offset = G_STRUCT_OFFSET (GskVulkanMaskInstance, tex_rect),
+      },
+      {
+          .location = 2,
+          .binding = 0,
+          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+          .offset = G_STRUCT_OFFSET (GskVulkanMaskInstance, color),
+      }
+  };
+  static const VkPipelineVertexInputStateCreateInfo info = {
+      .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
+      .vertexBindingDescriptionCount = G_N_ELEMENTS (vertexBindingDescriptions),
+      .pVertexBindingDescriptions = vertexBindingDescriptions,
+      .vertexAttributeDescriptionCount = G_N_ELEMENTS (vertexInputAttributeDescription),
+      .pVertexAttributeDescriptions = vertexInputAttributeDescription
+  };
+
+  return &info;
+}
+
+static void
+gsk_vulkan_mask_pipeline_finalize (GObject *gobject)
+{
+  //GskVulkanMaskPipeline *self = GSK_VULKAN_MASK_PIPELINE (gobject);
+
+  G_OBJECT_CLASS (gsk_vulkan_mask_pipeline_parent_class)->finalize (gobject);
+}
+
+static void
+gsk_vulkan_mask_pipeline_class_init (GskVulkanMaskPipelineClass *klass)
+{
+  GskVulkanPipelineClass *pipeline_class = GSK_VULKAN_PIPELINE_CLASS (klass);
+
+  G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_mask_pipeline_finalize;
+
+  pipeline_class->get_input_state_create_info = gsk_vulkan_mask_pipeline_get_input_state_create_info;
+}
+
+static void
+gsk_vulkan_mask_pipeline_init (GskVulkanMaskPipeline *self)
+{
+}
+
+GskVulkanPipeline *
+gsk_vulkan_mask_pipeline_new (GskVulkanPipelineLayout *layout,
+                               const char              *shader_name,
+                               VkRenderPass             render_pass)
+{
+  return gsk_vulkan_pipeline_new (GSK_TYPE_VULKAN_MASK_PIPELINE, layout, shader_name, render_pass);
+}
+
+gsize
+gsk_vulkan_mask_pipeline_count_vertex_data (GskVulkanMaskPipeline *pipeline)
+{
+  return sizeof (GskVulkanMaskInstance);
+}
+
+void
+gsk_vulkan_mask_pipeline_collect_vertex_data (GskVulkanMaskPipeline *pipeline,
+                                               guchar                 *data,
+                                               const graphene_rect_t  *rect,
+                                               const GdkRGBA          *color)
+{
+  GskVulkanMaskInstance *instance = (GskVulkanMaskInstance *) data;
+
+  instance->rect[0] = rect->origin.x;
+  instance->rect[1] = rect->origin.y;
+  instance->rect[2] = rect->size.width;
+  instance->rect[3] = rect->size.height;
+  instance->tex_rect[0] = 0.0;
+  instance->tex_rect[1] = 0.0;
+  instance->tex_rect[2] = 1.0;
+  instance->tex_rect[3] = 1.0;
+  instance->color[0] = color->red;
+  instance->color[1] = color->green;
+  instance->color[2] = color->blue;
+  instance->color[3] = color->alpha;
+}
+
+gsize
+gsk_vulkan_mask_pipeline_draw (GskVulkanMaskPipeline *pipeline,
+                                VkCommandBuffer         command_buffer,
+                                gsize                   offset,
+                                gsize                   n_commands)
+{
+  vkCmdDraw (command_buffer,
+             6, n_commands,
+             0, offset);
+
+  return n_commands;
+}
diff --git a/gsk/gskvulkanmaskpipelineprivate.h b/gsk/gskvulkanmaskpipelineprivate.h
new file mode 100644
index 0000000..a91c1ca
--- /dev/null
+++ b/gsk/gskvulkanmaskpipelineprivate.h
@@ -0,0 +1,32 @@
+#ifndef __GSK_VULKAN_MASK_PIPELINE_PRIVATE_H__
+#define __GSK_VULKAN_MASK_PIPELINE_PRIVATE_H__
+
+#include <graphene.h>
+
+#include "gskvulkanpipelineprivate.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GskVulkanMaskPipelineLayout GskVulkanMaskPipelineLayout;
+
+#define GSK_TYPE_VULKAN_MASK_PIPELINE (gsk_vulkan_mask_pipeline_get_type ())
+
+G_DECLARE_FINAL_TYPE (GskVulkanMaskPipeline, gsk_vulkan_mask_pipeline, GSK, VULKAN_MASK_PIPELINE, 
GskVulkanPipeline)
+
+GskVulkanPipeline *     gsk_vulkan_mask_pipeline_new                   (GskVulkanPipelineLayout *       
layout,
+                                                                        const char                     
*shader_name,
+                                                                        VkRenderPass                    
render_pass);
+
+gsize                   gsk_vulkan_mask_pipeline_count_vertex_data     (GskVulkanMaskPipeline         
*pipeline);
+void                    gsk_vulkan_mask_pipeline_collect_vertex_data   (GskVulkanMaskPipeline         
*pipeline,
+                                                                        guchar                         *data,
+                                                                        const graphene_rect_t          *rect,
+                                                                        const GdkRGBA                  
*color);
+gsize                   gsk_vulkan_mask_pipeline_draw                  (GskVulkanMaskPipeline         
*pipeline,
+                                                                        VkCommandBuffer                 
command_buffer,
+                                                                        gsize                           
offset,
+                                                                        gsize                           
n_commands);
+
+G_END_DECLS
+
+#endif /* __GSK_VULKAN_MASK_PIPELINE_PRIVATE_H__ */
diff --git a/gsk/gskvulkanrender.c b/gsk/gskvulkanrender.c
index 4da8e48..0c63f38 100644
--- a/gsk/gskvulkanrender.c
+++ b/gsk/gskvulkanrender.c
@@ -17,6 +17,7 @@
 #include "gskvulkancolorpipelineprivate.h"
 #include "gskvulkaneffectpipelineprivate.h"
 #include "gskvulkanlineargradientpipelineprivate.h"
+#include "gskvulkanmaskpipelineprivate.h"
 
 #define ORTHO_NEAR_PLANE        -10000
 #define ORTHO_FAR_PLANE          10000
@@ -344,6 +345,9 @@ gsk_vulkan_render_get_pipeline (GskVulkanRender       *self,
     { "blur", gsk_vulkan_blur_pipeline_new },
     { "blur-clip", gsk_vulkan_blur_pipeline_new },
     { "blur-clip-rounded", gsk_vulkan_blur_pipeline_new },
+    { "mask", gsk_vulkan_mask_pipeline_new },
+    { "mask-clip", gsk_vulkan_mask_pipeline_new },
+    { "mask-clip-rounded", gsk_vulkan_mask_pipeline_new },
   };
 
   g_return_val_if_fail (type < GSK_VULKAN_N_PIPELINES, NULL);
diff --git a/gsk/gskvulkanrenderpass.c b/gsk/gskvulkanrenderpass.c
index 1308c3a..267c3b5 100644
--- a/gsk/gskvulkanrenderpass.c
+++ b/gsk/gskvulkanrenderpass.c
@@ -14,6 +14,7 @@
 #include "gskvulkancolorpipelineprivate.h"
 #include "gskvulkaneffectpipelineprivate.h"
 #include "gskvulkanlineargradientpipelineprivate.h"
+#include "gskvulkanmaskpipelineprivate.h"
 #include "gskvulkanimageprivate.h"
 #include "gskvulkanpushconstantsprivate.h"
 #include "gskvulkanrendererprivate.h"
@@ -28,6 +29,7 @@ typedef enum {
   GSK_VULKAN_OP_FALLBACK_CLIP,
   GSK_VULKAN_OP_FALLBACK_ROUNDED_CLIP,
   GSK_VULKAN_OP_SURFACE,
+  GSK_VULKAN_OP_SURFACE_MASK,
   GSK_VULKAN_OP_TEXTURE,
   GSK_VULKAN_OP_COLOR,
   GSK_VULKAN_OP_LINEAR_GRADIENT,
@@ -175,15 +177,30 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass           *self,
     case GSK_TEXT_NODE:
       if (gsk_text_node_get_surface (node) == NULL)
         return;
-      if (gsk_vulkan_clip_contains_rect (&constants->clip, &node->bounds))
-        pipeline_type = GSK_VULKAN_PIPELINE_BLEND;
-      else if (constants->clip.type == GSK_VULKAN_CLIP_RECT)
-        pipeline_type = GSK_VULKAN_PIPELINE_BLEND_CLIP;
-      else if (constants->clip.type == GSK_VULKAN_CLIP_ROUNDED_CIRCULAR)
-        pipeline_type = GSK_VULKAN_PIPELINE_BLEND_CLIP_ROUNDED;
+      if (gsk_text_node_get_has_color (node))
+        {
+          if (gsk_vulkan_clip_contains_rect (&constants->clip, &node->bounds))
+            pipeline_type = GSK_VULKAN_PIPELINE_BLEND;
+          else if (constants->clip.type == GSK_VULKAN_CLIP_RECT)
+            pipeline_type = GSK_VULKAN_PIPELINE_BLEND_CLIP;
+          else if (constants->clip.type == GSK_VULKAN_CLIP_ROUNDED_CIRCULAR)
+            pipeline_type = GSK_VULKAN_PIPELINE_BLEND_CLIP_ROUNDED;
+          else
+            FALLBACK ("Text nodes can't deal with clip type %u\n", constants->clip.type);
+          op.type = GSK_VULKAN_OP_SURFACE;
+        }
       else
-        FALLBACK ("Cairo nodes can't deal with clip type %u\n", constants->clip.type);
-      op.type = GSK_VULKAN_OP_SURFACE;
+        {
+          if (gsk_vulkan_clip_contains_rect (&constants->clip, &node->bounds))
+            pipeline_type = GSK_VULKAN_PIPELINE_MASK;
+          else if (constants->clip.type == GSK_VULKAN_CLIP_RECT)
+            pipeline_type = GSK_VULKAN_PIPELINE_MASK_CLIP;
+          else if (constants->clip.type == GSK_VULKAN_CLIP_ROUNDED_CIRCULAR)
+            pipeline_type = GSK_VULKAN_PIPELINE_MASK_CLIP_ROUNDED;
+          else
+            FALLBACK ("Text nodes can't deal with clip type %u\n", constants->clip.type);
+          op.type = GSK_VULKAN_OP_SURFACE_MASK;
+        }
       op.render.pipeline = gsk_vulkan_render_get_pipeline (render, pipeline_type);
       g_array_append_val (self->render_ops, op);
       return;
@@ -547,6 +564,7 @@ gsk_vulkan_render_pass_upload (GskVulkanRenderPass  *self,
           break;
 
         case GSK_VULKAN_OP_SURFACE:
+        case GSK_VULKAN_OP_SURFACE_MASK:
           {
             cairo_surface_t *surface;
 
@@ -639,6 +657,7 @@ gsk_vulkan_render_pass_count_vertex_data (GskVulkanRenderPass *self)
         case GSK_VULKAN_OP_FALLBACK_CLIP:
         case GSK_VULKAN_OP_FALLBACK_ROUNDED_CLIP:
         case GSK_VULKAN_OP_SURFACE:
+        case GSK_VULKAN_OP_SURFACE_MASK:
         case GSK_VULKAN_OP_TEXTURE:
           op->render.vertex_count = gsk_vulkan_blend_pipeline_count_vertex_data (GSK_VULKAN_BLEND_PIPELINE 
(op->render.pipeline));
           n_bytes += op->render.vertex_count;
@@ -717,6 +736,17 @@ gsk_vulkan_render_pass_collect_vertex_data (GskVulkanRenderPass *self,
           }
           break;
 
+        case GSK_VULKAN_OP_SURFACE_MASK:
+          {
+            op->render.vertex_offset = offset + n_bytes;
+            gsk_vulkan_mask_pipeline_collect_vertex_data (GSK_VULKAN_MASK_PIPELINE (op->render.pipeline),
+                                                          data + n_bytes + offset,
+                                                          &op->render.node->bounds,
+                                                          gsk_text_node_get_color (op->render.node));
+            n_bytes += op->render.vertex_count;
+          }
+          break;
+
         case GSK_VULKAN_OP_COLOR:
           {
             op->render.vertex_offset = offset + n_bytes;
@@ -859,6 +889,7 @@ gsk_vulkan_render_pass_reserve_descriptor_sets (GskVulkanRenderPass *self,
         case GSK_VULKAN_OP_FALLBACK_CLIP:
         case GSK_VULKAN_OP_FALLBACK_ROUNDED_CLIP:
         case GSK_VULKAN_OP_SURFACE:
+        case GSK_VULKAN_OP_SURFACE_MASK:
         case GSK_VULKAN_OP_TEXTURE:
         case GSK_VULKAN_OP_OPACITY:
         case GSK_VULKAN_OP_BLUR:
@@ -935,6 +966,39 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
                                                                 current_draw_index, 1);
           break;
 
+        case GSK_VULKAN_OP_SURFACE_MASK:
+          if (current_pipeline != op->render.pipeline)
+            {
+              current_pipeline = op->render.pipeline;
+              vkCmdBindPipeline (command_buffer,
+                                 VK_PIPELINE_BIND_POINT_GRAPHICS,
+                                 gsk_vulkan_pipeline_get_pipeline (current_pipeline));
+              vkCmdBindVertexBuffers (command_buffer,
+                                      0,
+                                      1,
+                                      (VkBuffer[1]) {
+                                          gsk_vulkan_buffer_get_buffer (vertex_buffer)
+                                      },
+                                      (VkDeviceSize[1]) { op->render.vertex_offset });
+              current_draw_index = 0;
+            }
+
+          vkCmdBindDescriptorSets (command_buffer,
+                                   VK_PIPELINE_BIND_POINT_GRAPHICS,
+                                   gsk_vulkan_pipeline_layout_get_pipeline_layout (layout),
+                                   0,
+                                   1,
+                                   (VkDescriptorSet[1]) {
+                                       gsk_vulkan_render_get_descriptor_set (render, 
op->render.descriptor_set_index)
+                                   },
+                                   0,
+                                   NULL);
+
+          current_draw_index += gsk_vulkan_mask_pipeline_draw (GSK_VULKAN_MASK_PIPELINE (current_pipeline),
+                                                                command_buffer,
+                                                                current_draw_index, 1);
+          break;
+
         case GSK_VULKAN_OP_OPACITY:
         case GSK_VULKAN_OP_COLOR_MATRIX:
           if (current_pipeline != op->render.pipeline)
diff --git a/gsk/gskvulkanrenderprivate.h b/gsk/gskvulkanrenderprivate.h
index 4c01e82..3b910e2 100644
--- a/gsk/gskvulkanrenderprivate.h
+++ b/gsk/gskvulkanrenderprivate.h
@@ -34,6 +34,9 @@ typedef enum {
   GSK_VULKAN_PIPELINE_BLUR,
   GSK_VULKAN_PIPELINE_BLUR_CLIP,
   GSK_VULKAN_PIPELINE_BLUR_CLIP_ROUNDED,
+  GSK_VULKAN_PIPELINE_MASK,
+  GSK_VULKAN_PIPELINE_MASK_CLIP,
+  GSK_VULKAN_PIPELINE_MASK_CLIP_ROUNDED,
   /* add more */
   GSK_VULKAN_N_PIPELINES
 } GskVulkanPipelineType;
diff --git a/gsk/meson.build b/gsk/meson.build
index 3c1278f..7b74069 100644
--- a/gsk/meson.build
+++ b/gsk/meson.build
@@ -65,6 +65,7 @@ if have_vulkan
     'gskvulkaneffectpipeline.c',
     'gskvulkanlineargradientpipeline.c',
     'gskvulkanimage.c',
+    'gskvulkanmaskpipeline.c',
     'gskvulkanmemory.c',
     'gskvulkanpipeline.c',
     'gskvulkanpushconstants.c',
diff --git a/gsk/resources/vulkan/mask-clip-rounded.frag.spv b/gsk/resources/vulkan/mask-clip-rounded.frag.spv
new file mode 100644
index 0000000..83c9444
Binary files /dev/null and b/gsk/resources/vulkan/mask-clip-rounded.frag.spv differ
diff --git a/gsk/resources/vulkan/mask-clip-rounded.vert.spv b/gsk/resources/vulkan/mask-clip-rounded.vert.spv
new file mode 100644
index 0000000..34156b4
Binary files /dev/null and b/gsk/resources/vulkan/mask-clip-rounded.vert.spv differ
diff --git a/gsk/resources/vulkan/mask-clip.frag.spv b/gsk/resources/vulkan/mask-clip.frag.spv
new file mode 100644
index 0000000..7751f01
Binary files /dev/null and b/gsk/resources/vulkan/mask-clip.frag.spv differ
diff --git a/gsk/resources/vulkan/mask-clip.vert.spv b/gsk/resources/vulkan/mask-clip.vert.spv
new file mode 100644
index 0000000..34156b4
Binary files /dev/null and b/gsk/resources/vulkan/mask-clip.vert.spv differ
diff --git a/gsk/resources/vulkan/mask.frag b/gsk/resources/vulkan/mask.frag
new file mode 100644
index 0000000..aca9b4d
--- /dev/null
+++ b/gsk/resources/vulkan/mask.frag
@@ -0,0 +1,16 @@
+#version 420 core
+
+#include "clip.frag.glsl"
+
+layout(location = 0) in vec2 inPos;
+layout(location = 1) in vec2 inTexCoord;
+layout(location = 2) in vec4 inColor;
+
+layout(set = 0, binding = 0) uniform sampler2D inTexture;
+
+layout(location = 0) out vec4 color;
+
+void main()
+{
+  color = clip (inPos, inColor * texture (inTexture, inTexCoord).a);
+}
diff --git a/gsk/resources/vulkan/mask.frag.spv b/gsk/resources/vulkan/mask.frag.spv
new file mode 100644
index 0000000..7751f01
Binary files /dev/null and b/gsk/resources/vulkan/mask.frag.spv differ
diff --git a/gsk/resources/vulkan/mask.vert b/gsk/resources/vulkan/mask.vert
new file mode 100644
index 0000000..f4bd9c1
--- /dev/null
+++ b/gsk/resources/vulkan/mask.vert
@@ -0,0 +1,38 @@
+#version 420 core
+
+#include "clip.vert.glsl"
+
+layout(location = 0) in vec4 inRect;
+layout(location = 1) in vec4 inTexRect;
+layout(location = 2) in vec4 inColor;
+
+layout(location = 0) out vec2 outPos;
+layout(location = 1) out vec2 outTexCoord;
+layout(location = 2) out flat vec4 outColor;
+
+out gl_PerVertex {
+  vec4 gl_Position;
+};
+
+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) };
+
+void main() {
+  vec4 rect = clip (inRect);
+  vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
+  gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
+
+  outPos = pos;
+
+  vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
+                      rect.zw / inRect.zw);
+  texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy,
+                 inTexRect.zw * texrect.zw);
+  outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex];
+
+  outColor = inColor;
+}
diff --git a/gsk/resources/vulkan/mask.vert.spv b/gsk/resources/vulkan/mask.vert.spv
new file mode 100644
index 0000000..22cd856
Binary files /dev/null and b/gsk/resources/vulkan/mask.vert.spv differ
diff --git a/gsk/resources/vulkan/meson.build b/gsk/resources/vulkan/meson.build
index b18a298..1007858 100644
--- a/gsk/resources/vulkan/meson.build
+++ b/gsk/resources/vulkan/meson.build
@@ -14,6 +14,7 @@ gsk_private_vulkan_fragment_shaders = [
   'color-matrix.frag',
   'inset-shadow.frag',
   'linear.frag',
+  'mask.frag',
   'outset-shadow.frag',
 ]
 
@@ -25,6 +26,7 @@ gsk_private_vulkan_vertex_shaders = [
   'color-matrix.vert',
   'inset-shadow.vert',
   'linear.vert',
+  'mask.vert',
   'outset-shadow.vert',
 ]
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]