Skip to content

Commit

Permalink
present_mode: account for app requested mode
Browse files Browse the repository at this point in the history
  • Loading branch information
flightlessmango committed Feb 5, 2024
1 parent 2bc323b commit 0ab4c25
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/hud_elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,20 @@ class HudElements{
{VK_PRESENT_MODE_FIFO_KHR, "FIFO"},
{VK_PRESENT_MODE_FIFO_RELAXED_KHR, "FIFO Relaxed"},
{VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR, "DEMAND"},
{VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR, "ONTINUOUS"}
{VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR, "CONTINUOUS"}
};

VkPresentModeKHR cur_present_mode;

std::string get_present_mode(){
if (is_vulkan)
return presentModeMap[presentModes[params->vsync]];
return presentModeMap[cur_present_mode];
// TODO: the opengl side is probably not as solid.
// But it also might not be possible to figure out if vsync
// is on or off unless we specify it.
else
return params->gl_vsync == 0 ? "OFF" : "ON";

}
};

Expand Down
17 changes: 10 additions & 7 deletions src/vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1516,10 +1516,14 @@ static VkResult overlay_CreateSwapchainKHR(
createInfo.imageUsage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;

struct device_data *device_data = FIND(struct device_data, device);
auto params = device_data->instance->params;

VkPresentModeKHR presentMode = HUDElements.presentModes[device_data->instance->params.vsync];
if (device_data->instance->params.vsync < 4)
createInfo.presentMode = presentMode;
if (device_data->instance->params.vsync < 4) {
HUDElements.cur_present_mode = HUDElements.presentModes[params.vsync];
createInfo.presentMode = HUDElements.cur_present_mode;
} else {
HUDElements.cur_present_mode = createInfo.presentMode;
}

struct instance_data *instance_data =
FIND(struct instance_data, device_data->physical_device);
Expand All @@ -1533,11 +1537,10 @@ static VkResult overlay_CreateSwapchainKHR(
VkResult result = fpGetPhysicalDeviceSurfacePresentModesKHR(device_data->physical_device, pCreateInfo->surface, &presentModeCount, presentModes.data());

if (result == VK_SUCCESS) {
if (IsPresentModeSupported(HUDElements.presentModes[device_data->instance->params.vsync], presentModes))
SPDLOG_DEBUG("Present mode: {}", HUDElements.get_present_mode());
if (IsPresentModeSupported(HUDElements.cur_present_mode, presentModes))
SPDLOG_DEBUG("Present mode: {}", HUDElements.presentModeMap[HUDElements.cur_present_mode]);
else {
SPDLOG_DEBUG("Present mode is not supported: {}", HUDElements.get_present_mode());
device_data->instance->params.vsync = 3;
SPDLOG_DEBUG("Present mode is not supported: {}", HUDElements.presentModeMap[HUDElements.cur_present_mode]);
}
}
}
Expand Down

0 comments on commit 0ab4c25

Please sign in to comment.