]> O.S.I.I.S - jp/vkvg.git/commitdiff
don't clear stencil on surf creation, but on ctx first pass, polyfill vao size check...
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 14 Jan 2022 15:22:51 +0000 (16:22 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 14 Jan 2022 15:22:51 +0000 (16:22 +0100)
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_context_internal.h
src/vkvg_surface_internal.c

index 7835951a9279764c5615489658e1d745ed5af2e4..f497a5442e8fb3f517fc6ca56d6b9363216e4fc1 100644 (file)
@@ -161,9 +161,6 @@ VkvgContext vkvg_create(VkvgSurface surf)
        vkh_device_set_object_name((VkhDevice)dev, VK_OBJECT_TYPE_BUFFER, (uint64_t)ctx->vertices.buffer, "CTX Vertex Buff");
 #endif
 
-       //force run of one renderpass (even empty) to perform clear load op
-       //_start_cmd_for_render_pass(ctx);
-
        return ctx;
 }
 void vkvg_flush (VkvgContext ctx){
index 658e65761cc1845dc7d06cc3adfa14aac15ac604..d40d2b7f0a0e8f712e125f97c299a48f43d7f697 100644 (file)
@@ -46,29 +46,50 @@ void _resize_vertex_cache (VkvgContext ctx, uint32_t newSize) {
                ctx->vertCount, ctx->sizeVertices, newSize, (size_t)newSize * sizeof(Vertex), ctx->vertexCache, tmp);
        if (tmp == NULL){
                ctx->status = VKVG_STATUS_NO_MEMORY;
-               LOG(VKVG_LOG_ERR, "resize vertex cache failed: vert count: %u byte size: %zu\n", ctx->sizeVertices, ctx->sizeVertices * sizeof(Vertex));
+               LOG(VKVG_LOG_ERR, "resize vertex cache failed: vert count: %u byte size: %zu\n", newSize, newSize * sizeof(Vertex));
                return;
        }
        ctx->vertexCache = tmp;
        ctx->sizeVertices = newSize;
 }
+void _resize_index_cache (VkvgContext ctx, uint32_t newSize) {
+       VKVG_IBO_INDEX_TYPE* tmp = (VKVG_IBO_INDEX_TYPE*) realloc (ctx->indexCache, (size_t)newSize * sizeof(VKVG_IBO_INDEX_TYPE));
+       LOG(VKVG_LOG_DBG_ARRAYS, "resize IBO: new size: %lu Ptr: %p -> %p\n", (size_t)newSize * sizeof(VKVG_IBO_INDEX_TYPE), ctx->indexCache, tmp);
+       if (tmp == NULL){
+               ctx->status = VKVG_STATUS_NO_MEMORY;
+               LOG(VKVG_LOG_ERR, "resize IBO failed: idx count: %u size(byte): %zu\n", newSize, (size_t)newSize * sizeof(VKVG_IBO_INDEX_TYPE));
+               return;
+       }
+       ctx->indexCache = tmp;
+       ctx->sizeIndices = newSize;
+}
+void _ensure_vertex_cache_size (VkvgContext ctx, uint32_t addedVerticesCount) {
+       if (ctx->sizeVertices - ctx->vertCount > VKVG_ARRAY_THRESHOLD + addedVerticesCount)
+               return;
+       uint32_t newSize = ctx->sizeVertices + addedVerticesCount;
+       uint32_t modulo = addedVerticesCount % VKVG_VBO_SIZE;
+       if (modulo > 0)
+               newSize += VKVG_VBO_SIZE - modulo;
+       _resize_vertex_cache (ctx, newSize);
+}
 void _check_vertex_cache_size (VkvgContext ctx) {
        if (ctx->sizeVertices - ctx->vertCount > VKVG_ARRAY_THRESHOLD)
                return;
        _resize_vertex_cache (ctx, ctx->sizeVertices + VKVG_VBO_SIZE);
 }
+void _ensure_index_cache_size (VkvgContext ctx, uint32_t addedIndicesCount) {
+       if (ctx->sizeIndices - ctx->indCount > VKVG_ARRAY_THRESHOLD + addedIndicesCount)
+               return;
+       uint32_t newSize = ctx->sizeIndices + addedIndicesCount;
+       uint32_t modulo = addedIndicesCount % VKVG_IBO_SIZE;
+       if (modulo > 0)
+               newSize += VKVG_IBO_SIZE - modulo;
+       _resize_index_cache (ctx, newSize);
+}
 void _check_index_cache_size (VkvgContext ctx) {
        if (ctx->sizeIndices - ctx->indCount > VKVG_ARRAY_THRESHOLD)
                return;
-       ctx->sizeIndices += VKVG_IBO_SIZE;
-       VKVG_IBO_INDEX_TYPE* tmp = (VKVG_IBO_INDEX_TYPE*) realloc (ctx->indexCache, (size_t)ctx->sizeIndices * sizeof(VKVG_IBO_INDEX_TYPE));
-       LOG(VKVG_LOG_DBG_ARRAYS, "resize IBO: new size: %u Ptr: %p -> %p\n", ctx->sizeIndices, ctx->indexCache, tmp);
-       if (tmp == NULL){
-               ctx->status = VKVG_STATUS_NO_MEMORY;
-               LOG(VKVG_LOG_ERR, "resize IBO failed: idx count: %u size(byte): %zu\n", ctx->sizeIndices, (size_t)ctx->sizeIndices * sizeof(VKVG_IBO_INDEX_TYPE));
-               return;
-       }
-       ctx->indexCache = tmp;
+       _resize_index_cache (ctx, ctx->sizeIndices + VKVG_IBO_SIZE);
 }
 //check host path array size, return true if error. pathPtr is already incremented
 bool _check_pathes_array (VkvgContext ctx){
@@ -571,6 +592,9 @@ void _start_cmd_for_render_pass (VkvgContext ctx) {
                vkh_image_set_layout(ctx->cmd, ctx->pSurf->img, VK_IMAGE_ASPECT_COLOR_BIT,
                                                 VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
                                                 VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
+               vkh_image_set_layout (ctx->cmd, ctx->pSurf->stencil, VK_IMAGE_ASPECT_STENCIL_BIT,
+                                                         VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
+                                                         VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
        }
 
 #if defined(DEBUG) && defined (VKVG_DBG_UTILS)
@@ -1505,7 +1529,7 @@ void _elliptic_arc (VkvgContext ctx, float x1, float y1, float x2, float y2, boo
 //Even-Odd inside test with stencil buffer implementation.
 void _poly_fill (VkvgContext ctx){
        //we anticipate the check for vbo buffer size, ibo is not used in poly_fill
-       if (ctx->vertCount + ctx->pointCount > ctx->sizeVBO) {
+       if (ctx->vertCount + ctx->pointCount < ctx->sizeVBO) {
                if (ctx->cmdStarted) {
                        _end_render_pass(ctx);
                        _flush_vertices_caches(ctx);
@@ -1535,14 +1559,6 @@ void _poly_fill (VkvgContext ctx){
                if (pathPointCount > 2) {
                        VKVG_IBO_INDEX_TYPE firstVertIdx = (VKVG_IBO_INDEX_TYPE)ctx->vertCount;
 
-                       if (ctx->sizeVertices - ctx->vertCount < VKVG_ARRAY_THRESHOLD + pathPointCount) {
-                               VKVG_IBO_INDEX_TYPE newSize = ctx->sizeVertices + pathPointCount;
-                               VKVG_IBO_INDEX_TYPE modulo = pathPointCount % VKVG_VBO_SIZE;
-                               if (modulo > 0)
-                                       newSize += VKVG_VBO_SIZE - modulo;
-                               _resize_vertex_cache (ctx, newSize);
-                       }
-
                        for (uint32_t i = 0; i < pathPointCount; i++) {
                                v.pos = ctx->points [i+firstPtIdx];
                                ctx->vertexCache[ctx->vertCount++] = v;
index de546d6fd94ec2f84c48159e5560d7abe491fce8..537fc8f081cb30e08cc53b843a993c55ea4875d3 100644 (file)
@@ -170,7 +170,7 @@ typedef struct _vkvg_context_t {
        uint32_t        indCount;               //current indice count
 
        uint32_t        curIndStart;    //last index recorded in cmd buff
-       uint32_t        curVertOffset;  //vertex offset in draw indexed command
+       VKVG_IBO_INDEX_TYPE     curVertOffset;  //vertex offset in draw indexed command
 
        vkvg_buff       vertices;               //vertex buffer with persistent mapped memory
        uint32_t        sizeVBO;                //size of vk vbo size
@@ -244,9 +244,14 @@ typedef struct {
        VKVG_IBO_INDEX_TYPE firstIdx;//save first point idx for closed path
 }stroke_context_t;
 
-void _check_vertex_cache_size(VkvgContext ctx);
-void _resize_vertex_cache      (VkvgContext ctx, uint32_t newSize);
-void _check_index_cache_size(VkvgContext ctx);
+void _check_vertex_cache_size  (VkvgContext ctx);
+void _ensure_vertex_cache_size (VkvgContext ctx, uint32_t addedVerticesCount);
+void _resize_vertex_cache              (VkvgContext ctx, uint32_t newSize);
+
+void _check_index_cache_size   (VkvgContext ctx);
+void _ensure_index_cache_size  (VkvgContext ctx, uint32_t addedIndicesCount);
+void _resize_index_cache               (VkvgContext ctx, uint32_t newSize);
+
 bool _check_pathes_array       (VkvgContext ctx);
 
 bool _current_path_is_empty (VkvgContext ctx);
index 470965e3084a74a6db5b7b3b20933e3c7b71c67d..19cf0d8e8beca8a20497153f11c3f80e1584207b 100644 (file)
@@ -166,7 +166,7 @@ void _create_surface_images (VkvgSurface surf) {
        _create_surface_secondary_images(surf);
        _create_framebuffer                             (surf);
 
-       _clear_surface                          (surf, VK_IMAGE_ASPECT_STENCIL_BIT);
+       //_clear_surface                                        (surf, VK_IMAGE_ASPECT_STENCIL_BIT);
 #if defined(DEBUG) && defined(ENABLE_VALIDATION)
        vkh_image_set_name(surf->img, "surfImg");
        vkh_image_set_name(surf->imgMS, "surfImgMS");