[Refactor] (MG_Backend/DirectGLES, MG_Util/Texture): move the upload packing helpers to MG_Util

This commit is contained in:
swung0x48 committed 2026-11-26 04:56:56 -04:00
1 parent c025f9c4e8
commit 926e54e28c
3 files changed
+20 -19

No files matched your search

@@ -8,8 +8,8 @@
#include "ManagersInternal.h"
#include "DirectGLESInternal.h"
#include "PackedTextureUpload.h"
#include "TextureUploadBoxes.h"
#include <MG_Util/Texture/PackedTextureUpload.h>
#include <MG_Util/Texture/TextureUploadBoxes.h>
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<Uint>(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<Uint8*>(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<unsigned long long>(unionTexels * PackedTextureUpload::BytesPerTexel));
MGLOG_I_ONCE(
"Packed texture upload: %zu regions, %zu packed bytes, %llu bounding-box bytes", batch.count,
batch.ByteSize(),
static_cast<unsigned long long>(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<Uint16>(uploadTarget);
@@ -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 <cstdint>
#include <cstring>
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
@@ -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 <cstdint>
#include <optional>
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