[metacity] vulkan: create framebuffers
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] vulkan: create framebuffers
- Date: Thu, 16 Mar 2017 19:13:09 +0000 (UTC)
commit 7e0c4df3a88763c54f431138960bdd63a95be5f1
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Thu Mar 16 20:28:31 2017 +0200
vulkan: create framebuffers
src/compositor/meta-compositor-vulkan.c | 81 +++++++++++++++++++++++++++++--
1 files changed, 76 insertions(+), 5 deletions(-)
---
diff --git a/src/compositor/meta-compositor-vulkan.c b/src/compositor/meta-compositor-vulkan.c
index 2653ab7..4b2d3b1 100644
--- a/src/compositor/meta-compositor-vulkan.c
+++ b/src/compositor/meta-compositor-vulkan.c
@@ -42,6 +42,7 @@ struct _MetaCompositorVulkan
VkSurfaceKHR surface;
VkSurfaceFormatKHR surface_format;
+ VkExtent2D surface_extent;
VkPhysicalDevice physical_device;
uint32_t graphics_family_index;
@@ -65,6 +66,9 @@ struct _MetaCompositorVulkan
VkImageView *image_views;
VkRenderPass render_pass;
+
+ uint32_t n_framebuffers;
+ VkFramebuffer *framebuffers;
#endif
};
@@ -72,6 +76,67 @@ G_DEFINE_TYPE (MetaCompositorVulkan, meta_compositor_vulkan, META_TYPE_COMPOSITO
#ifdef HAVE_VULKAN
static void
+destroy_framebuffers (MetaCompositorVulkan *vulkan)
+{
+ uint32_t i;
+
+ if (vulkan->framebuffers == NULL)
+ return;
+
+ for (i = 0; i < vulkan->n_framebuffers; i++)
+ vkDestroyFramebuffer (vulkan->device, vulkan->framebuffers[i], NULL);
+
+ g_clear_pointer (&vulkan->framebuffers, g_free);
+
+ vulkan->n_framebuffers = 0;
+}
+
+static gboolean
+create_framebuffers (MetaCompositorVulkan *vulkan,
+ GError **error)
+{
+ uint32_t i;
+ VkFramebufferCreateInfo info;
+ VkResult result;
+
+ destroy_framebuffers (vulkan);
+
+ vulkan->framebuffers = g_new0 (VkFramebuffer, vulkan->n_images);
+
+ for (i = 0; i < vulkan->n_images; i++)
+ {
+ VkImageView attachments[1];
+
+ attachments[0] = vulkan->image_views[i];
+
+ info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
+ info.pNext = NULL;
+ info.flags = 0;
+ info.renderPass = vulkan->render_pass;
+ info.attachmentCount = 1;
+ info.pAttachments = attachments;
+ info.width = vulkan->surface_extent.width;
+ info.height = vulkan->surface_extent.height;
+ info.layers = 1;
+
+ result = vkCreateFramebuffer (vulkan->device, &info, NULL,
+ &vulkan->framebuffers[i]);
+
+ if (result != VK_SUCCESS)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Failed to create framebuffer");
+
+ return FALSE;
+ }
+
+ vulkan->n_framebuffers++;
+ }
+
+ return TRUE;
+}
+
+static void
destroy_render_pass (MetaCompositorVulkan *vulkan)
{
if (vulkan->render_pass != VK_NULL_HANDLE)
@@ -245,8 +310,10 @@ create_swapchain (MetaCompositorVulkan *vulkan,
return FALSE;
}
- if (capabilities.currentExtent.width == 0xffffffff &&
- capabilities.currentExtent.height == 0xffffffff)
+ vulkan->surface_extent = capabilities.currentExtent;
+
+ if (vulkan->surface_extent.width == 0xffffffff &&
+ vulkan->surface_extent.height == 0xffffffff)
{
MetaDisplay *display;
gint width;
@@ -256,8 +323,8 @@ create_swapchain (MetaCompositorVulkan *vulkan,
meta_screen_get_size (display->screen, &width, &height);
- capabilities.currentExtent.width = width;
- capabilities.currentExtent.height = height;
+ vulkan->surface_extent.width = width;
+ vulkan->surface_extent.height = height;
}
info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
@@ -267,7 +334,7 @@ create_swapchain (MetaCompositorVulkan *vulkan,
info.minImageCount = capabilities.minImageCount;
info.imageFormat = vulkan->surface_format.format;
info.imageColorSpace = vulkan->surface_format.colorSpace;
- info.imageExtent = capabilities.currentExtent;
+ info.imageExtent = vulkan->surface_extent;
info.imageArrayLayers = 1;
info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
info.preTransform = capabilities.currentTransform;
@@ -1018,6 +1085,7 @@ meta_compositor_vulkan_finalize (GObject *object)
vulkan = META_COMPOSITOR_VULKAN (object);
+ destroy_framebuffers (vulkan);
destroy_render_pass (vulkan);
destroy_image_views (vulkan);
destroy_swapchain (vulkan);
@@ -1137,6 +1205,9 @@ meta_compositor_vulkan_manage (MetaCompositor *compositor,
if (!create_render_pass (vulkan, error))
return FALSE;
+ if (!create_framebuffers (vulkan, error))
+ return FALSE;
+
g_timeout_add (10000, (GSourceFunc) not_implemented_cb, vulkan);
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]