From 1091846651e406d6422d38c3a6e69331a3c62db6 Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Sat, 19 Sep 2026 23:06:55 -0400 Subject: [PATCH] [MG_Backend] (Disaggregated): P5f fm - retain native storage usage for texture views --- .../DirectVulkan/Renderer/VkTextureManager.cpp | 14 ++++++++------ .../DirectVulkan/Renderer/VkTextureManager.h | 6 ++++-- .../MG_Backend/DirectVulkan/Renderer/WireDraw.inc | 10 +++++++--- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp index 39f972ac..89a75724 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.cpp @@ -2008,7 +2008,7 @@ namespace MobileGL::MG_Backend::DirectVulkan { } Bool VkTextureManager::SyncWireTextureShape(const MG_Pipe::MGPipeResourceRecord& record, - TextureResource& resource) { + TextureResource& resource, Bool requireStorage) { const MG_Pipe::MGPResourceDesc& desc = record.Desc; if (desc.StorageKind != static_cast(TextureStorageType::Mipmap)) { MGLOG_W_ONCE("Magma wire texture {slot=%u, gen=%u}: buffer-backed textures are not migrated; declined", @@ -2072,7 +2072,8 @@ namespace MobileGL::MG_Backend::DirectVulkan { vkGetPhysicalDeviceFormatProperties(m_physicalDevice, format, &formatProperties); // The descriptor's sticky bind mask carries the image-unit hint, so the image is born // with STORAGE usage and no re-mint ever pulls texels back (TextureEmit.h D-A3). - const Bool markedAsStorageImage = (desc.BindMask & MG_Pipe::kMGPipeBindShaderImage) != 0; + const Bool markedAsStorageImage = requireStorage || resource.storageUsageResolved || + (desc.BindMask & MG_Pipe::kMGPipeBindShaderImage) != 0; const Bool storageImageCapable = !isMultisample && (aspect & VK_IMAGE_ASPECT_COLOR_BIT) != 0 && (formatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0; @@ -2570,7 +2571,7 @@ namespace MobileGL::MG_Backend::DirectVulkan { } VkTextureManager::TextureResource* VkTextureManager::SyncTextureResourceByHandle( - MG_Pipe::MGPipeHandle handle, Bool renderbuffer) { + MG_Pipe::MGPipeHandle handle, Bool renderbuffer, Bool requireStorage) { MOBILEGL_ASSERT(m_device != VK_NULL_HANDLE, "SyncTextureResourceByHandle: m_device == VK_NULL_HANDLE"); if (MG_Pipe::MGPipeHandleIsNull(handle)) { return nullptr; @@ -2582,7 +2583,7 @@ namespace MobileGL::MG_Backend::DirectVulkan { const auto storage = ResolveWireTextureStorage(handle, level, layer, &viewFormat); if (MG_Pipe::MGPipeHandleIsNull(storage)) return nullptr; if (storage != handle) { - auto* resource = SyncTextureResourceByHandle(storage); + auto* resource = SyncTextureResourceByHandle(storage, false, requireStorage); if (!resource) return nullptr; if (viewFormat != resource->format && ((resource->imageCreateFlags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT) == 0 || @@ -2615,15 +2616,16 @@ namespace MobileGL::MG_Backend::DirectVulkan { (void)inserted; TextureResource& resource = it->second; if (resource.image != VK_NULL_HANDLE && resource.syncedWireSerial == record.Serial && - record.PendingUploads.empty()) { + record.PendingUploads.empty() && (!requireStorage || resource.storageUsageResolved)) { return &resource; } - if (!SyncWireTextureShape(record, resource)) { + if (!SyncWireTextureShape(record, resource, requireStorage)) { return nullptr; } if (!renderbuffer && !UploadPendingWireLevels(handle, record, resource)) { return nullptr; } + if (requireStorage && (resource.usageFlags & VK_IMAGE_USAGE_STORAGE_BIT) == 0) return nullptr; resource.syncedWireSerial = record.Serial; return &resource; } diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.h b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.h index 6b5e4543..0621b10c 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.h +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VkTextureManager.h @@ -553,7 +553,8 @@ public: // a NAMESPACE THE FRONTEND-KEYED m_textureResources NEVER MEETS, so a recycled {slot, gen} // can never inherit its predecessor's image. Texture views resolve the storage owner from // Desc.ViewOf and the window from ViewCso; buffer-backed textures remain P7's buffer arm. - TextureResource* SyncTextureResourceByHandle(MG_Pipe::MGPipeHandle handle, Bool renderbuffer = false); + TextureResource* SyncTextureResourceByHandle(MG_Pipe::MGPipeHandle handle, Bool renderbuffer = false, + Bool requireStorage = false); // Map a texture/view-relative subresource to its live storage owner. layerCount, when // supplied, receives the number of accessible layers starting at the input layer. // viewFormat is UNDEFINED for an ordinary texture, or the outer view's format. @@ -733,7 +734,8 @@ private: // descriptor (create / recreate / compatibility), then the pending-upload walk against the // server's staged store. UploadPendingWireLevels mutates the applier's record (consumed // entries are dropped), which is why the record is a non-const reference. - Bool SyncWireTextureShape(const MG_Pipe::MGPipeResourceRecord& record, TextureResource& resource); + Bool SyncWireTextureShape(const MG_Pipe::MGPipeResourceRecord& record, TextureResource& resource, + Bool requireStorage); Bool UploadPendingWireLevels(MG_Pipe::MGPipeHandle handle, MG_Pipe::MGPipeResourceRecord& record, TextureResource& resource); // The handle-keyed twin of m_textureResources, keyed by StagedTextureStore::KeyForHandle. diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/WireDraw.inc b/MobileGL/MG_Backend/DirectVulkan/Renderer/WireDraw.inc index 846a1b8f..b05e9252 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/WireDraw.inc +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/WireDraw.inc @@ -57,6 +57,13 @@ WireBufferLegacyFatal(); } + if (!frame.isCommandRecording) m_frameContext.BeginCommandRecording(); + // Descriptor resolution can upgrade a view's root image to STORAGE usage. + // Resolve it before constructing framebuffer views so both roles of that image + // name the same allocation even on its first storage-image use. + if (!m_uniformManager->BindProgramUniformBuffers(frame.commandBuffer, program, programObj, + m_frameContext.GetCurrentFrameIndex(), VK_PIPELINE_BIND_POINT_GRAPHICS)) return false; + Vector attachments; Vector views; Vector colors; @@ -146,9 +153,6 @@ VertexInputStateFactory::BackendVertexInputState input{}; const auto pipeline = GetOrCreatePipelineWithInput(mode, program, programObj, flags, input, pass, false); if (pipeline == VK_NULL_HANDLE) return false; - if (!frame.isCommandRecording) m_frameContext.BeginCommandRecording(); - if (!m_uniformManager->BindProgramUniformBuffers(frame.commandBuffer, program, programObj, - m_frameContext.GetCurrentFrameIndex(), VK_PIPELINE_BIND_POINT_GRAPHICS)) return false; Uint32 binding = 0; for (Uint32 location = 0; location < kMaxVertexAttribs; ++location) { if (!(programObj.activeVertexInputLocationMask & (1u << location))) continue;