Browse Source

vulkan: implement vsync setting

niki 3 years ago
parent
commit
7be9bb3ecc

+ 0 - 10
src/common/Matrix.h

@@ -83,16 +83,6 @@ public:
 	 **/
 	void operator *= (const Matrix4 &m);
 
-	static friend bool operator==(const Matrix4& first, const Matrix4& other)
-	{
-		for (int i = 0; i < 16; i++) {
-			if (first.e[i] != other.e[i]) {
-				return false;
-			}
-		}
-		return true;
-	}
-
 	/**
 	 * Gets a pointer to the 16 array elements.
 	 * @return The array elements.

+ 0 - 8
src/modules/graphics/Shader.h

@@ -178,14 +178,6 @@ public:
  		Vector4 normalMatrix[3]; // 3x3 matrix padded to an array of 3 vector4s.
  		Vector4 screenSizeParams;
  		Colorf constantColor;
-
-		bool operator==(const BuiltinUniformData& other) {
-			auto first = *this;
-			return first.transformMatrix == other.transformMatrix && first.projectionMatrix == other.projectionMatrix
-				&& first.normalMatrix[0] == other.normalMatrix[0] && first.normalMatrix[1] == other.normalMatrix[1]
-				&& first.normalMatrix[2] == other.normalMatrix[2] && first.screenSizeParams == other.screenSizeParams
-				&& first.constantColor == other.constantColor;
-		}
  	};
 
 	// Pointer to currently active Shader.

+ 22 - 6
src/modules/graphics/vulkan/Graphics.cpp

@@ -972,14 +972,30 @@ VkSurfaceFormatKHR Graphics::chooseSwapSurfaceFormat(const std::vector<VkSurface
 }
 
 VkPresentModeKHR Graphics::chooseSwapPresentMode(const std::vector<VkPresentModeKHR>& availablePresentModes) {
-	// needed ?
-	for (const auto& availablePresentMode : availablePresentModes) {
-		if (availablePresentMode == VK_PRESENT_MODE_MAILBOX_KHR) {
-			return availablePresentMode;
+	int vsync = Vulkan::getVsync();
+
+	switch (vsync) {
+	case -1: {
+		auto it = std::find(availablePresentModes.begin(), availablePresentModes.end(), VK_PRESENT_MODE_FIFO_RELAXED_KHR);
+		if (it != availablePresentModes.end()) {
+			return VK_PRESENT_MODE_FIFO_RELAXED_KHR;
 		}
 	}
-
-	return VK_PRESENT_MODE_FIFO_KHR;
+	case 1: {
+		auto it = std::find(availablePresentModes.begin(), availablePresentModes.end(), VK_PRESENT_MODE_MAILBOX_KHR);
+		if (it != availablePresentModes.end()) {
+			return VK_PRESENT_MODE_MAILBOX_KHR;
+		}
+	}
+	case 0: {
+		auto it = std::find(availablePresentModes.begin(), availablePresentModes.end(), VK_PRESENT_MODE_IMMEDIATE_KHR);
+		if (it != availablePresentModes.end()) {
+			return VK_PRESENT_MODE_IMMEDIATE_KHR;
+		}
+	}
+	default:
+		return VK_PRESENT_MODE_FIFO_KHR;
+	}
 }
 
 VkExtent2D Graphics::chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities) {

+ 9 - 0
src/modules/graphics/vulkan/Vulkan.cpp

@@ -7,6 +7,7 @@ namespace love {
 namespace graphics {
 namespace vulkan {
 static uint32_t numShaderSwitches;
+static int vsync = 1;
 
 void Vulkan::shaderSwitch() {
 	numShaderSwitches++;
@@ -20,6 +21,14 @@ void Vulkan::resetShaderSwitches() {
 	numShaderSwitches = 0;
 }
 
+void Vulkan::setVsync(int value) {
+	vsync = value;
+}
+
+int Vulkan::getVsync() {
+	return vsync;
+}
+
 VkFormat Vulkan::getVulkanVertexFormat(DataFormat format) {
 	switch (format) {
 	case DATAFORMAT_FLOAT:

+ 3 - 0
src/modules/graphics/vulkan/Vulkan.h

@@ -30,6 +30,9 @@ public:
 	static uint32_t getNumShaderSwitches();
 	static void resetShaderSwitches();
 
+	static void setVsync(int vsync);
+	static int getVsync();
+
 	static VkFormat getVulkanVertexFormat(DataFormat format);
 	static TextureFormat getTextureFormat(PixelFormat);
 	static std::string getVendorName(uint32_t vendorId);

+ 7 - 1
src/modules/window/sdl/Window.cpp

@@ -21,7 +21,10 @@
 // LOVE
 #include "common/config.h"
 #include "graphics/Graphics.h"
-#include "graphics/vulkan/Graphics.h"
+#ifdef LOVE_GRAPHICS_VULKAN
+#	include "graphics/vulkan/Graphics.h"
+#	include "graphics/vulkan/Vulkan.h"
+#endif
 #include "Window.h"
 
 #ifdef LOVE_ANDROID
@@ -1116,6 +1119,9 @@ void Window::setVSync(int vsync)
 	}
 
 	// fixme: doesn't work for vulkan yet.
+#ifdef LOVE_GRAPHICS_VULKAN
+	love::graphics::vulkan::Vulkan::setVsync(vsync);
+#endif
 
 #if defined(LOVE_GRAPHICS_METAL) && defined(LOVE_MACOS)
 	if (metalView != nullptr)