From 7f194a8579f7ffe18f8046c67da8e5051efc337b Mon Sep 17 00:00:00 2001 From: Swung0x48 Date: Tue, 6 Oct 2026 12:13:37 -0400 Subject: [PATCH] [Refactor] (P13 W5 S3): the apply side's backend comes through MG_Backend's ApplyRoleBackend hook, which ServerLoop installs. --- .../Renderer/VertexInputStateFactory.cpp | 3 ++- MobileGL/MG_Backend/Record/ApplyRoleBackend.h | 27 +++++++++++++++++++ MobileGL/MG_Remote/Server/ServerLoop.cpp | 13 +++++++++ .../GLState/BufferState/BufferObject.cpp | 3 +++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 MobileGL/MG_Backend/Record/ApplyRoleBackend.h diff --git a/MobileGL/MG_Backend/DirectVulkan/Renderer/VertexInputStateFactory.cpp b/MobileGL/MG_Backend/DirectVulkan/Renderer/VertexInputStateFactory.cpp index 7f6350de..9e7cec37 100644 --- a/MobileGL/MG_Backend/DirectVulkan/Renderer/VertexInputStateFactory.cpp +++ b/MobileGL/MG_Backend/DirectVulkan/Renderer/VertexInputStateFactory.cpp @@ -6,6 +6,7 @@ // SPDX-License-Identifier: LGPL-3.0-only // End of Source File Header +#include #include "VertexInputStateFactory.h" #include "MagmaPipeArms.h" #include "MG_Util/Converters/MGToStr/DataTypeConverter.h" @@ -464,7 +465,7 @@ namespace MobileGL::MG_Backend::DirectVulkan { attr.IsBgra, attr.IsLong); auto conversion = VertexStreamConversion::None; if (format == VK_FORMAT_UNDEFINED && type == DataType::Float64) { - const auto* backend = MG_Remote::Server::ServerLoopInstance().Backend(); + const auto* backend = MG_Backend::ApplyRoleBackend(); if (backend && backend->GetDynamicParameters().SupportsFloat64VertexAttributes) { // Exactly the monolith arm's answer for the same state: with native fp64 // the module KEPT its 64-bit inputs (DemoteFloat64Pass did not run), so diff --git a/MobileGL/MG_Backend/Record/ApplyRoleBackend.h b/MobileGL/MG_Backend/Record/ApplyRoleBackend.h new file mode 100644 index 00000000..0d59dbad --- /dev/null +++ b/MobileGL/MG_Backend/Record/ApplyRoleBackend.h @@ -0,0 +1,27 @@ +// MobileGL - MobileGL/MG_Backend/Record/ApplyRoleBackend.h +// Copyright (c) 2025-2026 MobileGL-Dev +// Licensed under the GNU Lesser General Public License v3.0: +// https://www.gnu.org/licenses/gpl-3.0.txt +// https://www.gnu.org/licenses/lgpl-3.0.txt +// SPDX-License-Identifier: LGPL-3.0-only +// End of Source File Header + +// P13 W5: WHOSE BACKEND ANSWERS A CAPABILITY QUESTION ON THE APPLY SIDE. Under a transport the +// server's own backend (ServerLoop's) is the authority for the records it applies; the record arm +// asked MG_Remote for it by name, which a library without MG_Remote cannot. The answer now comes +// through this hook, which ServerLoop.cpp installs at static init. Without it - a library without +// a transport - the answer is null, which is exactly what a monolith process got before (a +// monolith has no server loop, so its server backend was always null). + +#pragma once + +namespace MobileGL::MG_Backend { + class BackendObject; + + using ApplyRoleBackendHook = BackendObject* (*)(); + inline constinit ApplyRoleBackendHook gApplyRoleBackendHook = nullptr; + + inline BackendObject* ApplyRoleBackend() { + return gApplyRoleBackendHook != nullptr ? gApplyRoleBackendHook() : nullptr; + } +} // namespace MobileGL::MG_Backend diff --git a/MobileGL/MG_Remote/Server/ServerLoop.cpp b/MobileGL/MG_Remote/Server/ServerLoop.cpp index 77b60eca..4de9262d 100644 --- a/MobileGL/MG_Remote/Server/ServerLoop.cpp +++ b/MobileGL/MG_Remote/Server/ServerLoop.cpp @@ -9,6 +9,7 @@ // P5 package v1: the apply thread, its affinity, its parking, and the EGL ownership move. #include "ServerLoop.h" +#include #include "ApplyThreadPolicy.h" #include "SessionRuntime.h" #include @@ -1460,6 +1461,18 @@ namespace MobileGL::MG_Remote::Server { return instance; } + // P13 W5: the record arm asks for the apply side's backend through MG_Backend's hook + // (Record/ApplyRoleBackend.h), which has no MG_Remote to name. Installed at static init so it + // answers from the first record on, exactly as the direct ServerLoopInstance().Backend() did. + namespace { + [[maybe_unused]] const bool g_applyRoleBackendHookInstalled = [] { + MG_Backend::gApplyRoleBackendHook = []() -> MG_Backend::BackendObject* { + return ServerLoopInstance().Backend(); + }; + return true; + }(); + } // namespace + // --------------------------------------------------------------------------------- // The control-frame dispatch and the twelve EGL forwarders (P5f, package fc) // --------------------------------------------------------------------------------- diff --git a/MobileGL/MG_State/GLState/BufferState/BufferObject.cpp b/MobileGL/MG_State/GLState/BufferState/BufferObject.cpp index 5e2b13fe..cbfa395a 100644 --- a/MobileGL/MG_State/GLState/BufferState/BufferObject.cpp +++ b/MobileGL/MG_State/GLState/BufferState/BufferObject.cpp @@ -66,6 +66,9 @@ namespace MobileGL::MG_State::GLState { if (!MG_Record::PersistentMapTracker::OnServerRole()) return; FatalLegacyBufferArmFromApplyThread(accessor); } +#else + // P13 W5: no transport, no apply thread to refuse. + inline void RefuseLegacyBufferArmFromApplyThread(const char*) {} #endif }