mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-21 00:41:57 +09:00
[Fix] (Espryt): tell the backend when a frontend object dies instead of discovering it in a garbage sweep
- P2 step e2, as far as the file-ownership table lets one package take it. New frontend
header MG_State/GLState/StateObjectDeathNotice.h carries BufferBackendOps' shape for the
other six kinds: an ops table the backend fills in, and one entry point that takes
{kind, lifetimeId} rather than the object, because by the time the last SharedPtr has
dropped there is no object left to pass and the lifetime id is exactly what the client
slot allocator resolves a handle from. Declared only under MOBILEGL_PIPE_PUSH, so the
pull build's symbol set is untouched.
- BackendSlotTable::DestroyByLifetimeId drops the twin and returns the slot at the moment
the object goes, instead of at the next sweep - which for a renderbuffer or a texture
atlas is the difference between freeing the driver allocation now and freeing it 64
creations from now. It returns the slot only when THIS table holds it: two holders of one
kind already exist (the ScopedDirectGLESTextureBindings fixture; Magma's subsystem-4
table shares the VertexElementsCso kind), and a table that never twinned the object must
not free a slot the other one still names. The legacy arm keys on the frontend heap
address, cannot answer a notice at all, and keeps the sweep - which is the announced-
versus-discovered half of the A/B the compile-time arm exists for.
- Managers.cpp registers one dispatcher for all six kinds from ResolveEsprytSlotTablesArm(),
i.e. exactly when the arm that can answer a notice is the arm that runs, and drops a
notice that arrives after exit() has begun.
- FIRING it needs a destructor per class, and the P2 ownership table gives
{Texture,Framebuffer,Sampler,VertexArray}State/* to other packages, so only ProgramObject
and RenderbufferObject raise it here. The other four still rely on the sweep; their four
one-line calls retire it entirely.
- Three cases pin the three halves: the slot comes back with no sweep and the notice is
idempotent and does not free another holder's slot; a program and a renderbuffer announce
their own death when the last SharedPtr drops and not before; and the handle arm actually
installs a consumer, rather than the two halves each being fine on their own.
This commit is contained in:
@@ -33,17 +33,19 @@
|
||||
// * Slots are dense per kind, which is what lets the server side (ARCHITECTURE.md 10.1,
|
||||
// MG_Remote/Server/PipeObjectTables) be an array rather than an object graph.
|
||||
//
|
||||
// What has NOT changed, deliberately, and is this file's one departure from the P2 brief
|
||||
// (recorded in the package result file): a frontend object's death is still discovered rather
|
||||
// than announced. The brief's step e2 - a BufferBackendOps-shaped OnDestroy for the other six
|
||||
// kinds - has to be installed in MG_State/GLState/{Texture,Framebuffer,Renderbuffer,Sampler,
|
||||
// Program,VertexArray}State/*, and the P2 file-ownership table gives every one of those files
|
||||
// to another package. So the table keeps ONE weak_ptr per entry and uses it for exactly one
|
||||
// thing: ReclaimDeadSlots() frees the slot - and the twin, and the driver storage it owns -
|
||||
// once the frontend object is gone. That is a liveness sweep, not an identity test, and it is
|
||||
// what bumps Gen, which is precisely the ABA defence: a slot is only ever handed out again
|
||||
// after it was freed. When e2 lands, ReclaimDeadSlots() becomes the fallback path of an
|
||||
// explicit Destroy(handle) and the sweep call sites go away.
|
||||
// Death: announced where the package may announce it, discovered everywhere else.
|
||||
// DestroyByLifetimeId() below is step e2's backend half and it is complete - it drops the twin
|
||||
// and returns the slot the moment the frontend object's last SharedPtr goes - and the notice
|
||||
// that drives it (MG_State/GLState/StateObjectDeathNotice.h, BufferBackendOps' shape) is
|
||||
// registered for all six kinds. What is only PARTLY wired is the firing side: a destructor has
|
||||
// to raise the notice, and of the six object classes the P2 file-ownership table gives
|
||||
// {Texture,Framebuffer,Sampler,VertexArray}State/* to other packages, so only ProgramObject
|
||||
// and RenderbufferObject fire it here. The four that do not still rely on the sweep, which is
|
||||
// why the table keeps ONE weak_ptr per entry and uses it for exactly one thing:
|
||||
// ReclaimDeadSlots() frees the slot - and the twin, and the driver storage it owns - once the
|
||||
// frontend object is gone. That is a liveness sweep, not an identity test, and it is what
|
||||
// bumps Gen, which is precisely the ABA defence: a slot is only ever handed out again after it
|
||||
// was freed. The four remaining one-line destructor calls retire the sweep entirely.
|
||||
//
|
||||
// Because the sweep is still the only death signal, this table carries BOTH of the drivers
|
||||
// the registry it replaces carries, and for the same reasons:
|
||||
@@ -221,6 +223,40 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
m_isCollecting = false;
|
||||
}
|
||||
|
||||
// P2 step e2's backend half: the frontend object with this lifetime id has just been
|
||||
// DESTROYED, so drop its twin and return its slot now rather than waiting for a sweep
|
||||
// to notice the weak_ptr expired. Announced death is what the sweep is a stand-in for;
|
||||
// it frees the driver storage the twin owns at the moment the application let go of
|
||||
// the object, which is what Managers.h's "dead gigabytes" note is about.
|
||||
//
|
||||
// Returns whether this table held the slot. The slot goes back to the allocator ONLY
|
||||
// then, and this is not defensive: two holders of one kind already exist (the
|
||||
// ScopedDirectGLESTextureBindings fixture's saved copy is a second live table of kind
|
||||
// Texture; Magma's subsystem-4 table shares the VertexElementsCso kind), and a table
|
||||
// that never twinned the object must not free a slot the other one still names.
|
||||
Bool DestroyByLifetimeId(Uint64 lifetimeId) {
|
||||
const MG_Pipe::MGPipeHandle handle =
|
||||
MG_Pipe::MGPipeSlots().FindByLifetimeId(kKind, lifetimeId);
|
||||
if (MG_Pipe::MGPipeHandleIsNull(handle)) return false;
|
||||
if (handle.Slot >= m_slots.size()) return false;
|
||||
// Same ordering rule as ReclaimDeadSlots(): the twin's destructor is a driver call
|
||||
// and could re-enter GetOrCreate and resize m_slots, so nothing that outlives it
|
||||
// may be a reference into the vector.
|
||||
BackendPtr dead;
|
||||
{
|
||||
Entry& entry = m_slots[handle.Slot];
|
||||
if (!entry.Live || entry.Gen != handle.Gen) return false;
|
||||
dead = std::move(entry.backend);
|
||||
entry.backend.reset();
|
||||
entry.stateRef.reset();
|
||||
entry.Live = false;
|
||||
}
|
||||
if (m_memoHandle.Slot == handle.Slot) ForgetHandle();
|
||||
MG_Pipe::MGPipeSlots().Free(kKind, handle);
|
||||
dead.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
void CollectGarbageIfNeeded() {
|
||||
++m_gcTick;
|
||||
if (m_gcTick < kGCInterval) return;
|
||||
|
||||
Reference in New Issue
Block a user