From 94331082a09c8093ae70352f291781b3c2391430 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Mon, 30 Apr 2018 05:57:06 +0200 Subject: [PATCH] presentation queue detection, vkhImage for swap chain imgs --- include/vkh.h | 4 ++-- src/vkh_app.c | 4 ++-- src/vkh_image.c | 10 ++++++++++ src/vkh_phyinfo.c | 25 ++++++++++++++++++++----- src/vkh_phyinfo.h | 7 ++++--- src/vkh_presenter.h | 9 ++------- 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/include/vkh.h b/include/vkh.h index 56a5531..e53ceaa 100644 --- a/include/vkh.h +++ b/include/vkh.h @@ -60,12 +60,12 @@ VkhApp vkh_app_create (const char* app_name, int ext_count, co void vkh_app_destroy (VkhApp app); VkInstance vkh_app_get_inst (VkhApp app); VkPhysicalDevice vkh_app_select_phy (VkhApp app, VkPhysicalDeviceType preferedPhyType); -VkhPhyInfo* vkh_app_get_phyinfos (VkhApp app, uint32_t* count); +VkhPhyInfo* vkh_app_get_phyinfos (VkhApp app, uint32_t* count, VkSurfaceKHR surface); void vkh_app_free_phyinfos (uint32_t count, VkhPhyInfo* infos); VkPhysicalDeviceProperties vkh_app_get_phy_properties (VkhApp app, uint32_t phyIndex); // VkhPhy -VkhPhyInfo vkh_phyinfo_create (VkhApp app, VkPhysicalDevice phy); +VkhPhyInfo vkh_phyinfo_create (VkhApp app, VkPhysicalDevice phy, VkSurfaceKHR surface); void vkh_phyinfo_destroy (VkhPhyInfo phy); // VkhDevice VkhDevice vkh_device_create (VkPhysicalDevice phy, VkDevice vkDev); diff --git a/src/vkh_app.c b/src/vkh_app.c index 0f7c476..e47ae48 100644 --- a/src/vkh_app.c +++ b/src/vkh_app.c @@ -61,14 +61,14 @@ VkInstance vkh_app_get_inst (VkhApp app) { return app->inst; } -VkhPhyInfo* vkh_app_get_phyinfos (VkhApp app, uint32_t* count) { +VkhPhyInfo* vkh_app_get_phyinfos (VkhApp app, uint32_t* count, VkSurfaceKHR surface) { VK_CHECK_RESULT(vkEnumeratePhysicalDevices (app->inst, count, NULL)); VkPhysicalDevice phyDevices[(*count)]; VK_CHECK_RESULT(vkEnumeratePhysicalDevices (app->inst, count, phyDevices)); VkhPhyInfo* infos = (VkhPhyInfo*)malloc((*count) * sizeof(VkhPhyInfo)); for (int i=0; i<(*count); i++) - infos[i] = vkh_phyinfo_create (app, phyDevices[i]); + infos[i] = vkh_phyinfo_create (app, phyDevices[i], surface); return infos; } diff --git a/src/vkh_image.c b/src/vkh_image.c index 1281535..abd9f37 100644 --- a/src/vkh_image.c +++ b/src/vkh_image.c @@ -74,6 +74,16 @@ VkhImage vkh_image_create (VkhDevice pDev, return _vkh_image_create (pDev, VK_IMAGE_TYPE_2D, format, width, height, memprops,usage, VK_SAMPLE_COUNT_1_BIT, tiling, 1, 1); } +//create vkhImage from existing VkImage +VkhImage vkh_image_import (VkhDevice pDev, VkImage vkImg, VkFormat format, uint32_t width, uint32_t height) { + VkhImage img = (VkhImage)calloc(1,sizeof(vkh_image_t)); + img->pDev = pDev; + img->image = vkImg; + img->format = format; + img->width = width; + img->height = height; + return img; +} VkhImage vkh_image_ms_create(VkhDevice pDev, VkFormat format, VkSampleCountFlagBits num_samples, uint32_t width, uint32_t height, VkMemoryPropertyFlags memprops, diff --git a/src/vkh_phyinfo.c b/src/vkh_phyinfo.c index be1d4db..65c8fbb 100644 --- a/src/vkh_phyinfo.c +++ b/src/vkh_phyinfo.c @@ -23,7 +23,7 @@ #include "vkh_app.h" -VkhPhyInfo vkh_phyinfo_create (VkhApp app, VkPhysicalDevice phy) { +VkhPhyInfo vkh_phyinfo_create (VkhApp app, VkPhysicalDevice phy, VkSurfaceKHR surface) { VkhPhyInfo pi = (vkh_phy_t*)calloc(1, sizeof(vkh_phy_t)); pi->phy = phy; @@ -36,15 +36,22 @@ VkhPhyInfo vkh_phyinfo_create (VkhApp app, VkPhysicalDevice phy) { //identify dedicated queues - //try to find dedicated queues pi->cQueue = -1; pi->gQueue = -1; pi->tQueue = -1; + pi->pQueue = -1; + //try to find dedicated queues first for (int j=0; jqueueCount; j++){ + VkBool32 present = VK_FALSE; switch (pi->queues[j].queueFlags) { case VK_QUEUE_GRAPHICS_BIT: - if (pi->gQueue<0) + if (surface) + vkGetPhysicalDeviceSurfaceSupportKHR(phy, j, surface, &present); + if (present){ + if (pi->pQueue<0) + pi->pQueue = j; + }else if (pi->gQueue<0) pi->gQueue = j; break; case VK_QUEUE_COMPUTE_BIT: @@ -59,8 +66,16 @@ VkhPhyInfo vkh_phyinfo_create (VkhApp app, VkPhysicalDevice phy) { } //try to find suitable queue if no dedicated one found for (int j=0; jqueueCount; j++){ - if ((pi->queues[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) && (pi->gQueue < 0)) - pi->gQueue = j; + if (pi->queues[j].queueFlags & VK_QUEUE_GRAPHICS_BIT) { + VkBool32 present; + if (surface) + vkGetPhysicalDeviceSurfaceSupportKHR(phy, j, surface, &present); + if (present){ + if (pi->pQueue<0) + pi->pQueue = j; + }else if (pi->gQueue<0) + pi->gQueue = j; + } if ((pi->queues[j].queueFlags & VK_QUEUE_COMPUTE_BIT) && (pi->cQueue < 0)) pi->cQueue = j; if ((pi->queues[j].queueFlags & VK_QUEUE_TRANSFER_BIT) && (pi->tQueue < 0)) diff --git a/src/vkh_phyinfo.h b/src/vkh_phyinfo.h index 1843117..cf1fcea 100644 --- a/src/vkh_phyinfo.h +++ b/src/vkh_phyinfo.h @@ -30,9 +30,10 @@ typedef struct _vkh_phy_t{ VkPhysicalDeviceProperties properties; VkQueueFamilyProperties* queues; uint32_t queueCount; - int cQueue; - int gQueue; - int tQueue; + int cQueue;//compute + int gQueue;//graphic + int tQueue;//transfer + int pQueue;//presentation uint32_t qCreateInfosCount; VkDeviceQueueCreateInfo* qCreateInfos; diff --git a/src/vkh_presenter.h b/src/vkh_presenter.h index 99f48b1..1e553ef 100644 --- a/src/vkh_presenter.h +++ b/src/vkh_presenter.h @@ -24,18 +24,13 @@ #include "vkh.h" -typedef struct ImageBuffer_t { - VkImage image; - VkImageView view; -}ImageBuffer; - typedef struct _vkh_presenter_t { VkQueue queue; VkCommandPool cmdPool; uint32_t qFam; VkDevice dev; - //GLFWwindow* window; + void* window; VkSurfaceKHR surface; VkSemaphore semaPresentEnd; @@ -52,7 +47,7 @@ typedef struct _vkh_presenter_t { VkRenderPass renderPass; VkSwapchainKHR swapChain; - ImageBuffer* ScBuffers; + VkhImage* ScBuffers; VkCommandBuffer* cmdBuffs; VkFramebuffer* frameBuffs; }vkh_presenter_t; -- 2.47.3