+++ /dev/null
-#include <stdio.h>
-#include <stdlib.h>
-#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;
- VkExtent2D extent;
-
- extent.width = width;
- extent.height = height;
-
- memset(&s_info, 0, sizeof s_info);
-
- s_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
- s_info.flags = 0;
- 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;
-
- if (vkCreateSwapchainKHR(ctx->dev, &s_info, 0,
- &swapchain->swapchain) != VK_SUCCESS) {
- fprintf(stderr, "Failed to create a swapchain.\n");
- return false;
- }
-
- 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);
-}
+++ /dev/null
-#ifndef UI_H
-#define UI_H
-
-#include "vk.h"
-
-struct vk_swapchain
-{
- VkSwapchainKHR swapchain;
- VkSurfaceKHR surface;
- VkSurfaceFormatKHR surf_fmt;
- uint32_t num_images;
- VkExtent2D extent2d;
-};
-
-/* 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);
-
-#endif /* UI_H */
vkQueueWaitIdle(ctx->queue);
}
+bool
+vk_create_swapchain(struct vk_ctx *ctx,
+ int width, int height,
+ int num_qfam,
+ struct vk_swapchain *swapchain)
+{
+ VkSwapchainCreateInfoKHR s_info;
+ VkExtent2D extent;
+
+ extent.width = width;
+ extent.height = height;
+
+ memset(&s_info, 0, sizeof s_info);
+
+ s_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
+ s_info.flags = 0;
+ 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;
+
+ if (vkCreateSwapchainKHR(ctx->dev, &s_info, 0,
+ &swapchain->swapchain) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to create a swapchain.\n");
+ return false;
+ }
+
+ 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);
+}
+
void
vk_copy_image_to_buffer(struct vk_ctx *ctx,
struct vk_image_att *src_img,
uint8_t driverUUID[VK_UUID_SIZE];
};
+struct vk_swapchain
+{
+ VkSwapchainKHR swapchain;
+ VkSurfaceKHR surface;
+ VkSurfaceFormatKHR surf_fmt;
+ uint32_t num_images;
+ VkExtent2D extent2d;
+};
+
struct vk_image_props
{
uint32_t w;
uint32_t n_attachments,
float x, float y, float w, float h);
+/* 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);
+
/* transitions */
void