vk_swapchain: Avoid recreating the swapchain on each frame
Recreate only when requested (or sRGB is changed) instead of tracking the frontend's size. That size is still used as a hint.
This commit is contained in:
parent
22f0c4f002
commit
d26271b014
|
@ -97,19 +97,14 @@ RendererVulkan::RendererVulkan(Core::TelemetrySession& telemetry_session_,
|
||||||
Core::Frontend::EmuWindow& emu_window,
|
Core::Frontend::EmuWindow& emu_window,
|
||||||
Core::Memory::Memory& cpu_memory_, Tegra::GPU& gpu_,
|
Core::Memory::Memory& cpu_memory_, Tegra::GPU& gpu_,
|
||||||
std::unique_ptr<Core::Frontend::GraphicsContext> context_) try
|
std::unique_ptr<Core::Frontend::GraphicsContext> context_) try
|
||||||
: RendererBase(emu_window, std::move(context_)),
|
: RendererBase(emu_window, std::move(context_)), telemetry_session(telemetry_session_),
|
||||||
telemetry_session(telemetry_session_),
|
cpu_memory(cpu_memory_), gpu(gpu_), library(OpenLibrary()),
|
||||||
cpu_memory(cpu_memory_),
|
|
||||||
gpu(gpu_),
|
|
||||||
library(OpenLibrary()),
|
|
||||||
instance(CreateInstance(library, dld, VK_API_VERSION_1_1, render_window.GetWindowInfo().type,
|
instance(CreateInstance(library, dld, VK_API_VERSION_1_1, render_window.GetWindowInfo().type,
|
||||||
true, Settings::values.renderer_debug.GetValue())),
|
true, Settings::values.renderer_debug.GetValue())),
|
||||||
debug_callback(Settings::values.renderer_debug ? CreateDebugCallback(instance) : nullptr),
|
debug_callback(Settings::values.renderer_debug ? CreateDebugCallback(instance) : nullptr),
|
||||||
surface(CreateSurface(instance, render_window)),
|
surface(CreateSurface(instance, render_window)),
|
||||||
device(CreateDevice(instance, dld, *surface)),
|
device(CreateDevice(instance, dld, *surface)), memory_allocator(device, false),
|
||||||
memory_allocator(device, false),
|
state_tracker(gpu), scheduler(device, state_tracker),
|
||||||
state_tracker(gpu),
|
|
||||||
scheduler(device, state_tracker),
|
|
||||||
swapchain(*surface, device, scheduler, render_window.GetFramebufferLayout().width,
|
swapchain(*surface, device, scheduler, render_window.GetFramebufferLayout().width,
|
||||||
render_window.GetFramebufferLayout().height, false),
|
render_window.GetFramebufferLayout().height, false),
|
||||||
blit_screen(cpu_memory, render_window, device, memory_allocator, swapchain, scheduler,
|
blit_screen(cpu_memory, render_window, device, memory_allocator, swapchain, scheduler,
|
||||||
|
@ -139,17 +134,16 @@ void RendererVulkan::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
|
||||||
rasterizer.AccelerateDisplay(*framebuffer, framebuffer_addr, framebuffer->stride);
|
rasterizer.AccelerateDisplay(*framebuffer, framebuffer_addr, framebuffer->stride);
|
||||||
const bool is_srgb = use_accelerated && screen_info.is_srgb;
|
const bool is_srgb = use_accelerated && screen_info.is_srgb;
|
||||||
|
|
||||||
const Layout::FramebufferLayout layout = render_window.GetFramebufferLayout();
|
|
||||||
bool has_been_recreated = false;
|
bool has_been_recreated = false;
|
||||||
const auto recreate_swapchain = [&] {
|
const auto recreate_swapchain = [&] {
|
||||||
if (!has_been_recreated) {
|
if (!has_been_recreated) {
|
||||||
has_been_recreated = true;
|
has_been_recreated = true;
|
||||||
scheduler.WaitWorker();
|
scheduler.WaitWorker();
|
||||||
}
|
}
|
||||||
|
const Layout::FramebufferLayout layout = render_window.GetFramebufferLayout();
|
||||||
swapchain.Create(layout.width, layout.height, is_srgb);
|
swapchain.Create(layout.width, layout.height, is_srgb);
|
||||||
};
|
};
|
||||||
if (swapchain.NeedsRecreate() ||
|
if (swapchain.NeedsRecreate() || swapchain.HasColorSpaceChanged(is_srgb)) {
|
||||||
swapchain.HasDifferentLayout(layout.width, layout.height, is_srgb)) {
|
|
||||||
recreate_swapchain();
|
recreate_swapchain();
|
||||||
}
|
}
|
||||||
bool needs_recreate;
|
bool needs_recreate;
|
||||||
|
|
|
@ -33,9 +33,9 @@ public:
|
||||||
/// Presents the rendered image to the swapchain.
|
/// Presents the rendered image to the swapchain.
|
||||||
void Present(VkSemaphore render_semaphore);
|
void Present(VkSemaphore render_semaphore);
|
||||||
|
|
||||||
/// Returns true when the framebuffer layout has changed.
|
/// Returns true when the color space has changed.
|
||||||
bool HasDifferentLayout(u32 width, u32 height, bool is_srgb) const {
|
bool HasColorSpaceChanged(bool is_srgb) const {
|
||||||
return extent.width != width || extent.height != height || current_srgb != is_srgb;
|
return current_srgb != is_srgb;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true when the image has to be recreated.
|
/// Returns true when the image has to be recreated.
|
||||||
|
|
Loading…
Reference in New Issue