From: John Tsiombikas Date: Tue, 16 Aug 2022 04:06:05 +0000 (+0300) Subject: queue family selection X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=8a6eea3132749f35860b2bc7c4434cde8955b3de;p=vktest3 queue family selection --- diff --git a/src/vk.c b/src/vk.c index ca03b35..82b1ccf 100644 --- a/src/vk.c +++ b/src/vk.c @@ -65,9 +65,9 @@ static int initflags; static VkInstance vk; static VkPhysicalDevice vkpdev; -static int vkqfam_idx, vkqfam_maxq; +static VkQueueFamilyProperties *qfam; +static uint32_t num_qfam; static VkDevice vkdev; -static VkQueue vkq; static VkSurfaceKHR vksurf; static VkSurfaceCapabilitiesKHR vksurf_caps; static int vksurf_numfmt, vksurf_selfmt; @@ -176,6 +176,51 @@ int vk_reshape(int xsz, int ysz) return 0; } +int vk_find_qfamily(unsigned int flags) +{ + int i, famidx = -1; + VkBool32 can_pres; + + if(!qfam) return -1; /* not initialized I guess... */ + + for(i=0; i= qfam[fam].queueCount) { + fprintf(stderr, "vk_getq_fam: invalid index %d, family %d has %d queues\n", + n, fam, qfam[fam].queueCount); + return 0; + } + + vkGetDeviceQueue(vkdev, fam, n, &q); + return q; +} + +VkQueue vk_getq(unsigned int flags) +{ + return vk_getq_fam(vk_find_qfamily(flags), 0); +} int vk_create_rpass(void) { @@ -557,10 +602,9 @@ static int create_surface(void) int choose_phys_dev(void) { - uint32_t i, num_pdev, num_qfam, score, best_score, best_dev; + uint32_t i, num_pdev, score, best_score, best_dev; VkPhysicalDevice *pdev; VkPhysicalDeviceProperties pdevprop; - VkQueueFamilyProperties *qfam; VkBool32 can_pres; vkEnumeratePhysicalDevices(vk, &num_pdev, 0); @@ -591,21 +635,12 @@ int choose_phys_dev(void) } vkpdev = pdev[best_dev]; + if(qfam) free(qfam); + vkGetPhysicalDeviceQueueFamilyProperties(vkpdev, &num_qfam, 0); qfam = malloc_nf(num_qfam * sizeof *qfam); vkGetPhysicalDeviceQueueFamilyProperties(vkpdev, &num_qfam, qfam); - vkqfam_idx = -1; - for(i=0; i