summaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2026-10-17 20:12:51 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2026-10-17 20:12:51 +0200
commit470714239728600e72c6453fc62b8854562679ef (patch)
treeed80a433ce00e6aa14b726847b1781830a09bc25
parent42f7118a6cfc48965410ab52b4e18a466e4082b3 (diff)
wip
-rw-r--r--src/vkvg_context.c32
-rw-r--r--src/vkvg_context_internal.c47
-rw-r--r--src/vkvg_context_internal.h11
-rw-r--r--src/vkvg_device.c7
-rw-r--r--src/vkvg_device_internal.c19
-rw-r--r--src/vkvg_device_internal.h6
-rw-r--r--src/vkvg_fonts.c64
-rw-r--r--src/vkvg_fonts.h8
-rw-r--r--src/vkvg_surface.c12
-rw-r--r--src/vkvg_surface_internal.c56
-rw-r--r--src/vkvg_surface_internal.h4
11 files changed, 184 insertions, 82 deletions
diff --git a/src/vkvg_context.c b/src/vkvg_context.c
index 382b121..5a7c1eb 100644
--- a/src/vkvg_context.c
+++ b/src/vkvg_context.c
@@ -148,10 +148,10 @@ VkvgContext vkvg_create(VkvgSurface surf) {
_create_vertices_buff(ctx);
_create_gradient_buff(ctx);
_create_cmd_buff(ctx);
- _createDescriptorPool(ctx);
- _init_descriptor_sets(ctx);
- _font_cache_update_context_descset(ctx);
- _update_gradient_desc_set(ctx);
+ //_createDescriptorPool(ctx);
+ //_init_descriptor_sets(ctx);
+ //_font_cache_update_context_descset(ctx);
+ //_update_gradient_desc_set(ctx);
_clear_path(ctx);
@@ -171,11 +171,8 @@ VkvgContext vkvg_create(VkvgSurface surf) {
#ifndef VKVG_ENABLE_VK_TIMELINE_SEMAPHORE
vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_FENCE, (uint64_t)ctx->flushFence, "CTX Flush Fence");
#endif
- vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t)ctx->descriptorPool,
- "CTX Descriptor Pool");
- vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)ctx->dsSrc, "CTX DescSet SOURCE");
- vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)ctx->dsFont, "CTX DescSet FONT");
- vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)ctx->dsGrad, "CTX DescSet GRADIENT");
+ //vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)ctx->dsSrc, "CTX DescSet SOURCE");
+ //vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)ctx->dsGrad, "CTX DescSet GRADIENT");
vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_BUFFER, (uint64_t)ctx->indices.buffer, "CTX Index Buff");
vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_BUFFER, (uint64_t)ctx->vertices.buffer, "CTX Vertex Buff");
@@ -1048,6 +1045,7 @@ void vkvg_set_source_rgb(VkvgContext ctx, float r, float g, float b) {
return;
RECORD(ctx, VKVG_CMD_SET_SOURCE_RGB, r, g, b);
ctx->curColor = CreateRgbaf(r, g, b, 1);
+ _emit_draw_cmd_undrawn_vertices(ctx);
_update_cur_pattern(ctx, NULL);
}
void vkvg_set_source_rgba(VkvgContext ctx, float r, float g, float b, float a) {
@@ -1061,10 +1059,18 @@ void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y
if (vkvg_status(ctx) || vkvg_surface_status(surf))
return;
RECORD(ctx, VKVG_CMD_SET_SOURCE_SURFACE, x, y, surf);
- ctx->pushConsts.source.x = x;
- ctx->pushConsts.source.y = y;
- _update_cur_pattern(ctx, vkvg_pattern_create_for_surface(surf));
- ctx->pushCstDirty = true;
+ ctx->pushConsts.source = (vec4) { x, y, (float)surf->width, (float)surf->height };
+ ctx->pushConsts.fsq_patternType = (ctx->pushConsts.fsq_patternType & FULLSCREEN_BIT) + VKVG_PATTERN_TYPE_SURFACE;
+ ctx->pushCstDirty = true;
+
+ _ensure_renderpass_is_started(ctx);
+ /*vkh_image_set_layout(ctx->cmd, surf->img, VK_IMAGE_ASPECT_COLOR_BIT,
+ 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);*/
+
+ CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->dev->pipelineLayout,
+ 1, 1, &surf->dsSrc, 0, NULL);
+
}
void vkvg_set_source(VkvgContext ctx, VkvgPattern pat) {
if (vkvg_status(ctx) || vkvg_pattern_status(pat))
diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c
index 97f0c43..7a986aa 100644
--- a/src/vkvg_context_internal.c
+++ b/src/vkvg_context_internal.c
@@ -652,11 +652,12 @@ void _start_cmd_for_render_pass(VkvgContext ctx) {
CmdBeginRenderPass(ctx->cmd, &ctx->renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
VkViewport viewport = {0, 0, (float)ctx->pSurf->width, (float)ctx->pSurf->height, 0, 1.f};
CmdSetViewport(ctx->cmd, 0, 1, &viewport);
-
CmdSetScissor(ctx->cmd, 0, 1, &ctx->bounds);
- VkDescriptorSet dss[] = {ctx->dsFont, ctx->dsSrc, ctx->dsGrad};
- CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->dev->pipelineLayout, 0, 3, dss, 0, NULL);
+ /*VkDescriptorSet dss[] = {ctx->dev->fontCache->dsFont, NULL, NULL};
+ CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->dev->pipelineLayout, 0, 3, dss, 0, NULL);*/
+ CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->dev->pipelineLayout,
+ 0, 1, &ctx->dev->fontCache->dsFont, 0, NULL);
VkDeviceSize offsets[1] = {0};
CmdBindVertexBuffers(ctx->cmd, 0, 1, &ctx->vertices.buffer, offsets);
@@ -696,14 +697,14 @@ void _update_cur_pattern(VkvgContext ctx, VkvgPattern pat) {
ctx->pattern = pat;
switch (newPatternType) {
- case VKVG_PATTERN_TYPE_SOLID:
- _flush_cmd_buff(ctx);
+ //case VKVG_PATTERN_TYPE_SOLID:
+ //_flush_cmd_buff(ctx);
//if (!_wait_ctx_flush_end(ctx))
// return;
//if (lastPat->type == VKVG_PATTERN_TYPE_SURFACE) // unbind current source surface by replacing it with empty texture
//_update_descriptor_set(ctx, ctx->dev->emptyImg, ctx->dsSrc);
- break;
- case VKVG_PATTERN_TYPE_SURFACE: {
+// break;
+/* case VKVG_PATTERN_TYPE_SURFACE: {
_emit_draw_cmd_undrawn_vertices(ctx);
VkvgSurface surf = (VkvgSurface)pat->data;
@@ -755,7 +756,7 @@ void _update_cur_pattern(VkvgContext ctx, VkvgPattern pat) {
}
vkh_image_create_sampler(surf->img, filter, filter, VK_SAMPLER_MIPMAP_MODE_NEAREST, addrMode);
- _update_descriptor_set(ctx, surf->img, ctx->dsSrc);
+ //_update_descriptor_set(ctx, surf->img, ctx->dsSrc);
ctx->pushConsts.source.width = (float)surf->width;
ctx->pushConsts.source.height = (float)surf->height;
@@ -771,7 +772,7 @@ void _update_cur_pattern(VkvgContext ctx, VkvgPattern pat) {
}
break;
- }
+ }*/
case VKVG_PATTERN_TYPE_LINEAR:
case VKVG_PATTERN_TYPE_RADIAL:
_flush_cmd_buff(ctx);
@@ -831,7 +832,7 @@ void _update_cur_pattern(VkvgContext ctx, VkvgPattern pat) {
if (lastPat)
vkvg_pattern_destroy(lastPat);
}
-void _update_descriptor_set(VkvgContext ctx, VkhImage img, VkDescriptorSet ds) {
+/*void _update_descriptor_set(VkvgContext ctx, VkhImage img, VkDescriptorSet ds) {
VkDescriptorImageInfo descSrcTex = vkh_image_get_descriptor(img, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
VkWriteDescriptorSet writeDescriptorSet = {.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = ds,
@@ -840,9 +841,9 @@ void _update_descriptor_set(VkvgContext ctx, VkhImage img, VkDescriptorSet ds) {
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
.pImageInfo = &descSrcTex};
vkUpdateDescriptorSets(ctx->dev->vkDev, 1, &writeDescriptorSet, 0, NULL);
-}
+}*/
-void _update_gradient_desc_set(VkvgContext ctx) {
+/*void _update_gradient_desc_set(VkvgContext ctx) {
VkDescriptorBufferInfo dbi = {ctx->uboGrad.buffer, 0, VK_WHOLE_SIZE};
VkWriteDescriptorSet writeDescriptorSet = {.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = ctx->dsGrad,
@@ -851,7 +852,7 @@ void _update_gradient_desc_set(VkvgContext ctx) {
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.pBufferInfo = &dbi};
vkUpdateDescriptorSets(ctx->dev->vkDev, 1, &writeDescriptorSet, 0, NULL);
-}
+}*/
/*
* Reset currently bound descriptor which image could be destroyed
*/
@@ -867,7 +868,7 @@ void _update_gradient_desc_set(VkvgContext ctx) {
VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &ctx->dsSrc));
}*/
-void _createDescriptorPool(VkvgContext ctx) {
+/*void _createDescriptorPool(VkvgContext ctx) {
VkvgDevice dev = ctx->dev;
const VkDescriptorPoolSize descriptorPoolSize[] = {{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2},
{VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1}};
@@ -877,19 +878,17 @@ void _createDescriptorPool(VkvgContext ctx) {
.poolSizeCount = 2,
.pPoolSizes = descriptorPoolSize};
VK_CHECK_RESULT(vkCreateDescriptorPool(dev->vkDev, &descriptorPoolCreateInfo, NULL, &ctx->descriptorPool));
-}
-void _init_descriptor_sets(VkvgContext ctx) {
+}*/
+/*void _init_descriptor_sets(VkvgContext ctx) {
VkvgDevice dev = ctx->dev;
VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.descriptorPool = ctx->descriptorPool,
.descriptorSetCount = 1,
- .pSetLayouts = &dev->dslFont};
- VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &ctx->dsFont));
- descriptorSetAllocateInfo.pSetLayouts = &dev->dslSrc;
+ .pSetLayouts = &dev->dslSrc};
VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &ctx->dsSrc));
descriptorSetAllocateInfo.pSetLayouts = &dev->dslGrad;
VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &ctx->dsGrad));
-}
+}*/
void _release_context_ressources(VkvgContext ctx) {
VkDevice dev = ctx->dev->vkDev;
@@ -900,16 +899,14 @@ void _release_context_ressources(VkvgContext ctx) {
vkFreeCommandBuffers(dev, ctx->cmdPool, 2, ctx->cmdBuffers);
vkDestroyCommandPool(dev, ctx->cmdPool, NULL);
- VkDescriptorSet dss[] = {ctx->dsFont, ctx->dsSrc, ctx->dsGrad};
- vkFreeDescriptorSets(dev, ctx->descriptorPool, 3, dss);
-
- vkDestroyDescriptorPool(dev, ctx->descriptorPool, NULL);
+// VkDescriptorSet dss[] = {ctx->dsFont, ctx->dsSrc, ctx->dsGrad};
+// vkFreeDescriptorSets(dev, ctx->descriptorPool, 3, dss);
vkh_buffer_reset(&ctx->uboGrad);
vkh_buffer_reset(&ctx->indices);
vkh_buffer_reset(&ctx->vertices);
- vkh_image_destroy(ctx->fontCacheImg);
+ //vkh_image_destroy(ctx->fontCacheImg);
// TODO:check this for source counter
// vkh_image_destroy (ctx->source);
diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h
index 0b368f9..920590a 100644
--- a/src/vkvg_context_internal.h
+++ b/src/vkvg_context_internal.h
@@ -168,11 +168,12 @@ typedef struct _vkvg_context_t {
VkCommandPool cmdPool; // local pools ensure thread safety
VkCommandBuffer cmdBuffers[2]; // double cmd buff for context operations
VkCommandBuffer cmd; // current recording buffer
- VkDescriptorPool descriptorPool; // one pool per thread
- VkDescriptorSet dsFont; // fonts glyphs texture atlas descriptor (local for thread safety)
- VkDescriptorSet dsSrc; // source ds
- VkDescriptorSet dsGrad; // gradient uniform buffer
- VkhImage fontCacheImg; // current font cache, may not be the last one, updated only if new glyphs are uploaded by the current context
+
+ //VkDescriptorPool descriptorPool; // one pool per thread
+
+ //VkDescriptorSet dsGrad; // gradient uniform buffer
+
+ //VkhImage fontCacheImg; // current font cache, may not be the last one, updated only if new glyphs are uploaded by the current context
// vk buffers, holds data until flush
vkh_buffer_t uboGrad; // uniform buff obj holdings gradient infos
vkh_buffer_t indices; // index buffer with persistent map memory
diff --git a/src/vkvg_device.c b/src/vkvg_device.c
index c0cf94b..29445a9 100644
--- a/src/vkvg_device.c
+++ b/src/vkvg_device.c
@@ -22,6 +22,7 @@
#include "vkvg_device_internal.h"
#include "vkvg_context_internal.h"
+#include "vkvg_surface_internal.h"
#include "vkh_queue.h"
#include "vkh_phyinfo.h"
#include "vk_mem_alloc.h"
@@ -106,8 +107,8 @@ void _device_init(VkvgDevice dev, const vkvg_device_create_info_t* info) {
dev->fence = vkh_fence_create_signaled(vkhd);
//_device_create_pipeline_cache(dev);
- _fonts_cache_create(dev, info->fontsDirectories);
_device_createDescriptorSetLayout(dev);
+ _fonts_cache_create(dev, info->fontsDirectories);
if (dev->threadAware) {
mtx_init(&dev->mutex, mtx_plain);
@@ -388,10 +389,12 @@ void vkvg_device_destroy(VkvgDevice dev) {
vkDeviceWaitIdle(dev->vkDev);
for (int i = 0; i < dev->surfaceClasses.count; ++i) {
- //_surface_class_destroy (dev->surfaceClasses.elements[i]);
+ _destroy_surface_class (dev->surfaceClasses.elements[i]);
}
array_destroy_SurfaceClass(&dev->surfaceClasses);
+ vkDestroyDescriptorPool(dev->vkDev, dev->descriptorPool, NULL);
+
vkDestroyDescriptorSetLayout(dev->vkDev, dev->dslGrad, NULL);
vkDestroyDescriptorSetLayout(dev->vkDev, dev->dslFont, NULL);
vkDestroyDescriptorSetLayout(dev->vkDev, dev->dslSrc, NULL);
diff --git a/src/vkvg_device_internal.c b/src/vkvg_device_internal.c
index 918526c..00c53a4 100644
--- a/src/vkvg_device_internal.c
+++ b/src/vkvg_device_internal.c
@@ -108,7 +108,26 @@ void _device_createDescriptorSetLayout(VkvgDevice dev) {
.pSetLayouts = dsls};
VK_CHECK_RESULT(vkCreatePipelineLayout(dev->vkDev, &pipelineLayoutCreateInfo, NULL, &dev->pipelineLayout));
}
+void _device_allocalte_dummy_descriptors (VkvgDevice dev) {
+ const VkDescriptorPoolSize descriptorPoolSize[] = {
+ {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1},
+ {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1}
+ };
+ VkDescriptorPoolCreateInfo descriptorPoolCreateInfo = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
+ .maxSets = 2,
+ .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
+ .poolSizeCount = 2,
+ .pPoolSizes = descriptorPoolSize};
+ VK_CHECK_RESULT(vkCreateDescriptorPool(dev->vkDev, &descriptorPoolCreateInfo, NULL, &dev->descriptorPool));
+ VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
+ .descriptorPool = dev->descriptorPool,
+ .descriptorSetCount = 1,
+ .pSetLayouts = &dev->dslSrc};
+ VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &dev->dummySrcSet));
+ descriptorSetAllocateInfo.pSetLayouts = &dev->dslGrad;
+ VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &dev->dummyGradSet));
+}
void _device_wait_idle(VkvgDevice dev) { vkDeviceWaitIdle(dev->vkDev); }
void _device_wait_and_reset_device_fence(VkvgDevice dev) {
vkWaitForFences(dev->vkDev, 1, &dev->fence, VK_TRUE, UINT64_MAX);
diff --git a/src/vkvg_device_internal.h b/src/vkvg_device_internal.h
index eb47780..e8dabb1 100644
--- a/src/vkvg_device_internal.h
+++ b/src/vkvg_device_internal.h
@@ -96,11 +96,15 @@ typedef struct _vkvg_device_t {
VkDescriptorSetLayout dslSrc; /**< context source surface descriptors layout */
VkDescriptorSetLayout dslGrad; /**< context gradient descriptors layout */
+ VkDescriptorPool descriptorPool;
+ VkDescriptorSet dummySrcSet;
+ VkDescriptorSet dummyGradSet;
+
VkhDevice vkhDev; /**< old VkhDev created during vulkan context creation by @ref vkvg_device_create. */
bool deferredResolve; /**< if true, resolve only on context destruction and set as source */
- _font_cache_t* fontCache; /**< Store everything relative to common font caching system */
+ font_cache_t* fontCache; /**< Store everything relative to common font caching system */
VkvgContext lastCtx; /**< last element of double linked list of context, used to trigger font caching system update
on all contexts*/
diff --git a/src/vkvg_fonts.c b/src/vkvg_fonts.c
index 017dbe6..c39485e 100644
--- a/src/vkvg_fonts.c
+++ b/src/vkvg_fonts.c
@@ -85,7 +85,7 @@ static inline uint32_t get_face_glyph_count (FontFace face) {
}
void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) {
- _font_cache_t* cache = (_font_cache_t*)calloc(1, sizeof(_font_cache_t));
+ font_cache_t* cache = (font_cache_t*)calloc(1, sizeof(font_cache_t));
if (dev->threadAware)
mtx_init(&cache->mutex, mtx_plain);
@@ -162,6 +162,29 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) {
cache->uploadFence = vkh_fence_create(vkhd);
+ const VkDescriptorPoolSize descriptorPoolSize = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1};
+ VkDescriptorPoolCreateInfo descriptorPoolCreateInfo = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
+ .maxSets = 2,
+ .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
+ .poolSizeCount = 1,
+ .pPoolSizes = &descriptorPoolSize};
+ VK_CHECK_RESULT(vkCreateDescriptorPool(dev->vkDev, &descriptorPoolCreateInfo, NULL, &cache->descriptorPool));
+
+ VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
+ .descriptorPool = cache->descriptorPool,
+ .descriptorSetCount = 1,
+ .pSetLayouts = &dev->dslFont};
+ VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &cache->dsFont));
+
+ VkDescriptorImageInfo descSrcTex = vkh_image_get_descriptor(cache->texture, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
+ VkWriteDescriptorSet writeDescriptorSet = {.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
+ .dstSet = cache->dsFont,
+ .dstBinding = 0,
+ .descriptorCount = 1,
+ .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+ .pImageInfo = &descSrcTex};
+ vkUpdateDescriptorSets(dev->vkDev, 1, &writeDescriptorSet, 0, NULL);
+
const uint32_t buffLength = FONT_PAGE_SIZE * FONT_PAGE_SIZE * cache->texPixelSize;
vkh_buffer_init(vkhd, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VKH_MEMORY_USAGE_CPU_TO_GPU, buffLength, &cache->buff,
@@ -182,9 +205,15 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) {
cache->fontBuffers = array_create_FontBuffer(4);
+#if defined(DEBUG) && defined(VKVG_DBG_UTILS)
+ vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t)cache->descriptorPool,
+ "Font cache Descriptor Pool");
+ vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)cache->dsFont, "Cache DescSet FONT");
+#endif
+
dev->fontCache = cache;
}
-void _font_buffer_destroy (_font_cache_t* cache, FontBuffer fontBuffer) {
+void _font_buffer_destroy (font_cache_t* cache, FontBuffer fontBuffer) {
LOG(VKVG_LOG_FONT, "FontBuffer destroy\n");
free(fontBuffer->buffer);
array_destroy_FontFace(&fontBuffer->faces);
@@ -213,7 +242,7 @@ void _font_face_destroy (VkvgFont font) {
free(face);
}
void _font_cache_destroy(VkvgDevice dev) {
- _font_cache_t* cache = (_font_cache_t*)dev->fontCache;
+ font_cache_t* cache = (font_cache_t*)dev->fontCache;
free(cache->hostBuff);
@@ -229,6 +258,8 @@ void _font_cache_destroy(VkvgDevice dev) {
}
array_destroy_FontBuffer(&cache->fontBuffers);
+ vkDestroyDescriptorPool(dev->vkDev, cache->descriptorPool, NULL);
+
LOG(VKVG_LOG_FONT, "Font pages in cache: %d\n", cache->texPages.count);
for (int i = 0; i < cache->texPages.count; ++i) {
tex_page_t *p = &cache->texPages.elements[i];
@@ -267,7 +298,7 @@ void _font_cache_destroy(VkvgDevice dev) {
void _increase_font_tex_array(VkvgDevice dev) {
LOG(VKVG_LOG_FONT, "_increase_font_tex_array\n");
- _font_cache_t* cache = dev->fontCache;
+ font_cache_t* cache = dev->fontCache;
vkWaitForFences(dev->vkDev, 1, &cache->uploadFence, VK_TRUE, UINT64_MAX);
ResetFences(dev->vkDev, 1, &cache->uploadFence);
@@ -276,11 +307,12 @@ void _increase_font_tex_array(VkvgDevice dev) {
uint8_t oldSize = cache->texPages.count;
for (int i = 0; i < FONT_CACHE_INIT_LAYERS; ++i) {
- array_add_tex_page_t(&cache->texPages, (tex_page_t){array_create_TexRef(10), 0.f});
+ tex_page_t tp = (tex_page_t){array_create_TexRef(10), 0.f};
+ if (array_add_tex_page_t(&cache->texPages, tp) < 0)
+ array_destroy_TexRef(&tp.lines);
}
uint8_t newSize = cache->texPages.count;
-
VkhImage newImg = vkh_tex2d_array_create(
(VkhDevice)&dev->vkDev, cache->texFormat, FONT_PAGE_SIZE, FONT_PAGE_SIZE, newSize, VKH_MEMORY_USAGE_GPU_ONLY,
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
@@ -328,7 +360,7 @@ void _increase_font_tex_array(VkvgDevice dev) {
// flush font stagging buffer to cache texture array
// Trigger stagging buffer to be uploaded in font cache. Groupping upload improve performances.
void _flush_chars_to_tex(VkvgFont f) {
- _font_cache_t* cache = f->dev->fontCache;
+ font_cache_t* cache = f->dev->fontCache;
if (cache->stagingX == 0) // no char in stagging buff to flush
return;
tex_ref_t l = *f->texLines.elements[f->texLines.count - 1];
@@ -373,7 +405,7 @@ void _flush_chars_to_tex(VkvgFont f) {
/// Start a new line in font cache, increase texture layer count if needed.
void _init_next_line_in_tex_cache(VkvgFont f) {
- _font_cache_t* cache = f->dev->fontCache;
+ font_cache_t* cache = f->dev->fontCache;
for (int i = 0; i < cache->texPages.count; ++i) {
tex_page_t* page = &cache->texPages.elements[i];
@@ -408,7 +440,7 @@ void _init_next_line_in_tex_cache(VkvgFont f) {
_increase_font_tex_array(f->dev);
_init_next_line_in_tex_cache(f);
}
-void _font_cache_update_context_descset(VkvgContext ctx) {
+/*void _font_cache_update_context_descset(VkvgContext ctx) {
if (ctx->fontCacheImg)
vkh_image_destroy(ctx->fontCacheImg);
@@ -420,7 +452,7 @@ void _font_cache_update_context_descset(VkvgContext ctx) {
_update_descriptor_set(ctx, ctx->fontCacheImg, ctx->dsFont);
UNLOCK_FONTCACHE(ctx->dev)
-}
+}*/
// create a new char entry and put glyph in stagging buffer, ready for upload.
glyph_ref _put_glyph_in_cache(VkvgDevice dev, VkvgFont font, uint32_t gindex) {
#ifdef VKVG_USE_FREETYPE
@@ -520,7 +552,7 @@ vkvg_inline glyph_ref get_cached_glyph (VkvgDevice dev, VkvgFont font, uint32_t
return font->charLookup[gIndex];
}
-bool try_get_font_face_from_query_hash(_font_cache_t* cache, uint64_t queryHash, FontFace *const face) {
+bool try_get_font_face_from_query_hash(font_cache_t* cache, uint64_t queryHash, FontFace *const face) {
*face = NULL;
FontBuffer* buffs = cache->fontBuffers.elements;
for (int i = 0; i < cache->fontBuffers.count; ++i) {
@@ -537,7 +569,7 @@ bool try_get_font_face_from_query_hash(_font_cache_t* cache, uint64_t queryHash,
}
return false;
}
-bool try_get_font_buffer_from_path_hash(_font_cache_t* cache, uint64_t pathHash, FontBuffer *const fontBuff) {
+bool try_get_font_buffer_from_path_hash(font_cache_t* cache, uint64_t pathHash, FontBuffer *const fontBuff) {
*fontBuff = NULL;
for (int i = 0; i < cache->fontBuffers.count; ++i) {
if (cache->fontBuffers.elements[i]->fontPathHash == pathHash) {
@@ -549,7 +581,7 @@ bool try_get_font_buffer_from_path_hash(_font_cache_t* cache, uint64_t pathHash,
return false;
}
bool try_create_font_face_from_path (VkvgDevice dev, const char *fontFile, int faceIndex, FontFace *const face) {
- _font_cache_t* cache = dev->fontCache;
+ font_cache_t* cache = dev->fontCache;
uint64_t fontFileHash = fnv1a_64_str(fontFile);
FontBuffer buffPtr = NULL;
@@ -626,7 +658,7 @@ bool try_create_font_face_from_path (VkvgDevice dev, const char *fontFile, int f
bool try_get_or_create_font_face_from_query (VkvgDevice dev, const char* queryString, FontFace *const face,
signed long** pCoords) {
- _font_cache_t* cache = dev->fontCache;
+ font_cache_t* cache = dev->fontCache;
uint64_t queryHash = fnv1a_64_str(queryString);
*face = NULL;
@@ -965,10 +997,10 @@ void text_run_render(VkvgText tr, VkvgContext ctx) {
_flush_chars_to_tex(tr->font);
UNLOCK_FONTCACHE(ctx->dev)
- if (ctx->fontCacheImg != ctx->dev->fontCache->texture) {
+ /*if (ctx->fontCacheImg != ctx->dev->fontCache->texture) {
vkvg_flush(ctx);
_font_cache_update_context_descset(ctx);
- }
+ }*/
}
#ifdef DEBUG
diff --git a/src/vkvg_fonts.h b/src/vkvg_fonts.h
index 66f8612..a26c792 100644
--- a/src/vkvg_fonts.h
+++ b/src/vkvg_fonts.h
@@ -255,7 +255,7 @@ typedef struct _vkvg_font_t {
// Font cache global structure, entry point for all font related operations.
-typedef struct {
+typedef struct _font_cache_t {
#ifdef VKVG_USE_FREETYPE
FT_Library library; /* FreeType library*/
#else
@@ -272,6 +272,10 @@ typedef struct {
VkCommandBuffer cmd; /* vulkan command buffer for font textures upload */
vkh_buffer_t buff; /* stagin buffer */
VkhImage texture; /* 2d array texture used by contexts to draw characteres */
+
+ VkDescriptorPool descriptorPool;
+ VkDescriptorSet dsFont; /* fonts glyphs texture atlas descriptor set */
+
VkFormat texFormat; /* Format of the fonts texture array */
uint8_t texPixelSize; /* Size in byte of a single pixel in a font texture */
VkFence uploadFence; /* Signaled when upload is finished */
@@ -279,7 +283,7 @@ typedef struct {
vkvg_device_set_thread_aware) */
array_FontBuffer fontBuffers;
array_tex_page_t texPages;
-} _font_cache_t;
+} font_cache_t;
#define LOCK_FONTCACHE(dev) \
if (dev->threadAware) \
diff --git a/src/vkvg_surface.c b/src/vkvg_surface.c
index bb8ab1c..1d5a04f 100644
--- a/src/vkvg_surface.c
+++ b/src/vkvg_surface.c
@@ -48,7 +48,8 @@ VkvgSurface vkvg_surface_create(VkvgDevice dev, uint32_t width, uint32_t height)
surf->height = MAX(1, height);
surf->newSurf = true; // used to clear all attacments on first render pass
- _create_surface_images(surf);
+ _create_surface_images (surf);
+ _update_descriptor (surf);
_transition_surf_images(surf);
surf->status = VKVG_STATUS_SUCCESS;
@@ -171,7 +172,7 @@ VkvgSurface vkvg_surface_create_from_bitmap(VkvgDevice dev, unsigned char* img,
ctx->pushConsts.fsq_patternType = (ctx->pushConsts.fsq_patternType & FULLSCREEN_BIT) + VKVG_PATTERN_TYPE_SURFACE;
//_update_push_constants (ctx);
- _update_descriptor_set(ctx, tmpImg, ctx->dsSrc);
+ //_update_descriptor_set(ctx, tmpImg, ctx->dsSrc);
_ensure_renderpass_is_started(ctx);
vkvg_paint(ctx);
@@ -218,8 +219,10 @@ void vkvg_surface_destroy(VkvgSurface surf) {
- vkDestroyCommandPool(surf->dev->vkDev, surf->cmdPool, NULL);
- vkDestroyFramebuffer(surf->dev->vkDev, surf->fb, NULL);
+ vkDestroyCommandPool(dev->vkDev, surf->cmdPool, NULL);
+ vkDestroyFramebuffer(dev->vkDev, surf->fb, NULL);
+
+ vkDestroyDescriptorPool(dev->vkDev, surf->descriptorPool, NULL);
if (!surf->img->imported)
vkh_image_destroy(surf->img);
@@ -404,7 +407,6 @@ vkvg_status_t vkvg_surface_write_to_png(VkvgSurface surf, const char* path) {
UNLOCK_SURFACE(surf)
return VKVG_STATUS_SUCCESS;
}
-
vkvg_status_t vkvg_surface_write_to_memory(VkvgSurface surf, unsigned char* const bitmap) {
if (vkvg_surface_status(surf)) {
LOGE("vkvg_surface_write_to_memory failed, invalid status: %d\n", vkvg_surface_status(surf));
diff --git a/src/vkvg_surface_internal.c b/src/vkvg_surface_internal.c
index 5b56db9..85b8736 100644
--- a/src/vkvg_surface_internal.c
+++ b/src/vkvg_surface_internal.c
@@ -24,7 +24,6 @@
#include "vkvg_surface_internal.h"
#include "vkvg_context_internal.h"
-#include "vkh_image.h"
#include "vkh_queue.h"
#include "shaders.h"
@@ -128,6 +127,7 @@ void _clear_surface(VkvgSurface surf, VkImageAspectFlags aspect) {
UNLOCK_SURFACE(surf)
}
+
VkRenderPass _createRenderPassNoResolve(surface_class* surf, VkAttachmentLoadOp loadOp,
VkAttachmentLoadOp stencilLoadOp) {
VkAttachmentDescription attColor = {.format = FB_COLOR_FORMAT,
@@ -324,7 +324,7 @@ void _setupPipelines(surface_class* surf) {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, .viewportCount = 1, .scissorCount = 1};
VkPipelineMultisampleStateCreateInfo multisampleState = {
- .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT};
+ .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, .rasterizationSamples = surf->samples};
/*if (dev->samples != VK_SAMPLE_COUNT_1_BIT){
multisampleState.sampleShadingEnable = VK_TRUE;
multisampleState.minSampleShading = 0.5f;
@@ -589,17 +589,6 @@ surface_class* _create_surface_class (VkvgDevice dev, VkFormat format, VkSampleC
atomic_init(&surf->references, 1);
return surf;
}
-
-surface_class* _get_surface_class (VkvgDevice dev, VkFormat format, VkSampleCountFlags samples) {
- for (int i = 0; i < dev->surfaceClasses.count; ++i) {
- surface_class* sc = dev->surfaceClasses.elements[i];
- if (sc->format == format && sc->samples == samples) {
- atomic_fetch_add_explicit(&sc->references, 1, memory_order_relaxed);
- return sc;
- }
- }
- return _create_surface_class (dev, format, samples);
-}
void _destroy_surface_class (surface_class* surf) {
if (atomic_fetch_sub_explicit(&surf->references, 1, memory_order_acq_rel) != 1)
return;
@@ -629,6 +618,30 @@ void _destroy_surface_class (surface_class* surf) {
free(surf);
}
+surface_class* _get_surface_class (VkvgDevice dev, VkFormat format, VkSampleCountFlags samples) {
+ for (int i = 0; i < dev->surfaceClasses.count; ++i) {
+ surface_class* sc = dev->surfaceClasses.elements[i];
+ if (sc->format == format && sc->samples == samples) {
+ atomic_fetch_add_explicit(&sc->references, 1, memory_order_relaxed);
+ return sc;
+ }
+ }
+ return _create_surface_class (dev, format, samples);
+}
+
+void _update_descriptor (VkvgSurface surf) {
+ vkh_image_create_sampler(surf->img, VK_FILTER_NEAREST, VK_FILTER_NEAREST,
+ VK_SAMPLER_MIPMAP_MODE_NEAREST, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER);
+
+ VkDescriptorImageInfo descSrcTex = vkh_image_get_descriptor(surf->img, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
+ VkWriteDescriptorSet writeDescriptorSet = {.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
+ .dstSet = surf->dsSrc,
+ .dstBinding = 0,
+ .descriptorCount = 1,
+ .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
+ .pImageInfo = &descSrcTex};
+ vkUpdateDescriptorSets(surf->dev->vkDev, 1, &writeDescriptorSet, 0, NULL);
+}
VkvgSurface _create_surface(VkvgDevice dev, VkFormat format, VkSampleCountFlags samples) {
LOG(VKVG_LOG_INFO, "CREATE Surface\n");
@@ -663,8 +676,25 @@ VkvgSurface _create_surface(VkvgDevice dev, VkFormat format, VkSampleCountFlags
surf->flushFence = vkh_fence_create(vkhd);
#endif
+ const VkDescriptorPoolSize descriptorPoolSize = {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1};
+ VkDescriptorPoolCreateInfo descriptorPoolCreateInfo = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
+ .maxSets = 2,
+ .flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
+ .poolSizeCount = 1,
+ .pPoolSizes = &descriptorPoolSize};
+ VK_CHECK_RESULT(vkCreateDescriptorPool(dev->vkDev, &descriptorPoolCreateInfo, NULL, &surf->descriptorPool));
+
+ VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
+ .descriptorPool = surf->descriptorPool,
+ .descriptorSetCount = 1,
+ .pSetLayouts = &dev->dslSrc};
+ VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &surf->dsSrc));
+
#if defined(DEBUG) && defined(VKVG_DBG_UTILS)
vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_COMMAND_BUFFER, (uint64_t)surf->cmd, "vkvgSurfCmd");
+ vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_POOL, (uint64_t)surf->descriptorPool,
+ "Surf Descriptor Pool");
+ vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)surf->dsSrc, "Surf DescSet");
#endif
atomic_init(&surf->references, 1);
diff --git a/src/vkvg_surface_internal.h b/src/vkvg_surface_internal.h
index 1af9034..c3c97bf 100644
--- a/src/vkvg_surface_internal.h
+++ b/src/vkvg_surface_internal.h
@@ -64,6 +64,9 @@ typedef struct _vkvg_surface_t {
int hdpi, /**< only used for FreeType fonts and svg loading */
vdpi;
surface_class * surfClass;
+
+ VkDescriptorPool descriptorPool;
+ VkDescriptorSet dsSrc; // source ds
} vkvg_surface;
#define LOCK_SURFACE(surf) \
@@ -84,6 +87,7 @@ void _create_framebuffer(VkvgSurface surf);
void _create_surface_images(VkvgSurface surf);
VkvgSurface _create_surface(VkvgDevice dev, VkFormat format, VkSampleCountFlags samples);
void _surface_submit_cmd(VkvgSurface surf);
+void _update_descriptor (VkvgSurface surf);
void _destroy_surface_class (surface_class* surf);
// bool _surface_wait_cmd (VkvgSurface surf);