Parcourir la source

Change the presentation a bit and add target FPS

Panagiotis Christopoulos Charitos il y a 5 ans
Parent
commit
c979abdc1c
3 fichiers modifiés avec 19 ajouts et 8 suppressions
  1. 1 1
      src/anki/core/App.cpp
  2. 1 0
      src/anki/core/ConfigDefs.h
  3. 17 7
      src/anki/gr/vulkan/SwapchainFactory.cpp

+ 1 - 1
src/anki/core/App.cpp

@@ -346,7 +346,7 @@ Error App::initInternal(const ConfigSet& config_, AllocAlignedCallback allocCb,
 		__DATE__,
 		ANKI_REVISION);
 
-	m_timerTick = 1.0 / 60.0; // in sec. 1.0 / period
+	m_timerTick = 1.0 / F32(config.getNumberU32("core_targetFps")); // in sec. 1.0 / period
 
 // Check SIMD support
 #if ANKI_SIMD_SSE && ANKI_COMPILER_GCC_COMPATIBLE

+ 1 - 0
src/anki/core/ConfigDefs.h

@@ -10,6 +10,7 @@ ANKI_CONFIG_OPTION(core_textureBufferPerFrameMemorySize, 1_MB, 1_MB, 1_GB)
 
 ANKI_CONFIG_OPTION(width, 1280, 16, 16 * 1024, "Width")
 ANKI_CONFIG_OPTION(height, 768, 16, 16 * 1024, "Height")
+ANKI_CONFIG_OPTION(core_targetFps, 60u, 30u, MAX_U32, "Target FPS")
 ANKI_CONFIG_OPTION(core_mainThreadCount, max(2u, getCpuCoresCount() / 2u), 2u, 1024u)
 ANKI_CONFIG_OPTION(core_displayStats, 0, 0, 1)
 ANKI_CONFIG_OPTION(core_clearCaches, 0, 0, 1)

+ 17 - 7
src/anki/gr/vulkan/SwapchainFactory.cpp

@@ -88,6 +88,7 @@ Error MicroSwapchain::initInternal()
 
 	// Chose present mode
 	VkPresentModeKHR presentMode = VK_PRESENT_MODE_MAX_ENUM_KHR;
+	VkPresentModeKHR presentModeSecondChoice = VK_PRESENT_MODE_MAX_ENUM_KHR;
 	{
 		uint32_t presentModeCount;
 		vkGetPhysicalDeviceSurfacePresentModesKHR(
@@ -99,25 +100,34 @@ Error MicroSwapchain::initInternal()
 
 		if(m_factory->m_vsync)
 		{
-			presentMode = VK_PRESENT_MODE_FIFO_KHR;
+			for(U i = 0; i < presentModeCount; ++i)
+			{
+				if(presentModes[i] == VK_PRESENT_MODE_FIFO_RELAXED_KHR)
+				{
+					presentMode = presentModes[i];
+				}
+				else if(presentModes[i] == VK_PRESENT_MODE_FIFO_KHR)
+				{
+					presentModeSecondChoice = presentModes[i];
+				}
+			}
 		}
 		else
 		{
 			for(U i = 0; i < presentModeCount; ++i)
 			{
-				if(presentModes[i] == VK_PRESENT_MODE_MAILBOX_KHR)
+				if(presentModes[i] == VK_PRESENT_MODE_IMMEDIATE_KHR)
 				{
-					presentMode = VK_PRESENT_MODE_MAILBOX_KHR;
-					break;
+					presentMode = presentModes[i];
 				}
-				else if(presentModes[i] == VK_PRESENT_MODE_IMMEDIATE_KHR)
+				else if(presentModes[i] == VK_PRESENT_MODE_MAILBOX_KHR)
 				{
-					presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR;
-					break;
+					presentModeSecondChoice = presentModes[i];
 				}
 			}
 		}
 
+		presentMode = (presentMode != VK_PRESENT_MODE_MAX_ENUM_KHR) ? presentMode : presentModeSecondChoice;
 		if(presentMode == VK_PRESENT_MODE_MAX_ENUM_KHR)
 		{
 			ANKI_VK_LOGE("Couldn't find a present mode");