ctx->renderPassBeginInfo.renderArea.extent.height = ctx->pSurf->height;
ctx->renderPassBeginInfo.pClearValues = clearValues;
- if (ctx->pSurf->new)
+ if (ctx->pSurf->newSurf)
ctx->renderPassBeginInfo.renderPass = ctx->dev->renderPass_ClearAll;
else
ctx->renderPassBeginInfo.renderPass = ctx->dev->renderPass_ClearStencil;
- ctx->pSurf->new = false;
+ ctx->pSurf->newSurf = false;
vkvg_surface_reference (ctx->pSurf);
if (ctx->dev->samples == VK_SAMPLE_COUNT_1_BIT)
ctx->cmdStarted = false;
ctx->curClipState = vkvg_clip_state_none;
ctx->vertCount = ctx->indCount = 0;
+ ctx->timelineStep = 0;
}
VkvgContext vkvg_create(VkvgSurface surf)
//for context to be thread safe, command pool and descriptor pool have to be created in the thread of the context.
ctx->cmdPool = vkh_cmd_pool_create ((VkhDevice)dev, dev->gQueue->familyIndex, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
+
+#ifndef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE
ctx->flushFence = vkh_fence_create_signaled ((VkhDevice)ctx->dev);
+#endif
_create_vertices_buff (ctx);
_create_gradient_buff (ctx);
vkh_device_set_object_name((VkhDevice)dev, VK_OBJECT_TYPE_COMMAND_POOL, (uint64_t)ctx->cmdPool, "CTX Cmd Pool");
vkh_device_set_object_name((VkhDevice)dev, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)ctx->cmdBuffers[0], "CTX Cmd Buff A");
vkh_device_set_object_name((VkhDevice)dev, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)ctx->cmdBuffers[1], "CTX Cmd Buff B");
+#ifndef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE
vkh_device_set_object_name((VkhDevice)dev, VK_OBJECT_TYPE_FENCE, (uint64_t)ctx->flushFence, "CTX Flush Fence");
-
+#endif
vkh_device_set_object_name((VkhDevice)dev, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t)ctx->descriptorPool, "CTX Descriptor Pool");
vkh_device_set_object_name((VkhDevice)dev, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)ctx->dsSrc, "CTX DescSet SOURCE");
vkh_device_set_object_name((VkhDevice)dev, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)ctx->dsFont, "CTX DescSet FONT");
void _clear_attachment (VkvgContext ctx) {
}
+
bool _wait_flush_fence (VkvgContext ctx) {
LOG(VKVG_LOG_INFO, "CTX: _wait_flush_fence\n");
+#ifdef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE
+ if (vkh_timeline_wait ((VkhDevice)ctx->dev, ctx->pSurf->timeline, ctx->timelineStep) == VK_SUCCESS)
+ return true;
+#else
if (WaitForFences (ctx->dev->vkDev, 1, &ctx->flushFence, VK_TRUE, VKVG_FENCE_TIMEOUT) == VK_SUCCESS)
return true;
+#endif
LOG(VKVG_LOG_DEBUG, "CTX: _wait_flush_fence timeout\n");
ctx->status = VKVG_STATUS_TIMEOUT;
return false;
}
+
+
bool _wait_and_submit_cmd (VkvgContext ctx){
if (!ctx->cmdStarted)//current cmd buff is empty, be aware that wait is also canceled!!
return true;
LOG(VKVG_LOG_INFO, "CTX: _wait_and_submit_cmd\n");
+#ifdef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE
+ VkvgSurface surf = ctx->pSurf;
+ VkvgDevice dev = surf->dev;
+ vkh_timeline_wait ((VkhDevice)dev, surf->timeline, surf->timelineStep);
+ LOCK_SURFACE(surf)
+ LOCK_DEVICE
+ vkh_cmd_submit_timelined (dev->gQueue, &ctx->cmd, surf->timeline, surf->timelineStep, surf->timelineStep+1);
+ surf->timelineStep++;
+ ctx->timelineStep = surf->timelineStep;
+ UNLOCK_DEVICE
+ UNLOCK_SURFACE(surf)
+#else
+
if (!_wait_flush_fence (ctx))
return false;
_device_reset_fence(ctx->dev, ctx->flushFence);
_device_submit_cmd (ctx->dev, &ctx->cmd, ctx->flushFence);
+#endif
if (ctx->cmd == ctx->cmdBuffers[0])
ctx->cmd = ctx->cmdBuffers[1];
void _release_context_ressources (VkvgContext ctx) {
VkDevice dev = ctx->dev->vkDev;
+#ifndef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE
_device_destroy_fence (ctx->dev, ctx->flushFence);
+#endif
+
vkFreeCommandBuffers(dev, ctx->cmdPool, 2, ctx->cmdBuffers);
vkDestroyCommandPool(dev, ctx->cmdPool, NULL);
VkvgDevice dev;
VkvgSurface pSurf; //surface bound to context, set on creation of ctx
+#ifdef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE
+ uint64_t timelineStep; //context cmd last submission timeline id.
+#else
VkFence flushFence; //context fence
+#endif
VkhImage source; //source of painting operation
VkCommandPool cmdPool; //local pools ensure thread safety
LOCK_DEVICE
+#ifndef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE
if (dev->gQLastFence == ctx->flushFence)
dev->gQLastFence = VK_NULL_HANDLE;
+#endif
dev->cachedContext[dev->cachedContextCount++] = ctx;
ctx->references++;
surf->width = MAX(1, width);
surf->height = MAX(1, height);
- surf->new = true;//used to clear all attacments on first render pass
+ surf->newSurf = true;//used to clear all attacments on first render pass
_create_surface_images (surf);
vkvg_buffer_destroy (&buff);
vkh_image_destroy (stagImg);
- surf->new = false;
+ surf->newSurf = false;
//create tmp context with rendering pipeline to create the multisample img
VkvgContext ctx = vkvg_create (surf);
if (surf->dev->threadAware)
mtx_destroy (&surf->mutex);
+#if VKVG_ENABLE_VK_TIMELINE_SEMAPHORE
+ vkDestroySemaphore (surf->dev->vkDev, surf->timeline, NULL);
+#endif
+
vkvg_device_destroy (surf->dev);
free(surf);
}
surf->format = format;
if (dev->threadAware)
mtx_init (&surf->mutex, mtx_plain);
+
+#if VKVG_ENABLE_VK_TIMELINE_SEMAPHORE
+ surf->timeline = vkh_timeline_create ((VkhDevice)dev, 0);
+#endif
return surf;
}
VkhImage img;
VkhImage imgMS;
VkhImage stencil;
- bool new;
+ bool newSurf;
mtx_t mutex;
+#ifdef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE
+ VkSemaphore timeline; /**< Timeline semaphore */
+ uint64_t timelineStep;
+#endif
}vkvg_surface;
#define LOCK_SURFACE(surf) \
-Subproject commit 2a194890dfed6eb82d3a92fd56ecc46f47735d29
+Subproject commit 16a129f586060d7bd2608989e9b70242d0e6d023