From 4f23801d5c31fe074c0a38ad4b488ce715dc0403 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Mon, 2 Sep 2019 02:33:10 +0200 Subject: [PATCH] using scissor speed up full screen quad --- README.md | 11 ++++++----- src/vkvg_context.c | 3 +++ src/vkvg_context_internal.c | 29 +++++++++++++++++++++++------ src/vkvg_context_internal.h | 9 +++++++++ 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 521d4bd..89c6dc2 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ For API documentation and usage, please refer to the [Cairo](https://www.cairogr ### Current status: -- Fill (with stencil even-odd technic) and Stroke functional. +- Fill (stencil even-odd, non-zero with ear clipping). +- Stroke. - Basic painting operation. - Font system with caching operational. - Linear Gradients. @@ -73,15 +74,15 @@ make # Run Make ### To Do +- [ ] Use Scissor where possible. +- [ ] Improve stroke algorithms. - [ ] Radial gradients. - [ ] Dashed lines. - [ ] Operators. -- [ ] Improve stroke algorithms. -- [ ] Offscreen pattern building. - [x] Optimize vulkan memory allocations by sub-allocating from a single shared memory chunk per type. - [ ] Optimize command submissions. -- [ ] Test SDF font rendering. -- [ ] Avoid line joins inside curves and arc. +- [x] Test SDF font rendering. +- [x] Avoid line joins inside curves and arc. - [ ] Structured unit testing. - [ ] Perf and memory checks. - [ ] Code clean and comment. diff --git a/src/vkvg_context.c b/src/vkvg_context.c index a0a12ee..2e4c641 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -69,6 +69,9 @@ VkvgContext vkvg_create(VkvgSurface surf) ctx->indCount = 0; ctx->curIndStart = 0; + VkRect2D scissor = {{0,0},{ctx->pSurf->width,ctx->pSurf->height}}; + ctx->bounds = scissor; + ctx->savedStencils = malloc(0); push_constants pc = { diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index c28a20f..5a01542 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -98,13 +98,27 @@ void _clear_path (VkvgContext ctx){ ctx->pathPtr = 0; ctx->pointCount = 0; ctx->curvePtr = 0; + _resetMinMax(ctx); } inline bool _path_is_closed (VkvgContext ctx, uint32_t ptrPath){ return ctx->pathes[ptrPath] & PATH_CLOSED_BIT; } +void _resetMinMax (VkvgContext ctx) { + ctx->xMin = FLT_MAX; + ctx->xMax = FLT_MIN; + ctx->yMin = FLT_MAX; + ctx->yMax = FLT_MIN; +} void _add_point (VkvgContext ctx, float x, float y){ - vec2 v = {x,y}; - ctx->points[ctx->pointCount] = v; + if (x < ctx->xMin) + ctx->xMin = x; + if (x > ctx->xMax) + ctx->xMax = x; + if (y < ctx->yMin) + ctx->yMin = y; + if (y > ctx->yMax) + ctx->yMax = y; + ctx->points[ctx->pointCount] = (vec2){x,y}; ctx->pointCount++; } void _add_point_vec2(VkvgContext ctx, vec2 v){ @@ -303,8 +317,8 @@ void _start_cmd_for_render_pass (VkvgContext ctx) { CmdBeginRenderPass (ctx->cmd, &ctx->renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE); VkViewport viewport = {0,0,ctx->pSurf->width,ctx->pSurf->height,0,1}; CmdSetViewport(ctx->cmd, 0, 1, &viewport); - VkRect2D scissor = {{0,0},{ctx->pSurf->width,ctx->pSurf->height}}; - CmdSetScissor(ctx->cmd, 0, 1, &scissor); + + CmdSetScissor(ctx->cmd, 0, 1, &ctx->bounds); VkDescriptorSet dss[] = {ctx->dsFont,ctx->dsSrc,ctx->dsGrad}; CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineLayout, @@ -843,7 +857,7 @@ void _poly_fill (VkvgContext ctx){ uint32_t firstVertIdx = ctx->vertCount; if (_path_has_curves(ctx, ptrPath)) { - int i=0; + uint i=0; while (i < pathPointCount) { if (ptrPath + ptrCurve < ctx->pathPtr && ctx->pathes[ptrPath+2+ptrCurve] == i+firstPtIdx){ while (i < ctx->pathes[ptrPath+3+ptrCurve] && i < pathPointCount){ @@ -859,7 +873,7 @@ void _poly_fill (VkvgContext ctx){ } } }else{ - for (int i = 0; i < pathPointCount; i++) { + for (uint i = 0; i < pathPointCount; i++) { v.pos = ctx->points[i+firstPtIdx]; _add_vertex(ctx, v); } @@ -967,9 +981,12 @@ void _fill_ec (VkvgContext ctx){ static const uint32_t one = 1; static const uint32_t zero = 0; void _draw_full_screen_quad (VkvgContext ctx) { + VkRect2D r = {ctx->xMin, ctx->yMin, ctx->xMax - ctx->xMin, ctx->yMax - ctx->xMin}; + CmdSetScissor(ctx->cmd, 0, 1, &r); CmdPushConstants(ctx->cmd, ctx->pSurf->dev->pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 28, 4,&one); CmdDraw (ctx->cmd,3,1,0,0); CmdPushConstants(ctx->cmd, ctx->pSurf->dev->pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, 28, 4,&zero); + CmdSetScissor(ctx->cmd, 0, 1, &ctx->bounds); } diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index 54cd41e..fd08c70 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -84,6 +84,13 @@ typedef struct _vkvg_context_t { VkDescriptorSet dsSrc; //source ds VkDescriptorSet dsGrad; //gradient uniform buffer + VkRect2D bounds; + + float xMin; + float xMax; + float yMin; + float yMax; + vkvg_buff uboGrad; //uniform buff obj holdings gradient infos //vk buffers, holds data until flush @@ -161,6 +168,8 @@ vec2 _get_current_position (VkvgContext ctx); void _add_point (VkvgContext ctx, float x, float y); void _add_point_vec2 (VkvgContext ctx, vec2 v); +void _resetMinMax (VkvgContext ctx); + void _poly_fill (VkvgContext ctx); void _fill_ec (VkvgContext ctx);//earclipping fill void _draw_full_screen_quad (VkvgContext ctx); -- 2.47.3