]> O.S.I.I.S - jp/vkvg.git/commitdiff
use of most significant bit of first point of pathes to store closed/open state of...
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sat, 31 Aug 2019 15:24:51 +0000 (17:24 +0200)
committerj-p <jp_bruyere@hotmail.com>
Tue, 3 Sep 2019 18:36:09 +0000 (20:36 +0200)
src/vkvg_context.c
src/vkvg_context_internal.c
src/vkvg_internal.h
tests/common/vkengine.c
tests/common/vkengine.h

index aeef9535920ed5912ebecf8241095abe255f7951..db48ed2e919eb43f65d7752af120ec2f4f9467ea 100644 (file)
@@ -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)));
index 31e0ed1fc0b81b91edd056d965549d675882098c..73fc6751767878b20c5cf7566d0a8155881409bd 100644 (file)
@@ -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];
index 40a336f968184c2adf209b65250771463635b08d..0e66b42832979313f590850184d9aba32a3cc8ec 100644 (file)
@@ -30,7 +30,9 @@
 #include <float.h>
 #include <math.h>
 
-# 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)
index 787b3dfca8350b9f3d4cc0bb0950f1c7a3adae91..31d11e01df5475eee3100257c55b83bf73df47db 100644 (file)
@@ -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<layerCount; i++) {
+         printf ("\t - %s\n", availableLayers[i].layerName);
+    }
+    printf("-----------------\n\n");
+}
+
 static VkDebugReportCallbackEXT dbgReport;
 
 vk_engine_t* vkengine_create (VkPhysicalDeviceType preferedGPU, VkPresentModeKHR presentMode, uint32_t width, uint32_t height) {
index 3f80c5e134df085dd2be2d3f542ec8b977bef1c2..056be08bc8fd615ebb9b8921c528890e35c9c273 100644 (file)
@@ -46,7 +46,7 @@ typedef struct _vk_engine_t {
 }vk_engine_t;
 
 vk_engine_t*   vkengine_create  (VkPhysicalDeviceType preferedGPU, VkPresentModeKHR presentMode, uint32_t width, uint32_t height);
-
+void vkengine_dump_available_layers   ();
 void vkengine_destroy       (VkEngine e);
 bool vkengine_should_close  (VkEngine e);
 void vkengine_close         (VkEngine e);