summaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>2026-10-18 15:14:45 +0200
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>2026-10-18 15:28:04 +0200
commit64c0615b03f9dd93e8202c40b74aa60a2318d3be (patch)
tree57df4f492c5cdf31bd64e0dc926ad70f39bf9f22
parent470714239728600e72c6453fc62b8854562679ef (diff)
dummy descriptors for source and gradient buff, immutable sampler for font texture
-rw-r--r--src/vkvg_context_internal.c17
-rw-r--r--src/vkvg_device.c7
-rw-r--r--src/vkvg_device_internal.c22
-rw-r--r--src/vkvg_device_internal.h3
-rw-r--r--src/vkvg_fonts.c11
-rw-r--r--src/vkvg_fonts.h2
-rw-r--r--src/vkvg_pattern.c28
7 files changed, 42 insertions, 48 deletions
diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c
index 7a986aa..5488a6c 100644
--- a/src/vkvg_context_internal.c
+++ b/src/vkvg_context_internal.c
@@ -654,10 +654,8 @@ void _start_cmd_for_render_pass(VkvgContext ctx) {
CmdSetViewport(ctx->cmd, 0, 1, &viewport);
CmdSetScissor(ctx->cmd, 0, 1, &ctx->bounds);
- /*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);
+ VkDescriptorSet dss[] = {ctx->dev->fontCache->dsFont, ctx->dev->dummySrcSet, ctx->dev->dummyGradSet};
+ CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, ctx->dev->pipelineLayout, 0, 3, dss, 0, NULL);
VkDeviceSize offsets[1] = {0};
CmdBindVertexBuffers(ctx->cmd, 0, 1, &ctx->vertices.buffer, offsets);
@@ -697,13 +695,16 @@ void _update_cur_pattern(VkvgContext ctx, VkvgPattern pat) {
ctx->pattern = pat;
switch (newPatternType) {
- //case VKVG_PATTERN_TYPE_SOLID:
+ 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;
+ VkDescriptorSet dss[] = {ctx->dev->dummySrcSet, ctx->dev->dummyGradSet};
+ CmdBindDescriptorSets(ctx->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
+ ctx->dev->pipelineLayout, 1, 2, dss, 0, NULL);
+
+ break;
+ }
/* case VKVG_PATTERN_TYPE_SURFACE: {
_emit_draw_cmd_undrawn_vertices(ctx);
diff --git a/src/vkvg_device.c b/src/vkvg_device.c
index 29445a9..fc5bb4f 100644
--- a/src/vkvg_device.c
+++ b/src/vkvg_device.c
@@ -107,8 +107,9 @@ void _device_init(VkvgDevice dev, const vkvg_device_create_info_t* info) {
dev->fence = vkh_fence_create_signaled(vkhd);
//_device_create_pipeline_cache(dev);
- _device_createDescriptorSetLayout(dev);
- _fonts_cache_create(dev, info->fontsDirectories);
+ _device_createDescriptorSetLayout (dev);
+ _fonts_cache_create (dev, info->fontsDirectories);
+ _device_allocalte_dummy_descriptors(dev);
if (dev->threadAware) {
mtx_init(&dev->mutex, mtx_plain);
@@ -402,6 +403,8 @@ void vkvg_device_destroy(VkvgDevice dev) {
vkDestroyPipelineLayout(dev->vkDev, dev->pipelineLayout, NULL);
vkDestroyPipelineCache(dev->vkDev, dev->pipelineCache, NULL);
+ vkDestroySampler(dev->vkDev, dev->smpFont, NULL);
+
vkWaitForFences(dev->vkDev, 1, &dev->fence, VK_TRUE, UINT64_MAX);
vkDestroyFence(dev->vkDev, dev->fence, NULL);
diff --git a/src/vkvg_device_internal.c b/src/vkvg_device_internal.c
index 00c53a4..2f8528c 100644
--- a/src/vkvg_device_internal.c
+++ b/src/vkvg_device_internal.c
@@ -39,8 +39,8 @@ PFN_vkCmdBindDescriptorSets CmdBindDescriptorSets;
PFN_vkCmdBindIndexBuffer CmdBindIndexBuffer;
PFN_vkCmdBindVertexBuffers CmdBindVertexBuffers;
-PFN_vkCmdDrawIndexed CmdDrawIndexed;
-PFN_vkCmdDraw CmdDraw;
+PFN_vkCmdDrawIndexed CmdDrawIndexed;
+PFN_vkCmdDraw CmdDraw;
PFN_vkCmdSetStencilCompareMask CmdSetStencilCompareMask;
PFN_vkCmdSetStencilReference CmdSetStencilReference;
@@ -50,7 +50,7 @@ PFN_vkCmdEndRenderPass CmdEndRenderPass;
PFN_vkCmdSetViewport CmdSetViewport;
PFN_vkCmdSetScissor CmdSetScissor;
-PFN_vkCmdPushConstants CmdPushConstants;
+PFN_vkCmdPushConstants CmdPushConstants;
PFN_vkWaitForFences WaitForFences;
PFN_vkResetFences ResetFences;
@@ -73,6 +73,16 @@ void _device_create_pipeline_cache(VkvgDevice dev) {
}
void _device_createDescriptorSetLayout(VkvgDevice dev) {
+ VkSamplerCreateInfo samplerInfo = {.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
+ .maxAnisotropy = 1.0,
+ .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
+ .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
+ .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
+ .magFilter = VK_FILTER_NEAREST,
+ .minFilter = VK_FILTER_NEAREST,
+ .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST};
+ vkCreateSampler(dev->vkDev, &samplerInfo, NULL, &dev->smpFont);
+
VkDescriptorBindingFlags bindingFlags[] = {
VK_DESCRIPTOR_BINDING_PARTIALLY_BOUND_BIT // Allows empty/unbound slots in this binding
};
@@ -83,13 +93,15 @@ void _device_createDescriptorSetLayout(VkvgDevice dev) {
};
VkDescriptorSetLayoutBinding dsLayoutBinding = {0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1,
- VK_SHADER_STAGE_FRAGMENT_BIT, NULL};
+ VK_SHADER_STAGE_FRAGMENT_BIT, &dev->smpFont};
VkDescriptorSetLayoutCreateInfo dsLayoutCreateInfo = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.pNext = &bindingFlagsInfo,
.bindingCount = 1,
- .pBindings = &dsLayoutBinding};
+ .pBindings = &dsLayoutBinding
+ };
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(dev->vkDev, &dsLayoutCreateInfo, NULL, &dev->dslFont));
+ dsLayoutBinding.pImmutableSamplers = NULL;
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(dev->vkDev, &dsLayoutCreateInfo, NULL, &dev->dslSrc));
dsLayoutBinding.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(dev->vkDev, &dsLayoutCreateInfo, NULL, &dev->dslGrad));
diff --git a/src/vkvg_device_internal.h b/src/vkvg_device_internal.h
index e8dabb1..43adc3b 100644
--- a/src/vkvg_device_internal.h
+++ b/src/vkvg_device_internal.h
@@ -95,11 +95,13 @@ typedef struct _vkvg_device_t {
VkDescriptorSetLayout dslFont; /**< font cache descriptors layout */
VkDescriptorSetLayout dslSrc; /**< context source surface descriptors layout */
VkDescriptorSetLayout dslGrad; /**< context gradient descriptors layout */
+ VkSampler smpFont; /**< font immutable sampler */
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 */
@@ -141,6 +143,7 @@ VkRenderPass _device_createRenderPassNoResolve(VkvgDevice dev, VkAttachmentLoadO
VkAttachmentLoadOp stencilLoadOp);
void _device_setupPipelines(VkvgDevice dev);
void _device_createDescriptorSetLayout(VkvgDevice dev);
+void _device_allocalte_dummy_descriptors(VkvgDevice dev);
void _device_wait_idle(VkvgDevice dev);
void _device_wait_and_reset_device_fence(VkvgDevice dev);
void _device_submit_cmd(VkvgDevice dev, VkCommandBuffer* cmd, VkFence fence);
diff --git a/src/vkvg_fonts.c b/src/vkvg_fonts.c
index c39485e..641a396 100644
--- a/src/vkvg_fonts.c
+++ b/src/vkvg_fonts.c
@@ -156,9 +156,8 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) {
cache->texture = vkh_tex2d_array_create(
vkhd, cache->texFormat, FONT_PAGE_SIZE, FONT_PAGE_SIZE, FONT_CACHE_INIT_LAYERS, VKH_MEMORY_USAGE_GPU_ONLY,
VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
- vkh_image_create_descriptor(cache->texture, VK_IMAGE_VIEW_TYPE_2D_ARRAY, VK_IMAGE_ASPECT_COLOR_BIT,
- VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST,
- VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER);
+
+ vkh_image_create_view (cache->texture, VK_IMAGE_VIEW_TYPE_2D_ARRAY, VK_IMAGE_ASPECT_COLOR_BIT);
cache->uploadFence = vkh_fence_create(vkhd);
@@ -176,7 +175,7 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) {
.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);
+ 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,
@@ -316,9 +315,7 @@ void _increase_font_tex_array(VkvgDevice dev) {
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);
- vkh_image_create_descriptor(newImg, VK_IMAGE_VIEW_TYPE_2D_ARRAY, VK_IMAGE_ASPECT_COLOR_BIT, VK_FILTER_NEAREST,
- VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST,
- VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER);
+ vkh_image_create_view(newImg, VK_IMAGE_VIEW_TYPE_2D_ARRAY, VK_IMAGE_ASPECT_COLOR_BIT);
VkImageSubresourceRange subresNew = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, newSize};
VkImageSubresourceRange subres = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, oldSize};
diff --git a/src/vkvg_fonts.h b/src/vkvg_fonts.h
index a26c792..9ef3da0 100644
--- a/src/vkvg_fonts.h
+++ b/src/vkvg_fonts.h
@@ -274,7 +274,7 @@ typedef struct _font_cache_t {
VkhImage texture; /* 2d array texture used by contexts to draw characteres */
VkDescriptorPool descriptorPool;
- VkDescriptorSet dsFont; /* fonts glyphs texture atlas descriptor set */
+ 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 */
diff --git a/src/vkvg_pattern.c b/src/vkvg_pattern.c
index 6977821..1781689 100644
--- a/src/vkvg_pattern.c
+++ b/src/vkvg_pattern.c
@@ -1,28 +1,6 @@
-/*
- * Copyright (c) 2018-2022 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
- * this software and associated documentation files (the "Software"), to deal in
- * the Software without restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
- * Software, and to permit persons to whom the Software is furnished to do so, subject
- * to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "vkvg_surface_internal.h"
-#include "vkvg_context_internal.h"
-#include "vkvg_device_internal.h"
+// Copyright (c) 2018-2026 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
#include "vkvg_pattern.h"
VkvgPattern vkvg_pattern_create_solid(float r, float g, float b, float a) {