From 926e54e28c5b47b1385448b742f7b2c43fcfd58b Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Thu, 26 Nov 2026 04:56:56 -0400 Subject: [PATCH] [Refactor] (MG_Backend/DirectGLES, MG_Util/Texture): move the upload packing helpers to MG_Util --- .../DirectGLES/ManagersTextureSync.cpp | 25 ++++++++++--------- .../Texture}/PackedTextureUpload.h | 6 ++--- .../Texture}/TextureUploadBoxes.h | 8 +++--- 3 files changed, 20 insertions(+), 19 deletions(-) rename MobileGL/{MG_Backend/DirectGLES => MG_Util/Texture}/PackedTextureUpload.h (96%) rename MobileGL/{MG_Backend/DirectGLES => MG_Util/Texture}/TextureUploadBoxes.h (89%) diff --git a/MobileGL/MG_Backend/DirectGLES/ManagersTextureSync.cpp b/MobileGL/MG_Backend/DirectGLES/ManagersTextureSync.cpp index 295437a7..3be2ee15 100644 --- a/MobileGL/MG_Backend/DirectGLES/ManagersTextureSync.cpp +++ b/MobileGL/MG_Backend/DirectGLES/ManagersTextureSync.cpp @@ -8,8 +8,8 @@ #include "ManagersInternal.h" #include "DirectGLESInternal.h" -#include "PackedTextureUpload.h" -#include "TextureUploadBoxes.h" +#include +#include namespace MobileGL::MG_Backend::DirectGLES { namespace TextureImpl { @@ -103,7 +103,7 @@ namespace MobileGL::MG_Backend::DirectGLES { namespace { static Bool SplitMipUpload(const MG_Pipe::MGPipeResourceRecord::PendingUpload& pending, const IntVec3& levelSize, MG_State::GLState::MipmapDirtyRegion* boxes) { - using namespace TextureUploadBoxes; + using namespace MG_Util::TextureUploadBoxes; const auto& bounds = pending.UnionBox; if (bounds.X < 0 || bounds.Y < 0 || bounds.Z != 0 || bounds.D != 1 || bounds.X >= levelSize.x() || bounds.Y >= levelSize.y() || bounds.W > static_cast(levelSize.x() - bounds.X) || @@ -173,8 +173,8 @@ namespace MobileGL::MG_Backend::DirectGLES { Committed }; - static PackedUploadResult SubmitPackedUpload(const PackedTextureUpload::Batch& batch, GLuint destination, - Uint64 unionTexels) { + static PackedUploadResult SubmitPackedUpload(const MG_Util::PackedTextureUpload::Batch& batch, + GLuint destination, Uint64 unionTexels) { const Uint64 context = CurrentNativeContextSerial(); if (context == 0) return PackedUploadResult::Unavailable; static PackedUploadPages pool; @@ -188,7 +188,7 @@ namespace MobileGL::MG_Backend::DirectGLES { return PackedUploadResult::Unavailable; } auto* mapping = static_cast(BufferImpl::UnpackRingMappedPtr()); - PackedTextureUpload::WritePage(batch, mapping + offset); + MG_Util::PackedTextureUpload::WritePage(batch, mapping + offset); DrainDriverErrors("packed texture upload"); if (page->context != context) { @@ -200,8 +200,8 @@ namespace MobileGL::MG_Backend::DirectGLES { return PackedUploadResult::Rejected; } g_GLESFuncs.glBindTexture(GL_TEXTURE_2D, page->texture); - g_GLESFuncs.glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, PackedTextureUpload::PageSide, - PackedTextureUpload::PageSide); + g_GLESFuncs.glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, MG_Util::PackedTextureUpload::PageSide, + MG_Util::PackedTextureUpload::PageSide); g_GLESFuncs.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); g_GLESFuncs.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if (g_GLESFuncs.glGetError() != GL_NO_ERROR) { @@ -235,9 +235,10 @@ namespace MobileGL::MG_Backend::DirectGLES { region.height, 1); } if (g_GLESFuncs.glGetError() != GL_NO_ERROR) return PackedUploadResult::Rejected; - MGLOG_I_ONCE("Packed texture upload: %zu regions, %zu packed bytes, %llu bounding-box bytes", - batch.count, batch.ByteSize(), - static_cast(unionTexels * PackedTextureUpload::BytesPerTexel)); + MGLOG_I_ONCE( + "Packed texture upload: %zu regions, %zu packed bytes, %llu bounding-box bytes", batch.count, + batch.ByteSize(), + static_cast(unionTexels * MG_Util::PackedTextureUpload::BytesPerTexel)); return PackedUploadResult::Committed; } } // namespace @@ -904,7 +905,7 @@ namespace MobileGL::MG_Backend::DirectGLES { const MG_Pipe::MGPipeResourceRecord* pushedStorage, MG_Pipe::MGPipeHandle pushedRes, TextureUploadTarget uploadTarget, SizeT mipmapCount, GLuint destination) { - using namespace PackedTextureUpload; + using namespace MG_Util::PackedTextureUpload; Batch batch; Uint64 unionTexels = 0; const auto targetCode = static_cast(uploadTarget); diff --git a/MobileGL/MG_Backend/DirectGLES/PackedTextureUpload.h b/MobileGL/MG_Util/Texture/PackedTextureUpload.h similarity index 96% rename from MobileGL/MG_Backend/DirectGLES/PackedTextureUpload.h rename to MobileGL/MG_Util/Texture/PackedTextureUpload.h index b2b19c25..c1c3d6ab 100644 --- a/MobileGL/MG_Backend/DirectGLES/PackedTextureUpload.h +++ b/MobileGL/MG_Util/Texture/PackedTextureUpload.h @@ -1,4 +1,4 @@ -// MobileGL - MobileGL/MG_Backend/DirectGLES/PackedTextureUpload.h +// MobileGL - MobileGL/MG_Util/Texture/PackedTextureUpload.h // Copyright (c) 2025-2026 MobileGL-Dev // Licensed under the GNU Lesser General Public License v3.0: // https://www.gnu.org/licenses/gpl-3.0.txt @@ -14,7 +14,7 @@ #include #include -namespace MobileGL::MG_Backend::DirectGLES::TextureImpl::PackedTextureUpload { +namespace MobileGL::MG_Util::PackedTextureUpload { // A small RGBA8 page bounds both temporary storage and the packing search. constexpr int PageSide = 128; constexpr std::size_t MaxRegions = 32; @@ -144,4 +144,4 @@ namespace MobileGL::MG_Backend::DirectGLES::TextureImpl::PackedTextureUpload { } } } -} // namespace MobileGL::MG_Backend::DirectGLES::TextureImpl::PackedTextureUpload +} // namespace MobileGL::MG_Util::PackedTextureUpload diff --git a/MobileGL/MG_Backend/DirectGLES/TextureUploadBoxes.h b/MobileGL/MG_Util/Texture/TextureUploadBoxes.h similarity index 89% rename from MobileGL/MG_Backend/DirectGLES/TextureUploadBoxes.h rename to MobileGL/MG_Util/Texture/TextureUploadBoxes.h index 7e3513e3..0fa79318 100644 --- a/MobileGL/MG_Backend/DirectGLES/TextureUploadBoxes.h +++ b/MobileGL/MG_Util/Texture/TextureUploadBoxes.h @@ -1,4 +1,4 @@ -// MobileGL - MobileGL/MG_Backend/DirectGLES/TextureUploadBoxes.h +// MobileGL - MobileGL/MG_Util/Texture/TextureUploadBoxes.h // Copyright (c) 2025-2026 MobileGL-Dev // Licensed under the GNU Lesser General Public License v3.0: // https://www.gnu.org/licenses/gpl-3.0.txt @@ -14,7 +14,7 @@ #include #include -namespace MobileGL::MG_Backend::DirectGLES::TextureImpl::TextureUploadBoxes { +namespace MobileGL::MG_Util::TextureUploadBoxes { constexpr std::size_t MaxRegions = 64; constexpr std::uint64_t MinSavedTexels = 16 * 1024 / 4; @@ -29,7 +29,7 @@ namespace MobileGL::MG_Backend::DirectGLES::TextureImpl::TextureUploadBoxes { std::max(a.bottom, b.bottom)}; } - // A second GLES upload is worth taking only for separated groups with a + // A second upload job is worth taking only for separated groups with a // substantial absolute and relative reduction. Small mip levels keep one job. inline bool WorthSearching(Box bounds, std::size_t count) { return count >= 2 && count <= MaxRegions && bounds.Texels() > MinSavedTexels; @@ -65,4 +65,4 @@ namespace MobileGL::MG_Backend::DirectGLES::TextureImpl::TextureUploadBoxes { } return best; } -} // namespace MobileGL::MG_Backend::DirectGLES::TextureImpl::TextureUploadBoxes +} // namespace MobileGL::MG_Util::TextureUploadBoxes