vulkan: Add scale to push constants
authorBenjamin Otte <otte@redhat.com>
Fri, 12 May 2023 01:59:44 +0000 (03:59 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 4 Jun 2023 17:42:01 +0000 (19:42 +0200)
This way, it can be pushed to the shaders

gsk/vulkan/gskvulkanpushconstants.c
gsk/vulkan/gskvulkanpushconstantsprivate.h
gsk/vulkan/gskvulkanrenderpass.c
gsk/vulkan/resources/constants.glsl

index 456fff712b9075fdb94294b3e1acfd3dca87b41b..ebc38275bb4b6b6c15e0a60ec000d22ae64b9a5f 100644 (file)
@@ -12,6 +12,7 @@ struct _GskVulkanPushConstantsWire
   struct {
     float mvp[16];
     float clip[12];
+    float scale[2];
   } common;
 };
 
@@ -23,22 +24,25 @@ G_STATIC_ASSERT (sizeof (GskVulkanPushConstantsWire) <= 128);
 
 static void
 gsk_vulkan_push_constants_wire_init (GskVulkanPushConstantsWire *wire,
+                                     const graphene_vec2_t      *scale,
                                      const graphene_matrix_t    *mvp,
                                      const GskRoundedRect       *clip)
 {
   graphene_matrix_to_float (mvp, wire->common.mvp);
   gsk_rounded_rect_to_float (clip, graphene_point_zero (), wire->common.clip);
+  graphene_vec2_to_float (scale, wire->common.scale);
 }
 
 void
 gsk_vulkan_push_constants_push (VkCommandBuffer          command_buffer,
                                 VkPipelineLayout         pipeline_layout,
+                                const graphene_vec2_t   *scale,
                                 const graphene_matrix_t *mvp,
                                 const GskRoundedRect    *clip)
 {
   GskVulkanPushConstantsWire wire;
 
-  gsk_vulkan_push_constants_wire_init (&wire, mvp, clip);
+  gsk_vulkan_push_constants_wire_init (&wire, scale, mvp, clip);
 
   vkCmdPushConstants (command_buffer,
                       pipeline_layout,
index 6b8470d674960ab03254a6a14124237ef3b14543..1e04e5015466d32263dfc1836f91b7c9cc4a8109 100644 (file)
@@ -12,6 +12,7 @@ uint32_t                gsk_vulkan_push_constants_get_range_count       (void) G
 
 void                    gsk_vulkan_push_constants_push                  (VkCommandBuffer                 command_buffer,
                                                                          VkPipelineLayout                pipeline_layout,
+                                                                         const graphene_vec2_t          *scale,
                                                                          const graphene_matrix_t        *mvp,
                                                                          const GskRoundedRect           *clip);
 
index 93a6dd3024e39c47cefefe71e3832f1a0c65db58..ffe9e5bc3d6b57895de9ee49ffa7672323f2a579 100644 (file)
@@ -99,6 +99,7 @@ struct _GskVulkanOpPushConstants
 {
   GskVulkanOpType         type;
   GskRenderNode          *node; /* node that's the source of this op */
+  graphene_vec2_t         scale;
   graphene_matrix_t       mvp;
   GskRoundedRect          clip;
 };
@@ -250,6 +251,7 @@ gsk_vulkan_render_pass_append_push_constants (GskVulkanRenderPass       *self,
   GskVulkanOp op = {
     .constants.type = GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS,
     .constants.node = node,
+    .constants.scale= state->scale,
     .constants.mvp = state->mvp,
     .constants.clip = state->clip.rect,
   };
@@ -2268,6 +2270,7 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass     *self,
           for (int j = 0; j < layout_count; j++)
             gsk_vulkan_push_constants_push (command_buffer,
                                             pipeline_layout[j],
+                                            &op->constants.scale,
                                             &op->constants.mvp,
                                             &op->constants.clip);
 
index 427f42bc1a29de210f9eb2b905eca8a5a4f4d6b7..9fe24ad47537766615cc6443f3006267861f4453 100644 (file)
@@ -6,6 +6,7 @@ layout(push_constant) uniform PushConstants {
     vec4 clip_bounds;
     vec4 clip_widths;
     vec4 clip_heights;
+    vec2 scale;
 } push;
 
 #endif