]> O.S.I.I.S - jp/vkvg.git/commitdiff
timeline sync source surface, rename _wait_flush_fence=>_wait_ctx_flush_end, surface...
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 5 Apr 2022 10:54:15 +0000 (12:54 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 5 Apr 2022 10:54:15 +0000 (12:54 +0200)
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h
src/vkvg_surface.c
src/vkvg_surface_internal.c
vkh

index 262cedb098d765d689465a2104653323af1b3e17..d3234b3a9fac6768ef060046731dc69801a39425 100644 (file)
@@ -201,7 +201,7 @@ void vkvg_flush (VkvgContext ctx){
        if (ctx->status)
                return;
        _flush_cmd_buff         (ctx);
-       _wait_flush_fence       (ctx);
+       _wait_ctx_flush_end     (ctx);
 /*
 #ifdef DEBUG
 
@@ -1280,7 +1280,7 @@ void vkvg_save (VkvgContext ctx){
        vkvg_context_save_t* sav = (vkvg_context_save_t*)calloc(1,sizeof(vkvg_context_save_t));
 
        _flush_cmd_buff (ctx);
-       if (!_wait_flush_fence (ctx)) {
+       if (!_wait_ctx_flush_end (ctx)) {
                free (sav);
                return;
        }
@@ -1414,7 +1414,7 @@ void vkvg_restore (VkvgContext ctx){
        ctx->pSavedCtxs = sav->pNext;
 
        _flush_cmd_buff (ctx);
-       if (!_wait_flush_fence (ctx))
+       if (!_wait_ctx_flush_end (ctx))
                return;
 
        ctx->pushConsts   = sav->pushConsts;
@@ -1449,7 +1449,7 @@ void vkvg_restore (VkvgContext ctx){
 #endif
 
                        _flush_cmd_buff (ctx);
-                       if (!_wait_flush_fence (ctx))
+                       if (!_wait_ctx_flush_end (ctx))
                                return;
                }
        }
@@ -1491,7 +1491,7 @@ void vkvg_restore (VkvgContext ctx){
 
                        VK_CHECK_RESULT(vkEndCommandBuffer(ctx->cmd));
                        _wait_and_submit_cmd (ctx);
-                       if (!_wait_flush_fence (ctx))
+                       if (!_wait_ctx_flush_end (ctx))
                                return;
                        vkh_image_destroy (savStencil);
                }
index 1aa5e79715beba0e7f7946d5642c687e9b82b3a0..d14ad4f4847d244a658464e37cdd1526057b328b 100644 (file)
@@ -270,7 +270,7 @@ void _create_vertices_buff (VkvgContext ctx){
                ctx->sizeIBO * sizeof(VKVG_IBO_INDEX_TYPE), &ctx->indices);
 }
 void _resize_vbo (VkvgContext ctx, uint32_t new_size) {
-       if (!_wait_flush_fence (ctx))//wait previous cmd if not completed
+       if (!_wait_ctx_flush_end (ctx))//wait previous cmd if not completed
                return;
        LOG(VKVG_LOG_DBG_ARRAYS, "resize VBO: %d -> ", ctx->sizeVBO);
        ctx->sizeVBO = new_size;
@@ -285,7 +285,7 @@ void _resize_vbo (VkvgContext ctx, uint32_t new_size) {
                ctx->sizeVBO * sizeof(Vertex), &ctx->vertices);
 }
 void _resize_ibo (VkvgContext ctx, size_t new_size) {
-       if (!_wait_flush_fence (ctx))//wait previous cmd if not completed
+       if (!_wait_ctx_flush_end (ctx))//wait previous cmd if not completed
                return;
        ctx->sizeIBO = new_size;
        uint32_t mod = ctx->sizeIBO % VKVG_IBO_SIZE;
@@ -421,7 +421,7 @@ void _clear_attachment (VkvgContext ctx) {
 
 }
 
-bool _wait_flush_fence (VkvgContext ctx) {
+bool _wait_ctx_flush_end (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)
@@ -446,16 +446,34 @@ bool _wait_and_submit_cmd (VkvgContext ctx){
        VkvgSurface surf = ctx->pSurf;
        VkvgDevice dev = surf->dev;
        //vkh_timeline_wait ((VkhDevice)dev, surf->timeline, ct->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)
+       if (ctx->pattern && ctx->pattern->type == VKVG_PATTERN_TYPE_SURFACE) {
+               //add source surface timeline sync.
+               VkvgSurface source = (VkvgSurface)ctx->pattern->data;
+               LOCK_SURFACE(surf)
+               LOCK_SURFACE(source)
+               LOCK_DEVICE
+               vkh_cmd_submit_timelined2 (dev->gQueue, &ctx->cmd,
+                                                                 (VkSemaphore[2]){surf->timeline,source->timeline},
+                                                                 (uint64_t[2]){surf->timelineStep,source->timelineStep},
+                                                                 (uint64_t[2]){surf->timelineStep+1,source->timelineStep+1});
+               surf->timelineStep++;
+               source->timelineStep++;
+               ctx->timelineStep = surf->timelineStep;
+               UNLOCK_DEVICE
+               UNLOCK_SURFACE(source)
+               UNLOCK_SURFACE(surf)
+       } else {
+               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))
+       if (!_wait_ctx_flush_end (ctx))
                return false;
        ResetFences (ctx->dev->vkDev, 1, &ctx->flushFence);
        _device_submit_cmd (ctx->dev, &ctx->cmd, ctx->flushFence);
@@ -496,7 +514,7 @@ bool _wait_and_submit_cmd (VkvgContext ctx){
 //pre flush vertices because of vbo or ibo too small, all vertices except last draw call are flushed
 //this function expects a vertex offset > 0
 void _flush_vertices_caches_until_vertex_base (VkvgContext ctx) {
-       _wait_flush_fence (ctx);
+       _wait_ctx_flush_end (ctx);
 
        memcpy(ctx->vertices.allocInfo.pMappedData, ctx->vertexCache, ctx->curVertOffset * sizeof (Vertex));
        memcpy(ctx->indices.allocInfo.pMappedData, ctx->indexCache, ctx->curIndStart * sizeof (VKVG_IBO_INDEX_TYPE));
@@ -513,7 +531,7 @@ void _flush_vertices_caches_until_vertex_base (VkvgContext ctx) {
 //copy vertex and index caches to the vbo and ibo vkbuffers used by gpu for drawing
 //current running cmd has to be completed to free usage of those
 void _flush_vertices_caches (VkvgContext ctx) {
-       if (!_wait_flush_fence (ctx))
+       if (!_wait_ctx_flush_end (ctx))
                return;
 
        memcpy(ctx->vertices.allocInfo.pMappedData, ctx->vertexCache, ctx->vertCount * sizeof (Vertex));
@@ -693,7 +711,7 @@ void _update_cur_pattern (VkvgContext ctx, VkvgPattern pat) {
        switch (newPatternType)  {
        case VKVG_PATTERN_TYPE_SOLID:
                _flush_cmd_buff                         (ctx);
-               if (!_wait_flush_fence (ctx))
+               if (!_wait_ctx_flush_end (ctx))
                        return;
                if (lastPat->type == VKVG_PATTERN_TYPE_SURFACE)//unbind current source surface by replacing it with empty texture
                        _update_descriptor_set          (ctx, ctx->dev->emptyImg, ctx->dsSrc);
@@ -720,7 +738,7 @@ void _update_cur_pattern (VkvgContext ctx, VkvgPattern pat) {
 
                vkh_cmd_end                             (ctx->cmd);
                _wait_and_submit_cmd    (ctx);
-               if (!_wait_flush_fence (ctx))
+               if (!_wait_ctx_flush_end (ctx))
                        return;
 
                ctx->source = surf->img;
@@ -766,7 +784,7 @@ void _update_cur_pattern (VkvgContext ctx, VkvgPattern pat) {
        case VKVG_PATTERN_TYPE_LINEAR:
        case VKVG_PATTERN_TYPE_RADIAL:
                _flush_cmd_buff (ctx);
-               if (!_wait_flush_fence (ctx))
+               if (!_wait_ctx_flush_end (ctx))
                        return;
 
                if (lastPat && lastPat->type == VKVG_PATTERN_TYPE_SURFACE)
@@ -1634,7 +1652,7 @@ void _poly_fill (VkvgContext ctx, vec4* bounds){
                                _flush_vertices_caches (ctx);
                        vkh_cmd_end (ctx->cmd);
                        _wait_and_submit_cmd (ctx);
-                       _wait_flush_fence (ctx);
+                       _wait_ctx_flush_end (ctx);
                        if (ctx->sizeVBO - VKVG_ARRAY_THRESHOLD < ctx->pointCount){
                                _resize_vbo (ctx, ctx->pointCount + VKVG_ARRAY_THRESHOLD);
                                _resize_vertex_cache (ctx, ctx->sizeVBO);
index ee45ca729175b15e6a122214e0d86a6e6213f8c8..a558ff3939d99a7a790063bfcdef91b550f224ab 100644 (file)
@@ -306,7 +306,7 @@ void _flush_cmd_buff                        (VkvgContext ctx);
 void _ensure_renderpass_is_started             (VkvgContext ctx);
 void _emit_draw_cmd_undrawn_vertices   (VkvgContext ctx);
 void _flush_cmd_until_vx_base  (VkvgContext ctx);
-bool _wait_flush_fence                 (VkvgContext ctx);
+bool _wait_ctx_flush_end               (VkvgContext ctx);
 bool _wait_and_submit_cmd              (VkvgContext ctx);
 void _update_push_constants            (VkvgContext ctx);
 void _update_cur_pattern               (VkvgContext ctx, VkvgPattern pat);
index 3e6cea76f185f336ad9077cc3f905b1e674dce4f..701e9c491a4030b507f51f44ddf28967fd42c02a 100644 (file)
@@ -176,7 +176,7 @@ VkvgSurface vkvg_surface_create_from_bitmap (VkvgDevice dev, unsigned char* img,
 
        vkh_cmd_end             (cmd);
 
-       _surface_submit_cmd (surf);
+       _surface_submit_cmd (surf);//lock surface?
 
        vkvg_buffer_destroy (&buff);
        vkh_image_destroy       (stagImg);
index 4ef66686fb1c42eeb95a8664b7afb1977f620c85..263489bd9e0504e314a204a098a6a20978100894 100644 (file)
@@ -26,6 +26,8 @@
 #include "vkh_queue.h"
 
 void _explicit_ms_resolve (VkvgSurface surf){
+       LOCK_SURFACE (surf)
+
        VkCommandBuffer cmd = surf->cmd;
 
        vkh_cmd_begin (cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
@@ -52,10 +54,14 @@ void _explicit_ms_resolve (VkvgSurface surf){
        vkh_cmd_end (cmd);
 
        _surface_submit_cmd (surf);
+
+       UNLOCK_SURFACE (surf)
 }
 
 void _clear_surface (VkvgSurface surf, VkImageAspectFlags aspect)
 {
+       LOCK_SURFACE (surf)
+
        VkCommandBuffer cmd = surf->cmd;
 
        vkh_cmd_begin (cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
@@ -97,6 +103,8 @@ void _clear_surface (VkvgSurface surf, VkImageAspectFlags aspect)
        vkh_cmd_end (cmd);
 
        _surface_submit_cmd (surf);
+
+       UNLOCK_SURFACE (surf)
 }
 
 void _create_surface_main_image (VkvgSurface surf){
diff --git a/vkh b/vkh
index 16a129f586060d7bd2608989e9b70242d0e6d023..d966ae76eeb179e41ba0aeb947a32aaabc3bafcb 160000 (submodule)
--- a/vkh
+++ b/vkh
@@ -1 +1 @@
-Subproject commit 16a129f586060d7bd2608989e9b70242d0e6d023
+Subproject commit d966ae76eeb179e41ba0aeb947a32aaabc3bafcb