vulkan: implement vsync setting

This commit is contained in:
niki
2022-08-19 21:40:21 +02:00
parent be8778b4eb
commit 7be9bb3ecc
6 changed files with 41 additions and 25 deletions
-8
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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)