From: Jean-Philippe Bruyère Date: Mon, 9 Sep 2019 21:54:18 +0000 (+0200) Subject: wip X-Git-Tag: v0.1-alpha~50 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=ab2b264dcca053f1bc0f5e06679cc54ca924584c;p=jp%2Fvkvg.git wip --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d569c11..a76a541 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ ELSE() UNSET(ENABLE_VALIDATION CACHE) UNSET(ENABLE_WIRED_FILL CACHE) ENDIF() -OPTION(VKVG_TEST_DIRECT_DRAW "Draw directly on backend surface, if off surface is blitted." ON) +OPTION(VKVG_TEST_DIRECT_DRAW "(Experimental)Draw directly on backend surface, if off surface is blitted." OFF) IF (VKVG_TEST_DIRECT_DRAW) ADD_DEFINITIONS (-DVKVG_TEST_DIRECT_DRAW) ENDIF () @@ -57,6 +57,10 @@ endif() IF (ENABLE_VALIDATION) ADD_DEFINITIONS (-DVKVG_USE_VALIDATION) + OPTION(ENABLE_RENDERDOC "enable renderdoc" OFF) + IF (ENABLE_RENDERDOC) + ADD_DEFINITIONS (-DVKVG_USE_RENDERDOC) + ENDIF () ENDIF () IF (ENABLE_WIRED_FILL) ADD_DEFINITIONS (-DVKVG_WIRED_DEBUG) @@ -241,6 +245,11 @@ IF (ENABLE_VALIDATION) ELSE () MESSAGE(STATUS "Validation\t\t= disabled.") ENDIF () +IF (ENABLE_RENDERDOC) + MESSAGE(STATUS "Renderdoc\t\t= enabled.") +ELSE () + MESSAGE(STATUS "Renderdoc\t\t= disabled.") +ENDIF () IF (VKVG_PREMULT_ALPHA) MESSAGE(STATUS "Premult Alpha\t= enabled.") ELSE () diff --git a/include/vkvg.h b/include/vkvg.h index c637625..4946f70 100644 --- a/include/vkvg.h +++ b/include/vkvg.h @@ -259,6 +259,7 @@ void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, f void vkvg_arc_negative (VkvgContext ctx, float xc, float yc, float radius, float a1, float a2); void vkvg_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, float x3, float y3); void vkvg_rectangle (VkvgContext ctx, float x, float y, float w, float h); +void vkvg_fill_rectangle (VkvgContext ctx, float x, float y, float w, float h); void vkvg_stroke (VkvgContext ctx); void vkvg_stroke_preserve (VkvgContext ctx); void vkvg_fill (VkvgContext ctx); diff --git a/shaders/vkvg_main.vert b/shaders/vkvg_main.vert index 95c95c9..c6fee38 100644 --- a/shaders/vkvg_main.vert +++ b/shaders/vkvg_main.vert @@ -62,7 +62,6 @@ void main() if (pc.fullScreenQuad != 0) { gl_Position = vec4(vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2) * 2.0f + -1.0f, 0.0f, 1.0f); outUV = vec3(0,0,-1); - //gl_Position = vec4(vec2((gl_VertexIndex << 1) & 2, gl_VertexIndex & 2) -1.0f, 0.0f, 1.0f); return; } diff --git a/src/vkvg_context.c b/src/vkvg_context.c index 7917f6a..b0cd188 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -353,7 +353,7 @@ void vkvg_arc (VkvgContext ctx, float xc, float yc, float radius, float a1, floa vec2 v = {cosf(a1)*radius + xc, sinf(a1)*radius + yc}; - float step = M_PIF/radius*0.5f; + float step = _get_arc_step(radius); float a = a1; if (_current_path_is_empty(ctx)) @@ -396,7 +396,7 @@ void vkvg_arc_negative (VkvgContext ctx, float xc, float yc, float radius, float vec2 v = {cosf(a1)*radius + xc, sinf(a1)*radius + yc}; - float step = M_PIF/radius*1.5f; + float step = _get_arc_step(radius); float a = a1; if (_current_path_is_empty(ctx)) @@ -466,6 +466,10 @@ void vkvg_rel_curve_to (VkvgContext ctx, float x1, float y1, float x2, float y2, vec2 cp = _get_current_position(ctx); vkvg_curve_to (ctx, cp.x + x1, cp.y + y1, cp.x + x2, cp.y + y2, cp.x + x3, cp.y + y3); } +void vkvg_fill_rectangle (VkvgContext ctx, float x, float y, float w, float h){ + _vao_add_rectangle (ctx,x,y,w,h); + _record_draw_cmd(ctx); +} void vkvg_rectangle (VkvgContext ctx, float x, float y, float w, float h){ _finish_path (ctx); @@ -540,8 +544,6 @@ void vkvg_fill_preserve (VkvgContext ctx){ LOG(LOG_INFO, "FILL: ctx = %lu; path cpt = %d;\n", ctx, ctx->pathPtr / 2); - _check_cmd_buff_state (ctx); - if (ctx->curFillRule == VKVG_FILL_RULE_EVEN_ODD){ _poly_fill (ctx); _bind_draw_pipeline (ctx); @@ -549,6 +551,7 @@ void vkvg_fill_preserve (VkvgContext ctx){ _draw_full_screen_quad(ctx,true); CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); }else{ + _check_cmd_buff_state (ctx); CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); _fill_ec(ctx); } diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index f09f300..686ca21 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -166,12 +166,15 @@ void _add_point (VkvgContext ctx, float x, float y){ } float _normalizeAngle(float a) { - float res = ROUND_DOWN(fmod(a,2.0f*M_PIF),100); + float res = ROUND_DOWN(fmodf(a,2.0f*M_PIF),100); if (res < 0.0f) return res + 2.0f*M_PIF; else return res; } +inline float _get_arc_step (float radius) { + return M_PIF/sqrtf(radius)*0.35f; +} void _create_gradient_buff (VkvgContext ctx){ vkvg_buffer_create (ctx->pSurf->dev, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, @@ -188,12 +191,31 @@ void _create_vertices_buff (VkvgContext ctx){ VMA_MEMORY_USAGE_CPU_TO_GPU, ctx->sizeIBO * sizeof(VKVG_IBO_INDEX_TYPE), &ctx->indices); } -const vec3 blankuv = {}; +void _resize_vbo (VkvgContext ctx, size_t new_size) { + _wait_flush_fence (ctx);//wait previous cmd if not completed + ctx->sizeVBO = new_size; + ctx->sizeVBO += ctx->sizeVBO % VKVG_VBO_SIZE; + vkvg_buffer_destroy (&ctx->vertices); + vkvg_buffer_create (ctx->pSurf->dev, + VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, + VMA_MEMORY_USAGE_CPU_TO_GPU, + ctx->sizeVBO * sizeof(Vertex), &ctx->vertices); +} +void _resize_ibo (VkvgContext ctx, size_t new_size) { + _wait_flush_fence (ctx);//wait previous cmd if not completed + ctx->sizeIBO = ctx->sizeIndices; + ctx->sizeIBO += ctx->sizeIBO % VKVG_IBO_SIZE; + vkvg_buffer_destroy (&ctx->indices); + vkvg_buffer_create (ctx->pSurf->dev, + VK_BUFFER_USAGE_INDEX_BUFFER_BIT, + VMA_MEMORY_USAGE_CPU_TO_GPU, + ctx->sizeIBO * sizeof(VKVG_IBO_INDEX_TYPE), &ctx->indices); +} void _add_vertexf (VkvgContext ctx, float x, float y){ Vertex* pVert = &ctx->vertexCache[ctx->vertCount]; pVert->pos.x = x; pVert->pos.y = y; - pVert->uv = blankuv; + pVert->uv = (vec3){0}; ctx->vertCount++; _check_vbo_size(ctx); @@ -236,7 +258,7 @@ void _vao_add_rectangle (VkvgContext ctx, float x, float y, float width, float h {{x+width,y}, {0,0,-1}}, {{x+width,y+height},{0,0,-1}} }; - VKVG_IBO_INDEX_TYPE firstIdx = ctx->vertCount; + VKVG_IBO_INDEX_TYPE firstIdx = ctx->vertCount - ctx->curVertOffset; Vertex* pVert = &ctx->vertexCache[ctx->vertCount]; memcpy (pVert,v,4*sizeof(Vertex)); ctx->vertCount+=4; @@ -353,14 +375,12 @@ void _record_draw_cmd (VkvgContext ctx){ vkh_cmd_end (ctx->cmd); _wait_and_submit_cmd (ctx); //we could resize here + _resize_vbo(ctx, ctx->sizeVertices); + _resize_ibo(ctx, ctx->sizeIndices); }else{ //should resize vbo here - _wait_flush_fence (ctx); - ctx->sizeVBO = ctx->sizeVertices; - ctx->sizeIBO = ctx->sizeIndices; - vkvg_buffer_destroy (&ctx->indices); - vkvg_buffer_destroy (&ctx->vertices); - _create_vertices_buff (ctx); + _resize_vbo(ctx, ctx->sizeVertices); + _resize_ibo(ctx, ctx->sizeIndices); } } @@ -958,22 +978,18 @@ void _poly_fill (VkvgContext ctx){ //we anticipate the check for vbo buffer size if (ctx->vertCount + ctx->pointCount > ctx->sizeVBO) { if (ctx->cmdStarted) { - _end_render_pass (ctx); - _flush_vertices_caches (ctx); - vkh_cmd_end (ctx->cmd); - _wait_and_submit_cmd (ctx); - //we could resize here after a wait fence - }else{ - _wait_flush_fence (ctx);//wait previous cmd if not completed - ctx->sizeVBO = ctx->vertCount + ctx->pointCount; - vkvg_buffer_destroy (&ctx->vertices); - vkvg_buffer_create (ctx->pSurf->dev, - VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, - VMA_MEMORY_USAGE_CPU_TO_GPU, - ctx->sizeVBO * sizeof(Vertex), &ctx->vertices); - } + _end_render_pass(ctx); + _flush_vertices_caches(ctx); + vkh_cmd_end(ctx->cmd); + _wait_and_submit_cmd(ctx); + if (ctx->vertCount + ctx->pointCount > ctx->sizeVBO) + _resize_vbo(ctx, ctx->vertCount + ctx->pointCount); + }else + _resize_vbo(ctx, ctx->vertCount + ctx->pointCount); + _start_cmd_for_render_pass(ctx); - } + }else + _check_cmd_buff_state(ctx); CmdBindPipeline (ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelinePolyFill); @@ -997,7 +1013,8 @@ void _poly_fill (VkvgContext ctx){ for (uint i = 0; i < pathPointCount; i++) { v.pos = ctx->points [i+firstPtIdx]; - _add_vertex (ctx, v); + ctx->vertexCache[ctx->vertCount] = v; + ctx->vertCount++; } LOG(LOG_INFO_PATH, "\tpoly fill: point count = %d; 1st vert = %d; vert count = %d\n", pathPointCount, firstVertIdx, ctx->vertCount - firstVertIdx); diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index d69f944..e742154 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -175,6 +175,7 @@ void _set_curve_end (VkvgContext ctx); bool _path_has_curves (VkvgContext ctx, uint ptrPath); float _normalizeAngle (float a); +float _get_arc_step (float radius); vec2 _get_current_position (VkvgContext ctx); void _add_point (VkvgContext ctx, float x, float y); diff --git a/src/vkvg_device_internal.c b/src/vkvg_device_internal.c index a7053fc..82c82b8 100644 --- a/src/vkvg_device_internal.c +++ b/src/vkvg_device_internal.c @@ -49,7 +49,7 @@ VkRenderPass _createRenderPassNoResolve(VkvgDevice dev, VkAttachmentLoadOp loadO .storeOp = VK_ATTACHMENT_STORE_OP_STORE, .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE, - .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, .finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL }; VkAttachmentDescription attDS = { .format = FB_STENCIL_FORMAT, @@ -58,7 +58,7 @@ VkRenderPass _createRenderPassNoResolve(VkvgDevice dev, VkAttachmentLoadOp loadO .storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE, .stencilLoadOp = stencilLoadOp, .stencilStoreOp = VK_ATTACHMENT_STORE_OP_STORE, - .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, + .initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, .finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL }; VkAttachmentDescription attachments[] = {attColor,attDS}; @@ -112,7 +112,7 @@ VkRenderPass _createRenderPassMS(VkvgDevice dev, VkAttachmentLoadOp loadOp, VkAt .storeOp = VK_ATTACHMENT_STORE_OP_STORE, .stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE, .stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE, - .initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, + .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, .finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL }; VkAttachmentDescription attDS = { .format = FB_STENCIL_FORMAT, diff --git a/src/vkvg_internal.h b/src/vkvg_internal.h index 39f4a00..d94daf3 100644 --- a/src/vkvg_internal.h +++ b/src/vkvg_internal.h @@ -36,7 +36,8 @@ #define PATH_HAS_CURVES_BIT 0x40000000 /* 2d most significant bit of path elmts start = true if curve data are present, stored to avoid emiting join in curves */ #define PATH_IS_CURVE_BIT 0x80000000 /* most significant bit of path elmts end mark curves data in path array */ - +#define PATH_IS_CONCAVE_BIT 0x40000000 /* 2d most significant bit of path elmts end = true if path is simple concave + triangulation for fill may be simplified*/ #define PATH_ELT_MASK 0x3FFFFFFF /* Bit mask for fetching path element value */ #define ROUNDF(f, c) (((float)((int)((f) * (c))) / (c))) diff --git a/tests/common/test.c b/tests/common/test.c index 362ff31..80d2c04 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -10,10 +10,11 @@ bool mouseDown = false; VkvgDevice device = NULL; VkvgSurface surf = NULL; -uint test_size = 250; // items drawn in one run, or complexity -int iterations = 100; // repeat test n times +uint test_size = 100; // items drawn in one run, or complexity +int iterations = 500; // repeat test n times static bool paused = false; +static VkSampleCountFlags samples = VK_SAMPLE_COUNT_4_BIT; static vk_engine_t* e; static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { @@ -69,7 +70,7 @@ void randomize_color (VkvgContext ctx) { (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, - 0.5f//0.8f*rand()/RAND_MAX + 0.2f + (float)rand()/RAND_MAX ); } /* from caskbench */ @@ -119,7 +120,7 @@ void init_test (uint width, uint height){ bool deferredResolve = false; - device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, VK_SAMPLE_COUNT_1_BIT, deferredResolve); + device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve); vkvg_device_set_dpy(device, 96, 96); @@ -198,7 +199,7 @@ void perform_test (void(*testfunc)(void),uint width, uint height) { bool deferredResolve = false; - device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, VK_SAMPLE_COUNT_1_BIT, deferredResolve); + device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve); vkvg_device_set_dpy(device, 96, 96); @@ -259,6 +260,9 @@ void perform_test (void(*testfunc)(void),uint width, uint height) { vkDeviceWaitIdle(e->dev->dev); + if (paused) + continue; + stop_time = get_tick(); run_time = stop_time - start_time; run_time_values[i] = run_time; diff --git a/tests/common/vkengine.c b/tests/common/vkengine.c index 4b54ead..92f6993 100644 --- a/tests/common/vkengine.c +++ b/tests/common/vkengine.c @@ -108,15 +108,17 @@ vk_engine_t* vkengine_create (VkPhysicalDeviceType preferedGPU, VkPresentModeKHR for (uint i=0;iphy, &device_info, NULL, &dev)); - e->dev = vkh_device_create(vkh_app_get_inst (e->app), pi->phy, dev); + e->dev = vkh_device_create(e->app, pi, &device_info); #if DEBUG dbgReport = vkh_device_create_debug_report (e->dev, diff --git a/tests/random_cirles.c b/tests/random_cirles.c index 6953cb5..2722692 100644 --- a/tests/random_cirles.c +++ b/tests/random_cirles.c @@ -9,7 +9,7 @@ void test(){ const float w = 800.f; VkvgContext ctx = vkvg_create(surf); - vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_NON_ZERO); + vkvg_set_fill_rule(ctx, VKVG_FILL_RULE_EVEN_ODD); vkvg_set_line_width(ctx, 1.0f); //vkvg_set_line_join(ctx,VKVG_LINE_JOIN_BEVEL); @@ -17,16 +17,12 @@ void test(){ for (uint i=0; i