From: Jean-Philippe Bruyère Date: Tue, 3 Sep 2019 17:25:03 +0000 (+0200) Subject: debug X-Git-Tag: v0.1-alpha~55 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=362351789a1335f569b2061203ecdf675c3841f3;p=jp%2Fvkvg.git debug --- diff --git a/src/vectors.c b/src/vectors.c index 5f7374c..686db85 100644 --- a/src/vectors.c +++ b/src/vectors.c @@ -22,11 +22,6 @@ #include "vectors.h" -// init float vector -inline vec2 vec2_create (float x, float y) { - vec2 v = {x,y}; - return v; -} // compute normal direction vector from line defined by 2 points in double precision vec2d vec2d_line_norm(vec2d a, vec2d b) { @@ -40,77 +35,66 @@ vec2d vec2d_line_norm(vec2d a, vec2d b) vec2 vec2_line_norm(vec2 a, vec2 b) { vec2 d = {b.x - a.x, b.y - a.y}; - float md = sqrt (d.x*d.x + d.y*d.y); + float md = sqrtf (d.x*d.x + d.y*d.y); d.x/=md; d.y/=md; return d; } // compute length of double vector 2d -double vec2d_length(vec2d v){ +inline double vec2d_length(vec2d v){ return sqrt (v.x*v.x + v.y*v.y); } // compute length of float vector 2d -float vec2_length(vec2 v){ - return sqrt (v.x*v.x + v.y*v.y); +inline float vec2_length(vec2 v){ + return sqrtf (v.x*v.x + v.y*v.y); } // normalize float vector vec2 vec2_norm(vec2 a) { - float m = sqrt (a.x*a.x + a.y*a.y); - vec2 d = {a.x/m, a.y/m}; - return d; + float m = sqrtf (a.x*a.x + a.y*a.y); + return (vec2){a.x/m, a.y/m}; } // normalize double vector vec2d vec2d_norm(vec2d a) { double m = sqrt (a.x*a.x + a.y*a.y); - vec2d d = {a.x/m, a.y/m}; - return d; + return (vec2d){a.x/m, a.y/m}; } // multiply 2d vector by scalar -vec2d vec2d_mult(vec2d a, double m){ - vec2d r = {a.x*m,a.y*m}; - return r; +inline vec2d vec2d_mult(vec2d a, double m){ + return (vec2d){a.x*m,a.y*m}; } // multiply 2d vector by scalar -vec2 vec2_mult(vec2 a, float m){ - vec2 r = {a.x*m,a.y*m}; - return r; +inline vec2 vec2_mult(vec2 a, float m){ + return (vec2){a.x*m,a.y*m}; } // compute perpendicular vector -vec2d vec2d_perp (vec2d a){ - vec2d vp = {a.y, -a.x}; - return vp; +inline vec2d vec2d_perp (vec2d a){ + return (vec2d){a.y, -a.x}; } // compute perpendicular vector -vec2 vec2_perp (vec2 a){ - vec2 vp = {a.y, -a.x}; - return vp; +inline vec2 vec2_perp (vec2 a){ + return (vec2){a.y, -a.x}; } // convert double precision vector to single precision -vec2 vec2d_to_vec2(vec2d vd){ - vec2 v = {vd.x,vd.y}; - return v; +inline vec2 vec2d_to_vec2(vec2d vd){ + return (vec2){(float)vd.x,(float)vd.y}; } // compute sum of two single precision vectors -vec2 vec2_add (vec2 a, vec2 b){ - vec2 r = {a.x + b.x, a.y + b.y}; - return r; +inline vec2 vec2_add (vec2 a, vec2 b){ + return (vec2){a.x + b.x, a.y + b.y}; } // compute sum of two double precision vectors -vec2d vec2d_add (vec2d a, vec2d b){ - vec2d r = {a.x + b.x, a.y + b.y}; - return r; +inline vec2d vec2d_add (vec2d a, vec2d b){ + return (vec2d){a.x + b.x, a.y + b.y}; } // compute subbstraction of two single precision vectors -vec2 vec2_sub (vec2 a, vec2 b){ - vec2 r = {a.x - b.x, a.y - b.y}; - return r; +inline vec2 vec2_sub (vec2 a, vec2 b){ + return (vec2){a.x - b.x, a.y - b.y}; } // compute subbstraction of two double precision vectors -vec2d vec2d_sub (vec2d a, vec2d b){ - vec2d r = {a.x - b.x, a.y - b.y}; - return r; +inline vec2d vec2d_sub (vec2d a, vec2d b){ + return (vec2d){a.x - b.x, a.y - b.y}; } // test equality of two single precision vectors bool vec2_equ (vec2 a, vec2 b){ diff --git a/src/vectors.h b/src/vectors.h index dbd37bb..6352e5e 100644 --- a/src/vectors.h +++ b/src/vectors.h @@ -73,7 +73,6 @@ typedef struct { }vec2i16; float vec2_length (vec2 v); -vec2 vec2_create (float x, float y); vec2 vec2_norm (vec2 a); vec2 vec2_perp (vec2 a); vec2 vec2_add (vec2 a, vec2 b); diff --git a/src/vkvg_context.c b/src/vkvg_context.c index 2643afc..02e47e8 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -34,9 +34,9 @@ static uint32_t dlpCount = 0; #endif static VkClearValue clearValues[3] = { - { 0.0f, 0.0f, 0.0f, 0.0f }, + { 0 }, { 1.0f, 0 }, - { 0.0f, 0.0f, 0.0f, 0.0f } + { 0 } }; /** @@ -179,8 +179,7 @@ void vkvg_destroy (VkvgContext ctx) return; _flush_cmd_buff(ctx); - - vkWaitForFences (ctx->pSurf->dev->vkDev, 1, &ctx->flushFence, VK_TRUE, VKVG_FENCE_TIMEOUT); + _wait_flush_fence(ctx); LOG(LOG_INFO, "DESTROY Context: ctx = %lu; surf = %lu\n", (ulong)ctx, (ulong)ctx->pSurf); @@ -502,8 +501,8 @@ void vkvg_clip_preserve (VkvgContext ctx){ LOG(LOG_INFO, "CLIP: ctx = %lu; path cpt = %d;\n", ctx, ctx->pathPtr / 2); - if (ctx->pointCount * 4 > ctx->sizeIndices - ctx->indCount)//flush if vk buff is full - _flush_cmd_buff(ctx); + _check_flush_needed (ctx); + if (ctx->curFillRule == VKVG_FILL_RULE_EVEN_ODD){ _check_cmd_buff_state(ctx); @@ -535,10 +534,8 @@ void vkvg_fill_preserve (VkvgContext ctx){ LOG(LOG_INFO, "FILL: ctx = %lu; path cpt = %d;\n", ctx, ctx->pathPtr / 2); - if (ctx->pointCount * 4 > ctx->sizeIndices - ctx->indCount)//flush if vk buff is full - _flush_cmd_buff(ctx); - - _check_cmd_buff_state(ctx); + _check_flush_needed (ctx); + _check_cmd_buff_state (ctx); if (ctx->curFillRule == VKVG_FILL_RULE_EVEN_ODD){ _poly_fill (ctx); @@ -559,10 +556,9 @@ void vkvg_stroke_preserve (VkvgContext ctx) LOG(LOG_INFO, "STROKE: ctx = %lu; path cpt = %d;\n", ctx, ctx->pathPtr / 2); - if (ctx->pointCount * 4 > ctx->sizeIndices - ctx->indCount) - _flush_cmd_buff(ctx); + _check_flush_needed (ctx); - Vertex v = {}; + Vertex v = {0}; v.uv.z = -1; float hw = ctx->lineWidth / 2.0f; @@ -572,7 +568,7 @@ void vkvg_stroke_preserve (VkvgContext ctx) while (ptrPath < ctx->pathPtr){ uint ptrCurve = 0; - uint32_t firstIdx = ctx->vertCount; + VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)ctx->vertCount; i = ctx->pathes[ptrPath]&PATH_ELT_MASK; LOG(LOG_INFO_PATH, "\tPATH: start = %d; ", ctx->pathes[ptrPath]&PATH_ELT_MASK, ctx->pathes[ptrPath+1]&PATH_ELT_MASK); @@ -686,8 +682,8 @@ void vkvg_stroke_preserve (VkvgContext ctx) i++; }else{ - iR = ctx->pathes[ptrPath]&PATH_ELT_MASK; - _build_vb_step(ctx,v,hw,iL,i,iR, false); + iR = ctx->pathes[ptrPath] & PATH_ELT_MASK; + _build_vb_step (ctx,v,hw,iL,i,iR, false); VKVG_IBO_INDEX_TYPE* inds = &ctx->indexCache [ctx->indCount-6]; VKVG_IBO_INDEX_TYPE ii = firstIdx; @@ -702,8 +698,8 @@ void vkvg_stroke_preserve (VkvgContext ctx) _record_draw_cmd(ctx); } void vkvg_paint (VkvgContext ctx){ - _check_cmd_buff_state(ctx); - _draw_full_screen_quad(ctx,true); + _check_cmd_buff_state (ctx); + _draw_full_screen_quad (ctx, true); } inline void vkvg_set_source_rgb (VkvgContext ctx, float r, float g, float b) { vkvg_set_source_rgba (ctx, r, g, b, 1); @@ -856,7 +852,6 @@ void vkvg_save (VkvgContext ctx){ _bind_draw_pipeline (ctx); CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); - sav->lineWidth = ctx->lineWidth; sav->curOperator= ctx->curOperator; sav->lineCap = ctx->lineCap; @@ -916,6 +911,7 @@ void vkvg_restore (VkvgContext ctx){ CmdSetStencilCompareMask (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT); _flush_cmd_buff (ctx); + _wait_flush_fence (ctx); uint8_t curSaveStencil = ctx->curSavBit / 6; if (ctx->curSavBit > 0 && ctx->curSavBit % 6 == 0){//addtional save/restore stencil image have to be copied back to surf stencil first @@ -944,7 +940,7 @@ void vkvg_restore (VkvgContext ctx){ VK_CHECK_RESULT(vkEndCommandBuffer(ctx->cmd)); _wait_and_submit_cmd (ctx); - + _wait_flush_fence (ctx); vkh_image_destroy (savStencil); } diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index 504fcaa..b8411e4 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -36,11 +36,12 @@ #include "vkh_queue.h" #include "vkh_image.h" -void _check_cmd_buff_state (VkvgContext ctx) { +void _check_flush_needed (VkvgContext ctx) { if (!ctx->cmdStarted) - _start_cmd_for_render_pass(ctx); - else if (ctx->pushCstDirty) - _update_push_constants(ctx); + return; + if (ctx->pointCount * 4 < ctx->sizeIndices - ctx->indCount) + return; + _flush_cmd_buff(ctx); } void _check_vbo_size (VkvgContext ctx) { if (ctx->sizeVertices - ctx->vertCount > VKVG_ARRAY_THRESHOLD) @@ -52,7 +53,7 @@ void _check_ibo_size (VkvgContext ctx) { if (ctx->sizeIndices - ctx->indCount > VKVG_ARRAY_THRESHOLD) return; ctx->sizeIndices += VKVG_IBO_SIZE; - ctx->indexCache = (VKVG_IBO_INDEX_TYPE*) realloc (ctx->vertexCache, ctx->sizeVertices * sizeof(VKVG_IBO_INDEX_TYPE)); + ctx->indexCache = (VKVG_IBO_INDEX_TYPE*) realloc (ctx->indexCache, ctx->sizeIndices * sizeof(VKVG_IBO_INDEX_TYPE)); } void _check_pathes_array (VkvgContext ctx){ if (ctx->sizePathes - ctx->pathPtr - ctx->curvePtr > VKVG_ARRAY_THRESHOLD) @@ -154,7 +155,7 @@ void _create_gradient_buff (VkvgContext ctx){ void _create_vertices_buff (VkvgContext ctx){ ctx->vertexCache = (Vertex*)malloc(ctx->sizeVertices * sizeof(Vertex)); - ctx->indexCache = (VKVG_IBO_INDEX_TYPE*)malloc(ctx->sizeVertices * sizeof(VKVG_IBO_INDEX_TYPE)); + ctx->indexCache = (VKVG_IBO_INDEX_TYPE*)malloc(ctx->sizeIndices * sizeof(VKVG_IBO_INDEX_TYPE)); vkvg_buffer_create (ctx->pSurf->dev, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, @@ -212,7 +213,12 @@ void _vao_add_rectangle (VkvgContext ctx, float x, float y, float width, float h _add_tri_indices_for_rect(ctx, firstIdx); } - +void _check_cmd_buff_state (VkvgContext ctx) { + if (!ctx->cmdStarted) + _start_cmd_for_render_pass(ctx); + else if (ctx->pushCstDirty) + _update_push_constants(ctx); +} void _create_cmd_buff (VkvgContext ctx){ vkh_cmd_buffs_create((VkhDevice)ctx->pSurf->dev, ctx->cmdPool,VK_COMMAND_BUFFER_LEVEL_PRIMARY, 2, ctx->cmdBuffers); #if defined(DEBUG) && defined(ENABLE_VALIDATION) @@ -240,12 +246,15 @@ void _clear_attachment (VkvgContext ctx) { inline void _wait_flush_fence (VkvgContext ctx) { vkWaitForFences (ctx->pSurf->dev->vkDev, 1, &ctx->flushFence, VK_TRUE, VKVG_FENCE_TIMEOUT); } +inline void _reset_flush_fence (VkvgContext ctx) { + vkResetFences (ctx->pSurf->dev->vkDev, 1, &ctx->flushFence); +} void _wait_and_submit_cmd (VkvgContext ctx){ if (!ctx->cmdStarted) return; _wait_flush_fence (ctx); - vkResetFences (ctx->pSurf->dev->vkDev, 1, &ctx->flushFence); + _reset_flush_fence(ctx); _submit_cmd (ctx->pSurf->dev, &ctx->cmd, ctx->flushFence); @@ -279,29 +288,32 @@ void _wait_and_submit_cmd (VkvgContext ctx){ VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL , VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT); }*/ - +//this func expect cmdStarted to be true, so that vert and ind count are > 0 void _end_render_pass (VkvgContext ctx) { _record_draw_cmd (ctx); LOG(LOG_INFO, "END RENDER PASS: ctx = %lu;\n", ctx); CmdEndRenderPass (ctx->cmd); ctx->renderPassBeginInfo.renderPass = ctx->pSurf->dev->renderPass; + + //copy vertex and index caches to the vbo and ibo vkbuffers + _wait_flush_fence (ctx); + + memcpy(ctx->vertices.allocInfo.pMappedData, ctx->vertexCache, ctx->vertCount * sizeof (Vertex)); + memcpy(ctx->indices.allocInfo.pMappedData, ctx->indexCache, ctx->indCount * sizeof (VKVG_IBO_INDEX_TYPE)); + + ctx->vertCount = 0; + ctx->indCount = 0; + ctx->curIndStart = 0; } void _flush_cmd_buff (VkvgContext ctx){ if (!ctx->cmdStarted) return; - memcpy(ctx->vertices.allocInfo.pMappedData, ctx->vertexCache, ctx->vertCount * sizeof (Vertex)); - memcpy(ctx->indices.allocInfo.pMappedData, ctx->indexCache, ctx->indCount * sizeof (VKVG_IBO_INDEX_TYPE)); - - _end_render_pass (ctx); - vkh_cmd_end (ctx->cmd); + _end_render_pass (ctx); + vkh_cmd_end (ctx->cmd); LOG(LOG_INFO, "FLUSH CTX: ctx = %lu; vertices = %d; indices = %d\n", ctx, ctx->vertCount, ctx->indCount); _wait_and_submit_cmd(ctx); - - ctx->vertCount = 0; - ctx->indCount = 0; - ctx->curIndStart = 0; } //bind correct draw pipeline depending on current OPERATOR diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index 400c87d..b378caf 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -29,7 +29,7 @@ #include "vkvg_fonts.h" #define VKVG_PTS_SIZE 4096 -#define VKVG_VBO_SIZE 4096 * 8 +#define VKVG_VBO_SIZE VKVG_PTS_SIZE * 8 #define VKVG_IBO_SIZE VKVG_VBO_SIZE * 6 #define VKVG_PATHES_SIZE 16 #define VKVG_ARRAY_THRESHOLD 4 @@ -157,11 +157,13 @@ typedef struct _ear_clip_point{ struct _ear_clip_point* next; }ear_clip_point; -bool _current_path_is_empty (VkvgContext ctx); -void _start_sub_path (VkvgContext ctx, float x, float y); +void _check_flush_needed (VkvgContext ctx); void _check_vbo_size (VkvgContext ctx); void _check_ibo_size (VkvgContext ctx); void _check_pathes_array (VkvgContext ctx); + +bool _current_path_is_empty (VkvgContext ctx); +void _start_sub_path (VkvgContext ctx, float x, float y); void _finish_path (VkvgContext ctx); void _clear_path (VkvgContext ctx); bool _path_is_closed (VkvgContext ctx, uint32_t ptrPath); @@ -196,6 +198,7 @@ void _check_cmd_buff_state (VkvgContext ctx); void _flush_cmd_buff (VkvgContext ctx); void _record_draw_cmd (VkvgContext ctx); void _wait_flush_fence (VkvgContext ctx); +void _reset_flush_fence (VkvgContext ctx); void _wait_and_submit_cmd (VkvgContext ctx); void _update_push_constants (VkvgContext ctx); void _update_cur_pattern (VkvgContext ctx, VkvgPattern pat); diff --git a/src/vkvg_device_internal.c b/src/vkvg_device_internal.c index d7daeca..244d652 100644 --- a/src/vkvg_device_internal.c +++ b/src/vkvg_device_internal.c @@ -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}; @@ -121,7 +121,7 @@ VkRenderPass _createRenderPassMS(VkvgDevice dev, VkAttachmentLoadOp loadOp, VkAt .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[] = {attColorResolve,attDS,attColor}; diff --git a/tests/common/test.c b/tests/common/test.c index 869b95e..8aa1f7c 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -77,9 +77,9 @@ void init_test (uint width, uint height){ vkengine_set_cursor_pos_callback(e, mouse_move_callback); vkengine_set_scroll_callback(e, scroll_callback); - bool deferredResolve = true; + 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_4_BIT, deferredResolve); + 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); vkvg_device_set_dpy(device, 96, 96); @@ -141,7 +141,7 @@ void perform_test (void(*testfunc)(void),uint width, uint height) { vkengine_set_cursor_pos_callback(e, mouse_move_callback); vkengine_set_scroll_callback(e, scroll_callback); - bool deferredResolve = false; + bool deferredResolve = true; device = vkvg_device_create_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, VK_SAMPLE_COUNT_4_BIT, deferredResolve); @@ -173,10 +173,12 @@ void perform_test (void(*testfunc)(void),uint width, uint height) { vkDestroyFence (e->dev->dev, fences[i], NULL); fences[i] = NULL; } - vkvg_surface_destroy(surfaces[i]); - surfaces[i] = vkvg_surface_create_for_VkhImage (device, r->ScBuffers[i]); + vkvg_surface_destroy (surfaces[i]); } vkDestroyFence (e->dev->dev, fence, NULL); + vkh_presenter_create_swapchain (r); + for (uint i=0; i < r->imgCount;i++) + surfaces[i] = vkvg_surface_create_for_VkhImage (device, r->ScBuffers[i]); }else{ surf = surfaces[r->currentScBufferIndex]; if (fences[r->currentScBufferIndex] != NULL){ @@ -195,8 +197,7 @@ void perform_test (void(*testfunc)(void),uint width, uint height) { .pSwapchains = &r->swapChain, .pImageIndices = &r->currentScBufferIndex }; - /* Make sure command buffer is finished before presenting */ - VK_CHECK_RESULT(vkQueuePresentKHR(r->queue, &present)); + vkQueuePresentKHR(r->queue, &present); } #else testfunc(); @@ -236,5 +237,4 @@ void perform_test (void(*testfunc)(void),uint width, uint height) { vkvg_device_destroy (device); vkengine_destroy (e); - } diff --git a/vkh b/vkh index 4824a7e..bced714 160000 --- a/vkh +++ b/vkh @@ -1 +1 @@ -Subproject commit 4824a7ec5b113892f2fdac0059f0e0f88a490625 +Subproject commit bced7146e49377256b4e4ab8856e02a7b3a50355