early-access version 3552
This commit is contained in:
@@ -88,7 +88,7 @@ RendererVulkan::RendererVulkan(Core::TelemetrySession& telemetry_session_,
|
||||
instance(CreateInstance(library, dld, VK_API_VERSION_1_1, render_window.GetWindowInfo().type,
|
||||
Settings::values.renderer_debug.GetValue())),
|
||||
debug_callback(Settings::values.renderer_debug ? CreateDebugCallback(instance) : nullptr),
|
||||
surface(CreateSurface(instance, render_window.GetWindowInfo())),
|
||||
surface(CreateSurface(instance, render_window)),
|
||||
device(CreateDevice(instance, dld, *surface)), memory_allocator(device, false),
|
||||
state_tracker(), scheduler(device, state_tracker),
|
||||
swapchain(*surface, device, scheduler, render_window.GetFramebufferLayout().width,
|
||||
|
||||
@@ -502,6 +502,29 @@ bool RasterizerVulkan::MustFlushRegion(VAddr addr, u64 size, VideoCommon::CacheT
|
||||
return false;
|
||||
}
|
||||
|
||||
VideoCore::RasterizerDownloadArea RasterizerVulkan::GetFlushArea(VAddr addr, u64 size) {
|
||||
{
|
||||
std::scoped_lock lock{texture_cache.mutex};
|
||||
auto area = texture_cache.GetFlushArea(addr, size);
|
||||
if (area) {
|
||||
return *area;
|
||||
}
|
||||
}
|
||||
{
|
||||
std::scoped_lock lock{buffer_cache.mutex};
|
||||
auto area = buffer_cache.GetFlushArea(addr, size);
|
||||
if (area) {
|
||||
return *area;
|
||||
}
|
||||
}
|
||||
VideoCore::RasterizerDownloadArea new_area{
|
||||
.start_address = Common::AlignDown(addr, Core::Memory::YUZU_PAGESIZE),
|
||||
.end_address = Common::AlignUp(addr + size, Core::Memory::YUZU_PAGESIZE),
|
||||
.preemtive = true,
|
||||
};
|
||||
return new_area;
|
||||
}
|
||||
|
||||
void RasterizerVulkan::InvalidateRegion(VAddr addr, u64 size, VideoCommon::CacheType which) {
|
||||
if (addr == 0 || size == 0) {
|
||||
return;
|
||||
@@ -598,7 +621,7 @@ void RasterizerVulkan::SignalSyncPoint(u32 value) {
|
||||
}
|
||||
|
||||
void RasterizerVulkan::SignalReference() {
|
||||
fence_manager.SignalOrdering();
|
||||
fence_manager.SignalReference();
|
||||
}
|
||||
|
||||
void RasterizerVulkan::ReleaseFences() {
|
||||
@@ -631,7 +654,7 @@ void RasterizerVulkan::WaitForIdle() {
|
||||
cmdbuf.SetEvent(event, flags);
|
||||
cmdbuf.WaitEvents(event, flags, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, {}, {}, {});
|
||||
});
|
||||
SignalReference();
|
||||
fence_manager.SignalOrdering();
|
||||
}
|
||||
|
||||
void RasterizerVulkan::FragmentBarrier() {
|
||||
|
||||
@@ -92,6 +92,7 @@ public:
|
||||
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
|
||||
bool MustFlushRegion(VAddr addr, u64 size,
|
||||
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
|
||||
VideoCore::RasterizerDownloadArea GetFlushArea(VAddr addr, u64 size) override;
|
||||
void InvalidateRegion(VAddr addr, u64 size,
|
||||
VideoCommon::CacheType which = VideoCommon::CacheType::All) override;
|
||||
void InnerInvalidation(std::span<const std::pair<VAddr, std::size_t>> sequences) override;
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include "video_core/renderer_vulkan/vk_swapchain.h"
|
||||
#include "video_core/vulkan_common/vulkan_device.h"
|
||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||
#include "vulkan/vulkan_core.h"
|
||||
|
||||
namespace Vulkan {
|
||||
|
||||
@@ -34,47 +33,23 @@ VkSurfaceFormatKHR ChooseSwapSurfaceFormat(vk::Span<VkSurfaceFormatKHR> formats)
|
||||
return found != formats.end() ? *found : formats[0];
|
||||
}
|
||||
|
||||
static constexpr VkPresentModeKHR ChooseSwapPresentMode(bool has_imm, bool has_mailbox,
|
||||
bool has_fifo_relaxed) {
|
||||
// Mailbox doesn't lock the application like FIFO (vsync)
|
||||
// FIFO present mode locks the framerate to the monitor's refresh rate
|
||||
Settings::VSyncMode setting = [has_imm, has_mailbox]() {
|
||||
// Choose Mailbox or Immediate if unlocked and those modes are supported
|
||||
const auto mode = Settings::values.vsync_mode.GetValue();
|
||||
if (Settings::values.use_speed_limit.GetValue()) {
|
||||
return mode;
|
||||
}
|
||||
switch (mode) {
|
||||
case Settings::VSyncMode::FIFO:
|
||||
case Settings::VSyncMode::FIFORelaxed:
|
||||
if (has_mailbox) {
|
||||
return Settings::VSyncMode::Mailbox;
|
||||
} else if (has_imm) {
|
||||
return Settings::VSyncMode::Immediate;
|
||||
}
|
||||
[[fallthrough]];
|
||||
default:
|
||||
return mode;
|
||||
}
|
||||
}();
|
||||
if ((setting == Settings::VSyncMode::Mailbox && !has_mailbox) ||
|
||||
(setting == Settings::VSyncMode::Immediate && !has_imm) ||
|
||||
(setting == Settings::VSyncMode::FIFORelaxed && !has_fifo_relaxed)) {
|
||||
setting = Settings::VSyncMode::FIFO;
|
||||
}
|
||||
|
||||
switch (setting) {
|
||||
case Settings::VSyncMode::Immediate:
|
||||
return VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||
case Settings::VSyncMode::Mailbox:
|
||||
VkPresentModeKHR ChooseSwapPresentMode(vk::Span<VkPresentModeKHR> modes) {
|
||||
// Mailbox (triple buffering) doesn't lock the application like fifo (vsync),
|
||||
// prefer it if vsync option is not selected
|
||||
const auto found_mailbox = std::find(modes.begin(), modes.end(), VK_PRESENT_MODE_MAILBOX_KHR);
|
||||
if (Settings::values.fullscreen_mode.GetValue() == Settings::FullscreenMode::Borderless &&
|
||||
found_mailbox != modes.end() && !Settings::values.use_vsync.GetValue()) {
|
||||
return VK_PRESENT_MODE_MAILBOX_KHR;
|
||||
case Settings::VSyncMode::FIFO:
|
||||
return VK_PRESENT_MODE_FIFO_KHR;
|
||||
case Settings::VSyncMode::FIFORelaxed:
|
||||
return VK_PRESENT_MODE_FIFO_RELAXED_KHR;
|
||||
default:
|
||||
return VK_PRESENT_MODE_FIFO_KHR;
|
||||
}
|
||||
if (!Settings::values.use_speed_limit.GetValue()) {
|
||||
// FIFO present mode locks the framerate to the monitor's refresh rate,
|
||||
// Find an alternative to surpass this limitation if FPS is unlocked.
|
||||
const auto found_imm = std::find(modes.begin(), modes.end(), VK_PRESENT_MODE_IMMEDIATE_KHR);
|
||||
if (found_imm != modes.end()) {
|
||||
return VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||
}
|
||||
}
|
||||
return VK_PRESENT_MODE_FIFO_KHR;
|
||||
}
|
||||
|
||||
VkExtent2D ChooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities, u32 width, u32 height) {
|
||||
@@ -192,17 +167,11 @@ void Swapchain::Present(VkSemaphore render_semaphore) {
|
||||
void Swapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, bool srgb) {
|
||||
const auto physical_device{device.GetPhysical()};
|
||||
const auto formats{physical_device.GetSurfaceFormatsKHR(surface)};
|
||||
const auto present_modes = physical_device.GetSurfacePresentModesKHR(surface);
|
||||
has_mailbox = std::find(present_modes.begin(), present_modes.end(),
|
||||
VK_PRESENT_MODE_MAILBOX_KHR) != present_modes.end();
|
||||
has_imm = std::find(present_modes.begin(), present_modes.end(),
|
||||
VK_PRESENT_MODE_IMMEDIATE_KHR) != present_modes.end();
|
||||
has_fifo_relaxed = std::find(present_modes.begin(), present_modes.end(),
|
||||
VK_PRESENT_MODE_FIFO_RELAXED_KHR) != present_modes.end();
|
||||
const auto present_modes{physical_device.GetSurfacePresentModesKHR(surface)};
|
||||
|
||||
const VkCompositeAlphaFlagBitsKHR alpha_flags{ChooseAlphaFlags(capabilities)};
|
||||
surface_format = ChooseSwapSurfaceFormat(formats);
|
||||
present_mode = ChooseSwapPresentMode(has_imm, has_mailbox, has_fifo_relaxed);
|
||||
present_mode = ChooseSwapPresentMode(present_modes);
|
||||
|
||||
u32 requested_image_count{capabilities.minImageCount + 1};
|
||||
// Ensure Triple buffering if possible.
|
||||
@@ -263,6 +232,7 @@ void Swapchain::CreateSwapchain(const VkSurfaceCapabilitiesKHR& capabilities, bo
|
||||
|
||||
extent = swapchain_ci.imageExtent;
|
||||
current_srgb = srgb;
|
||||
current_fps_unlocked = !Settings::values.use_speed_limit.GetValue();
|
||||
|
||||
images = swapchain.GetImages();
|
||||
image_count = static_cast<u32>(images.size());
|
||||
@@ -284,9 +254,14 @@ void Swapchain::Destroy() {
|
||||
swapchain.reset();
|
||||
}
|
||||
|
||||
bool Swapchain::HasFpsUnlockChanged() const {
|
||||
return current_fps_unlocked != !Settings::values.use_speed_limit.GetValue();
|
||||
}
|
||||
|
||||
bool Swapchain::NeedsPresentModeUpdate() const {
|
||||
const auto requested_mode = ChooseSwapPresentMode(has_imm, has_mailbox, has_fifo_relaxed);
|
||||
return present_mode != requested_mode;
|
||||
// Mailbox present mode is the ideal for all scenarios. If it is not available,
|
||||
// A different present mode is needed to support unlocked FPS above the monitor's refresh rate.
|
||||
return present_mode != VK_PRESENT_MODE_MAILBOX_KHR && HasFpsUnlockChanged();
|
||||
}
|
||||
|
||||
} // namespace Vulkan
|
||||
|
||||
@@ -116,6 +116,8 @@ private:
|
||||
|
||||
void Destroy();
|
||||
|
||||
bool HasFpsUnlockChanged() const;
|
||||
|
||||
bool NeedsPresentModeUpdate() const;
|
||||
|
||||
const VkSurfaceKHR surface;
|
||||
@@ -140,11 +142,9 @@ private:
|
||||
VkExtent2D extent{};
|
||||
VkPresentModeKHR present_mode{};
|
||||
VkSurfaceFormatKHR surface_format{};
|
||||
bool has_imm{false};
|
||||
bool has_mailbox{false};
|
||||
bool has_fifo_relaxed{false};
|
||||
|
||||
bool current_srgb{};
|
||||
bool current_fps_unlocked{};
|
||||
bool is_outdated{};
|
||||
bool is_suboptimal{};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user