WIP create and destroy swapchain
authorEleni Maria Stea <estea@igalia.com>
Fri, 4 Jun 2021 20:08:17 +0000 (23:08 +0300)
committerEleni Maria Stea <estea@igalia.com>
Fri, 4 Jun 2021 20:08:17 +0000 (23:08 +0300)
I might want to move them to vk.[hc]

src/ui.c
src/ui.h

index 13f96fc..fd00364 100644 (file)
--- a/src/ui.c
+++ b/src/ui.c
@@ -1,19 +1,57 @@
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include "ui.h"
 
 bool
 vk_create_swapchain(struct vk_ctx *ctx,
 #include <string.h>
 #include "ui.h"
 
 bool
 vk_create_swapchain(struct vk_ctx *ctx,
+                    int width, int height,
+                    int num_qfam,
                     struct vk_swapchain *swapchain)
 {
     VkSwapchainCreateInfoKHR s_info;
                     struct vk_swapchain *swapchain)
 {
     VkSwapchainCreateInfoKHR s_info;
+    VkExtent2D extent;
+
+    extent.width = width;
+    extent.height = height;
 
     memset(&s_info, 0, sizeof s_info);
 
     memset(&s_info, 0, sizeof s_info);
+
     s_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
     s_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
-    s_info.flags = VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR;
+    s_info.flags = 0;
     s_info.surface = swapchain->surface;
     s_info.minImageCount = 2;
     s_info.surface = swapchain->surface;
     s_info.minImageCount = 2;
+    s_info.imageFormat = VK_FORMAT_R32G32B32A32_SFLOAT;
+    s_info.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
+    s_info.imageExtent = extent;
+    s_info.imageArrayLayers = 1;
+    s_info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
+                        VK_IMAGE_USAGE_SAMPLED_BIT |
+                        VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
+                        VK_IMAGE_USAGE_TRANSFER_DST_BIT;
+
+    s_info.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
+    s_info.queueFamilyIndexCount = num_qfam; /* how many queue families */
+
+    s_info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
+    s_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
+    s_info.presentMode = VK_PRESENT_MODE_FIFO_KHR;
+    s_info.clipped = VK_TRUE;
+    s_info.oldSwapchain = VK_NULL_HANDLE;
 
 
-    // FIXME: to be continued
+    if (vkCreateSwapchainKHR(ctx->dev, &s_info, 0,
+                             &swapchain->swapchain) != VK_SUCCESS) {
+        fprintf(stderr, "Failed to create a swapchain.\n");
+        return false;
+    }
 
     return true;
 }
 
     return true;
 }
+
+void
+vk_destroy_swapchain(struct vk_ctx *ctx,
+                     struct vk_swapchain *swapchain)
+{
+    vkDestroySwapchainKHR(ctx->dev, swapchain->swapchain, 0);
+    vkDestroySurfaceKHR(ctx->inst, swapchain->surface, 0);
+}
index 6cc6713..d26f4f0 100644 (file)
--- a/src/ui.h
+++ b/src/ui.h
@@ -15,6 +15,8 @@ struct vk_swapchain
 /* swapchain */
 bool
 vk_create_swapchain(struct vk_ctx *ctx,
 /* swapchain */
 bool
 vk_create_swapchain(struct vk_ctx *ctx,
+                    int width, int height,
+                    int num_qfam,
                     struct vk_swapchain *swapchain);
 void
 vk_destroy_swapchain(struct vk_ctx *ctx,
                     struct vk_swapchain *swapchain);
 void
 vk_destroy_swapchain(struct vk_ctx *ctx,