]> O.S.I.I.S - jp/vkvg.git/commitdiff
store vbo/ibo caches, points and pathes arrays in threaded objects tinycthread
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 18 Jan 2022 14:44:39 +0000 (15:44 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 18 Jan 2022 14:44:39 +0000 (15:44 +0100)
src/vkvg_context.c
src/vkvg_context_internal.h
src/vkvg_device_internal.c
src/vkvg_device_internal.h

index 312ed7e6f654225f10e6579d2debf159e98b7839..033c9a84a8df791aa7b3339dc61837fda53f702b 100644 (file)
@@ -54,10 +54,6 @@ VkvgContext vkvg_create(VkvgSurface surf)
                return NULL;
        }
 
-       ctx->sizePoints         = VKVG_PTS_SIZE;
-       ctx->sizeVertices       = VKVG_VBO_SIZE;
-       ctx->sizeIndices        = VKVG_IBO_SIZE;
-       ctx->sizePathes         = VKVG_PATHES_SIZE;
        ctx->lineWidth          = 1;
        ctx->curOperator        = VKVG_OPERATOR_OVER;
        ctx->curFillRule        = VKVG_FILL_RULE_NON_ZERO;
@@ -97,16 +93,12 @@ VkvgContext vkvg_create(VkvgSurface surf)
                ctx->pPrev->pNext = ctx;
        surf->dev->lastCtx = ctx;
 
-       ctx->points     = (vec2*)malloc (VKVG_VBO_SIZE*sizeof(vec2));
-       ctx->pathes     = (uint32_t*)malloc (VKVG_PATHES_SIZE*sizeof(uint32_t));
-       ctx->vertexCache = (Vertex*)malloc(ctx->sizeVertices * sizeof(Vertex));
-       ctx->indexCache = (VKVG_IBO_INDEX_TYPE*)malloc(ctx->sizeIndices * sizeof(VKVG_IBO_INDEX_TYPE));
-       ctx->savedStencils = malloc(0);
-
        ctx->selectedCharSize = 10 << 6;
        ctx->currentFont = NULL;
 
-       if (!ctx->points || !ctx->pathes || !ctx->vertexCache || !ctx->indexCache || !ctx->savedStencils ) {
+       ctx->savedStencils = malloc(0);
+
+       /*if (!ctx->points || !ctx->pathes || !ctx->vertexCache || !ctx->indexCache || !ctx->savedStencils ) {
                dev->status = VKVG_STATUS_NO_MEMORY;
                if (ctx->points)
                        free(ctx->points);
@@ -119,7 +111,7 @@ VkvgContext vkvg_create(VkvgSurface surf)
                if (ctx->savedStencils)
                        free(ctx->savedStencils);
                return NULL;
-       }
+       }*/
 
        ctx->flushFence = vkh_fence_create_signaled ((VkhDevice)dev);
        //for context to be thread safe, command pool and descriptor pool have to be created in the thread of the context.
@@ -128,6 +120,15 @@ VkvgContext vkvg_create(VkvgSurface surf)
 
        ctx->th_objs = _get_or_create_threaded_objects(ctx->pSurf->dev, thrd_current());
 
+       ctx->points = ctx->th_objs->points;
+       ctx->sizePoints = ctx->th_objs->sizePoints;
+       ctx->pathes = ctx->th_objs->pathes;
+       ctx->sizePathes = ctx->th_objs->sizePathes;
+       ctx->indexCache = ctx->th_objs->indexCache;
+       ctx->sizeIndices = ctx->th_objs->sizeIndices;
+       ctx->vertexCache = ctx->th_objs->vertexCache;
+       ctx->sizeVertices = ctx->th_objs->sizeVertices;
+
        _create_cmd_buff                (ctx);
 
        _clear_path                             (ctx);
@@ -189,6 +190,14 @@ void vkvg_destroy (VkvgContext ctx)
        vkvg_flush (ctx);
 
        _update_descriptor_set          (ctx->th_objs, ctx->pSurf->dev->emptyImg, ctx->th_objs->dsSrc);
+       ctx->th_objs->points = ctx->points;
+       ctx->th_objs->sizePoints = ctx->sizePoints;
+       ctx->th_objs->pathes = ctx->pathes;
+       ctx->th_objs->sizePathes = ctx->sizePathes;
+       ctx->th_objs->indexCache = ctx->indexCache;
+       ctx->th_objs->sizeIndices = ctx->sizeIndices;
+       ctx->th_objs->vertexCache = ctx->vertexCache;
+       ctx->th_objs->sizeVertices = ctx->sizeVertices;
 
        LOG(VKVG_LOG_DBG_ARRAYS, "END\tctx = %p; pathes:%d pts:%d vch:%d vbo:%d ich:%d ibo:%d\n", ctx, ctx->sizePathes, ctx->sizePoints, ctx->sizeVertices, ctx->th_objs->sizeVBO, ctx->sizeIndices, ctx->th_objs->sizeIBO);
 
@@ -223,14 +232,8 @@ void vkvg_destroy (VkvgContext ctx)
        vkFreeCommandBuffers(dev, ctx->cmdPool, 2, ctx->cmdBuffers);
        vkDestroyCommandPool(dev, ctx->cmdPool, NULL);
 
-       free(ctx->vertexCache);
-       free(ctx->indexCache);
-
        //TODO:check this for source counter
        //vkh_image_destroy       (ctx->source);
-
-       free(ctx->pathes);
-       free(ctx->points);
        if (ctx->dashCount > 0)
                free(ctx->dashes);
 
index 34d3990f20df790643491dd3e6d02ad747b4c2e4..d5f0eada1bc1fe6f1d7997dd1f24da55fb4f184b 100644 (file)
        #define RECORD(ctx,cmd,...)
 #endif
 
-#define VKVG_PTS_SIZE                          1024
-#define VKVG_VBO_SIZE                          (VKVG_PTS_SIZE * 4)
-#define VKVG_IBO_SIZE                          (VKVG_VBO_SIZE * 6)
-#define VKVG_PATHES_SIZE                       16
-#define VKVG_ARRAY_THRESHOLD           8
-
-#define VKVG_IBO_16                                    0
-#define VKVG_IBO_32                                    1
-
-#define VKVG_CUR_IBO_TYPE                      VKVG_IBO_32//change this only
-
-#if VKVG_CUR_IBO_TYPE == VKVG_IBO_16
-       #define VKVG_IBO_MAX                    UINT16_MAX
-       #define VKVG_IBO_INDEX_TYPE             uint16_t
-       #define VKVG_VK_INDEX_TYPE              VK_INDEX_TYPE_UINT16
-#else
-       #define VKVG_IBO_MAX                    UINT32_MAX
-       #define VKVG_IBO_INDEX_TYPE             uint32_t
-       #define VKVG_VK_INDEX_TYPE              VK_INDEX_TYPE_UINT32
-#endif
-
 #define FULLSCREEN_BIT 0x10000000
 #define SRCTYPE_MASK   0x000000FF
 
        #define CreateRgbaf(r, g, b, a) (((int)(a * 255.0f) << 24) | ((int)(b * 255.0f) << 16) | ((int)(g * 255.0f) << 8) | (int)(r * 255.0f))
 #endif
 
-typedef struct{
-       vec2 pos;
-       uint32_t color;
-       vec3 uv;
-}Vertex;
-
 typedef struct {
        vec4                    source;
        vec2                    size;
index 10492309bede066c0599a2c536a056aa8d92e687..1e83e4e9375889e2fd78e5ffc414d04112490838 100644 (file)
@@ -101,6 +101,11 @@ void _delete_threaded_object (VkvgDevice dev, vkvg_device_thread_items_t* throbj
 
        vkDestroyDescriptorPool (dev->vkDev, throbjs->descriptorPool,NULL);
 
+       free(throbjs->vertexCache);
+       free(throbjs->indexCache);
+       free(throbjs->pathes);
+       free(throbjs->points);
+
        free (throbjs);
 }
 void _add_threaded_objects (VkvgDevice dev, vkvg_device_thread_items_t* throbjs) {
@@ -126,8 +131,18 @@ vkvg_device_thread_items_t* _get_or_create_threaded_objects (VkvgDevice dev, thr
        tmp = (vkvg_device_thread_items_t*)calloc(1, sizeof(vkvg_device_thread_items_t));
        tmp->id = thrd_current();
        tmp->dev = dev;
-       tmp->sizeVBO = VKVG_VBO_SIZE;
-       tmp->sizeIBO = VKVG_IBO_SIZE;
+       tmp->sizeVertices = tmp->sizeVBO = VKVG_VBO_SIZE;
+       tmp->sizeIndices = tmp->sizeIBO = VKVG_IBO_SIZE;
+       tmp->sizePoints         = VKVG_PTS_SIZE;
+       tmp->sizeVertices       = VKVG_VBO_SIZE;
+       tmp->sizeIndices        = VKVG_IBO_SIZE;
+       tmp->sizePathes         = VKVG_PATHES_SIZE;
+
+       tmp->points     = (vec2*)malloc (VKVG_VBO_SIZE*sizeof(vec2));
+       tmp->pathes     = (uint32_t*)malloc (VKVG_PATHES_SIZE*sizeof(uint32_t));
+       tmp->vertexCache = (Vertex*)malloc(tmp->sizeVertices * sizeof(Vertex));
+       tmp->indexCache = (VKVG_IBO_INDEX_TYPE*)malloc(tmp->sizeIndices * sizeof(VKVG_IBO_INDEX_TYPE));
+
 
        const VkDescriptorPoolSize descriptorPoolSize[] = {
                {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2 },
index 647ce22b37c0b047ee536470bcf4920dcda6ca33..268314382197d8da5efa9a20cb5c1273050f08bd 100644 (file)
 #define STENCIL_CLIP_BIT       0x2
 #define STENCIL_ALL_BIT                0x3
 
+#define VKVG_PTS_SIZE                          1024
+#define VKVG_VBO_SIZE                          (VKVG_PTS_SIZE * 4)
+#define VKVG_IBO_SIZE                          (VKVG_VBO_SIZE * 6)
+#define VKVG_PATHES_SIZE                       16
+#define VKVG_ARRAY_THRESHOLD           8
+
+#define VKVG_IBO_16                                    0
+#define VKVG_IBO_32                                    1
+
+#define VKVG_CUR_IBO_TYPE                      VKVG_IBO_32//change this only
+
+#if VKVG_CUR_IBO_TYPE == VKVG_IBO_16
+       #define VKVG_IBO_MAX                    UINT16_MAX
+       #define VKVG_IBO_INDEX_TYPE             uint16_t
+       #define VKVG_VK_INDEX_TYPE              VK_INDEX_TYPE_UINT16
+#else
+       #define VKVG_IBO_MAX                    UINT32_MAX
+       #define VKVG_IBO_INDEX_TYPE             uint32_t
+       #define VKVG_VK_INDEX_TYPE              VK_INDEX_TYPE_UINT32
+#endif
+
 extern PFN_vkCmdBindPipeline                   CmdBindPipeline;
 extern PFN_vkCmdBindDescriptorSets             CmdBindDescriptorSets;
 extern PFN_vkCmdBindIndexBuffer                        CmdBindIndexBuffer;
@@ -51,6 +72,12 @@ extern PFN_vkWaitForFences                           WaitForFences;
 extern PFN_vkResetFences                               ResetFences;
 extern PFN_vkResetCommandBuffer                        ResetCommandBuffer;
 
+typedef struct{
+       vec2 pos;
+       uint32_t color;
+       vec3 uv;
+}Vertex;
+
 //per thread vulkan object used in contexts
 typedef struct _vkvg_device_thread_items_t {
        thrd_t                          id;
@@ -69,6 +96,18 @@ typedef struct _vkvg_device_thread_items_t {
        vkvg_buff       vertices;               //vertex buffer with persistent mapped memory
        uint32_t        sizeVBO;                //size of vk vbo size
 
+       uint32_t        sizeIndices;    //reserved size
+       uint32_t        sizeVertices;   //reserved size
+
+       Vertex*         vertexCache;
+       VKVG_IBO_INDEX_TYPE* indexCache;
+
+       //pathes, exists until stroke of fill
+       vec2*           points;                 //points array
+       uint32_t        sizePoints;             //reserved size
+       //pathes array is a list of point count per segment
+       uint32_t*       pathes;
+       uint32_t        sizePathes;
 
        struct _vkvg_device_thread_items_t* next;
 }vkvg_device_thread_items_t;