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);
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;
}
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,
#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;
//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:
}
//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))
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;
#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;
VkRenderPass renderPass;
VkSwapchainKHR swapChain;
- ImageBuffer* ScBuffers;
+ VkhImage* ScBuffers;
VkCommandBuffer* cmdBuffs;
VkFramebuffer* frameBuffs;
}vkh_presenter_t;