]> O.S.I.I.S - jp/vkhelpers.git/commitdiff
presentation queue detection, vkhImage for swap chain imgs
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 30 Apr 2018 03:57:06 +0000 (05:57 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 30 Apr 2018 03:57:06 +0000 (05:57 +0200)
include/vkh.h
src/vkh_app.c
src/vkh_image.c
src/vkh_phyinfo.c
src/vkh_phyinfo.h
src/vkh_presenter.h

index 56a55317abb12e7e2dfd33d03c164efa9ddb06d7..e53ceaa876f409143ba9c64aa9aca6194b331416 100644 (file)
@@ -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);
index 0f7c47634a76955c622e734b521e82b456ccb153..e47ae48e835e7e9c1a02b15de34dcdf2b1fba652 100644 (file)
@@ -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;
 }
index 1281535c227ebfba57413a1805d7e6ad37e71dba..abd9f3705db812c951cb75daa5c079c4316047ef 100644 (file)
@@ -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,
index be1d4db0e7b2e4666d4cf74eae73db986ed90782..65c8fbb31dc57bd48e9f6c6ad33a5e09de912b9c 100644 (file)
@@ -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; j<pi->queueCount; 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; j<pi->queueCount; 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))
index 18431174902642af450b960f25e53c439a8afb12..cf1fceaf0883654d5c3d78e3a2e97c6d50dad061 100644 (file)
@@ -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;
index 99f48b17242ada93e85683742b985285c3d63005..1e553effebea7d504e75d97dbffd8307d16e18d4 100644 (file)
 
 #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;