From: Jean-Philippe Bruyère Date: Mon, 28 Feb 2022 09:32:53 +0000 (+0100) Subject: revert getop in test, does not compile on win X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=5e4f0232482ea252436ee3c843ded15f0dad7796;p=jp%2Fvkvg.git revert getop in test, does not compile on win --- diff --git a/tests/common/test.c b/tests/common/test.c index 6dac99e..f5f1b08 100644 --- a/tests/common/test.c +++ b/tests/common/test.c @@ -1,8 +1,4 @@ -#include -#include -#include - -#include "test.h" +#include "test.h" #include "string.h" #if defined(_WIN32) || defined(_WIN64) @@ -38,21 +34,21 @@ VkvgDevice device = NULL; VkvgSurface surf = NULL; uint32_t test_size = 500; // items drawn in one run, or complexity -uint32_t iterations = 500;// repeat test n times +uint32_t iterations = 500; // repeat test n times uint32_t test_width = 512; uint32_t test_height= 512; bool test_vsync = false; bool quiet = false;//if true, don't print details and head row -bool first_test = true;//if multiple tests, dont print header row. +bool first_test = true; //if multiple tests, dont print header row. bool no_test_size= false;//several test consist of a single draw sequence without looping 'size' times - //those test must be preceded by setting no_test_size to 'true' + //those test must be preceded by setting no_test_size to 'true' int test_index = 0; int single_test = -1; //if not < 0, contains the index of the single test to run -static bool paused = false; -static bool offscreen = false; -static bool threadAware = false; +static bool paused = false; +static bool offscreen = false; +static bool threadAware = false; static VkSampleCountFlags samples = VK_SAMPLE_COUNT_1_BIT; static VkPhysicalDeviceType preferedPhysicalDeviceType = VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU; static vk_engine_t* e; @@ -63,7 +59,7 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, return; switch (key) { case GLFW_KEY_SPACE: - paused = !paused; + paused = !paused; break; case GLFW_KEY_ESCAPE : glfwSetWindowShouldClose(window, GLFW_TRUE); @@ -147,7 +143,7 @@ double standard_deviation (const double data[], int n, double mean) double sum_deviation = 0.0; int i; for (i = 0; i < n; ++i) - sum_deviation += (data[i]-mean) * (data[i]-mean); + sum_deviation += (data[i]-mean) * (data[i]-mean); return sqrt (sum_deviation / n); } /***************/ @@ -171,7 +167,7 @@ void init_test (uint32_t width, uint32_t height){ vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), width, height); } -void clear_test (void) { +void clear_test () { vkDeviceWaitIdle(e->dev->dev); vkvg_surface_destroy (surf); @@ -183,7 +179,7 @@ void clear_test (void) { #ifdef VKVG_TEST_DIRECT_DRAW VkvgSurface* surfaces; #endif -void _print_usage_and_exit(void) { +void _print_usage_and_exit () { printf("\nUsage: test [options]\n\n"); printf("\t-i iterations:\tSpecify the repeat count for the test.\n"); printf("\t-s size:\tWhen applicable, specify the size of the test.\n"); @@ -220,87 +216,63 @@ void _print_usage_and_exit(void) { printf("\n"); exit(-1); } - -void _print_details_and_exit(void) { - #ifdef DEBUG - printf("Debug build\n"); - #else - printf("Release build\n"); - #endif - #ifdef VKVG_USE_RENDERDOC - printf("Render doc enabled\n"); - #endif - #ifdef VKVG_USE_VALIDATION - printf("Validation enabled\n"); - #endif - printf("surf dims:\t%d x %d\n", test_width, test_height); - printf("Samples:\t%d\n", samples); - printf("Gpu type:\t"); - switch (preferedPhysicalDeviceType) { - case VK_PHYSICAL_DEVICE_TYPE_OTHER: - printf("Other\n"); - break; - case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: - printf("Integrated\n"); - break; - case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: - printf("Discrete\n"); - break; - case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: - printf("Virtual\n"); - break; - case VK_PHYSICAL_DEVICE_TYPE_CPU: - printf("CPU\n"); - break; - } - if (offscreen) - printf("Offscreen:\ttrue\n"); - else - printf("Offscreen:\tfalse\n"); - if (fill_rule == VKVG_FILL_RULE_EVEN_ODD) - printf("Fillrule:\tEven/Odd\n"); - else - printf("Fillrule:\tNon zero\n"); - - printf("\n"); - exit(0); -} - void _parse_args (int argc, char* argv[]) { - int opt = 0; bool printTestDetailsAndExit = false; - while ((opt = getopt(argc, argv, "+c:df:g:i:j:l:n:opqtS:s:v:w:x:y:")) != -1) { - switch (opt) { - case 'c': - switch (optarg[0]) { - case 'b': - line_cap = VKVG_LINE_CAP_BUTT; - break; - case 'r': - line_cap = VKVG_LINE_CAP_ROUND; - break; - case 's': - line_cap = VKVG_LINE_CAP_SQUARE; - break; - default: - fprintf(stderr, "%s: invalid argument -- '%s'\n\n", argv[0], optarg); + for (int i = 1; i < argc; i++) { + if (strcmp (argv[i], "-h\0") == 0) + _print_usage_and_exit (); + if (strcmp (argv[i], "-p\0") == 0) + printTestDetailsAndExit = true; + else if (strcmp (argv[i], "-vsync\0") == 0) + test_vsync = true; + else if (strcmp(argv[i], "-q\0") == 0) + quiet = true; + else if (strcmp(argv[i], "-t\0") == 0) + threadAware = true; + else if (strcmp (argv[i], "-i\0") == 0) { + if (argc -1 < ++i) _print_usage_and_exit(); - } - break; - case 'd': + iterations = atoi (argv[i]); + }else if (strcmp (argv[i], "-x\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + test_width = atoi (argv[i]); + }else if (strcmp (argv[i], "-y\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + test_height = atoi (argv[i]); + }else if (strcmp (argv[i], "-n\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + single_test = atoi (argv[i]); + }else if (strcmp (argv[i], "-s\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + test_size = atoi (argv[i]); + }else if (strcmp (argv[i], "-S\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + samples = (VkSampleCountFlags)atoi (argv[i]); + }else if (strcmp (argv[i], "-g\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + preferedPhysicalDeviceType = (VkPhysicalDeviceType)atoi (argv[i]); + }else if (strcmp (argv[i], "-l\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + line_width = atoi (argv[i]); + }else if (strcmp (argv[i], "-d\0") == 0) { dashes_count = 2; - break; - case 'f': - fill_rule = atoi (optarg); - break; - case 'g': - preferedPhysicalDeviceType = (VkPhysicalDeviceType)atoi (optarg); - break; - case 'i': - iterations = atoi (optarg); - break; - case 'j': - switch (optarg[0]) { + }else if (strcmp (argv[i], "-f\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + fill_rule = atoi (argv[i]); + } else if (strcmp (argv[i], "-o\0") == 0) { + offscreen = true; + }else if (strcmp (argv[i], "-j\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + switch (argv[i][0]) { case 'm': line_join = VKVG_LINE_JOIN_MITER; break; @@ -311,57 +283,77 @@ void _parse_args (int argc, char* argv[]) { line_join = VKVG_LINE_JOIN_BEVEL; break; default: - fprintf(stderr, "%s: invalid argument -- '%s'\n\n", argv[0], optarg); _print_usage_and_exit(); } - break; - case 'l': - line_width = atoi (optarg); - break; - case 'n': - single_test = atoi (optarg); - break; - case 'o': - offscreen = true; - break; - case 'p': - printTestDetailsAndExit = true; - break; - case 'q': - quiet = true; - break; - case 't': - threadAware = true; - break; - case 'S': - samples = (VkSampleCountFlags)atoi (optarg); - break; - case 's': - test_size = atoi (optarg); - break; - case 'v': - if (strcmp(optarg, "sync") == 0) - test_vsync = true; - else { - fprintf(stderr, "%s: invalid option -- '%c'\n\n", argv[0], optarg[0]); + }else if (strcmp (argv[i], "-c\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + switch (argv[i][0]) { + case 'b': + line_cap = VKVG_LINE_CAP_BUTT; + break; + case 'r': + line_cap = VKVG_LINE_CAP_ROUND; + break; + case 's': + line_cap = VKVG_LINE_CAP_SQUARE; + break; + default: _print_usage_and_exit(); } + }else if (strcmp (argv[i], "-w\0") == 0) { + if (argc -1 < ++i) + _print_usage_and_exit(); + saveToPng = argv[i]; + }else + _print_usage_and_exit(); + } + if (printTestDetailsAndExit) { + #ifdef DEBUG + printf("Debug build\n"); + #else + printf("Release build\n"); + #endif + #ifdef VKVG_USE_RENDERDOC + printf("Render doc enabled\n"); + #endif + #ifdef VKVG_USE_VALIDATION + printf("Validation enabled\n"); + #endif + printf("surf dims:\t%d x %d\n", test_width, test_height); + printf("Samples:\t%d\n", samples); + printf("Gpu type:\t"); + switch (preferedPhysicalDeviceType) { + case VK_PHYSICAL_DEVICE_TYPE_OTHER: + printf("Other\n"); break; - case 'w': - saveToPng = optarg; + case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: + printf("Integrated\n"); break; - case 'x': - test_width = atoi (optarg); + case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: + printf("Discrete\n"); break; - case 'y': - test_height = atoi (optarg); + case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: + printf("Virtual\n"); + break; + case VK_PHYSICAL_DEVICE_TYPE_CPU: + printf("CPU\n"); break; - default: - _print_usage_and_exit(); } + + if (offscreen) + printf("Offscreen:\ttrue\n"); + else + printf("Offscreen:\tfalse\n"); + + if (fill_rule == VKVG_FILL_RULE_EVEN_ODD) + printf("Fillrule:\tEven/Odd\n"); + else + printf("Fillrule:\tNon zero\n"); + + printf("\n"); + exit(0); } - if (printTestDetailsAndExit) - _print_details_and_exit(); } void _print_results (const char *testName, int argc, char* argv[], uint32_t i, double run_total, double* run_time_values) { @@ -413,26 +405,26 @@ void _print_debug_stats () { #endif void perform_test (void(*testfunc)(void), const char *testName, int argc, char* argv[]) { + //dumpLayerExts(); _parse_args (argc, argv); - if (offscreen) - perform_test_offscreen(testfunc, testName, argc, argv); - else - perform_test_onscreen(testfunc, testName, argc, argv); -} -void perform_test_offscreen (void(*testfunc)(void), const char *testName, int argc, char* argv[]) { //init random gen struct timeval currentTime; gettimeofday(¤tTime, NULL); - srand((unsigned) currentTime.tv_usec); + srand((unsigned)currentTime.tv_usec); - //dumpLayerExts(); - - if (single_test >= 0 && test_index != single_test){ + if (single_test >= 0 && test_index != single_test) { test_index++; return; } - + + if (offscreen) + perform_test_offscreen(testfunc, testName, argc, argv); + else + perform_test_onscreen(testfunc, testName, argc, argv); +} + +void perform_test_offscreen (void(*testfunc)(void), const char *testName, int argc, char* argv[]) { uint32_t enabledExtsCount = 0, phyCount = 0; const char* enabledExts [10]; #ifdef VKVG_USE_RENDERDOC @@ -538,18 +530,6 @@ void perform_test_offscreen (void(*testfunc)(void), const char *testName, int ar } void perform_test_onscreen (void(*testfunc)(void), const char *testName, int argc, char* argv[]) { - //init random gen - struct timeval currentTime; - gettimeofday(¤tTime, NULL); - srand((unsigned) currentTime.tv_usec); - - //dumpLayerExts(); - - if (single_test >= 0 && test_index != single_test){ - test_index++; - return; - } - if (test_vsync) e = vkengine_create (preferedPhysicalDeviceType, VK_PRESENT_MODE_FIFO_KHR, test_width, test_height); else @@ -557,15 +537,15 @@ void perform_test_onscreen (void(*testfunc)(void), const char *testName, int arg VkhPresenter r = e->renderer; vkengine_set_key_callback (e, key_callback); - vkengine_set_mouse_but_callback(e, mouse_button_callback); - vkengine_set_cursor_pos_callback(e, mouse_move_callback); - vkengine_set_scroll_callback(e, scroll_callback); + vkengine_set_mouse_but_callback (e, mouse_button_callback); + vkengine_set_cursor_pos_callback (e, mouse_move_callback); + vkengine_set_scroll_callback (e, scroll_callback); bool deferredResolve = false; - device = vkvg_device_create_from_vk_multisample(vkh_app_get_inst(e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve); + device = vkvg_device_create_from_vk_multisample (vkh_app_get_inst (e->app), r->dev->phy, r->dev->dev, r->qFam, 0, samples, deferredResolve); - vkvg_device_set_dpy(device, 96, 96); + vkvg_device_set_dpy (device, 96, 96); if (threadAware) vkvg_device_set_thread_aware (device, 1); @@ -574,7 +554,7 @@ void perform_test_onscreen (void(*testfunc)(void), const char *testName, int arg for (uint32_t i=0; i < r->imgCount;i++) surfaces[i] = vkvg_surface_create_for_VkhImage (device, r->ScBuffers[i]); #else - surf = vkvg_surface_create(device, test_width, test_height); + surf = vkvg_surface_create (device, test_width, test_height); vkh_presenter_build_blit_cmd (r, vkvg_surface_get_vk_image(surf), test_width, test_height); #endif @@ -583,7 +563,7 @@ void perform_test_onscreen (void(*testfunc)(void), const char *testName, int arg uint32_t i = 0; - vkengine_set_title(e, testName); + vkengine_set_title (e, testName); while (!vkengine_should_close (e) && i < iterations) { glfwPollEvents(); @@ -658,6 +638,7 @@ void perform_test_onscreen (void(*testfunc)(void), const char *testName, int arg #ifdef VKVG_TEST_DIRECT_DRAW for (uint32_t i=0; iimgCount;i++) vkvg_surface_destroy (surfaces[i]); + free (surfaces); #else vkvg_surface_destroy (surf);