From 75c011017295932be6e6fea874a7660579c3b223 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Sat, 31 Aug 2019 17:24:51 +0200 Subject: [PATCH] use of most significant bit of first point of pathes to store closed/open state of path --- src/vkvg_context.c | 19 ++++++++----------- src/vkvg_context_internal.c | 27 ++++++++++++++------------- src/vkvg_internal.h | 4 +++- tests/common/vkengine.c | 23 +++++++++++++++++++---- tests/common/vkengine.h | 2 +- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/vkvg_context.c b/src/vkvg_context.c index aeef953..db48ed2 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -273,12 +273,9 @@ void vkvg_close_path (VkvgContext ctx){ return; } //check if at least 3 points are present - if (ctx->pointCount - ctx->pathes [ctx->pathPtr-1] > 2){ - //set end idx of path to the same as start idx - ctx->pathes[ctx->pathPtr] = ctx->pathes [ctx->pathPtr-1]; - //if last point of path is same pos as first point, remove it - //if (vec2_equ(ctx->points[ctx->pointCount-1], ctx->points[ctx->pathes[ctx->pathPtr]])) - // ctx->pointCount--; + if (ctx->pointCount - (ctx->pathes [ctx->pathPtr-1]&PATH_ELT_MASK) > 2){ + ctx->pathes[ctx->pathPtr] = ctx->pointCount - 1; + ctx->pathes[ctx->pathPtr-1] |= PATH_CLOSED_BIT; _check_pathes_array(ctx); ctx->pathPtr++; }else @@ -550,12 +547,12 @@ void vkvg_stroke_preserve (VkvgContext ctx) while (ptrPath < ctx->pathPtr){ uint32_t firstIdx = ctx->vertCount; - i = ctx->pathes[ptrPath]; + i = ctx->pathes[ptrPath]&PATH_ELT_MASK; - LOG(LOG_INFO_PATH, "\tPATH: start = %d; ", ctx->pathes[ptrPath], ctx->pathes[ptrPath+1]); + LOG(LOG_INFO_PATH, "\tPATH: start = %d; ", ctx->pathes[ptrPath]&PATH_ELT_MASK, ctx->pathes[ptrPath+1]&PATH_ELT_MASK); if (_path_is_closed(ctx,ptrPath)){ - lastPathPointIdx = _get_last_point_of_closed_path(ctx,ptrPath); + lastPathPointIdx = ctx->pathes[ptrPath+1]&PATH_ELT_MASK;// _get_last_point_of_closed_path(ctx,ptrPath); LOG(LOG_INFO_PATH, "end = %d\n", lastPathPointIdx); //prevent closing on the same position, this could be generalize //to prevent processing of two consecutive point at the same position @@ -563,7 +560,7 @@ void vkvg_stroke_preserve (VkvgContext ctx) lastPathPointIdx--; iL = lastPathPointIdx; }else{ - lastPathPointIdx = ctx->pathes[ptrPath+1]; + lastPathPointIdx = ctx->pathes[ptrPath+1]&PATH_ELT_MASK; LOG(LOG_INFO_PATH, "end = %d\n", lastPathPointIdx); vec2 n = vec2_line_norm(ctx->points[i], ctx->points[i+1]); @@ -645,7 +642,7 @@ void vkvg_stroke_preserve (VkvgContext ctx) i++; }else{ - iR = ctx->pathes[ptrPath]; + iR = ctx->pathes[ptrPath]&PATH_ELT_MASK; _build_vb_step(ctx,v,hw,iL,i,iR); uint32_t* inds = (uint32_t*)(ctx->indices.allocInfo.pMappedData + ((ctx->indCount-6) * sizeof(uint32_t))); diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index 31e0ed1..73fc675 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -84,7 +84,7 @@ void _clear_path (VkvgContext ctx){ ctx->pointCount = 0; } inline bool _path_is_closed (VkvgContext ctx, uint32_t ptrPath){ - return (ctx->pathes[ptrPath] == ctx->pathes[ptrPath+1]); + return ctx->pathes[ptrPath] & PATH_CLOSED_BIT; } uint32_t _get_last_point_of_closed_path(VkvgContext ctx, uint32_t ptrPath){ if (ptrPath+2 < ctx->pathPtr) //this is not the last path @@ -176,6 +176,9 @@ void _vao_add_rectangle (VkvgContext ctx, float x, float y, float width, float h void _create_cmd_buff (VkvgContext ctx){ ctx->cmd = vkh_cmd_buff_create((VkhDevice)ctx->pSurf->dev, ctx->cmdPool,VK_COMMAND_BUFFER_LEVEL_PRIMARY); +#if DEBUG + vkh_device_set_object_name((VkhDevice)ctx->pSurf->dev, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT, (uint64_t)ctx->cmd, "vkvgCtxCmd"); +#endif } void _record_draw_cmd (VkvgContext ctx){ if (ctx->indCount == ctx->curIndStart) @@ -807,15 +810,14 @@ void _poly_fill (VkvgContext ctx){ v.uv.z = -1; while (ptrPath < ctx->pathPtr){ - if (!_path_is_closed(ctx, ptrPath)) - ctx->pathes[ptrPath+1] = ctx->pathes[ptrPath];//close path by setting start and end equal + //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]; - uint32_t lastPtIdx = _get_last_point_of_closed_path (ctx, ptrPath); - uint32_t pathPointCount = lastPtIdx - ctx->pathes[ptrPath] + 1; + 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 (int i = 0; i < pathPointCount; i++) { v.pos = ctx->points[i+firstPtIdx]; _add_vertex(ctx, v); @@ -833,13 +835,12 @@ void _fill_ec (VkvgContext ctx){ v.uv.z = -1; while (ptrPath < ctx->pathPtr){ - if (!_path_is_closed(ctx, ptrPath)) - //close path - ctx->pathes[ptrPath+1] = ctx->pathes[ptrPath]; - uint32_t firstPtIdx = ctx->pathes[ptrPath]; - uint32_t lastPtIdx = _get_last_point_of_closed_path (ctx, ptrPath); - uint32_t pathPointCount = lastPtIdx - ctx->pathes[ptrPath] + 1; + ctx->pathes[ptrPath]|=PATH_CLOSED_BIT;//close path + + uint32_t firstPtIdx = ctx->pathes[ptrPath]&PATH_ELT_MASK; + uint32_t lastPtIdx = ctx->pathes[ptrPath+1]&PATH_ELT_MASK; + uint32_t pathPointCount = lastPtIdx - firstPtIdx + 1; uint32_t firstVertIdx = ctx->vertCount; ear_clip_point ecps[pathPointCount]; diff --git a/src/vkvg_internal.h b/src/vkvg_internal.h index 40a336f..0e66b42 100644 --- a/src/vkvg_internal.h +++ b/src/vkvg_internal.h @@ -30,7 +30,9 @@ #include #include -# define M_PIF 3.14159265358979323846f /* float pi */ +#define M_PIF 3.14159265358979323846f /* float pi */ +#define PATH_CLOSED_BIT 0x80000000 /* most significant bit of path elmts is closed/open path state */ +#define PATH_ELT_MASK 0x7FFFFFFF /* Bit mask for fetching path element value */ #define ROUNDF(f, c) (((float)((int)((f) * (c))) / (c))) #define ROUND_DOWN(v,p) (floorf(v * p) / p) diff --git a/tests/common/vkengine.c b/tests/common/vkengine.c index 787b3df..31d11e0 100644 --- a/tests/common/vkengine.c +++ b/tests/common/vkengine.c @@ -32,7 +32,7 @@ bool vkeCheckPhyPropBlitSource (VkEngine e) { VkFormatProperties formatProps; vkGetPhysicalDeviceFormatProperties(e->dev->phy, e->renderer->format, &formatProps); -#if VKVG_TILING_OPTIMAL +#ifdef VKVG_TILING_OPTIMAL assert((formatProps.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT) && "Format cannot be used as transfer source"); #else assert((formatProps.linearTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT) && "Format cannot be used as transfer source"); @@ -56,12 +56,12 @@ void vkengine_dump_Infos (VkEngine e){ printf("max tex array layers = %d\n", e->gpu_props.limits.maxImageArrayLayers); printf("max mem alloc count = %d\n", e->gpu_props.limits.maxMemoryAllocationCount); - for (int i = 0; i < e->memory_properties.memoryHeapCount; i++) { + for (uint32_t i = 0; i < e->memory_properties.memoryHeapCount; i++) { printf("Mem Heap %d\n", i); printf("\tflags= %d\n", e->memory_properties.memoryHeaps[i].flags); - printf("\tsize = %d Mo\n", e->memory_properties.memoryHeaps[i].size/ (1024*1024)); + printf("\tsize = %lu Mo\n", e->memory_properties.memoryHeaps[i].size/ (uint32_t)(1024*1024)); } - for (int i = 0; i < e->memory_properties.memoryTypeCount; i++) { + for (uint32_t i = 0; i < e->memory_properties.memoryTypeCount; i++) { printf("Mem type %d\n", i); printf("\theap %d: ", e->memory_properties.memoryTypes[i].heapIndex); if (e->memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) @@ -78,6 +78,21 @@ void vkengine_dump_Infos (VkEngine e){ } } +void vkengine_dump_available_layers () { + uint32_t layerCount; + vkEnumerateInstanceLayerProperties(&layerCount, NULL); + + VkLayerProperties availableLayers [layerCount]; + vkEnumerateInstanceLayerProperties(&layerCount, availableLayers); + + printf("Available Layers:\n"); + printf("-----------------\n"); + for (uint i=0; i