From: Jean-Philippe Bruyère Date: Thu, 10 Sep 2020 16:45:50 +0000 (+0200) Subject: rename _flush_undrawn to emit_undrawn X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=511940574345a38286bf2e8bcf4e4406a96cda4b;p=jp%2Fvkvg.git rename _flush_undrawn to emit_undrawn --- diff --git a/src/vkvg_context.c b/src/vkvg_context.c index d305109..f2f0988 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -450,7 +450,7 @@ static const VkClearAttachment clearStencil = {VK_IMAGE_ASPECT_STENCIL_BI static const VkClearAttachment clearColorAttach = {VK_IMAGE_ASPECT_COLOR_BIT, 0, {{{0}}}}; void vkvg_reset_clip (VkvgContext ctx){ - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); if (!ctx->cmdStarted) { //if command buffer is not already started and in a renderpass, we use the renderpass //with the loadop clear for stencil @@ -462,7 +462,7 @@ void vkvg_reset_clip (VkvgContext ctx){ vkCmdClearAttachments(ctx->cmd, 1, &clearStencil, 1, &ctx->clearRect); } void vkvg_clear (VkvgContext ctx){ - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); if (!ctx->cmdStarted) { ctx->renderPassBeginInfo.renderPass = ctx->pSurf->dev->renderPass_ClearAll; _start_cmd_for_render_pass(ctx); @@ -489,7 +489,7 @@ void vkvg_clip_preserve (VkvgContext ctx){ if (ctx->pathPtr == 0 && _current_path_is_empty(ctx))//nothing to clip return; - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); _finish_path(ctx); @@ -506,7 +506,7 @@ void vkvg_clip_preserve (VkvgContext ctx){ CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); CmdSetStencilWriteMask (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT); _fill_ec(ctx); - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); } CmdSetStencilReference (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT); @@ -526,7 +526,7 @@ void vkvg_fill_preserve (VkvgContext ctx){ LOG(VKVG_LOG_INFO, "FILL: ctx = %p; path cpt = %d;\n", ctx, ctx->pathPtr / 2); if (ctx->curFillRule == VKVG_FILL_RULE_EVEN_ODD){ - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); _poly_fill (ctx); _bind_draw_pipeline (ctx); @@ -537,7 +537,7 @@ void vkvg_fill_preserve (VkvgContext ctx){ } if (ctx->vertCount - ctx->curVertOffset + ctx->pointCount > VKVG_IBO_MAX) - _flush_undrawn_vertices(ctx);//limit draw call to addressable vx with choosen index type + _emit_draw_cmd_undrawn_vertices(ctx);//limit draw call to addressable vx with choosen index type if (ctx->pattern)//if not solid color, source img of gradient has to be bound _ensure_renderpass_is_started(ctx); @@ -546,7 +546,7 @@ void vkvg_fill_preserve (VkvgContext ctx){ void _draw_stoke_cap (VkvgContext ctx, float hw, vec2 p0, vec2 n, bool isStart) { Vertex v = {{0},ctx->curColor,{0,0,-1}}; - VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset); + VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset); if (isStart){ vec2 vhw = vec2_mult(n,hw); @@ -650,7 +650,14 @@ void _draw_segment (VkvgContext ctx, float hw, bool isCurve) { iL = curPathPointIdx++; } -bool _process_stroke (VkvgContext ctx) { +void vkvg_stroke_preserve (VkvgContext ctx) +{ + if (ctx->pathPtr == 0 && _current_path_is_empty(ctx))//nothing to stroke + return; + _finish_path(ctx); + + LOG(VKVG_LOG_INFO, "STROKE: ctx = %p; path ptr = %d;\n", ctx, ctx->pathPtr); + curPathPointIdx = lastPathPointIdx = ptrPath = iL = iR = 0; float hw = ctx->lineWidth / 2.0f; @@ -681,7 +688,7 @@ bool _process_stroke (VkvgContext ctx) { totDashLength+=ctx->dashes[i]; if (totDashLength == 0){ ctx->status = VKVG_STATUS_INVALID_DASH; - return true; + return; } /*if (ctx->dashOffset == 0) curDashOffset = 0; @@ -752,8 +759,28 @@ bool _process_stroke (VkvgContext ctx) { }else _draw_stoke_cap (ctx, hw, ctx->points[curPathPointIdx], vec2_line_norm(ctx->points[curPathPointIdx-1], ctx->points[curPathPointIdx]), false); - if (ctx->vertCount - ctx->curVertOffset > VKVG_IBO_MAX) - return false; + /*if (ctx->vertCount - ctx->curVertOffset > VKVG_IBO_MAX) { + _check_vao_size (ctx); + _ensure_renderpass_is_started(ctx); + + //split triangle emission into batch adressable by VKVG_IBO_MAX (index type) + VKVG_IBO_INDEX_TYPE indexMax = VKVG_IBO_MAX - VKVG_IBO_MAX % 3; + uint32_t vxTot = ctx->vertCount; + uint32_t idxTot = ctx->indCount; + ctx->indCount = ctx->curIndStart; + + + while (ctx->curVertOffset < vxTot) { + while (ctx->indexCache[ctx->indCount] < indexMax) + ctx->indCount++; + ctx->indCount -= ctx->indCount % 3; + uint32_t minInd = + uint32_t newVertOffset = ctx->indexCache[ctx->indCount-1]; + + _emit_draw (ctx); + } + + } */ curPathPointIdx = firstPathPointIdx + pathPointCount; @@ -763,29 +790,6 @@ bool _process_stroke (VkvgContext ctx) { ptrPath++; } - - - - return true; -} - -void vkvg_stroke_preserve (VkvgContext ctx) -{ - if (ctx->pathPtr == 0 && _current_path_is_empty(ctx))//nothing to stroke - return; - _finish_path(ctx); - - LOG(VKVG_LOG_INFO, "STROKE: ctx = %p; path ptr = %d;\n", ctx, ctx->pathPtr); - - uint32_t tmpVxCount = ctx->vertCount; - uint32_t tmpIxCount = ctx->indCount; - - if (!_process_stroke(ctx)) { - ctx->vertCount = tmpVxCount; - ctx->indCount = tmpIxCount; - _flush_undrawn_vertices(ctx);//limit draw call to addressable vx with choosen index type - _process_stroke(ctx); - } } void vkvg_paint (VkvgContext ctx){ if (ctx->pathPtr || ctx->segmentPtr){//path to fill @@ -1098,35 +1102,35 @@ void vkvg_restore (VkvgContext ctx){ } void vkvg_translate (VkvgContext ctx, float dx, float dy){ - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); vkvg_matrix_translate (&ctx->pushConsts.mat, dx, dy); _set_mat_inv_and_vkCmdPush (ctx); } void vkvg_scale (VkvgContext ctx, float sx, float sy){ - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); vkvg_matrix_scale (&ctx->pushConsts.mat, sx, sy); _set_mat_inv_and_vkCmdPush (ctx); } void vkvg_rotate (VkvgContext ctx, float radians){ - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); vkvg_matrix_rotate (&ctx->pushConsts.mat, radians); _set_mat_inv_and_vkCmdPush (ctx); } void vkvg_transform (VkvgContext ctx, const vkvg_matrix_t* matrix) { - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); vkvg_matrix_t res; vkvg_matrix_multiply (&res, &ctx->pushConsts.mat, matrix); ctx->pushConsts.mat = res; _set_mat_inv_and_vkCmdPush (ctx); } void vkvg_identity_matrix (VkvgContext ctx) { - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); vkvg_matrix_t im = VKVG_IDENTITY_MATRIX; ctx->pushConsts.mat = im; _set_mat_inv_and_vkCmdPush (ctx); } void vkvg_set_matrix (VkvgContext ctx, const vkvg_matrix_t* matrix){ - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); ctx->pushConsts.mat = (*matrix); _set_mat_inv_and_vkCmdPush (ctx); } diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index dceba19..d0a53e3 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -439,7 +439,7 @@ void _check_vao_size (VkvgContext ctx) { } //stroke and non-zero draw call for solid color flush -void _flush_undrawn_vertices (VkvgContext ctx){ +void _emit_draw_cmd_undrawn_vertices (VkvgContext ctx){ if (ctx->indCount == ctx->curIndStart) return; @@ -472,7 +472,7 @@ void _flush_cmd_until_vx_base (VkvgContext ctx){ _wait_and_submit_cmd (ctx); } void _flush_cmd_buff (VkvgContext ctx){ - _flush_undrawn_vertices (ctx); + _emit_draw_cmd_undrawn_vertices (ctx); if (!ctx->cmdStarted) return; _end_render_pass (ctx); @@ -578,7 +578,7 @@ void _update_cur_pattern (VkvgContext ctx, VkvgPattern pat) { break; case VKVG_PATTERN_TYPE_SURFACE: { - _flush_undrawn_vertices(ctx); + _emit_draw_cmd_undrawn_vertices(ctx); VkvgSurface surf = (VkvgSurface)pat->data; diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index 9d1a141..95a52ab 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -215,9 +215,10 @@ void _vao_add_rectangle (VkvgContext ctx, float x, float y, float width, flo void _bind_draw_pipeline (VkvgContext ctx); void _create_cmd_buff (VkvgContext ctx); +void _check_vao_size (VkvgContext ctx); void _ensure_renderpass_is_started (VkvgContext ctx); void _flush_cmd_buff (VkvgContext ctx); -void _flush_undrawn_vertices(VkvgContext ctx); +void _emit_draw_cmd_undrawn_vertices(VkvgContext ctx); void _flush_cmd_until_vx_base (VkvgContext ctx); void _wait_flush_fence (VkvgContext ctx); void _reset_flush_fence (VkvgContext ctx); diff --git a/tests/common/test.c b/tests/common/test.c index ef7d207..349ada8 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -33,8 +33,8 @@ bool mouseDown = false; VkvgDevice device = NULL; VkvgSurface surf = NULL; -uint32_t test_size = 10; // items drawn in one run, or complexity -uint32_t iterations = 100;// repeat test n times +uint32_t test_size = 500; // items drawn in one run, or complexity +uint32_t iterations = 500;// repeat test n times uint32_t test_width = 512; uint32_t test_height= 512; bool test_vsync = false; diff --git a/tests/dashes.c b/tests/dashes.c index d0d6269..310d4ae 100644 --- a/tests/dashes.c +++ b/tests/dashes.c @@ -89,12 +89,12 @@ void curve () { int main(int argc, char *argv[]) { //PERFORM_TEST(test, argc, argv); //vkvg_log_level = VKVG_LOG_ERR|VKVG_LOG_DEBUG|VKVG_LOG_INFO|VKVG_LOG_INFO_PATH|VKVG_LOG_DBG_ARRAYS|VKVG_LOG_FULL; - dashes_count = 1; - dashes[0] = 50; - dashes[1] = 60; - line_width = 10; + dashes_count = 2; + dashes[0] = 2; + dashes[1] = 3; + line_width = 2; line_cap = VKVG_LINE_CAP_ROUND; PERFORM_TEST(path, argc, argv); - PERFORM_TEST(curve, argc, argv); + //PERFORM_TEST(curve, argc, argv); return 0; } diff --git a/tests/test1.c b/tests/test1.c index a689a2e..7b66037 100644 --- a/tests/test1.c +++ b/tests/test1.c @@ -297,6 +297,23 @@ void cairo_test_line_joins (VkvgContext cr) { vkvg_rel_line_to (cr, 51.2f, 51.2f); vkvg_set_line_join (cr, VKVG_LINE_JOIN_ROUND); vkvg_stroke (cr); + + /* draw helping lines */ + vkvg_set_source_rgb (cr, 1, 0.2f, 0.2f); + vkvg_set_line_width (cr, 2.56f); + vkvg_set_line_join (cr, VKVG_LINE_JOIN_MITER); + vkvg_move_to (cr, 76.8f, 84.48f); + vkvg_rel_line_to (cr, 51.2f, -51.2f); + vkvg_rel_line_to (cr, 51.2f, 51.2f); + vkvg_move_to (cr, 76.8f, 161.28f); + vkvg_rel_line_to (cr, 51.2f, -51.2f); + vkvg_rel_line_to (cr, 51.2f, 51.2f); + vkvg_move_to (cr, 76.8f, 238.08f); + vkvg_rel_line_to (cr, 51.2f, -51.2f); + vkvg_rel_line_to (cr, 51.2f, 51.2f); + + vkvg_stroke (cr); + } void cairo_print_arc (VkvgContext cr) { float xc = 128.0f;