From: Jeremy Hayes Date: Wed, 16 Nov 2016 21:47:13 +0000 (-0700) Subject: demos: make present mode a command line option X-Git-Tag: sdk-1.0.37.0~220 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b14457f56caafd949c0db4356dc9fa9b3f464fce;p=platform%2Fupstream%2FVulkan-LoaderAndValidationLayers.git demos: make present mode a command line option Change-Id: I0dedd685225f5aecaba968ba81da487e5d05da26 --- diff --git a/demos/cube.cpp b/demos/cube.cpp index c6ce561..d7e8436 100644 --- a/demos/cube.cpp +++ b/demos/cube.cpp @@ -610,6 +610,7 @@ struct Demo { vec3 origin = {0, 0, 0}; vec3 up = {0.0f, 1.0f, 0.0}; + presentMode = vk::PresentModeKHR::eFifo; frameCount = UINT32_MAX; use_xlib = false; @@ -618,6 +619,12 @@ struct Demo { use_staging_buffer = true; continue; } + if ((strcmp(argv[i], "--present_mode") == 0) && + (i < argc - 1)) { + presentMode = (vk::PresentModeKHR)atoi(argv[i+1]); + i++; + continue; + } if (strcmp(argv[i], "--break") == 0) { use_break = true; continue; @@ -647,8 +654,13 @@ struct Demo { #if defined(VK_USE_PLATFORM_XLIB_KHR) "[--xlib] " #endif - "[--c ] [--suppress_popups]\n", - APP_SHORT_NAME); + "[--c ] [--suppress_popups] [--present_mode ]\n" + "VK_PRESENT_MODE_IMMEDIATE_KHR = %d\n" + "VK_PRESENT_MODE_MAILBOX_KHR = %d\n" + "VK_PRESENT_MODE_FIFO_KHR = %d\n" + "VK_PRESENT_MODE_FIFO_RELAXED_KHR = %d\n", + APP_SHORT_NAME, VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_MAILBOX_KHR, + VK_PRESENT_MODE_FIFO_KHR, VK_PRESENT_MODE_FIFO_RELAXED_KHR); fflush(stderr); exit(1); } @@ -1286,33 +1298,23 @@ struct Demo { // and to have no tearing. It's a great default present mode to use. vk::PresentModeKHR swapchainPresentMode = vk::PresentModeKHR::eFifo; -// There are times when you may wish to use another present mode. The -// following code shows how to select them, and the comments provide some -// reasons you may wish to use them. -// -// It should be noted that Vulkan 1.0 doesn't provide a method for -// synchronizing rendering with the presentation engine's display. There -// is a method provided for throttling rendering with the display, but -// there are some presentation engines for which this method will not work. -// If an application doesn't throttle its rendering, and if it renders much -// faster than the refresh rate of the display, this can waste power on -// mobile devices. That is because power is being spent rendering images -// that may never be seen. -//#define DESIRE_VK_PRESENT_MODE_IMMEDIATE_KHR -//#define DESIRE_VK_PRESENT_MODE_MAILBOX_KHR -//#define DESIRE_VK_PRESENT_MODE_FIFO_RELAXED_KHR -#if defined(DESIRE_VK_PRESENT_MODE_IMMEDIATE_KHR) + // There are times when you may wish to use another present mode. The + // following code shows how to select them, and the comments provide some + // reasons you may wish to use them. + // + // It should be noted that Vulkan 1.0 doesn't provide a method for + // synchronizing rendering with the presentation engine's display. There + // is a method provided for throttling rendering with the display, but + // there are some presentation engines for which this method will not work. + // If an application doesn't throttle its rendering, and if it renders much + // faster than the refresh rate of the display, this can waste power on + // mobile devices. That is because power is being spent rendering images + // that may never be seen. + // VK_PRESENT_MODE_IMMEDIATE_KHR is for applications that don't care // about // tearing, or have some way of synchronizing their rendering with the // display. - for (size_t i = 0; i < presentModeCount; ++i) { - if (presentModes[i] == vk::PresentModeKHR::eImmediate) { - swapchainPresentMode = vk::PresentModeKHR::eImmediate; - break; - } - } -#elif defined(DESIRE_VK_PRESENT_MODE_MAILBOX_KHR) // VK_PRESENT_MODE_MAILBOX_KHR may be useful for applications that // generally render a new presentable image every refresh cycle, but are // occasionally early. In this case, the application wants the new @@ -1320,13 +1322,6 @@ struct Demo { // to be displayed instead of the previously-queued-for-presentation // image // that has not yet been displayed. - for (size_t i = 0; i < presentModeCount; ++i) { - if (presentModes[i] == vk::PresentModeKHR::eMailbox) { - swapchainPresentMode = vk::PresentModeKHR::eMailbox; - break; - } - } -#elif defined(DESIRE_VK_PRESENT_MODE_FIFO_RELAXED_KHR) // VK_PRESENT_MODE_FIFO_RELAXED_KHR is for applications that generally // render a new presentable image every refresh cycle, but are // occasionally @@ -1334,13 +1329,21 @@ struct Demo { // the application wants the late image to be immediately displayed, // even // though that may mean some tearing. - for (size_t i = 0; i < presentModeCount; ++i) { - if (presentModes[i] == vk::PresentModeKHR::eFifoRelaxed) { - swapchainPresentMode = vk::PresentModeKHR::eFifoRelaxed; - break; + + if(presentMode != swapchainPresentMode) + { + for (size_t i = 0; i < presentModeCount; ++i) { + if (presentModes[i] == presentMode) { + swapchainPresentMode = presentMode; + break; + } } } -#endif + + if(swapchainPresentMode != presentMode) + { + ERR_EXIT("Present mode specified is not supported\n", "Present mode unsupported"); + } // Determine the number of VkImage's to use in the swap chain (we desire // to @@ -2636,6 +2639,7 @@ struct Demo { uint32_t swapchainImageCount; vk::SwapchainKHR swapchain; std::unique_ptr buffers; + vk::PresentModeKHR presentMode; vk::Fence fences[FRAME_LAG]; uint32_t frame_index;