diff options
| author | Karl Schultz <karl@lunarg.com> | 2016-03-24 18:43:41 -0600 |
|---|---|---|
| committer | Karl Schultz <karl@lunarg.com> | 2016-03-24 18:43:41 -0600 |
| commit | 8a66391f7fc6cc1d04a2e64f7ab790bb5ef849db (patch) | |
| tree | f2cfaf076b6479dea7c27136fcdf5a7cd7d5a810 | |
| parent | ca081b52049603090d41dcd451f1e6abdda0dc0e (diff) | |
| download | usermoji-8a66391f7fc6cc1d04a2e64f7ab790bb5ef849db.tar.xz | |
demos: Unify cmd arg handling between cube and tri.
Add --c (frame count) handling to tri to improve testability and
to bring it up to par with cube.
Fix exit code return in both cube and tri for Windows.
Change-Id: I27516b9fc0d13f25f5511ab159a80159c2550237
| -rw-r--r-- | demos/cube.c | 5 | ||||
| -rw-r--r-- | demos/tri.c | 123 |
2 files changed, 94 insertions, 34 deletions
diff --git a/demos/cube.c b/demos/cube.c index 5477beee..0e87aedf 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -1910,11 +1910,8 @@ static void demo_run(struct demo *demo) { vkDeviceWaitIdle(demo->device); demo->curFrame++; - if (demo->frameCount != INT_MAX && demo->curFrame == demo->frameCount) { - demo->quit = true; - demo_cleanup(demo); - ExitProcess(0); + PostQuitMessage(validation_error); } } diff --git a/demos/tri.c b/demos/tri.c index c17d668c..a7366255 100644 --- a/demos/tri.c +++ b/demos/tri.c @@ -112,6 +112,8 @@ struct texture_object { int32_t tex_width, tex_height; }; +static int validation_error = 0; + VKAPI_ATTR VkBool32 VKAPI_CALL dbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, uint64_t srcObject, size_t location, int32_t msgCode, @@ -120,6 +122,8 @@ dbgFunc(VkFlags msgFlags, VkDebugReportObjectTypeEXT objType, assert(message); + validation_error = 1; + if (msgFlags & VK_DEBUG_REPORT_ERROR_BIT_EXT) { sprintf(message, "ERROR: [%s] Code %d : %s", pLayerPrefix, msgCode, pMsg); @@ -243,7 +247,10 @@ struct demo { VkPhysicalDeviceMemoryProperties memory_properties; + int32_t curFrame; + int32_t frameCount; bool validate; + bool use_break; PFN_vkCreateDebugReportCallbackEXT CreateDebugReportCallback; PFN_vkDestroyDebugReportCallbackEXT DestroyDebugReportCallback; VkDebugReportCallbackEXT msg_callback; @@ -1510,6 +1517,11 @@ static void demo_run(struct demo *demo) { demo->depthIncrement = 0.001f; demo->depthStencil += demo->depthIncrement; + + demo->curFrame++; + if (demo->frameCount != INT32_MAX && demo->curFrame == demo->frameCount) { + PostQuitMessage(validation_error); + } } // On MS-Windows, make this a global, so it's available to WndProc() @@ -1523,7 +1535,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { case WM_CREATE: return 0; case WM_CLOSE: - PostQuitMessage(0); + PostQuitMessage(validation_error); return 0; case WM_PAINT: if (demo.prepared) { @@ -1652,6 +1664,9 @@ static void demo_run(struct demo *demo) { // Wait for work to finish before updating MVP. vkDeviceWaitIdle(demo->device); + demo->curFrame++; + if (demo->frameCount != INT32_MAX && demo->curFrame == demo->frameCount) + demo->quit = true; } } @@ -2224,6 +2239,9 @@ static void demo_init_vk_swapchain(struct demo *demo) { } demo->color_space = surfFormats[0].colorSpace; + demo->quit = false; + demo->curFrame = 0; + // Get Memory information and properties vkGetPhysicalDeviceMemoryProperties(demo->gpu, &demo->memory_properties); } @@ -2251,38 +2269,34 @@ static void demo_init_connection(struct demo *demo) { #endif // _WIN32 } -#ifdef _WIN32 -static void demo_init(struct demo *demo, HINSTANCE hInstance, LPSTR pCmdLine) -#else // _WIN32 static void demo_init(struct demo *demo, const int argc, const char *argv[]) -#endif // _WIN32 { - bool argv_error = false; - memset(demo, 0, sizeof(*demo)); + demo->frameCount = INT32_MAX; -#ifdef _WIN32 - demo->connection = hInstance; - strncpy(demo->name, APP_SHORT_NAME, APP_NAME_STR_LEN); - - if (strncmp(pCmdLine, "--use_staging", strlen("--use_staging")) == 0) - demo->use_staging_buffer = true; - else if (strncmp(pCmdLine, "--validate", strlen("--validate")) == 0) - demo->validate = true; - else if (strlen(pCmdLine) != 0) { - fprintf(stderr, "Do not recognize argument \"%s\".\n", pCmdLine); - argv_error = true; - } -#else // _WIN32 - for (int i = 0; i < argc; i++) { - if (strncmp(argv[i], "--use_staging", strlen("--use_staging")) == 0) + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "--use_staging") == 0) { demo->use_staging_buffer = true; - if (strncmp(argv[i], "--validate", strlen("--validate")) == 0) + continue; + } + if (strcmp(argv[i], "--break") == 0) { + demo->use_break = true; + continue; + } + if (strcmp(argv[i], "--validate") == 0) { demo->validate = true; - } -#endif // _WIN32 - if (argv_error) { - fprintf(stderr, "Usage:\n %s [--use_staging] [--validate]\n", APP_SHORT_NAME); + continue; + } + if (strcmp(argv[i], "--c") == 0 && demo->frameCount == INT32_MAX && + i < argc - 1 && sscanf(argv[i + 1], "%d", &demo->frameCount) == 1 && + demo->frameCount >= 0) { + i++; + continue; + } + + fprintf(stderr, "Usage:\n %s [--use_staging] [--validate] [--break] " + "[--c <framecount>]\n", + APP_SHORT_NAME); fflush(stderr); exit(1); } @@ -2411,12 +2425,61 @@ static void demo_resize(struct demo *demo) { } #ifdef _WIN32 -int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, +// Include header required for parsing the command line options. +#include <shellapi.h> + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pCmdLine, int nCmdShow) { MSG msg; // message bool done; // flag saying when app is complete + int argc; + char **argv; + + // Use the CommandLine functions to get the command line arguments. + // Unfortunately, Microsoft outputs + // this information as wide characters for Unicode, and we simply want the + // Ascii version to be compatible + // with the non-Windows side. So, we have to convert the information to + // Ascii character strings. + LPWSTR *commandLineArgs = CommandLineToArgvW(GetCommandLineW(), &argc); + if (NULL == commandLineArgs) { + argc = 0; + } + + if (argc > 0) { + argv = (char **)malloc(sizeof(char *) * argc); + if (argv == NULL) { + argc = 0; + } else { + for (int iii = 0; iii < argc; iii++) { + size_t wideCharLen = wcslen(commandLineArgs[iii]); + size_t numConverted = 0; + + argv[iii] = (char *)malloc(sizeof(char) * (wideCharLen + 1)); + if (argv[iii] != NULL) { + wcstombs_s(&numConverted, argv[iii], wideCharLen + 1, + commandLineArgs[iii], wideCharLen + 1); + } + } + } + } else { + argv = NULL; + } + + demo_init(&demo, argc, argv); + + // Free up the items we had to allocate for the command line arguments. + if (argc > 0 && argv != NULL) { + for (int iii = 0; iii < argc; iii++) { + if (argv[iii] != NULL) { + free(argv[iii]); + } + } + free(argv); + } - demo_init(&demo, hInstance, pCmdLine); + demo.connection = hInstance; + strncpy(demo.name, "tri", APP_NAME_STR_LEN); demo_create_window(&demo); demo_init_vk_swapchain(&demo); @@ -2454,6 +2517,6 @@ int main(const int argc, const char *argv[]) { demo_cleanup(&demo); - return 0; + return validation_error; } #endif // _WIN32 |
