aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2022-03-18 20:43:35 +0100
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2022-04-04 12:34:27 +0200
commit7b71a29f8f181a0b7ce9c2acf09a0609f3a65969 (patch)
tree73edd7074bb72161994d3ed64d324848c89e5fb9
parent892c65cd614910b5fbf53de6e88d277f1cb612e0 (diff)
timeline semaphore
-rw-r--r--include/vkh.h13
-rw-r--r--src/vkh_image.c5
-rw-r--r--src/vkh_phyinfo.c2
-rw-r--r--src/vkhelpers.c52
4 files changed, 64 insertions, 8 deletions
diff --git a/include/vkh.h b/include/vkh.h
index 93db165..7e8d0f3 100644
--- a/include/vkh.h
+++ b/include/vkh.h
@@ -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);
diff --git a/src/vkh_image.c b/src/vkh_image.c
index 585a36b..d6a82df 100644
--- a/src/vkh_image.c
+++ b/src/vkh_image.c
@@ -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));
diff --git a/src/vkh_phyinfo.c b/src/vkh_phyinfo.c
index 49c9564..5a1ef61 100644
--- a/src/vkh_phyinfo.c
+++ b/src/vkh_phyinfo.c
@@ -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;
}
diff --git a/src/vkhelpers.c b/src/vkhelpers.c
index 03d32ff..e7a05ca 100644
--- a/src/vkhelpers.c
+++ b/src/vkhelpers.c
@@ -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);