vulkan: Only use a single pipeline layout
authorBenjamin Otte <otte@redhat.com>
Fri, 12 May 2023 18:49:31 +0000 (20:49 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 4 Jun 2023 17:42:01 +0000 (19:42 +0200)
There's no need to use 3 different ones when they are compatible.

gsk/vulkan/gskvulkanpipeline.c
gsk/vulkan/gskvulkanpipelineprivate.h
gsk/vulkan/gskvulkanrender.c
gsk/vulkan/gskvulkanrenderpass.c
gsk/vulkan/gskvulkanrenderpassprivate.h

index 0a4a54d8e641a917240edb171bd59f3b217bfe7c..a061ee1335a4e5133ec833fc0c5441bef1213a96 100644 (file)
@@ -16,7 +16,6 @@ struct _GskVulkanPipelinePrivate
   GdkVulkanContext *context;
 
   VkPipeline pipeline;
-  VkPipelineLayout layout;
 
   GskVulkanShader *vertex_shader;
   GskVulkanShader *fragment_shader;
@@ -54,11 +53,11 @@ gsk_vulkan_pipeline_init (GskVulkanPipeline *self)
 }
 
 GskVulkanPipeline *
-gsk_vulkan_pipeline_new (GType                    pipeline_type,
-                         GdkVulkanContext        *context,
-                         VkPipelineLayout         layout,
-                         const char              *shader_name,
-                         VkRenderPass             render_pass)
+gsk_vulkan_pipeline_new (GType             pipeline_type,
+                         GdkVulkanContext *context,
+                         VkPipelineLayout  layout,
+                         const char       *shader_name,
+                         VkRenderPass      render_pass)
 {
   GskVulkanPipelinePrivate *priv;
   GskVulkanPipeline *self;
@@ -76,7 +75,6 @@ gsk_vulkan_pipeline_new (GType                    pipeline_type,
   device = gdk_vulkan_context_get_device (context);
 
   priv->context = context;
-  priv->layout = layout;
 
   priv->vertex_shader = gsk_vulkan_shader_new_from_resource (context, GSK_VULKAN_SHADER_VERTEX, shader_name, NULL);
   priv->fragment_shader = gsk_vulkan_shader_new_from_resource (context, GSK_VULKAN_SHADER_FRAGMENT, shader_name, NULL);
@@ -146,7 +144,7 @@ gsk_vulkan_pipeline_new (GType                    pipeline_type,
                                                        VK_DYNAMIC_STATE_SCISSOR
                                                    },
                                                },
-                                               .layout = priv->layout,
+                                               .layout = layout,
                                                .renderPass = render_pass,
                                                .subpass = 0,
                                                .basePipelineHandle = VK_NULL_HANDLE,
@@ -166,10 +164,3 @@ gsk_vulkan_pipeline_get_pipeline (GskVulkanPipeline *self)
   return priv->pipeline;
 }
 
-VkPipelineLayout
-gsk_vulkan_pipeline_get_pipeline_layout (GskVulkanPipeline *self)
-{
-  GskVulkanPipelinePrivate *priv = gsk_vulkan_pipeline_get_instance_private (self);
-
-  return priv->layout;
-}
index 39df45b8851a1dca9474beacf7201c53f9631292..50b7158526c11708bd31282184ace047d5afbf0a 100644 (file)
@@ -37,7 +37,6 @@ GskVulkanPipeline *     gsk_vulkan_pipeline_new                         (GType
                                                                          const char                     *shader_name,
                                                                          VkRenderPass                    render_pass);
 VkPipeline              gsk_vulkan_pipeline_get_pipeline                (GskVulkanPipeline              *self);
-VkPipelineLayout        gsk_vulkan_pipeline_get_pipeline_layout         (GskVulkanPipeline              *self);
 
 G_END_DECLS
 
index 801128383d3a35b7264ed3462b978d29fe5542de..ca9ffcea5d872306c1101659780215f57178fd94 100644 (file)
@@ -40,7 +40,7 @@ struct _GskVulkanRender
   VkFence fence;
   VkRenderPass render_pass;
   VkDescriptorSetLayout descriptor_set_layout;
-  VkPipelineLayout pipeline_layout[3]; /* indexed by number of textures */
+  VkPipelineLayout pipeline_layout;
   GskVulkanUploader *uploader;
 
   GHashTable *descriptor_set_indexes;
@@ -203,25 +203,19 @@ gsk_vulkan_render_new (GskRenderer      *renderer,
                                              NULL,
                                              &self->descriptor_set_layout);
 
-  for (guint i = 0; i < 3; i++)
-    {
-      VkDescriptorSetLayout layouts[3] = {
-        self->descriptor_set_layout,
-        self->descriptor_set_layout,
-        self->descriptor_set_layout
-      };
-
-      GSK_VK_CHECK (vkCreatePipelineLayout, device,
-                                            &(VkPipelineLayoutCreateInfo) {
-                                                .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
-                                                .setLayoutCount = i,
-                                                .pSetLayouts = layouts,
-                                                .pushConstantRangeCount = gsk_vulkan_push_constants_get_range_count (),
-                                                .pPushConstantRanges = gsk_vulkan_push_constants_get_ranges ()
+  GSK_VK_CHECK (vkCreatePipelineLayout, device,
+                                        &(VkPipelineLayoutCreateInfo) {
+                                            .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
+                                            .setLayoutCount = 2,
+                                            .pSetLayouts = (VkDescriptorSetLayout[2]) {
+                                              self->descriptor_set_layout,
+                                              self->descriptor_set_layout
                                             },
-                                            NULL,
-                                            &self->pipeline_layout[i]);
-    }
+                                            .pushConstantRangeCount = gsk_vulkan_push_constants_get_range_count (),
+                                            .pPushConstantRanges = gsk_vulkan_push_constants_get_ranges ()
+                                        },
+                                        NULL,
+                                        &self->pipeline_layout);
 
   GSK_VK_CHECK (vkCreateSampler, device,
                                  &(VkSamplerCreateInfo) {
@@ -423,7 +417,7 @@ gsk_vulkan_render_get_pipeline (GskVulkanRender       *self,
 
   if (self->pipelines[type] == NULL)
     self->pipelines[type] = pipeline_info[type].create_func (self->vulkan,
-                                                             self->pipeline_layout[pipeline_info[type].num_textures],
+                                                             self->pipeline_layout,
                                                              pipeline_info[type].name,
                                                              self->render_pass);
 
@@ -612,7 +606,7 @@ gsk_vulkan_render_draw (GskVulkanRender *self)
 
       command_buffer = gsk_vulkan_command_pool_get_buffer (self->command_pool);
 
-      gsk_vulkan_render_pass_draw (pass, self, 3, self->pipeline_layout, command_buffer);
+      gsk_vulkan_render_pass_draw (pass, self, self->pipeline_layout, command_buffer);
 
       gsk_vulkan_command_pool_submit_buffer (self->command_pool,
                                              command_buffer,
@@ -718,10 +712,9 @@ gsk_vulkan_render_free (GskVulkanRender *self)
 
   g_clear_pointer (&self->uploader, gsk_vulkan_uploader_free);
 
-  for (i = 0; i < 3; i++)
-    vkDestroyPipelineLayout (device,
-                             self->pipeline_layout[i],
-                             NULL);
+  vkDestroyPipelineLayout (device,
+                           self->pipeline_layout,
+                           NULL);
 
   vkDestroyRenderPass (device,
                        self->render_pass,
index 81ef38927c79cd884e56b06647c37ae496a20bd6..4004570029e57fe4bc89d9205a41341df6e0eadb 100644 (file)
@@ -569,9 +569,11 @@ gsk_vulkan_render_pass_add_transform_node (GskVulkanRenderPass       *self,
         gsk_vulkan_clip_scale (&new_state.clip, &state->clip, scale_x, scale_y);
         new_state.offset.x = (state->offset.x + dx) / scale_x;
         new_state.offset.y = (state->offset.y + dy) / scale_y;
-        graphene_vec2_init (&new_state.scale, scale_x, scale_y);
+        graphene_vec2_init (&new_state.scale, fabs (scale_x), fabs (scale_y));
         graphene_vec2_multiply (&new_state.scale, &state->scale, &new_state.scale);
-        new_state.modelview = gsk_transform_ref (state->modelview);
+        new_state.modelview = gsk_transform_scale (gsk_transform_ref (state->modelview),
+                                                   scale_x / fabs (scale_x),
+                                                   scale_y / fabs (scale_y));
       }
       break;
 
@@ -2028,8 +2030,7 @@ gsk_vulkan_render_pass_reserve_descriptor_sets (GskVulkanRenderPass *self,
 static void
 gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass     *self,
                                   GskVulkanRender         *render,
-                                  guint                    layout_count,
-                                  VkPipelineLayout        *pipeline_layout,
+                                  VkPipelineLayout         pipeline_layout,
                                   VkCommandBuffer          command_buffer)
 {
   GskVulkanPipeline *current_pipeline = NULL;
@@ -2072,7 +2073,7 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
+                                   pipeline_layout,
                                    0,
                                    1,
                                    (VkDescriptorSet[1]) {
@@ -2105,7 +2106,7 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
+                                   pipeline_layout,
                                    0,
                                    1,
                                    (VkDescriptorSet[1]) {
@@ -2138,7 +2139,7 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
+                                   pipeline_layout,
                                    0,
                                    1,
                                    (VkDescriptorSet[1]) {
@@ -2174,7 +2175,7 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
+                                   pipeline_layout,
                                    0,
                                    1,
                                    (VkDescriptorSet[1]) {
@@ -2209,7 +2210,7 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
+                                   pipeline_layout,
                                    0,
                                    1,
                                    (VkDescriptorSet[1]) {
@@ -2317,13 +2318,11 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass     *self,
           break;
 
         case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
-          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);
-
+          gsk_vulkan_push_constants_push (command_buffer,
+                                          pipeline_layout,
+                                          &op->constants.scale,
+                                          &op->constants.mvp,
+                                          &op->constants.clip);
           break;
 
         case GSK_VULKAN_OP_CROSS_FADE:
@@ -2347,7 +2346,7 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
+                                   pipeline_layout,
                                    0,
                                    2,
                                    (VkDescriptorSet[2]) {
@@ -2383,7 +2382,7 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass     *self,
 
           vkCmdBindDescriptorSets (command_buffer,
                                    VK_PIPELINE_BIND_POINT_GRAPHICS,
-                                   gsk_vulkan_pipeline_get_pipeline_layout (current_pipeline),
+                                   pipeline_layout,
                                    0,
                                    2,
                                    (VkDescriptorSet[2]) {
@@ -2406,11 +2405,10 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass     *self,
 }
 
 void
-gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
-                             GskVulkanRender         *render,
-                             guint                    layout_count,
-                             VkPipelineLayout        *pipeline_layout,
-                             VkCommandBuffer          command_buffer)
+gsk_vulkan_render_pass_draw (GskVulkanRenderPass *self,
+                             GskVulkanRender     *render,
+                             VkPipelineLayout     pipeline_layout,
+                             VkCommandBuffer      command_buffer)
 {
   guint i;
 
@@ -2456,7 +2454,7 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass     *self,
                             },
                             VK_SUBPASS_CONTENTS_INLINE);
 
-      gsk_vulkan_render_pass_draw_rect (self, render, layout_count, pipeline_layout, command_buffer);
+      gsk_vulkan_render_pass_draw_rect (self, render, pipeline_layout, command_buffer);
 
       vkCmdEndRenderPass (command_buffer);
     }
index 049b579b605d52a9968a6e620e416c37048e1fa3..18b1be1b40cefd9111f39092f07950b057281f45 100644 (file)
@@ -30,8 +30,7 @@ void                    gsk_vulkan_render_pass_reserve_descriptor_sets  (GskVulk
                                                                          GskVulkanRender        *render);
 void                    gsk_vulkan_render_pass_draw                     (GskVulkanRenderPass    *self,
                                                                          GskVulkanRender        *render,
-                                                                         guint                   layout_count,
-                                                                         VkPipelineLayout       *pipeline_layout,
+                                                                         VkPipelineLayout        pipeline_layout,
                                                                          VkCommandBuffer         command_buffer);
 gsize                   gsk_vulkan_render_pass_get_wait_semaphores      (GskVulkanRenderPass    *self,
                                                                          VkSemaphore           **semaphores);