[MG_Backend] (Disaggregated): P5f fm - retain native storage usage for texture views

This commit is contained in:
2026-09-19 23:06:55 -04:00
parent 60bc3ca113
commit 1091846651
3 changed files with 19 additions and 11 deletions
@@ -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<Uint8>(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;
}
@@ -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.
@@ -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<VkAttachmentDescription> attachments;
Vector<VkImageView> views;
Vector<VkAttachmentReference> 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;