vulkan: Generate vertex array headers from shaders
authorBenjamin Otte <otte@redhat.com>
Tue, 27 Jun 2023 04:45:31 +0000 (06:45 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 27 Jun 2023 05:11:48 +0000 (07:11 +0200)
The script is pretty dumb but it does its job.

17 files changed:
gsk/meson.build
gsk/vulkan/gskvulkanblendmodepipeline.c
gsk/vulkan/gskvulkanblurpipeline.c
gsk/vulkan/gskvulkanborderpipeline.c
gsk/vulkan/gskvulkanboxshadowpipeline.c
gsk/vulkan/gskvulkancolorpipeline.c
gsk/vulkan/gskvulkancolortextpipeline.c
gsk/vulkan/gskvulkancrossfadepipeline.c
gsk/vulkan/gskvulkaneffectpipeline.c
gsk/vulkan/gskvulkanlineargradientpipeline.c
gsk/vulkan/gskvulkantextpipeline.c
gsk/vulkan/gskvulkantexturepipeline.c
gsk/vulkan/resources/border.vert
gsk/vulkan/resources/generate-header.py [new file with mode: 0644]
gsk/vulkan/resources/inset-shadow.vert
gsk/vulkan/resources/meson.build
gsk/vulkan/resources/outset-shadow.vert

index 5b4f2389e97298aba832e6a22990e74ffe8a3ab5..90908881d89af6e101aa97f7429a5c5938789471 100644 (file)
@@ -103,6 +103,7 @@ gsk_private_vulkan_shaders = []
 # on constantly regenerated files.
 gsk_private_vulkan_compiled_shaders = []
 gsk_private_vulkan_compiled_shaders_deps = []
+gsk_private_vulkan_shader_headers = []
 
 if have_vulkan
   gsk_private_sources += files([
@@ -197,6 +198,7 @@ libgsk = static_library('gsk',
     gsk_private_sources,
     gsk_enums,
     gskresources,
+    gsk_private_vulkan_shader_headers,
   ],
   dependencies: gsk_deps,
   include_directories: [ confinc, ],
index b592efa52b73a30d4dea84c9129d932626258c6e..fb71b3b846e3e9d4049bf5d367ce58443d5988a8 100644 (file)
@@ -2,6 +2,8 @@
 
 #include "gskvulkanblendmodepipelineprivate.h"
 
+#include "vulkan/resources/blend-mode.vert.h"
+
 struct _GskVulkanBlendModePipeline
 {
   GObject parent_instance;
@@ -9,89 +11,12 @@ struct _GskVulkanBlendModePipeline
 
 typedef struct _GskVulkanBlendModeInstance GskVulkanBlendModeInstance;
 
-struct _GskVulkanBlendModeInstance
-{
-  float rect[4];
-  float top_rect[4];
-  float bottom_rect[4];
-  float top_tex_rect[4];
-  float bottom_tex_rect[4];
-  guint32 top_tex_id[2];
-  guint32 bottom_tex_id[2];
-  guint32 blend_mode;
-};
-
 G_DEFINE_TYPE (GskVulkanBlendModePipeline, gsk_vulkan_blend_mode_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
 static const VkPipelineVertexInputStateCreateInfo *
 gsk_vulkan_blend_mode_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
 {
-  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
-      {
-          .binding = 0,
-          .stride = sizeof (GskVulkanBlendModeInstance),
-          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
-      }
-  };
-  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
-      {
-          .location = 0,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = 0,
-      },
-      {
-          .location = 1,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, top_rect),
-      },
-      {
-          .location = 2,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, bottom_rect),
-      },
-      {
-          .location = 3,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, top_tex_rect),
-      },
-      {
-          .location = 4,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, bottom_tex_rect),
-      },
-      {
-          .location = 5,
-          .binding = 0,
-          .format = VK_FORMAT_R32_UINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, top_tex_id),
-      },
-      {
-          .location = 6,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32_UINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, bottom_tex_id),
-      },
-      {
-          .location = 7,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32_UINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBlendModeInstance, blend_mode),
-      }
-  };
-  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;
+  return &gsk_vulkan_blend_mode_info;
 }
 
 static void
index 8893794b11fae780c9585f38fba2ed4cd2983254..5b9352908a1d43d1387a6fd315d222f5ce57669b 100644 (file)
@@ -2,68 +2,19 @@
 
 #include "gskvulkanblurpipelineprivate.h"
 
+#include "vulkan/resources/blur.vert.h"
+
 struct _GskVulkanBlurPipeline
 {
   GObject parent_instance;
 };
 
-typedef struct _GskVulkanBlurInstance GskVulkanBlurInstance;
-
-struct _GskVulkanBlurInstance
-{
-  float rect[4];
-  float tex_rect[4];
-  float blur_radius;
-  guint32 tex_id[2];
-};
-
 G_DEFINE_TYPE (GskVulkanBlurPipeline, gsk_vulkan_blur_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
 static const VkPipelineVertexInputStateCreateInfo *
 gsk_vulkan_blur_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
 {
-  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
-      {
-          .binding = 0,
-          .stride = sizeof (GskVulkanBlurInstance),
-          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
-      }
-  };
-  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
-      {
-          .location = 0,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = 0,
-      },
-      {
-          .location = 1,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBlurInstance, tex_rect),
-      },
-      {
-          .location = 2,
-          .binding = 0,
-          .format = VK_FORMAT_R32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBlurInstance, blur_radius),
-      },
-      {
-          .location = 3,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32_UINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBlurInstance, tex_id),
-      }
-  };
-  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;
+  return &gsk_vulkan_blur_info;
 }
 
 static void
@@ -105,7 +56,7 @@ gsk_vulkan_blur_pipeline_collect_vertex_data (GskVulkanBlurPipeline  *pipeline,
                                               const graphene_point_t *offset,
                                               const graphene_rect_t  *rect,
                                               const graphene_rect_t  *tex_rect,
-                                              double                  blur_radius)
+                                              double                  radius)
 {
   GskVulkanBlurInstance *instance = (GskVulkanBlurInstance *) data;
 
@@ -117,7 +68,7 @@ gsk_vulkan_blur_pipeline_collect_vertex_data (GskVulkanBlurPipeline  *pipeline,
   instance->tex_rect[1] = tex_rect->origin.y;
   instance->tex_rect[2] = tex_rect->size.width;
   instance->tex_rect[3] = tex_rect->size.height;
-  instance->blur_radius = blur_radius;
+  instance->radius = radius;
   instance->tex_id[0] = tex_id[0];
   instance->tex_id[1] = tex_id[1];
 }
index 927b2aa0c8fc71f612bc11fa1b3580cf870fb0a4..92417807603e8ed24bbac296f04015d6ae01653b 100644 (file)
@@ -4,91 +4,19 @@
 
 #include "gskroundedrectprivate.h"
 
+#include "vulkan/resources/border.vert.h"
+
 struct _GskVulkanBorderPipeline
 {
   GObject parent_instance;
 };
 
-typedef struct _GskVulkanBorderInstance GskVulkanBorderInstance;
-
-struct _GskVulkanBorderInstance
-{
-  float rect[12];
-  float widths[4];
-  float colors[16];
-};
-
 G_DEFINE_TYPE (GskVulkanBorderPipeline, gsk_vulkan_border_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
 static const VkPipelineVertexInputStateCreateInfo *
 gsk_vulkan_border_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
 {
-  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
-      {
-          .binding = 0,
-          .stride = sizeof (GskVulkanBorderInstance),
-          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
-      }
-  };
-  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
-      {
-          .location = 0,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBorderInstance, rect),
-      },
-      {
-          .location = 1,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBorderInstance, rect) + 4 * sizeof (float),
-      },
-      {
-          .location = 2,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBorderInstance, rect) + 8 * sizeof (float),
-      },
-      {
-          .location = 3,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBorderInstance, widths),
-      },
-      {
-          .location = 4,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBorderInstance, colors),
-      },
-      {
-          .location = 5,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBorderInstance, colors) + 4 * sizeof (float),
-      },
-      {
-          .location = 6,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBorderInstance, colors) + 8 * sizeof (float),
-      },
-      {
-          .location = 7,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBorderInstance, colors) + 12 * sizeof (float),
-      }
-  };
-  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;
+  return &gsk_vulkan_border_info;
 }
 
 static void
@@ -137,11 +65,11 @@ gsk_vulkan_border_pipeline_collect_vertex_data (GskVulkanBorderPipeline *pipelin
   gsk_rounded_rect_to_float (rect, offset, instance->rect);
   for (i = 0; i < 4; i++)
     {
-      instance->widths[i] = widths[i];
-      instance->colors[4 * i + 0] = colors[i].red;
-      instance->colors[4 * i + 1] = colors[i].green;
-      instance->colors[4 * i + 2] = colors[i].blue;
-      instance->colors[4 * i + 3] = colors[i].alpha;
+      instance->border_widths[i] = widths[i];
+      instance->border_colors[4 * i + 0] = colors[i].red;
+      instance->border_colors[4 * i + 1] = colors[i].green;
+      instance->border_colors[4 * i + 2] = colors[i].blue;
+      instance->border_colors[4 * i + 3] = colors[i].alpha;
     }
 }
 
index 912174f304bb5501200bd4f2b404926a744e4b9b..1f81dd4ed124b43f06c999a95d7fd236aa7699cd 100644 (file)
@@ -2,6 +2,8 @@
 
 #include "gskvulkanboxshadowpipelineprivate.h"
 
+#include "vulkan/resources/inset-shadow.vert.h"
+
 #include "gskroundedrectprivate.h"
 
 struct _GskVulkanBoxShadowPipeline
@@ -9,82 +11,12 @@ struct _GskVulkanBoxShadowPipeline
   GObject parent_instance;
 };
 
-typedef struct _GskVulkanBoxShadowInstance GskVulkanBoxShadowInstance;
-
-struct _GskVulkanBoxShadowInstance
-{
-  float outline[12];
-  float color[4];
-  float offset[2];
-  float spread;
-  float blur_radius;
-};
-
 G_DEFINE_TYPE (GskVulkanBoxShadowPipeline, gsk_vulkan_box_shadow_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
 static const VkPipelineVertexInputStateCreateInfo *
 gsk_vulkan_box_shadow_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
 {
-  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
-      {
-          .binding = 0,
-          .stride = sizeof (GskVulkanBoxShadowInstance),
-          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
-      }
-  };
-  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
-      {
-          .location = 0,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBoxShadowInstance, outline),
-      },
-      {
-          .location = 1,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBoxShadowInstance, outline) + 4 * sizeof (float),
-      },
-      {
-          .location = 2,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBoxShadowInstance, outline) + 8 * sizeof (float),
-      },
-      {
-          .location = 3,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBoxShadowInstance, color),
-      },
-      {
-          .location = 4,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBoxShadowInstance, offset),
-      },
-      {
-          .location = 5,
-          .binding = 0,
-          .format = VK_FORMAT_R32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBoxShadowInstance, spread),
-      },
-      {
-          .location = 6,
-          .binding = 0,
-          .format = VK_FORMAT_R32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanBoxShadowInstance, blur_radius),
-      }
-  };
-  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;
+  return &gsk_vulkan_inset_shadow_info;
 }
 
 static void
@@ -130,7 +62,7 @@ gsk_vulkan_box_shadow_pipeline_collect_vertex_data (GskVulkanBoxShadowPipeline *
                                                     float                      spread,
                                                     float                      blur_radius)
 {
-  GskVulkanBoxShadowInstance *instance = (GskVulkanBoxShadowInstance *) data;
+  GskVulkanInsetShadowInstance *instance = (GskVulkanInsetShadowInstance *) data;
 
   gsk_rounded_rect_to_float (outline, offset, instance->outline);
   instance->color[0] = color->red;
index abcb0f1721e43b9d2fb5d4cc3d066c2b322e2924..1bc67419ecd3b3be3a8ee7cd4219f29e251e75c7 100644 (file)
@@ -2,54 +2,19 @@
 
 #include "gskvulkancolorpipelineprivate.h"
 
+#include "vulkan/resources/color.vert.h"
+
 struct _GskVulkanColorPipeline
 {
   GObject parent_instance;
 };
 
-typedef struct _GskVulkanColorInstance GskVulkanColorInstance;
-
-struct _GskVulkanColorInstance
-{
-  float rect[4];
-  float color[4];
-};
-
 G_DEFINE_TYPE (GskVulkanColorPipeline, gsk_vulkan_color_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
 static const VkPipelineVertexInputStateCreateInfo *
 gsk_vulkan_color_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
 {
-  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
-      {
-          .binding = 0,
-          .stride = sizeof (GskVulkanColorInstance),
-          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
-      }
-  };
-  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
-      {
-          .location = 0,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = 0,
-      },
-      {
-          .location = 1,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanColorInstance, 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;
+  return &gsk_vulkan_color_info;
 }
 
 static void
index 022ab0812f19a529ef956fcd8f76b5054e7f6cce..6e45cfe01e015114fc580f3d8d5dd5b1010ebc18 100644 (file)
@@ -2,61 +2,19 @@
 
 #include "gskvulkancolortextpipelineprivate.h"
 
+#include "vulkan/resources/texture.vert.h"
+
 struct _GskVulkanColorTextPipeline
 {
   GObject parent_instance;
 };
 
-typedef struct _GskVulkanColorTextInstance GskVulkanColorTextInstance;
-
-struct _GskVulkanColorTextInstance
-{
-  float rect[4];
-  float tex_rect[4];
-  guint32 tex_id[2];
-};
-
 G_DEFINE_TYPE (GskVulkanColorTextPipeline, gsk_vulkan_color_text_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
 static const VkPipelineVertexInputStateCreateInfo *
 gsk_vulkan_color_text_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
 {
-  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
-      {
-          .binding = 0,
-          .stride = sizeof (GskVulkanColorTextInstance),
-          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
-      }
-  };
-  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
-      {
-          .location = 0,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanColorTextInstance, rect),
-      },
-      {
-          .location = 1,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanColorTextInstance, tex_rect),
-      },
-      {
-          .location = 2,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32_UINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanColorTextInstance, tex_id),
-      }
-  };
-  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;
+  return &gsk_vulkan_texture_info;
 }
 
 static void
@@ -105,7 +63,7 @@ gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *
                                                     guint                       num_glyphs,
                                                     float                       scale)
 {
-  GskVulkanColorTextInstance *instances = (GskVulkanColorTextInstance *) data;
+  GskVulkanTextureInstance *instances = (GskVulkanTextureInstance *) data;
   int i;
   int count = 0;
   int x_position = 0;
@@ -121,7 +79,7 @@ gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *
         {
           double cx = (x_position + gi->geometry.x_offset) / PANGO_SCALE;
           double cy = gi->geometry.y_offset / PANGO_SCALE;
-          GskVulkanColorTextInstance *instance = &instances[count];
+          GskVulkanTextureInstance *instance = &instances[count];
           GskVulkanCachedGlyph *glyph;
 
           glyph = gsk_vulkan_renderer_get_cached_glyph (renderer,
index 889634df89b81e55d7a10c38cc947f4470b36f66..1ad42cbcd14dc04b995db52a7ce815bdf083aa31 100644 (file)
@@ -2,96 +2,19 @@
 
 #include "gskvulkancrossfadepipelineprivate.h"
 
+#include "vulkan/resources/cross-fade.vert.h"
+
 struct _GskVulkanCrossFadePipeline
 {
   GObject parent_instance;
 };
 
-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];
-  guint32 start_tex_id[2];
-  guint32 end_tex_id[2];
-  float progress;
-};
-
 G_DEFINE_TYPE (GskVulkanCrossFadePipeline, gsk_vulkan_cross_fade_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
 static const VkPipelineVertexInputStateCreateInfo *
 gsk_vulkan_cross_fade_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
 {
-  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
-      {
-          .binding = 0,
-          .stride = sizeof (GskVulkanCrossFadeInstance),
-          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
-      }
-  };
-  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
-      {
-          .location = 0,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = 0,
-      },
-      {
-          .location = 1,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, start_rect),
-      },
-      {
-          .location = 2,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .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_R32G32_UINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, start_tex_id),
-      },
-      {
-          .location = 6,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32_UINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, end_tex_id),
-      },
-      {
-          .location = 7,
-          .binding = 0,
-          .format = VK_FORMAT_R32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanCrossFadeInstance, progress),
-      }
-  };
-  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;
+  return &gsk_vulkan_cross_fade_info;
 }
 
 static void
index dcbf35626d2a4b642e5e70a4bbbe80e591a9dcd1..b611502e016b0d2c9aed5711f77180cbbd6f69d5 100644 (file)
@@ -2,93 +2,19 @@
 
 #include "gskvulkaneffectpipelineprivate.h"
 
+#include "vulkan/resources/color-matrix.vert.h"
+
 struct _GskVulkanEffectPipeline
 {
   GObject parent_instance;
 };
 
-typedef struct _GskVulkanEffectInstance GskVulkanEffectInstance;
-
-struct _GskVulkanEffectInstance
-{
-  float rect[4];
-  float tex_rect[4];
-  float color_matrix[16];
-  float color_offset[4];
-  guint32 tex_id[2];
-};
-
 G_DEFINE_TYPE (GskVulkanEffectPipeline, gsk_vulkan_effect_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
 static const VkPipelineVertexInputStateCreateInfo *
 gsk_vulkan_effect_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
 {
-  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
-      {
-          .binding = 0,
-          .stride = sizeof (GskVulkanEffectInstance),
-          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
-      }
-  };
-  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
-      {
-          .location = 0,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = 0,
-      },
-      {
-          .location = 1,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, tex_rect),
-      },
-      {
-          .location = 2,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, color_matrix),
-      },
-      {
-          .location = 3,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, color_matrix) + sizeof (float) * 4,
-      },
-      {
-          .location = 4,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, color_matrix) + sizeof (float) * 8,
-      },
-      {
-          .location = 5,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, color_matrix) + sizeof (float) * 12,
-      },
-      {
-          .location = 6,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, color_offset),
-      },
-      {
-          .location = 7,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32_UINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanEffectInstance, tex_id),
-      }
-  };
-  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;
+  return &gsk_vulkan_color_matrix_info;
 }
 
 static void
@@ -133,7 +59,7 @@ gsk_vulkan_effect_pipeline_collect_vertex_data (GskVulkanEffectPipeline *pipelin
                                                 const graphene_matrix_t *color_matrix,
                                                 const graphene_vec4_t   *color_offset)
 {
-  GskVulkanEffectInstance *instance = (GskVulkanEffectInstance *) data;
+  GskVulkanColorMatrixInstance *instance = (GskVulkanColorMatrixInstance *) data;
 
   instance->rect[0] = rect->origin.x + offset->x;
   instance->rect[1] = rect->origin.y + offset->y;
index 1a790de475ca47df7d247243d7e6249151c4cba9..3e62778f0b2b03ddf30c63ff20cfd5f784feec2e 100644 (file)
@@ -2,82 +2,19 @@
 
 #include "gskvulkanlineargradientpipelineprivate.h"
 
+#include "vulkan/resources/linear.vert.h"
+
 struct _GskVulkanLinearGradientPipeline
 {
   GObject parent_instance;
 };
 
-typedef struct _GskVulkanLinearGradientInstance GskVulkanLinearGradientInstance;
-
-struct _GskVulkanLinearGradientInstance
-{
-  float rect[4];
-  float start[2];
-  float end[2];
-  gint32 repeating;
-  gint32 offset;
-  gint32 stop_count;
-};
-
 G_DEFINE_TYPE (GskVulkanLinearGradientPipeline, gsk_vulkan_linear_gradient_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
 static const VkPipelineVertexInputStateCreateInfo *
 gsk_vulkan_linear_gradient_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
 {
-  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
-      {
-          .binding = 0,
-          .stride = sizeof (GskVulkanLinearGradientInstance),
-          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
-      }
-  };
-  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
-      {
-          .location = 0,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = 0,
-      },
-      {
-          .location = 1,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanLinearGradientInstance, start),
-      },
-      {
-          .location = 2,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanLinearGradientInstance, end),
-      },
-      {
-          .location = 3,
-          .binding = 0,
-          .format = VK_FORMAT_R32_SINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanLinearGradientInstance, repeating),
-      },
-      {
-          .location = 4,
-          .binding = 0,
-          .format = VK_FORMAT_R32_SINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanLinearGradientInstance, offset),
-      },
-      {
-          .location = 5,
-          .binding = 0,
-          .format = VK_FORMAT_R32_SINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanLinearGradientInstance, stop_count),
-      }
-  };
-  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;
+  return &gsk_vulkan_linear_info;
 }
 
 static void
@@ -123,7 +60,7 @@ gsk_vulkan_linear_gradient_pipeline_collect_vertex_data (GskVulkanLinearGradient
                                                          gsize                            gradient_offset,
                                                          gsize                            n_stops)
 {
-  GskVulkanLinearGradientInstance *instance = (GskVulkanLinearGradientInstance *) data;
+  GskVulkanLinearInstance *instance = (GskVulkanLinearInstance *) data;
 
   instance->rect[0] = rect->origin.x + offset->x;
   instance->rect[1] = rect->origin.y + offset->y;
@@ -134,7 +71,7 @@ gsk_vulkan_linear_gradient_pipeline_collect_vertex_data (GskVulkanLinearGradient
   instance->end[0] = end->x + offset->x;
   instance->end[1] = end->y + offset->y;
   instance->repeating = repeating;
-  instance->offset = gradient_offset;
+  instance->stop_offset = gradient_offset;
   instance->stop_count = n_stops;
 }
 
index 60cdd16bd5d6230529cd32e512be9f5c0221566b..c7eed9386f73e1806a05983ad6a97679187b3fe2 100644 (file)
@@ -2,68 +2,19 @@
 
 #include "gskvulkantextpipelineprivate.h"
 
+#include "vulkan/resources/mask.vert.h"
+
 struct _GskVulkanTextPipeline
 {
   GObject parent_instance;
 };
 
-typedef struct _GskVulkanTextInstance GskVulkanTextInstance;
-
-struct _GskVulkanTextInstance
-{
-  float rect[4];
-  float tex_rect[4];
-  float color[4];
-  guint32 tex_id[2];
-};
-
 G_DEFINE_TYPE (GskVulkanTextPipeline, gsk_vulkan_text_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
 static const VkPipelineVertexInputStateCreateInfo *
 gsk_vulkan_text_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
 {
-  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
-      {
-          .binding = 0,
-          .stride = sizeof (GskVulkanTextInstance),
-          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
-      }
-  };
-  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
-      {
-          .location = 0,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanTextInstance, rect),
-      },
-      {
-          .location = 1,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanTextInstance, tex_rect),
-      },
-      {
-          .location = 2,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanTextInstance, color),
-      },
-      {
-          .location = 3,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32_UINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanTextInstance, tex_id),
-      }
-  };
-  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;
+  return &gsk_vulkan_mask_info;
 }
 
 static void
@@ -113,7 +64,7 @@ gsk_vulkan_text_pipeline_collect_vertex_data (GskVulkanTextPipeline  *pipeline,
                                               guint                   num_glyphs,
                                               float                   scale)
 {
-  GskVulkanTextInstance *instances = (GskVulkanTextInstance *) data;
+  GskVulkanMaskInstance *instances = (GskVulkanMaskInstance *) data;
   int i;
   int count = 0;
   int x_position = 0;
@@ -129,7 +80,7 @@ gsk_vulkan_text_pipeline_collect_vertex_data (GskVulkanTextPipeline  *pipeline,
         {
           double cx = (x_position + gi->geometry.x_offset) / PANGO_SCALE;
           double cy = gi->geometry.y_offset / PANGO_SCALE;
-          GskVulkanTextInstance *instance = &instances[count];
+          GskVulkanMaskInstance *instance = &instances[count];
           GskVulkanCachedGlyph *glyph;
 
           glyph = gsk_vulkan_renderer_get_cached_glyph (renderer,
index 2b9e07520dff7f66dd3a5806502140e586882a53..19b5e5339efa749572f75a872cf1e7db4bc61061 100644 (file)
@@ -2,61 +2,19 @@
 
 #include "gskvulkantexturepipelineprivate.h"
 
+#include "vulkan/resources/texture.vert.h"
+
 struct _GskVulkanTexturePipeline
 {
   GObject parent_instance;
 };
 
-typedef struct _GskVulkanTextureInstance GskVulkanTextureInstance;
-
-struct _GskVulkanTextureInstance
-{
-  float rect[4];
-  float tex_rect[4];
-  guint32 tex_id[2];
-};
-
 G_DEFINE_TYPE (GskVulkanTexturePipeline, gsk_vulkan_texture_pipeline, GSK_TYPE_VULKAN_PIPELINE)
 
 static const VkPipelineVertexInputStateCreateInfo *
 gsk_vulkan_texture_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
 {
-  static const VkVertexInputBindingDescription vertexBindingDescriptions[] = {
-      {
-          .binding = 0,
-          .stride = sizeof (GskVulkanTextureInstance),
-          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
-      }
-  };
-  static const VkVertexInputAttributeDescription vertexInputAttributeDescription[] = {
-      {
-          .location = 0,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanTextureInstance, rect),
-      },
-      {
-          .location = 1,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32B32A32_SFLOAT,
-          .offset = G_STRUCT_OFFSET (GskVulkanTextureInstance, tex_rect),
-      },
-      {
-          .location = 2,
-          .binding = 0,
-          .format = VK_FORMAT_R32G32_UINT,
-          .offset = G_STRUCT_OFFSET (GskVulkanTextureInstance, tex_id),
-      }
-  };
-  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;
+  return &gsk_vulkan_texture_info;
 }
 
 static void
index 6f242f2ea7ff1e39f1bc69b9ceae4eb8f52260b6..a7dce7f2050e59eeaaf769366df0082bdbe50220 100644 (file)
@@ -3,9 +3,7 @@
 #include "clip.vert.glsl"
 #include "rounded-rect.glsl"
 
-layout(location = 0) in vec4 inRect;
-layout(location = 1) in vec4 inCornerWidths;
-layout(location = 2) in vec4 inCornerHeights;
+layout(location = 0) in mat3x4 inRect;
 layout(location = 3) in vec4 inBorderWidths;
 layout(location = 4) in mat4 inBorderColors;
 
@@ -44,47 +42,47 @@ void main() {
   int slice_index = gl_VertexIndex / 6;
   int vert_index = gl_VertexIndex % 6;
 
-  vec4 corner_widths = max (inCornerWidths, inBorderWidths.wyyw);
-  vec4 corner_heights = max (inCornerHeights, inBorderWidths.xxzz);
+  vec4 corner_widths = max (inRect[1], inBorderWidths.wyyw);
+  vec4 corner_heights = max (inRect[2], inBorderWidths.xxzz);
 
   Rect rect;
 
   switch (slice_index)
     {
     case SLICE_TOP_LEFT:
-      rect = rect_from_gsk (vec4(inRect.xy, corner_widths[TOP_LEFT], corner_heights[TOP_LEFT]));
+      rect = rect_from_gsk (vec4(inRect[0].xy, corner_widths[TOP_LEFT], corner_heights[TOP_LEFT]));
       rect = rect_round_larger (rect);
       vert_index = (vert_index + 3) % 6;
       break;
     case SLICE_TOP:
-      rect = rect_from_gsk (vec4(inRect.x + corner_widths[TOP_LEFT], inRect.y, inRect.z - corner_widths[TOP_LEFT] - corner_widths[TOP_RIGHT], inBorderWidths[TOP]));
+      rect = rect_from_gsk (vec4(inRect[0].x + corner_widths[TOP_LEFT], inRect[0].y, inRect[0].z - corner_widths[TOP_LEFT] - corner_widths[TOP_RIGHT], inBorderWidths[TOP]));
       rect = rect_round_smaller_larger (rect);
       outColor = inBorderColors[TOP];
       break;
     case SLICE_TOP_RIGHT:
-      rect = rect_from_gsk (vec4(inRect.x + inRect.z - corner_widths[TOP_RIGHT], inRect.y, corner_widths[TOP_RIGHT], corner_heights[TOP_RIGHT]));
+      rect = rect_from_gsk (vec4(inRect[0].x + inRect[0].z - corner_widths[TOP_RIGHT], inRect[0].y, corner_widths[TOP_RIGHT], corner_heights[TOP_RIGHT]));
       rect = rect_round_larger (rect);
       break;
     case SLICE_RIGHT:
-      rect = rect_from_gsk (vec4(inRect.x + inRect.z - inBorderWidths[RIGHT], inRect.y + corner_heights[TOP_RIGHT], inBorderWidths[RIGHT], inRect.w - corner_heights[TOP_RIGHT] - corner_heights[BOTTOM_RIGHT]));
+      rect = rect_from_gsk (vec4(inRect[0].x + inRect[0].z - inBorderWidths[RIGHT], inRect[0].y + corner_heights[TOP_RIGHT], inBorderWidths[RIGHT], inRect[0].w - corner_heights[TOP_RIGHT] - corner_heights[BOTTOM_RIGHT]));
       rect = rect_round_larger_smaller (rect);
       outColor = inBorderColors[RIGHT];
       break;
     case SLICE_BOTTOM_RIGHT:
-      rect = rect_from_gsk (vec4(inRect.x + inRect.z - corner_widths[BOTTOM_RIGHT], inRect.y + inRect.w - corner_heights[BOTTOM_RIGHT], corner_widths[BOTTOM_RIGHT], corner_heights[BOTTOM_RIGHT]));
+      rect = rect_from_gsk (vec4(inRect[0].x + inRect[0].z - corner_widths[BOTTOM_RIGHT], inRect[0].y + inRect[0].w - corner_heights[BOTTOM_RIGHT], corner_widths[BOTTOM_RIGHT], corner_heights[BOTTOM_RIGHT]));
       rect = rect_round_larger (rect);
       break;
     case SLICE_BOTTOM:
-      rect = rect_from_gsk (vec4(inRect.x + corner_widths[BOTTOM_LEFT], inRect.y + inRect.w - inBorderWidths[BOTTOM], inRect.z - corner_widths[BOTTOM_LEFT] - corner_widths[BOTTOM_RIGHT], inBorderWidths[BOTTOM]));
+      rect = rect_from_gsk (vec4(inRect[0].x + corner_widths[BOTTOM_LEFT], inRect[0].y + inRect[0].w - inBorderWidths[BOTTOM], inRect[0].z - corner_widths[BOTTOM_LEFT] - corner_widths[BOTTOM_RIGHT], inBorderWidths[BOTTOM]));
       rect = rect_round_smaller_larger (rect);
       break;
     case SLICE_BOTTOM_LEFT:
-      rect = rect_from_gsk (vec4(inRect.x, inRect.y + inRect.w - corner_heights[BOTTOM_LEFT], corner_widths[BOTTOM_LEFT], corner_heights[BOTTOM_LEFT]));
+      rect = rect_from_gsk (vec4(inRect[0].x, inRect[0].y + inRect[0].w - corner_heights[BOTTOM_LEFT], corner_widths[BOTTOM_LEFT], corner_heights[BOTTOM_LEFT]));
       vert_index = (vert_index + 3) % 6;
       rect = rect_round_larger (rect);
       break;
     case SLICE_LEFT:
-      rect = rect_from_gsk (vec4(inRect.x, inRect.y + corner_heights[TOP_LEFT], inBorderWidths[LEFT], inRect.w - corner_heights[TOP_LEFT] - corner_heights[BOTTOM_LEFT]));
+      rect = rect_from_gsk (vec4(inRect[0].x, inRect[0].y + corner_heights[TOP_LEFT], inBorderWidths[LEFT], inRect[0].w - corner_heights[TOP_LEFT] - corner_heights[BOTTOM_LEFT]));
       rect = rect_round_larger_smaller (rect);
       break;
     }
@@ -99,7 +97,7 @@ void main() {
   gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
   outColor = inBorderColors[((gl_VertexIndex / 3 + 15) / 4) % 4];
   outPos = pos;
-  outRect = RoundedRect(inRect.xyxy + vec4(0,0,inRect.zw), inCornerWidths, inCornerHeights);
+  outRect = RoundedRect(inRect[0].xyxy + vec4(0,0,inRect[0].zw), inRect[1], inRect[2]);
   outRect = rounded_rect_scale (outRect, push.scale);
   outBorderWidths = inBorderWidths * push.scale.yxyx;
 }
diff --git a/gsk/vulkan/resources/generate-header.py b/gsk/vulkan/resources/generate-header.py
new file mode 100644 (file)
index 0000000..57aa954
--- /dev/null
@@ -0,0 +1,192 @@
+#!/usr/bin/env python3
+
+import sys
+import re
+import os
+
+name = os.path.splitext(os.path.basename(sys.argv[1]))[0]
+var_name = "gsk_vulkan_" + name.replace('-', '_')
+struct_name = "GskVulkan" + name.title().replace('-', '') + "Instance"
+
+lines = open (sys.argv[1]).readlines()
+matches = []
+
+for line in lines:
+    match = re.search("^layout\(location = ([0-9]+)\) in ([a-z0-9]+) ([a-zA-Z0-9]+);$", line)
+    if not match:
+        if re.search("layout.*\sin\s.*", line):
+            raise Exception("Failed to parse file")
+        continue;
+    if not match.group(3).startswith('in'):
+        raise Exception("Variable doesn't start with 'in'")
+    matches.append({ 'name': ''.join('_' + char.lower() if char.isupper() else char for char in match.group(3))[3:],
+                     'location': int(match.group(1)),
+                     'type': match.group(2) })
+
+print(
+f'''#pragma once
+
+typedef struct _{struct_name} {struct_name};
+
+struct _{struct_name} {{''')
+
+expected = 0;
+for match in matches:
+    if expected != int(match['location']):
+        raise Exception(f"Should be layout location {expected} but is {match['location']}")
+
+    match match['type']:
+        case "float":
+            print(f"  float {match['name']};")
+            expected += 1
+        case "int":
+            print(f"  gint32 {match['name']};")
+            expected += 1
+        case "uint":
+            print(f"  guint32 {match['name']};")
+            expected += 1
+        case "uvec2":
+            print(f"  guint32 {match['name']}[2];")
+            expected += 1
+        case "vec2":
+            print(f"  float {match['name']}[2];")
+            expected += 1
+        case "vec4":
+            print(f"  float {match['name']}[4];")
+            expected += 1
+        case "mat3x4":
+            print(f"  float {match['name']}[12];")
+            expected += 3
+        case "mat4":
+            print(f"  float {match['name']}[16];")
+            expected += 4
+        case _:
+            raise Exception(f"Don't know what a {match['type']} is")
+
+print(
+'''};
+''')
+
+print(
+f'''static const VkPipelineVertexInputStateCreateInfo {var_name}_info = {{
+  .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
+  .vertexBindingDescriptionCount = 1,
+  .pVertexBindingDescriptions = (VkVertexInputBindingDescription[1]) {{
+      {{
+          .binding = 0,
+          .stride = sizeof ({struct_name}),
+          .inputRate = VK_VERTEX_INPUT_RATE_INSTANCE
+      }}
+  }},
+  .vertexAttributeDescriptionCount = {expected},
+  .pVertexAttributeDescriptions = (VkVertexInputAttributeDescription[{expected}]) {{''')
+
+for match in matches:
+    match match['type']:
+        case "float":
+            print(
+f'''      {{
+        .location = {match['location']},
+        .binding = 0,
+        .format = VK_FORMAT_R32_SFLOAT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}),
+      }},''')
+
+        case "int":
+            print(
+f'''      {{
+        .location = {match['location']},
+        .binding = 0,
+        .format = VK_FORMAT_R32_SINT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}),
+      }},''')
+
+        case "uint":
+            print(
+f'''      {{
+        .location = {match['location']},
+        .binding = 0,
+        .format = VK_FORMAT_R32_UINT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}),
+      }},''')
+
+        case "uvec2":
+            print(
+f'''      {{
+        .location = {match['location']},
+        .binding = 0,
+        .format = VK_FORMAT_R32G32_UINT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}),
+      }},''')
+
+        case "vec2":
+            print(
+f'''      {{
+        .location = {match['location']},
+        .binding = 0,
+        .format = VK_FORMAT_R32G32_SFLOAT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}),
+      }},''')
+
+        case "vec4":
+            print(
+f'''      {{
+        .location = {match['location']},
+        .binding = 0,
+        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}),
+      }},''')
+
+        case "mat3x4":
+            print(
+f'''      {{
+        .location = {match['location']},
+        .binding = 0,
+        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}),
+      }},
+      {{
+        .location = {int(match['location']) + 1},
+        .binding = 0,
+        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}) + sizeof (float) * 4,
+      }},
+      {{
+        .location = {int(match['location']) + 2},
+        .binding = 0,
+        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}) + sizeof (float) * 8,
+      }},''')
+
+        case "mat4":
+            print(
+f'''      {{
+        .location = {match['location']},
+        .binding = 0,
+        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}),
+      }},
+      {{
+        .location = {int(match['location']) + 1},
+        .binding = 0,
+        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}) + sizeof (float) * 4,
+      }},
+      {{
+        .location = {int(match['location']) + 2},
+        .binding = 0,
+        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}) + sizeof (float) * 8,
+      }},
+      {{
+        .location = {int(match['location']) + 3},
+        .binding = 0,
+        .format = VK_FORMAT_R32G32B32A32_SFLOAT,
+        .offset = G_STRUCT_OFFSET({struct_name}, {match['name']}) + sizeof (float) * 12,
+      }},''')
+
+        case _:
+            raise Exception(f"Don't know what a {match['type']} is")
+
+print("  },")
+print("};")
index 29bec228436e2e82e2449d13e71e017e6e843d18..bda0060a1ca898c6f8bdb2507beabd5ea8c09be2 100644 (file)
@@ -2,9 +2,7 @@
 
 #include "clip.vert.glsl"
 
-layout(location = 0) in vec4 inOutline;
-layout(location = 1) in vec4 inOutlineCornerWidths;
-layout(location = 2) in vec4 inOutlineCornerHeights;
+layout(location = 0) in mat3x4 inOutline;
 layout(location = 3) in vec4 inColor;
 layout(location = 4) in vec2 inOffset;
 layout(location = 5) in float inSpread;
@@ -26,15 +24,15 @@ vec2 offsets[6] = { vec2(0.0, 0.0),
                     vec2(1.0, 1.0) };
 
 void main() {
-  vec4 rect = clip (inOutline);
+  vec4 rect = clip (inOutline[0]);
 
   vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
   gl_Position = push.mvp * vec4 (push.scale * pos, 0.0, 1.0);
   outPos = pos;
 
-  outOutline = inOutline;
-  outOutlineCornerWidths = inOutlineCornerWidths;
-  outOutlineCornerHeights = inOutlineCornerHeights;
+  outOutline = inOutline[0];
+  outOutlineCornerWidths = inOutline[1];
+  outOutlineCornerHeights = inOutline[2];
   outColor = inColor;
   outOffset = inOffset;
   outSpread = inSpread;
index 019d9d4da8552d8b895444745181f897536c8f37..3e5b00dafabe702a1206608dc5098d0b869611dd 100644 (file)
@@ -90,3 +90,14 @@ foreach shader: gsk_private_vulkan_shaders
   endif
   gsk_private_vulkan_compiled_shaders += files(spv_shader, clip_spv_shader, clip_rounded_spv_shader)
 endforeach
+
+foreach shader: gsk_private_vulkan_vertex_shaders
+  shader_header = configure_file(output: '@0@.h'.format(shader),
+                                 input: shader,
+                                 command: [
+                                   find_program('generate-header.py'),
+                                   '@INPUT@',
+                                 ],
+                                 capture: true)
+  gsk_private_vulkan_shader_headers += shader_header
+endforeach
index 67b3ed2d55034347ef48c93d04c06e43dd7159cd..8bbfb77259185e0b8d7ab2573fc98497bcba5dfc 100644 (file)
@@ -2,9 +2,7 @@
 
 #include "clip.vert.glsl"
 
-layout(location = 0) in vec4 inOutline;
-layout(location = 1) in vec4 inOutlineCornerWidths;
-layout(location = 2) in vec4 inOutlineCornerHeights;
+layout(location = 0) in mat3x4 inOutline;
 layout(location = 3) in vec4 inColor;
 layout(location = 4) in vec2 inOffset;
 layout(location = 5) in float inSpread;
@@ -31,19 +29,19 @@ float radius_pixels(float radius) {
 }
 
 void main() {
-  vec4 rect = inOutline;
+  vec4 rect = inOutline[0];
   float spread = inSpread + radius_pixels(inBlurRadius);
   rect += vec4(inOffset - spread, vec2(2 * spread));
   
-  clip (inOutline);
+  clip (inOutline[0]);
 
   vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex];
   gl_Position = push.mvp * vec4 (push.scale * pos, 0.0, 1.0);
   outPos = pos;
 
-  outOutline = inOutline;
-  outOutlineCornerWidths = inOutlineCornerWidths;
-  outOutlineCornerHeights = inOutlineCornerHeights;
+  outOutline = inOutline[0];
+  outOutlineCornerWidths = inOutline[1];
+  outOutlineCornerHeights = inOutline[2];
   outColor = inColor;
   outOffset = inOffset;
   outSpread = inSpread;