]> O.S.I.I.S - jp/vkvg.git/commitdiff
threaded context cache merge
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 21 Mar 2022 12:43:16 +0000 (13:43 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 21 Mar 2022 12:43:16 +0000 (13:43 +0100)
1  2 
include/vkvg.h
src/vkvg_context.c
src/vkvg_device.c
src/vkvg_device_internal.c
src/vkvg_device_internal.h
tests/multithreading/multithreaded.c

diff --cc include/vkvg.h
index 7313bd36d2e70f6c3e71bf309bbe3d59e61a9315,769a330c31ffa342c0d2fddbbb7724660b3160a7..27f562c5cf92121447cebab709471f40205b7e9f
@@@ -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.
   *
index 1fd8078c3c7e3542105a6ba9fcd60eebb2ccf90f,dfcd76eb7c4ad31cc54a21d804703fd980eb712b..262cedb098d765d689465a2104653323af1b3e17
@@@ -62,12 -62,17 +62,16 @@@ void _init_ctx (VkvgContext ctx) 
        ctx->renderPassBeginInfo.renderArea.extent.height = ctx->pSurf->height;
        ctx->renderPassBeginInfo.pClearValues = clearValues;
  
 -      if (ctx->pSurf->new)
+       LOCK_SURFACE (ctx->pSurf)
 +      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)
Simple merge
index 6096297c21baddda4e7f3cf7546d968b5bd44426,87784c2227d49ecf20564f9b6f7e7138508ebbf2..ab37f2d1625c054f952d3f2fa260e2c95d777d7d
@@@ -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
index b282094b17504421aa678f6315690b50bc865b6b,eba61a177c9f2513f1696810edd7eb1a9564cea8..5503d175ee675a7ec07f5ae024be2d4008327be1
@@@ -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;
index 49818604cdcfb8ec81f056073044d19564120e82,49818604cdcfb8ec81f056073044d19564120e82..05ee0384a25af07a641df833df77c74575ef119b
@@@ -5,7 -5,7 +5,7 @@@
  #include "test.h"
  #include "tinycthread.h"
  
--#define THREAD_COUNT 64
++#define THREAD_COUNT 32
  
  
  static int finishedThreadCount = 0;