From 553eb86d31f7d4f7f09ee4c5d2e09578715bda03 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Wed, 7 Oct 2026 16:26:07 -0400 Subject: [PATCH] [Perf] (Magma): texture level uploads stop waiting for the GPU to drain; queue order and the upload barrier already order them (rd12 monolith 70.4 -> 83.4, openra 367 -> 745 fps). --- .../DirectVulkan/Renderer/VkTextureManager.cpp | 2 +- .../MG_Backend/DirectVulkan/Renderer/VulkanRenderer.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp index cb42f89e..b17d23e7 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp @@ -1464,7 +1464,7 @@ namespace MobileGL::MG_Backend::DirectVulkan { // Submit older renderer work before adding the new bytes to the batch, // otherwise Draw(old T), TexSubImage(T), Draw(new T) can upload before // the first draw. A clean texture never reaches this submission boundary. - if (pVulkanRenderer && !pVulkanRenderer->FlushWirePendingCommandsForTextureUpdate()) { + if (pVulkanRenderer && !pVulkanRenderer->FlushWirePendingCommandsForTextureUpload()) { MGL_WIRE_DECLINE_AT(UploadFlushFailed, "texture {slot=%u, gen=%u}: earlier renderer work could not be submitted before " "its upload batch", diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.h b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.h index ff6cf2f8..b6386994 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.h +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.h @@ -155,6 +155,16 @@ namespace MobileGL::MG_Backend::DirectVulkan { if (HasPendingRecordedWork() && !FlushPendingCommands()) return false; return WaitForSubmitsUpTo(m_submitCounter, UINT64_MAX); } + // The level-upload arm's half of the above, WITHOUT the CPU wait. Its bytes go through a + // staging buffer into an upload batch that is submitted on this same queue after this + // flush, and the batch's first barrier takes its source scope from the image's tracked + // layout (ALL_COMMANDS for GENERAL, the sampled-read stages for a read-only layout), so + // queue submission order already puts every earlier draw's access to the old texels + // ahead of the copy. The preserve arm keeps the wait: it retires the old image. + // (rd12 Magma: the wait was ~1.8 ms/frame of fence stall, one per lightmap update.) + Bool FlushWirePendingCommandsForTextureUpload() { + return !HasPendingRecordedWork() || FlushPendingCommands(); + } // P7 wave 2 package B3: the submission that will carry whatever is recorded NEXT. // RetireWireObjects (WireDraw.inc) already tags future objects with exactly this, and // for the same reason: a draw being set up now is not in any submission yet, so the