mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-16 22:43:24 +09:00
[MG_Remote, MG_Pipe, MG_Impl, MG_Test, MG_IntegrationTest, Docs] (Disaggregated): inproc performance package - dirty-driven persistent-map push, batched barrier waits, spin-clock batching
VD12 Minecraft on the Redmi (FCL, DirectGLES): the split's in-world frame rate
13 -> 60-66 fps against monolith's 110-114, and persistent-map wire bytes
25 MB/frame -> ~0.23 MB/frame. The residual split-specific costs are named at
the end, not hidden: the R-1 serialization (WaitForApplied ~12%, P11's
versioned-inputs design) and a split-only mutex complex still under
investigation.
Persistent-map push, three arms picked per buffer at map time:
- mprotect dirty tracker: the mapped range's page-aligned interior is
protected PROT_READ; the app's next write faults, the SIGSEGV handler marks
the page in the slot's bitmap and unprotects, and the push ships one 64 KB
block per block containing a faulted page. Ownership is three tests -
SEGV_ACCERR only (a userspace raise and an unmapped page chain verbatim),
inside a live tracked range, and not a refault on a still-set bit (a write
we unprotected succeeds, so that is a non-write access and it crashes
honestly). The alignment is INWARD: an outward-aligned edge page holds
foreign bytes, and a signal-blocking worker thread faulting on one is a
process kill - that was the ctest-only SmallRing segfault. Edge spans
(at most two per map) are hashed per push and ship their containing block
only on change (unconditional edges measured 112 MB/frame). Re-arm is one
mprotect per contiguous run. The first push ships everything once.
- hash-suppress arm (MOBILEGL_IPC_PERSISTENT_HASH_SUPPRESS, default 1):
per-block XXH3 against the last push's hashes; untracked buffers only.
- PushDrawConsumers: only the buffers the upcoming draw/dispatch can read
(VAO attribs/element, indexed binding points, indirect/parameter slots,
TexBuffer backing - the last also retires the per-frame-cadence cloud
twitch), plus the fault-epoch skip: an unmoved epoch proves no interior
byte changed, tracked edges are hashed in place, and any hash-arm member
vetoes. The membership map caches the tracker slot pointer (a 64-slot
rescan per buffer per draw was measured and removed).
MOBILEGL_IPC_BATCH_WAITS (default 1; MOBILEGL_PIPE_VERIFY forces 0): a
value-class record (kCtxState/kCtxCso/kCtxObject with no reply slot) is
published without waiting for its own apply; the barrier is taken at the next
pull-reading verb, the only place BARRIER-PULLED fields are read, so the R-1
fence posts are untouched and only the round trips between them change. Two
consequences are pinned rather than argued: kCtxObject verbs the tests read
synchronously get explicit fences (GenerateMipmapFieldsCross,
FramebufferDeathCrosses), and a frontend object whose last SharedPtr drops on
the apply thread - impossible before batching - now enqueues its
(kind, lifetimeId) on the deferred destroy queue and the GL thread replays
the DestroyAndFree helper at the verb hooks (CopyImageLayeredScenario aborted
Fatal{RoleViolation, MGPipeSlots} without it).
Doorbell::Wait's spin reads the clock once per 64 yields: on the workload
device a steady_clock read is a real syscall (no vDSO) and the per-iteration
reads were ~20% of the whole process at ~1000 waits/frame.
Gates: gen_pipe --check/--self-test green; unit 2188/2188;
integration-split 110/111, the one red being GenerateMipmapDepthPixels whose
DirectGLES and DirectVulkan MONOLITH siblings flake identically with every
code path of this package provably inert (PushIsArmed false, no ClientSession,
deferral's monolith early-out).
This commit is contained in:
@@ -57,6 +57,7 @@
|
||||
#endif
|
||||
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
@@ -971,7 +972,79 @@ namespace MobileGL::MG_Pipe {
|
||||
return published;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
namespace {
|
||||
struct MGPipeDeferredDestroy {
|
||||
MGPipeKind kind;
|
||||
Uint64 lifetimeId;
|
||||
};
|
||||
// A plain mutex, not a lock-free queue: producers are destructors that lost the
|
||||
// last-reference race (rare), the consumer is the GL thread's verb hook, and neither
|
||||
// holds the lock past a vector push/swap. The count is the fast no-work check for
|
||||
// the per-verb drain.
|
||||
std::mutex g_deferredDestroyMutex;
|
||||
Vector<MGPipeDeferredDestroy> g_deferredDestroys;
|
||||
std::atomic<Uint32> g_deferredDestroyCount{0};
|
||||
} // namespace
|
||||
|
||||
Bool MGPipeDeferDestroyAndFreeIfOnApplyThread(MGPipeKind kind, Uint64 lifetimeId) {
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return false;
|
||||
if (!MG_Remote::Client::RunsAsTheServerRole()) return false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_deferredDestroyMutex);
|
||||
g_deferredDestroys.push_back(MGPipeDeferredDestroy{kind, lifetimeId});
|
||||
}
|
||||
g_deferredDestroyCount.fetch_add(1, std::memory_order_release);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MGPipeDrainDeferredDestroys() {
|
||||
if (g_deferredDestroyCount.load(std::memory_order_acquire) == 0) return;
|
||||
Vector<MGPipeDeferredDestroy> drained;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_deferredDestroyMutex);
|
||||
drained.swap(g_deferredDestroys);
|
||||
g_deferredDestroyCount.store(0, std::memory_order_release);
|
||||
}
|
||||
for (const MGPipeDeferredDestroy& one : drained) {
|
||||
// Each replay lands back in the helper itself, on the GL thread this time, so
|
||||
// the deferral branch passes and the helper's own order runs unchanged.
|
||||
switch (one.kind) {
|
||||
case MGPipeKind::VertexElementsCso:
|
||||
MGPipeEmitVertexElementsDestroyAndFree(one.lifetimeId);
|
||||
break;
|
||||
case MGPipeKind::SamplerViewCso:
|
||||
MGPipeEmitSamplerViewCsoDestroyAndFree(one.lifetimeId);
|
||||
break;
|
||||
case MGPipeKind::Texture:
|
||||
MGPipeEmitTextureDestroyAndFree(one.lifetimeId);
|
||||
break;
|
||||
case MGPipeKind::Renderbuffer:
|
||||
MGPipeEmitRenderbufferDestroyAndFree(one.lifetimeId);
|
||||
break;
|
||||
case MGPipeKind::Framebuffer:
|
||||
MGPipeEmitFramebufferDestroyAndFree(one.lifetimeId);
|
||||
break;
|
||||
case MGPipeKind::SamplerCso:
|
||||
MGPipeEmitSamplerCsoDestroyAndFree(one.lifetimeId);
|
||||
break;
|
||||
case MGPipeKind::ShaderCso:
|
||||
MGPipeEmitShaderCsoDestroyAndFree(one.lifetimeId);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Bool MGPipeEmitVertexElementsDestroyAndFree(Uint64 lifetimeId) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (MGPipeDeferDestroyAndFreeIfOnApplyThread(MGPipeKind::VertexElementsCso,
|
||||
lifetimeId)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
// C-1. THE SAME SHAPE AS MGPipeEmitResourceDestroyAndFree ABOVE, and for the same
|
||||
// reason: whatever mints a handle owns the death of that handle, and the mint for this
|
||||
// kind is MGPipeVertexInputEmitter::EmitVertexElements - i.e. the client, on every
|
||||
@@ -1585,6 +1658,11 @@ namespace MobileGL::MG_Pipe {
|
||||
// none per object (its death is the cache's LRU, ID-17). Unconditional in a push build,
|
||||
// like the mints: the entries exist whether or not the family bit is set.
|
||||
Bool MGPipeEmitSamplerViewCsoDestroyAndFree(Uint64 lifetimeId) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (MGPipeDeferDestroyAndFreeIfOnApplyThread(MGPipeKind::SamplerViewCso, lifetimeId)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
const MGPipeHandle handle =
|
||||
MGPipeSlots().FindByLifetimeId(MGPipeKind::SamplerViewCso, lifetimeId);
|
||||
const Bool published =
|
||||
@@ -1607,6 +1685,11 @@ namespace MobileGL::MG_Pipe {
|
||||
}
|
||||
|
||||
Bool MGPipeEmitTextureDestroyAndFree(Uint64 lifetimeId) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (MGPipeDeferDestroyAndFreeIfOnApplyThread(MGPipeKind::Texture, lifetimeId)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
const MGPipeHandle handle = MGPipeSlots().FindByLifetimeId(MGPipeKind::Texture, lifetimeId);
|
||||
const Bool published =
|
||||
EmitDeleteIfPublished(MGPipeKind::Texture, handle, &MGPipeRouteResourceDestroy);
|
||||
@@ -1647,6 +1730,11 @@ namespace MobileGL::MG_Pipe {
|
||||
}
|
||||
|
||||
Bool MGPipeEmitRenderbufferDestroyAndFree(Uint64 lifetimeId) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (MGPipeDeferDestroyAndFreeIfOnApplyThread(MGPipeKind::Renderbuffer, lifetimeId)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
const MGPipeHandle handle =
|
||||
MGPipeSlots().FindByLifetimeId(MGPipeKind::Renderbuffer, lifetimeId);
|
||||
const Bool published =
|
||||
@@ -1658,6 +1746,11 @@ namespace MobileGL::MG_Pipe {
|
||||
}
|
||||
|
||||
Bool MGPipeEmitFramebufferDestroyAndFree(Uint64 lifetimeId) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (MGPipeDeferDestroyAndFreeIfOnApplyThread(MGPipeKind::Framebuffer, lifetimeId)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
// NO WIRE DELETE EXISTS FOR THIS KIND, and none is invented: PipeCalls.def has
|
||||
// resource_destroy and the five delete_* rows and no framebuffer delete, because a
|
||||
// framebuffer is not a resource and is not a CSO - it is STATE, and
|
||||
@@ -1684,6 +1777,11 @@ namespace MobileGL::MG_Pipe {
|
||||
}
|
||||
|
||||
Bool MGPipeEmitSamplerCsoDestroyAndFree(Uint64 lifetimeId) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (MGPipeDeferDestroyAndFreeIfOnApplyThread(MGPipeKind::SamplerCso, lifetimeId)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
const MGPipeHandle handle =
|
||||
MGPipeSlots().FindByLifetimeId(MGPipeKind::SamplerCso, lifetimeId);
|
||||
const Bool published =
|
||||
@@ -1698,6 +1796,11 @@ namespace MobileGL::MG_Pipe {
|
||||
}
|
||||
|
||||
Bool MGPipeEmitShaderCsoDestroyAndFree(Uint64 lifetimeId) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (MGPipeDeferDestroyAndFreeIfOnApplyThread(MGPipeKind::ShaderCso, lifetimeId)) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
// ORDINARY PROGRAMS AND PIPELINE COMPOSITES TAKE THE SAME PATH, deliberately: the
|
||||
// server never learns a composite is a composite, and the only difference on this side
|
||||
// is which band the slot came out of. A composite's slot has TWO independent release
|
||||
|
||||
Reference in New Issue
Block a user