ctx->selectedFont.fontFile = (char*)calloc(FONT_FILE_NAME_MAX_SIZE,sizeof(char));
ctx->currentFont = NULL;
- ctx->flushFence = vkh_fence_create((VkhDevice)dev);
+ ctx->flushFence = vkh_fence_create_signaled ((VkhDevice)dev);
ctx->points = (vec2*) malloc (VKVG_VBO_SIZE*sizeof(vec2));
ctx->pathes = (uint32_t*) malloc (VKVG_PATHES_SIZE*sizeof(uint32_t));
_clear_path (ctx);
+ ctx->cmd = ctx->cmdBuffers[0];//current recording buffer
+
ctx->references = 1;
ctx->status = VKVG_STATUS_SUCCESS;
return ctx;
*/
void vkvg_flush (VkvgContext ctx){
_flush_cmd_buff(ctx);
+ _wait_flush_fence(ctx);
/*
#ifdef DEBUG
_flush_cmd_buff(ctx);
+ vkWaitForFences (ctx->pSurf->dev->vkDev, 1, &ctx->flushFence, VK_TRUE, VKVG_FENCE_TIMEOUT);
+
LOG(LOG_INFO, "DESTROY Context: ctx = %lu; surf = %lu\n", (ulong)ctx, (ulong)ctx->pSurf);
if (ctx->pattern)
VkDevice dev = ctx->pSurf->dev->vkDev;
vkDestroyFence (dev, ctx->flushFence,NULL);
- vkFreeCommandBuffers(dev, ctx->cmdPool, 1, &ctx->cmd);
+ vkFreeCommandBuffers(dev, ctx->cmdPool, 2, ctx->cmdBuffers);
vkDestroyCommandPool(dev, ctx->cmdPool, NULL);
VkDescriptorSet dss[] = {ctx->dsFont, ctx->dsSrc, ctx->dsGrad};
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
- vkvg_flush(ctx);
+ _flush_cmd_buff(ctx);
if (ctx->curFillRule == VKVG_FILL_RULE_EVEN_ODD){
_check_cmd_buff_state(ctx);
_poly_fill (ctx);
- CmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineClipping);
- CmdSetStencilReference(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
+ CmdBindPipeline (ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineClipping);
+ CmdSetStencilReference (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT);
- CmdSetStencilWriteMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_ALL_BIT);
+ CmdSetStencilWriteMask (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_ALL_BIT);
}else{
_check_cmd_buff_state(ctx);
- CmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineClipping);
- CmdSetStencilReference (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT);
+ CmdBindPipeline (ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineClipping);
+ CmdSetStencilReference (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT);
CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
- CmdSetStencilWriteMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT);
+ CmdSetStencilWriteMask (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT);
_fill_ec(ctx);
- CmdSetStencilReference(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
+ CmdSetStencilReference (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT);
- CmdSetStencilWriteMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_ALL_BIT);
+ CmdSetStencilWriteMask (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_ALL_BIT);
}
- _draw_full_screen_quad(ctx,false);
+ _draw_full_screen_quad (ctx, false);
//should test current operator to bind correct pipeline
_bind_draw_pipeline (ctx);
- CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
+ CmdSetStencilCompareMask (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
}
void vkvg_fill_preserve (VkvgContext ctx){
if (ctx->pathPtr == 0) //nothing to fill
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
- vkvg_flush(ctx);
+ _flush_cmd_buff(ctx);
_check_cmd_buff_state(ctx);
_draw_full_screen_quad(ctx,true);
CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
}else{
- //CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_FILL_BIT);
CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
_fill_ec(ctx);
}
LOG(LOG_INFO, "STROKE: ctx = %lu; path cpt = %d;\n", ctx, ctx->pathPtr / 2);
if (ctx->pointCount * 4 > ctx->sizeIndices - ctx->indCount)
- vkvg_flush(ctx);
+ _flush_cmd_buff(ctx);
Vertex v = {};
v.uv.z = -1;
void vkvg_save (VkvgContext ctx){
LOG(LOG_INFO, "SAVE CONTEXT: ctx = %lu\n", (ulong)ctx);
- _flush_cmd_buff(ctx);
+ _flush_cmd_buff (ctx);
+ _wait_flush_fence (ctx);
VkvgDevice dev = ctx->pSurf->dev;
vkvg_context_save_t* sav = (vkvg_context_save_t*)calloc(1,sizeof(vkvg_context_save_t));
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
VK_CHECK_RESULT(vkEndCommandBuffer(ctx->cmd));
- _submit_wait_and_reset_cmd(ctx);
+ _wait_and_submit_cmd(ctx);
}
uint8_t curSaveBit = 1 << (ctx->curSavBit % 6 + 2);
- _start_cmd_for_render_pass(ctx);
+ _start_cmd_for_render_pass (ctx);
- CmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineClipping);
+ CmdBindPipeline (ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineClipping);
- CmdSetStencilReference(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT|curSaveBit);
+ CmdSetStencilReference (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT|curSaveBit);
CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
- CmdSetStencilWriteMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, curSaveBit);
+ CmdSetStencilWriteMask (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, curSaveBit);
- _draw_full_screen_quad(ctx,false);
+ _draw_full_screen_quad (ctx, false);
_bind_draw_pipeline (ctx);
CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
ctx->pushConsts = sav->pushConsts;
if (sav->pattern)
- _update_cur_pattern(ctx, sav->pattern);
+ _update_cur_pattern (ctx, sav->pattern);
- _flush_cmd_buff(ctx);
+ _flush_cmd_buff (ctx);
+ _wait_flush_fence (ctx);
ctx->curSavBit--;
uint8_t curSaveBit = 1 << (ctx->curSavBit % 6 + 2);
- _start_cmd_for_render_pass(ctx);
+ _start_cmd_for_render_pass (ctx);
- CmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineClipping);
+ CmdBindPipeline (ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelineClipping);
- CmdSetStencilReference(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT|curSaveBit);
+ CmdSetStencilReference (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT|curSaveBit);
CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, curSaveBit);
- CmdSetStencilWriteMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
+ CmdSetStencilWriteMask (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
- _draw_full_screen_quad(ctx,false);
+ _draw_full_screen_quad (ctx, false);
_bind_draw_pipeline (ctx);
- CmdSetStencilCompareMask(ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
+ CmdSetStencilCompareMask (ctx->cmd, VK_STENCIL_FRONT_AND_BACK, STENCIL_CLIP_BIT);
- _flush_cmd_buff(ctx);
+ _flush_cmd_buff (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
VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
VK_CHECK_RESULT(vkEndCommandBuffer(ctx->cmd));
- _submit_wait_and_reset_cmd(ctx);
+ _wait_and_submit_cmd (ctx);
- vkh_image_destroy(savStencil);
+ vkh_image_destroy (savStencil);
}
ctx->lineWidth = sav->lineWidth;
void _create_cmd_buff (VkvgContext ctx){
- ctx->cmd = vkh_cmd_buff_create((VkhDevice)ctx->pSurf->dev, ctx->cmdPool,VK_COMMAND_BUFFER_LEVEL_PRIMARY);
+ vkh_cmd_buffs_create((VkhDevice)ctx->pSurf->dev, ctx->cmdPool,VK_COMMAND_BUFFER_LEVEL_PRIMARY, 2, ctx->cmdBuffers);
#if defined(DEBUG) && defined(ENABLE_VALIDATION)
vkh_device_set_object_name((VkhDevice)ctx->pSurf->dev, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)ctx->cmd, "vkvgCtxCmd");
#endif
void _clear_attachment (VkvgContext ctx) {
}
-inline void _submit_ctx_cmd(VkvgContext ctx){
- _submit_cmd (ctx->pSurf->dev, &ctx->cmd, ctx->flushFence);
+inline void _wait_flush_fence (VkvgContext ctx) {
+ vkWaitForFences (ctx->pSurf->dev->vkDev, 1, &ctx->flushFence, VK_TRUE, VKVG_FENCE_TIMEOUT);
}
-void _wait_and_reset_ctx_cmd (VkvgContext ctx){
+void _wait_and_submit_cmd (VkvgContext ctx){
if (!ctx->cmdStarted)
return;
- vkWaitForFences(ctx->pSurf->dev->vkDev,1,&ctx->flushFence,VK_TRUE,UINT64_MAX);
- vkResetFences(ctx->pSurf->dev->vkDev,1,&ctx->flushFence);
- vkResetCommandBuffer(ctx->cmd,0);
- ctx->cmdStarted = false;
-}
-inline void _submit_wait_and_reset_cmd (VkvgContext ctx){
- _submit_ctx_cmd(ctx);
- _wait_and_reset_ctx_cmd(ctx);
+ _wait_flush_fence (ctx);
+ vkResetFences (ctx->pSurf->dev->vkDev, 1, &ctx->flushFence);
+
+ _submit_cmd (ctx->pSurf->dev, &ctx->cmd, ctx->flushFence);
+
+ if (ctx->cmd == ctx->cmdBuffers[0])
+ ctx->cmd = ctx->cmdBuffers[1];
+ else
+ ctx->cmd = ctx->cmdBuffers[0];
+
+ vkResetCommandBuffer (ctx->cmd, 0);
+ ctx->cmdStarted = false;
}
/*void _explicit_ms_resolve (VkvgContext ctx){//should init cmd before calling this (unused, using automatic resolve by renderpass)
vkh_image_set_layout (ctx->cmd, ctx->pSurf->imgMS, VK_IMAGE_ASPECT_COLOR_BIT,
ctx->renderPassBeginInfo.renderPass = ctx->pSurf->dev->renderPass;
}
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 (uint32_t));
- if (!ctx->cmdStarted)
- return;
_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);
- _submit_wait_and_reset_cmd(ctx);
+ _wait_and_submit_cmd(ctx);
ctx->vertCount = 0;
ctx->indCount = 0;
//flush ctx in two steps to add the src transitioning in the cmd buff
if (ctx->cmdStarted)//transition of img without appropriate dependencies in subpass must be done outside renderpass.
- _end_render_pass (ctx);
+ _end_render_pass (ctx);
else {
vkh_cmd_begin (ctx->cmd,VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
ctx->cmdStarted = true;
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
- vkh_cmd_end (ctx->cmd);
- _submit_wait_and_reset_cmd(ctx);
+ vkh_cmd_end (ctx->cmd);
+ _wait_and_submit_cmd (ctx);
ctx->source = surf->img;
vkvg_pattern_destroy (lastPat);
}
void _update_descriptor_set (VkvgContext ctx, VkhImage img, VkDescriptorSet ds){
+ _wait_flush_fence(ctx);//descriptorSet update invalidate cmd buffs
VkDescriptorImageInfo descSrcTex = vkh_image_get_descriptor (img, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VkWriteDescriptorSet writeDescriptorSet = {
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
// Continue subdivision
//----------------------
- _recursive_bezier(ctx, x1, y1, x12, y12, x123, y123, x1234, y1234, level + 1);
- _recursive_bezier(ctx, x1234, y1234, x234, y234, x34, y34, x4, y4, level + 1);
+ _recursive_bezier (ctx, x1, y1, x12, y12, x123, y123, x1234, y1234, level + 1);
+ _recursive_bezier (ctx, x1234, y1234, x234, y234, x34, y34, x4, y4, level + 1);
}
void _poly_fill (VkvgContext ctx){
- CmdBindPipeline(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelinePolyFill);
+ CmdBindPipeline (ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->pSurf->dev->pipelinePolyFill);
uint32_t ptrPath = 0;
Vertex v = {};
//close path
ctx->pathes[ptrPath] |= PATH_CLOSED_BIT;// ctx->pathes[ptrPath];//close path by setting start and end equal
- uint32_t firstPtIdx = ctx->pathes[ptrPath]&PATH_ELT_MASK;
- uint32_t lastPtIdx = ctx->pathes[ptrPath+1]&PATH_ELT_MASK;//_get_last_point_of_closed_path (ctx, ptrPath);
+ uint32_t firstPtIdx = ctx->pathes [ptrPath] & PATH_ELT_MASK;
+ uint32_t lastPtIdx = ctx->pathes [ptrPath+1] & PATH_ELT_MASK;//_get_last_point_of_closed_path (ctx, ptrPath);
uint32_t pathPointCount = lastPtIdx - firstPtIdx + 1;
uint32_t firstVertIdx = ctx->vertCount;
for (uint i = 0; i < pathPointCount; i++) {
- v.pos = ctx->points[i+firstPtIdx];
- _add_vertex(ctx, v);
+ v.pos = ctx->points [i+firstPtIdx];
+ _add_vertex (ctx, v);
}
LOG(LOG_INFO_PATH, "\tpoly fill: point count = %d; 1st vert = %d; vert count = %d\n", pathPointCount, firstVertIdx, ctx->vertCount - firstVertIdx);