From 6ad3d3f51950c2dbcf6a67e7540282e95959a358 Mon Sep 17 00:00:00 2001 From: Eurya0x13 Date: Thu, 26 Nov 2026 18:14:18 +0800 Subject: [PATCH] [Fix] (MG_Backend/DirectGLES): require raw RGBA8 for packed texture uploads - Check the shadow format before copying bytes into the staging texture. - Document the draw-batch scope of sampled-storage tracking. --- .../MG_Backend/DirectGLES/DrawTextureReads.h | 2 ++ .../DirectGLES/ManagersTextureSync.cpp | 18 +++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/MobileGL/MG_Backend/DirectGLES/DrawTextureReads.h b/MobileGL/MG_Backend/DirectGLES/DrawTextureReads.h index ed695f17..d3242bb9 100644 --- a/MobileGL/MG_Backend/DirectGLES/DrawTextureReads.h +++ b/MobileGL/MG_Backend/DirectGLES/DrawTextureReads.h @@ -14,6 +14,8 @@ namespace MobileGL::MG_Backend::DirectGLES::TextureImpl { // One instance per native context. Slot generations distinguish reused texture names, // and batch stamps let us discard a batch without walking its texture slots. + // This upload heuristic follows sampler reads from offscreen draws and the framebuffer + // changes observed by BindCurrentFBO. Compute dispatches do not record reads here. class DrawTextureReads { public: void BindFramebuffer(std::uint32_t framebuffer) { diff --git a/MobileGL/MG_Backend/DirectGLES/ManagersTextureSync.cpp b/MobileGL/MG_Backend/DirectGLES/ManagersTextureSync.cpp index 3be2ee15..0c436723 100644 --- a/MobileGL/MG_Backend/DirectGLES/ManagersTextureSync.cpp +++ b/MobileGL/MG_Backend/DirectGLES/ManagersTextureSync.cpp @@ -1640,9 +1640,10 @@ namespace MobileGL::MG_Backend::DirectGLES { } const auto mipmapCount = MGB_STORAGE_LEVELS(textureMipmapObject); + const auto storageFormat = MGB_STORAGE_FORMAT(textureMipmapObject); GLenum glInternalFormat, glType, glFormat; - TextureImpl::GenerateTextureFormatInfo(MGB_STORAGE_FORMAT(textureMipmapObject), &glInternalFormat, - &glFormat, &glType, targetInternal); + TextureImpl::GenerateTextureFormatInfo(storageFormat, &glInternalFormat, &glFormat, &glType, + targetInternal); // The storage this level is being written into was widened when it was minted // (see above), so the transfer pair has to describe the carrier here too - ES // requires glTexSubImage's `format` to match the storage's base internal @@ -1652,15 +1653,18 @@ namespace MobileGL::MG_Backend::DirectGLES { ScopedDefaultUnpackState unpackState; // Update sampled storage directly to avoid stalling the current offscreen batch on a PBO. const Bool useClientUnpack = stableStorage && WasTextureReadInDrawBatch(pushedRes); + // The staging page copies the shadow bytes as-is. Check the shadow and driver + // formats because a driver format can also be used for converted client data. + const Bool rawRgba8Copy = storageFormat == TextureInternalFormat::RGBA8 && + glInternalFormat == GL_RGBA8 && glFormat == GL_RGBA && + glType == GL_UNSIGNED_BYTE; // Pack the small writes across all dirty mip levels before their // per-level union boxes can pull in untouched atlas texels. The packed // copies write the destination on the GPU too, so sampled storage skips them. if (stableStorage && !useClientUnpack && !m_driverMayHoldGpuWrites && !m_packedUploadRejected && - !m_imageBindableStorageRequired && target == GL_TEXTURE_2D && - (glInternalFormat == GL_RGBA8 || glInternalFormat == GL_RGBA) && glFormat == GL_RGBA && - glType == GL_UNSIGNED_BYTE && pushedStorage != nullptr && uploadTargets.size() == 1 && - g_GLESFuncs.glCopyImageSubData && g_GLESFuncs.glTexStorage2D && - BufferImpl::UnpackRingAvailable()) { + !m_imageBindableStorageRequired && target == GL_TEXTURE_2D && rawRgba8Copy && + pushedStorage != nullptr && uploadTargets.size() == 1 && g_GLESFuncs.glCopyImageSubData && + g_GLESFuncs.glTexStorage2D && BufferImpl::UnpackRingAvailable()) { const auto result = TryPackedMipUpload(textureMipmapObject, pushedStorage, pushedRes, uploadTargets.front(), mipmapCount, m_backendTextureId); if (result == PackedUploadResult::Rejected) {