From c03c4cb95ae386ff1afe00b5661ade4f22a71951 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 6 Feb 2021 19:10:46 +1000 Subject: [PATCH] GPU: Elide VRAM copies when they will have no effect Can provide a performance boost in most games because of the redundant copy they issue once a frame. --- src/core/gpu_commands.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/core/gpu_commands.cpp b/src/core/gpu_commands.cpp index 0cf03260a..fea325276 100644 --- a/src/core/gpu_commands.cpp +++ b/src/core/gpu_commands.cpp @@ -602,8 +602,15 @@ bool GPU::HandleCopyRectangleVRAMToVRAMCommand() Log_DebugPrintf("Copy rectangle from VRAM to VRAM src=(%u,%u), dst=(%u,%u), size=(%u,%u)", src_x, src_y, dst_x, dst_y, width, height); - FlushRender(); - CopyVRAM(src_x, src_y, dst_x, dst_y, width, height); + // Some VRAM copies aren't going to do anything. Most games seem to send a 2x2 VRAM copy at the end of a frame. + const bool skip_copy = + width == 0 || height == 0 || (src_x == dst_x && src_y == dst_y && !m_GPUSTAT.set_mask_while_drawing); + if (!skip_copy) + { + FlushRender(); + CopyVRAM(src_x, src_y, dst_x, dst_y, width, height); + } + m_stats.num_vram_copies++; AddCommandTicks(width * height * 2); EndCommand();