summaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2022-04-05 12:54:15 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2022-04-05 12:54:15 +0200
commitfd3434e4f84ef83ef26a87ffe380fd6e3371b9b6 (patch)
treef7371dc40aa143c9a21772f78f821cb7d38594d6
parent071aef41cec9df3570e57669310f3f903536e2ca (diff)
timeline sync source surface, rename _wait_flush_fence=>_wait_ctx_flush_end, surface locks debug
-rw-r--r--src/vkvg_context.c10
-rw-r--r--src/vkvg_context_internal.c52
-rw-r--r--src/vkvg_context_internal.h2
-rw-r--r--src/vkvg_surface.c2
-rw-r--r--src/vkvg_surface_internal.c8
m---------vkh0
6 files changed, 50 insertions, 24 deletions
diff --git a/src/vkvg_context.c b/src/vkvg_context.c
index 262cedb..d3234b3 100644
--- a/src/vkvg_context.c
+++ b/src/vkvg_context.c
@@ -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);
}
diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c
index 1aa5e79..d14ad4f 100644
--- a/src/vkvg_context_internal.c
+++ b/src/vkvg_context_internal.c
@@ -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);
diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h
index ee45ca7..a558ff3 100644
--- a/src/vkvg_context_internal.h
+++ b/src/vkvg_context_internal.h
@@ -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);
diff --git a/src/vkvg_surface.c b/src/vkvg_surface.c
index 3e6cea7..701e9c4 100644
--- a/src/vkvg_surface.c
+++ b/src/vkvg_surface.c
@@ -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);
diff --git a/src/vkvg_surface_internal.c b/src/vkvg_surface_internal.c
index 4ef6668..263489b 100644
--- a/src/vkvg_surface_internal.c
+++ b/src/vkvg_surface_internal.c
@@ -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
-Subproject 16a129f586060d7bd2608989e9b70242d0e6d02
+Subproject d966ae76eeb179e41ba0aeb947a32aaabc3bafc