mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-16 06:23:23 +09:00
[Feature] (P14): state ownership - multi-session, multi-context, share groups
Breaks the one process = one server = one session = one context equation
that the whole stack's correctness used to rest on. Design and per-slice
shape: docs/Disaggregated/design/11-state-ownership.md.
S1 wire: bind_context ring record (opcode 84) announces the current
context at the make-current edge; CreateContext/DestroyContext join the
SurfaceOp control frames; control revision 5 -> 6; the server keeps a
per-session token table and refuses unknown tokens by name.
S2 server: SessionRuntime per session with thread-scoped resolution
(singletons become fallbacks), per-thread gPipeInputs, per-session latch
domains, per-thread segment resolvers; the in-process unix supervisor
serves up to MOBILEGL_IPC_INPROC_MAX_SESSIONS (16) concurrent sessions;
surface mode is declared per session and the display lease refuses a
second on-screen session by name.
S3 frontend: ShareGroupState owns the shared object stores and name
generators (buffer/texture/renderbuffer/sampler/program), GLContext keeps
per-context bindings/errors/container objects; pGLContext becomes
thread-local with a process default context preserving the single-context
world verbatim; eglCreateContext builds a real GLContext and joins the
sharing context's group.
S4 backend: native EGL tuples keyed by (session, context token);
InitDisplayAndContext's unconditional teardown is gone - creating a
second context or surface no longer destroys the first; eglCreateContext
sharing is wired to the native driver; bind_context is the native switch
point.
S5 applier: MGPipeApplierState splits into MGPipeObjectRecords (per
share group) and MGPipeWorkingState (per context), resolved through a
{session, token} registry with a thread-local cached fast path.
Tests: MultiSessionTest (incl. two sessions x two contexts interleaved
with real clear/readback witnesses), ApplierOwnershipTest (with a
null-resolver negative control), ContextStateOwnershipTest,
ServerLoopEglTest native-context liveness; 99/99 of the acceptance set
green on the host build.
Known debts (documented in the design doc): twin registries still keyed
by handle alone, no per-record ContextSlot, process-global backend
generations, MakeCurrent dedup per current binding.
This commit is contained in:
@@ -268,7 +268,7 @@ namespace {
|
||||
MobileGL::Vector<TextureBindCall> bindCalls;
|
||||
|
||||
private:
|
||||
MobileGL::UniquePtr<MobileGL::MG_State::GLState::GLContext> previousContext;
|
||||
MobileGL::SharedPtr<MobileGL::MG_State::GLState::GLContext> previousContext;
|
||||
MobileGL::MG_External::GLESFunctionsTable previousFunctions;
|
||||
MobileGL::Uint previousActiveUnit;
|
||||
decltype(MobileGL::MG_Backend::DirectGLES::TextureImpl::g_boundTexturesCache) previousCache;
|
||||
@@ -5320,7 +5320,14 @@ TEST(DirectGLESVertexInputDraw, TheAttributeWalkTakesItsBuffersFromTheRecordNotT
|
||||
// THE PUBLISHED STATE: attribute 0 fetches from A, attribute 1 from B, attribute 2 from A
|
||||
// again (the dedupe), attribute 3 is a client-memory array (null Res, nothing to ensure).
|
||||
MG_Pipe::MGPipeApplierState& st = MG_Pipe::MGPipeApplier();
|
||||
const MG_Pipe::MGPipeApplierState saved = st;
|
||||
// P14 S5: the applier is not copyable any more (its object tables are references into the
|
||||
// share group it belongs to), so the case saves the WORKING fields it is about to move
|
||||
// instead of the whole object - which is also the smaller blast radius: nothing here
|
||||
// touches a record.
|
||||
const Uint32 savedVertexBufferStart = st.VertexBufferStart;
|
||||
const Uint32 savedVertexBufferCount = st.VertexBufferCount;
|
||||
const Array<MG_Pipe::MGPVertexBuffer, VertexArrayObject::MAX_VERTEX_ATTRIBS> savedVertexBuffers =
|
||||
st.VertexBuffers;
|
||||
st.VertexBufferStart = 0;
|
||||
st.VertexBufferCount = 4;
|
||||
for (Uint32 i = 0; i < 4; ++i) {
|
||||
@@ -5338,7 +5345,7 @@ TEST(DirectGLESVertexInputDraw, TheAttributeWalkTakesItsBuffersFromTheRecordNotT
|
||||
// this case exists to catch - MGB_CTX->GetBoundVertexArray()->GetAllAttributes() - has
|
||||
// anything to read at all; a free-standing object would make the revert crash instead of
|
||||
// disagree, which is a red for the wrong reason.
|
||||
UniquePtr<GLContext> previousContext = Move(MG_State::pGLContext);
|
||||
SharedPtr<GLContext> previousContext = Move(MG_State::pGLContext);
|
||||
MG_State::pGLContext = MakeUnique<GLContext>();
|
||||
MG_State::pGLContext->CreateVertexArrayObject(1);
|
||||
MG_State::pGLContext->BindVertexArray(1);
|
||||
@@ -5369,7 +5376,9 @@ TEST(DirectGLESVertexInputDraw, TheAttributeWalkTakesItsBuffersFromTheRecordNotT
|
||||
"run-ahead client has already moved on from";
|
||||
}
|
||||
|
||||
st = saved;
|
||||
st.VertexBufferStart = savedVertexBufferStart;
|
||||
st.VertexBufferCount = savedVertexBufferCount;
|
||||
st.VertexBuffers = savedVertexBuffers;
|
||||
MG_State::pGLContext.reset();
|
||||
MG_State::pGLContext = Move(previousContext);
|
||||
MG_Pipe::MGPipeSlots().Free(MG_Pipe::MGPipeKind::Buffer, a);
|
||||
@@ -5399,14 +5408,15 @@ TEST(DirectGLESVertexInputDraw, TheIndexArmTakesItsBufferAndItsSerialFromTheReco
|
||||
ASSERT_FALSE(MG_Pipe::MGPipeHandleIsNull(publishedHandle));
|
||||
|
||||
MG_Pipe::MGPipeApplierState& st = MG_Pipe::MGPipeApplier();
|
||||
const MG_Pipe::MGPipeApplierState saved = st;
|
||||
const MG_Pipe::MGPIndexBuffer savedIndexBuffer = st.IndexBuffer;
|
||||
const Uint64 savedIndexBufferSerial = st.IndexBufferSerial;
|
||||
st.IndexBuffer = MG_Pipe::MGPIndexBuffer{};
|
||||
st.IndexBuffer.Res = publishedHandle;
|
||||
st.IndexBufferSerial = 11;
|
||||
|
||||
// The frontend's element slot has moved to another buffer with nothing emitted, in a real
|
||||
// context for the reason the case above gives.
|
||||
UniquePtr<GLContext> previousContext = Move(MG_State::pGLContext);
|
||||
SharedPtr<GLContext> previousContext = Move(MG_State::pGLContext);
|
||||
MG_State::pGLContext = MakeUnique<GLContext>();
|
||||
MG_State::pGLContext->CreateVertexArrayObject(1);
|
||||
MG_State::pGLContext->BindVertexArray(1);
|
||||
@@ -5428,7 +5438,8 @@ TEST(DirectGLESVertexInputDraw, TheIndexArmTakesItsBufferAndItsSerialFromTheReco
|
||||
<< "a re-emitted set_index_buffer on the SAME handle is invisible to this arm without "
|
||||
"the serial, and the memo would read clean over it";
|
||||
|
||||
st = saved;
|
||||
st.IndexBuffer = savedIndexBuffer;
|
||||
st.IndexBufferSerial = savedIndexBufferSerial;
|
||||
MG_State::pGLContext.reset();
|
||||
MG_State::pGLContext = Move(previousContext);
|
||||
MG_Pipe::MGPipeSlots().Free(MG_Pipe::MGPipeKind::Buffer, publishedHandle);
|
||||
|
||||
Reference in New Issue
Block a user