[gtk+/wip/otte/vulkan: 33/36] gskvulkan: Create render pass and command pool



commit ee5deec8f1875830b3c109d2f2c8497efc3b71d9
Author: Benjamin Otte <otte redhat com>
Date:   Wed Nov 30 03:59:28 2016 +0100

    gskvulkan: Create render pass and command pool

 gdk/gdkvulkancontext.c  |    8 +++++
 gdk/gdkvulkancontext.h  |    2 +
 gsk/gskvulkanrenderer.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 0 deletions(-)
---
diff --git a/gdk/gdkvulkancontext.c b/gdk/gdkvulkancontext.c
index dd76dfe..5b6082d 100644
--- a/gdk/gdkvulkancontext.c
+++ b/gdk/gdkvulkancontext.c
@@ -357,6 +357,14 @@ gdk_vulkan_context_get_queue (GdkVulkanContext *context)
   return gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context))->vk_queue;
 }
 
+uint32_t
+gdk_vulkan_context_get_queue_family_index (GdkVulkanContext *context)
+{
+  g_return_val_if_fail (GDK_IS_VULKAN_CONTEXT (context), 0);
+
+  return gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context))->vk_queue_family_index;
+}
+
 VkFormat
 gdk_vulkan_context_get_image_format (GdkVulkanContext *context)
 {
diff --git a/gdk/gdkvulkancontext.h b/gdk/gdkvulkancontext.h
index b40257b..2690048 100644
--- a/gdk/gdkvulkancontext.h
+++ b/gdk/gdkvulkancontext.h
@@ -60,6 +60,8 @@ VkDevice                gdk_vulkan_context_get_device               (GdkVulkanCo
 GDK_AVAILABLE_IN_3_90
 VkQueue                 gdk_vulkan_context_get_queue                (GdkVulkanContext  *context);
 GDK_AVAILABLE_IN_3_90
+uint32_t                gdk_vulkan_context_get_queue_family_index   (GdkVulkanContext  *context);
+GDK_AVAILABLE_IN_3_90
 VkFormat                gdk_vulkan_context_get_image_format         (GdkVulkanContext  *context);
 GDK_AVAILABLE_IN_3_90
 guint                   gdk_vulkan_context_get_n_images             (GdkVulkanContext  *context);
diff --git a/gsk/gskvulkanrenderer.c b/gsk/gskvulkanrenderer.c
index 19dc2e8..dc8cffe 100644
--- a/gsk/gskvulkanrenderer.c
+++ b/gsk/gskvulkanrenderer.c
@@ -25,7 +25,9 @@ struct _GskVulkanRenderer
 
   guint n_targets;
   GskVulkanTarget **targets;
+
   VkRenderPass render_pass;
+  VkCommandPool command_pool;
 
 #ifdef G_ENABLE_DEBUG
   ProfileTimers profile_timers;
@@ -165,11 +167,64 @@ gsk_vulkan_renderer_realize (GskRenderer  *renderer,
                              GError      **error)
 {
   GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
+  VkDevice device;
 
   self->vulkan = gdk_window_create_vulkan_context (window, error);
   if (self->vulkan == NULL)
     return FALSE;
 
+  device = gdk_vulkan_context_get_device (self->vulkan);
+
+  GSK_VK_CHECK (vkCreateRenderPass, gdk_vulkan_context_get_device (self->vulkan),
+                                    &(VkRenderPassCreateInfo) {
+                                        .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
+                                        .attachmentCount = 1,
+                                        .pAttachments = (VkAttachmentDescription[]) {
+                                           {
+                                              .format = gdk_vulkan_context_get_image_format (self->vulkan),
+                                              .samples = VK_SAMPLE_COUNT_1_BIT,
+                                              .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
+                                              .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
+                                              .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
+                                              .finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
+                                           }
+                                        },
+                                        .subpassCount = 1,
+                                        .pSubpasses = (VkSubpassDescription []) {
+                                           {
+                                              .pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
+                                              .inputAttachmentCount = 0,
+                                              .colorAttachmentCount = 1,
+                                              .pColorAttachments = (VkAttachmentReference []) {
+                                                 {
+                                                    .attachment = 0,
+                                                     .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
+                                                  }
+                                               },
+                                               .pResolveAttachments = (VkAttachmentReference []) {
+                                                  {
+                                                     .attachment = VK_ATTACHMENT_UNUSED,
+                                                     .layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
+                                                  }
+                                               },
+                                               .pDepthStencilAttachment = NULL,
+                                               .preserveAttachmentCount = 1,
+                                               .pPreserveAttachments = (uint32_t []) { 0 },
+                                            }
+                                         },
+                                         .dependencyCount = 0
+                                      },
+                                      NULL,
+                                      &self->render_pass);
+   GSK_VK_CHECK (vkCreateCommandPool, device,
+                                      &(const VkCommandPoolCreateInfo) {
+                                          .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
+                                          .queueFamilyIndex = gdk_vulkan_context_get_queue_family_index 
(self->vulkan),
+                                          .flags = 0
+                                      },
+                                      NULL,
+                                      &self->command_pool);
+
   g_signal_connect (self->vulkan,
                     "images-updated",
                     G_CALLBACK (gsk_vulkan_renderer_update_images_cb),
@@ -183,11 +238,25 @@ static void
 gsk_vulkan_renderer_unrealize (GskRenderer *renderer)
 {
   GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
+  VkDevice device;
+
+  device = gdk_vulkan_context_get_device (self->vulkan);
 
   gsk_vulkan_renderer_free_targets (self);
   g_signal_handlers_disconnect_by_func(self->vulkan,
                                        gsk_vulkan_renderer_update_images_cb,
                                        self);
+
+  vkDestroyCommandPool (device,
+                        self->command_pool,
+                        NULL);
+  self->command_pool = VK_NULL_HANDLE;
+
+  vkDestroyRenderPass (device,
+                       self->render_pass,
+                       NULL);
+  self->render_pass = VK_NULL_HANDLE;
+
   g_clear_object (&self->vulkan);
 }
 


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