renderer_vulkan: Prefer immediate over mailbox present mode

This commit is contained in:
emufan4568
2022-10-19 20:37:42 +03:00
committed by GPUCode
parent 4868c361e7
commit 053221f155
2 changed files with 22 additions and 4 deletions

View File

@ -4,6 +4,7 @@
#include <algorithm> #include <algorithm>
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/microprofile.h"
#include "core/settings.h" #include "core/settings.h"
#include "video_core/renderer_vulkan/vk_instance.h" #include "video_core/renderer_vulkan/vk_instance.h"
#include "video_core/renderer_vulkan/vk_renderpass_cache.h" #include "video_core/renderer_vulkan/vk_renderpass_cache.h"
@ -112,11 +113,13 @@ void Swapchain::Create(u32 width, u32 height) {
// Wait for maximum of 1 second // Wait for maximum of 1 second
constexpr u64 ACQUIRE_TIMEOUT = 1000000000; constexpr u64 ACQUIRE_TIMEOUT = 1000000000;
MICROPROFILE_DEFINE(Vulkan_Acquire, "Vulkan", "Swapchain Acquire", MP_RGB(185, 66, 245));
void Swapchain::AcquireNextImage(vk::Semaphore signal_acquired) { void Swapchain::AcquireNextImage(vk::Semaphore signal_acquired) {
if (NeedsRecreation()) [[unlikely]] { if (NeedsRecreation()) [[unlikely]] {
return; return;
} }
MICROPROFILE_SCOPE(Vulkan_Acquire);
vk::Device device = instance.GetDevice(); vk::Device device = instance.GetDevice();
vk::Result result = device.acquireNextImageKHR(swapchain, ACQUIRE_TIMEOUT, signal_acquired, vk::Result result = device.acquireNextImageKHR(swapchain, ACQUIRE_TIMEOUT, signal_acquired,
VK_NULL_HANDLE, &current_image); VK_NULL_HANDLE, &current_image);
@ -135,11 +138,13 @@ void Swapchain::AcquireNextImage(vk::Semaphore signal_acquired) {
} }
} }
MICROPROFILE_DEFINE(Vulkan_Present, "Vulkan", "Swapchain Present", MP_RGB(66, 185, 245));
void Swapchain::Present(vk::Semaphore wait_for_present) { void Swapchain::Present(vk::Semaphore wait_for_present) {
if (NeedsRecreation()) [[unlikely]] { if (NeedsRecreation()) [[unlikely]] {
return; return;
} }
MICROPROFILE_SCOPE(Vulkan_Present);
const vk::PresentInfoKHR present_info = {.waitSemaphoreCount = 1, const vk::PresentInfoKHR present_info = {.waitSemaphoreCount = 1,
.pWaitSemaphores = &wait_for_present, .pWaitSemaphores = &wait_for_present,
.swapchainCount = 1, .swapchainCount = 1,
@ -185,11 +190,18 @@ void Swapchain::Configure(u32 width, u32 height) {
// FIFO is guaranteed by the Vulkan standard to be available // FIFO is guaranteed by the Vulkan standard to be available
present_mode = vk::PresentModeKHR::eFifo; present_mode = vk::PresentModeKHR::eFifo;
if (!Settings::values.use_vsync_new) { if (!Settings::values.use_vsync_new) {
auto iter = std::ranges::find_if( const auto FindMode = [&modes](vk::PresentModeKHR requested) {
modes, [](vk::PresentModeKHR mode) { return vk::PresentModeKHR::eMailbox == mode; }); auto it =
std::find_if(modes.begin(), modes.end(),
[&requested](vk::PresentModeKHR mode) { return mode == requested; });
// Prefer Mailbox when vsync is disabled for lowest latency return it != modes.end();
if (iter != modes.end()) { };
// Prefer Immediate when vsync is disabled for fastest acquire
if (FindMode(vk::PresentModeKHR::eImmediate)) {
present_mode = vk::PresentModeKHR::eImmediate;
} else if (FindMode(vk::PresentModeKHR::eMailbox)) {
present_mode = vk::PresentModeKHR::eMailbox; present_mode = vk::PresentModeKHR::eMailbox;
} }
} }

View File

@ -4,6 +4,7 @@
#include "common/assert.h" #include "common/assert.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "common/microprofile.h"
#include "video_core/renderer_vulkan/renderer_vulkan.h" #include "video_core/renderer_vulkan/renderer_vulkan.h"
#include "video_core/renderer_vulkan/vk_instance.h" #include "video_core/renderer_vulkan/vk_instance.h"
#include "video_core/renderer_vulkan/vk_task_scheduler.h" #include "video_core/renderer_vulkan/vk_task_scheduler.h"
@ -86,12 +87,14 @@ TaskScheduler::~TaskScheduler() {
device.destroyCommandPool(command_pool); device.destroyCommandPool(command_pool);
} }
MICROPROFILE_DEFINE(Vulkan_Synchronize, "Vulkan", "Scheduler Synchronize", MP_RGB(100, 52, 235));
void TaskScheduler::Synchronize(u32 slot) { void TaskScheduler::Synchronize(u32 slot) {
const auto& command = commands[slot]; const auto& command = commands[slot];
vk::Device device = instance.GetDevice(); vk::Device device = instance.GetDevice();
const u64 completed_counter = GetFenceCounter(); const u64 completed_counter = GetFenceCounter();
if (command.fence_counter > completed_counter) { if (command.fence_counter > completed_counter) {
MICROPROFILE_SCOPE(Vulkan_Synchronize);
if (instance.IsTimelineSemaphoreSupported()) { if (instance.IsTimelineSemaphoreSupported()) {
const vk::SemaphoreWaitInfo wait_info = { const vk::SemaphoreWaitInfo wait_info = {
.semaphoreCount = 1, .pSemaphores = &timeline, .pValues = &command.fence_counter}; .semaphoreCount = 1, .pSemaphores = &timeline, .pValues = &command.fence_counter};
@ -113,6 +116,7 @@ void TaskScheduler::Synchronize(u32 slot) {
device.resetDescriptorPool(command.descriptor_pool); device.resetDescriptorPool(command.descriptor_pool);
} }
MICROPROFILE_DEFINE(Vulkan_Submit, "Vulkan", "Scheduler Queue Submit", MP_RGB(66, 245, 170));
void TaskScheduler::Submit(SubmitMode mode) { void TaskScheduler::Submit(SubmitMode mode) {
if (False(mode & SubmitMode::Shutdown)) { if (False(mode & SubmitMode::Shutdown)) {
renderer.FlushBuffers(); renderer.FlushBuffers();
@ -134,6 +138,8 @@ void TaskScheduler::Submit(SubmitMode mode) {
command_buffers[command_buffer_count++] = command.render_command_buffer; command_buffers[command_buffer_count++] = command.render_command_buffer;
const auto QueueSubmit = [this](const vk::SubmitInfo& info, vk::Fence fence) { const auto QueueSubmit = [this](const vk::SubmitInfo& info, vk::Fence fence) {
MICROPROFILE_SCOPE(Vulkan_Submit);
try { try {
vk::Queue queue = instance.GetGraphicsQueue(); vk::Queue queue = instance.GetGraphicsQueue();
queue.submit(info, fence); queue.submit(info, fence);