From: Jean-Philippe Bruyère Date: Mon, 21 Mar 2022 12:43:16 +0000 (+0100) Subject: threaded context cache merge X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=1502ac263b56502f1fe4287cc4ab1bf848f12a37;p=jp%2Fvkvg.git threaded context cache merge --- 1502ac263b56502f1fe4287cc4ab1bf848f12a37 diff --cc include/vkvg.h index 7313bd3,769a330..27f562c --- a/include/vkvg.h +++ b/include/vkvg.h @@@ -88,8 -89,8 +88,9 @@@ extern "C" #define VKVG_LOG_INFO_VBO 0x00000020 #define VKVG_LOG_INFO_IBO 0x00000040 #define VKVG_LOG_INFO_VAO (VKVG_LOG_INFO_VBO|VKVG_LOG_INFO_IBO) + #define VKVG_LOG_THREAD 0x00000080 #define VKVG_LOG_DBG_ARRAYS 0x00001000 +#define VKVG_LOG_STROKE 0x00010000 #define VKVG_LOG_FULL 0xffffffff #define VKVG_LOG_INFO 0x00008000//(VKVG_LOG_INFO_PTS|VKVG_LOG_INFO_PATH|VKVG_LOG_INFO_CMD|VKVG_LOG_INFO_VAO) @@@ -541,14 -552,19 +542,24 @@@ void vkvg_matrix_get_scale (const vkvg_ * * @{ */ +/** + * @brief vkvg_device_set_thread_aware + * @param dev + * @param thread_awayre + */ vkvg_public void vkvg_device_set_thread_aware (VkvgDevice dev, uint32_t thread_awayre); - + vkvg_public + /** + * @brief Set maximum cached context count. + * + * The context cache stored destroyed contexts per thread to speed-up new context creation. + * To disable context cache, call this method with maxCount=0. + * + * @param dev A valid vkvg device pointer. + * @param maxCount The maximum count of saved contexts for fast context instanciation. + */ + void vkvg_device_set_context_cache_size (VkvgDevice dev, uint32_t maxCount); /** * @brief Create a new vkvg device. * diff --cc src/vkvg_context.c index 1fd8078,dfcd76e..262cedb --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@@ -62,12 -62,17 +62,16 @@@ void _init_ctx (VkvgContext ctx) ctx->renderPassBeginInfo.renderArea.extent.height = ctx->pSurf->height; ctx->renderPassBeginInfo.pClearValues = clearValues; + LOCK_SURFACE (ctx->pSurf) + - 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; + + UNLOCK_SURFACE (ctx->pSurf); + vkvg_surface_reference (ctx->pSurf); if (ctx->dev->samples == VK_SAMPLE_COUNT_1_BIT) diff --cc src/vkvg_device_internal.c index 6096297,87784c2..ab37f2d --- a/src/vkvg_device_internal.c +++ b/src/vkvg_device_internal.c @@@ -435,7 -476,19 +454,16 @@@ void _device_store_context (VkvgContex LOCK_DEVICE - dev->cachedContext[dev->cachedContextCount++] = ctx; - if (dev->gQLastFence == ctx->flushFence) - dev->gQLastFence = VK_NULL_HANDLE; - + _cached_ctx* cur = (_cached_ctx*)calloc(1, sizeof(_cached_ctx)); + cur->ctx = ctx; + cur->thread = thrd_current (); + cur->pNext = dev->cachedContextLast; + + dev->cachedContextLast = cur; + dev->cachedContextCount++; + + LOG(VKVG_LOG_THREAD,"store context: %p, thd:%lu cached ctx: %d\n", cur->ctx, cur->thread, dev->cachedContextCount); + ctx->references++; UNLOCK_DEVICE diff --cc src/vkvg_device_internal.h index b282094,eba61a1..5503d17 --- a/src/vkvg_device_internal.h +++ b/src/vkvg_device_internal.h @@@ -30,7 -30,7 +30,7 @@@ #define STENCIL_CLIP_BIT 0x2 #define STENCIL_ALL_BIT 0x3 --#define VKVG_MAX_CACHED_CONTEXT_COUNT 2 ++#define VKVG_MAX_CACHED_CONTEXT_COUNT 36 extern PFN_vkCmdBindPipeline CmdBindPipeline; extern PFN_vkCmdBindDescriptorSets CmdBindDescriptorSets; diff --cc tests/multithreading/multithreaded.c index 4981860,4981860..05ee038 --- a/tests/multithreading/multithreaded.c +++ b/tests/multithreading/multithreaded.c @@@ -5,7 -5,7 +5,7 @@@ #include "test.h" #include "tinycthread.h" --#define THREAD_COUNT 64 ++#define THREAD_COUNT 32 static int finishedThreadCount = 0;