From bb816906a7078af4fc57ffd0ce0641b64b5b40db Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Sun, 20 Sep 2026 12:07:28 -0400 Subject: [PATCH] [Magma] resolve copy-image renderbuffer endpoints from wire storage --- .../DirectVulkan/Renderer/VulkanRenderer.cpp | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp index 2e3b4cf3..c2828439 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp @@ -10059,6 +10059,10 @@ void main() { } Uint CopyImageEndpointName(const CopyImageEndpoint& endpoint) { +#if MOBILEGL_BUILD_DISAGGREGATED + if (MG_Config::Transport != MG_Config::TransportMode::Monolith) + return endpoint.IsRenderbuffer() ? endpoint.RenderbufferHandle.Slot : endpoint.TextureHandle.Slot; +#endif if (endpoint.IsRenderbuffer()) return endpoint.Renderbuffer->GetExternalIndex(); return endpoint.Texture ? endpoint.Texture->GetExternalIndex() : 0u; } @@ -10071,6 +10075,7 @@ void main() { GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth) { #if MOBILEGL_BUILD_DISAGGREGATED const Bool wire = MG_Config::Transport != MG_Config::TransportMode::Monolith; + MG_Pipe::MGPipeHandle dstStorageHandle = dstEndpoint.TextureHandle; if (wire && HasPendingRecordedWork() && !FlushPendingCommands()) MagmaWireFatal("copy-image-flush"); #endif MOBILEGL_ASSERT(srcEndpoint.Exists() && dstEndpoint.Exists(), @@ -10124,8 +10129,13 @@ void main() { const auto resolveImage = [this](const CopyImageEndpoint& endpoint, CopyImageVkImage& out) { #if MOBILEGL_BUILD_DISAGGREGATED if (MG_Config::Transport != MG_Config::TransportMode::Monolith) { - auto* resource = m_textureManager->SyncTextureResourceByHandle(endpoint.TextureHandle); + const Bool renderbuffer = endpoint.IsRenderbuffer(); + // The same handle-keyed allocation used by wire FBO clear/draw/read. + // The legacy render-pass manager owns a different, frontend-keyed map. + auto* resource = m_textureManager->SyncTextureResourceByHandle( + renderbuffer ? endpoint.RenderbufferHandle : endpoint.TextureHandle, renderbuffer); if (!resource) MagmaWireFatal("copy-image-resource"); + out.isRenderbuffer = renderbuffer; out.image = resource->image; out.trackedLayout = &resource->layout; out.aspect = resource->aspect; @@ -10203,14 +10213,20 @@ void main() { // can index a subresource, exactly as at every other attachment boundary. #if MOBILEGL_BUILD_DISAGGREGATED if (wire) { - Uint32 srcMip = static_cast(srcLevel), srcLayer = static_cast(srcZ); - Uint32 dstMip = static_cast(dstLevel), dstLayer = static_cast(dstZ); - if (MG_Pipe::MGPipeHandleIsNull(m_textureManager->ResolveWireTextureStorage( - srcEndpoint.TextureHandle, srcMip, srcLayer)) || - MG_Pipe::MGPipeHandleIsNull(m_textureManager->ResolveWireTextureStorage( - dstEndpoint.TextureHandle, dstMip, dstLayer))) MagmaWireFatal("copy-image-view-record"); - srcLevel = static_cast(srcMip); srcZ = static_cast(srcLayer); - dstLevel = static_cast(dstMip); dstZ = static_cast(dstLayer); + const auto mapSubresource = [this](const CopyImageEndpoint& endpoint, GLint& mip, GLint& layer) { + if (endpoint.IsRenderbuffer()) { + if (mip != 0 || layer != 0) MagmaWireFatal("copy-image-renderbuffer-subresource"); + return endpoint.RenderbufferHandle; + } + Uint32 mappedMip = static_cast(mip), mappedLayer = static_cast(layer); + const auto storage = m_textureManager->ResolveWireTextureStorage( + endpoint.TextureHandle, mappedMip, mappedLayer); + if (MG_Pipe::MGPipeHandleIsNull(storage)) MagmaWireFatal("copy-image-view-record"); + mip = static_cast(mappedMip); layer = static_cast(mappedLayer); + return storage; + }; + (void)mapSubresource(srcEndpoint, srcLevel, srcZ); + dstStorageHandle = mapSubresource(dstEndpoint, dstLevel, dstZ); } #endif srcLevel = static_cast(ToStorageMipLevel(srcEndpoint.Texture.get(), srcLevel)); @@ -10432,7 +10448,9 @@ void main() { dstImage.image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ©Region); #if MOBILEGL_BUILD_DISAGGREGATED - if (wire) m_textureManager->MarkWireTextureGpuWritten(dstEndpoint.TextureHandle, + // The copy coordinates above are already storage-relative. Name that + // storage here too, so a texture view's offsets are not applied twice. + if (wire && !dstImage.isRenderbuffer) m_textureManager->MarkWireTextureGpuWritten(dstStorageHandle, dstMipLevel, dstSlices.BaseArrayLayer(), dstSlices.slicesAreDepth ? 1u : copySliceCount); #endif