]> O.S.I.I.S - jp/vkhelpers.git/commitdiff
timeline semaphore
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 18 Mar 2022 19:43:35 +0000 (20:43 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 4 Apr 2022 10:34:27 +0000 (12:34 +0200)
include/vkh.h
src/vkh_image.c
src/vkh_phyinfo.c
src/vkhelpers.c

index 93db165913081b8815d9ffe31f0b2a14e56706f7..7e8d0f3c0a81f29a0ec0111e8c298960be140615 100644 (file)
@@ -252,9 +252,9 @@ vkh_public
 void        vkh_buffer_unmap    (VkhBuffer buff);
 
 vkh_public
-VkBuffer    vkh_buffer_get_vkbuffer         (VkhBuffer buff);
+VkBuffer    vkh_buffer_get_vkbuffer                    (VkhBuffer buff);
 vkh_public
-void*       vkh_buffer_get_mapped_pointer   (VkhBuffer buff);
+void*       vkh_buffer_get_mapped_pointer      (VkhBuffer buff);
 
 vkh_public
 VkFence         vkh_fence_create                       (VkhDevice dev);
@@ -263,7 +263,14 @@ VkFence         vkh_fence_create_signaled  (VkhDevice dev);
 vkh_public
 VkSemaphore     vkh_semaphore_create           (VkhDevice dev);
 vkh_public
-VkEvent         vkh_event_create            (VkhDevice dev);
+VkSemaphore            vkh_timeline_create                     (VkhDevice dev, uint64_t initialValue);
+vkh_public
+VkResult               vkh_timeline_wait                       (VkhDevice dev, VkSemaphore timeline, const uint64_t wait);
+vkh_public
+void                   vkh_cmd_submit_timelined        (VkhQueue queue, VkCommandBuffer *pCmdBuff, VkSemaphore timeline,
+                                                                                                const uint64_t wait, const uint64_t signal);
+vkh_public
+VkEvent         vkh_event_create                               (VkhDevice dev);
 
 vkh_public
 VkCommandPool   vkh_cmd_pool_create (VkhDevice dev, uint32_t qFamIndex, VkCommandPoolCreateFlags flags);
index 585a36b67b2211a53c009d99c3085e885fe1980d..d6a82dfaf7a2faf09e0039e146b04a6bf89290ad 100644 (file)
@@ -27,6 +27,7 @@ VkhImage _vkh_image_create (VkhDevice pDev, VkImageType imageType,
                                  VmaMemoryUsage memprops, VkImageUsageFlags usage,
                                  VkSampleCountFlagBits samples, VkImageTiling tiling,
                                  uint32_t mipLevels, uint32_t arrayLayers){
+
        VkhImage img = (VkhImage)calloc(1,sizeof(vkh_image_t));
 
        img->pDev = pDev;
@@ -46,12 +47,12 @@ VkhImage _vkh_image_create (VkhDevice pDev, VkImageType imageType,
        pInfo->arrayLayers              = arrayLayers;
        pInfo->samples                  = samples;
 
+       /*
        img->imported = false;
-
        img->alloc      = VK_NULL_HANDLE;
        img->image      = VK_NULL_HANDLE;
        img->sampler= VK_NULL_HANDLE;
-       img->view       = VK_NULL_HANDLE;
+       img->view       = VK_NULL_HANDLE;*/
 
        VmaAllocationCreateInfo allocInfo = { .usage = memprops };
        VK_CHECK_RESULT(vmaCreateImage (pDev->allocator, pInfo, &allocInfo, &img->image, &img->alloc, &img->allocInfo));
index 49c95640e6ac54e65d1a8bacb2383b59b5ce289d..5a1ef619e6dcbabf36c5a3362e962d5c2027c431 100644 (file)
@@ -193,7 +193,7 @@ bool vkh_phyinfo_try_get_extension_properties (VkhPhyInfo phy, const char* name,
        }
        for (uint32_t i=0; i<phy->extensionCount; i++) {
                if (strcmp(name, phy->pExtensionProperties[i].extensionName)==0) {
-                       if (properties != NULL)
+                       if (properties)
                                properties = &phy->pExtensionProperties[i];
                        return true;
                }
index 03d32ff810e16c732c9c4f8ab72c8eff77fad5c1..e7a05ca9256b24536dfc528f91e9093d09b2c0ce 100644 (file)
@@ -48,6 +48,54 @@ VkSemaphore vkh_semaphore_create (VkhDevice dev) {
        VK_CHECK_RESULT(vkCreateSemaphore(dev->dev, &info, NULL, &semaphore));
        return semaphore;
 }
+VkSemaphore vkh_timeline_create (VkhDevice dev, uint64_t initialValue) {
+       VkSemaphore semaphore;
+       VkSemaphoreTypeCreateInfo timelineInfo = {
+               .sType = VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO, .pNext = NULL,
+               .semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE,
+               .initialValue = initialValue};
+       VkSemaphoreCreateInfo info = { .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
+                                                                  .pNext = &timelineInfo,
+                                                                  .flags = 0};
+       VK_CHECK_RESULT(vkCreateSemaphore(dev->dev, &info, NULL, &semaphore));
+       return semaphore;
+}
+
+VkResult vkh_timeline_wait (VkhDevice dev, VkSemaphore timeline, const uint64_t wait) {
+       VkSemaphoreWaitInfo waitInfo;
+       waitInfo.sType                  = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO;
+       waitInfo.pNext                  = NULL;
+       waitInfo.flags                  = 0;
+       waitInfo.semaphoreCount = 1;
+       waitInfo.pSemaphores    = &timeline;
+       waitInfo.pValues                = &wait;
+
+       return vkWaitSemaphores(dev->dev, &waitInfo, UINT64_MAX);
+}
+void vkh_cmd_submit_timelined (VkhQueue queue, VkCommandBuffer *pCmdBuff, VkSemaphore timeline, const uint64_t wait, const uint64_t signal) {
+       static VkPipelineStageFlags stageFlags = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
+       VkTimelineSemaphoreSubmitInfo timelineInfo;
+       timelineInfo.sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO;
+       timelineInfo.pNext = NULL;
+       timelineInfo.waitSemaphoreValueCount = 1;
+       timelineInfo.pWaitSemaphoreValues = &wait;
+       timelineInfo.signalSemaphoreValueCount = 1;
+       timelineInfo.pSignalSemaphoreValues = &signal;
+
+       VkSubmitInfo submitInfo;
+       submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
+       submitInfo.pNext = &timelineInfo;
+       submitInfo.waitSemaphoreCount = 1;
+       submitInfo.pWaitSemaphores = &timeline;
+       submitInfo.signalSemaphoreCount  = 1;
+       submitInfo.pSignalSemaphores = &timeline;
+       submitInfo.pWaitDstStageMask = &stageFlags,
+       submitInfo.commandBufferCount = 1;
+       submitInfo.pCommandBuffers = pCmdBuff;
+
+       VK_CHECK_RESULT(vkQueueSubmit(queue->queue, 1, &submitInfo, VK_NULL_HANDLE));
+}
+
 VkEvent vkh_event_create (VkhDevice dev) {
        VkEvent evt;
        VkEventCreateInfo evtInfo = {.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO};
@@ -273,11 +321,11 @@ uint32_t* readFile(uint32_t* length, const char* filename) {
 void dumpLayerExts () {
        printf ("Layers:\n");
        uint32_t instance_layer_count;
-       assert (vkEnumerateInstanceLayerProperties(&instance_layer_count, NULL)==VK_SUCCESS);
+       VK_CHECK_RESULT (vkEnumerateInstanceLayerProperties(&instance_layer_count, NULL));
        if (instance_layer_count == 0)
                return;
        VkLayerProperties* vk_props = (VkLayerProperties*)malloc (instance_layer_count * sizeof(VkLayerProperties));
-       assert (vkEnumerateInstanceLayerProperties(&instance_layer_count, vk_props)==VK_SUCCESS);
+       VK_CHECK_RESULT (vkEnumerateInstanceLayerProperties(&instance_layer_count, vk_props));
 
        for (uint32_t i = 0; i < instance_layer_count; i++) {
                printf ("\t%s, %s\n", vk_props[i].layerName, vk_props[i].description);