From b42af4e54b90dc92debadfb8a09d26fc740bc18a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Wed, 14 Oct 2020 09:36:50 +0200 Subject: [PATCH] solve macro=type problem for ibo int, debug statistic --- CMakeLists.txt | 11 ++++++++++ include/vkvg.h | 20 ++++++++++++++++++ src/vkvg_context.c | 17 +++++++++++++++ src/vkvg_context_internal.c | 6 +----- src/vkvg_context_internal.h | 17 +++++++++++---- src/vkvg_device.c | 13 ++++++++++++ src/vkvg_device_internal.h | 3 +++ tests/common/test.c | 41 +++++++++++++++++++++++++++++-------- 8 files changed, 110 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5269a7f..857f4d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,12 @@ IF (VKVG_PREMULT_ALPHA) ADD_DEFINITIONS (-DVKVG_PREMULT_ALPHA) ENDIF () +OPTION(VKVG_DBG_STATS "record contexts statistics in the device" OFF) +IF (VKVG_DBG_STATS) + ADD_DEFINITIONS (-DVKVG_DBG_STATS) +ENDIF () + + SET(VULKAN_SDK "$ENV{VULKAN_SDK}" CACHE STRING "LunarG Vulkan SDK path") IF (VULKAN_SDK) SET(ENV{VULKAN_SDK} ${VULKAN_SDK}) @@ -221,6 +227,11 @@ ENDIF () IF (VKVG_TEST_OFFSCREEN) MESSAGE(STATUS "Offscreen\t\t= true.") ENDIF () +IF (VKVG_DBG_STATS) + MESSAGE(STATUS "Debug statistics\t= enabled.") +ELSE () + MESSAGE(STATUS "Debug statistics\t= disabled.") +ENDIF () IF (ENABLE_DBG_UTILS) MESSAGE(STATUS "Debug utils\t\t= enabled.") ELSE () diff --git a/include/vkvg.h b/include/vkvg.h index 903e59e..156c148 100644 --- a/include/vkvg.h +++ b/include/vkvg.h @@ -274,6 +274,26 @@ typedef struct _vkvg_device_t* VkvgDevice; */ typedef struct _vkvg_pattern_t* VkvgPattern; +#if VKVG_DBG_STATS +/** + * @brief vkvg memory and vulkan statistiques. + * + * @ingroup device + */ +typedef struct { + uint32_t sizePoints; /**< maximum point array size */ + uint32_t sizePathes; /**< maximum path array size */ + uint32_t sizeVertices; /**< maximum size of host vertice cache */ + uint32_t sizeIndices; /**< maximum size of host index cache */ + uint32_t sizeVBO; /**< maximum size of vulkan vertex buffer */ + uint32_t sizeIBO; /**< maximum size of vulkan index buffer */ +} vkvg_debug_stats_t; + +vkvg_debug_stats_t vkvg_device_get_stats (VkvgDevice dev); +vkvg_debug_stats_t vkvg_device_reset_stats (VkvgDevice dev); +#endif + + /** * @defgroup matrix Matrices * @brief Generic matrix operations diff --git a/src/vkvg_context.c b/src/vkvg_context.c index f0ae09e..7a99356 100644 --- a/src/vkvg_context.c +++ b/src/vkvg_context.c @@ -201,6 +201,23 @@ void vkvg_destroy (VkvgContext ctx) VkDevice dev = ctx->pSurf->dev->vkDev; +#if VKVG_DBG_STATS + vkvg_debug_stats_t* dbgstats = &ctx->pSurf->dev->debug_stats; + if (dbgstats->sizePoints < ctx->sizePoints) + dbgstats->sizePoints = ctx->sizePoints; + if (dbgstats->sizePathes < ctx->sizePathes) + dbgstats->sizePathes = ctx->sizePathes; + if (dbgstats->sizeVertices < ctx->sizeVertices) + dbgstats->sizeVertices = ctx->sizeVertices; + if (dbgstats->sizeIndices < ctx->sizeIndices) + dbgstats->sizeIndices = ctx->sizeIndices; + if (dbgstats->sizeVBO < ctx->sizeVBO) + dbgstats->sizeVBO = ctx->sizeVBO; + if (dbgstats->sizeIBO < ctx->sizeIBO) + dbgstats->sizeIBO = ctx->sizeIBO; + +#endif + vkDestroyFence (dev, ctx->flushFence,NULL); vkFreeCommandBuffers(dev, ctx->cmdPool, 2, ctx->cmdBuffers); vkDestroyCommandPool(dev, ctx->cmdPool, NULL); diff --git a/src/vkvg_context_internal.c b/src/vkvg_context_internal.c index cfe944c..d3df56b 100644 --- a/src/vkvg_context_internal.c +++ b/src/vkvg_context_internal.c @@ -534,11 +534,7 @@ void _start_cmd_for_render_pass (VkvgContext ctx) { VkDeviceSize offsets[1] = { 0 }; CmdBindVertexBuffers(ctx->cmd, 0, 1, &ctx->vertices.buffer, offsets); -#if VKVG_IBO_INDEX_TYPE == uint16_t - CmdBindIndexBuffer(ctx->cmd, ctx->indices.buffer, 0, VK_INDEX_TYPE_UINT16); -#else - CmdBindIndexBuffer(ctx->cmd, ctx->indices.buffer, 0, VK_INDEX_TYPE_UINT32); -#endif + CmdBindIndexBuffer(ctx->cmd, ctx->indices.buffer, 0, VKVG_VK_INDEX_TYPE); _update_push_constants (ctx); diff --git a/src/vkvg_context_internal.h b/src/vkvg_context_internal.h index e9b45c9..4f65868 100644 --- a/src/vkvg_context_internal.h +++ b/src/vkvg_context_internal.h @@ -33,11 +33,20 @@ #define VKVG_IBO_SIZE (VKVG_VBO_SIZE * 6) #define VKVG_PATHES_SIZE 16 #define VKVG_ARRAY_THRESHOLD 8 -#define VKVG_IBO_INDEX_TYPE uint16_t -#if VKVG_IBO_INDEX_TYPE == uint16_t - #define VKVG_IBO_MAX UINT16_MAX + +#define VKVG_IBO_16 0 +#define VKVG_IBO_32 1 + +#define VKVG_CUR_IBO_TYPE VKVG_IBO_16//change this only + +#if VKVG_CUR_IBO_TYPE == VKVG_IBO_16 + #define VKVG_IBO_MAX UINT16_MAX + #define VKVG_IBO_INDEX_TYPE uint16_t + #define VKVG_VK_INDEX_TYPE VK_INDEX_TYPE_UINT16 #else - #define VKVG_IBO_MAX UINT32_MAX + #define VKVG_IBO_MAX UINT32_MAX + #define VKVG_IBO_INDEX_TYPE uint32_t + #define VKVG_VK_INDEX_TYPE VK_INDEX_TYPE_UINT32 #endif diff --git a/src/vkvg_device.c b/src/vkvg_device.c index e17b81b..f71b48d 100644 --- a/src/vkvg_device.c +++ b/src/vkvg_device.c @@ -43,6 +43,10 @@ VkvgDevice vkvg_device_create_multisample(VkInstance inst, VkPhysicalDevice phy, dev->vkDev = vkdev; dev->phy = phy; +#if VKVG_DBG_STATS + dev->debug_stats = (vkvg_debug_stats_t) {0}; +#endif + VkFormat format = FB_COLOR_FORMAT; VkImageTiling tiling; if (!_get_best_image_tiling (dev, format, &tiling)) { @@ -187,3 +191,12 @@ void vkvg_device_get_dpy (VkvgDevice dev, int* hdpy, int* vdpy) { *hdpy = dev->hdpi; *vdpy = dev->vdpi; } + +#if VKVG_DBG_STATS +vkvg_debug_stats_t vkvg_device_get_stats (VkvgDevice dev) { + return dev->debug_stats; +} +vkvg_debug_stats_t vkvg_device_reset_stats (VkvgDevice dev) { + dev->debug_stats = (vkvg_debug_stats_t) {0}; +} +#endif diff --git a/src/vkvg_device_internal.h b/src/vkvg_device_internal.h index 8d8da08..ff5378d 100644 --- a/src/vkvg_device_internal.h +++ b/src/vkvg_device_internal.h @@ -77,6 +77,9 @@ typedef struct _vkvg_device_t{ #ifdef VKVG_WIRED_DEBUG VkPipeline pipelineWired; VkPipeline pipelineLineList; +#endif +#if VKVG_DBG_STATS + vkvg_debug_stats_t debug_stats; /**< debug statistics on memory usage and vulkan ressources */ #endif VkPipelineCache pipelineCache; /**< speed up startup by caching configured pipelines on disk */ VkPipelineLayout pipelineLayout; /**< layout common to all pipelines */ diff --git a/tests/common/test.c b/tests/common/test.c index 625037b..f145e7d 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -247,19 +247,42 @@ void _print_results (const char *testName, int argc, char* argv[], uint32_t i, d avg_frames_per_second = (avg_frames_per_second<9999) ? avg_frames_per_second:9999; if (!quiet && (test_index == 0 || test_index == single_test)) { - printf ("__________________________________________________________________________________________________________\n"); +#if VKVG_DBG_STATS + printf ("_____________________________________________________________________________________________________________________________\n"); + printf ("| N° | Test File Name | Sub Test | Iter | Size | Pts |Pathes| Vx cache | Ix cache | VBO | IBO |\n"); + printf ("|----|-----------------|---------------------------|------|------|-------|------|----------|----------|----------|----------|\n"); +#else + printf ("__________________________________________________________________________________________________________\n"); printf ("| N° | Test File Name | Sub Test | Iter | Size | FPS | Average | Median | Sigma |\n"); printf ("|----|-----------------|---------------------------|------|------|---------|---------|---------|---------|\n"); +#endif } - printf ("| %2d | %-15s | %-25s | ", test_index, whoami + 5, testName); + + printf ("| %2d | %-15s | %-25s | %4d | ", test_index, whoami + 5, testName, i); if (no_test_size) - printf ("%4d | %4d | %7.2f | %6.5f | %6.5f | %6.5f |\n", - i, 1, avg_frames_per_second, avg_run_time, med_run_time, standard_dev); + printf ("%4d | ", 1); else - printf ("%4d | %4d | %7.2f | %6.5f | %6.5f | %6.5f |\n", - i, test_size, avg_frames_per_second, avg_run_time, med_run_time, standard_dev); - + printf ("%4d | ", test_size); + +#if VKVG_DBG_STATS + vkvg_debug_stats_t dbgStats = vkvg_device_get_stats (device); + printf ("%5d | %4d | %8d | %8d | %8d | %8d |\n", + dbgStats.sizePoints, dbgStats.sizePathes, dbgStats.sizeVertices, + dbgStats.sizeIndices, dbgStats.sizeVBO, dbgStats.sizeIBO); +#else + printf ("%7.2f | %6.5f | %6.5f | %6.5f |\n", + avg_frames_per_second, avg_run_time, med_run_time, standard_dev); +#endif +} + +#if VKVG_DBG_STATS +void _print_debug_stats () { + + vkvg_debug_stats_t dbgStats = vkvg_device_get_stats (device); + printf ("| %8d | %8d | %8d | %8d | %8d | %8d |\n", dbgStats.sizePoints, dbgStats.sizePathes, dbgStats.sizeVertices, + dbgStats.sizeIndices, dbgStats.sizeVBO, dbgStats.sizeIBO); } +#endif void perform_test_offscreen (void(*testfunc)(void), const char *testName, int argc, char* argv[]) { //init random gen @@ -501,7 +524,7 @@ void perform_test (void(*testfunc)(void), const char *testName, int argc, char* #else vkvg_surface_destroy (surf); #endif - + vkvg_device_destroy (device); vkengine_destroy (e); @@ -517,7 +540,7 @@ vkvg_line_join_t line_join = VKVG_LINE_JOIN_MITER; float dashes[] = {20.0f, 10.0f}; uint32_t dashes_count= 0; float dash_offset = 0; -float line_width = 1.f; +float line_width = 10.f; VkvgContext _initCtx() { VkvgContext ctx = vkvg_create(surf); -- 2.47.3