]> O.S.I.I.S - jp/vkvg.git/commitdiff
using host cached vbo and ibo, memcpy before draw
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 2 Sep 2019 13:07:47 +0000 (15:07 +0200)
committerj-p <jp_bruyere@hotmail.com>
Tue, 3 Sep 2019 18:36:09 +0000 (20:36 +0200)
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h
src/vkvg_device_internal.c
src/vkvg_device_internal.h

index 92849c2f3089b5cd0157b403fc6be6424fb5031b..2cdd7cc04e36d3c3a12ae53d22f7da0d06fdb7e6 100644 (file)
@@ -194,6 +194,9 @@ void vkvg_destroy (VkvgContext ctx)
     vkvg_buffer_destroy (&ctx->indices);
     vkvg_buffer_destroy (&ctx->vertices);
 
+    free(ctx->vertexCache);
+    free(ctx->indexCache);
+
     //vkh_image_destroy   (ctx->source);
 
     free(ctx->selectedFont.fontFile);
@@ -679,7 +682,7 @@ void vkvg_stroke_preserve (VkvgContext ctx)
             iR = ctx->pathes[ptrPath]&PATH_ELT_MASK;
             _build_vb_step(ctx,v,hw,iL,i,iR, false);
 
-            uint32_t* inds = (uint32_t*)(ctx->indices.allocInfo.pMappedData + ((ctx->indCount-6) * sizeof(uint32_t)));
+            uint32_t* inds = &ctx->indexCache [ctx->indCount-6];
             uint32_t ii = firstIdx;
             inds[1] = ii;
             inds[4] = ii;
index c25528a5a01d35dbad3990a99d784d6f71160f10..bd9c30df3b6752e48ebcf58b36823730a0952f3c 100644 (file)
@@ -140,6 +140,10 @@ void _create_gradient_buff (VkvgContext ctx){
         sizeof(vkvg_gradient_t), &ctx->uboGrad);
 }
 void _create_vertices_buff (VkvgContext ctx){
+
+    ctx->vertexCache = (Vertex*)malloc(ctx->sizeVertices * sizeof(Vertex));
+    ctx->indexCache = (uint32_t*)malloc(ctx->sizeVertices * sizeof(uint32_t));
+
     vkvg_buffer_create (ctx->pSurf->dev,
         VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
         VMA_MEMORY_USAGE_CPU_TO_GPU,
@@ -151,23 +155,21 @@ void _create_vertices_buff (VkvgContext ctx){
 }
 const vec3 blankuv = {};
 void _add_vertexf (VkvgContext ctx, float x, float y){
-    Vertex* pVert = (Vertex*)(ctx->vertices.allocInfo.pMappedData + ctx->vertCount * sizeof(Vertex));
+    Vertex* pVert = &ctx->vertexCache[ctx->vertCount];
     pVert->pos.x = x;
     pVert->pos.y = y;
     pVert->uv = blankuv;
     ctx->vertCount++;
 }
 void _add_vertex(VkvgContext ctx, Vertex v){
-    Vertex* pVert = (Vertex*)(ctx->vertices.allocInfo.pMappedData + ctx->vertCount * sizeof(Vertex));
-    *pVert = v;
+    ctx->vertexCache[ctx->vertCount] = v;
     ctx->vertCount++;
 }
 void _set_vertex(VkvgContext ctx, uint32_t idx, Vertex v){
-    Vertex* pVert = (Vertex*)(ctx->vertices.allocInfo.pMappedData + idx * sizeof(Vertex));
-    *pVert = v;
+    ctx->vertexCache[idx] = v;
 }
 void _add_tri_indices_for_rect (VkvgContext ctx, uint32_t i){
-    uint32_t* inds = (uint32_t*)(ctx->indices.allocInfo.pMappedData + (ctx->indCount * sizeof(uint32_t)));
+    uint32_t* inds = &ctx->indexCache[ctx->indCount];
     inds[0] = i;
     inds[1] = i+2;
     inds[2] = i+1;
@@ -177,7 +179,7 @@ void _add_tri_indices_for_rect (VkvgContext ctx, uint32_t i){
     ctx->indCount+=6;
 }
 void _add_triangle_indices(VkvgContext ctx, uint32_t i0, uint32_t i1, uint32_t i2){
-    uint32_t* inds = (uint32_t*)(ctx->indices.allocInfo.pMappedData + (ctx->indCount * sizeof(uint32_t)));
+    uint32_t* inds = &ctx->indexCache[ctx->indCount];
     inds[0] = i0;
     inds[1] = i1;
     inds[2] = i2;
@@ -192,7 +194,7 @@ void _vao_add_rectangle (VkvgContext ctx, float x, float y, float width, float h
         {{x+width,y+height},{0,0,-1}}
     };
     uint32_t firstIdx = ctx->vertCount;
-    Vertex* pVert = (Vertex*)(ctx->vertices.allocInfo.pMappedData + ctx->vertCount * sizeof(Vertex));
+    Vertex* pVert = &ctx->vertexCache[ctx->vertCount];
     memcpy (pVert,v,4*sizeof(Vertex));
     ctx->vertCount+=4;
     _add_tri_indices_for_rect(ctx, firstIdx);
@@ -269,6 +271,10 @@ void _end_render_pass (VkvgContext ctx) {
     ctx->renderPassBeginInfo.renderPass = ctx->pSurf->dev->renderPass;
 }
 void _flush_cmd_buff (VkvgContext ctx){
+
+    memcpy(ctx->vertices.allocInfo.pMappedData, ctx->vertexCache, ctx->vertCount * sizeof (Vertex));
+    memcpy(ctx->indices.allocInfo.pMappedData, ctx->indexCache, ctx->indCount * sizeof (uint32_t));
+
     if (!ctx->cmdStarted)
         return;
     _end_render_pass        (ctx);
@@ -529,7 +535,7 @@ void add_line(vkvg_context* ctx, vec2 p1, vec2 p2, vec4 col){
     _add_vertex(ctx, v);
     v.pos = p2;
     _add_vertex(ctx, v);
-    uint32_t* inds = (uint32_t*)(ctx->indices.allocInfo.pMappedData  + (ctx->indCount * sizeof(uint32_t)));
+    uint32_t* inds = &ctx->indexCache [ctx->indCount];
     inds[0] = ctx->vertCount - 2;
     inds[1] = ctx->vertCount - 1;
     ctx->indCount+=2;
index 27cba31ade478687e7d1f2b6049d2daf3d259d12..d844741e746f904bfb2fafd22688fcf3dc0e8312 100644 (file)
@@ -104,6 +104,10 @@ typedef struct _vkvg_context_t {
     size_t             sizeVertices;   //reserved size
     uint32_t   vertCount;      //effective vertices count
 
+    Vertex*     vertexCache;
+    uint32_t*   indexCache;
+
+
     //pathes, exists until stroke of fill
     vec2*              points;         //points array
     size_t             sizePoints;     //reserved size
index d9b40003278d959f8d90657650a09f098bfa066d..98c7eba926f8815e110f406cc1aca73b2b405454 100644 (file)
@@ -370,6 +370,9 @@ void _createDescriptorSetLayout (VkvgDevice dev) {
     VK_CHECK_RESULT(vkCreatePipelineLayout(dev->vkDev, &pipelineLayoutCreateInfo, NULL, &dev->pipelineLayout));
 }
 
+void _wait_idle (VkvgDevice dev) {
+    vkDeviceWaitIdle (dev->vkDev);
+}
 void _wait_and_reset_device_fence (VkvgDevice dev) {
     vkWaitForFences (dev->vkDev, 1, &dev->fence, VK_TRUE, UINT64_MAX);
     vkResetFences (dev->vkDev, 1, &dev->fence);
index 49f4ffa56007c778ae639c8e4dad5a6397c96f98..3d27f442aedbfba47b8347457498243bb68a2fa7 100644 (file)
@@ -107,6 +107,7 @@ VkRenderPass _createRenderPassNoResolve(VkvgDevice dev, VkAttachmentLoadOp loadO
 void _setupPipelines            (VkvgDevice dev);
 void _createDescriptorSetLayout (VkvgDevice dev);
 void _flush_all_contexes        (VkvgDevice dev);
+void _wait_idle                 (VkvgDevice dev);
 void _wait_and_reset_device_fence (VkvgDevice dev);
 void _submit_cmd                (VkvgDevice dev, VkCommandBuffer* cmd, VkFence fence);
 #endif