mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-16 22:43:24 +09:00
Merge branch 'p5e/id' into feat/disaggregated (P5e id: handle-keyed twins, the barriered exemption, the scope rename)
This commit is contained in:
@@ -223,37 +223,45 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// nor the client's allocator is touched from there any more.
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith &&
|
||||
!MG_Remote::Server::ServerLoop::OnApplyThread()) {
|
||||
if (MG_Remote::Client::EmitObjectDeathRecord(kind, lifetimeId) !=
|
||||
MG_Remote::Client::ObjectDeathEmit::NoSession) {
|
||||
return;
|
||||
}
|
||||
// NoSession is the ONE shape the record cannot carry: a transport configured
|
||||
// with no client session at all - a ServerLoop fixture driving a server role
|
||||
// with no client, never a real split (there a session exists whenever the
|
||||
// server does). The server loop IS there, so the death takes the delivery
|
||||
// that predates the record, kept VERBATIM for exactly this arm: a stack
|
||||
// struct hopped to the apply thread, which runs the switch below. NoHandle
|
||||
// does NOT land here - a handle that never existed has no twin to kill (§5.2)
|
||||
// - and a loop that is not RUNNING (teardown, pre-Start) has no thread to hop
|
||||
// to; the twin dies with the server either way.
|
||||
if (!MG_Remote::Server::ServerLoopInstance().Running()) {
|
||||
return;
|
||||
}
|
||||
struct Death { MG_Pipe::MGPipeKind kind; Uint64 lifetimeId; } death{kind, lifetimeId};
|
||||
MG_Remote::Server::ServerLoopInstance().RunOnApplyThread(
|
||||
+[](void* user) -> MobileGLResult {
|
||||
const auto& death = *static_cast<Death*>(user);
|
||||
OnFrontendStateObjectDestroyed(death.kind, death.lifetimeId);
|
||||
return MOBILEGL_OK;
|
||||
}, &death);
|
||||
// P5e (id), CONTRACT-P5E §4.4: THE RECORD IS THE ONLY DELIVERY NOW. What used
|
||||
// to sit here was a mailbox hop for the ONE shape the record cannot carry - a
|
||||
// transport configured with no client session at all, i.e. a ServerLoop
|
||||
// fixture driving a server role with no client, never a real split (there a
|
||||
// session exists whenever the server does). It posted a stack struct to the
|
||||
// apply thread, which re-entered this function and ran the switch below; that
|
||||
// switch's DestroyByLifetimeId probes and FREES in the CLIENT'S allocator from
|
||||
// the apply thread, which is precisely the read P5e is retiring - and it is
|
||||
// not a read a barrier could ever make safe, because under run-ahead there is
|
||||
// no wait behind which the allocator stands still.
|
||||
//
|
||||
// WHAT REPLACES IT: nothing, and that is the answer rather than an omission. A
|
||||
// fixture with no client session has no client allocator worth the name and no
|
||||
// handle ever crossed, so there is no twin the server built from a record; its
|
||||
// twins die with the backend at Stop (InProcessTeardown / the registry's own
|
||||
// destruction), which is what already happened for every death raised past
|
||||
// `Running() == false`. ID-96 enumerates the fixtures this changed and what
|
||||
// each one drives instead; every one of them now drives `object_death` by
|
||||
// handle through the applier, which is the delivery a real split uses.
|
||||
// ID-96, ANSWERED BY MEASUREMENT: the set of fixtures that lose death delivery
|
||||
// here is EMPTY. A probe that aborted in exactly this branch (NoSession with a
|
||||
// RUNNING server loop, i.e. the only shape the deleted hop ever fired for) was
|
||||
// run over the whole unit lane (2204 entries) and the whole integration-split
|
||||
// lane (111) and never fired once. The one fixture family that could reach it -
|
||||
// ServerLoopTest.cpp's ServerFixture / EglServerFixture, the only server role in
|
||||
// the tree with no client session - has exactly one case that lets a re-keyed
|
||||
// frontend object die off the apply thread
|
||||
// (ServerLoopEglTest.FrontendFramebufferDeathDeletesOnTheContextOwner), and that
|
||||
// case is already refused at its FIRST step by P5c's allocator guard, so its
|
||||
// `framebuffer.reset()` was unreachable at 2fde7034 too.
|
||||
(void)MG_Remote::Client::EmitObjectDeathRecord(kind, lifetimeId);
|
||||
return;
|
||||
}
|
||||
// P5c merge coordination: the record arm above carries every death a real split
|
||||
// sees; what still lands HERE through the mailbox is the NoSession server-only
|
||||
// fixture arm, whose DestroyByLifetimeId probes the client allocator from the
|
||||
// apply thread. Those probes ride inside the G6 scope (CONTRACT-P5C §5.2, the
|
||||
// amended ruling) - named debt that dies with the mailbox hop.
|
||||
const MG_Pipe::MGPipeFrontendKeyedRegistryScope frontendKeyedRegistry;
|
||||
// Falling through HERE under a transport means the death was raised ON the apply
|
||||
// thread - the server backend destroying a frontend object it created itself
|
||||
// (Magma's hidden blit/depth-mipmap resources). Those sites carry their own named
|
||||
// scope (MagmaP7AllocatorDebtScope), so the allocator probe below is admitted
|
||||
// there and refused everywhere else; this function no longer opens a scope of its
|
||||
// own, because the one arm that needed it is the mailbox hop that just went.
|
||||
#endif
|
||||
switch (kind) {
|
||||
case MG_Pipe::MGPipeKind::Texture:
|
||||
@@ -325,6 +333,29 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
} // namespace
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5e (id), CONTRACT-P5E §4.2 / §4.3: THE TWIN DEATH MOMENT, AND THE ABA ANSWER.
|
||||
//
|
||||
// The moment: the apply of `object_death` / the kind's own delete opcode / `resource_destroy`
|
||||
// - in RING ORDER, i.e. after every verb that named the dying generation and before any
|
||||
// record that names the slot's next owner - or the server backend's own destruction at Stop
|
||||
// (InProcessTeardown). `applier_reset` touches neither twins nor object records
|
||||
// (PipeApply.h's MGPipeApplierReset), so a make-current kills nothing.
|
||||
//
|
||||
// The ABA answer, which is what makes "no wait is added at any delete" (§2.7) safe: Gen
|
||||
// moves ONLY on reuse (SlotAllocator.cpp), the client frees a slot only AFTER its death
|
||||
// record went out (PipeFill.cpp's NotifyAndFree), and the ring is in order. So at the
|
||||
// server every record naming {s, g} is applied before object_death{s, g}, which is applied
|
||||
// before create{s, g+1}. THE ORDERING IS THE ARGUMENT AND THE GEN COMPARE IS THE PROOF:
|
||||
// * GetOrCreate({s, g+1}) on a live {s, g} entry RE-MINTS - it resets the twin, so the
|
||||
// successor never inherits the dead object's driver ids (SlotTables.h);
|
||||
// * FindByHandle({s, g}) after the recycle answers NULL, so a stale handle resolves to
|
||||
// nothing rather than to its successor's twin;
|
||||
// * a backward {s, g-1} is REFUSED rather than adopted, so a late record cannot destroy
|
||||
// the incumbent.
|
||||
// Which means even a SKIPPED death (an object that never crossed emits none,
|
||||
// WireTables.cpp) is answered by the forward-Gen reset alone. Pinned by
|
||||
// DirectGLESSlotTable.AGenerationBehindTheLiveTwinIsRefusedRatherThanAdopted (all three
|
||||
// clauses, on the table itself) and end to end by the CtWireScenario recycle cases.
|
||||
Bool ReleaseTwinsForWireObjectDeath(MG_Pipe::MGPipeHandle handle, MG_Pipe::MGPipeKind kind) {
|
||||
// The handle-keyed twin of the notice switch above, and deliberately NOT that switch:
|
||||
// the record carried the handle, so no lifetime id is probed and the client's
|
||||
@@ -2932,10 +2963,19 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5c merge coordination (CONTRACT-P5C §3.1's named exemption): every caller of
|
||||
// this function is a site whose handle-carrying records (set_shader_buffers /
|
||||
// set_stream_output_targets) the client does not emit until P4b, so the probe
|
||||
// set_stream_output_targets) the client does not emit until sb, so the probe
|
||||
// below runs inside the scoped exemption. The scope, not a silent guard removal,
|
||||
// is what keeps the debt named and greppable.
|
||||
const MG_Pipe::MGPipeReverseAnnouncementScope reverseAnnouncement;
|
||||
//
|
||||
// P5e (id), ruling 12: THE SCOPE CHANGED UNDER THIS SITE AND THE SITE HAD TO MOVE.
|
||||
// The exemption it used to name is now MagmaP7AllocatorDebtScope and is keyed on a
|
||||
// DirectVulkan server (Magma's four P7 debts); this is Espryt's, and it belongs to
|
||||
// the frontend-keyed registry family with the rest of the Espryt debt. Which scope
|
||||
// it names is not cosmetic: the Magma one would not exempt it here at all. It
|
||||
// retires when vi/sb carry the handle into EnsureBufferResourceForHandle /
|
||||
// IsBufferDrawCleanByHandle / MarkBufferGpuWrittenByHandle, which is the last
|
||||
// caller set this function has.
|
||||
const MG_Pipe::MGPipeFrontendKeyedRegistryScope frontendKeyedRegistry;
|
||||
#endif
|
||||
return g_backendBufferResources.HandleOf(bufferObject);
|
||||
}
|
||||
@@ -4876,6 +4916,27 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
if (!record.Live || record.Gen != cso.Gen) return nullptr;
|
||||
return &record;
|
||||
}
|
||||
|
||||
// P5e (id), CONTRACT-P5E §4.1. See Managers.h for the contract; the body is the one
|
||||
// SamplerImpl::ResolveSamplerCsoTwin already runs, with the sync left to vi.
|
||||
BackendVertexArrayObject* ResolveVaoTwin(MG_Pipe::MGPipeHandle elements) {
|
||||
if (MG_Pipe::MGPipeHandleIsNull(elements)) return nullptr;
|
||||
// THE RECORD FIRST, before the table is touched: a handle with no record means the
|
||||
// client named a vertex-elements CSO it never described (or one it deleted while a
|
||||
// binding still names it), and adopting a slot for it would leave a twin nothing
|
||||
// can ever sync. The applier's own Gen check is what turns a stale handle into this
|
||||
// null rather than into its successor's record.
|
||||
if (PipeRecordAt(MG_Pipe::MGPipeApplier().VertexElementsCsos, elements) == nullptr) {
|
||||
MGLOG_E_ONCE("MGPipe: vertex-elements CSO {%u, %u} has no applier record on the handle "
|
||||
"arm, so no driver VAO can be built for it and the draw keeps what is bound",
|
||||
elements.Slot, elements.Gen);
|
||||
return nullptr;
|
||||
}
|
||||
auto* slot = AdoptTwinByHandle(g_backendVertexArrayObjects, elements, "vertex-elements CSO");
|
||||
if (slot == nullptr) return nullptr;
|
||||
if (!*slot) *slot = MakeShared<BackendVertexArrayObject>();
|
||||
return slot->get();
|
||||
}
|
||||
#endif // MOBILEGL_PIPE_PUSH
|
||||
|
||||
void BackendVertexArrayObject::SyncToBackend(
|
||||
@@ -9096,6 +9157,28 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
MG_State::GLState::TextureState::MAX_TEXTURE_IMAGE_UNITS>
|
||||
g_boundTexturesCache;
|
||||
TwinRegistry<MG_State::GLState::ITextureObject, BackendTextureObject, MG_Pipe::MGPipeKind::Texture> g_backendTextureObjects;
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (id), CONTRACT-P5E §4.1. See Managers.h for the contract.
|
||||
BackendTextureObject* ResolveTextureTwin(MG_Pipe::MGPipeHandle res) {
|
||||
if (MG_Pipe::MGPipeHandleIsNull(res)) return nullptr;
|
||||
// THE RECORD FIRST: a texture handle with no resource record is a seam defect - the
|
||||
// client named a texture it never created, or one whose resource_destroy has
|
||||
// already applied while a binding still names it - and a twin adopted for it would
|
||||
// own a driver texture nothing ever uploads to.
|
||||
if (PipeTextureRecordForHandle(res) == nullptr) {
|
||||
MGLOG_E_ONCE("MGPipe: texture {%u, %u} has no applier resource record on the handle "
|
||||
"arm, so no driver texture can be built for it and the unit keeps what "
|
||||
"it holds",
|
||||
res.Slot, res.Gen);
|
||||
return nullptr;
|
||||
}
|
||||
auto* slot = AdoptTwinByHandle(g_backendTextureObjects, res, "texture");
|
||||
if (slot == nullptr) return nullptr;
|
||||
if (!*slot) *slot = MakeShared<BackendTextureObject>();
|
||||
return slot->get();
|
||||
}
|
||||
#endif
|
||||
} // namespace TextureImpl
|
||||
|
||||
namespace FramebufferImpl {
|
||||
@@ -10756,6 +10839,27 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
constexpr Int kMaxDrainedProgramErrors = 32;
|
||||
TwinRegistry<MG_State::GLState::ProgramObject, BackendProgramObjectImpl, MG_Pipe::MGPipeKind::ShaderCso> g_backendProgramObjects;
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (id), CONTRACT-P5E §4.1. See Managers.h for the contract - in particular why the
|
||||
// composite band had to land in the same package as this function.
|
||||
BackendProgramObjectImpl* ResolveProgramTwin(MG_Pipe::MGPipeHandle cso) {
|
||||
if (MG_Pipe::MGPipeHandleIsNull(cso)) return nullptr;
|
||||
// THE RECORD FIRST, and through the BAND-AWARE reader: a composite pipeline's CSO
|
||||
// lives in the applier's CompositeShaderCsos table, and asking the ordinary one for
|
||||
// it would answer null for a program that is perfectly live.
|
||||
if (PipeShaderCsoRecordForHandle(cso) == nullptr) {
|
||||
MGLOG_E_ONCE("MGPipe: shader CSO {%u, %u} has no applier record on the handle arm, so "
|
||||
"no driver program can be built for it and the draw keeps what is bound",
|
||||
cso.Slot, cso.Gen);
|
||||
return nullptr;
|
||||
}
|
||||
auto* slot = AdoptTwinByHandle(g_backendProgramObjects, cso, "shader CSO");
|
||||
if (slot == nullptr) return nullptr;
|
||||
if (!*slot) *slot = MakeShared<BackendProgramObjectImpl>();
|
||||
return slot->get();
|
||||
}
|
||||
#endif
|
||||
|
||||
BackendProgramObjectImpl::BackendProgramObjectImpl() {
|
||||
#ifdef TRACY_ENABLE
|
||||
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
||||
|
||||
Reference in New Issue
Block a user