[MG_Backend, MG_Test] (P12): the server backend's destruction drops every Espryt twin under a transport, so the in-process display server's next session no longer adopts the ended session's programs, VAOs and buffers (split build only; the pull build is unchanged, G1)

This commit is contained in:
2026-09-24 00:40:35 -04:00
parent 984db45576
commit c2758abdf9
4 changed files with 125 additions and 0 deletions
@@ -188,9 +188,18 @@ namespace MobileGL::MG_Backend::DirectGLES {
namespace {
Bool g_processTeardown = false;
std::once_flag g_teardownSentinelOnce;
#if MOBILEGL_BUILD_DISAGGREGATED
// P12: raised only while DropEveryTwinForEndedServerSession empties the twin tables, on the
// apply thread that is the only reader of the twins (Managers.h).
Bool g_serverSessionTwinTeardown = false;
#endif
} // namespace
#if MOBILEGL_BUILD_DISAGGREGATED
Bool InProcessTeardown() { return g_processTeardown || g_serverSessionTwinTeardown; }
#else
Bool InProcessTeardown() { return g_processTeardown; }
#endif
void EnsureProcessTeardownSentinel() {
std::call_once(g_teardownSentinelOnce,
[] { std::atexit(+[] { g_processTeardown = true; }); });
@@ -396,6 +405,26 @@ namespace MobileGL::MG_Backend::DirectGLES {
return false;
}
}
// P12: see Managers.h. Every table is replaced by an empty one, holders first (views before
// the textures they view, framebuffers before their attachments, VAOs before the buffers they
// fetch from), so the last reference to each twin goes here and its destructor - answered
// InProcessTeardown() - touches neither the driver nor another TU's statics.
void DropEveryTwinForEndedServerSession() {
if (g_processTeardown) return;
g_serverSessionTwinTeardown = true;
SamplerViewImpl::g_backendSamplerViews = {};
FramebufferImpl::g_backendFramebufferObjects = {};
VertexArrayImpl::g_backendVertexArrayObjects = {};
PrgramImpl::g_backendProgramObjects = {};
SamplerImpl::g_backendSamplerObjects = {};
TextureImpl::g_backendTextureObjects = {};
RenderbufferImpl::g_backendRenderbufferObjects = {};
BufferImpl::g_backendBufferResources = {};
g_serverSessionTwinTeardown = false;
MGLOG_I("DirectGLES: the ended server session's twins are dropped (every kind, no driver call); the next "
"session in this process starts from empty twin tables");
}
#endif
// The one sentence that decides the arm, written once so that a test can drive every