From: Jean-Philippe Bruyère Date: Tue, 17 Apr 2018 14:26:48 +0000 (+0200) Subject: VkhPhyInfos X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=6c5d18209e6050a1b5ce7cf8d03dc602dc1b7d2c;p=jp%2Fvkhelpers.git VkhPhyInfos --- diff --git a/README.md b/README.md index 5484cdf..186d4a4 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ ### What is vkh? **vkh** is a multiplatform helper library for [Vulkan](https://www.khronos.org/vulkan/) written in **c**. - vkh main goal is to offer an api which will ease the development of wrappers for higher level languages. No additional library except vulkan is required. diff --git a/include/vkh.h b/include/vkh.h index 08c0190..9b43f05 100644 --- a/include/vkh.h +++ b/include/vkh.h @@ -1,6 +1,10 @@ #ifndef VK_HELPERS_H #define VK_HELPERS_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include @@ -23,19 +27,26 @@ } typedef struct _vkh_app_t* VkhApp; +typedef struct _vkh_phy_t* VkhPhyInfo; typedef struct _vkh_device_t* VkhDevice; typedef struct _vkh_image_t* VkhImage; typedef struct _vkh_buffer_t* VkhBuffer; typedef struct _vkh_queue_t* VkhQueue; //typedef struct _vkh_presenter_t* VkhPresenter; -/////////////////// +// VkhApp VkhApp vkh_app_create (const char* app_name, int ext_count, const char* extentions[]); 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); +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); +void vkh_phyinfo_destroy (VkhPhyInfo phy); +// VkhImage VkhImage vkh_image_create (VkhDevice pDev, VkFormat format, uint32_t width, uint32_t height, VkImageTiling tiling, VkMemoryPropertyFlags memprops, VkImageUsageFlags usage); VkhImage vkh_image_ms_create (VkhDevice pDev, VkFormat format, VkSampleCountFlagBits num_samples, uint32_t width, uint32_t height, @@ -60,7 +71,7 @@ VkImageView vkh_image_get_view (VkhImage img); VkImageLayout vkh_image_get_layout (VkhImage img); VkSampler vkh_image_get_sampler (VkhImage img); VkDescriptorImageInfo vkh_image_get_descriptor(VkhImage img, VkImageLayout imageLayout); -//////////////////////////////// +// VkhBuffer VkhBuffer vkh_buffer_create (VkhDevice pDev, VkBufferUsageFlags usage, VkMemoryPropertyFlags memoryPropertyFlags, VkDeviceSize size); void vkh_buffer_destroy (VkhBuffer buff); @@ -80,8 +91,8 @@ VkCommandPool vkh_cmd_pool_create (VkDevice dev, uint32_t qFamIndex, VkCommand VkCommandBuffer vkh_cmd_buff_create (VkDevice dev, VkCommandPool cmdPool, VkCommandBufferLevel level); void vkh_cmd_begin (VkCommandBuffer cmdBuff, VkCommandBufferUsageFlags flags); void vkh_cmd_end (VkCommandBuffer cmdBuff); -void vkh_cmd_submit (VkQueue queue, VkCommandBuffer *pCmdBuff, VkFence fence); -void vkh_cmd_submit_with_semaphores(VkQueue queue, VkCommandBuffer *pCmdBuff, VkSemaphore waitSemaphore, +void vkh_cmd_submit (VkhQueue queue, VkCommandBuffer *pCmdBuff, VkFence fence); +void vkh_cmd_submit_with_semaphores(VkhQueue queue, VkCommandBuffer *pCmdBuff, VkSemaphore waitSemaphore, VkSemaphore signalSemaphore, VkFence fence); VkShaderModule vkh_load_module(VkDevice dev, const char* path); @@ -102,4 +113,9 @@ VkhQueue vkh_queue_create (VkhDevice dev, uint32_t familyIndex, uint32_t q void vkh_queue_destroy (VkhQueue queue); VkhQueue vkh_queue_find (VkhDevice dev, VkQueueFlags flags); ///////////////////// + +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/vkh_app.c b/src/vkh_app.c index 9836d9c..7810bc3 100644 --- a/src/vkh_app.c +++ b/src/vkh_app.c @@ -29,9 +29,6 @@ VkhApp vkh_app_create (const char* app_name, int ext_count, const char* extentio .ppEnabledLayerNames = enabledLayers }; VK_CHECK_RESULT(vkCreateInstance (&inst_info, NULL, &app->inst)); - - VK_CHECK_RESULT(vkEnumeratePhysicalDevices (app->inst, &app->phyCount, NULL)); - return app; } @@ -44,23 +41,41 @@ VkInstance vkh_app_get_inst (VkhApp app) { return app->inst; } -VkPhysicalDevice vkh_app_select_phy (VkhApp app, VkPhysicalDeviceType preferedPhyType) { - VkPhysicalDevice phys[app->phyCount]; - VK_CHECK_RESULT(vkEnumeratePhysicalDevices (app->inst, &app->phyCount, &phys)); +VkhPhyInfo* vkh_app_get_phyinfos (VkhApp app, uint32_t* count) { + 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]); + + return infos; +} - if (app->phyCount == 1) - return phys[0]; +void vkh_app_free_phyinfos (uint32_t count, VkhPhyInfo* infos) { + for (int i=0; iphyCount == 1) + return app->phyDevices[0]; for (int i=0; iphyCount; i++){ VkPhysicalDeviceProperties phy; - vkGetPhysicalDeviceProperties (phys[i], &phy); + vkGetPhysicalDeviceProperties (app->phyDevices[i], &phy); if (phy.deviceType & preferedPhyType){ +#if DEBUG printf ("GPU: %s vulkan:%d.%d.%d driver:%d\n", phy.deviceName, phy.apiVersion>>22, phy.apiVersion>>12&2048, phy.apiVersion&8191, phy.driverVersion); - return phys[i]; +#endif + return app->phyDevices[i]; } } fprintf (stderr, "No suitable GPU found\n"); - exit (-1); + exit (-1);*/ } diff --git a/src/vkh_app.h b/src/vkh_app.h index e39b851..c937a4b 100644 --- a/src/vkh_app.h +++ b/src/vkh_app.h @@ -6,6 +6,5 @@ typedef struct _vkh_app_t{ VkApplicationInfo infos; VkInstance inst; - uint32_t phyCount; }vkh_app_t; #endif diff --git a/src/vkh_device.c b/src/vkh_device.c index debfffb..cd64644 100644 --- a/src/vkh_device.c +++ b/src/vkh_device.c @@ -1 +1,2 @@ #include "vkh_device.h" + diff --git a/src/vkh_phyinfo.c b/src/vkh_phyinfo.c new file mode 100644 index 0000000..e5a92f4 --- /dev/null +++ b/src/vkh_phyinfo.c @@ -0,0 +1,60 @@ +#include "vkh_phyinfo.h" +#include "vkh_app.h" + + +VkhPhyInfo vkh_phyinfo_create (VkhApp app, VkPhysicalDevice phy) { + VkhPhyInfo pi = (vkh_phy_t*)calloc(1, sizeof(vkh_phy_t)); + pi->phy = phy; + + vkGetPhysicalDeviceProperties (phy, &pi->properties); + vkGetPhysicalDeviceMemoryProperties (phy, &pi->memProps); + + vkGetPhysicalDeviceQueueFamilyProperties (phy, &pi->queueCount, NULL); + pi->queues = (VkQueueFamilyProperties*)malloc(pi->queueCount * sizeof(VkQueueFamilyProperties)); + vkGetPhysicalDeviceQueueFamilyProperties (phy, &pi->queueCount, pi->queues); + + //identify dedicated queues + + //try to find dedicated queues + pi->cQueue = -1; + pi->gQueue = -1; + pi->tQueue = -1; + + for (int j=0; jqueueCount; j++){ + switch (pi->queues[j].queueFlags) { + case VK_QUEUE_GRAPHICS_BIT: + if (pi->gQueue<0) + pi->gQueue = j; + break; + case VK_QUEUE_COMPUTE_BIT: + if (pi->cQueue<0) + pi->cQueue = j; + break; + case VK_QUEUE_TRANSFER_BIT: + if (pi->tQueue<0) + pi->tQueue = j; + break; + } + } + //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_COMPUTE_BIT) && (pi->cQueue < 0)) + pi->cQueue = j; + if ((pi->queues[j].queueFlags & VK_QUEUE_TRANSFER_BIT) && (pi->tQueue < 0)) + pi->tQueue = j; + } + + return pi; +} + +void vkh_phyinfo_destroy (VkhPhyInfo phy) { + + free(phy->queues); + free(phy); +} + +void vkh_phyinfo_select_queue (VkhPhyInfo phy, uint32_t qIndex, float* priorities) { + +} diff --git a/src/vkh_phyinfo.h b/src/vkh_phyinfo.h new file mode 100644 index 0000000..9e99101 --- /dev/null +++ b/src/vkh_phyinfo.h @@ -0,0 +1,19 @@ +#ifndef VKH_PHY_H +#define VKH_PHY_H + +#include "vkh.h" + +typedef struct _vkh_phy_t{ + VkPhysicalDevice phy; + VkPhysicalDeviceMemoryProperties memProps; + VkPhysicalDeviceProperties properties; + VkQueueFamilyProperties* queues; + uint32_t queueCount; + int cQueue; + int gQueue; + int tQueue; + + uint32_t qCreateInfosCount; + VkDeviceQueueCreateInfo* qCreateInfos; +}vkh_phy_t; +#endif diff --git a/src/vkhelpers.c b/src/vkhelpers.c index 762b104..033abd9 100644 --- a/src/vkhelpers.c +++ b/src/vkhelpers.c @@ -1,4 +1,4 @@ - +#include "vkh_queue.h" #include "vkh.h" VkFence vkh_fence_create (VkDevice dev) { @@ -56,13 +56,15 @@ void vkh_cmd_begin(VkCommandBuffer cmdBuff, VkCommandBufferUsageFlags flags) { void vkh_cmd_end(VkCommandBuffer cmdBuff){ VK_CHECK_RESULT (vkEndCommandBuffer (cmdBuff)); } -void vkh_cmd_submit(VkQueue queue, VkCommandBuffer *pCmdBuff, VkFence fence){ +void vkh_cmd_submit(VkhQueue queue, VkCommandBuffer *pCmdBuff, VkFence fence){ + VkPipelineStageFlags stageFlags = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; VkSubmitInfo submit_info = { .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, + .pWaitDstStageMask = &stageFlags, .commandBufferCount = 1, .pCommandBuffers = pCmdBuff}; - VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submit_info, fence)); + VK_CHECK_RESULT(vkQueueSubmit(queue->queue, 1, &submit_info, fence)); } -void vkh_cmd_submit_with_semaphores(VkQueue queue, VkCommandBuffer *pCmdBuff, VkSemaphore waitSemaphore, +void vkh_cmd_submit_with_semaphores(VkhQueue queue, VkCommandBuffer *pCmdBuff, VkSemaphore waitSemaphore, VkSemaphore signalSemaphore, VkFence fence){ VkPipelineStageFlags stageFlags = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; @@ -80,7 +82,7 @@ void vkh_cmd_submit_with_semaphores(VkQueue queue, VkCommandBuffer *pCmdBuff, Vk submit_info.pSignalSemaphores= &signalSemaphore; } - VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submit_info, fence)); + VK_CHECK_RESULT(vkQueueSubmit(queue->queue, 1, &submit_info, fence)); }