void vkvg_surface_destroy (VkvgSurface surf);
VkImage vkvg_surface_get_vk_image (VkvgSurface surf);
+uint32_t vkvg_surface_get_width (VkvgSurface surf);
+uint32_t vkvg_surface_get_height (VkvgSurface surf);
VkImage vkvg_surface_get_vkh_image (VkvgSurface surf);
void vkvg_surface_write_to_png (VkvgSurface surf, const char* path);
#include "vkvg_buff.h"
#include "vkvg_device_internal.h"
-void _set_size_and_map(VkvgDevice pDev, VkBufferUsageFlags usage, VkMemoryPropertyFlags memoryPropertyFlags, VkDeviceSize size, vkvg_buff *buff){
- VkMemoryRequirements memReq;
- vkGetBufferMemoryRequirements(pDev->vkDev, buff->buffer, &memReq);
- VkMemoryAllocateInfo memAllocInfo = { .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
- .allocationSize = memReq.size };
- assert(memory_type_from_properties(&pDev->phyMemProps, memReq.memoryTypeBits,memoryPropertyFlags, &memAllocInfo.memoryTypeIndex));
- VK_CHECK_RESULT(vkAllocateMemory(pDev->vkDev, &memAllocInfo, NULL, &buff->memory));
-
- buff->alignment = memReq.alignment;
- buff->size = memAllocInfo.allocationSize;
- buff->usageFlags = usage;
- buff->memoryPropertyFlags = memoryPropertyFlags;
-
- VK_CHECK_RESULT(vkBindBufferMemory(buff->pDev->vkDev, buff->buffer, buff->memory, 0));
- VK_CHECK_RESULT(vkMapMemory(buff->pDev->vkDev, buff->memory, 0, VK_WHOLE_SIZE, 0, &buff->mapped));
-}
-
-void vkvg_buffer_create(VkvgDevice pDev, VkBufferUsageFlags usage, VkMemoryPropertyFlags memoryPropertyFlags, VkDeviceSize size, vkvg_buff *buff){
+void vkvg_buffer_create(VkvgDevice pDev, VkBufferUsageFlags usage, VmaMemoryUsage memoryPropertyFlags, VkDeviceSize size, vkvg_buff *buff){
buff->pDev = pDev;
VkBufferCreateInfo bufCreateInfo = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.usage = usage, .size = size, .sharingMode = VK_SHARING_MODE_EXCLUSIVE};
- VK_CHECK_RESULT(vkCreateBuffer(pDev->vkDev, &bufCreateInfo, NULL, &buff->buffer));
+ VmaAllocationCreateInfo allocInfo = { .usage = memoryPropertyFlags, .flags = VMA_ALLOCATION_CREATE_MAPPED_BIT };
- _set_size_and_map(pDev,usage,memoryPropertyFlags,size,buff);
+ VK_CHECK_RESULT(vmaCreateBuffer (pDev->allocator, &bufCreateInfo, &allocInfo, &buff->buffer, &buff->alloc, &buff->allocInfo));
}
void vkvg_buffer_destroy(vkvg_buff *buff){
- vkUnmapMemory (buff->pDev->vkDev, buff->memory);
- vkDestroyBuffer (buff->pDev->vkDev, buff->buffer, NULL);
- vkFreeMemory (buff->pDev->vkDev, buff->memory, NULL);
+ vmaDestroyBuffer (buff->pDev->allocator, buff->buffer, buff->alloc);
}
-
-void vkvg_buffer_increase_size(vkvg_buff *buff, uint32_t sizeAdded){
- size_t oldBSize = buff->size;
- void* pSave = (void*)malloc (oldBSize);
- memcpy (pSave, buff->mapped, oldBSize);
-
- vkvg_buffer_destroy(buff);
- vkvg_buffer_create(buff->pDev, buff->usageFlags, buff->memoryPropertyFlags, oldBSize + sizeAdded, buff);
- memcpy (buff->mapped, pSave, oldBSize);
- free(pSave);
-}
#include <vulkan/vulkan.h>
#include "vkvg.h"
+#include "vk_mem_alloc.h"
typedef struct vkvg_buff_t {
- VkvgDevice pDev;
- VkBuffer buffer;
- VkDeviceMemory memory;
+ VkvgDevice pDev;
+ VkBuffer buffer;
+ VmaAllocation alloc;
+ VmaAllocationInfo allocInfo;
VkDescriptorBufferInfo descriptor;
- VkDeviceSize size;
- VkDeviceSize alignment;
-
- VkBufferUsageFlags usageFlags;
- VkMemoryPropertyFlags memoryPropertyFlags;
-
- void* mapped;
}vkvg_buff;
void vkvg_buffer_create (VkvgDevice pDev, VkBufferUsageFlags usage,
- VkMemoryPropertyFlags memoryPropertyFlags, VkDeviceSize size, vkvg_buff* buff);
+ VmaMemoryUsage memoryPropertyFlags, VkDeviceSize size, vkvg_buff *buff);
void vkvg_buffer_destroy (vkvg_buff* buff);
-void vkvg_buffer_increase_size (vkvg_buff *buff, uint32_t sizeAdded);
#endif
void vkvg_flush (VkvgContext ctx){
_flush_cmd_buff(ctx);
_init_cmd_buff(ctx);
-
+/*
#ifdef DEBUG
vec4 red = {0,0,1,1};
vkCmdDrawIndexed(ctx->cmd, ctx->indCount-ctx->curIndStart, 1, ctx->curIndStart, 0, 1);
_flush_cmd_buff(ctx);
#endif
-
+*/
}
void vkvg_destroy (VkvgContext ctx)
iR = ctx->pathes[ptrPath];
_build_vb_step(ctx,v,hw,iL,i,iR);
- uint32_t* inds = (uint32_t*)(ctx->indices.mapped + ((ctx->indCount-6) * sizeof(uint32_t)));
+ uint32_t* inds = (uint32_t*)(ctx->indices.allocInfo.pMappedData + ((ctx->indCount-6) * sizeof(uint32_t)));
uint32_t ii = firstIdx;
inds[1] = ii;
inds[4] = ii;
}
void vkvg_set_source_surface(VkvgContext ctx, VkvgSurface surf, float x, float y){
_update_cur_pattern (ctx, vkvg_pattern_create_for_surface(surf));
+ ctx->pushConsts.source.x = x;
+ ctx->pushConsts.source.y = y;
+ _update_push_constants (ctx);
}
void vkvg_set_source (VkvgContext ctx, VkvgPattern pat){
_update_cur_pattern (ctx, pat);
void _create_gradient_buff (VkvgContext ctx){
vkvg_buffer_create (ctx->pSurf->dev,
VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
- VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
+ VMA_MEMORY_USAGE_CPU_TO_GPU,
sizeof(vkvg_gradient_t), &ctx->uboGrad);
}
void _create_vertices_buff (VkvgContext ctx){
vkvg_buffer_create (ctx->pSurf->dev,
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
- VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
+ VMA_MEMORY_USAGE_CPU_TO_GPU,
ctx->sizeVertices * sizeof(Vertex), &ctx->vertices);
vkvg_buffer_create (ctx->pSurf->dev,
VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
- VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
+ VMA_MEMORY_USAGE_CPU_TO_GPU,
ctx->sizeIndices * sizeof(uint32_t), &ctx->indices);
}
const vec3 blankuv = {};
void _add_vertexf (VkvgContext ctx, float x, float y){
- Vertex* pVert = (Vertex*)(ctx->vertices.mapped + ctx->vertCount * sizeof(Vertex));
+ Vertex* pVert = (Vertex*)(ctx->vertices.allocInfo.pMappedData + ctx->vertCount * sizeof(Vertex));
pVert->pos.x = x;
pVert->pos.y = y;
pVert->uv = blankuv;
ctx->vertCount++;
}
void _add_vertex(VkvgContext ctx, Vertex v){
- Vertex* pVert = (Vertex*)(ctx->vertices.mapped + ctx->vertCount * sizeof(Vertex));
+ Vertex* pVert = (Vertex*)(ctx->vertices.allocInfo.pMappedData + ctx->vertCount * sizeof(Vertex));
*pVert = v;
ctx->vertCount++;
}
void _set_vertex(VkvgContext ctx, uint32_t idx, Vertex v){
- Vertex* pVert = (Vertex*)(ctx->vertices.mapped + idx * sizeof(Vertex));
+ Vertex* pVert = (Vertex*)(ctx->vertices.allocInfo.pMappedData + idx * sizeof(Vertex));
*pVert = v;
}
void _add_tri_indices_for_rect (VkvgContext ctx, uint32_t i){
- uint32_t* inds = (uint32_t*)(ctx->indices.mapped + (ctx->indCount * sizeof(uint32_t)));
+ uint32_t* inds = (uint32_t*)(ctx->indices.allocInfo.pMappedData + (ctx->indCount * sizeof(uint32_t)));
inds[0] = i;
inds[1] = i+2;
inds[2] = i+1;
ctx->indCount+=6;
}
void _add_triangle_indices(VkvgContext ctx, uint32_t i0, uint32_t i1, uint32_t i2){
- uint32_t* inds = (uint32_t*)(ctx->indices.mapped + (ctx->indCount * sizeof(uint32_t)));
+ uint32_t* inds = (uint32_t*)(ctx->indices.allocInfo.pMappedData + (ctx->indCount * sizeof(uint32_t)));
inds[0] = i0;
inds[1] = i1;
inds[2] = i2;
{{x+width,y+height},{0,0,-1}}
};
uint32_t firstIdx = ctx->vertCount;
- Vertex* pVert = (Vertex*)(ctx->vertices.mapped + ctx->vertCount * sizeof(Vertex));
+ Vertex* pVert = (Vertex*)(ctx->vertices.allocInfo.pMappedData + ctx->vertCount * sizeof(Vertex));
memcpy (pVert,v,4*sizeof(Vertex));
ctx->vertCount+=4;
_add_tri_indices_for_rect(ctx, firstIdx);
vkvg_matrix_transform_point(&ctx->pushConsts.mat, &grad.cp[1].x, &grad.cp[1].y);
//to do, scale radial radiuses in cp[2]
- memcpy(ctx->uboGrad.mapped, &grad, sizeof(vkvg_gradient_t));
+ memcpy(ctx->uboGrad.allocInfo.pMappedData , &grad, sizeof(vkvg_gradient_t));
_init_cmd_buff (ctx);
break;
_add_vertex(ctx, v);
v.pos = p2;
_add_vertex(ctx, v);
- uint32_t* inds = (uint32_t*)(ctx->indices.mapped + (ctx->indCount * sizeof(uint32_t)));
+ uint32_t* inds = (uint32_t*)(ctx->indices.allocInfo.pMappedData + (ctx->indCount * sizeof(uint32_t)));
inds[0] = ctx->vertCount - 2;
inds[1] = ctx->vertCount - 1;
ctx->indCount+=2;
}Vertex;
typedef struct {
- vec4 source;
- vec2 size;
- uint32_t patternType;
- uint32_t pad;
- vkvg_matrix_t mat;
- vkvg_matrix_t matInv;
+ vec4 source;
+ vec2 size;
+ uint32_t patternType;
+ uint32_t pad;
+ vkvg_matrix_t mat;
+ vkvg_matrix_t matInv;
}push_constants;
typedef struct _vkvg_context_save_t{
#include "vkvg_device_internal.h"
#include "vkh_queue.h"
#include "vkh_phyinfo.h"
+#include "vk_mem_alloc.h"
VkvgDevice vkvg_device_create(VkPhysicalDevice phy, VkDevice vkdev, uint32_t qFamIdx, uint32_t qIndex)
{
VkvgDevice dev = (vkvg_device*)malloc(sizeof(vkvg_device));
- dev->hdpi = 96;
- dev->vdpi = 96;
+ dev->hdpi = 72;
+ dev->vdpi = 72;
dev->vkDev = vkdev;
dev->phy = phy;
vkh_phyinfo_destroy (phyInfos);
+ VmaAllocatorCreateInfo allocatorInfo = {
+ .physicalDevice = phy,
+ .device = vkdev
+ };
+ vmaCreateAllocator(&allocatorInfo, &dev->allocator);
+
dev->lastCtx= NULL;
dev->cmdPool= vkh_cmd_pool_create (dev, dev->gQueue->familyIndex, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT);
vkDestroyCommandPool (dev->vkDev, dev->cmdPool, NULL);
_destroy_font_cache(dev);
+
+ vmaDestroyAllocator (dev->allocator);
+
free(dev);
}
VkDevice vkDev;
VkPhysicalDeviceMemoryProperties phyMemProps;
VkPhysicalDevice phy;
+ VmaAllocator allocator;
VkhQueue gQueue;
VkRenderPass renderPass;
FT_BBox* bbox = &ctx->currentFont->face->bbox;
FT_Size_Metrics* metrics = &ctx->currentFont->face->size->metrics;
extents->ascent = metrics->ascender >> 6;
- extents->descent= metrics->descender >> 6;
+ extents->descent= -(metrics->descender >> 6);
extents->height = metrics->height >> 6;
extents->max_x_advance = bbox->xMax >> 6;
extents->max_y_advance = bbox->yMax >> 6;
void _init_surface (VkvgSurface surf) {
surf->format = FB_COLOR_FORMAT;//force bgra internally
- surf->img = vkh_image_create(surf->dev,surf->format,surf->width,surf->height,VK_IMAGE_TILING_LINEAR,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+ surf->img = vkh_image_create(surf->dev,surf->format,surf->width,surf->height,VK_IMAGE_TILING_LINEAR,VMA_MEMORY_USAGE_GPU_ONLY,
VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT);
- surf->imgMS = vkh_image_ms_create(surf->dev,surf->format,VKVG_SAMPLES,surf->width,surf->height,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+ surf->imgMS = vkh_image_ms_create(surf->dev,surf->format,VKVG_SAMPLES,surf->width,surf->height,VMA_MEMORY_USAGE_GPU_ONLY,
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
- surf->stencilMS = vkh_image_ms_create(surf->dev,VK_FORMAT_S8_UINT,VKVG_SAMPLES,surf->width,surf->height,VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+ surf->stencilMS = vkh_image_ms_create(surf->dev,VK_FORMAT_S8_UINT,VKVG_SAMPLES,surf->width,surf->height,VMA_MEMORY_USAGE_GPU_ONLY,
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT);
vkh_image_create_descriptor(surf->img, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST,VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE);
VkImageSubresourceLayers imgSubResLayers = {VK_IMAGE_ASPECT_COLOR_BIT,0,0,1};
//original format image
VkhImage stagImg= vkh_image_create (surf->dev,VK_FORMAT_R8G8B8A8_UNORM,surf->width,surf->height,VK_IMAGE_TILING_LINEAR,
- VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+ VMA_MEMORY_USAGE_GPU_ONLY,
VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT);
//bgra bliting target
VkhImage tmpImg = vkh_image_create (surf->dev,surf->format,surf->width,surf->height,VK_IMAGE_TILING_LINEAR,
- VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
+ VMA_MEMORY_USAGE_GPU_ONLY,
VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT);
vkh_image_create_descriptor (tmpImg, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT,
VK_FILTER_NEAREST, VK_FILTER_NEAREST, VK_SAMPLER_MIPMAP_MODE_NEAREST, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER);
{
return vkh_image_get_vkimage (surf->img);
}
+uint32_t vkvg_surface_get_width (VkvgSurface surf) {
+ return surf->width;
+}
+uint32_t vkvg_surface_get_height (VkvgSurface surf) {
+ return surf->height;
+}
void vkvg_surface_write_to_png (VkvgSurface surf, const char* path){
uint32_t stride = surf->width * 4;
//RGBA to blit to, surf img is bgra
VkhImage stagImg= vkh_image_create (surf->dev,VK_FORMAT_R8G8B8A8_UNORM,surf->width,surf->height,VK_IMAGE_TILING_LINEAR,
- VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
+ VMA_MEMORY_USAGE_GPU_TO_CPU,
VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT);
VkCommandBuffer cmd = dev->cmd;
// vkvg_fill(ctx);
VkvgPattern pat = vkvg_pattern_create_for_surface(surf2);
- vkvg_pattern_set_extend(pat, VKVG_EXTEND_NONE);
+ vkvg_pattern_set_extend(pat, VKVG_EXTEND_REFLECT);
vkvg_pattern_set_filter(pat, VKVG_FILTER_BILINEAR);
vkvg_set_source (ctx, pat);
//vkvg_rectangle(ctx,100,100,400,400);
vkvg_destroy(ctx);
}
+void test_1 () {
+ const char* text = "This is a petit test {}";
+ VkvgContext ctx = vkvg_create (surf);
+
+ vkvg_set_source_rgba(ctx,0,0,0,1.0);
+ vkvg_paint (ctx);
+ vkvg_set_source_rgba(ctx,1,1,1,1.0);
+
+ vkvg_select_font_face(ctx, "mono");
+ vkvg_set_font_size(ctx, 12);
+
+ vkvg_font_extents_t f = {};
+ vkvg_font_extents(ctx, &f);
+
+ vkvg_text_extents_t t = {};
+ vkvg_text_extents(ctx, text, &t);
+
+ vkvg_move_to(ctx,100,100);
+ vkvg_show_text(ctx, text);
+
+ vkvg_move_to(ctx,100,100.5 - f.ascent);
+ vkvg_line_to(ctx,100+t.width,100.5 - f.ascent);
+
+ vkvg_move_to(ctx,100,100.5 - f.descent);
+ vkvg_line_to(ctx,100+t.width,100.5 - f.descent);
+
+ vkvg_stroke(ctx);
+
+ vkvg_flush(ctx);
+ vkvg_destroy (ctx);
+}
void test_painting () {
VkvgSurface surf2 = vkvg_surface_create (device,400,400);;
VkvgContext ctx = vkvg_create (surf2);
surf = vkvg_surface_create(device, 1024, 800);
//test_svg();
-
+ //test_img_surface();
//
//test_grad_transforms();
while (!vkengine_should_close (e)) {
glfwPollEvents();
+ //test_1();
cairo_tests();
//multi_test1();
//test_painting();
* THE SOFTWARE.
*/
-#include "vkengine.h"
#include "vkh.h"
+#include "vkengine.h"
#include "vkh_app.h"
#include "vkh_phyinfo.h"
#include "vkh_presenter.h"
-Subproject commit 3c56e7f095f2eb60e5f3ada2e6805383ec430508
+Subproject commit 6362a530a88166df5b52376bd2107e7a531b2411