mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-20 16:31:57 +09:00
Compare commits
27
Commits
b9b14c4775
...
8d3e2317a6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d3e2317a6 | ||
|
|
0b55b55d4d | ||
|
|
642ac891af | ||
|
|
592558f5fc | ||
|
|
0a117243d5 | ||
|
|
344e2f8439 | ||
|
|
91900bdc5e | ||
|
|
b32140e614 | ||
|
|
e44d6ac7da | ||
|
|
8571e0c001 | ||
|
|
7784d6bbf7 | ||
|
|
4aec5621a8 | ||
|
|
4c02279f22 | ||
|
|
e869d18ce8 | ||
|
|
9d1e788597 | ||
|
|
ce5753c883 | ||
|
|
5e65907d63 | ||
|
|
98bf1925aa | ||
|
|
17f1c0b59b | ||
|
|
2522f1803c | ||
|
|
7cde55b1c1 | ||
|
|
2a69f61c88 | ||
|
|
590d74525d | ||
|
|
b57276b88a | ||
|
|
ac25e3323a | ||
|
|
96881f639c | ||
|
|
16ea23c927 |
@@ -29,6 +29,8 @@ option(MOBILEGL_BUILD_DISAGGREGATED "Build the MG_Remote transport layer (two-pr
|
||||
# only decides whether the shims are compiled in.
|
||||
option(MOBILEGL_BUILD_DISAGGREGATED_INPROC "Compile the in-process (one-process, two-role) split shims; implies MOBILEGL_BUILD_DISAGGREGATED" OFF)
|
||||
option(MOBILEGL_BUILD_SERVER_SPIKE "Build the P0 spike-A MobileGLServer delivery-chain executable (Android only)" OFF)
|
||||
option(MOBILEGL_BUILD_EXTMEM_PROBE "Package tools/spikes/extmem_probe as libMobileGLExtmemProbe.so for the trace APK's exec hook (P11 A3, Android only)" OFF)
|
||||
option(MOBILEGL_EXTMEM_PROBE_AS_SERVER "Spike only (P11 B2 step 1): also package the probe as libMobileGLServer.so, the real server as libMobileGLServerReal.so" OFF)
|
||||
# The PipeInputs strangler (ARCHITECTURE.md 9.2). OFF is the pull build and must stay
|
||||
# byte-identical to a tree without either option: MGB_CTX is the live GLContext, no
|
||||
# MGPipe/PipeInputs source is compiled, every MGP_FILL is ((void)0).
|
||||
@@ -616,6 +618,8 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
# P11 A1: the adopt tier settled at the handshake from the knob and the data plane, by
|
||||
# both roles (so SERVER-partition code in the link ratchet, not the client's tracker).
|
||||
MobileGL/MG_Remote/Transport/AdoptTier.cpp
|
||||
# P11 B2: T0 - the client's AHardwareBuffer store and its hop descriptor (both roles).
|
||||
MobileGL/MG_Remote/Transport/AdoptT0.cpp
|
||||
# ---- P5: the three new directories ------------------------------
|
||||
# Wire/ the G3 codec: MGPWireRec_* in and out of SEG_CMD, blobs and
|
||||
# var-tails in and out of SEG_STAGE. [w1]
|
||||
@@ -659,6 +663,8 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
# P11 PAIR: a socket client's control and aux connections paired by the nonce each
|
||||
# presents first (PairBind), not by arrival order - both unix supervisors take pairs here.
|
||||
MobileGL/MG_Remote/Server/PairAcceptor.cpp
|
||||
# P11 B2: T0's Offers on the aux socket, matched to their map_persistent records by seq.
|
||||
MobileGL/MG_Remote/Server/AdoptInbox.cpp
|
||||
MobileGL/MG_Remote/Server/ServerSpawn.cpp
|
||||
# P5f fc: the value frame that replaced the control mailbox's function-pointer payload,
|
||||
# and its codec against protocol.fbs's SurfaceOp/SurfaceReply (the spawn arm's seam).
|
||||
@@ -1105,3 +1111,48 @@ if (ANDROID AND MOBILEGL_BUILD_SERVER_SPIKE)
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (ANDROID AND MOBILEGL_BUILD_EXTMEM_PROBE)
|
||||
# P11 A3 (open question 3): the spike-B external-memory probe, exec'd from the trace
|
||||
# app's own process by the spike hook (`--es mobilegl_spike_spawn
|
||||
# libMobileGLExtmemProbe.so`), so its rows answer for the untrusted_app domain. The
|
||||
# same PIE-executable-named-like-a-library shape as MobileGLServerSpike above; it
|
||||
# links nothing from MobileGL.
|
||||
add_executable(MobileGLExtmemProbe
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/spikes/extmem_probe/extmem_probe.cpp)
|
||||
set_target_properties(MobileGLExtmemProbe PROPERTIES
|
||||
PREFIX "lib"
|
||||
SUFFIX ".so"
|
||||
OUTPUT_NAME "MobileGLExtmemProbe"
|
||||
POSITION_INDEPENDENT_CODE ON)
|
||||
target_compile_options(MobileGLExtmemProbe PRIVATE -fPIE)
|
||||
target_link_options(MobileGLExtmemProbe PRIVATE -pie)
|
||||
target_link_libraries(MobileGLExtmemProbe PRIVATE vulkan EGL GLESv3 android log)
|
||||
if (CMAKE_LIBRARY_OUTPUT_DIRECTORY)
|
||||
set_target_properties(MobileGLExtmemProbe PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
|
||||
endif()
|
||||
if (MOBILEGL_EXTMEM_PROBE_AS_SERVER)
|
||||
# P11 B2 step 1, spike APKs only: MobileGLServerService execs `libMobileGLServer.so
|
||||
# <endpoint> --serve` and B1's broker connects to whatever that listens on, so the probe
|
||||
# takes the server's file name and answers "does a client's AHardwareBuffer cross this
|
||||
# route into the server app" on the real route (tools/spikes/extmem_probe, route mode).
|
||||
if (TARGET MobileGLServer)
|
||||
set_target_properties(MobileGLServer PROPERTIES OUTPUT_NAME "MobileGLServerReal")
|
||||
endif()
|
||||
add_executable(MobileGLExtmemProbeAsServer
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/spikes/extmem_probe/extmem_probe.cpp)
|
||||
set_target_properties(MobileGLExtmemProbeAsServer PROPERTIES
|
||||
PREFIX "lib"
|
||||
SUFFIX ".so"
|
||||
OUTPUT_NAME "MobileGLServer"
|
||||
POSITION_INDEPENDENT_CODE ON)
|
||||
target_compile_options(MobileGLExtmemProbeAsServer PRIVATE -fPIE)
|
||||
target_link_options(MobileGLExtmemProbeAsServer PRIVATE -pie)
|
||||
target_link_libraries(MobileGLExtmemProbeAsServer PRIVATE vulkan EGL GLESv3 android log)
|
||||
if (CMAKE_LIBRARY_OUTPUT_DIRECTORY)
|
||||
set_target_properties(MobileGLExtmemProbeAsServer PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
+15
-6
@@ -500,6 +500,9 @@ namespace MobileGL::MG_Config {
|
||||
Offscreen = 0, // a window surface is the client's own window, as before (the default)
|
||||
Server = 1, // a window surface is the SERVER's window: WindowKind::ServerOwned
|
||||
};
|
||||
// IpcTable::AdoptTier when MOBILEGL_IPC_ADOPT_TIER is unset (or unparseable): T0 by default,
|
||||
// with QUIET fallbacks. Not a tier a user can type - the knob admits 0..2.
|
||||
inline constexpr Uint32 kAdoptTierUnset = 3;
|
||||
struct IpcTable {
|
||||
// MOBILEGL_IPC_SERVER_PATH: where to find libMobileGLServer. P6 consumes it; P5
|
||||
// lands the parse because t1's ctest ENVIRONMENT blocks and add_trace_replay_test's
|
||||
@@ -625,12 +628,18 @@ namespace MobileGL::MG_Config {
|
||||
// poll loop cannot outlive a late report. 0 = every poll crosses, as before P10: the A/B
|
||||
// arm and the red-once of the no-reply gate (FencePollScenario).
|
||||
Uint32 PollEscalate = 64;
|
||||
// MOBILEGL_IPC_ADOPT_TIER: 2 = emulate (T2: client keeps the shadow and pushes), the
|
||||
// only implemented tier and the reason persistent-map-push can be non-zero at all
|
||||
// (R-6). 0 (T0) and 1 (T1) parse and are settled at the handshake (P11 A1,
|
||||
// MG_Remote/Transport/AdoptTier.h): a stream data plane refuses them by name and runs
|
||||
// T2; over shared segments the client dies by name before any record.
|
||||
Uint32 AdoptTier = 2;
|
||||
// MOBILEGL_IPC_ADOPT_TIER, THE ZERO-COPY SWITCH (ruling ID-P11-14, CONTRACT-P11 B2):
|
||||
// UNSET (kAdoptTierUnset, the default since 2026-09-29, the user's decision) = T0 where the
|
||||
// session can run it, T2 QUIETLY where it cannot (MGLOG_D only, still counted);
|
||||
// 0 = T0 asked by name - a T0 this session cannot use (a stream plane, the server's allow
|
||||
// switch, no AHardwareBuffer, a failed server POST) is T2 plus one named line;
|
||||
// 1 = T1, closed - refused by name, then T2; 2 = emulate (T2: the client keeps the shadow
|
||||
// and pushes). Never a Fatal (MG_Remote/Transport/AdoptTier.h).
|
||||
Uint32 AdoptTier = kAdoptTierUnset;
|
||||
// MOBILEGL_IPC_ALLOW_ADOPT_T0 (server): 1 (default) = grant a client's T0 ask when this
|
||||
// platform and the backend's POST self-test allow it; 0 = never grant it (the session
|
||||
// runs T2 and says so). Read by the server role only; kept through ServerSpawn.
|
||||
Uint32 AllowAdoptT0 = 1;
|
||||
// MOBILEGL_IPC_VERB_BARRIER: 1 = the client blocks at every verb boundary until
|
||||
// appliedSeq reaches its emitSeq (R-1). 0 is the negative control: it is EXPECTED to
|
||||
// be red, because 31 of the 63 PipeInputs fields are still pulled from a live
|
||||
|
||||
@@ -433,9 +433,12 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
// torn read rather than a divergence. The batch is therefore off whenever the
|
||||
// shadow comparer is armed.
|
||||
if (MG_Config::Features.PipeVerify) ipc.BatchWaits = 0;
|
||||
// 2 is the only implemented tier (R-6). 0 and 1 parse here and are settled at the
|
||||
// handshake from the data plane (P11 A1, MG_Remote/Transport/AdoptTier.h).
|
||||
ipc.AdoptTier = QueryEnvUint32("MOBILEGL_IPC_ADOPT_TIER", 2, 0, 2);
|
||||
// UNSET is T0 with quiet fallbacks (the default since 2026-09-29); 0 asks for T0 by name, 1 is
|
||||
// refused by name, 2 is T2 - settled at the handshake from the data plane (P11 A1/B2,
|
||||
// MG_Remote/Transport/AdoptTier.h). An unparseable value is warned about and reads as unset.
|
||||
ipc.AdoptTier = QueryEnvUint32("MOBILEGL_IPC_ADOPT_TIER", MG_Config::kAdoptTierUnset, 0, 2);
|
||||
// P11 B2: the server's own T0 allow switch (Config.h).
|
||||
ipc.AllowAdoptT0 = QueryEnvUint32("MOBILEGL_IPC_ALLOW_ADOPT_T0", 1, 0, 1);
|
||||
ipc.VerbBarrier = QueryEnvUint32("MOBILEGL_IPC_VERB_BARRIER", 1, 0, 1);
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §1). The wait rule's A/B, parsed here like every
|
||||
// other IPC knob and armed only where the server publishes kCapRunAheadApply.
|
||||
@@ -530,10 +533,12 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
// log that does not name it makes every run ambiguous about its own configuration.
|
||||
MGLOG_I("Config: IPC ring=%uMiB stage=%uMiB wire-deferred=%uMiB spin=%uus event-wait=%ums "
|
||||
"persistent-block=%uKiB create-window=%u pbo-readback-sync=%u poll-escalate=%u "
|
||||
"adopt-tier=%u verb-barrier=%u run-ahead=%u present-credit=%u control-timeout=%ums "
|
||||
"adopt-tier=%s allow-t0=%u verb-barrier=%u run-ahead=%u present-credit=%u control-timeout=%ums "
|
||||
"cold-start=%ums strict=%d audit=%d role-split-state=%d affinity='%s' surface=%s",
|
||||
ipc.RingMb, ipc.StageMb, ipc.WireDeferredMb, ipc.SpinUs, ipc.EventWaitMs,
|
||||
ipc.PersistentBlockKb, ipc.CreateWindow, ipc.PboReadbackSync, ipc.PollEscalate, ipc.AdoptTier,
|
||||
ipc.PersistentBlockKb, ipc.CreateWindow, ipc.PboReadbackSync, ipc.PollEscalate,
|
||||
ipc.AdoptTier == 0 ? "0" : ipc.AdoptTier == 1 ? "1" : ipc.AdoptTier == 2 ? "2" : "unset(T0)",
|
||||
ipc.AllowAdoptT0,
|
||||
ipc.VerbBarrier, ipc.RunAhead, ipc.PresentCredit, ipc.ControlTimeoutMs, ipc.ColdStartMs,
|
||||
static_cast<int>(ipc.StrictErrors), static_cast<int>(ipc.Audit),
|
||||
static_cast<int>(ipc.RoleSplitState), ipc.ServerAffinity.c_str(),
|
||||
|
||||
@@ -483,7 +483,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
const MG_Pipe::MGPipeHandle handle = MG_Pipe::MGPipeApplier().VerbIndirectBuffer;
|
||||
if (!MG_Pipe::MGPipeHandleIsNull(handle)) {
|
||||
auto* resource = BufferImpl::FindBufferResourceForHandle(handle);
|
||||
const Uint8* const base = resource ? resource->hostBytes : nullptr;
|
||||
const Uint8* const base = resource ? BufferImpl::SplitHostBytes(*resource) : nullptr;
|
||||
const SizeT commandOffset = reinterpret_cast<SizeT>(indirect);
|
||||
if (base == nullptr) {
|
||||
MGLOG_E_ONCE("%s skipped: the verb's indirect buffer {%u, %u} has no staged "
|
||||
@@ -1284,6 +1284,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
||||
#endif
|
||||
ProcessDeferredBufferReleases();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
ProcessDeferredT0Retires(); // P11 B2
|
||||
#endif
|
||||
|
||||
// All buffers we need are:
|
||||
// 1.VBO 2.IBO (if needed) 3.UBO 4.IndirectBuffer (if needed)
|
||||
@@ -1531,6 +1534,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
||||
#endif
|
||||
ProcessDeferredBufferReleases();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
ProcessDeferredT0Retires(); // P11 B2
|
||||
#endif
|
||||
// THE COMPUTE PATH IS THE ONE THAT NEEDS THE FRONTEND-INDEXED UNIFORM PASS, and it
|
||||
// is why the uniform class is emitted at all: compute does NOT go through the
|
||||
// per-program block remap in BindCurrentProgramWithResources, so these are the
|
||||
@@ -9215,7 +9221,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// The staged shadow is the source of truth for CPU reads on this side: a
|
||||
// persistent map's blocks and a shader write's writeback were consumed by the
|
||||
// applier before this verb ran.
|
||||
const Uint8* hostBytes = elementResource ? elementResource->hostBytes : nullptr;
|
||||
const Uint8* hostBytes = elementResource ? BufferImpl::SplitHostBytes(*elementResource) : nullptr;
|
||||
if (hostBytes == nullptr) {
|
||||
MGLOG_E_ONCE("Draw skipped: GL_PRIMITIVE_RESTART with restart index %u needs a CPU-readable copy of "
|
||||
"the bound element array buffer and none is available.",
|
||||
@@ -9532,8 +9538,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
auto* drawResource = BufferImpl::FindBufferResourceForHandle(applierState.VerbIndirectBuffer);
|
||||
auto* paramResource =
|
||||
BufferImpl::FindBufferResourceForHandle(applierState.VerbIndirectParameterBuffer);
|
||||
const Uint8* const drawBytes = drawResource ? drawResource->hostBytes : nullptr;
|
||||
const Uint8* const parameterBytes = paramResource ? paramResource->hostBytes : nullptr;
|
||||
const Uint8* const drawBytes = drawResource ? BufferImpl::SplitHostBytes(*drawResource) : nullptr;
|
||||
const Uint8* const parameterBytes = paramResource ? BufferImpl::SplitHostBytes(*paramResource) : nullptr;
|
||||
if (commandBytes > BufferImpl::ResourceWidthForHandle(applierState.VerbIndirectBuffer)) {
|
||||
MGLOG_E_ONCE("MultiDrawElementsIndirectCount skipped: invalid GL_DRAW_INDIRECT_BUFFER binding or range");
|
||||
return;
|
||||
@@ -9686,8 +9692,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
auto* drawResource = BufferImpl::FindBufferResourceForHandle(applierState.VerbIndirectBuffer);
|
||||
auto* paramResource =
|
||||
BufferImpl::FindBufferResourceForHandle(applierState.VerbIndirectParameterBuffer);
|
||||
const Uint8* const drawBytes = drawResource ? drawResource->hostBytes : nullptr;
|
||||
const Uint8* const parameterBytes = paramResource ? paramResource->hostBytes : nullptr;
|
||||
const Uint8* const drawBytes = drawResource ? BufferImpl::SplitHostBytes(*drawResource) : nullptr;
|
||||
const Uint8* const parameterBytes = paramResource ? BufferImpl::SplitHostBytes(*paramResource) : nullptr;
|
||||
if (commandBytes > BufferImpl::ResourceWidthForHandle(applierState.VerbIndirectBuffer)) {
|
||||
MGLOG_E_ONCE("MultiDrawArraysIndirectCount skipped: invalid GL_DRAW_INDIRECT_BUFFER binding or range");
|
||||
return;
|
||||
|
||||
@@ -30,6 +30,12 @@
|
||||
// emits the record through the client's emit helper instead of hopping a stack struct to the
|
||||
// apply thread.
|
||||
#include <MG_Remote/Client/WireTables.h>
|
||||
// P11 B2 (T0): the client's AHardwareBuffer store - its reference counting and, on Android, the
|
||||
// allocation the POST self-test makes.
|
||||
#include <MG_Remote/Transport/AdoptT0.h>
|
||||
#if defined(__ANDROID__)
|
||||
#include <android/hardware_buffer.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "Utils.h"
|
||||
@@ -1231,6 +1237,77 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
ServerStaged().RequireCoverage(&resource, hostBase, start, end, site);
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// P11 B2 (T0) - WHEN AN IMPORTED STORE'S AHardwareBuffer MAY BE LET GO.
|
||||
//
|
||||
// A T0 store is the client's AHardwareBuffer imported with glBufferStorageExternalEXT
|
||||
// (Ops_H_ImportExternal below). The twin holds its own reference, and every path that
|
||||
// ends the store - a respecify, a destroy, a re-import - deletes the GL id and then
|
||||
// RETIRES the reference here: a fence is inserted after the delete, and the reference is
|
||||
// released only once that fence has signalled, i.e. once every command that could still
|
||||
// read or write the pages has completed on this context's GPU. The client's own
|
||||
// reference ends independently (it releases on respecify/destroy); the pages live until
|
||||
// the last of the two. No link watermark is involved (F-L2): the fence is this server's.
|
||||
//
|
||||
// Swept (non-blocking) at every import, every deferred-release drain and every ensure;
|
||||
// a context loss releases the lot, because the GPU work those fences named ended with
|
||||
// the context. Apply thread only, like every GL call here.
|
||||
// -------------------------------------------------------------------------------
|
||||
struct T0RetiredImport {
|
||||
GLsync fence = nullptr;
|
||||
void* ahb = nullptr;
|
||||
Uint generation = 0;
|
||||
};
|
||||
Vector<T0RetiredImport> g_t0Retired;
|
||||
// T0 twins whose destroy found no current context: Ops_OnDestroy queued them on the
|
||||
// deferred-release list and keeps a second reference here, so the reference is
|
||||
// retired only after that drain deleted the id (ProcessDeferredT0Retires). Guarded by
|
||||
// g_deferredBufferReleasesMutex, like the list it shadows.
|
||||
Vector<SharedPtr<BackendBufferResource>> g_t0DeferredDestroys;
|
||||
std::atomic<Bool> g_hasT0DeferredDestroys{false};
|
||||
Uint64 g_t0ImportsLive = 0;
|
||||
|
||||
void SweepT0Retired(Bool contextGone) {
|
||||
for (SizeT i = 0; i < g_t0Retired.size();) {
|
||||
T0RetiredImport& retired = g_t0Retired[i];
|
||||
const Bool sameContext = !contextGone && retired.generation == g_bufferContextGeneration &&
|
||||
CanTouchGLNow();
|
||||
Bool done = contextGone || retired.generation != g_bufferContextGeneration ||
|
||||
retired.fence == nullptr;
|
||||
if (!done && sameContext && g_GLESFuncs.glClientWaitSync) {
|
||||
const GLenum status = g_GLESFuncs.glClientWaitSync(retired.fence, 0, 0);
|
||||
done = status == GL_ALREADY_SIGNALED || status == GL_CONDITION_SATISFIED ||
|
||||
status == GL_WAIT_FAILED;
|
||||
}
|
||||
if (!done) {
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
if (retired.fence != nullptr && sameContext && g_GLESFuncs.glDeleteSync)
|
||||
g_GLESFuncs.glDeleteSync(retired.fence);
|
||||
MG_Remote::Transport::AdoptT0::ReleaseImported(retired.ahb);
|
||||
retired = g_t0Retired.back();
|
||||
g_t0Retired.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
// Call AFTER the store's GL id is deleted (or known dead): the fence then follows every
|
||||
// command that used it. Clears the twin's reference whatever the context state.
|
||||
void RetireT0Import(GLESBufferResource& resource) {
|
||||
if (resource.externalAhb == nullptr) return;
|
||||
T0RetiredImport retired;
|
||||
retired.ahb = resource.externalAhb;
|
||||
retired.generation = resource.contextGeneration;
|
||||
if (CanTouchGLNow() && resource.contextGeneration == g_bufferContextGeneration &&
|
||||
g_GLESFuncs.glFenceSync) {
|
||||
retired.fence = g_GLESFuncs.glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
||||
}
|
||||
resource.externalAhb = nullptr;
|
||||
if (g_t0ImportsLive > 0) --g_t0ImportsLive;
|
||||
g_t0Retired.push_back(retired);
|
||||
SweepT0Retired(false);
|
||||
}
|
||||
#endif // MOBILEGL_BUILD_DISAGGREGATED
|
||||
|
||||
// The four hostBytes sites read the same in both builds. The non-split expansion is the
|
||||
@@ -2075,6 +2152,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
auto* glesResource = static_cast<GLESBufferResource*>(resource.get());
|
||||
if (glesResource->contextGeneration != g_bufferContextGeneration) {
|
||||
glesResource->id = 0; // id belonged to a destroyed context
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
RetireT0Import(*glesResource); // P11 B2: its GL store died with that context
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if (CanTouchGLNow()) {
|
||||
@@ -2090,9 +2170,19 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
g_GLESFuncs.glDeleteBuffers(1, &glesResource->id);
|
||||
glesResource->id = 0;
|
||||
}
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2: a T0 store's AHardwareBuffer goes only after a fence behind the delete.
|
||||
RetireT0Import(*glesResource);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
const std::lock_guard<std::mutex> lock(g_deferredBufferReleasesMutex);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (glesResource->externalAhb != nullptr) { // P11 B2: retired after the drain deletes it
|
||||
g_t0DeferredDestroys.push_back(resource);
|
||||
g_hasT0DeferredDestroys.store(true, std::memory_order_release);
|
||||
}
|
||||
#endif
|
||||
g_deferredBufferReleases.push_back(std::move(resource));
|
||||
g_hasDeferredBufferReleases.store(true, std::memory_order_release);
|
||||
}
|
||||
@@ -2232,6 +2322,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
resource->id = 0;
|
||||
resource->immutableStorage = false;
|
||||
}
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2: a respecified T0 store ends here on the server's side too. Its
|
||||
// AHardwareBuffer is released only after a fence behind the delete (or at once
|
||||
// when the store's context is already gone) - never under a frame in flight,
|
||||
// however the client's own release (at this respecify) raced it.
|
||||
RetireT0Import(*resource);
|
||||
#endif
|
||||
resource->storageInitialized = false;
|
||||
resource->storageSize = 0;
|
||||
resource->pendingRespecify = true;
|
||||
@@ -2282,6 +2379,26 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
#endif
|
||||
if (!resource) return;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2: A T0 STORE TAKES A SERVER-ORIGINATED WRITE GPU-ORDERED. Its pages are the
|
||||
// client's AHardwareBuffer, so there is no staged copy to refresh and the adopted
|
||||
// early return below ("the coherent map already has the bytes") is false for bytes
|
||||
// the SERVER produced - P9 W1's pack-buffer landing (PipeApplier.cpp
|
||||
// LandReadbackInBuffer) is the one producer, and it would lose its pixels there. They
|
||||
// are queued exactly as a resident SubData is (Ops_H_ResidentSubData): landed after
|
||||
// every command already recorded, before the next one that reads the store.
|
||||
if (resource->externalAhb != nullptr && bytes != nullptr && size != 0) {
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(resource->pendingMutex);
|
||||
auto& write = resource->pendingResidentWrites.emplace_back();
|
||||
write.offset = offset;
|
||||
const auto* source = static_cast<const Uint8*>(bytes);
|
||||
write.bytes.assign(source, source + size);
|
||||
}
|
||||
resource->syncedChangeSerial = ResourceSerialOf(res);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
// M-2: UNDER pendingMutex, because this line runs BEFORE the CanTouchGLNow()
|
||||
// test below - i.e. on the arm D-A2 deliberately keeps reachable off the render
|
||||
// thread - while every reader of hostBytes (Ops_H_Readback's drain, the
|
||||
@@ -2656,6 +2773,319 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return result;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
// ---- P11 B2: T0 - THE CLIENT'S AHardwareBuffer AS A STORE'S RESIDENT TWIN ------------
|
||||
//
|
||||
// The split twin of Ops_H_MapPersistent: where a monolith map_persistent mints a
|
||||
// coherent persistent store (glBufferStorageEXT) and hands its pointer to the frontend,
|
||||
// a T0 map_persistent IMPORTS the pages the client already holds and maps -
|
||||
// glBufferStorageExternalEXT on eglGetNativeClientBufferANDROID(ahb) - and the result
|
||||
// is the SAME resource shape (immutable, persistentMapped, persistentPtr = this
|
||||
// server's coherent map of those pages), so every adopted-store path in this file
|
||||
// applies unchanged: draws bind it with nothing to upload, resident SubData lands
|
||||
// GPU-ordered (DrainResidentWritesNow), a readback drains and waits and posts no
|
||||
// bytes. The R-11 staged copy is dropped: the pages are the client's.
|
||||
//
|
||||
// THE ENTRY POINTS ARE OPTIONAL: neither is in the loader's tables (an EGL function
|
||||
// missing there is MGLOG_F), and eglGetProcAddress hands back live-looking stubs, so
|
||||
// the extension strings decide and the pointers are only then taken.
|
||||
using T0GetNativeClientBufferFn = EGLClientBuffer (*)(const struct AHardwareBuffer*);
|
||||
using T0BufferStorageExternalFn = void (*)(GLenum, GLintptr, GLsizeiptr, EGLClientBuffer, GLbitfield);
|
||||
T0GetNativeClientBufferFn g_t0GetNativeClientBuffer = nullptr;
|
||||
T0BufferStorageExternalFn g_t0BufferStorageExternal = nullptr;
|
||||
constexpr GLbitfield kT0MapReadBit = 0x0001;
|
||||
constexpr GLbitfield kT0MapWriteBit = 0x0002;
|
||||
constexpr GLbitfield kT0StorageFlags =
|
||||
kT0MapReadBit | kT0MapWriteBit | kMapPersistentBit | kMapCoherentBit | kDynamicStorageBit;
|
||||
constexpr GLbitfield kT0MapFlags = kT0MapReadBit | kT0MapWriteBit | kMapPersistentBit | kMapCoherentBit;
|
||||
|
||||
Bool HasExtensionWord(const char* list, const char* word) {
|
||||
if (list == nullptr) return false;
|
||||
const SizeT n = std::strlen(word);
|
||||
for (const char* at = std::strstr(list, word); at != nullptr; at = std::strstr(at + 1, word)) {
|
||||
const Bool startOk = at == list || at[-1] == ' ';
|
||||
const Bool endOk = at[n] == '\0' || at[n] == ' ';
|
||||
if (startOk && endOk) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Bool ResolveT0EntryPoints(String& why) {
|
||||
if (g_t0GetNativeClientBuffer != nullptr && g_t0BufferStorageExternal != nullptr) return true;
|
||||
if (!g_EGLFuncs.eglGetProcAddress || !g_EGLFuncs.eglQueryString || !g_EGLFuncs.eglGetCurrentDisplay ||
|
||||
!g_GLESFuncs.glGetString || !g_GLESFuncs.glMapBufferRange || !g_GLESFuncs.glGenBuffers) {
|
||||
why = "the loader has no eglGetProcAddress/eglQueryString/glGetString/glMapBufferRange";
|
||||
return false;
|
||||
}
|
||||
const char* egl = g_EGLFuncs.eglQueryString(g_EGLFuncs.eglGetCurrentDisplay(), EGL_EXTENSIONS);
|
||||
const char* gl = reinterpret_cast<const char*>(g_GLESFuncs.glGetString(GL_EXTENSIONS));
|
||||
if (!HasExtensionWord(egl, "EGL_ANDROID_get_native_client_buffer")) {
|
||||
why = "EGL_ANDROID_get_native_client_buffer is not advertised";
|
||||
return false;
|
||||
}
|
||||
if (!HasExtensionWord(gl, "GL_EXT_external_buffer") || !HasExtensionWord(gl, "GL_EXT_buffer_storage")) {
|
||||
why = "GL_EXT_external_buffer / GL_EXT_buffer_storage is not advertised";
|
||||
return false;
|
||||
}
|
||||
g_t0GetNativeClientBuffer = reinterpret_cast<T0GetNativeClientBufferFn>(
|
||||
g_EGLFuncs.eglGetProcAddress("eglGetNativeClientBufferANDROID"));
|
||||
g_t0BufferStorageExternal = reinterpret_cast<T0BufferStorageExternalFn>(
|
||||
g_EGLFuncs.eglGetProcAddress("glBufferStorageExternalEXT"));
|
||||
if (g_t0GetNativeClientBuffer == nullptr || g_t0BufferStorageExternal == nullptr) {
|
||||
why = "eglGetProcAddress gave no eglGetNativeClientBufferANDROID / glBufferStorageExternalEXT";
|
||||
g_t0GetNativeClientBuffer = nullptr;
|
||||
g_t0BufferStorageExternal = nullptr;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DrainGLErrors() {
|
||||
if (!g_GLESFuncs.glGetError) return;
|
||||
for (Uint guard = 0; guard < 16 && g_GLESFuncs.glGetError() != GL_NO_ERROR; ++guard) {
|
||||
}
|
||||
}
|
||||
|
||||
// A fresh GL buffer whose storage IS `ahb`, mapped persistent + coherent. 0 on failure
|
||||
// (with `why`); nothing on the resource is touched here. `throwaway` = the POST's own
|
||||
// context is current: bind raw and keep Espryt's binding caches (which describe the
|
||||
// session's context, whose name space this is not) out of it.
|
||||
Uint ImportAhbAsBuffer(void* ahb, Uint64 size, void** outPtr, String& why, Bool throwaway = false) {
|
||||
*outPtr = nullptr;
|
||||
const EGLClientBuffer clientBuffer =
|
||||
g_t0GetNativeClientBuffer(static_cast<const struct AHardwareBuffer*>(ahb));
|
||||
if (clientBuffer == nullptr) {
|
||||
why = "eglGetNativeClientBufferANDROID returned null";
|
||||
return 0;
|
||||
}
|
||||
Uint id = 0;
|
||||
g_GLESFuncs.glGenBuffers(1, &id);
|
||||
if (id == 0) {
|
||||
why = "glGenBuffers gave no name";
|
||||
return 0;
|
||||
}
|
||||
DrainGLErrors();
|
||||
if (throwaway) g_GLESFuncs.glBindBuffer(TempBufferTarget, id);
|
||||
else BindBufferId(TempBufferTarget, id);
|
||||
g_t0BufferStorageExternal(TempBufferTarget, 0, static_cast<GLsizeiptr>(size), clientBuffer,
|
||||
kT0StorageFlags);
|
||||
const GLenum stored = g_GLESFuncs.glGetError ? g_GLESFuncs.glGetError() : GL_NO_ERROR;
|
||||
void* ptr = stored == GL_NO_ERROR
|
||||
? g_GLESFuncs.glMapBufferRange(TempBufferTarget, 0, static_cast<GLsizeiptr>(size), kT0MapFlags)
|
||||
: nullptr;
|
||||
if (ptr == nullptr) {
|
||||
char text[160];
|
||||
std::snprintf(text, sizeof(text), "glBufferStorageExternalEXT -> 0x%04x, map %s", stored,
|
||||
stored == GL_NO_ERROR ? "failed" : "not attempted");
|
||||
why = text;
|
||||
if (!throwaway) {
|
||||
NoteBufferIdDeleted(id);
|
||||
++g_bufferBackendIdGeneration;
|
||||
}
|
||||
g_GLESFuncs.glDeleteBuffers(1, &id);
|
||||
return 0;
|
||||
}
|
||||
*outPtr = ptr;
|
||||
return id;
|
||||
}
|
||||
|
||||
Bool T0Answer(char* out, Uint64 outBytes, Bool ok, const char* fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
std::vsnprintf(out, static_cast<SizeT>(outBytes), fmt, args);
|
||||
va_end(args);
|
||||
return ok;
|
||||
}
|
||||
|
||||
// Installs an imported store on the twin. The caller has retired whatever was there.
|
||||
void InstallT0Store(GLESBufferResource& resource, Uint id, void* ptr, Uint64 size) {
|
||||
resource.id = id;
|
||||
resource.immutableStorage = true;
|
||||
resource.persistentPtr = ptr;
|
||||
resource.persistentMapped = true;
|
||||
resource.storageSize = static_cast<SizeT>(size);
|
||||
resource.storageInitialized = true;
|
||||
resource.pendingRespecify = false;
|
||||
resource.contextGeneration = g_bufferContextGeneration;
|
||||
const std::lock_guard<std::mutex> lock(resource.pendingMutex);
|
||||
resource.pendingRanges.clear();
|
||||
resource.pendingResidentWrites.clear();
|
||||
}
|
||||
|
||||
Bool Ops_H_ImportExternal(MG_Pipe::MGPipeHandle res, void* ahb, Uint64 size) {
|
||||
SweepT0Retired(false);
|
||||
if (!CanTouchGLNow() || size == 0 || ahb == nullptr) return false;
|
||||
String why;
|
||||
if (!ResolveT0EntryPoints(why)) {
|
||||
MGLOG_W_ONCE("Espryt T0: no import on this context - %s", why.c_str());
|
||||
return false;
|
||||
}
|
||||
auto* resource = GetOrCreateBufferResourceForHandle(res);
|
||||
if (resource == nullptr) return false;
|
||||
// IMPORT FIRST, retire second: a refused import leaves the T2 store (and its staged
|
||||
// copy) exactly as it was, so the DECLINED the client gets leaves nothing to repair.
|
||||
void* ptr = nullptr;
|
||||
const Uint id = ImportAhbAsBuffer(ahb, size, &ptr, why);
|
||||
if (id == 0) {
|
||||
MGLOG_W("Espryt T0: store {slot=%u, gen=%u} (%llu bytes) not imported - %s", res.Slot, res.Gen,
|
||||
static_cast<unsigned long long>(size), why.c_str());
|
||||
return false;
|
||||
}
|
||||
if (resource->contextGeneration == g_bufferContextGeneration && resource->id != 0) {
|
||||
NoteBufferIdDeleted(resource->id);
|
||||
// Driver VAOs may have the old id baked into bindings keyed on versions this
|
||||
// replacement does not move (the Ops_H_MapPersistent re-mint's rule).
|
||||
++g_bufferBackendIdGeneration;
|
||||
g_GLESFuncs.glDeleteBuffers(1, &resource->id);
|
||||
}
|
||||
resource->id = 0;
|
||||
RetireT0Import(*resource); // a previous import of this handle, fenced
|
||||
InstallT0Store(*resource, id, ptr, size);
|
||||
MG_Remote::Transport::AdoptT0::AcquireImported(ahb);
|
||||
resource->externalAhb = ahb;
|
||||
++g_t0ImportsLive;
|
||||
// The bytes are the client's pages now; R-11's copy would answer a later drain
|
||||
// with pre-import content.
|
||||
MGL_SERVER_STAGED_DROP(*resource);
|
||||
resource->hostBytes = nullptr;
|
||||
resource->syncedChangeSerial = ResourceSerialOf(res);
|
||||
MGLOG_D("Espryt T0: imported {slot=%u, gen=%u} as buffer %u (%llu bytes); %llu live imports",
|
||||
res.Slot, res.Gen, id, static_cast<unsigned long long>(size),
|
||||
static_cast<unsigned long long>(g_t0ImportsLive));
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool Ops_H_ImportExternalTracked(MG_Pipe::MGPipeHandle res, void* ahb, Uint64 size) {
|
||||
const Bool imported = Ops_H_ImportExternal(res, ahb, size);
|
||||
BumpBufferMutationEpoch();
|
||||
return imported;
|
||||
}
|
||||
|
||||
// THE POST (B2, the standing rule: decide by probe, never by driver name). The AHB API
|
||||
// promises CPU coherence only across an unlock/lock; T0 keeps the client's lock for the
|
||||
// store's life, so the pattern it depends on is exactly what this exercises, on this
|
||||
// context's own driver, before kCapAdoptT0 may be published:
|
||||
// hold - a 64 KiB BLOB allocated and locked by this test, never unlocked while it runs;
|
||||
// read - this server's own host map of the import reads the pattern the CPU wrote
|
||||
// through the held pointer (every hostBytes fallback reads persistentPtr);
|
||||
// gpu - a compute dispatch copies that pattern out of the import (the GPU read) and
|
||||
// fills another region of it (the GPU write);
|
||||
// back - after glFinish the fill is read through the HELD pointer and the copy is
|
||||
// read back from the dispatch's output.
|
||||
// In a throwaway ES 3.1 pbuffer context, so none of this context's state or Espryt's
|
||||
// binding caches is disturbed; the caller's bind is restored before returning.
|
||||
Bool Ops_H_SelfTestExternal(char* whyOut, Uint64 whyBytes) {
|
||||
const auto answer = [&](Bool ok, const char* text, const char* arg = "") {
|
||||
return T0Answer(whyOut, whyBytes, ok, text, arg);
|
||||
};
|
||||
String why;
|
||||
if (!ResolveT0EntryPoints(why)) return answer(false, "%s", why.c_str());
|
||||
if (!g_EGLFuncs.eglChooseConfig || !g_EGLFuncs.eglCreateContext || !g_EGLFuncs.eglMakeCurrent ||
|
||||
!g_EGLFuncs.eglCreatePbufferSurface || !g_GLESFuncs.glCreateShaderProgramv ||
|
||||
!g_GLESFuncs.glDispatchCompute || !g_GLESFuncs.glMemoryBarrier || !g_GLESFuncs.glFinish)
|
||||
return answer(false, "the loader lacks the EGL/GLES 3.1 entry points the test needs");
|
||||
const EGLDisplay display = g_EGLFuncs.eglGetCurrentDisplay();
|
||||
const EGLContext savedContext = g_EGLFuncs.eglGetCurrentContext();
|
||||
const EGLSurface savedDraw = g_EGLFuncs.eglGetCurrentSurface(EGL_DRAW);
|
||||
const EGLSurface savedRead = g_EGLFuncs.eglGetCurrentSurface(EGL_READ);
|
||||
const EGLint configAttribs[] = {EGL_RENDERABLE_TYPE, 0x0040 /*EGL_OPENGL_ES3_BIT*/, EGL_SURFACE_TYPE,
|
||||
EGL_PBUFFER_BIT, EGL_NONE};
|
||||
EGLConfig config = nullptr;
|
||||
EGLint configs = 0;
|
||||
if (!g_EGLFuncs.eglChooseConfig(display, configAttribs, &config, 1, &configs) || configs < 1)
|
||||
return answer(false, "no ES3 pbuffer config for the throwaway context");
|
||||
const EGLint surfaceAttribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
|
||||
const EGLSurface surface = g_EGLFuncs.eglCreatePbufferSurface(display, config, surfaceAttribs);
|
||||
const EGLint contextAttribs[] = {0x3098 /*EGL_CONTEXT_MAJOR_VERSION*/, 3, 0x30FB /*MINOR*/, 1, EGL_NONE};
|
||||
const EGLContext context = surface != EGL_NO_SURFACE
|
||||
? g_EGLFuncs.eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs)
|
||||
: EGL_NO_CONTEXT;
|
||||
const auto restore = [&] {
|
||||
g_EGLFuncs.eglMakeCurrent(display, savedDraw, savedRead, savedContext);
|
||||
if (context != EGL_NO_CONTEXT) g_EGLFuncs.eglDestroyContext(display, context);
|
||||
if (surface != EGL_NO_SURFACE) g_EGLFuncs.eglDestroySurface(display, surface);
|
||||
};
|
||||
if (context == EGL_NO_CONTEXT || !g_EGLFuncs.eglMakeCurrent(display, surface, surface, context)) {
|
||||
restore();
|
||||
return answer(false, "the throwaway ES 3.1 context could not be made current");
|
||||
}
|
||||
|
||||
constexpr Uint64 kBytes = 64 * 1024;
|
||||
constexpr Uint32 kWords = 1024; // one 4 KiB region
|
||||
constexpr Uint32 kFillAtWord = 4 * kWords; // region 4
|
||||
MG_Remote::Transport::AdoptT0::HeldStore held;
|
||||
Vector<Uint32> pattern(kBytes / 4);
|
||||
for (SizeT i = 0; i < pattern.size(); ++i) pattern[i] = 0x5A000000u ^ static_cast<Uint32>(i * 2654435761u);
|
||||
if (!MG_Remote::Transport::AdoptT0::AllocateHeld(kBytes, pattern.data(), held, why)) {
|
||||
restore();
|
||||
return answer(false, "hold: %s", why.c_str());
|
||||
}
|
||||
Bool ok = false;
|
||||
GLuint out = 0, program = 0;
|
||||
void* hostMap = nullptr;
|
||||
const GLuint imported = ImportAhbAsBuffer(held.ahb, kBytes, &hostMap, why, /*throwaway=*/true);
|
||||
char detail[256] = {};
|
||||
if (imported == 0) {
|
||||
std::snprintf(detail, sizeof(detail), "import: %s", why.c_str());
|
||||
} else if (std::memcmp(hostMap, pattern.data(), kWords * 4) != 0) {
|
||||
std::snprintf(detail, sizeof(detail), "read: the server's host map of the import does not "
|
||||
"hold the CPU's pattern");
|
||||
} else {
|
||||
static const char* kSource =
|
||||
"#version 310 es\n"
|
||||
"layout(local_size_x = 64) in;\n"
|
||||
"layout(std430, binding = 0) buffer Ext { uint w[]; } ext;\n"
|
||||
"layout(std430, binding = 1) buffer Out { uint w[]; } outb;\n"
|
||||
"void main() {\n"
|
||||
" uint i = gl_GlobalInvocationID.x;\n"
|
||||
" outb.w[i] = ext.w[i];\n"
|
||||
" ext.w[4096u + i] = 0x6C0FFEE0u ^ i;\n"
|
||||
"}\n";
|
||||
program = g_GLESFuncs.glCreateShaderProgramv(GL_COMPUTE_SHADER, 1, &kSource);
|
||||
GLint linked = 0;
|
||||
if (program != 0) g_GLESFuncs.glGetProgramiv(program, GL_LINK_STATUS, &linked);
|
||||
g_GLESFuncs.glGenBuffers(1, &out);
|
||||
g_GLESFuncs.glBindBuffer(GL_SHADER_STORAGE_BUFFER, out);
|
||||
g_GLESFuncs.glBufferData(GL_SHADER_STORAGE_BUFFER, kWords * 4, nullptr, GL_DYNAMIC_READ);
|
||||
if (!linked) {
|
||||
std::snprintf(detail, sizeof(detail), "gpu: the test's compute program did not link");
|
||||
} else {
|
||||
g_GLESFuncs.glUseProgram(program);
|
||||
g_GLESFuncs.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, imported);
|
||||
g_GLESFuncs.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, out);
|
||||
g_GLESFuncs.glDispatchCompute(kWords / 64, 1, 1);
|
||||
g_GLESFuncs.glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT |
|
||||
0x00004000 /*GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT_EXT*/);
|
||||
g_GLESFuncs.glFinish();
|
||||
Uint32 gpuRead = 0, heldSaw = 0;
|
||||
const auto* heldWords = static_cast<const Uint32*>(held.ptr);
|
||||
for (Uint32 i = 0; i < kWords; ++i)
|
||||
if (heldWords[kFillAtWord + i] == (0x6C0FFEE0u ^ i)) ++heldSaw;
|
||||
g_GLESFuncs.glBindBuffer(GL_SHADER_STORAGE_BUFFER, out);
|
||||
const auto* copied = static_cast<const Uint32*>(g_GLESFuncs.glMapBufferRange(
|
||||
GL_SHADER_STORAGE_BUFFER, 0, kWords * 4, GL_MAP_READ_BIT));
|
||||
if (copied != nullptr) {
|
||||
for (Uint32 i = 0; i < kWords; ++i)
|
||||
if (copied[i] == pattern[i]) ++gpuRead;
|
||||
g_GLESFuncs.glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
|
||||
}
|
||||
ok = gpuRead == kWords && heldSaw == kWords;
|
||||
std::snprintf(detail, sizeof(detail),
|
||||
"64 KiB AHB, lock held throughout: host map read ok, GPU read %u/%u words of "
|
||||
"the CPU's pattern, GPU write seen through the held lock %u/%u words",
|
||||
gpuRead, kWords, heldSaw, kWords);
|
||||
}
|
||||
}
|
||||
if (program != 0) g_GLESFuncs.glDeleteProgram(program);
|
||||
if (out != 0) g_GLESFuncs.glDeleteBuffers(1, &out);
|
||||
if (imported != 0) g_GLESFuncs.glDeleteBuffers(1, &imported);
|
||||
g_GLESFuncs.glFinish();
|
||||
restore();
|
||||
MG_Remote::Transport::AdoptT0::ReleaseHeld(held);
|
||||
return answer(ok, "%s", detail);
|
||||
}
|
||||
#endif // MOBILEGL_BUILD_DISAGGREGATED && __ANDROID__
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// ---- P5c (tx): the TEXTURE half of the resource family, staged server-side --------
|
||||
//
|
||||
@@ -2823,6 +3253,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
.TextureSubData = Ops_H_TextureSubData,
|
||||
.TextureRespecify = Ops_H_TextureRespecify,
|
||||
.TextureDestroy = Ops_H_TextureDestroy,
|
||||
#if defined(__ANDROID__)
|
||||
// P11 B2 (T0). Android only: nowhere else is there an AHardwareBuffer to import.
|
||||
.ImportExternal = Ops_H_ImportExternalTracked,
|
||||
.SelfTestExternal = Ops_H_SelfTestExternal,
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
#endif // MOBILEGL_PIPE_PUSH
|
||||
@@ -3253,6 +3688,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// but with the same recycled-identity failure mode: a new context's allocator may
|
||||
// hand out a {slot, gen} the old one's store still answers for.
|
||||
MG_Remote::Server::ServerStagedTexture().DropAll();
|
||||
// P11 B2: every retired T0 import's fence named work on the context that just ended,
|
||||
// so all of them let go now. LIVE imports keep their reference: the next ensure
|
||||
// imports them again on the new context (EnsureBufferResourceForHandle).
|
||||
ProcessDeferredT0Retires();
|
||||
SweepT0Retired(/*contextGone=*/true);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@@ -3289,6 +3729,33 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2: the T0 half of the deferred-release drain, run right after it at both sync
|
||||
// points (ProcessDeferredBufferReleases itself moves verbatim, G5). Retired imports whose
|
||||
// fence signalled let go of their AHardwareBuffer; a deferred T0 destroy is retired once
|
||||
// the drain deleted its id (the fence then follows the delete) or its context is gone.
|
||||
void ProcessDeferredT0Retires() {
|
||||
if (!g_t0Retired.empty()) SweepT0Retired(false);
|
||||
if (!g_hasT0DeferredDestroys.load(std::memory_order_acquire)) return;
|
||||
Vector<SharedPtr<BackendBufferResource>> ready;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(g_deferredBufferReleasesMutex);
|
||||
for (SizeT i = 0; i < g_t0DeferredDestroys.size();) {
|
||||
auto* r = static_cast<GLESBufferResource*>(g_t0DeferredDestroys[i].get());
|
||||
if (r->id == 0 || r->contextGeneration != g_bufferContextGeneration) {
|
||||
ready.push_back(std::move(g_t0DeferredDestroys[i]));
|
||||
g_t0DeferredDestroys[i] = std::move(g_t0DeferredDestroys.back());
|
||||
g_t0DeferredDestroys.pop_back();
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
g_hasT0DeferredDestroys.store(!g_t0DeferredDestroys.empty(), std::memory_order_release);
|
||||
}
|
||||
for (auto& resource : ready) RetireT0Import(*static_cast<GLESBufferResource*>(resource.get()));
|
||||
}
|
||||
#endif
|
||||
|
||||
GLESBufferResource* GetBufferResource(MG_State::GLState::BufferObject* bufferObject) {
|
||||
if (!bufferObject) return nullptr;
|
||||
return static_cast<GLESBufferResource*>(bufferObject->GetBackendResource().get());
|
||||
@@ -3466,6 +3933,29 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
!ServerStaged().HasShadow(resource)) {
|
||||
resource->hostBytes = nullptr;
|
||||
}
|
||||
#if defined(__ANDROID__)
|
||||
// P11 B2: A T0 STORE OUTLIVES ITS CONTEXT. Its pages are the client's
|
||||
// AHardwareBuffer, which this twin still holds, so the store is imported again on
|
||||
// the new context - the client keeps writing through the same pointer and nothing
|
||||
// has to be re-sent. A refusal here leaves the twin without a store and says so.
|
||||
if (resource->externalAhb != nullptr) {
|
||||
String why;
|
||||
void* ptr = nullptr;
|
||||
const Uint64 size = ResourceWidthOf(res);
|
||||
const Uint id = ResolveT0EntryPoints(why) ? ImportAhbAsBuffer(resource->externalAhb, size, &ptr, why)
|
||||
: 0;
|
||||
if (id != 0) {
|
||||
InstallT0Store(*resource, id, ptr, size);
|
||||
MGLOG_I("Espryt T0: store {slot=%u, gen=%u} re-imported on the new context (%llu bytes)",
|
||||
res.Slot, res.Gen, static_cast<unsigned long long>(size));
|
||||
} else {
|
||||
MGLOG_E("Espryt T0: store {slot=%u, gen=%u} could not be re-imported after a context loss - "
|
||||
"%s; the store has no GPU backing",
|
||||
res.Slot, res.Gen, why.c_str());
|
||||
RetireT0Import(*resource);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1042,6 +1042,15 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// the legacy arm did; this member exists for the drains that have no object, which
|
||||
// in P3a is the readback flush and the fp64 narrowing.
|
||||
const Uint8* hostBytes = nullptr;
|
||||
#endif
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2 (T0): the client's AHardwareBuffer this store IS - imported with
|
||||
// glBufferStorageExternalEXT, so `id` is immutable, persistentMapped and
|
||||
// persistentPtr is this server's own coherent map of the client's pages. The
|
||||
// reference is this twin's own, released only after a fence that follows the
|
||||
// store's last use has signalled (RetireT0Import). Survives an ES context loss:
|
||||
// the next ensure re-imports it. Null for every store T0 did not adopt.
|
||||
void* externalAhb = nullptr;
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -1104,6 +1113,16 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
void RequireStagedCoverage(GLESBufferResource& resource, const Uint8* hostBase, SizeT start,
|
||||
SizeT end, const char* site);
|
||||
|
||||
// P11 B2: THE CPU-READABLE BYTES OF A SPLIT SERVER'S BUFFER TWIN, for the handle-arm
|
||||
// readers that have no frontend object (indirect commands, primitive-restart
|
||||
// substitution, the multi-draw index rebase): the R-11 staged copy, or - for a T0 store,
|
||||
// which has none - this server's own coherent map of the client's AHardwareBuffer, read
|
||||
// exactly as the monolith arm reads the adopted map through MappedData().
|
||||
inline const Uint8* SplitHostBytes(const GLESBufferResource& resource) {
|
||||
if (resource.hostBytes != nullptr) return resource.hostBytes;
|
||||
return resource.externalAhb != nullptr ? static_cast<const Uint8*>(resource.persistentPtr) : nullptr;
|
||||
}
|
||||
|
||||
// M-3's WHOLE-STORE predicate, and the GUARD every caller of RequireStagedCoverage over
|
||||
// a whole-store read has to carry: true when the application DECLARED the store's
|
||||
// content (glBufferData(size, data)), so a coverage gap is a missing record; false when
|
||||
@@ -1267,6 +1286,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// Deletes GL buffers whose owning frontend objects died (possibly on a
|
||||
// thread without a current ES context). Called from draw-time sync.
|
||||
void ProcessDeferredBufferReleases();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2: the T0 half of that drain - run right after it (retired AHardwareBuffers).
|
||||
void ProcessDeferredT0Retires();
|
||||
#endif
|
||||
|
||||
// glBindBuffer with a redundant-bind cache for GL_ARRAY_BUFFER.
|
||||
void BindBufferId(GLenum target, Uint id);
|
||||
|
||||
@@ -199,7 +199,7 @@ namespace MobileGL::MG_Backend::DirectGLES::MultiDrawImpl {
|
||||
auto* resource = BufferImpl::FindBufferResourceForHandle(res);
|
||||
if (resource == nullptr) RefuseMissingIndexBufferRecord(entry, res, "backend resource");
|
||||
view.Size = BufferImpl::ResourceWidthForHandle(res);
|
||||
view.HostBytes = resource->hostBytes;
|
||||
view.HostBytes = BufferImpl::SplitHostBytes(*resource);
|
||||
if (view.HostBytes != nullptr && IndexBufferRecordHasDefinedContent(st, res)) {
|
||||
BufferImpl::RequireStagedCoverage(*resource, view.HostBytes, 0, view.Size,
|
||||
"multidraw_index_rebase");
|
||||
|
||||
@@ -2784,9 +2784,20 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
|
||||
auto& bindingPoint = MGB_CTX->GetBufferBindingPoint(BufferTarget::Uniform, frontendBinding);
|
||||
const auto& bufferObject = bindingPoint.GetBoundObject();
|
||||
MOBILEGL_ASSERT(bufferObject != nullptr,
|
||||
"ResolveUniformBufferPayload: no UBO bound at frontend binding %u for block '%s'",
|
||||
frontendBinding, program.GetUniformBlockName(static_cast<Uint32>(blockIndex)).c_str());
|
||||
static thread_local Vector<Uint8> paddedUbo;
|
||||
if (bufferObject == nullptr) {
|
||||
// A block the program declares at a point with nothing bound - e.g. its buffer was
|
||||
// deleted while bound, which unbinds it (DeletedBoundBufferScenario). GL leaves what
|
||||
// the shader READS undefined and raises no error; this used to dereference the null
|
||||
// object. The wire arm already answers it with a zeroed block
|
||||
// (ResolveWireUniformBufferPayload), so this one does too.
|
||||
const VkDeviceSize blockSize =
|
||||
static_cast<VkDeviceSize>(program.GetUBOSizeAt(static_cast<Uint32>(blockIndex)));
|
||||
paddedUbo.assign(static_cast<SizeT>(blockSize > 0 ? blockSize : 16), 0);
|
||||
out.payload = paddedUbo.data();
|
||||
out.payloadSize = static_cast<VkDeviceSize>(paddedUbo.size());
|
||||
return true;
|
||||
}
|
||||
bufferObject->SyncPersistentMappedRange();
|
||||
|
||||
MOBILEGL_ASSERT(bufferObject->MappedData() != nullptr && bufferObject->GetSize() != 0,
|
||||
@@ -2819,7 +2830,6 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
outSize = blockSize;
|
||||
outData = bufferObject->MappedData() + static_cast<SizeT>(rangeStart);
|
||||
if (available < blockSize) {
|
||||
static thread_local Vector<Uint8> paddedUbo;
|
||||
paddedUbo.assign(static_cast<SizeT>(blockSize), 0);
|
||||
Memcpy(paddedUbo.data(), outData, static_cast<SizeT>(available));
|
||||
outData = paddedUbo.data();
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
#include "MG_Pipe/MGPipeCallbacks.h"
|
||||
#include "MG_Pipe/PipeApply.h"
|
||||
#include "MG_Remote/Server/StagedShadow.h"
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#include "MG_Remote/Transport/AdoptT0.h"
|
||||
#endif
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
#include <android/hardware_buffer.h>
|
||||
#endif
|
||||
#include <Config.h>
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
@@ -206,6 +212,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// modified ranges. A server pointer is never donated across the wire.
|
||||
.MapPersistent = [](MG_Pipe::MGPipeHandle, Uint64, const void*) -> void* { return nullptr; },
|
||||
.UnmapPersistent = [](MG_Pipe::MGPipeHandle) {},
|
||||
#if defined(__ANDROID__)
|
||||
// P11 B2 (T0): the one door a server pointer is still never donated through stays shut;
|
||||
// what T0 adds is the other direction - the CLIENT's pages imported as the store.
|
||||
.ImportExternal = [](MG_Pipe::MGPipeHandle res, void* ahb, Uint64 size) -> Bool {
|
||||
return WireManager().ImportWireBuffer(res, ahb, size);
|
||||
},
|
||||
.SelfTestExternal = [](char* why, Uint64 whyBytes) -> Bool {
|
||||
return VkBufferManager::SelfTestWireImport(why, whyBytes);
|
||||
},
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
} // namespace
|
||||
@@ -245,7 +261,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// to wait for a submission (DeferredWireRelease), and three lines from now the record
|
||||
// no longer carries it.
|
||||
const Uint64 orphanedUseSerial = resource->lastUseSerial;
|
||||
DeferWireRelease(std::move(resource->buffer), orphanedUseSerial);
|
||||
// P11 B2: a T0 store is ALWAYS released through the serial-gated list (never "at once"),
|
||||
// so the client's AHardwareBuffer outlives every submission that can still name it however
|
||||
// the client's own release (at this respecify) raced the frames in flight.
|
||||
DeferWireRelease(std::move(resource->buffer),
|
||||
resource->imported ? T0ReleaseSerial(orphanedUseSerial) : orphanedUseSerial);
|
||||
resource->imported = false;
|
||||
resource->size = desc.Width;
|
||||
resource->lastUseSerial = 0;
|
||||
resource->lastUseSubmitIndex = 0; // M2 r2: the new store carries no submission yet (B3's stamp is per store)
|
||||
@@ -537,11 +558,23 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
|
||||
void VkBufferManager::ReadbackWireBuffer(MG_Pipe::MGPipeHandle res, Uint64 offset, Uint64 size) {
|
||||
Vector<Uint8> bytes(static_cast<SizeT>(size));
|
||||
if (!ReadWireBuffer(res, offset, size, bytes.data())) {
|
||||
// P11 B2: A T0 STORE'S READBACK IS "DONE, NO BYTES". Its pages are the client's
|
||||
// AHardwareBuffer, so what the client needs before it reads them is this server's GPU
|
||||
// having finished every write to them - the resident copies WriteWireBuffer recorded and
|
||||
// any shader write - and nothing crossing SEG_EVENT. The wait is the store's own host-access
|
||||
// wait (a barrier to host, then the sync point's submission); the reply then says "done".
|
||||
// One death for both shapes: the store could not be made readable.
|
||||
auto* resource = FindWireBuffer(res);
|
||||
const Bool t0 = resource != nullptr && resource->imported;
|
||||
Vector<Uint8> bytes(t0 ? 0 : static_cast<SizeT>(size));
|
||||
if (t0 ? !WaitForWireBufferHostAccess(*resource) : !ReadWireBuffer(res, offset, size, bytes.data())) {
|
||||
MGLOG_F("Magma: Fatal{ResourceUnavailable, \"buffer-readback\"} {slot=%u, gen=%u}", res.Slot, res.Gen);
|
||||
std::abort();
|
||||
}
|
||||
if (t0) {
|
||||
++m_sliceEpochCounter;
|
||||
return;
|
||||
}
|
||||
if (MG_Pipe::gMGPipeCallbacks.OnBufferWriteback == nullptr) {
|
||||
MGLOG_F("Magma: Fatal{ResourceUnavailable, \"buffer-writeback-callback\"}");
|
||||
std::abort();
|
||||
@@ -573,10 +606,305 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
MG_Pipe::gMGPipeCallbacks.OnGpuWritten(res, 1, &range);
|
||||
}
|
||||
|
||||
// ---- P11 B2: T0 - THE CLIENT'S AHardwareBuffer AS A WIRE STORE -----------------------------
|
||||
|
||||
// The serial a T0 store is released under: its last use, or - when no GPU command has named it
|
||||
// since a host-access wait - the current frame's, so the release still waits for the sync
|
||||
// point rather than taking DeferWireRelease's "never named, destroy now" arm. Conservative by
|
||||
// at most one submission.
|
||||
Uint64 VkBufferManager::T0ReleaseSerial(Uint64 lastUseSerial) const {
|
||||
if (lastUseSerial != 0) return lastUseSerial;
|
||||
return m_frameSerial != 0 ? m_frameSerial : 1;
|
||||
}
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
namespace {
|
||||
Int32 T0PickMemoryType(const VkPhysicalDeviceMemoryProperties& props, Uint32 bits,
|
||||
VkMemoryPropertyFlags want) {
|
||||
for (Uint32 i = 0; i < props.memoryTypeCount; ++i) {
|
||||
if ((bits & (1u << i)) != 0 && (props.memoryTypes[i].propertyFlags & want) == want)
|
||||
return static_cast<Int32>(i);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct T0ImportedBuffer {
|
||||
VkBuffer buffer = VK_NULL_HANDLE;
|
||||
VkDeviceMemory memory = VK_NULL_HANDLE;
|
||||
void* mapped = nullptr;
|
||||
Bool coherent = true;
|
||||
};
|
||||
|
||||
void T0DestroyImported(VkDevice device, T0ImportedBuffer& imported) {
|
||||
if (imported.mapped != nullptr) vkUnmapMemory(device, imported.memory);
|
||||
if (imported.buffer != VK_NULL_HANDLE) vkDestroyBuffer(device, imported.buffer, nullptr);
|
||||
if (imported.memory != VK_NULL_HANDLE) vkFreeMemory(device, imported.memory, nullptr);
|
||||
imported = T0ImportedBuffer{};
|
||||
}
|
||||
|
||||
// A VkBuffer on a dedicated allocation IMPORTED from `ahb`, in a host-visible memory type
|
||||
// (coherent preferred), mapped whole. The server's own host map is what WriteWireBuffer's
|
||||
// idle path and every CPU reader of a wire store use, so a type without HOST_VISIBLE is a
|
||||
// refusal, not a degraded import. Nothing is left behind on failure.
|
||||
Bool T0ImportAhb(const VulkanRenderer::WireAhbImport& ctx, void* ahb, Uint64 size, VkBufferUsageFlags usage,
|
||||
T0ImportedBuffer& out, String& why) {
|
||||
out = T0ImportedBuffer{};
|
||||
const auto getProperties =
|
||||
reinterpret_cast<PFN_vkGetAndroidHardwareBufferPropertiesANDROID>(ctx.getAhbProperties);
|
||||
VkAndroidHardwareBufferPropertiesANDROID properties{
|
||||
VK_STRUCTURE_TYPE_ANDROID_HARDWARE_BUFFER_PROPERTIES_ANDROID};
|
||||
VkResult result = getProperties(ctx.device, static_cast<const AHardwareBuffer*>(ahb), &properties);
|
||||
if (result != VK_SUCCESS) {
|
||||
why = "vkGetAndroidHardwareBufferPropertiesANDROID -> " + std::to_string(static_cast<int>(result));
|
||||
return false;
|
||||
}
|
||||
VkExternalMemoryBufferCreateInfo external{VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO};
|
||||
external.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID;
|
||||
VkBufferCreateInfo bufferInfo{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
|
||||
bufferInfo.pNext = &external;
|
||||
bufferInfo.size = size;
|
||||
bufferInfo.usage = usage;
|
||||
bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
result = vkCreateBuffer(ctx.device, &bufferInfo, nullptr, &out.buffer);
|
||||
if (result != VK_SUCCESS) {
|
||||
out.buffer = VK_NULL_HANDLE;
|
||||
why = "vkCreateBuffer(external AHB) -> " + std::to_string(static_cast<int>(result));
|
||||
return false;
|
||||
}
|
||||
Int32 type = T0PickMemoryType(ctx.memory, properties.memoryTypeBits,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
out.coherent = type >= 0;
|
||||
if (type < 0)
|
||||
type = T0PickMemoryType(ctx.memory, properties.memoryTypeBits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
|
||||
if (type < 0) {
|
||||
why = "no host-visible memory type can import it (memoryTypeBits 0x" +
|
||||
std::to_string(properties.memoryTypeBits) + ")";
|
||||
T0DestroyImported(ctx.device, out);
|
||||
return false;
|
||||
}
|
||||
VkMemoryDedicatedAllocateInfo dedicated{VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO};
|
||||
dedicated.buffer = out.buffer;
|
||||
VkImportAndroidHardwareBufferInfoANDROID import{VK_STRUCTURE_TYPE_IMPORT_ANDROID_HARDWARE_BUFFER_INFO_ANDROID};
|
||||
import.buffer = static_cast<AHardwareBuffer*>(ahb);
|
||||
import.pNext = &dedicated;
|
||||
VkMemoryAllocateInfo allocateInfo{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
|
||||
allocateInfo.pNext = &import;
|
||||
allocateInfo.allocationSize = properties.allocationSize;
|
||||
allocateInfo.memoryTypeIndex = static_cast<Uint32>(type);
|
||||
result = vkAllocateMemory(ctx.device, &allocateInfo, nullptr, &out.memory);
|
||||
if (result != VK_SUCCESS) {
|
||||
out.memory = VK_NULL_HANDLE;
|
||||
why = "vkAllocateMemory(import AHB) -> " + std::to_string(static_cast<int>(result));
|
||||
T0DestroyImported(ctx.device, out);
|
||||
return false;
|
||||
}
|
||||
result = vkBindBufferMemory(ctx.device, out.buffer, out.memory, 0);
|
||||
if (result == VK_SUCCESS) result = vkMapMemory(ctx.device, out.memory, 0, VK_WHOLE_SIZE, 0, &out.mapped);
|
||||
if (result != VK_SUCCESS || out.mapped == nullptr) {
|
||||
out.mapped = nullptr;
|
||||
why = "vkBindBufferMemory/vkMapMemory -> " + std::to_string(static_cast<int>(result));
|
||||
T0DestroyImported(ctx.device, out);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
Bool VkBufferManager::ImportWireBuffer(MG_Pipe::MGPipeHandle res, void* ahb, Uint64 size) {
|
||||
#if defined(__ANDROID__)
|
||||
auto* resource = FindWireBuffer(res);
|
||||
if (resource == nullptr || ahb == nullptr || size == 0 || size != resource->size) return false;
|
||||
VulkanRenderer::WireAhbImport ctx;
|
||||
if (pVulkanRenderer == nullptr || !pVulkanRenderer->GetWireAhbImport(ctx)) {
|
||||
MGLOG_W_ONCE("Magma T0: this device did not take VK_ANDROID_external_memory_android_hardware_buffer");
|
||||
return false;
|
||||
}
|
||||
VkBufferUsageFlags usage = kPersistentBackedUsage | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
if (m_initInfo.transformFeedbackUsageEnabled) usage |= VK_BUFFER_USAGE_TRANSFORM_FEEDBACK_BUFFER_BIT_EXT;
|
||||
T0ImportedBuffer imported;
|
||||
String why;
|
||||
if (!T0ImportAhb(ctx, ahb, size, usage, imported, why)) {
|
||||
MGLOG_W("Magma T0: store {slot=%u, gen=%u} (%llu bytes) not imported - %s", res.Slot, res.Gen,
|
||||
static_cast<unsigned long long>(size), why.c_str());
|
||||
return false;
|
||||
}
|
||||
// The T2 store it replaces goes the way a respecify's does (and any draw still naming it
|
||||
// keeps it until its submission completes).
|
||||
DeferWireRelease(std::move(resource->buffer), resource->lastUseSerial);
|
||||
MG_Remote::Transport::AdoptT0::AcquireImported(ahb);
|
||||
resource->buffer.AdoptExternal(ctx.device, imported.buffer, imported.memory, size, imported.mapped,
|
||||
imported.coherent, ahb);
|
||||
resource->imported = true;
|
||||
resource->lastUseSerial = 0;
|
||||
resource->lastUseSubmitIndex = 0;
|
||||
resource->gpuWritesPending = false;
|
||||
// The whole store holds bytes the client supplied (its AHB, seeded from its shadow).
|
||||
resource->stagedCoverage.clear();
|
||||
MG_Remote::Server::StagedShadowStore::CoverageAdd(resource->stagedCoverage, 0, static_cast<SizeT>(size));
|
||||
++m_sliceEpochCounter;
|
||||
++m_wireStoreCount;
|
||||
NoteWireStorePeaks();
|
||||
PublishWireReclaimGauges();
|
||||
MGLOG_D("Magma T0: imported {slot=%u, gen=%u} (%llu bytes, %s memory)", res.Slot, res.Gen,
|
||||
static_cast<unsigned long long>(size), imported.coherent ? "coherent" : "non-coherent");
|
||||
return true;
|
||||
#else
|
||||
(void)res;
|
||||
(void)ahb;
|
||||
(void)size;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// THE POST (B2; decided by probe, never by driver name). The AHB API promises CPU coherence only
|
||||
// across an unlock/lock, and T0 holds the client's lock for the store's life, so this exercises
|
||||
// that pattern on THIS device before kCapAdoptT0 may be published:
|
||||
// hold - a 64 KiB BLOB allocated and locked by the test, never unlocked while it runs;
|
||||
// read - this server's own host map of the import reads what the CPU wrote through the lock;
|
||||
// gpu - one submission copies that pattern out of the import (the GPU read) and fills another
|
||||
// region of it (the GPU write), then a transfer->host barrier and a fence wait;
|
||||
// back - the fill is read through the HELD pointer, the copy from a host-visible staging buffer.
|
||||
Bool VkBufferManager::SelfTestWireImport(char* whyOut, Uint64 whyBytes) {
|
||||
const auto answer = [&](Bool ok, const String& text) {
|
||||
std::snprintf(whyOut, static_cast<SizeT>(whyBytes), "%s", text.c_str());
|
||||
return ok;
|
||||
};
|
||||
#if defined(__ANDROID__)
|
||||
VulkanRenderer::WireAhbImport ctx;
|
||||
if (pVulkanRenderer == nullptr || !pVulkanRenderer->GetWireAhbImport(ctx))
|
||||
return answer(false, "the device did not take VK_ANDROID_external_memory_android_hardware_buffer");
|
||||
constexpr Uint64 kBytes = 64 * 1024;
|
||||
constexpr Uint32 kWords = 1024; // one 4 KiB region
|
||||
constexpr Uint64 kFillAt = 4 * 4096; // region 4
|
||||
constexpr Uint32 kFillWord = 0x6C0FFEE0u;
|
||||
Vector<Uint32> pattern(kBytes / 4);
|
||||
for (SizeT i = 0; i < pattern.size(); ++i) pattern[i] = 0x5A000000u ^ static_cast<Uint32>(i * 2654435761u);
|
||||
MG_Remote::Transport::AdoptT0::HeldStore held;
|
||||
String why;
|
||||
if (!MG_Remote::Transport::AdoptT0::AllocateHeld(kBytes, pattern.data(), held, why))
|
||||
return answer(false, "hold: " + why);
|
||||
T0ImportedBuffer imported, staging;
|
||||
VkCommandPool pool = VK_NULL_HANDLE;
|
||||
VkFence fence = VK_NULL_HANDLE;
|
||||
String verdict;
|
||||
Bool ok = false;
|
||||
do {
|
||||
if (!T0ImportAhb(ctx, held.ahb, kBytes,
|
||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT |
|
||||
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
|
||||
imported, why)) {
|
||||
verdict = "import: " + why;
|
||||
break;
|
||||
}
|
||||
if (!imported.coherent) {
|
||||
VkMappedMemoryRange range{VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE};
|
||||
range.memory = imported.memory;
|
||||
range.size = VK_WHOLE_SIZE;
|
||||
vkInvalidateMappedMemoryRanges(ctx.device, 1, &range);
|
||||
}
|
||||
if (std::memcmp(imported.mapped, pattern.data(), kWords * 4) != 0) {
|
||||
verdict = "read: the server's host map of the import does not hold the CPU's pattern";
|
||||
break;
|
||||
}
|
||||
// A host-visible staging buffer for the GPU read's destination.
|
||||
VkBufferCreateInfo stagingInfo{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
|
||||
stagingInfo.size = kWords * 4;
|
||||
stagingInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
stagingInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
if (vkCreateBuffer(ctx.device, &stagingInfo, nullptr, &staging.buffer) != VK_SUCCESS) {
|
||||
staging.buffer = VK_NULL_HANDLE;
|
||||
verdict = "staging buffer";
|
||||
break;
|
||||
}
|
||||
VkMemoryRequirements requirements{};
|
||||
vkGetBufferMemoryRequirements(ctx.device, staging.buffer, &requirements);
|
||||
const Int32 stagingType = T0PickMemoryType(ctx.memory, requirements.memoryTypeBits,
|
||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
|
||||
VkMemoryAllocateInfo stagingAlloc{VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
|
||||
stagingAlloc.allocationSize = requirements.size;
|
||||
stagingAlloc.memoryTypeIndex = static_cast<Uint32>(stagingType < 0 ? 0 : stagingType);
|
||||
if (stagingType < 0 || vkAllocateMemory(ctx.device, &stagingAlloc, nullptr, &staging.memory) != VK_SUCCESS ||
|
||||
vkBindBufferMemory(ctx.device, staging.buffer, staging.memory, 0) != VK_SUCCESS ||
|
||||
vkMapMemory(ctx.device, staging.memory, 0, VK_WHOLE_SIZE, 0, &staging.mapped) != VK_SUCCESS) {
|
||||
verdict = "staging memory";
|
||||
break;
|
||||
}
|
||||
std::memset(staging.mapped, 0, kWords * 4);
|
||||
VkCommandPoolCreateInfo poolInfo{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO};
|
||||
poolInfo.queueFamilyIndex = ctx.queueFamily;
|
||||
poolInfo.flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT;
|
||||
VkCommandBuffer commands = VK_NULL_HANDLE;
|
||||
VkCommandBufferAllocateInfo commandInfo{VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO};
|
||||
commandInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
commandInfo.commandBufferCount = 1;
|
||||
VkFenceCreateInfo fenceInfo{VK_STRUCTURE_TYPE_FENCE_CREATE_INFO};
|
||||
if (vkCreateCommandPool(ctx.device, &poolInfo, nullptr, &pool) != VK_SUCCESS) {
|
||||
pool = VK_NULL_HANDLE;
|
||||
verdict = "command pool";
|
||||
break;
|
||||
}
|
||||
commandInfo.commandPool = pool;
|
||||
if (vkAllocateCommandBuffers(ctx.device, &commandInfo, &commands) != VK_SUCCESS ||
|
||||
vkCreateFence(ctx.device, &fenceInfo, nullptr, &fence) != VK_SUCCESS) {
|
||||
verdict = "command buffer / fence";
|
||||
break;
|
||||
}
|
||||
VkCommandBufferBeginInfo begin{VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
|
||||
begin.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
vkBeginCommandBuffer(commands, &begin);
|
||||
VkMemoryBarrier hostWrites{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
|
||||
hostWrites.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT;
|
||||
hostWrites.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
vkCmdPipelineBarrier(commands, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1,
|
||||
&hostWrites, 0, nullptr, 0, nullptr);
|
||||
VkBufferCopy region{0, 0, kWords * 4};
|
||||
vkCmdCopyBuffer(commands, imported.buffer, staging.buffer, 1, ®ion);
|
||||
vkCmdFillBuffer(commands, imported.buffer, kFillAt, kWords * 4, kFillWord);
|
||||
VkMemoryBarrier toHost{VK_STRUCTURE_TYPE_MEMORY_BARRIER};
|
||||
toHost.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
toHost.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
|
||||
vkCmdPipelineBarrier(commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 1, &toHost,
|
||||
0, nullptr, 0, nullptr);
|
||||
vkEndCommandBuffer(commands);
|
||||
VkSubmitInfo submit{VK_STRUCTURE_TYPE_SUBMIT_INFO};
|
||||
submit.commandBufferCount = 1;
|
||||
submit.pCommandBuffers = &commands;
|
||||
if (vkQueueSubmit(ctx.queue, 1, &submit, fence) != VK_SUCCESS ||
|
||||
vkWaitForFences(ctx.device, 1, &fence, VK_TRUE, 2'000'000'000ull) != VK_SUCCESS) {
|
||||
verdict = "gpu: the submission did not complete within 2 s";
|
||||
break;
|
||||
}
|
||||
Uint32 gpuRead = 0, heldSaw = 0;
|
||||
const auto* copied = static_cast<const Uint32*>(staging.mapped);
|
||||
const auto* heldWords = static_cast<const Uint32*>(held.ptr);
|
||||
for (Uint32 i = 0; i < kWords; ++i) {
|
||||
if (copied[i] == pattern[i]) ++gpuRead;
|
||||
if (heldWords[kFillAt / 4 + i] == kFillWord) ++heldSaw;
|
||||
}
|
||||
ok = gpuRead == kWords && heldSaw == kWords;
|
||||
verdict = "64 KiB AHB, lock held throughout: host map read ok (" +
|
||||
String(imported.coherent ? "coherent" : "non-coherent") + " memory), GPU read " +
|
||||
std::to_string(gpuRead) + "/1024 words of the CPU's pattern, GPU write seen through the "
|
||||
"held lock " + std::to_string(heldSaw) + "/1024 words";
|
||||
} while (false);
|
||||
if (fence != VK_NULL_HANDLE) vkDestroyFence(ctx.device, fence, nullptr);
|
||||
if (pool != VK_NULL_HANDLE) vkDestroyCommandPool(ctx.device, pool, nullptr);
|
||||
T0DestroyImported(ctx.device, staging);
|
||||
T0DestroyImported(ctx.device, imported);
|
||||
MG_Remote::Transport::AdoptT0::ReleaseHeld(held);
|
||||
return answer(ok, verdict);
|
||||
#else
|
||||
return answer(false, "no AHardwareBuffer on this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void VkBufferManager::DestroyWireBuffer(MG_Pipe::MGPipeHandle res) {
|
||||
const auto found = m_wireBuffers.find(WireBufferKey(res));
|
||||
if (found == m_wireBuffers.end()) return;
|
||||
DeferWireRelease(std::move(found->second.buffer), found->second.lastUseSerial);
|
||||
DeferWireRelease(std::move(found->second.buffer),
|
||||
found->second.imported ? T0ReleaseSerial(found->second.lastUseSerial)
|
||||
: found->second.lastUseSerial); // P11 B2, as Respecify
|
||||
m_wireBuffers.erase(found);
|
||||
++m_sliceEpochCounter;
|
||||
PublishWireReclaimGauges();
|
||||
|
||||
@@ -134,6 +134,15 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
void FlushWireBuffer(MG_Pipe::MGPipeHandle res, Uint64 offset, Uint64 size, const void* bytes);
|
||||
void ReadbackWireBuffer(MG_Pipe::MGPipeHandle res, Uint64 offset, Uint64 size);
|
||||
void DestroyWireBuffer(MG_Pipe::MGPipeHandle res);
|
||||
// P11 B2 (T0): make the client's AHardwareBuffer `ahb` (a BLOB of `size` bytes) buffer
|
||||
// `res`'s store - a VkBuffer on memory imported through
|
||||
// VK_ANDROID_external_memory_android_hardware_buffer, host-visible and mapped like every
|
||||
// wire store, so every wire path (draw binds, WriteWireBuffer's ordered copy, CPU readers)
|
||||
// applies unchanged. The T2 store it replaces goes through DeferWireRelease. False = not
|
||||
// imported (the T2 store is untouched and the client is DECLINED).
|
||||
Bool ImportWireBuffer(MG_Pipe::MGPipeHandle res, void* ahb, Uint64 size);
|
||||
// The POST self-test of the sustained-lock pattern on this device (see the definition).
|
||||
static Bool SelfTestWireImport(char* why, Uint64 whyBytes);
|
||||
#endif
|
||||
|
||||
// Recreate all per-frame transient arenas
|
||||
@@ -245,12 +254,17 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// Only ranges actually submitted by resource_subdata are covered. No
|
||||
// shadow is retained: flush cannot replay stale bytes over GPU writes.
|
||||
Vector<Range1D> stagedCoverage;
|
||||
// P11 B2 (T0): `buffer` is the client's imported AHardwareBuffer. Its readback posts
|
||||
// no bytes (the client reads its own pages once the wait below it is done).
|
||||
Bool imported = false;
|
||||
};
|
||||
static Uint64 WireBufferKey(MG_Pipe::MGPipeHandle res) {
|
||||
return (static_cast<Uint64>(res.Gen) << 32) | res.Slot;
|
||||
}
|
||||
WireBufferResource* FindWireBuffer(MG_Pipe::MGPipeHandle res);
|
||||
Bool WaitForWireBufferHostAccess(WireBufferResource& resource);
|
||||
// P11 B2: the serial a T0 store's release waits behind (never "destroy at once").
|
||||
Uint64 T0ReleaseSerial(Uint64 lastUseSerial) const;
|
||||
|
||||
// P7 wave 4 (M2), ID-P7-27: THE WIRE ARM'S ORPHANS NEED A RECLAIM THAT IS NOT A FRAME
|
||||
// BOUNDARY.
|
||||
|
||||
@@ -8,13 +8,45 @@
|
||||
|
||||
#include "VkBufferObject.h"
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#include <MG_Remote/Transport/AdoptT0.h>
|
||||
#endif
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
void VkBufferObject::MoveExternalFrom(VkBufferObject& other) {
|
||||
m_device = other.m_device;
|
||||
m_externalMemory = other.m_externalMemory;
|
||||
m_externalAhb = other.m_externalAhb;
|
||||
m_externalCoherent = other.m_externalCoherent;
|
||||
other.m_device = VK_NULL_HANDLE;
|
||||
other.m_externalMemory = VK_NULL_HANDLE;
|
||||
other.m_externalAhb = nullptr;
|
||||
other.m_externalCoherent = true;
|
||||
}
|
||||
|
||||
void VkBufferObject::AdoptExternal(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize size,
|
||||
void* mapped, Bool coherent, void* ahb) {
|
||||
Destroy();
|
||||
m_device = device;
|
||||
m_buffer = buffer;
|
||||
m_externalMemory = memory;
|
||||
m_mappedData = mapped;
|
||||
m_size = size;
|
||||
m_externalCoherent = coherent;
|
||||
m_externalAhb = ahb;
|
||||
}
|
||||
#endif
|
||||
|
||||
VkBufferObject::VkBufferObject(VkBufferObject&& other) noexcept {
|
||||
m_allocator = other.m_allocator;
|
||||
m_buffer = other.m_buffer;
|
||||
m_allocation = other.m_allocation;
|
||||
m_mappedData = other.m_mappedData;
|
||||
m_size = other.m_size;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MoveExternalFrom(other);
|
||||
#endif
|
||||
|
||||
other.m_allocator = nullptr;
|
||||
other.m_buffer = VK_NULL_HANDLE;
|
||||
@@ -35,6 +67,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
m_allocation = other.m_allocation;
|
||||
m_mappedData = other.m_mappedData;
|
||||
m_size = other.m_size;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MoveExternalFrom(other);
|
||||
#endif
|
||||
|
||||
other.m_allocator = nullptr;
|
||||
other.m_buffer = VK_NULL_HANDLE;
|
||||
@@ -89,6 +124,24 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
|
||||
void VkBufferObject::Destroy() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (m_externalMemory != VK_NULL_HANDLE) {
|
||||
// P11 B2 (T0): an imported AHardwareBuffer store. Reached through the wire arm's
|
||||
// deferred release, i.e. once no submission can still name it.
|
||||
if (m_mappedData != nullptr) vkUnmapMemory(m_device, m_externalMemory);
|
||||
if (m_buffer != VK_NULL_HANDLE) vkDestroyBuffer(m_device, m_buffer, nullptr);
|
||||
vkFreeMemory(m_device, m_externalMemory, nullptr);
|
||||
MG_Remote::Transport::AdoptT0::ReleaseImported(m_externalAhb);
|
||||
m_mappedData = nullptr;
|
||||
m_buffer = VK_NULL_HANDLE;
|
||||
m_externalMemory = VK_NULL_HANDLE;
|
||||
m_externalAhb = nullptr;
|
||||
m_device = VK_NULL_HANDLE;
|
||||
m_externalCoherent = true;
|
||||
m_size = 0;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
Unmap();
|
||||
if (m_allocator != nullptr && m_buffer != VK_NULL_HANDLE && m_allocation != nullptr) {
|
||||
vmaDestroyBuffer(m_allocator, m_buffer, m_allocation);
|
||||
@@ -117,6 +170,10 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
|
||||
void VkBufferObject::Unmap() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// An imported store stays mapped for its life (Destroy unmaps it).
|
||||
if (m_externalMemory != VK_NULL_HANDLE) return;
|
||||
#endif
|
||||
if (!IsValid() || m_mappedData == nullptr) {
|
||||
m_mappedData = nullptr;
|
||||
return;
|
||||
@@ -143,6 +200,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
|
||||
Memcpy(static_cast<Uint8*>(mapped) + offset, data, static_cast<SizeT>(size));
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (m_externalMemory != VK_NULL_HANDLE) {
|
||||
if (m_externalCoherent) return true;
|
||||
VkMappedMemoryRange range{VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE};
|
||||
range.memory = m_externalMemory;
|
||||
range.offset = 0;
|
||||
range.size = VK_WHOLE_SIZE;
|
||||
return vkFlushMappedMemoryRanges(m_device, 1, &range) == VK_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
const VkResult flushResult = vmaFlushAllocation(m_allocator, m_allocation, offset, size);
|
||||
if (flushResult != VK_SUCCESS) {
|
||||
MGLOG_E_ONCE("VkBufferObject::Upload failed: vmaFlushAllocation returned %d", flushResult);
|
||||
@@ -167,6 +234,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
if (resolvedSize == 0) {
|
||||
return true;
|
||||
}
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (m_externalMemory != VK_NULL_HANDLE) {
|
||||
if (m_externalCoherent) return true;
|
||||
VkMappedMemoryRange range{VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE};
|
||||
range.memory = m_externalMemory;
|
||||
range.offset = 0;
|
||||
range.size = VK_WHOLE_SIZE;
|
||||
return vkInvalidateMappedMemoryRanges(m_device, 1, &range) == VK_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
const VkResult result = vmaInvalidateAllocation(m_allocator, m_allocation, offset, resolvedSize);
|
||||
if (result != VK_SUCCESS) {
|
||||
|
||||
@@ -64,7 +64,25 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
void* GetMappedData() const { return m_mappedData; }
|
||||
Bool IsMapped() const { return m_mappedData != nullptr; }
|
||||
Bool IsValid() const { return m_allocator != nullptr && m_buffer != VK_NULL_HANDLE && m_allocation != nullptr; }
|
||||
Bool IsValid() const {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (m_externalMemory != VK_NULL_HANDLE) return m_buffer != VK_NULL_HANDLE;
|
||||
#endif
|
||||
return m_allocator != nullptr && m_buffer != VK_NULL_HANDLE && m_allocation != nullptr;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2 (T0): a store whose memory is NOT this allocator's - a client's AHardwareBuffer
|
||||
// imported with VK_ANDROID_external_memory_android_hardware_buffer into `memory` (a
|
||||
// dedicated allocation bound to `buffer`, mapped persistently at `mapped`). It behaves
|
||||
// like any mapped store (GetSlice, Upload, Invalidate), and Destroy frees the buffer and
|
||||
// the memory and drops `ahb` - which is why the store goes through the wire arm's
|
||||
// serial-gated deferred release like every other: the AHardwareBuffer is let go only once
|
||||
// no submission can still name it. `coherent` = the memory type is HOST_COHERENT.
|
||||
void AdoptExternal(VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize size,
|
||||
void* mapped, Bool coherent, void* ahb);
|
||||
Bool IsExternal() const { return m_externalMemory != VK_NULL_HANDLE; }
|
||||
#endif
|
||||
|
||||
private:
|
||||
VmaAllocator m_allocator = nullptr;
|
||||
@@ -72,5 +90,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
VmaAllocation m_allocation = nullptr;
|
||||
void* m_mappedData = nullptr;
|
||||
VkDeviceSize m_size = 0;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
VkDevice m_device = VK_NULL_HANDLE;
|
||||
VkDeviceMemory m_externalMemory = VK_NULL_HANDLE;
|
||||
void* m_externalAhb = nullptr;
|
||||
Bool m_externalCoherent = true;
|
||||
void MoveExternalFrom(VkBufferObject& other);
|
||||
#endif
|
||||
};
|
||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||
|
||||
@@ -15333,6 +15333,30 @@ void main() {
|
||||
// P7 gate 5 (g5-msprobe): which multisample depth/stencil resolve arm goes first is measured
|
||||
// once the device exists (ArmWireDepthResolveOrder, below), not keyed on the vendor.
|
||||
m_wirePreferShaderDepthResolve = false;
|
||||
// P11 B2 (T0): a client's AHardwareBuffer imported as a wire buffer store. Wire arms, on
|
||||
// Android, whenever the device advertises the extension - not per session: the device is
|
||||
// created once per server and a later session asking T0 must find it able. Enabling it
|
||||
// changes no T2 behaviour; only an import uses it. The 1.0-era dependencies are core at the
|
||||
// 1.1 this device is created at, and are enabled too when advertised (the spike's set).
|
||||
m_wireAhbImport = false;
|
||||
m_wireGetAhbProperties = nullptr;
|
||||
#if defined(__ANDROID__)
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith &&
|
||||
m_physicalDevice.properties.apiVersion >= VK_API_VERSION_1_1 &&
|
||||
IsExtensionSupported(availableExtensions, VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME) &&
|
||||
IsExtensionSupported(availableExtensions, VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME)) {
|
||||
m_wireAhbImport = true;
|
||||
for (const char* name : {VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME,
|
||||
VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME, VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME,
|
||||
VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME,
|
||||
VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME,
|
||||
VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME,
|
||||
VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, VK_KHR_MAINTENANCE_1_EXTENSION_NAME}) {
|
||||
if (IsExtensionSupported(availableExtensions, name))
|
||||
EnableOptionalDeviceExtension(availableExtensions, enabledDeviceExtensions, name);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if ((descriptorIndexingCore || descriptorIndexingExtension) && getPhysicalDeviceFeatures2 != nullptr &&
|
||||
getPhysicalDeviceProperties2 != nullptr) {
|
||||
@@ -15892,6 +15916,11 @@ void main() {
|
||||
m_wireCreateRenderPass2 = reinterpret_cast<PFN_vkCreateRenderPass2>(
|
||||
vkGetDeviceProcAddr(m_device, wireDepthResolveCore ? "vkCreateRenderPass2" : "vkCreateRenderPass2KHR"));
|
||||
}
|
||||
if (m_wireAhbImport) {
|
||||
m_wireGetAhbProperties =
|
||||
reinterpret_cast<void*>(vkGetDeviceProcAddr(m_device, "vkGetAndroidHardwareBufferPropertiesANDROID"));
|
||||
if (m_wireGetAhbProperties == nullptr) m_wireAhbImport = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
s_vkCmdDrawIndexedIndirectCount = reinterpret_cast<PFNDrawIndexedIndirectCountFunc>(
|
||||
@@ -16733,6 +16762,19 @@ void main() {
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
Bool VulkanRenderer::GetWireAhbImport(WireAhbImport& out) const {
|
||||
out = WireAhbImport{};
|
||||
if (!m_wireAhbImport || m_device == VK_NULL_HANDLE || m_wireGetAhbProperties == nullptr) return false;
|
||||
out.device = m_device;
|
||||
out.queue = m_graphicsQueue;
|
||||
out.queueFamily = static_cast<Uint32>(m_physicalDevice.queueFamilies.graphicsFamily);
|
||||
vkGetPhysicalDeviceMemoryProperties(m_physicalDevice.handle, &out.memory);
|
||||
out.getAhbProperties = m_wireGetAhbProperties;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
Bool VulkanRenderer::IsDrawIndirectCountExtensionEnabled() const {
|
||||
return m_drawIndirectCountExtensionEnabled;
|
||||
}
|
||||
|
||||
@@ -160,6 +160,17 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// GetSyncPointSubmitIndex(), which answers m_submitCounter when nothing is recorded -
|
||||
// true for a fence taken at that instant, wrong for work about to be recorded.
|
||||
Uint64 GetWireNextSubmitIndex() const { return m_submitCounter + 1; }
|
||||
// P11 B2 (T0): what importing a client's AHardwareBuffer as a wire buffer store needs from
|
||||
// this device. False when the device did not take VK_ANDROID_external_memory_android_
|
||||
// hardware_buffer at creation (not Android, not advertised, or a monolith device).
|
||||
struct WireAhbImport {
|
||||
VkDevice device = VK_NULL_HANDLE;
|
||||
VkQueue queue = VK_NULL_HANDLE;
|
||||
Uint32 queueFamily = 0;
|
||||
VkPhysicalDeviceMemoryProperties memory{};
|
||||
void* getAhbProperties = nullptr; // PFN_vkGetAndroidHardwareBufferPropertiesANDROID
|
||||
};
|
||||
Bool GetWireAhbImport(WireAhbImport& out) const;
|
||||
#endif
|
||||
|
||||
// FrameContext::IRecordingObserver: prepares the frame's timer-query
|
||||
@@ -574,6 +585,10 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// target unwritten while the shader control resolved - the shader arm then resolves
|
||||
// first and the render-pass arm is the fallback (P7 gate 5, g5-msprobe).
|
||||
Bool m_wirePreferShaderDepthResolve = false;
|
||||
// P11 B2 (T0): the device took the AHardwareBuffer import extensions at creation, and the
|
||||
// one entry point the import needs (PFN_vkGetAndroidHardwareBufferPropertiesANDROID).
|
||||
Bool m_wireAhbImport = false;
|
||||
void* m_wireGetAhbProperties = nullptr;
|
||||
// Runs the probe (memoized per device identity) and sets the member above. Called at the end of
|
||||
// device creation, after ArmPrimGenReroute: it records on m_graphicsQueue.
|
||||
void ArmWireDepthResolveOrder();
|
||||
|
||||
@@ -146,6 +146,7 @@ add_executable(MobileGLIntegrationTest
|
||||
Scenarios/LayeredTextureReadbackScenario.cpp
|
||||
Scenarios/AtomicCounterScenario.cpp
|
||||
Scenarios/LargeArenaAdoptionScenario.cpp
|
||||
Scenarios/DeletedBoundBufferScenario.cpp
|
||||
Scenarios/SsboArrayDynamicIndexScenario.cpp
|
||||
Scenarios/StorageBufferRegrowScenario.cpp
|
||||
Scenarios/SpirvShaderBinaryScenario.cpp
|
||||
@@ -2039,10 +2040,16 @@ set(MGL_ITEST_SPLIT_SERVER_PATH "${CMAKE_BINARY_DIR}/libMobileGLServer.so")
|
||||
# only by ConfigLoader's Espryt feature block, so on DirectVulkan it would be a parsed-and-
|
||||
# ignored name, and tier 2's informational Magma replay of these registrations wants the two
|
||||
# backends' arms to differ only where the product differs.
|
||||
#
|
||||
# P11 B2: MOBILEGL_ITEST_REQUIRE_GPU=1 IS PINNED here and on the SPAWN list below, as the Magma
|
||||
# split/spawn lists and the Espryt TCP list already pin it. Without it a handshake-time Fatal in
|
||||
# the harness's forked pre-flight turns every case into a SKIP, which ctest counts as a pass in
|
||||
# `-L integration-split` / `-L integration-spawn` (only the gate's integration-gpu passes, which
|
||||
# export it job-wide, caught one - and entries without that label were never covered at all).
|
||||
mgl_itest_join_environment(MGL_ITEST_GLES_SPLIT_ENVIRONMENT
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc"
|
||||
"MOBILEGL_IPC_SERVER_PATH=${MGL_ITEST_SPLIT_SERVER_PATH}" "MGITEST_SPLIT_LANE=1"
|
||||
"MOBILEGL_ESPRYT_ENABLE_TEXTURE_VIEW=1"
|
||||
"MOBILEGL_ESPRYT_ENABLE_TEXTURE_VIEW=1" "MOBILEGL_ITEST_REQUIRE_GPU=1"
|
||||
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
|
||||
|
||||
# The two counting lanes, one per transport, and they are a PAIR: exit gate E3(c) asks that the
|
||||
@@ -2114,7 +2121,7 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
mgl_itest_join_environment(MGL_ITEST_GLES_SPAWN_ENVIRONMENT
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=spawn"
|
||||
"MOBILEGL_IPC_SERVER_PATH=${MGL_ITEST_SPLIT_SERVER_PATH}" "MGITEST_SPLIT_LANE=1"
|
||||
"MOBILEGL_ESPRYT_ENABLE_TEXTURE_VIEW=1"
|
||||
"MOBILEGL_ESPRYT_ENABLE_TEXTURE_VIEW=1" "MOBILEGL_ITEST_REQUIRE_GPU=1"
|
||||
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
|
||||
|
||||
# A single supervisor serves one session at a time. Fixture teardown also reaps a
|
||||
@@ -2464,6 +2471,37 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
# adopt-tier-refusal cases skip here for want of their lane markers. The Magma arms are the
|
||||
# gated `Arena.` block beside `Pbo.` / `Fence.` below, plus the Buffers lane.
|
||||
mgl_itest_register_split_arms("LargeArenaAdoptionScenario.*" "")
|
||||
# P11 B2 addendum: A BUFFER DELETED WHILE BOUND TO AN INDEXED POINT (storage, uniform, atomic
|
||||
# counter, transform feedback), then its slot reused at a newer generation and a draw and a
|
||||
# dispatch that declare the point. The monolith half is the ambient DirectGLES./DirectVulkan.
|
||||
# entries; Magma's three arms are the `DeletedBound.` block beside `Arena.` below.
|
||||
mgl_itest_register_split_arms("DeletedBoundBufferScenario.*" "")
|
||||
# ...and the repro it came from, kept as a regression: the two arena cases in ONE process (the
|
||||
# harness has one context per process, so the first case's storage binding outlives it). ctest
|
||||
# runs one case per process everywhere else, which is how this stayed hidden; add_test because
|
||||
# gtest_discover_tests registers cases one at a time. A PLAIN list for add_test: the joined
|
||||
# environments are escaped for gtest_discover_tests' PROPERTIES (see SpawnLane.EventForfeitPeer).
|
||||
foreach(mglItestPairArm IN ITEMS Split Spawn Tcp)
|
||||
string(TOLOWER "${mglItestPairArm}" mglItestPairArmLower)
|
||||
string(TOUPPER "${mglItestPairArm}" mglItestPairArmUpper)
|
||||
set(mglItestPairProperties)
|
||||
if(mglItestPairArm STREQUAL "Tcp")
|
||||
set(mglItestPairProperties FIXTURES_REQUIRED mobilegl-tcp RESOURCE_LOCK mobilegl-tcp)
|
||||
endif()
|
||||
string(REPLACE "\\;" ";" mglItestPairEnv "${MGL_ITEST_GLES_${mglItestPairArmUpper}_ENVIRONMENT}")
|
||||
list(APPEND mglItestPairEnv "MGITEST_PERSISTENT_MAP_ARM=emulated"
|
||||
"MOBILEGL_LOG_FILE_PATH=${CMAKE_CURRENT_BINARY_DIR}/split-logs/DirectGLES.${mglItestPairArm}.ArenaPairInOneProcess.log")
|
||||
set(mglItestPairName "DirectGLES.${mglItestPairArm}.LargeArenaAdoptionScenario.GpuWriteThenTheTierCaseInOneProcess")
|
||||
add_test(NAME "${mglItestPairName}"
|
||||
COMMAND MobileGLIntegrationTest
|
||||
"--gtest_filter=LargeArenaAdoptionScenario.GpuWriteIntoTheArenaIsReadBack:LargeArenaAdoptionScenario.TheArenaLandsInTheTierItsLaneDeclares"
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties("${mglItestPairName}" PROPERTIES
|
||||
LABELS "integration-gpu;integration-${mglItestPairArmLower}"
|
||||
TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
ENVIRONMENT "${mglItestPairEnv}"
|
||||
${mglItestPairProperties})
|
||||
endforeach()
|
||||
# P11 A1 (CONTRACT-P11 §1): the tcp arm with MOBILEGL_IPC_ADOPT_TIER=0. A stream refuses the
|
||||
# tier by name at the client's handshake and runs T2, so the whole scenario is green here and
|
||||
# AStreamSessionRefusesTheAdoptTierOnceByName reads exactly one refusal line. TCP ONLY by
|
||||
@@ -2483,6 +2521,41 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
)
|
||||
list(APPEND MGL_SPLIT_ARM_TEST_LISTS "MGL_SPLIT_ARM_TESTS_${MGL_SPLIT_ARM_INDEX}")
|
||||
math(EXPR MGL_SPLIT_ARM_INDEX "${MGL_SPLIT_ARM_INDEX} + 1")
|
||||
# P11 B2 (CONTRACT-P11 B2): THE SHARED-SEGMENT ARMS WITH MOBILEGL_IPC_ADOPT_TIER=0, which A1 made
|
||||
# die at the handshake and B2 turned into an ASK. A host has no AHardwareBuffer, so the server
|
||||
# refuses T0 by name at its first native bind, publishes no kCapAdoptT0, and the client falls
|
||||
# back to T2 with one named line at its first map_persistent: every case green, the arena
|
||||
# emulated (SplitLogPaths declares it), ASessionThatCannotRunT0FallsBackToT2OnceByName reading
|
||||
# the two lines. `.AdoptT0Disallowed.` is the same on the spawn arm with the server's allow switch
|
||||
# off - which also proves MOBILEGL_IPC_ALLOW_ADOPT_T0 survives ServerSpawn's environment scrub.
|
||||
foreach(mglT0Arm IN ITEMS Split Spawn)
|
||||
string(TOUPPER "${mglT0Arm}" mglT0ArmUpper)
|
||||
string(TOLOWER "${mglT0Arm}" mglT0ArmLower)
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX "DirectGLES.${mglT0Arm}.AdoptTier0."
|
||||
TEST_LIST "MGL_SPLIT_ARM_TESTS_${MGL_SPLIT_ARM_INDEX}"
|
||||
TEST_FILTER "LargeArenaAdoptionScenario.*"
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES
|
||||
LABELS "integration-gpu\;integration-${mglT0ArmLower}"
|
||||
TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
ENVIRONMENT "${MGL_ITEST_GLES_${mglT0ArmUpper}_ENVIRONMENT}\;MOBILEGL_IPC_ADOPT_TIER=0\;MGITEST_ADOPT_T0_FALLBACK=no AHardwareBuffer"
|
||||
)
|
||||
list(APPEND MGL_SPLIT_ARM_TEST_LISTS "MGL_SPLIT_ARM_TESTS_${MGL_SPLIT_ARM_INDEX}")
|
||||
math(EXPR MGL_SPLIT_ARM_INDEX "${MGL_SPLIT_ARM_INDEX} + 1")
|
||||
endforeach()
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX "DirectGLES.Spawn.AdoptT0Disallowed."
|
||||
TEST_LIST "MGL_SPLIT_ARM_TESTS_${MGL_SPLIT_ARM_INDEX}"
|
||||
TEST_FILTER "LargeArenaAdoptionScenario.ASessionThatCannotRunT0FallsBackToT2OnceByName:LargeArenaAdoptionScenario.TheArenaLandsInTheTierItsLaneDeclares"
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES
|
||||
LABELS "integration-gpu\;integration-spawn"
|
||||
TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
ENVIRONMENT "${MGL_ITEST_GLES_SPAWN_ENVIRONMENT}\;MOBILEGL_IPC_ADOPT_TIER=0\;MOBILEGL_IPC_ALLOW_ADOPT_T0=0\;MGITEST_ADOPT_T0_FALLBACK=disallowed"
|
||||
)
|
||||
list(APPEND MGL_SPLIT_ARM_TEST_LISTS "MGL_SPLIT_ARM_TESTS_${MGL_SPLIT_ARM_INDEX}")
|
||||
math(EXPR MGL_SPLIT_ARM_INDEX "${MGL_SPLIT_ARM_INDEX} + 1")
|
||||
|
||||
# ---- P3b/P4b espryt D1 slice 1: THE ORPHANED XFB CAPTURE TARGET -------------------------
|
||||
#
|
||||
@@ -2558,7 +2631,7 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
mgl_itest_magma_arm_shape(${mglItestDsArm})
|
||||
string(TOLOWER "${mglItestDsArm}" mglItestDsArmLower)
|
||||
mgl_itest_join_environment(mglItestDsEnvironment
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MGITEST_SPLIT_LANE=1"
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MGITEST_SPLIT_LANE=1" "MOBILEGL_ITEST_REQUIRE_GPU=1"
|
||||
"MOBILEGL_ESPRYT_FORCE_DS_READBACK_EMULATION=1"
|
||||
${mglItestArmTransportEnv} ${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
@@ -2757,7 +2830,7 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
"MultiDrawScenario.*:IndexedDrawFamilyScenario.MultiDraw*-MultiDrawScenario.ClientSideIndicesBatchMatchesUnrolledDraws")
|
||||
foreach(mglItestMultiDrawTier IN LISTS MGL_SPLIT_MULTIDRAW_TIERS)
|
||||
mgl_itest_join_environment(MGL_ITEST_GLES_SPLIT_MULTIDRAW_ENVIRONMENT
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc"
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc" "MOBILEGL_ITEST_REQUIRE_GPU=1"
|
||||
"MOBILEGL_IPC_SERVER_PATH=${MGL_ITEST_SPLIT_SERVER_PATH}" "MGITEST_SPLIT_LANE=1"
|
||||
"MOBILEGL_ESPRYT_MULTIDRAW_MODE=${mglItestMultiDrawTier}"
|
||||
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
|
||||
@@ -3030,7 +3103,7 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
set(mglD2Locks "${mglD2LogName}\;mobilegl-tcp")
|
||||
endif()
|
||||
mgl_itest_join_environment(MGL_D2_TUS_ENV_${mglD2Arm}
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" ${mglD2Transport} "MGITEST_SPLIT_LANE=1"
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" ${mglD2Transport} "MGITEST_SPLIT_LANE=1" "MOBILEGL_ITEST_REQUIRE_GPU=1"
|
||||
"MGITEST_TEXTURE_UPLOAD_SHAPE_LANE=1" "MOBILEGL_PIPE_PUSH=0x1fff"
|
||||
"MOBILEGL_PIPE_STATS=1" "MOBILEGL_PIPE_STATS_PERIOD=1"
|
||||
"MOBILEGL_ESPRYT_ENABLE_TEXTURE_VIEW=1"
|
||||
@@ -3158,7 +3231,7 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
# lane's number. pmap == 0 here means MGPipeApplyMapPersistent handed back a pointer, which is
|
||||
# exit gate E3(d) failing, and under inproc that failure is invisible in pixels.
|
||||
mgl_itest_join_environment(MGL_ITEST_GLES_SPLIT_PMAP_ARM_ENVIRONMENT
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc"
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc" "MOBILEGL_ITEST_REQUIRE_GPU=1"
|
||||
"MOBILEGL_IPC_SERVER_PATH=${MGL_ITEST_SPLIT_SERVER_PATH}" "MGITEST_SPLIT_LANE=1"
|
||||
"MGITEST_PMAP_LANE=1" "MGITEST_PERSISTENT_MAP_ARM=emulated"
|
||||
"MOBILEGL_PIPE_STATS=1" "MOBILEGL_PIPE_STATS_PERIOD=1"
|
||||
@@ -3195,7 +3268,7 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
# small ring, not that the small ring bit. The gap is named in t1-v1.md's debts rather than
|
||||
# left for someone to discover from a green.
|
||||
mgl_itest_join_environment(MGL_ITEST_GLES_SPLIT_SMALL_RING_ENVIRONMENT
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc"
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc" "MOBILEGL_ITEST_REQUIRE_GPU=1"
|
||||
"MOBILEGL_IPC_SERVER_PATH=${MGL_ITEST_SPLIT_SERVER_PATH}" "MGITEST_SPLIT_LANE=1"
|
||||
"MGITEST_SMALL_RING_LANE=1" "MOBILEGL_IPC_RING_MB=1" "MOBILEGL_IPC_STAGE_MB=1"
|
||||
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
|
||||
@@ -3242,7 +3315,7 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
# An entry that cannot fail for the reason it exists is worse than none (R-16), so this lane
|
||||
# names the arm it is for in its own prefix. The F1. lane sets the same precedent.
|
||||
mgl_itest_join_environment(MGL_ITEST_GLES_SPLIT_STRICT_ENVIRONMENT
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc"
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc" "MOBILEGL_ITEST_REQUIRE_GPU=1"
|
||||
"MOBILEGL_IPC_SERVER_PATH=${MGL_ITEST_SPLIT_SERVER_PATH}" "MGITEST_SPLIT_LANE=1"
|
||||
"MOBILEGL_IPC_STRICT_ERRORS=1"
|
||||
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
|
||||
@@ -3864,21 +3937,57 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
${mglItestArmProperties}
|
||||
ENVIRONMENT "${mglItestMagmaBandEnvironment}\;MGITEST_PERSISTENT_MAP_ARM=emulated\;MOBILEGL_LOG_FILE_PATH=${CMAKE_CURRENT_BINARY_DIR}/p11-arena${mglItestArmLogTag}-${arenaCase}.log")
|
||||
endforeach()
|
||||
# P11 A1 (CONTRACT-P11 §1): the tcp arm with MOBILEGL_IPC_ADOPT_TIER=0 - refused by name at
|
||||
# the client's handshake, T2, the scenario green. TCP ONLY by construction (over shared
|
||||
# segments the knob dies at the handshake); spawn_lane_parity.py names the tail in
|
||||
# MAGMA_TCP_ONLY.
|
||||
# P11 B2 addendum: DeletedBoundBufferScenario on Magma's three arms, same flavour (the
|
||||
# Espryt arms come from mgl_itest_register_split_arms). Before the frontend fix Magma did
|
||||
# not die: the stale handle resolved to no wire buffer and the draw / dispatch declaring
|
||||
# the point was dropped - which these cases' markers catch.
|
||||
foreach(deletedCase AStorageBufferDeletedWhileBoundLeavesNoStaleBinding
|
||||
AUniformBufferDeletedWhileBoundLeavesNoStaleBinding
|
||||
AnAtomicCounterBufferDeletedWhileBoundLeavesNoStaleBinding
|
||||
ATransformFeedbackBufferDeletedWhileBoundLeavesNoStaleBinding)
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX "DirectVulkan.${mglItestArm}.DeletedBound."
|
||||
TEST_FILTER "DeletedBoundBufferScenario.${deletedCase}"
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES LABELS "${mglItestMagmaLabels}" TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
${mglItestArmProperties}
|
||||
ENVIRONMENT "${mglItestMagmaBandEnvironment}\;MOBILEGL_LOG_FILE_PATH=${CMAKE_CURRENT_BINARY_DIR}/p11-deleted-bound${mglItestArmLogTag}-${deletedCase}.log")
|
||||
endforeach()
|
||||
# ...and the one-process arena pair (the Espryt half is beside mgl_itest_register_split_arms).
|
||||
string(REPLACE "\\;" ";" mglItestPairEnv "${mglItestMagmaBandEnvironment}")
|
||||
list(APPEND mglItestPairEnv "MGITEST_PERSISTENT_MAP_ARM=emulated"
|
||||
"MOBILEGL_LOG_FILE_PATH=${CMAKE_CURRENT_BINARY_DIR}/p11-arena-pair${mglItestArmLogTag}.log")
|
||||
string(REPLACE "\\;" ";" mglItestPairLabels "${mglItestMagmaLabels}")
|
||||
set(mglItestPairName "DirectVulkan.${mglItestArm}.Arena.LargeArenaAdoptionScenario.GpuWriteThenTheTierCaseInOneProcess")
|
||||
add_test(NAME "${mglItestPairName}"
|
||||
COMMAND MobileGLIntegrationTest
|
||||
"--gtest_filter=LargeArenaAdoptionScenario.GpuWriteIntoTheArenaIsReadBack:LargeArenaAdoptionScenario.TheArenaLandsInTheTierItsLaneDeclares"
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties("${mglItestPairName}" PROPERTIES
|
||||
LABELS "${mglItestPairLabels}" TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
ENVIRONMENT "${mglItestPairEnv}"
|
||||
${mglItestArmProperties})
|
||||
# P11 A1 + B2 (CONTRACT-P11 §1, B2): MOBILEGL_IPC_ADOPT_TIER=0 on every arm, one case set.
|
||||
# On tcp a stream refuses the tier by name at the client's handshake (A1, the stream case
|
||||
# reads the line); over shared segments (split, spawn) the knob ASKS T0, a host has no
|
||||
# AHardwareBuffer, and the session falls back to T2 by name (B2, the fallback case reads
|
||||
# both lines). Each arm's marker makes the other arm's case skip, so the three arms carry
|
||||
# the same names and spawn_lane_parity.py compares them like any other lane.
|
||||
if(mglItestArm STREQUAL "Tcp")
|
||||
foreach(arenaCase IN LISTS MGL_ITEST_ARENA_CASES ITEMS AStreamSessionRefusesTheAdoptTierOnceByName)
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX "DirectVulkan.Tcp.AdoptTier0."
|
||||
TEST_FILTER "LargeArenaAdoptionScenario.${arenaCase}"
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES LABELS "${mglItestMagmaLabels}" TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
${mglItestArmProperties}
|
||||
ENVIRONMENT "${mglItestMagmaBandEnvironment}\;MOBILEGL_IPC_ADOPT_TIER=0\;MGITEST_ADOPT_TIER_REFUSAL=T0\;MGITEST_PERSISTENT_MAP_ARM=emulated\;MOBILEGL_LOG_FILE_PATH=${CMAKE_CURRENT_BINARY_DIR}/p11-adopt-tier0-tcp-${arenaCase}.log")
|
||||
endforeach()
|
||||
set(mglItestAdoptTier0Env "MGITEST_ADOPT_TIER_REFUSAL=T0")
|
||||
else()
|
||||
set(mglItestAdoptTier0Env "MGITEST_ADOPT_T0_FALLBACK=no AHardwareBuffer")
|
||||
endif()
|
||||
foreach(arenaCase IN LISTS MGL_ITEST_ARENA_CASES ITEMS AStreamSessionRefusesTheAdoptTierOnceByName
|
||||
ASessionThatCannotRunT0FallsBackToT2OnceByName)
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX "DirectVulkan.${mglItestArm}.AdoptTier0."
|
||||
TEST_FILTER "LargeArenaAdoptionScenario.${arenaCase}"
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES LABELS "${mglItestMagmaLabels}" TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
${mglItestArmProperties}
|
||||
ENVIRONMENT "${mglItestMagmaBandEnvironment}\;MOBILEGL_IPC_ADOPT_TIER=0\;${mglItestAdoptTier0Env}\;MGITEST_PERSISTENT_MAP_ARM=emulated\;MOBILEGL_LOG_FILE_PATH=${CMAKE_CURRENT_BINARY_DIR}/p11-adopt-tier0${mglItestArmLogTag}-${arenaCase}.log")
|
||||
endforeach()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
@@ -4425,7 +4534,7 @@ endif()
|
||||
# disaggregated section above, so keeping this one textually apart lets all three merge cleanly.
|
||||
if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
mgl_itest_join_environment(MGL_ITEST_GLES_SPLIT_STRICT_ARMING_ENVIRONMENT
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc"
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc" "MOBILEGL_ITEST_REQUIRE_GPU=1"
|
||||
"MOBILEGL_IPC_SERVER_PATH=${MGL_ITEST_SPLIT_SERVER_PATH}" "MGITEST_SPLIT_LANE=1"
|
||||
"MGITEST_STRICT_ARMING_LANE=1"
|
||||
"MOBILEGL_PIPE_STATS=1" "MOBILEGL_PIPE_STATS_PERIOD=1"
|
||||
@@ -4484,7 +4593,7 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
target_sources(MobileGLIntegrationTest PRIVATE
|
||||
Scenarios/DualBlockScenario.cpp Harness/DualBlockPeek.cpp)
|
||||
mgl_itest_join_environment(MGL_ITEST_GLES_DUALBLOCK_ENVIRONMENT
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc"
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc" "MOBILEGL_ITEST_REQUIRE_GPU=1"
|
||||
"MOBILEGL_IPC_SERVER_PATH=${MGL_ITEST_SPLIT_SERVER_PATH}" "MGITEST_SPLIT_LANE=1"
|
||||
"MOBILEGL_IPC_RUN_AHEAD=0"
|
||||
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
|
||||
@@ -4522,7 +4631,7 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
set(p5f_rsp_label "${mglItestMagmaLabels}")
|
||||
endif()
|
||||
mgl_itest_join_environment(p5f_rsp_environment
|
||||
"MOBILEGL_BACKEND_TYPE=${backend}" "MGITEST_SPLIT_LANE=1"
|
||||
"MOBILEGL_BACKEND_TYPE=${backend}" "MGITEST_SPLIT_LANE=1" "MOBILEGL_ITEST_REQUIRE_GPU=1"
|
||||
"MGITEST_P5F_RSP_LANE=1" "MOBILEGL_PIPE_STATS=1" "MOBILEGL_PIPE_STATS_PERIOD=1"
|
||||
"MOBILEGL_LOG_FILE_PATH=${CMAKE_CURRENT_BINARY_DIR}/p5f-rsp-${backend}${mglItestArmLogTag}.log"
|
||||
${MGL_ITEST_CAPABILITY_ENV} ${p5f_rsp_base_env} ${mglItestArmTransportEnv})
|
||||
|
||||
@@ -0,0 +1,369 @@
|
||||
// MobileGL - MobileGL/MG_IntegrationTest/Scenarios/DeletedBoundBufferScenario.cpp
|
||||
// Copyright (c) 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
|
||||
//
|
||||
// Scenario - A BUFFER DELETED WHILE IT IS STILL BOUND TO AN INDEXED BINDING POINT.
|
||||
//
|
||||
// glDeleteBuffers unbinds the buffer from every binding point of the current context (GL 4.6
|
||||
// core 5.1.2, ES 3.2 6.1.1), indexed ones included, and the frontend does (BufferState::
|
||||
// MarkBufferObjectForDeletion). Under a transport that is not enough: the SERVER holds its own
|
||||
// copy of each indexed window (set_shader_buffers / the uniform window), re-sent only when the
|
||||
// target's bind-point GENERATION moves (Tracker.h's bits 15/16/17). A delete that cleared the
|
||||
// points without moving the generation left the server naming the dead buffer's handle; once
|
||||
// the client recycled that handle's slot at a newer generation, the next draw or dispatch that
|
||||
// walked the window asked the backend for the old one:
|
||||
// Espryt Fatal{ProtocolCorruption, "BackendSlotTable.Generation"} (the whole session dies);
|
||||
// Magma the handle resolves to nothing and the draw / dispatch that declares the point is
|
||||
// dropped.
|
||||
// (P11 B2 addendum; first seen as LargeArenaAdoptionScenario.GpuWriteIntoTheArenaIsReadBack
|
||||
// followed by TheArenaLandsInTheTierItsLaneDeclares in one process.)
|
||||
//
|
||||
// Each case, for one indexed target: bind a buffer at point 0 and use it (so the window naming it
|
||||
// reaches the server), delete it WHILE BOUND, create buffers until its slot has been reused at a
|
||||
// newer generation, then draw and dispatch with a program that DECLARES point 0 but never
|
||||
// touches it (a uniform-guarded branch: reading an empty point would be undefined, declaring it
|
||||
// is not). Both must run - no Fatal, a marker written, the frame drawn - and a fresh buffer bound
|
||||
// at the same point afterwards must be read correctly.
|
||||
|
||||
#include <array>
|
||||
#include <initializer_list>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../Harness/HeadlessGL.h"
|
||||
#include "../Harness/ScenarioFixture.h"
|
||||
|
||||
#ifdef GLAPI
|
||||
#undef GLAPI
|
||||
#endif
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glcorearb.h>
|
||||
#undef GL_GLEXT_PROTOTYPES
|
||||
|
||||
namespace MGITest {
|
||||
namespace {
|
||||
|
||||
// More than enough for any free-list order: the dead buffer's slot is reused well before.
|
||||
constexpr int kRecycledBuffers = 16;
|
||||
constexpr unsigned int kMarker = 0xC0FFEEu;
|
||||
constexpr unsigned int kFreshWord = 0x1234u;
|
||||
constexpr GLuint kResultBinding = 7;
|
||||
|
||||
constexpr const char* kQuadVertexSource = R"(#version 430 core
|
||||
layout(location = 0) in vec2 a_pos;
|
||||
void main() { gl_Position = vec4(a_pos, 0.0, 1.0); }
|
||||
)";
|
||||
constexpr const char* kQuadFragmentSource = R"(#version 430 core
|
||||
out vec4 o_color;
|
||||
void main() { o_color = vec4(0.0, 1.0, 0.0, 1.0); }
|
||||
)";
|
||||
|
||||
// The target's declaration and the one read of it; the read is only ever taken with
|
||||
// u_read = 1 (a fresh buffer bound). Result: the marker, unconditional, and what was read.
|
||||
std::string ComputeSource(const char* declaration, const char* read) {
|
||||
std::ostringstream os;
|
||||
os << "#version 430 core\n"
|
||||
"layout(local_size_x = 1) in;\n"
|
||||
"layout(std430, binding = 7) buffer Result { uint marker; uint value; };\n"
|
||||
"uniform uint u_read;\n"
|
||||
<< declaration << "\n"
|
||||
<< "void main() {\n"
|
||||
" uint v = 0u;\n"
|
||||
" if (u_read != 0u) { v = " << read << "; }\n"
|
||||
" marker = 0xC0FFEEu;\n"
|
||||
" value = v;\n"
|
||||
"}\n";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
constexpr const char* kCaptureVertexSource = R"(#version 430 core
|
||||
layout(location = 0) in vec2 a_pos;
|
||||
out float vs_value;
|
||||
void main() {
|
||||
vs_value = float(gl_VertexID) * 2.0 + 1.0;
|
||||
gl_Position = vec4(a_pos, 0.0, 1.0);
|
||||
gl_PointSize = 1.0;
|
||||
}
|
||||
)";
|
||||
|
||||
class DeletedBoundBufferScenario : public ScenarioTest {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
ScenarioTest::SetUp();
|
||||
if (!Ready()) return;
|
||||
m_quad = Link(kQuadVertexSource, kQuadFragmentSource);
|
||||
ASSERT_NE(m_quad, 0u) << m_log;
|
||||
const float quad[] = {-1.f, -1.f, 1.f, -1.f, 1.f, 1.f, -1.f, -1.f, 1.f, 1.f, -1.f, 1.f};
|
||||
glGenVertexArrays(1, &m_vao);
|
||||
glBindVertexArray(m_vao);
|
||||
glGenBuffers(1, &m_vbo);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
|
||||
glEnableVertexAttribArray(0);
|
||||
// The result block lives at its own point, bound ONCE here: nothing later rebinds
|
||||
// a storage point, so the storage window the server holds is only ever re-sent
|
||||
// by what the case itself does.
|
||||
const unsigned int zero[2] = {0u, 0u};
|
||||
glGenBuffers(1, &m_result);
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_result);
|
||||
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(zero), zero, GL_DYNAMIC_DRAW);
|
||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, kResultBinding, m_result);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
if (!Ready()) return;
|
||||
glUseProgram(0);
|
||||
glBindVertexArray(0);
|
||||
if (!m_owned.empty()) glDeleteBuffers(static_cast<GLsizei>(m_owned.size()), m_owned.data());
|
||||
if (m_result != 0) glDeleteBuffers(1, &m_result);
|
||||
if (m_vbo != 0) glDeleteBuffers(1, &m_vbo);
|
||||
if (m_vao != 0) glDeleteVertexArrays(1, &m_vao);
|
||||
for (GLuint p : {m_quad, m_compute, m_capture}) {
|
||||
if (p != 0) glDeleteProgram(p);
|
||||
}
|
||||
m_owned.clear();
|
||||
m_result = m_vbo = m_vao = m_quad = m_compute = m_capture = 0;
|
||||
}
|
||||
|
||||
GLuint Compile(GLenum stage, const char* source) {
|
||||
const GLuint shader = glCreateShader(stage);
|
||||
glShaderSource(shader, 1, &source, nullptr);
|
||||
glCompileShader(shader);
|
||||
GLint ok = 0;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
|
||||
if (!ok) {
|
||||
char log[2048] = {};
|
||||
glGetShaderInfoLog(shader, sizeof(log) - 1, nullptr, log);
|
||||
m_log = std::string("shader did not compile: ") + log;
|
||||
glDeleteShader(shader);
|
||||
return 0;
|
||||
}
|
||||
return shader;
|
||||
}
|
||||
|
||||
GLuint LinkShaders(std::initializer_list<GLuint> shaders, const char* varying = nullptr) {
|
||||
const GLuint program = glCreateProgram();
|
||||
for (GLuint s : shaders) glAttachShader(program, s);
|
||||
if (varying != nullptr) glTransformFeedbackVaryings(program, 1, &varying, GL_INTERLEAVED_ATTRIBS);
|
||||
glLinkProgram(program);
|
||||
for (GLuint s : shaders) glDeleteShader(s);
|
||||
GLint ok = 0;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &ok);
|
||||
if (!ok) {
|
||||
char log[2048] = {};
|
||||
glGetProgramInfoLog(program, sizeof(log) - 1, nullptr, log);
|
||||
m_log = std::string("program did not link: ") + log;
|
||||
glDeleteProgram(program);
|
||||
return 0;
|
||||
}
|
||||
return program;
|
||||
}
|
||||
|
||||
GLuint Link(const char* vs, const char* fs, const char* varying = nullptr) {
|
||||
const GLuint v = Compile(GL_VERTEX_SHADER, vs);
|
||||
if (v == 0) return 0;
|
||||
const GLuint f = Compile(GL_FRAGMENT_SHADER, fs);
|
||||
if (f == 0) {
|
||||
glDeleteShader(v);
|
||||
return 0;
|
||||
}
|
||||
return LinkShaders({v, f}, varying);
|
||||
}
|
||||
|
||||
GLuint LinkCompute(const std::string& source) {
|
||||
const GLuint c = Compile(GL_COMPUTE_SHADER, source.c_str());
|
||||
return c == 0 ? 0 : LinkShaders({c});
|
||||
}
|
||||
|
||||
GLuint MakeBuffer(GLenum target, const void* data, GLsizeiptr size) {
|
||||
GLuint buffer = 0;
|
||||
glGenBuffers(1, &buffer);
|
||||
glBindBuffer(target, buffer);
|
||||
glBufferData(target, size, data, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(target, 0);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// Delete the buffer still bound at `target` point 0, then take the dead buffer's slot
|
||||
// back at a newer generation: every new buffer is defined with content, which is what
|
||||
// makes the server twin it (and so move its live generation) at once.
|
||||
void DeleteWhileBoundAndRecycle(GLuint& bound) {
|
||||
glDeleteBuffers(1, &bound);
|
||||
bound = 0;
|
||||
std::vector<unsigned int> payload(64);
|
||||
for (int i = 0; i < kRecycledBuffers; ++i) {
|
||||
for (auto& word : payload) word = static_cast<unsigned int>(i);
|
||||
m_owned.push_back(MakeBuffer(GL_ARRAY_BUFFER, payload.data(),
|
||||
static_cast<GLsizeiptr>(payload.size() * sizeof(unsigned int))));
|
||||
}
|
||||
}
|
||||
|
||||
// The draw path first (Espryt walks the whole storage window at every draw), then the
|
||||
// frame must show the quad.
|
||||
void DrawTheQuadAndExpectIt(const char* when) {
|
||||
glViewport(0, 0, Gl().Width(), Gl().Height());
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glUseProgram(m_quad);
|
||||
glBindVertexArray(m_vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
unsigned char px[4] = {0, 0, 0, 0};
|
||||
glReadPixels(Gl().Width() / 2, Gl().Height() / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, px);
|
||||
EXPECT_GT(px[1], 200) << "the quad was not drawn " << when;
|
||||
EXPECT_LT(px[0], 50) << when;
|
||||
}
|
||||
|
||||
// Dispatch the target's program once; returns {marker, value}.
|
||||
std::array<unsigned int, 2> Dispatch(unsigned int read) {
|
||||
const unsigned int zero[2] = {0u, 0u};
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_result);
|
||||
glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, sizeof(zero), zero);
|
||||
glUseProgram(m_compute);
|
||||
glUniform1ui(glGetUniformLocation(m_compute, "u_read"), read);
|
||||
glDispatchCompute(1, 1, 1);
|
||||
glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_BUFFER_UPDATE_BARRIER_BIT |
|
||||
GL_ATOMIC_COUNTER_BARRIER_BIT);
|
||||
std::array<unsigned int, 2> out = {0xDEADBEEFu, 0xDEADBEEFu};
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_result);
|
||||
glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, sizeof(out), out.data());
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
|
||||
return out;
|
||||
}
|
||||
|
||||
// The three shader-buffer targets share one shape.
|
||||
void RunShaderBufferTarget(GLenum target, const char* declaration, const char* read,
|
||||
unsigned int freshSeed, unsigned int expectedRead) {
|
||||
m_compute = LinkCompute(ComputeSource(declaration, read));
|
||||
ASSERT_NE(m_compute, 0u) << m_log;
|
||||
|
||||
// 1. A buffer at point 0, used once so the window naming it crosses.
|
||||
const unsigned int seed[4] = {freshSeed, 0u, 0u, 0u};
|
||||
GLuint doomed = MakeBuffer(target, seed, sizeof(seed));
|
||||
glBindBufferBase(target, 0, doomed);
|
||||
auto first = Dispatch(0);
|
||||
EXPECT_EQ(first[0], kMarker) << "the dispatch with the buffer bound did not run";
|
||||
ASSERT_EQ(FirstGLError(), 0u);
|
||||
|
||||
// 2. Deleted while bound; its slot recycled at a newer generation.
|
||||
DeleteWhileBoundAndRecycle(doomed);
|
||||
GLint stillBound = -1;
|
||||
glGetIntegeri_v(target == GL_SHADER_STORAGE_BUFFER ? GL_SHADER_STORAGE_BUFFER_BINDING
|
||||
: target == GL_UNIFORM_BUFFER ? GL_UNIFORM_BUFFER_BINDING
|
||||
: GL_ATOMIC_COUNTER_BUFFER_BINDING,
|
||||
0, &stillBound);
|
||||
EXPECT_EQ(stillBound, 0) << "glDeleteBuffers did not unbind indexed point 0";
|
||||
|
||||
// 3. The SAME program dispatched again - no glUseProgram of another program in
|
||||
// between, because the uniform window's shutter mixes the program identity in and a
|
||||
// program change would re-send the window anyway - then a draw. Both must run.
|
||||
auto after = Dispatch(0);
|
||||
EXPECT_EQ(after[0], kMarker)
|
||||
<< "the dispatch that declares the deleted buffer's point did not run: its window still named "
|
||||
"the dead handle (Magma drops the dispatch; Espryt would have died with "
|
||||
"Fatal{ProtocolCorruption, \"BackendSlotTable.Generation\"} before this line)";
|
||||
DrawTheQuadAndExpectIt("after the bound buffer was deleted and its slot reused");
|
||||
EXPECT_EQ(FirstGLError(), 0u);
|
||||
|
||||
// 4. A fresh buffer at the same point reads correctly.
|
||||
const unsigned int fresh[4] = {freshSeed, 0u, 0u, 0u};
|
||||
const GLuint replacement = MakeBuffer(target, fresh, sizeof(fresh));
|
||||
m_owned.push_back(replacement);
|
||||
glBindBufferBase(target, 0, replacement);
|
||||
auto read1 = Dispatch(1);
|
||||
EXPECT_EQ(read1[0], kMarker);
|
||||
EXPECT_EQ(read1[1], expectedRead) << "the buffer bound after the delete was not the one read";
|
||||
EXPECT_EQ(FirstGLError(), 0u);
|
||||
glBindBufferBase(target, 0, 0);
|
||||
}
|
||||
|
||||
GLuint m_quad = 0;
|
||||
GLuint m_compute = 0;
|
||||
GLuint m_capture = 0;
|
||||
GLuint m_vao = 0;
|
||||
GLuint m_vbo = 0;
|
||||
GLuint m_result = 0;
|
||||
std::vector<GLuint> m_owned;
|
||||
std::string m_log;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_F(DeletedBoundBufferScenario, AStorageBufferDeletedWhileBoundLeavesNoStaleBinding) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
RunShaderBufferTarget(GL_SHADER_STORAGE_BUFFER,
|
||||
"layout(std430, binding = 0) buffer Target { uint word; };", "word",
|
||||
kFreshWord, kFreshWord);
|
||||
}
|
||||
|
||||
TEST_F(DeletedBoundBufferScenario, AUniformBufferDeletedWhileBoundLeavesNoStaleBinding) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
RunShaderBufferTarget(GL_UNIFORM_BUFFER, "layout(std140, binding = 0) uniform Target { uint word; };",
|
||||
"word", kFreshWord, kFreshWord);
|
||||
}
|
||||
|
||||
// The counter's pre-increment value is what the shader reads, and the buffer then holds seed + 1.
|
||||
TEST_F(DeletedBoundBufferScenario, AnAtomicCounterBufferDeletedWhileBoundLeavesNoStaleBinding) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
GLint counters = 0;
|
||||
glGetIntegerv(GL_MAX_COMPUTE_ATOMIC_COUNTERS, &counters);
|
||||
if (counters < 1) GTEST_SKIP() << "GL_MAX_COMPUTE_ATOMIC_COUNTERS is " << counters;
|
||||
RunShaderBufferTarget(GL_ATOMIC_COUNTER_BUFFER, "layout(binding = 0, offset = 0) uniform atomic_uint counter;",
|
||||
"atomicCounterIncrement(counter)", 41u, 41u);
|
||||
}
|
||||
|
||||
// Transform feedback: nothing re-sends a capture window at a draw today (bit 17 is computed and
|
||||
// not emitted), so the stale-handle failure cannot reach the backend through this target; the
|
||||
// case pins the behaviour anyway - the delete unbinds, a draw after the slot is reused runs,
|
||||
// and a fresh capture buffer at the same point receives exactly the captured values.
|
||||
TEST_F(DeletedBoundBufferScenario, ATransformFeedbackBufferDeletedWhileBoundLeavesNoStaleBinding) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
m_capture = Link(kCaptureVertexSource, kQuadFragmentSource, "vs_value");
|
||||
ASSERT_NE(m_capture, 0u) << m_log;
|
||||
constexpr int kPoints = 4;
|
||||
const float poison[kPoints + 2] = {-7.f, -7.f, -7.f, -7.f, -7.f, -7.f};
|
||||
|
||||
auto capture = [&](GLuint into) {
|
||||
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, into);
|
||||
glUseProgram(m_capture);
|
||||
glBindVertexArray(m_vao);
|
||||
glEnable(GL_RASTERIZER_DISCARD);
|
||||
glBeginTransformFeedback(GL_POINTS);
|
||||
glDrawArrays(GL_POINTS, 0, kPoints);
|
||||
glEndTransformFeedback();
|
||||
glDisable(GL_RASTERIZER_DISCARD);
|
||||
};
|
||||
|
||||
GLuint doomed = MakeBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, poison, sizeof(poison));
|
||||
capture(doomed);
|
||||
ASSERT_EQ(FirstGLError(), 0u);
|
||||
|
||||
DeleteWhileBoundAndRecycle(doomed);
|
||||
GLint stillBound = -1;
|
||||
glGetIntegeri_v(GL_TRANSFORM_FEEDBACK_BUFFER_BINDING, 0, &stillBound);
|
||||
EXPECT_EQ(stillBound, 0) << "glDeleteBuffers did not unbind transform feedback point 0";
|
||||
DrawTheQuadAndExpectIt("after the bound capture buffer was deleted and its slot reused");
|
||||
EXPECT_EQ(FirstGLError(), 0u);
|
||||
|
||||
const GLuint fresh = MakeBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, poison, sizeof(poison));
|
||||
m_owned.push_back(fresh);
|
||||
capture(fresh);
|
||||
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
|
||||
float captured[kPoints + 2] = {};
|
||||
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, fresh);
|
||||
glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(captured), captured);
|
||||
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
|
||||
EXPECT_EQ(FirstGLError(), 0u);
|
||||
for (int i = 0; i < kPoints + 2; ++i) {
|
||||
const float expected = i < kPoints ? static_cast<float>(i) * 2.f + 1.f : -7.f;
|
||||
EXPECT_EQ(captured[i], expected) << "capture record " << i;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace MGITest
|
||||
@@ -99,6 +99,9 @@ void main() { word = 0xC0FFEEu; }
|
||||
// P11 A1: set (to the tier the lane names, "T0") only by the `.AdoptTier0.` tcp entries,
|
||||
// which also set MOBILEGL_IPC_ADOPT_TIER=0; a harness marker, never read by the library.
|
||||
constexpr const char* kAdoptTierRefusalMarker = "MGITEST_ADOPT_TIER_REFUSAL";
|
||||
// P11 B2: set by the shared-segment `.AdoptTier0.` / `.AdoptT0Disallowed.` entries to the reason word the
|
||||
// server gives for not granting T0 ("no AHardwareBuffer" on a host, "disallowed" with its allow switch off).
|
||||
constexpr const char* kAdoptT0FallbackMarker = "MGITEST_ADOPT_T0_FALLBACK";
|
||||
// Draws issued against the arena inside the counted window. One definition, many draws:
|
||||
// "one per definition" (1) and "one per draw" (kDrawsInTheWindow) have to be different
|
||||
// numbers or the assertion cannot tell them apart.
|
||||
@@ -319,6 +322,44 @@ void main() { word = 0xC0FFEEu; }
|
||||
EXPECT_LT(px[0], 50) << "the draw still shows the previous frame's bytes";
|
||||
}
|
||||
|
||||
// P11 B2: THE SAME REWRITE WITH NO READBACK BETWEEN THE TWO DRAWS. The case above reads
|
||||
// pixels after the first draw, which retires it before the SubData, so a store that took the
|
||||
// write IN PLACE (straight into pages the GPU reads - a T0 import is the client's
|
||||
// AHardwareBuffer, an adopted store is a coherent map) would still pass it. Here the first
|
||||
// draw is only queued when the arena is rewritten: it must still fetch the bytes it was
|
||||
// issued against (red, left half) and the second draw the new ones (green, right half).
|
||||
TEST_F(LargeArenaAdoptionScenario, ADrawQueuedBeforeASubDataKeepsItsOwnBytes) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
|
||||
const GLint w = Gl().Width();
|
||||
const GLint h = Gl().Height();
|
||||
UploadQuad(1.f, 0.f, 0.f);
|
||||
glViewport(0, 0, w, h);
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glUseProgram(m_program);
|
||||
glBindVertexArray(m_vao);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(0, 0, w / 2, h);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
UploadQuad(0.f, 1.f, 0.f);
|
||||
glScissor(w / 2, 0, w - w / 2, h);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
std::array<unsigned char, 4> left = {0, 0, 0, 0};
|
||||
std::array<unsigned char, 4> right = {0, 0, 0, 0};
|
||||
glReadPixels(w / 4, h / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, left.data());
|
||||
glReadPixels(w / 2 + w / 4, h / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, right.data());
|
||||
EXPECT_EQ(FirstGLError(), 0u);
|
||||
EXPECT_GT(left[0], 200) << "the draw queued BEFORE the rewrite lost its bytes: the SubData reached "
|
||||
"pages that draw had not read yet (a write that landed in place instead "
|
||||
"of GPU-ordered)";
|
||||
EXPECT_LT(left[1], 50) << "the draw queued before the rewrite fetched the rewritten bytes";
|
||||
EXPECT_GT(right[1], 200) << "the draw after the rewrite did not see the new bytes";
|
||||
EXPECT_LT(right[0], 50) << "the draw after the rewrite still fetched the old bytes";
|
||||
}
|
||||
|
||||
// Respecifying a frontend buffer preserves its VAO attachments even when the
|
||||
// backend replaces the adopted store's GL name. Keep every attribute binding
|
||||
// unchanged so a stale backend VAO cannot be repaired by a frontend rebind.
|
||||
@@ -367,6 +408,44 @@ void main() { word = 0xC0FFEEu; }
|
||||
glDeleteVertexArrays(1, &otherVao);
|
||||
}
|
||||
|
||||
// P11 B2: A RESPECIFY WHILE A DRAW OF THE OLD STORE IS STILL QUEUED. The case above reads pixels
|
||||
// before every respecify, so the old store is retired by then and a server that freed it at
|
||||
// once would still pass. Here the first draw is only queued when the arena is redefined: the
|
||||
// old store (a T0 import: the client's AHardwareBuffer, which the client lets go of at this
|
||||
// very respecify) must outlive it, and the draw must show the bytes it was issued against.
|
||||
TEST_F(LargeArenaAdoptionScenario, ARespecifyWithADrawQueuedKeepsThatDrawsStore) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
|
||||
const GLint w = Gl().Width();
|
||||
const GLint h = Gl().Height();
|
||||
UploadQuad(1.f, 0.f, 0.f);
|
||||
glViewport(0, 0, w, h);
|
||||
glClearColor(0.f, 0.f, 0.f, 1.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glUseProgram(m_program);
|
||||
glBindVertexArray(m_vao);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
glScissor(0, 0, w / 2, h);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_arena);
|
||||
glBufferData(GL_ARRAY_BUFFER, kArenaBytes, nullptr, GL_DYNAMIC_DRAW);
|
||||
UploadQuad(0.f, 1.f, 0.f);
|
||||
glScissor(w / 2, 0, w - w / 2, h);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
|
||||
std::array<unsigned char, 4> left = {0, 0, 0, 0};
|
||||
std::array<unsigned char, 4> right = {0, 0, 0, 0};
|
||||
glReadPixels(w / 4, h / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, left.data());
|
||||
glReadPixels(w / 2 + w / 4, h / 2, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, right.data());
|
||||
EXPECT_EQ(FirstGLError(), 0u);
|
||||
EXPECT_GT(left[0], 200) << "the draw queued before the respecify lost the store it was issued "
|
||||
"against (freed before that draw ran)";
|
||||
EXPECT_LT(left[1], 50) << "the draw queued before the respecify fetched the new store's bytes";
|
||||
EXPECT_GT(right[1], 200) << "the draw after the respecify did not fetch the new store";
|
||||
EXPECT_LT(right[0], 50) << "the draw after the respecify still fetched the old store";
|
||||
}
|
||||
|
||||
TEST_F(LargeArenaAdoptionScenario, RespecifiedIndexArenaKeepsVaoBinding) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
|
||||
@@ -619,4 +698,52 @@ void main() { word = 0xC0FFEEu; }
|
||||
EXPECT_EQ(log.find("Fatal{UnimplementedAdoptTier"), std::string::npos) << log;
|
||||
}
|
||||
|
||||
// P11 B2 (MG_Remote/CONTRACT-P11.md B2): A SHARED-SEGMENT SESSION THAT ASKS T0 AND CANNOT RUN IT.
|
||||
// MOBILEGL_IPC_ADOPT_TIER=0 over shared segments asks T0 in the Hello (A1 made it die at the
|
||||
// handshake; ruling ID-P11-14 made it this). The lane's server cannot grant it - a host has no
|
||||
// AHardwareBuffer, or `.AdoptT0Disallowed.` turned its allow switch off - so it refuses by name
|
||||
// at its first native bind, publishes no kCapAdoptT0, and the client falls back to T2 with ONE
|
||||
// named line at its first map_persistent. Never a Fatal; the other cases in the lane are green
|
||||
// and the arena is emulated. Everywhere else it skips.
|
||||
TEST_F(LargeArenaAdoptionScenario, ASessionThatCannotRunT0FallsBackToT2OnceByName) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
const char* why = std::getenv(kAdoptT0FallbackMarker);
|
||||
if (why == nullptr || why[0] == '\0') {
|
||||
GTEST_SKIP() << "runs only in the shared-segment `.AdoptTier0.` / `.AdoptT0Disallowed.` entries, "
|
||||
"which set MOBILEGL_IPC_ADOPT_TIER=0 and " << kAdoptT0FallbackMarker;
|
||||
}
|
||||
if (PipeStatsWindow::LibraryLogPath().empty()) {
|
||||
GTEST_SKIP() << "the lane configured no MOBILEGL_LOG_FILE_PATH, and the two logs are where the "
|
||||
"fallback is written";
|
||||
}
|
||||
// A frame of the arena's work first: the fallback is only worth reading from a session that
|
||||
// then ran on T2 - and the client decides at its first map_persistent, which SetUp's
|
||||
// definition of the arena has already made.
|
||||
UploadQuad(0.f, 1.f, 0.f);
|
||||
DrawQuad();
|
||||
EXPECT_GT(CenterPixel()[1], 200) << "the session that fell back to T2 did not render";
|
||||
EXPECT_EQ(FirstGLError(), 0u);
|
||||
Gl().EndFrame();
|
||||
|
||||
const auto countOf = [](const std::string& text, const std::string& needle) {
|
||||
std::size_t n = 0;
|
||||
for (auto at = text.find(needle); at != std::string::npos; at = text.find(needle, at + 1)) ++n;
|
||||
return n;
|
||||
};
|
||||
const std::string client = PipeStatsWindow::ReadWholeFile(PipeStatsWindow::LibraryLogPath());
|
||||
const std::string server = PipeStatsWindow::ReadServerLogSince(PipeStatsWindow::LogMark{});
|
||||
const std::string clientLine = "Refuse{AdoptT0Unavailable, \"no kCapAdoptT0\"}";
|
||||
const std::string serverLine = std::string("Refuse{AdoptT0Unavailable, \"") + why + "\"}";
|
||||
RecordProperty("t0_client_fallbacks", static_cast<int>(countOf(client, clientLine)));
|
||||
RecordProperty("t0_server_refusals", static_cast<int>(countOf(server, serverLine)));
|
||||
EXPECT_EQ(countOf(client, clientLine), 1u)
|
||||
<< "the client names a T0 it asked for and cannot run exactly once, at its first map_persistent ("
|
||||
<< clientLine << "), in " << PipeStatsWindow::LibraryLogPath();
|
||||
EXPECT_EQ(countOf(server, serverLine), 1u)
|
||||
<< "the server names why it did not grant T0 exactly once, at its first native bind (" << serverLine
|
||||
<< "), in " << PipeStatsWindow::ServerLibraryLogPath();
|
||||
EXPECT_EQ(client.find("Fatal{"), std::string::npos) << client;
|
||||
EXPECT_EQ(server.find("Fatal{"), std::string::npos) << server;
|
||||
}
|
||||
|
||||
} // namespace MGITest
|
||||
|
||||
@@ -150,6 +150,13 @@ namespace MobileGL::MG_Pipe {
|
||||
// snapshot may only turn it OFF, because a caps re-run must not be able to make a
|
||||
// lockstep server run-ahead in the middle of a frame.
|
||||
kCapRunAheadApply = 1ull << 10,
|
||||
// P11 B2 (MG_Remote/CONTRACT-P11.md B2). THIS SESSION MAY RUN T0: the client asked for
|
||||
// it in its Hello (LinkTerms.adoptTier = 0) on a shared-segment plane, the server's
|
||||
// allow switch is on, this platform has AHardwareBuffer, and the backend's POST
|
||||
// self-test of the sustained-lock pattern passed on its live context. Never set in the
|
||||
// CapsSnapshot Accept sends (no context exists yet); set in the one the first native
|
||||
// bind republishes. The client adopts through T0 only while it reads this bit.
|
||||
kCapAdoptT0 = 1ull << 11,
|
||||
};
|
||||
|
||||
// Readiness is supplied independently by each backend's integration gate.
|
||||
|
||||
@@ -2497,6 +2497,30 @@ namespace MobileGL::MG_Pipe {
|
||||
}
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
Bool MGPipeApplyAdoptExternal(const MGPHandleOnly& handle, void* ahb, Uint64 size) {
|
||||
// The same kind verdict unmap_persistent gives: a store is the buffer family's.
|
||||
if (static_cast<MGPipeKind>(handle.Kind) != MGPipeKind::Buffer) {
|
||||
MGP_TRIP_WIRE_REPORT("MGPipe: " MGP_TRIP_WIRE_TAG("ProtocolCorruption")
|
||||
" adopt_external {slot=%u, gen=%u}: a T0 store is the buffer family's "
|
||||
"and the handle names another kind (%u)",
|
||||
handle.Handle.Slot, handle.Handle.Gen, handle.Kind);
|
||||
return false;
|
||||
}
|
||||
MGPipeResourceRecord* record = ResolveResource("adopt_external", handle.Handle);
|
||||
if (record == nullptr) return false;
|
||||
// The store the AHB replaces is the record's whole extent; a handle whose width moved
|
||||
// (a respecify the client has not caught up with) is not this store any more.
|
||||
if (size == 0 || size != record->Desc.Width) return false;
|
||||
// The same pin map_persistent takes: adoption is where a producer of live host writes
|
||||
// would attach, and T0 attaches none - the client writes the AHB through its lock, as a
|
||||
// monolith client writes its adopted map, and the applier is told nothing either way.
|
||||
PinNoLiveHostWrites(*record, handle.Handle, "adopt_external");
|
||||
if (g_resourceOps == nullptr || g_resourceOps->ImportExternal == nullptr) return false;
|
||||
return g_resourceOps->ImportExternal(handle.Handle, ahb, size);
|
||||
}
|
||||
#endif
|
||||
|
||||
// ================================================================================
|
||||
// P3a: the five vertex-input entry points (D-G, D-H, D-I).
|
||||
//
|
||||
|
||||
@@ -127,6 +127,22 @@ namespace MobileGL::MG_Pipe {
|
||||
void (*TextureRespecify)(MGPipeHandle res, const MGPResourceDesc& desc,
|
||||
const MGPRespecifiedLevel* level);
|
||||
void (*TextureDestroy)(MGPipeHandle res);
|
||||
// P11 B2 (T0, MG_Remote/CONTRACT-P11.md B2): the two members a backend that can take a
|
||||
// client's AHardwareBuffer as a store registers. Both null = this backend has no T0 and
|
||||
// every session it serves runs T2. Appended after the texture trio for the same reason.
|
||||
//
|
||||
// ImportExternal makes `ahb` (an AHardwareBuffer*, a BLOB of `size` bytes) the resident
|
||||
// store of buffer `res` - the twin a monolith map_persistent would have minted - and takes
|
||||
// its OWN reference, which it releases only after its own GPU fence for the store's last
|
||||
// use has completed. False = not imported: the session answers DECLINED and the store runs
|
||||
// T2 as before.
|
||||
Bool (*ImportExternal)(MGPipeHandle res, void* ahb, Uint64 size);
|
||||
// The POST self-test of the sustained-lock pattern (the AHB API does not promise it): with
|
||||
// this backend's context current on the apply thread, allocate a small AHB, hold its CPU
|
||||
// lock for the whole test, import it, let the GPU read what the CPU wrote and write a
|
||||
// pattern of its own, and read that back through the held pointer (and through the
|
||||
// backend's own host map of the import). False with the reason in `why`.
|
||||
Bool (*SelfTestExternal)(char* why, Uint64 whyBytes);
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -1298,6 +1314,14 @@ namespace MobileGL::MG_Pipe {
|
||||
// unmap_persistent: the donation ends. Never emitted by P3a's own paths; the call exists
|
||||
// so the pair is complete and the transport has both halves.
|
||||
void MGPipeApplyUnmapPersistent(const MGPHandleOnly& handle);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2 (T0): the split server's map_persistent for a session that runs T0. The client's
|
||||
// AHardwareBuffer `ahb` (`size` bytes) becomes buffer `handle`'s resident store through the
|
||||
// backend's ImportExternal. A handle that is not a live buffer of that width, or a backend
|
||||
// without the member, declines (false); the codec answers DECLINED and the store runs T2.
|
||||
// MapPersistentRoundtrips is not moved: under split the server never counted map_persistent.
|
||||
Bool MGPipeApplyAdoptExternal(const MGPHandleOnly& handle, void* ahb, Uint64 size);
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// P3a: the five vertex-input entry points (D-G, D-H, D-I)
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
| SharedSegments(inproc、fork / unix spawn) | client | `Fatal{UnimplementedAdoptTier, "T<n>"}`,握手期、任何记录之前 |
|
||||
| SharedSegments | server | 一行 W(档位由 client 定),T2 |
|
||||
|
||||
- **B2 起,SharedSegments 两行被 B2 的档位表取代**(0 = 问 T0、1 = 具名拒绝后 T2,都不再 Fatal),见 B2 节。
|
||||
|
||||
- 调用点:client `StartOverTransportPair`(Welcome 校验后)与 `StartOverSocket`(link terms 定下 `stream` 后、开数据连接前);server `ServerSession::Accept`(后端检查后、Welcome 前)。
|
||||
- 使用处 `Client::AdoptTierIsEmulate`(`PipeApply.cpp`、`PipeWireCodec.cpp` 仍问它):旋钮 2 → true;本进程已有握手定档 → true,不再打印;没有握手定过档的调用者 → 仍 `Fatal{UnimplementedAdoptTier}`("no handshake settled")。旋钮 > 2(解析器不收)→ Fatal。
|
||||
- `ServerSpawn` 从它拉起的子进程环境剔除 `MOBILEGL_IPC_*`(五个 server 自有旋钮除外),所以 fork / unix spawn 的 server 看不到 client 的旋钮;tcp 的 server 读自己的环境。
|
||||
@@ -51,7 +53,7 @@
|
||||
## 不变量
|
||||
|
||||
- G1:新代码全在 `MOBILEGL_BUILD_DISAGGREGATED` 下(`MG_Remote`)。
|
||||
- 线上格式与控制协议修订号不变(3)。(A 包;PAIR 包把修订号升到 4,见下节。)
|
||||
- 线上格式与控制协议修订号不变(3)。(A 包;PAIR 包把修订号升到 4,见下节;B2 升到 5。)
|
||||
|
||||
## PAIR:socket client 的两条连接按身份配对(B0 F2)
|
||||
|
||||
@@ -221,3 +223,129 @@
|
||||
|
||||
- G1:原生改动全在 `MG_Remote`(`MOBILEGL_BUILD_DISAGGREGATED` 下);pull 构建符号增 0 减 0。
|
||||
- 线上格式与控制协议修订号不变(4)。
|
||||
|
||||
## B2:T0——client 的 AHardwareBuffer 作 persistent map 的存储
|
||||
|
||||
依据 [`PLAN-P11.md`](../../docs/Disaggregated/notes/p11/PLAN-P11.md) §2 B、`design/07`。证据根 `~/w7/notes/p11/evidence/b2/`,报告 `~/w7/notes/p11/b2-report.md`。T0 只换**存储**:采纳门(≥ 16 MiB 的 NULL 定义、persistent 写映射等,与 monolith 同一组门)问到的那个 store 由 client 分配的 AHB 承载,server 导入它;GPU 有序的写(`glBufferSubData` 进已采纳 store = resident subdata)仍走 SEG_STAGE——**T0 不减少 MC 26.3 每帧的 stage 字节**:红米实测 SEG_STAGE 1071 → 1052 KiB/帧(只少了 T2 的 persistent-map 推送 19.4 KiB/帧),省的是 client shadow 与 server 暂存副本(内存)。monolith 不变。
|
||||
|
||||
### 档位(取代 §1 表里 SharedSegments 的 client 行)
|
||||
|
||||
| 数据面 | `MOBILEGL_IPC_ADOPT_TIER` | client | server |
|
||||
|---|---|---|---|
|
||||
| SharedSegments | **未设(缺省,2026-09-29 起)** | Hello 问 `0x80`(`kAdoptAskT0Default`:T0,回退安静)。有 `kCapAdoptT0` → T0(I 行同 0);没有 → **只 MGLOG_D**,本会话 T2,计入 `T0Fallbacks` | 授予同 0(`T0 granted` I 行);不授予 → **只 MGLOG_D**(POST 结果行同样降为 D),计入 `T0Refusals`;会话总计行降为 D |
|
||||
| Stream | 未设 | Hello 问 2;**只 MGLOG_D**(不是 A1 的 W 行),T2,计入 `T0Fallbacks` | server 自己的旋钮未设时同样只 D |
|
||||
| 任意 | 2 | 今天的 T2,逐字节不变;Hello 的 `adoptTier` = 2 | 不变 |
|
||||
| Stream | 0 / 1 | A1 不变:一行 W `Refuse{AdoptTierOnStream, "T<n>"}`,T2 | A1 不变 |
|
||||
| SharedSegments | 1 | 一行 W `Refuse{AdoptTierClosed, "T1"}`,问 2,T2 | — |
|
||||
| SharedSegments | 0 | Hello 问 T0。第一次 `map_persistent` 时档 = min(旋钮, caps, 数据面):有 `kCapAdoptT0` → T0(I 行);没有 → 一行 W `Refuse{AdoptT0Unavailable, "no kCapAdoptT0"}`,本会话 T2 | 第一次原生 bind 时定(`ServerSession::SettleAdoptT0AtBind`,`ServerSession.cpp:1076`):允许开关 → 平台有 AHB → 后端登记了导入 op → POST(进程内缓存)。授予:I `T0 granted`,post-bind 的 caps 快照带 `kCapAdoptT0`;否则一行 W `Refuse{AdoptT0Unavailable, "disallowed" \| "no AHardwareBuffer" \| "POST"}`,不发布 |
|
||||
| 任意 | 解析不了的值 | 一行 W(Config 忽略该值),按**未设**处理 | 同 |
|
||||
|
||||
- **缺省是 T0(用户 2026-09-29 决定)**:旋钮未设 = 能用就用 T0,不能用就安静回退 T2——stream、没有 AHB、POST 失败、server 不允许这四种都只打 MGLOG_D、没有 W / I 行,但照样计数(client `T0Fallbacks`、server `T0Refusals`,以及两侧的会话总计)。否则每个 tcp 会话和每个主机会话都会多一行回退。**显式 `=0` 与未设的区别只在日志**:`=0` 保留全部具名行(A1 的 `Refuse{AdoptTierOnStream}`、`Refuse{AdoptT0Unavailable, …}`),线上问 `0`;未设问 `0x80`,这样 server 才知道要安静(拒绝的原因只有 server 知道)。`=2` 仍是 T2,`MOBILEGL_IPC_ALLOW_ADOPT_T0` 不变。Config 行记为 `adopt-tier=unset(T0)`。
|
||||
- **修订 5 的 schema 补丁**:`protocol.fbs` 里 `adoptTier` 的注释加上 `0x80`,修订 5 按 `protocol_revision_pin.py --write --force` 重钉(`4632750f…`)。依据是脚本自己写的「修订号提交本身的罕见补丁」这一例外:修订 5 只在这条未落地的分支里出现过,没有外部对端。e44d6ac7 之前的修订 5 server 收到 `0x80` 时按名 `Refuse{LinkTerms}`,不会静默误读。生成的头文件不变。
|
||||
- **行为变化(A1 → B2)**:SharedSegments + 0 / 1 不再在握手期 `Fatal{UnimplementedAdoptTier}`。A1 的两个死亡用例改写为 `RemoteClientAdoptT0.*` 的具名回退用例。从不 Fatal:T0 不可用 → T2 + 具名行。
|
||||
- server 允许开关 `MOBILEGL_IPC_ALLOW_ADOPT_T0`(缺省 1;0 = 从不授予),进 `ServerSpawn` 的 server 自有名单(环境剔除后仍在),Config 行 `allow-t0=`。
|
||||
- 门(缺省 T0):`RemoteClientAdoptT0.AnUnsetKnobFallsBackToT2QuietlyAndCountsIt`(主机无 AHB 的共享段)、`AdoptTierStream.AnUnsetKnobRunsT2OnAStreamQuietlyAndCountsTheFallback`(真 tcp);未设 → T2,没有 W / I 回退行,计数为 1。red-once:把未设路径的三处 D 改成 W → 两例都红。`KnobTwoIsTodaysT2WithNoT0Line` 显式设 2。`SessionHandshakeTest` 的问值表加上 `0x80`(合法且安静)和 `0x81`(`Refuse{LinkTerms}`)。
|
||||
- 单个 store 的拒绝(server 已授予,这一条没导入)→ 该 store DECLINED = T2,client W 行,会话继续:Offer 未到(E `Refuse{AdoptT0NoStore, "record N"}`)、client 分配失败(Offer flags 0)、hop 读不出、后端导入失败;client 建不了 hop → W `Refuse{AdoptT0NoStore, "hop"}`、不发记录。
|
||||
- refusal 词 4 → 7(`AdoptTierClosed`、`AdoptT0Unavailable`、`AdoptT0NoStore` 进 `LOCAL_REFUSAL_WORDS`);abort 站点仍 79、family 仍 45。
|
||||
|
||||
### 线上格式(控制协议修订 4 → 5)
|
||||
|
||||
- `LinkTerms` 末尾追加 `adoptTier: ubyte = 2`:Hello 里是 client 的问,Welcome 里 server 回显。server 收到既非 2、也非(共享段上的)0 的问 → `Refuse{LinkTerms}`;client 见回显 ≠ 问 → `Refuse{LinkTerms}`。
|
||||
- 修订号 5(`mg_protocol_base.h`,`protocol_revision_pins.json` 第 5 行 `f83f4c5b…`);`wireFingerprint` 含修订号,修订 4 的对端得 `Refuse{WireFingerprint}`,从不配对。
|
||||
- `kCapAdoptT0` = `MGPCapBit` 1 << 11(`MGPipeTypes.h`),只在 post-bind 的 `CapsSnapshot.callMask` 里(POST 在第一次原生 bind 之后才能跑;client 在 make-current 返回前采用 post-bind caps)。
|
||||
- `map_persistent` 记录与回复不变:OK = 已导入、client 采纳 AHB 映射;DECLINED = 该 store T2;ERROR → `Fatal{ReplyError}`;OK 而 client 没给 AHB → `Fatal{UnexpectedMapAccept}`。
|
||||
- **Offer**(aux 套接字,`SCM_RIGHTS`,`Transport/AdoptT0.h:36`):32 字节旁带 {magic `'MGT0'` = `0x3054474D`,version 1,seq = 该 `map_persistent` 记录序号,size,flags bit 0 = HasBuffer} + 一个 fd = **hop**:client 建的 socketpair 一端,client 已在另一端 `AHardwareBuffer_sendHandleToUnixSocket`;server `recvHandleFromUnixSocket`(校验 BLOB 宽 = size)。hop 的理由:AHB 自带的 fd 集不定长,aux 上一条消息只带一个 fd。
|
||||
|
||||
### 顺序、线程、为什么不死锁
|
||||
|
||||
- client(app 的 GL 线程,`ClientSession::AdoptPersistentT0`,`ClientSession.cpp:2739`):分配 AHB(BLOB,CPU_READ/WRITE_OFTEN \| GPU_DATA_BUFFER)、lock(整个 store 生命期持有)、用 shadow 播种、建 hop → 编码 `map_persistent` → pre-publish 钩子在 `EncodeRecord` 与 `PublishAndNotify` 之间把 Offer 排上 aux → 发布 → 阻塞等回复。
|
||||
- server:**apply 线程**(`mgl-srv-apply`)在应用该记录时取 Offer:codec 的 `MapPersistent` 分支先问 `WireVerbSink::OnMapPersistent`(`PipeWireCodec.cpp:1834`)→ `ServerSession::AdoptStoreT0`(`:1118`)→ `AdoptInbox::Take(seq, 2000 ms)`。
|
||||
- 不死锁:(1) fd 在记录可见之前已进内核队列;(2) 握手后只有 apply 线程读 server 的 aux;(3) 每会话至多一条 T0 `map_persistent` 在飞(client 阻塞等回复),aux 队列里至多一个有效 Offer,排不满;(4) 等待有界(`kOfferWaitMs` = 2000)→ 具名 DECLINED,不挂。晚到 / 乱序:按 seq 暂存(`AdoptInbox`);seq 小于当前的旧 Offer 关闭并计数;畸形的跳过并计数。
|
||||
|
||||
### POST(`kCapAdoptT0` 的前提)
|
||||
|
||||
持续持锁形状:分配 64 KiB AHB,**整个测试期间 CPU lock 不放**,导入,GPU 读 CPU 写的图案、GPU 写一段,经持有的指针读回比较。
|
||||
- Espryt(`Ops_H_SelfTestExternal`):一次性 ES 3.1 pbuffer 上下文(不碰 Espryt 的绑定缓存),`glBufferStorageExternalEXT` + 持久 coherent 映射,映射读一遍,compute shader 把 region 0 拷到输出、在 word 4096 起写 `0x6C0FFEE0 ^ i`。
|
||||
- Magma(`VkBufferManager::SelfTestWireImport`,`VkBufferManager.cpp:768`):renderer 的设备,`vkCmdCopyBuffer` region 0 → staging、`vkCmdFillBuffer` region 4,栅栏等 2 s。
|
||||
- 结果一行 I `T0 POST (<后端>, sustained-lock pattern) PASSED|FAILED - …`。红米(Adreno 830)两后端 PASSED。
|
||||
|
||||
### server 端存储
|
||||
|
||||
- Espryt:`Ops_H_ImportExternal` → `ImportAhbAsBuffer`(`eglGetNativeClientBufferANDROID` + `glBufferStorageExternalEXT`,flags READ \| WRITE \| PERSISTENT \| COHERENT \| DYNAMIC_STORAGE,持久 coherent 映射);**先导入、再退役旧存储**(导入失败则 T2 存储原样);孪生体 = adopted 形状(`InstallT0Store`:immutable、persistentMapped、无 pendingRanges、无 hostBytes → 不进 buffer pool、不走 R-11 暂存)。上下文丢失后下一次 ensure 在新上下文重导入。
|
||||
- Magma:`VkBufferManager::ImportWireBuffer`(`:714`)经 `VK_ANDROID_external_memory_android_hardware_buffer`(Android 线路设备上有就启用,连同 `VK_EXT_queue_family_foreign`):要求 host-visible,优先 coherent,dedicated 导入;`VkBufferObject` 外部模式;`stagedCoverage` = 整个 store(`:742`)。
|
||||
|
||||
暂存副本(R-11 的 server shadow)读者审计——T0 孪生体没有暂存副本:
|
||||
|
||||
| 读者 | T0 下 |
|
||||
|---|---|
|
||||
| CPU 回读 `Ops_H_Readback`(Espryt `Managers.cpp:2540`) | persistentMapped 分支:`DrainResidentWritesNow` + `glFinish`,不回字节 |
|
||||
| CPU 回读 `ReadbackWireBuffer`(Magma `:560`) | imported:只 `WaitForWireBufferHostAccess`,不回字节 |
|
||||
| P9 W1 pack-buffer 落地(`PipeApplier.cpp:648` → `Ops_H_SubData`) | imported 分支排进 `pendingResidentWrites`(`Managers.cpp:2378`,GPU 有序);B2 前 adopted 的提前返回会丢这批像素 |
|
||||
| GPU 写跟踪 | client 自有(`m_gpuWritePending`);XFB 捕获回读跳过 persistentMapped(`DirectGLES.cpp:1806`) |
|
||||
| R-11 排水(`FlushPendingRangesFrom`、`MGL_SERVER_STAGED_REQUIRE_PENDING`) | 不可达:T0 孪生体无 pendingRanges |
|
||||
| handle 臂的 CPU 读者(间接命令、primitive restart 替换、multi-draw 索引重定基:`DirectGLES.cpp:486`、`:9224`、`:9541-9542`、`:9695-9696`、`MultiDraw.cpp:202`) | `SplitHostBytes`(`Managers.h:1121`)→ 导入的 coherent 映射,同 monolith 读 adopted 映射 |
|
||||
| Magma `WriteWireBuffer`(`:329`) | 不变:store 忙 → staged copy(GPU 有序),闲 → host 写进导入内存 |
|
||||
|
||||
### 生命周期
|
||||
|
||||
- client:从采纳到 respecify / destroy(`WireTables.cpp:214`、`:907` → `ReleaseT0Store`)或会话结束(`ResetT0`)持有 AHB 与 lock;之后 unlock + release。
|
||||
- server 在自己的栅栏之后放手,不依赖 link watermark,不需要 `completedFrameSerial` 的生产者:
|
||||
- Espryt:导入时 `AcquireImported`;`glDeleteBuffers` 之后 `RetireT0Import` 插栅栏,栅栏 signal 后才 release(`SweepT0Retired`:每次导入、ensure、以及两个同步点在延迟释放排水之后的 `ProcessDeferredT0Retires`);无上下文时的 destroy 进延迟列表并留第二个引用,排水删 id 后再退役;上下文丢失 → 全部释放。`ProcessDeferredBufferReleases` 逐字不动(G5)。
|
||||
- Magma:respecify / destroy 一律 `DeferWireRelease(T0ReleaseSerial(lastUse))`,按 serial 回收、从不"立即";外部 `VkBufferObject::Destroy` 释放 buffer / memory 后 `ReleaseImported`。
|
||||
|
||||
### CPU 读
|
||||
|
||||
client `BufferObject::SyncGpuWrites` 的 T0 分支:发 `ResourceReadback` 往返("完成、无字节"),清标记,读持有的映射;server 先落地排队的 resident 写、等 GPU(Espryt `glFinish`,Magma host-access 等待)再答。
|
||||
|
||||
### 计数与日志
|
||||
|
||||
client 与 server 每会话:导入 store 数、字节、拒绝数(I `T0 store {…} adopted - N bytes` / `T0 imported store {…} - N bytes (record R); session total S stores / B bytes`;会话结束 I `T0 session totals - …`)。
|
||||
|
||||
### 门
|
||||
|
||||
主机(`~/w7/notes/p11/evidence/b2/redonce-host*`;每次拷回原文件、`cmp` 相同、touch 后复绿):
|
||||
|
||||
| 门 | 用例 | red-once(变异 → 红) |
|
||||
|---|---|---|
|
||||
| 旋钮 2 = 今天的 T2 | `RemoteClientAdoptT0.KnobTwoIsTodaysT2WithNoT0Line`;全门禁缺省旋钮全绿 | Hello 不看旋钮一律问 0 → 红(client `Refuse{LinkTerms}` 回显 ≠ 问) |
|
||||
| 旋钮 0、主机无 AHB → T2 + 具名行 | `RemoteClientAdoptT0.{KnobZero…,NoAhardwareBuffer…}`、`DirectGLES.{Split,Spawn}.AdoptTier0.*`、`DirectVulkan.{Split,Spawn,Tcp}.AdoptTier0.*`(`ASessionThatCannotRunT0FallsBackToT2OnceByName` 读两行) | 恢复 A1 的握手 Fatal → 单元 2 例 + 集成例红(`e869d18c` 起 Espryt split / spawn 各条目的 ENVIRONMENT 自带 `MOBILEGL_ITEST_REQUIRE_GPU=1`,预检 abort 是失败而不是被 ctest 算作通过的 SKIP;之前只有门禁的 integration-gpu 两遍能抓到);删 client 的具名行 → 单元 1 例 + 两臂集成例红 |
|
||||
| 允许开关关 → T2 + 具名行 | `…TheServersAllowSwitchOffIsT2AndANamedLine`、`DirectGLES.Spawn.AdoptT0Disallowed.*` | 开关不进 `ServerSpawn` 白名单 → spawn 例红(server 说 "no AHardwareBuffer" 不是 "disallowed") |
|
||||
| 修订不符 → 具名拒绝 | `SessionHandshakeTest.ARevisionFourPeerIsRefusedByNameAtRevisionFive`、`protocol_revision_pin.py` | 修订号留 4 → 编译期 `static_assert` 红;去掉它 → 运行期该例红(两指纹相等,Welcome 发出) |
|
||||
| Stream + 0 → A1 行不变 | `{DirectGLES,DirectVulkan}.Tcp.AdoptTier0.*` | stream 上也问 0 → 19 / 21 例在 bring-up abort(握手不成,client 随后 `Fatal{CapsBeforeFirstSnapshot}`) |
|
||||
| 授予 + 存储落地 | `…AGrantedStoreLandsWithTheClientsBytes`(替身平台:memfd 当 AHB) | 不发布 `kCapAdoptT0` → 3 例红 |
|
||||
| Offer 按 seq 配对 | `Channels/AdoptInboxTest.*`(6 例 × inprocess / socket) | 按到达顺序配对 → 4 例红 |
|
||||
| Offer 晚到 / 不到 | `…AnOfferThatArrivesAfterItsRecordStillLands`(晚 300 ms)、`…AnOfferThatNeverArrivesIsANamedDeclineNotAHang`、`AdoptInboxTest.AnOfferThatNeverComesTimesOutWithinItsBound` | 等待不设界 → 3 例红(2 例超时 90 s) |
|
||||
|
||||
设备(红米 `2f7cbe2e`,Adreno 830;Android 集成测试静态 peek 载具 inproc 臂,每个用例一个进程,同主机 ctest;`evidence/b2/itest/`):对照载具旋钮 0 两后端 arena 落 T0(`arena_arm = adopted`,18 次导入),旋钮 2 落 T2(`emulated`),11 例(8 过、3 条车道专属跳过)全绿。
|
||||
|
||||
| 变异(只改一次性源码拷贝) | 载具 / 用例 | Espryt | Magma |
|
||||
|---|---|---|---|
|
||||
| M1 resident 写就地落(client 把 T0 store 的 SubData 直接写进 AHB) | `ADrawQueuedBeforeASubDataKeepsItsOwnBytes` | 红 | 红 |
|
||||
| M2 respecify 时立即释放导入 | `ARespecifyWithADrawQueuedKeepsThatDrawsStore` | **绿**:与"GL 导入自持内存引用、早放我们的 AHB 引用不释放页"一致,未直接验证;扩展不保证这一引用,栅栏后释放保留 | 红(先排队的绘制读到被释放的存储) |
|
||||
| M3 不发布 `kCapAdoptT0` | `TheArenaLandsInTheTierItsLaneDeclares` | 红(emulated) | 红 |
|
||||
| M4 CPU 读不做回读往返 | `ReadbackSeesTheLatestCpuWrite`、`GpuWriteIntoTheArenaIsReadBack` | 红 | 红 |
|
||||
|
||||
brief 点名的 `SubDataAfterAnInFlightDrawReachesTheNextDraw`(M1)与 `RespecifiedVertexArenaKeepsVaoBindings`(M2)在变异下**仍绿**:两者在每次写 / respecify 前都 `glReadPixels`,GPU 已退役,就地写与早释放都看不出来;所以加了上表两个"两次绘制之间不回读"的用例(主机各车道全绿)。
|
||||
|
||||
MC 26.3(同 app,spawn+shm 与 inproc × 两后端 × 旋钮 0 / 2)ssim 全过、旋钮 0 时 8 个 store(441.5 MiB)全部 T0;create-instancing 1 个 16 MiB store T0、ssim 过;B1 外部路线 b(helper)旋钮 0 同样导入。内存与帧时间见报告。
|
||||
|
||||
### 不变量
|
||||
|
||||
- G1:pull 构建符号增 0 减 0,`.text` 不变;原生改动在 `MG_Remote` 与两后端的线路路径(`MOBILEGL_BUILD_DISAGGREGATED` 下);Espryt 的 T0 导入只在 `__ANDROID__`。
|
||||
- G5:`ProcessDeferredBufferReleases` 等 P3a / P4a 名单上的函数逐字不动(T0 退役放在它之后的 `ProcessDeferredT0Retires`)。
|
||||
- 线上格式:控制协议修订 5(`LinkTerms.adoptTier`);Offer 走 aux 描述符通道,不是新帧。
|
||||
|
||||
## B2 追加:删除仍绑定在索引绑定点上的 buffer
|
||||
|
||||
- **缺陷(B2 之前就有,`b9b14c47` 同样复现)**:`BufferState::MarkBufferObjectForDeletion` 解绑索引绑定点,但不动绑定点代次(`NoteBindPointChanged`)。dirty 位 15 / 16 / 17(`Tracker.h`)只看代次,所以窗口不重发,server 一直指着死 buffer 的句柄;槽位以新代次被复用后,下一次遍历窗口的 draw / dispatch 就去要旧代次。
|
||||
- Espryt:`Fatal{ProtocolCorruption, "BackendSlotTable.Generation"}`(`Managers.cpp:3507`),整个会话死掉。
|
||||
- Magma:不 Fatal,句柄解析不到 wire buffer,声明了该点的 draw / dispatch 被具名拒绝后丢掉(`Magma wire decline [ComputeUniformBufferBinding]`)。
|
||||
- 触发面:storage / atomic 在 Espryt 的每次 draw(storage 窗口整窗遍历)和声明该点的程序;uniform 在 compute(整窗遍历)和声明该点的程序,且只在程序没换时才触发,因为 uniform 窗口的 shutter 混入了程序身份;transform feedback 目前没有消费者(位 17 只计算、不发射)。
|
||||
- **修法(`4aec5621`)**:删除时解绑的每个索引目标都调用 `NoteBindPointChanged`;transform-feedback 对象切换(`RestoreBoundTransformFeedbackState`,写绑定点的第四处)也调用。都在 `MOBILEGL_PIPE_PUSH` 下:代次计数器本身只存在于 push 构建。其余写入口(`BindBuffer{Base,Range}_State`、`SetNamedTransformFeedbackBinding`)原本就会动代次。
|
||||
- **Magma 单体(`7784d6bb`,新用例暴露的旧崩溃)**:程序声明的 uniform block 所在点为空时,`ResolveUniformBufferPayload` 解引用空指针。现在改给一个清零的块,与线路臂一致。
|
||||
- **门**:`DeletedBoundBufferScenario` 覆盖 storage / uniform / atomic counter / transform feedback 四个目标。
|
||||
- 注册:单体用 ambient `DirectGLES.` / `DirectVulkan.`;Espryt 用 `Split` / `Spawn` / `Tcp`(`mgl_itest_register_split_arms`);Magma 用 `DirectVulkan.<arm>.DeletedBound.`;另有同进程两例的回归 `…LargeArenaAdoptionScenario.GpuWriteThenTheTierCaseInOneProcess`,两后端 × 三臂。
|
||||
- red-once(去掉修法):前三个目标在 Espryt 三臂和 inproc 都 abort,报上面那条 Fatal;在 Magma 三臂和 inproc 都失败,dispatch 被丢;同进程对在 Espryt 三臂都 abort。transform feedback 在两后端都保持绿(没有消费者);单体在两后端都保持绿(没有窗口)。
|
||||
- red-once(去掉 Magma 空 UBO 分支):`DirectVulkan.DeletedBoundBufferScenario.AUniformBuffer…` 单体 SegFault。
|
||||
- 每次拷回原文件、`cmp` 相同、touch 后复绿。
|
||||
- **G1**:符号增 0 减 0;`.text` a5b933 → a5ba13(+224 字节),全部来自 `UniformManager::ResolveUniformBufferPayload`(Magma 修复:单体属于 pull 构建,这里改的是真实行为,没有加守卫)。`BufferState.cpp` / `Core.cpp` 按 pull 构建自己的参数预处理,新旧逐字相同。
|
||||
|
||||
@@ -138,6 +138,11 @@ These three are the reason `kHasBlob` had to be given an exact meaning (table 0)
|
||||
| 19b | `ResourceRespecify`'s **second** uncarried companion | — | **`const MGPRespecifiedLevel* level` (`PipeApply.h:792-795`, 4 bytes: `Uint16 UploadTarget; Uint16 Level;`) has no wire carrier either, and it is not bytes — R-13.3 does not cover it.** Ruling: it rides in `MGPResourceDesc`'s existing pads — `Pad1` (4 B, `:315`) becomes `{Uint16 RespecifiedUploadTarget; Uint16 RespecifiedLevel;}` and one byte of `Pad0` (`:303`) becomes `Uint8 HasRespecifiedLevel`. **Zero size change, `MGP_ASSERT_POD(..., 88)` does not move**, and `PipeFields.def`'s `MGP_FIELDS_MGPResourceDesc` gains the two named members (pads are excluded from field lists, so this is required, not optional). | Null means "this respecify redefines the **whole** resource" and drops every pending upload; non-null names the single `(uploadTarget, level)` and drops **only** that key. Clearing the whole set for a per-level `glTexImage2D` loses exactly the texels the server-side set exists to protect (`PipeApply.h:805-820`). Without a carrier, every OpenRA per-level respecify would silently take the whole-resource arm. **LANDED** (integrator ruling A made `MGPipeTypes.h` c0's file): `Uint8 HasRespecifiedLevel` in Pad0's high byte, `Uint16 RespecifiedUploadTarget; Uint16 RespecifiedLevel;` in Pad1, `MGP_ASSERT_POD(MGPResourceDesc, 88)` unmoved, plus an `offsetof` assertion that the pair stays adjacent and in `MGPRespecifiedLevel`'s order. **Read it only through `MGPipeRespecifyIsWholeResource` / `MGPipeRespecifiedUploadTargetOf` / `MGPipeRespecifiedLevelOf`, and write it only through `MGPipeSetRespecifiedLevel` / `MGPipeClearRespecifiedLevel`**: three fields are one value, and an open-coded reader that forgets the presence byte reads level 0 of upload target 0 as a real scope. **The carrier has no producer** — P5 builds only whole-resource descriptors, and a verify build pins that (`PinWholeResourceRespecifyScope`, `PipeApply.cpp`, the `PinNoLiveHostWrites` shape) so the phase that wires it cannot arrive unannounced. |
|
||||
| 20 | `ResourceFlushRange` (51) | stays `kNone` (R-13.2) | **It carries no bytes at all under split.** It is a `{range, AccessFlags}` control record; the bytes of `[Offset, Offset+Size)` arrive **ahead of it** as `ResourceSubData` records covering exactly that range. | R-13.2 offered "add a blobref" or "write the convention down". Neither, and for a reason: the ladder this record drives rewrites its range *"from the authoritative shadow"* (`Managers.cpp:1047-1076`), and under split the authoritative shadow is **server-owned** by rule C — so `resource_subdata` is already the only way bytes reach it, and a blobref here would be a second, forgeable way to say the same thing. `AccessFlags` must still cross **verbatim**, not normalised (`PipeApply.h:902-903`). **Overturn condition:** if the tier-1 `INVALIDATE_RANGE` arm turns out to need the bytes and the range in the *same* record — i.e. an intervening record could stale the subdata — this needs its own blobref. It cannot happen while the verb barrier holds, because nothing interleaves; **revisit when the barrier retires for the buffer family.** |
|
||||
|
||||
**Row 18 invariant (added 2026-09-29, debt review).** The two `GetCaps` blobrefs never cross the wire.
|
||||
The reply carries the decoded objects; `CapsMirror::Adopt` clears both refs (`CapsMirror.cpp:107-112`)
|
||||
because they name SEG_STAGE runs of the server's encoder. A change that transports them needs its own
|
||||
server → client carrier rule; it cannot reuse `SEG_STAGE`.
|
||||
|
||||
### Group D — the four server → client rows the brief's list omitted
|
||||
|
||||
| # | call (op) | flags | ruling | reply name |
|
||||
|
||||
@@ -667,7 +667,7 @@ Negative controls, each run red once:
|
||||
## §11 Not P6
|
||||
|
||||
Real window arrival and the `android:process=":mgl"` Service (P12); multi-context (P12); chunked
|
||||
readback and the reply-slot pool (P9); `DynamicBackendParameters`' fixed-width rewrite (P7);
|
||||
readback and the reply-slot pool (P9); `DynamicBackendParameters`' fixed-width rewrite (landed by P6.5 wf);
|
||||
`MOBILEGL_IPC_POLL_ESCALATE` (P10); remaining monolith-only frontend-object / twin-registry glue
|
||||
(P3b/P4b) and the named P7 functionality debts; Windows `pipe:` / `unix:`; the 511 class-C entries.
|
||||
|
||||
|
||||
@@ -721,7 +721,11 @@ namespace MobileGL::MG_Remote::Client {
|
||||
{
|
||||
::flatbuffers::FlatBufferBuilder builder(512);
|
||||
auto stamp = builder.CreateString(BuildFingerprint());
|
||||
auto terms = ::MobileGL::Wire::CreateLinkTerms(builder, dataPlane);
|
||||
// P11 B2: the adopt-tier ask rides the proposal (LinkTerms.adoptTier, append-only).
|
||||
auto terms = ::MobileGL::Wire::CreateLinkTerms(
|
||||
builder, dataPlane, ::MobileGL::Wire::WireForm::StructImage, 0, 0, 0, 0,
|
||||
static_cast<std::uint8_t>(Transport::AdoptTierAskFor(
|
||||
dataPlane == ::MobileGL::Wire::DataPlane::Stream)));
|
||||
const char* tokenText = std::getenv("MOBILEGL_IPC_TOKEN");
|
||||
auto token = builder.CreateString(tokenText == nullptr ? "" : tokenText);
|
||||
auto hello = ::MobileGL::Wire::CreateHello(
|
||||
@@ -809,8 +813,20 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// P11 A1: the adopt tier, settled by the side that holds the knob once the link terms
|
||||
// say which plane this is (inproc is shared segments by construction), before any
|
||||
// record. T0/T1 over shared segments die here by name (Transport/AdoptTier.h).
|
||||
(void)Transport::SettleAdoptTierAtHandshake(
|
||||
// P11 B2: 0 = this client asked T0 in its Hello; the Welcome echoes the ask it recorded.
|
||||
const std::uint32_t adoptAsk = Transport::SettleAdoptTierAtHandshake(
|
||||
terms->dataPlane() == ::MobileGL::Wire::DataPlane::Stream, Transport::AdoptTierSide::Client);
|
||||
if (terms->adoptTier() != adoptAsk) {
|
||||
const auto result = RefuseHandshake(*m_transport, ::MobileGL::Wire::RefuseCode::LinkTerms,
|
||||
"the server's adoptTier echo is not this client's ask", adoptAsk, terms->adoptTier());
|
||||
Stop();
|
||||
return result;
|
||||
}
|
||||
ResetT0(false);
|
||||
m_adoptT0Asked = Transport::AdoptAskIsT0(adoptAsk);
|
||||
m_adoptT0Quiet = Transport::AdoptTierIsDefault();
|
||||
if (terms->dataPlane() == ::MobileGL::Wire::DataPlane::Stream && Transport::AdoptTierWantsT0())
|
||||
m_t0Fallbacks = 1; // a stream carries T2 only (the settle said so, by name or at D)
|
||||
// The four SegmentRefs are what a spawn client MAPS (P6). Under inproc the mapping
|
||||
// already exists, so what they are good for here is the cross-check that the two
|
||||
// sides agree about the geometry at all - which is the assertion that would
|
||||
@@ -1013,7 +1029,11 @@ namespace MobileGL::MG_Remote::Client {
|
||||
{
|
||||
::flatbuffers::FlatBufferBuilder builder(512);
|
||||
auto stamp = builder.CreateString(BuildFingerprint());
|
||||
auto terms = ::MobileGL::Wire::CreateLinkTerms(builder, dataPlane);
|
||||
// P11 B2: the adopt-tier ask rides the proposal (LinkTerms.adoptTier, append-only).
|
||||
auto terms = ::MobileGL::Wire::CreateLinkTerms(
|
||||
builder, dataPlane, ::MobileGL::Wire::WireForm::StructImage, 0, 0, 0, 0,
|
||||
static_cast<std::uint8_t>(Transport::AdoptTierAskFor(
|
||||
dataPlane == ::MobileGL::Wire::DataPlane::Stream)));
|
||||
const char* tokenText = std::getenv("MOBILEGL_IPC_TOKEN");
|
||||
auto token = builder.CreateString(tokenText == nullptr ? "" : tokenText);
|
||||
auto hello = ::MobileGL::Wire::CreateHello(
|
||||
@@ -1101,7 +1121,19 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// P11 A1: as in StartOverTransportPair - the knob against the plane the link terms
|
||||
// settled, before the data connection and before any record. A stream refuses T0/T1
|
||||
// by name and runs T2; shared segments die here by name (Transport/AdoptTier.h).
|
||||
(void)Transport::SettleAdoptTierAtHandshake(stream, Transport::AdoptTierSide::Client);
|
||||
const std::uint32_t adoptAsk =
|
||||
Transport::SettleAdoptTierAtHandshake(stream, Transport::AdoptTierSide::Client);
|
||||
if (terms->adoptTier() != adoptAsk) {
|
||||
const auto result = RefuseHandshake(*m_transport, ::MobileGL::Wire::RefuseCode::LinkTerms,
|
||||
"the server's adoptTier echo is not this client's ask", adoptAsk, terms->adoptTier());
|
||||
Stop();
|
||||
return result;
|
||||
}
|
||||
ResetT0(false);
|
||||
m_adoptT0Asked = Transport::AdoptAskIsT0(adoptAsk);
|
||||
m_adoptT0Quiet = Transport::AdoptTierIsDefault();
|
||||
if (stream && Transport::AdoptTierWantsT0())
|
||||
m_t0Fallbacks = 1; // a stream carries T2 only (the settle said so, by name or at D)
|
||||
if (stream) {
|
||||
// PH-7 (4). A Stream Welcome without a nonce of exactly the minted width names no
|
||||
// data connection this client could open; refused rather than guessed at.
|
||||
@@ -1803,6 +1835,9 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// 4. and ONLY NOW may anything an emitter owns be released: a var-tail still
|
||||
// referenced by an unapplied record is a use-after-free the join is what prevents.
|
||||
LogMemory("teardown");
|
||||
// P11 B2: the T0 arm's proof for this session, and the client's references to its stores
|
||||
// (the server's imports held their own and are gone with the server's backend).
|
||||
ResetT0(true);
|
||||
LogWireLedger();
|
||||
Transport::LinkMetricsEnd();
|
||||
m_producer.Detach();
|
||||
@@ -1999,6 +2034,14 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// and the window does not defer on them (see ClientSession::LinkRetainsReplies).
|
||||
if (rowCarriesReplySlot && willReadReply && m_link != nullptr)
|
||||
m_link->DeclareReplyRead(seq);
|
||||
// P11 B2: T0's Offer is queued HERE - the seq exists and the record is not yet visible,
|
||||
// so the server's inbox finds the descriptor already queued when it decodes the record
|
||||
// (Server/AdoptInbox.h). One-shot: AdoptPersistentT0 sets it for its own record only.
|
||||
if (m_prePublish) {
|
||||
std::function<void(Uint64)> hook = std::move(m_prePublish);
|
||||
m_prePublish = nullptr;
|
||||
hook(seq);
|
||||
}
|
||||
m_producer.PublishAndNotify(seq);
|
||||
if (op == MG_Pipe::MGPWireOp::Present) {
|
||||
// A credit is permission to run ahead, not permission to retain the
|
||||
@@ -2666,6 +2709,194 @@ namespace MobileGL::MG_Remote::Client {
|
||||
|
||||
Transport::ITransport* ClientSession::Control_Plane() { return m_transport; }
|
||||
|
||||
// ---- P11 B2: T0 (MG_Remote/CONTRACT-P11.md B2) --------------------------------------------
|
||||
|
||||
namespace {
|
||||
Uint64 T0Key(MG_Pipe::MGPipeHandle handle) {
|
||||
return (static_cast<Uint64>(handle.Gen) << 32) | handle.Slot;
|
||||
}
|
||||
// 0 = queue each Offer in order; > 0 = queue it that many ms AFTER its record is published
|
||||
// (from another thread); < 0 = never queue it. Test seam only (SetT0OfferFaultForTest).
|
||||
std::atomic<Int32> g_t0OfferFault{0};
|
||||
} // namespace
|
||||
|
||||
void ClientSession::SetT0OfferFaultForTest(Int32 delayMs) {
|
||||
g_t0OfferFault.store(delayMs, std::memory_order_release);
|
||||
}
|
||||
|
||||
Bool ClientSession::AdoptT0() {
|
||||
if (!m_adoptT0Asked) return false;
|
||||
if (m_adoptT0Decision >= 0) return m_adoptT0Decision == 1;
|
||||
if (Caps().HasCap(MG_Pipe::kCapAdoptT0)) {
|
||||
m_adoptT0Decision = 1;
|
||||
MGLOG_I("MG_Remote client: T0 - the server published kCapAdoptT0 (its POST self-test of the "
|
||||
"sustained-lock pattern passed), so this session adopts persistent stores as "
|
||||
"AHardwareBuffers the server imports");
|
||||
} else {
|
||||
m_adoptT0Decision = 0;
|
||||
++m_t0Fallbacks;
|
||||
if (m_adoptT0Quiet) {
|
||||
// T0 BY DEFAULT (knob unset) FALLS BACK QUIETLY - counted, said at MGLOG_D.
|
||||
MGLOG_D("MG_Remote client: T0 by default is not available (no kCapAdoptT0; the server's log "
|
||||
"says why at MGLOG_D); the session runs T2");
|
||||
return false;
|
||||
}
|
||||
MGLOG_W("MG_Remote client: Refuse{AdoptT0Unavailable, \"no kCapAdoptT0\"} - "
|
||||
"MOBILEGL_IPC_ADOPT_TIER=0 asked for T0 and the server did not publish kCapAdoptT0 (its "
|
||||
"log names why: its allow switch, no AHardwareBuffer, or its POST self-test); the "
|
||||
"session runs T2 (emulate: the client keeps the shadow and pushes)");
|
||||
}
|
||||
return m_adoptT0Decision == 1;
|
||||
}
|
||||
|
||||
void* ClientSession::AdoptPersistentT0(const MG_Pipe::MGPHandleOnly& handle, Uint64 size,
|
||||
const void* seed) {
|
||||
using namespace Transport::AdoptT0;
|
||||
// Everything that can fail runs BEFORE the record is encoded, so the record never waits on
|
||||
// a step that has not happened: either the Offer carries the handle or it says it does not.
|
||||
HeldStore store;
|
||||
std::string why;
|
||||
const Bool held = AllocateHeld(size, seed, store, why);
|
||||
if (!held) {
|
||||
MGLOG_W("MG_Remote client: T0 store {slot=%u, gen=%u} (%llu bytes) could not be allocated (%s); "
|
||||
"the server is told (an Offer without a handle) and this store runs T2",
|
||||
handle.Handle.Slot, handle.Handle.Gen, static_cast<unsigned long long>(size), why.c_str());
|
||||
}
|
||||
std::string hopWhy;
|
||||
const int hop = MakeHop(held ? &store : nullptr, hopWhy);
|
||||
if (hop < 0) {
|
||||
// No descriptor at all, not even an empty hop. NO RECORD IS EMITTED: a map_persistent
|
||||
// the server would wait on without an Offer is exactly what the protocol never sends.
|
||||
// The store stays on its shadow (T2) - the same answer a DECLINED would have given -
|
||||
// and the server, having seen no record, has nothing to answer.
|
||||
MGLOG_W("MG_Remote client: Refuse{AdoptT0NoStore, \"hop\"} - no hop socket for the T0 store "
|
||||
"{slot=%u, gen=%u} (%s); no map_persistent is sent and the store runs T2",
|
||||
handle.Handle.Slot, handle.Handle.Gen, hopWhy.c_str());
|
||||
ReleaseHeld(store);
|
||||
++m_t0Declined;
|
||||
return nullptr;
|
||||
}
|
||||
MobileGLResult shared = MOBILEGL_ERR_NOT_INITIALIZED;
|
||||
m_prePublish = [&](Uint64 seq) {
|
||||
Offer offer{};
|
||||
offer.magic = kOfferMagic;
|
||||
offer.version = kOfferVersion;
|
||||
offer.seq = seq;
|
||||
offer.size = size;
|
||||
offer.flags = held ? kOfferHasBuffer : 0u;
|
||||
const Int32 fault = g_t0OfferFault.load(std::memory_order_acquire);
|
||||
if (fault < 0) {
|
||||
shared = MOBILEGL_OK; // the test's lost Offer: the server's bounded wait answers
|
||||
return;
|
||||
}
|
||||
#if !defined(_WIN32)
|
||||
if (fault > 0 && m_transport != nullptr) {
|
||||
// The test's LATE Offer: the record goes out now, the descriptor `fault` ms later.
|
||||
const int copy = ::dup(hop);
|
||||
Transport::ITransport* transport = m_transport;
|
||||
std::thread([transport, copy, offer, fault] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(fault));
|
||||
Transport::AdoptT0::Offer late = offer;
|
||||
(void)transport->ShareFd(copy, MobileGLByteSpan{&late, sizeof(late)});
|
||||
::close(copy);
|
||||
}).detach();
|
||||
shared = copy >= 0 ? MOBILEGL_OK : MOBILEGL_ERR_TRANSPORT_CLOSED;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
shared = m_transport != nullptr
|
||||
? m_transport->ShareFd(hop, MobileGLByteSpan{&offer, sizeof(offer)})
|
||||
: MOBILEGL_ERR_NOT_INITIALIZED;
|
||||
};
|
||||
Int32 status = Wire::ReplySink::kStatusError;
|
||||
EmitAndWait(MG_Pipe::MGPWireOp::MapPersistent, &handle, sizeof(handle), nullptr, 0, nullptr, 0, &status);
|
||||
m_prePublish = nullptr; // a cancelled encode never ran it
|
||||
#if !defined(_WIN32)
|
||||
::close(hop);
|
||||
#endif
|
||||
if (shared != MOBILEGL_OK) {
|
||||
MGLOG_E("MG_Remote client: the T0 store {slot=%u, gen=%u} could not be queued on the aux socket "
|
||||
"(rc=%d); its record is answered by the server's bounded wait",
|
||||
handle.Handle.Slot, handle.Handle.Gen, static_cast<int>(shared));
|
||||
}
|
||||
if (status == Wire::ReplySink::kStatusError) {
|
||||
ReleaseHeld(store);
|
||||
SessionFail(MGFatalFamily::ReplyError,
|
||||
"MGPipe: Fatal{ReplyError, \"map_persistent\"} - the T0 row answered ERROR, which is "
|
||||
"not an acceptance answer");
|
||||
}
|
||||
if (status == Wire::ReplySink::kStatusOk) {
|
||||
if (!held) {
|
||||
SessionFail(MGFatalFamily::UnexpectedMapAccept,
|
||||
"MGPipe: Fatal{UnexpectedMapAccept, \"map_persistent\"} - the server accepted a T0 "
|
||||
"store whose Offer carried no AHardwareBuffer");
|
||||
}
|
||||
++m_t0Imported;
|
||||
m_t0Bytes += size;
|
||||
void* ptr = store.ptr;
|
||||
// A handle is one store at a time; a stale entry (never released) would leak a lock.
|
||||
const Uint64 key = T0Key(handle.Handle);
|
||||
if (auto it = m_t0Stores.find(key); it != m_t0Stores.end()) {
|
||||
ReleaseHeld(it->second);
|
||||
++m_t0Released;
|
||||
}
|
||||
m_t0Stores[key] = store;
|
||||
MGLOG_I("MG_Remote client: T0 store {slot=%u, gen=%u} adopted - %llu bytes, the server imported "
|
||||
"this AHardwareBuffer; session total %llu stores / %llu bytes",
|
||||
handle.Handle.Slot, handle.Handle.Gen, static_cast<unsigned long long>(size),
|
||||
static_cast<unsigned long long>(m_t0Imported), static_cast<unsigned long long>(m_t0Bytes));
|
||||
return ptr;
|
||||
}
|
||||
++m_t0Declined;
|
||||
if (held) {
|
||||
MGLOG_W("MG_Remote client: T0 store {slot=%u, gen=%u} (%llu bytes) DECLINED by the server (its log "
|
||||
"names why); the store runs T2",
|
||||
handle.Handle.Slot, handle.Handle.Gen, static_cast<unsigned long long>(size));
|
||||
}
|
||||
ReleaseHeld(store);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ClientSession::ReleaseT0Store(MG_Pipe::MGPipeHandle handle) {
|
||||
auto it = m_t0Stores.find(T0Key(handle));
|
||||
if (it == m_t0Stores.end()) return;
|
||||
Transport::AdoptT0::ReleaseHeld(it->second);
|
||||
m_t0Stores.erase(it);
|
||||
++m_t0Released;
|
||||
}
|
||||
|
||||
void ClientSession::ResetT0(Bool releaseStores) {
|
||||
if (m_adoptT0Asked || m_t0Fallbacks != 0) {
|
||||
// A default (unset-knob) session that did not run T0 says its totals at MGLOG_D.
|
||||
const bool quiet = m_adoptT0Quiet && m_adoptT0Decision != 1;
|
||||
const char* ran =
|
||||
m_adoptT0Decision == 1 ? "ran T0" : m_adoptT0Decision == 0 || m_t0Fallbacks ? "fell back to T2" : "never decided";
|
||||
#define MGL_T0_CLIENT_TOTALS(LOG) \
|
||||
LOG("MG_Remote client: T0 session totals - %s%s; stores imported %llu, bytes %llu, declined %llu, " \
|
||||
"fallbacks %llu, released %llu, held at teardown %zu", \
|
||||
ran, m_adoptT0Quiet ? " (default)" : "", static_cast<unsigned long long>(m_t0Imported), \
|
||||
static_cast<unsigned long long>(m_t0Bytes), static_cast<unsigned long long>(m_t0Declined), \
|
||||
static_cast<unsigned long long>(m_t0Fallbacks), static_cast<unsigned long long>(m_t0Released), \
|
||||
m_t0Stores.size())
|
||||
if (quiet) {
|
||||
MGL_T0_CLIENT_TOTALS(MGLOG_D);
|
||||
} else {
|
||||
MGL_T0_CLIENT_TOTALS(MGLOG_I);
|
||||
}
|
||||
#undef MGL_T0_CLIENT_TOTALS
|
||||
(void)ran;
|
||||
}
|
||||
if (releaseStores) {
|
||||
for (auto& [key, store] : m_t0Stores) Transport::AdoptT0::ReleaseHeld(store);
|
||||
}
|
||||
m_t0Stores.clear();
|
||||
m_adoptT0Asked = false;
|
||||
m_adoptT0Quiet = false;
|
||||
m_adoptT0Decision = -1;
|
||||
m_t0Imported = m_t0Bytes = m_t0Declined = m_t0Released = m_t0Fallbacks = 0;
|
||||
m_prePublish = nullptr;
|
||||
}
|
||||
|
||||
Transport::RoleMemorySample ClientSession::SampleMemory() const {
|
||||
return Transport::SampleRoleMemory(Transport::MemoryRole::Client);
|
||||
}
|
||||
|
||||
@@ -52,9 +52,13 @@
|
||||
#include "../Transport/RoleMemory.h"
|
||||
#include "../Transport/SessionRings.h"
|
||||
#include "../Transport/SocketTransport.h"
|
||||
#include "../Transport/AdoptT0.h"
|
||||
#include "../Wire/PipeWireCodec.h"
|
||||
#include "CapsMirror.h"
|
||||
|
||||
#include <functional>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace MobileGL::MG_Remote::Transport {
|
||||
@@ -223,6 +227,41 @@ namespace MobileGL::MG_Remote::Client {
|
||||
Uint64* replySizeOut = nullptr, Bool wantReply = true,
|
||||
Bool willReadReply = true);
|
||||
|
||||
// ---- P11 B2: T0 (MG_Remote/CONTRACT-P11.md B2) ------------------------------------
|
||||
//
|
||||
// Does this session adopt persistent stores through T0? Decided ONCE, lazily, at the first
|
||||
// map_persistent - the first moment it matters, and one at which the server's first native
|
||||
// bind has certainly republished its caps (a buffer store cannot exist before a
|
||||
// make-current, and the make-current adopts what the bind published): the Hello asked T0
|
||||
// (MOBILEGL_IPC_ADOPT_TIER=0 over shared segments) AND the server published kCapAdoptT0.
|
||||
// A T0 the session asked for and cannot use is T2 plus ONE named line here
|
||||
// (`Refuse{AdoptT0Unavailable, ...}`), never a Fatal.
|
||||
Bool AdoptT0();
|
||||
// T0's map_persistent: allocate the AHB, hold its lock, seed it from `seed` (the shadow),
|
||||
// queue its Offer for the record's seq BEFORE the record is published (the order the
|
||||
// server's inbox relies on), and wait for the answer. The held pointer on OK - the caller
|
||||
// adopts it as the store's mapping - or null on DECLINED (the store stays T2).
|
||||
void* AdoptPersistentT0(const MG_Pipe::MGPHandleOnly& handle, Uint64 size, const void* seed);
|
||||
// The client's reference to buffer `handle`'s T0 store ends because the buffer was
|
||||
// respecified or destroyed: unlock and release it. The server's import holds its own
|
||||
// reference until its own fence for the store's last use has completed. No-op for a
|
||||
// handle with no T0 store.
|
||||
void ReleaseT0Store(MG_Pipe::MGPipeHandle handle);
|
||||
// Per-session T0 arm proof (B2): stores the server imported, their bytes, and the
|
||||
// map_persistent answers that came back DECLINED in a T0 session.
|
||||
Uint64 T0StoresImported() const { return m_t0Imported; }
|
||||
Uint64 T0BytesImported() const { return m_t0Bytes; }
|
||||
Uint64 T0Declined() const { return m_t0Declined; }
|
||||
// 1 when this session's knob asked for T0 (0, or unset) and it runs T2 instead: a stream
|
||||
// data plane, or no kCapAdoptT0 at the first map_persistent. Counted whether the fallback
|
||||
// was named (knob 0) or quiet (unset, the default).
|
||||
Uint64 T0Fallbacks() const { return m_t0Fallbacks; }
|
||||
// Test seam: 0 = queue each Offer before its record (the product order); > 0 = queue it
|
||||
// that many ms AFTER the record is published, from another thread; < 0 = never queue it.
|
||||
// What the host tests use to prove a late Offer still lands and a lost one is a named
|
||||
// DECLINED rather than a hang.
|
||||
static void SetT0OfferFaultForTest(Int32 delayMs);
|
||||
|
||||
// `willReadReply` (P12) and `wantReply` ARE TWO QUESTIONS AND MUST STAY TWO.
|
||||
//
|
||||
// wantReply does THIS CALL read the answer (it blocks on the barrier and takes the
|
||||
@@ -554,6 +593,22 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// Welcome::serverPid, kept because §9.5's arm proof wants it and because a value that is
|
||||
// only ever logged cannot be asserted on.
|
||||
std::uint32_t m_peerServerPid = 0;
|
||||
|
||||
// P11 B2 (T0). The Hello's ask, settled at the handshake; the lazy decision (-1 = not
|
||||
// yet, 0 = T2, 1 = T0); the stores this client holds by handle key (Gen << 32 | Slot);
|
||||
// the counters; and the one-shot hook EmitAndWaitTails runs between EncodeRecord (the
|
||||
// seq exists) and PublishAndNotify (the record is visible) - where the Offer is queued.
|
||||
Bool m_adoptT0Asked = false;
|
||||
Bool m_adoptT0Quiet = false; // the knob is unset: fallbacks at MGLOG_D
|
||||
Int32 m_adoptT0Decision = -1;
|
||||
std::unordered_map<Uint64, Transport::AdoptT0::HeldStore> m_t0Stores;
|
||||
Uint64 m_t0Imported = 0;
|
||||
Uint64 m_t0Bytes = 0;
|
||||
Uint64 m_t0Declined = 0;
|
||||
Uint64 m_t0Released = 0;
|
||||
Uint64 m_t0Fallbacks = 0;
|
||||
std::function<void(Uint64)> m_prePublish;
|
||||
void ResetT0(Bool releaseStores);
|
||||
};
|
||||
|
||||
// One per process in P5, because P5 serves one context, and LEAKED AT EXIT like every other
|
||||
|
||||
@@ -1247,6 +1247,10 @@ namespace MobileGL::MG_Remote::Client {
|
||||
Bool AdoptTierIsEmulate() {
|
||||
const Uint32 tier = MG_Config::Ipc.AdoptTier;
|
||||
if (tier == 2) return true;
|
||||
// P11 B2: UNSET (T0 by default) reaching the T2 path - settled or not - is T2, quietly: a
|
||||
// session-free caller (a unit case, a harness) runs the P5 default it always ran, and a
|
||||
// settled session already counted its fallback at the handshake or its first map_persistent.
|
||||
if (tier == MG_Config::kAdoptTierUnset) return true;
|
||||
// P11 A1 (CONTRACT-P11 §1): THE VERDICT IS THE HANDSHAKE'S, NOT THIS CALL'S. Both roles
|
||||
// settle the tier from the knob and the data plane before the first record
|
||||
// (Transport/AdoptTier.cpp): a stream refuses T0/T1 by name and runs T2, a client over
|
||||
|
||||
@@ -201,7 +201,18 @@ namespace MobileGL::MG_Remote::Client {
|
||||
}
|
||||
|
||||
// -- screen -------------------------------------------------------------------
|
||||
MGP_WIRE_PLAIN(ResourceDestroy, MGPHandleOnly, Screen)
|
||||
// resource_destroy is MGP_WIRE_PLAIN plus one line: P11 B2 - a destroyed buffer's T0
|
||||
// store is released by this client after the record is out (the server's import holds its
|
||||
// own reference until its fence for the store's last use; CONTRACT-P11.md B2).
|
||||
void Wire_ResourceDestroy(const MG_Pipe::MGPHandleOnly* payload) {
|
||||
if (RunsAsTheServerRole()) { MG_Pipe::MGPipeMonolithScreen().ResourceDestroy(payload); return; }
|
||||
ClientSession& session = RequireSession("ResourceDestroy");
|
||||
session.EmitAndWait(MGPWireOp::ResourceDestroy, payload, sizeof(*payload), nullptr, 0, nullptr, 0,
|
||||
nullptr);
|
||||
++g_emitted;
|
||||
if (static_cast<MG_Pipe::MGPipeKind>(payload->Kind) == MG_Pipe::MGPipeKind::Buffer)
|
||||
session.ReleaseT0Store(payload->Handle);
|
||||
}
|
||||
MGP_WIRE_PLAIN(UnmapPersistent, MGPHandleOnly, Screen)
|
||||
|
||||
// -- context, plain -----------------------------------------------------------
|
||||
@@ -887,6 +898,13 @@ namespace MobileGL::MG_Remote::Client {
|
||||
nullptr, 0, nullptr, 0, &status);
|
||||
}
|
||||
++g_emitted;
|
||||
// P11 B2: A RESPECIFIED BUFFER'S T0 STORE IS DONE FOR THIS CLIENT. The frontend has
|
||||
// already dropped its adopted pointer (BufferObject::RedefineStorage) and the store's
|
||||
// replacement is minted by the next map_persistent; the server keeps its own
|
||||
// reference until its fence for the store's last use has completed, so releasing ours
|
||||
// here cannot pull pages from under a frame still in flight (the fire-and-forget arm
|
||||
// above included).
|
||||
if (desc->Target == MG_Pipe::kMGPipeResourceTargetBuffer) session.ReleaseT0Store(desc->Resource);
|
||||
// ERROR IS NOT A DECLINE (M4 / codex 5 / R-5). status is 0 OK / 1 DECLINED / 2 ERROR;
|
||||
// an escape may not fold 2 into `false`, which is what a bare `return status == 0`
|
||||
// did - a transport fault then read as "the server said no". Every reply-owning row
|
||||
@@ -929,6 +947,16 @@ namespace MobileGL::MG_Remote::Client {
|
||||
return MG_Pipe::MGPipeMonolithEscapes().MapPersistent(handle, size, seedBytes);
|
||||
}
|
||||
ClientSession& session = RequireSession("MapPersistent");
|
||||
// P11 B2 (CONTRACT-P11.md B2): A T0 SESSION ADOPTS FOR REAL. The store is an
|
||||
// AHardwareBuffer this client allocates, holds locked and seeds from the shadow
|
||||
// (`seedBytes`, `size` of them); the server imports it and answers OK, and the held
|
||||
// pointer is the mapping. Everything below is the T2 arm, unchanged byte for byte.
|
||||
if (session.AdoptT0()) {
|
||||
void* adopted = session.AdoptPersistentT0(*handle, size, seedBytes);
|
||||
++g_emitted;
|
||||
if (adopted == nullptr) ++g_declined;
|
||||
return adopted;
|
||||
}
|
||||
(void)size;
|
||||
(void)seedBytes;
|
||||
Int32 status = 0;
|
||||
|
||||
@@ -783,7 +783,8 @@ struct LinkTerms FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
VT_MAXREPLYBYTES = 8,
|
||||
VT_CMDWINDOWBYTES = 10,
|
||||
VT_STAGEWINDOWBYTES = 12,
|
||||
VT_EVENTWINDOWBYTES = 14
|
||||
VT_EVENTWINDOWBYTES = 14,
|
||||
VT_ADOPTTIER = 16
|
||||
};
|
||||
MobileGL::Wire::DataPlane dataPlane() const {
|
||||
return static_cast<MobileGL::Wire::DataPlane>(GetField<uint8_t>(VT_DATAPLANE, 0));
|
||||
@@ -803,6 +804,9 @@ struct LinkTerms FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
uint64_t eventWindowBytes() const {
|
||||
return GetField<uint64_t>(VT_EVENTWINDOWBYTES, 0);
|
||||
}
|
||||
uint8_t adoptTier() const {
|
||||
return GetField<uint8_t>(VT_ADOPTTIER, 2);
|
||||
}
|
||||
template <bool B = false>
|
||||
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
@@ -812,6 +816,7 @@ struct LinkTerms FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
VerifyField<uint64_t>(verifier, VT_CMDWINDOWBYTES, 8) &&
|
||||
VerifyField<uint64_t>(verifier, VT_STAGEWINDOWBYTES, 8) &&
|
||||
VerifyField<uint64_t>(verifier, VT_EVENTWINDOWBYTES, 8) &&
|
||||
VerifyField<uint8_t>(verifier, VT_ADOPTTIER, 1) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
@@ -838,6 +843,9 @@ struct LinkTermsBuilder {
|
||||
void add_eventWindowBytes(uint64_t eventWindowBytes) {
|
||||
fbb_.AddElement<uint64_t>(LinkTerms::VT_EVENTWINDOWBYTES, eventWindowBytes, 0);
|
||||
}
|
||||
void add_adoptTier(uint8_t adoptTier) {
|
||||
fbb_.AddElement<uint8_t>(LinkTerms::VT_ADOPTTIER, adoptTier, 2);
|
||||
}
|
||||
explicit LinkTermsBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
@@ -856,12 +864,14 @@ inline ::flatbuffers::Offset<LinkTerms> CreateLinkTerms(
|
||||
uint64_t maxReplyBytes = 0,
|
||||
uint64_t cmdWindowBytes = 0,
|
||||
uint64_t stageWindowBytes = 0,
|
||||
uint64_t eventWindowBytes = 0) {
|
||||
uint64_t eventWindowBytes = 0,
|
||||
uint8_t adoptTier = 2) {
|
||||
LinkTermsBuilder builder_(_fbb);
|
||||
builder_.add_eventWindowBytes(eventWindowBytes);
|
||||
builder_.add_stageWindowBytes(stageWindowBytes);
|
||||
builder_.add_cmdWindowBytes(cmdWindowBytes);
|
||||
builder_.add_maxReplyBytes(maxReplyBytes);
|
||||
builder_.add_adoptTier(adoptTier);
|
||||
builder_.add_wireForm(wireForm);
|
||||
builder_.add_dataPlane(dataPlane);
|
||||
return builder_.Finish();
|
||||
|
||||
@@ -69,7 +69,8 @@ extern "C" {
|
||||
// SurfaceReply.width/height/refusal.
|
||||
// 4 P11 PAIR: the PairBind message - a socket client's control and aux connections pair by
|
||||
// the nonce each presents first, not by arrival order.
|
||||
#define MOBILEGL_PROTOCOL_CONTROL_REVISION 4
|
||||
// 5 P11 B2: LinkTerms.adoptTier - the client's persistent-map adoption tier ask (T0 or T2).
|
||||
#define MOBILEGL_PROTOCOL_CONTROL_REVISION 5
|
||||
|
||||
#define MOBILEGL_ABI_VERSION(major, minor) (((uint32_t)(major) << 16) | (uint32_t)(minor))
|
||||
#define MOBILEGL_ABI_MAJOR_OF(version) ((uint32_t)(version) >> 16)
|
||||
|
||||
@@ -69,6 +69,15 @@ table LinkTerms {
|
||||
cmdWindowBytes: ulong;
|
||||
stageWindowBytes: ulong;
|
||||
eventWindowBytes: ulong;
|
||||
// P11 B2 (MG_Remote/CONTRACT-P11.md B2), appended. In the Hello: the persistent-map adoption
|
||||
// tier the client ASKS for - 0 = T0 (it allocates each adopted store as an AHardwareBuffer and
|
||||
// hands it over the aux socket), 0x80 = T0 by DEFAULT (the client's knob is unset: the same T0,
|
||||
// but the server names a refusal only at debug level), 2 = T2 (emulate: shadow + push). 1 (T1)
|
||||
// is closed and never sent; a stream plane always asks 2. In the Welcome: the server's echo of the ask it
|
||||
// recorded. It is not the tier: T0 needs the server's POST self-test, which runs at the first
|
||||
// native bind (the GPU context does not exist yet), and is published as kCapAdoptT0 in the
|
||||
// CapsSnapshot that bind republishes. Absent (an older peer) reads 2.
|
||||
adoptTier: ubyte = 2;
|
||||
}
|
||||
|
||||
enum RefuseCode : uint {
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
// MobileGL - MobileGL/MG_Remote/Server/AdoptInbox.cpp
|
||||
// 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
|
||||
|
||||
#include "AdoptInbox.h"
|
||||
|
||||
#include "../Transport/FdPassing.h"
|
||||
|
||||
#include <MG_Util/Debug/Log.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace MobileGL::MG_Remote::Server {
|
||||
|
||||
namespace {
|
||||
void CloseFd(int fd) {
|
||||
#if !defined(_WIN32)
|
||||
if (fd >= 0) ::close(fd);
|
||||
#else
|
||||
(void)fd;
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
AdoptInbox::~AdoptInbox() { Clear(); }
|
||||
|
||||
void AdoptInbox::Clear() {
|
||||
for (auto& [seq, kept] : m_kept) CloseFd(kept.fd);
|
||||
m_kept.clear();
|
||||
}
|
||||
|
||||
AdoptInbox::Outcome AdoptInbox::Take(Uint64 seq, Uint32 timeoutMs, int* outFd,
|
||||
Transport::AdoptT0::Offer* outOffer, std::string& why) {
|
||||
using Clock = std::chrono::steady_clock;
|
||||
*outFd = -1;
|
||||
*outOffer = Transport::AdoptT0::Offer{};
|
||||
if (auto it = m_kept.find(seq); it != m_kept.end()) {
|
||||
*outFd = it->second.fd;
|
||||
*outOffer = it->second.offer;
|
||||
m_kept.erase(it);
|
||||
return Outcome::Taken;
|
||||
}
|
||||
if (m_transport == nullptr) {
|
||||
why = "the session has no control transport to receive the store on";
|
||||
return Outcome::Closed;
|
||||
}
|
||||
const auto deadline = Clock::now() + std::chrono::milliseconds(timeoutMs);
|
||||
for (;;) {
|
||||
const auto now = Clock::now();
|
||||
const Uint32 left = now >= deadline ? 0u
|
||||
: static_cast<Uint32>(std::chrono::duration_cast<std::chrono::milliseconds>(deadline - now).count());
|
||||
int fd = -1;
|
||||
Uint8 sideband[Transport::FdPassing::kMaxSidebandBytes] = {};
|
||||
std::uint64_t sidebandSize = 0;
|
||||
const MobileGLResult received = m_transport->ReceiveFd(
|
||||
&fd, MobileGLMutableByteSpan{sideband, sizeof(sideband)}, &sidebandSize, left);
|
||||
if (received == MOBILEGL_ERR_TIMEOUT) {
|
||||
why = "no store arrived on the aux socket within " + std::to_string(timeoutMs) +
|
||||
" ms of its record";
|
||||
return Outcome::TimedOut;
|
||||
}
|
||||
if (received != MOBILEGL_OK) {
|
||||
why = "the aux socket closed (rc=" + std::to_string(static_cast<int>(received)) +
|
||||
") before the store arrived";
|
||||
return Outcome::Closed;
|
||||
}
|
||||
Transport::AdoptT0::Offer offer{};
|
||||
if (sidebandSize != sizeof(offer)) {
|
||||
++m_malformed;
|
||||
MGLOG_W("MG_Remote server: T0 - an aux descriptor with a %llu-byte sideband is not a store "
|
||||
"offer; closed",
|
||||
static_cast<unsigned long long>(sidebandSize));
|
||||
CloseFd(fd);
|
||||
continue;
|
||||
}
|
||||
std::memcpy(&offer, sideband, sizeof(offer));
|
||||
if (offer.magic != Transport::AdoptT0::kOfferMagic ||
|
||||
offer.version != Transport::AdoptT0::kOfferVersion) {
|
||||
++m_malformed;
|
||||
MGLOG_W("MG_Remote server: T0 - an aux descriptor whose sideband is not an Offer "
|
||||
"(magic 0x%08x version %u); closed",
|
||||
offer.magic, offer.version);
|
||||
CloseFd(fd);
|
||||
continue;
|
||||
}
|
||||
if (offer.seq == seq) {
|
||||
*outFd = fd;
|
||||
*outOffer = offer;
|
||||
return Outcome::Taken;
|
||||
}
|
||||
if (offer.seq < seq) {
|
||||
// Its record already timed out and was declined; the client has released the
|
||||
// store on that answer, and this late copy of the handle is only a reference.
|
||||
++m_stale;
|
||||
MGLOG_W("MG_Remote server: T0 - the store for record %llu arrived after its record was "
|
||||
"answered; closed (stale)",
|
||||
static_cast<unsigned long long>(offer.seq));
|
||||
CloseFd(fd);
|
||||
continue;
|
||||
}
|
||||
// For a later record: keep it for that record. Replacing a kept one would leak it.
|
||||
if (auto it = m_kept.find(offer.seq); it != m_kept.end()) {
|
||||
++m_malformed;
|
||||
CloseFd(it->second.fd);
|
||||
it->second = KeptOffer{fd, offer};
|
||||
continue;
|
||||
}
|
||||
m_kept.emplace(offer.seq, KeptOffer{fd, offer});
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace MobileGL::MG_Remote::Server
|
||||
@@ -0,0 +1,72 @@
|
||||
// MobileGL - MobileGL/MG_Remote/Server/AdoptInbox.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
|
||||
|
||||
// P11 B2 (MG_Remote/CONTRACT-P11.md B2): the server's end of T0's descriptor channel.
|
||||
//
|
||||
// WHO READS THE FD, AND WHY IT CANNOT DEADLOCK THE APPLY THREAD. The APPLY THREAD reads it,
|
||||
// inline, when it decodes the map_persistent record whose seq the Offer names - nothing else reads
|
||||
// a session's aux socket after the handshake, so there is no second reader to race. The wait
|
||||
// cannot deadlock because of the client's order: it queues the Offer (ShareFd returns once the
|
||||
// kernel - or the in-process queue - holds it) BEFORE it publishes the record, so when the apply
|
||||
// thread sees the record the descriptor is already there, and the wait depends on nothing the
|
||||
// client has still to do. A client emits at most one T0 map_persistent at a time (the row blocks
|
||||
// on its reply), so at most one Offer is ever outstanding and the aux queue (10 datagrams on an
|
||||
// Android kernel) cannot fill. The wait is still bounded (AdoptT0::kOfferWaitMs): an Offer that
|
||||
// never comes is a named DECLINED, never a hang.
|
||||
//
|
||||
// Offers are matched by seq, not by arrival order. One that arrives for a LATER record is kept
|
||||
// for it; one for an EARLIER record (its record already timed out and was declined) is closed
|
||||
// and counted as stale.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Includes.h>
|
||||
|
||||
#include "../Transport/AdoptT0.h"
|
||||
#include "../Transport/ITransport.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace MobileGL::MG_Remote::Server {
|
||||
|
||||
class AdoptInbox {
|
||||
public:
|
||||
enum class Outcome : Uint8 { Taken, TimedOut, Closed };
|
||||
|
||||
AdoptInbox() = default;
|
||||
~AdoptInbox();
|
||||
AdoptInbox(const AdoptInbox&) = delete;
|
||||
AdoptInbox& operator=(const AdoptInbox&) = delete;
|
||||
|
||||
void Attach(Transport::ITransport* transport) { m_transport = transport; }
|
||||
|
||||
// The Offer for record `seq` and its hop descriptor (owned by the caller on Taken). Waits
|
||||
// at most `timeoutMs` for it; `why` names what went wrong otherwise.
|
||||
Outcome Take(Uint64 seq, Uint32 timeoutMs, int* outFd, Transport::AdoptT0::Offer* outOffer,
|
||||
std::string& why);
|
||||
|
||||
// Closes every kept descriptor (session teardown).
|
||||
void Clear();
|
||||
|
||||
Uint64 StaleOffers() const { return m_stale; }
|
||||
Uint64 MalformedOffers() const { return m_malformed; }
|
||||
SizeT Kept() const { return m_kept.size(); }
|
||||
|
||||
private:
|
||||
struct KeptOffer {
|
||||
int fd = -1;
|
||||
Transport::AdoptT0::Offer offer{};
|
||||
};
|
||||
Transport::ITransport* m_transport = nullptr;
|
||||
std::map<Uint64, KeptOffer> m_kept;
|
||||
Uint64 m_stale = 0;
|
||||
Uint64 m_malformed = 0;
|
||||
};
|
||||
|
||||
} // namespace MobileGL::MG_Remote::Server
|
||||
@@ -137,6 +137,11 @@ namespace MobileGL::MG_Remote::Server {
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Bool ServerVerbSink::OnMapPersistent(const MG_Pipe::MGPHandleOnly& handle, Uint64 seq, Int32& status) {
|
||||
ServerSession* session = ServerSession::Active();
|
||||
return session != nullptr && session->AdoptStoreT0(handle, seq, status);
|
||||
}
|
||||
|
||||
Bool ServerVerbSink::OnFenceCreate(const MG_Pipe::MGPHandleOnly& desc) {
|
||||
if (desc.Kind != static_cast<Uint32>(MG_Pipe::MGPipeKind::Fence))
|
||||
Wire::WireProtocolFatal("Fence.Kind", "expected Fence namespace");
|
||||
|
||||
@@ -153,6 +153,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
void SetBackend(MG_Backend::BackendObject* backend);
|
||||
void SetMaxReplyBytes(Uint64 bytes) { m_maxReplyBytes = bytes; }
|
||||
|
||||
// P11 B2: T0's map_persistent - ServerSession::AdoptStoreT0 (it owns the aux socket).
|
||||
Bool OnMapPersistent(const MG_Pipe::MGPHandleOnly& handle, Uint64 seq, Int32& status) override;
|
||||
Bool OnFenceCreate(const MG_Pipe::MGPHandleOnly&) override;
|
||||
Bool OnFenceDestroy(const MG_Pipe::MGPHandleOnly&) override;
|
||||
Bool OnFenceStatus(const MG_Pipe::MGPHandleOnly&, Uint32&) override;
|
||||
|
||||
@@ -1409,6 +1409,11 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// bind: the ID-67 control's different tuple reads 1 republish where 2 are required.
|
||||
ServerSession* session = ServerSession::Active();
|
||||
if (session != nullptr && session->Accepted()) {
|
||||
// P11 B2: THE T0 GRANT, HERE AND NOWHERE EARLIER - the first moment this session has
|
||||
// a live context (Magma: a device) to run the POST self-test on, and before the
|
||||
// snapshot below, which is the one the client's make-current adopts. Once per
|
||||
// session; a session that did not ask T0 does nothing.
|
||||
session->SettleAdoptT0AtBind();
|
||||
const MobileGLResult published = session->PublishCapsSnapshot();
|
||||
if (published == MOBILEGL_OK) NoteMakeCurrentRepublished();
|
||||
if (published != MOBILEGL_OK) {
|
||||
@@ -1483,6 +1488,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
if (frame.ok) {
|
||||
ServerSession* session = ServerSession::Active();
|
||||
if (session != nullptr && session->Accepted()) {
|
||||
session->SettleAdoptT0AtBind(); // P11 B2: idempotent; the bind has usually settled it
|
||||
(void)session->PublishCapsSnapshot();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,15 +16,18 @@
|
||||
#include "../Handshake.h"
|
||||
#include "../Transport/LinkMetrics.h"
|
||||
#include "../Transport/AdoptTier.h"
|
||||
#include "../Transport/AdoptT0.h"
|
||||
#include "../Protocol/generated/protocol_generated.h"
|
||||
#include "../Transport/InProcessTransport.h"
|
||||
|
||||
#include <Config.h>
|
||||
#include <MGGitHash.h>
|
||||
#include <MG_Pipe/MGPipeCallbacks.h>
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
#include <MG_Util/Debug/Log.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
@@ -683,6 +686,22 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// for, before a byte of Welcome. A stream refuses T0/T1 by name and serves T2; over
|
||||
// shared segments the client settles it (Transport/AdoptTier.h). 0/1 never die here.
|
||||
(void)Transport::SettleAdoptTierAtHandshake(stream, Transport::AdoptTierSide::Server);
|
||||
// ---- P11 B2: the client's ask (LinkTerms.adoptTier). 2 or, over shared segments, 0 (T0
|
||||
// by name) or kAdoptAskT0Default (T0 by default: refusals quiet); anything else is not an
|
||||
// ask this revision knows. Recorded, echoed in the Welcome, and granted or refused at the
|
||||
// first native bind (SettleAdoptT0AtBind).
|
||||
if (terms->adoptTier() != 2 && !(Transport::AdoptAskIsT0(terms->adoptTier()) && !stream))
|
||||
return RefuseHandshake(transport, ::MobileGL::Wire::RefuseCode::LinkTerms,
|
||||
"adoptTier is neither 2 nor, over shared segments, a T0 ask (0 or 0x80)", 2,
|
||||
terms->adoptTier());
|
||||
m_adoptAsk = terms->adoptTier();
|
||||
m_adoptT0Asked = Transport::AdoptAskIsT0(m_adoptAsk);
|
||||
m_adoptT0Quiet = m_adoptAsk == Transport::kAdoptAskT0Default;
|
||||
m_adoptT0Settled = false;
|
||||
m_adoptT0 = false;
|
||||
m_t0Stores = m_t0Bytes = m_t0Declined = m_t0Refusals = 0;
|
||||
m_adoptInbox.Clear();
|
||||
m_adoptInbox.Attach(&transport);
|
||||
|
||||
// ---- 3. the four segments, both control pages, the rings.
|
||||
MobileGLResult created = MOBILEGL_ERR_UNSUPPORTED;
|
||||
@@ -778,7 +797,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
static_cast<unsigned long long>(maxReply));
|
||||
}
|
||||
auto negotiated = ::MobileGL::Wire::CreateLinkTerms(builder, terms->dataPlane(),
|
||||
::MobileGL::Wire::WireForm::StructImage, maxReply, cmdWindow, stageWindow, eventWindow);
|
||||
::MobileGL::Wire::WireForm::StructImage, maxReply, cmdWindow, stageWindow, eventWindow,
|
||||
static_cast<Uint8>(m_adoptT0Asked ? m_adoptAsk : 2));
|
||||
auto welcome = ::MobileGL::Wire::CreateWelcome(
|
||||
builder, MOBILEGL_PROTOCOL_ABI_MAJOR, MOBILEGL_PROTOCOL_ABI_MINOR,
|
||||
// CONTRACT-P6 4.3: THE SERVER'S OWN PID, not an echo of the client's.
|
||||
@@ -898,6 +918,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// R-8/C-4: bits 32..47 of CallMask are the CONSUMER MASK, and this is the only place
|
||||
// they are produced.
|
||||
Uint64 callMask = CallMask();
|
||||
// P11 B2: this session's T0 grant, never part of the process-wide m_capBits - it is a
|
||||
// statement about THIS client's ask and this server's self-test.
|
||||
if (m_adoptT0) callMask |= static_cast<Uint64>(MG_Pipe::kCapAdoptT0);
|
||||
const auto timerSupported = m_backend->GetBackendFunctions().GL.IsTimerQuerySupported;
|
||||
if ((callMask & MG_Pipe::kCapTimerQuery) && (!timerSupported || !timerSupported()))
|
||||
callMask &= ~static_cast<Uint64>(MG_Pipe::kCapTimerQuery);
|
||||
@@ -1008,6 +1031,32 @@ namespace MobileGL::MG_Remote::Server {
|
||||
MG_Pipe::gMGPipeEventRingCapacityBytes = nullptr;
|
||||
}
|
||||
}
|
||||
// P11 B2: the T0 arm's proof for this session, then the inbox's leftovers (an Offer whose
|
||||
// record never came; its client has released the store on the session's end).
|
||||
if (m_accepted && m_adoptT0Asked) {
|
||||
// A default ask that ended on T2 says its totals at MGLOG_D, like its refusal.
|
||||
const bool quiet = m_adoptT0Quiet && !m_adoptT0;
|
||||
const char* ran = m_adoptT0 ? "ran T0" : m_adoptT0Settled ? "not granted (T2)" : "no native bind (T2)";
|
||||
#define MGL_T0_SERVER_TOTALS(LOG) \
|
||||
LOG("MG_Remote server: T0 session totals - %s%s; stores imported %llu, bytes %llu, declined %llu, " \
|
||||
"refused %llu, stale offers %llu, malformed %llu, unclaimed %zu", \
|
||||
ran, m_adoptT0Quiet ? " (default ask)" : "", static_cast<unsigned long long>(m_t0Stores), \
|
||||
static_cast<unsigned long long>(m_t0Bytes), static_cast<unsigned long long>(m_t0Declined), \
|
||||
static_cast<unsigned long long>(m_t0Refusals), \
|
||||
static_cast<unsigned long long>(m_adoptInbox.StaleOffers()), \
|
||||
static_cast<unsigned long long>(m_adoptInbox.MalformedOffers()), m_adoptInbox.Kept())
|
||||
if (quiet) {
|
||||
MGL_T0_SERVER_TOTALS(MGLOG_D);
|
||||
} else {
|
||||
MGL_T0_SERVER_TOTALS(MGLOG_I);
|
||||
}
|
||||
#undef MGL_T0_SERVER_TOTALS
|
||||
(void)ran;
|
||||
}
|
||||
m_adoptInbox.Clear();
|
||||
m_adoptInbox.Attach(nullptr);
|
||||
m_adoptT0Asked = m_adoptT0Settled = m_adoptT0 = m_adoptT0Quiet = false;
|
||||
m_adoptAsk = 2;
|
||||
m_consumer.Detach();
|
||||
*m_commands = Transport::RingConsumer();
|
||||
*m_events = Transport::EventRingProducer();
|
||||
@@ -1023,6 +1072,139 @@ namespace MobileGL::MG_Remote::Server {
|
||||
std::memory_order_release, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
// ---- P11 B2: T0 (MG_Remote/CONTRACT-P11.md B2) ------------------------------------------
|
||||
|
||||
namespace {
|
||||
// THE POST VERDICT IS THE PROCESS'S, like DriverPost's: the driver and the device do not
|
||||
// change between two sessions of one server process, and the test allocates, imports and
|
||||
// waits for the GPU - not a per-session cost. Apply thread only.
|
||||
struct T0PostVerdict {
|
||||
Bool ran = false;
|
||||
Bool passed = false;
|
||||
std::string detail;
|
||||
};
|
||||
T0PostVerdict& T0Post() {
|
||||
static T0PostVerdict verdict;
|
||||
return verdict;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void ServerSession::SettleAdoptT0AtBind() {
|
||||
if (!m_accepted || !m_adoptT0Asked || m_adoptT0Settled) return;
|
||||
m_adoptT0Settled = true;
|
||||
const char* backendName = m_backend == nullptr ? "server"
|
||||
: m_backend->GetBackendType() == BackendType::DirectVulkan ? "Magma" : "Espryt";
|
||||
std::string why;
|
||||
if (MG_Config::Ipc.AllowAdoptT0 == 0) {
|
||||
why = "this server's MOBILEGL_IPC_ALLOW_ADOPT_T0=0 disallows it";
|
||||
} else if (!Transport::AdoptT0::PlatformHasAhb()) {
|
||||
why = "no AHardwareBuffer on this platform";
|
||||
} else {
|
||||
const MG_Pipe::MGPipeResourceOps* ops = MG_Pipe::MGPipeGetResourceOps();
|
||||
if (ops == nullptr || ops->ImportExternal == nullptr || ops->SelfTestExternal == nullptr) {
|
||||
why = std::string("the ") + backendName + " backend registers no T0 import";
|
||||
} else {
|
||||
T0PostVerdict& post = T0Post();
|
||||
if (!post.ran) {
|
||||
char detail[512] = {};
|
||||
post.passed = ops->SelfTestExternal(detail, sizeof(detail));
|
||||
post.detail = detail;
|
||||
post.ran = true;
|
||||
if (m_adoptT0Quiet) {
|
||||
MGLOG_D("MG_Remote server: T0 POST (%s, sustained-lock pattern) %s - %s", backendName,
|
||||
post.passed ? "PASSED" : "FAILED", post.detail.c_str());
|
||||
} else {
|
||||
MGLOG_I("MG_Remote server: T0 POST (%s, sustained-lock pattern) %s - %s", backendName,
|
||||
post.passed ? "PASSED" : "FAILED", post.detail.c_str());
|
||||
}
|
||||
}
|
||||
if (!post.passed) why = std::string("the ") + backendName + " POST self-test failed: " + post.detail;
|
||||
}
|
||||
}
|
||||
if (!why.empty()) {
|
||||
++m_t0Refusals;
|
||||
const char* word = MG_Config::Ipc.AllowAdoptT0 == 0 ? "disallowed"
|
||||
: !Transport::AdoptT0::PlatformHasAhb() ? "no AHardwareBuffer" : "POST";
|
||||
if (m_adoptT0Quiet) {
|
||||
// THE DEFAULT ASK (MOBILEGL_IPC_ADOPT_TIER unset) FALLS BACK QUIETLY: every host
|
||||
// session would otherwise carry this line. Counted (T0Refusals, the totals line).
|
||||
MGLOG_D("MG_Remote server: T0 by default not granted (%s) - %s; the session runs T2",
|
||||
word, why.c_str());
|
||||
return;
|
||||
}
|
||||
MGLOG_W("MG_Remote server: Refuse{AdoptT0Unavailable, \"%s\"} - the client asked T0 "
|
||||
"(MOBILEGL_IPC_ADOPT_TIER=0) and %s; kCapAdoptT0 is not published and the session "
|
||||
"runs T2 (emulate)",
|
||||
word, why.c_str());
|
||||
return;
|
||||
}
|
||||
m_adoptT0 = true;
|
||||
MGLOG_I("MG_Remote server: T0 granted - the client asked T0 and the %s POST self-test passed; "
|
||||
"kCapAdoptT0 is published and each map_persistent imports the client's AHardwareBuffer",
|
||||
backendName);
|
||||
}
|
||||
|
||||
Bool ServerSession::AdoptStoreT0(const MG_Pipe::MGPHandleOnly& handle, Uint64 seq, Int32& status) {
|
||||
if (!m_adoptT0) return false;
|
||||
status = Wire::ReplySink::kStatusDeclined;
|
||||
int hop = -1;
|
||||
Transport::AdoptT0::Offer offer{};
|
||||
std::string why;
|
||||
const AdoptInbox::Outcome outcome =
|
||||
m_adoptInbox.Take(seq, Transport::AdoptT0::kOfferWaitMs, &hop, &offer, why);
|
||||
const auto closeHop = [&] {
|
||||
#if !defined(_WIN32)
|
||||
if (hop >= 0) ::close(hop);
|
||||
#endif
|
||||
hop = -1;
|
||||
};
|
||||
if (outcome != AdoptInbox::Outcome::Taken) {
|
||||
++m_t0Declined;
|
||||
MGLOG_E("MG_Remote server: Refuse{AdoptT0NoStore, \"record %llu\"} - the T0 map_persistent for "
|
||||
"{slot=%u, gen=%u} is DECLINED: %s; the store runs T2",
|
||||
static_cast<unsigned long long>(seq), handle.Handle.Slot, handle.Handle.Gen, why.c_str());
|
||||
return true;
|
||||
}
|
||||
if ((offer.flags & Transport::AdoptT0::kOfferHasBuffer) == 0) {
|
||||
closeHop();
|
||||
++m_t0Declined;
|
||||
MGLOG_W("MG_Remote server: T0 map_persistent {slot=%u, gen=%u} (record %llu) DECLINED - the "
|
||||
"client could not allocate its AHardwareBuffer (its log names why); the store runs T2",
|
||||
handle.Handle.Slot, handle.Handle.Gen, static_cast<unsigned long long>(seq));
|
||||
return true;
|
||||
}
|
||||
void* ahb = nullptr;
|
||||
const Bool received = Transport::AdoptT0::ReceiveFromHop(hop, offer.size, &ahb, why);
|
||||
closeHop();
|
||||
if (!received) {
|
||||
++m_t0Declined;
|
||||
MGLOG_E("MG_Remote server: T0 map_persistent {slot=%u, gen=%u} (record %llu) DECLINED - the "
|
||||
"AHardwareBuffer could not be read off its hop: %s",
|
||||
handle.Handle.Slot, handle.Handle.Gen, static_cast<unsigned long long>(seq), why.c_str());
|
||||
return true;
|
||||
}
|
||||
// The backend takes its own reference on success; this one is the hop's, released here.
|
||||
const Bool imported = MG_Pipe::MGPipeApplyAdoptExternal(handle, ahb, offer.size);
|
||||
Transport::AdoptT0::ReleaseImported(ahb);
|
||||
if (!imported) {
|
||||
++m_t0Declined;
|
||||
MGLOG_W("MG_Remote server: T0 map_persistent {slot=%u, gen=%u} (record %llu, %llu bytes) DECLINED - "
|
||||
"the backend did not import the AHardwareBuffer (its log names why); the store runs T2",
|
||||
handle.Handle.Slot, handle.Handle.Gen, static_cast<unsigned long long>(seq),
|
||||
static_cast<unsigned long long>(offer.size));
|
||||
return true;
|
||||
}
|
||||
++m_t0Stores;
|
||||
m_t0Bytes += offer.size;
|
||||
status = Wire::ReplySink::kStatusOk;
|
||||
MGLOG_I("MG_Remote server: T0 imported store {slot=%u, gen=%u} - %llu bytes (record %llu); session "
|
||||
"total %llu stores / %llu bytes",
|
||||
handle.Handle.Slot, handle.Handle.Gen, static_cast<unsigned long long>(offer.size),
|
||||
static_cast<unsigned long long>(seq), static_cast<unsigned long long>(m_t0Stores),
|
||||
static_cast<unsigned long long>(m_t0Bytes));
|
||||
return true;
|
||||
}
|
||||
|
||||
Transport::RingConsumer& ServerSession::CommandRing() { return *m_commands; }
|
||||
|
||||
Transport::RingControl& ServerSession::Control() {
|
||||
|
||||
@@ -57,6 +57,7 @@
|
||||
#include "../Transport/RoleMemory.h"
|
||||
#include "../Transport/SessionRings.h"
|
||||
#include "../Wire/PipeWireCodec.h"
|
||||
#include "AdoptInbox.h"
|
||||
#include "ApplyThreadPolicy.h"
|
||||
#include "PipeApplier.h"
|
||||
|
||||
@@ -290,6 +291,37 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Transport::RoleMemorySample SampleMemory() const;
|
||||
void LogMemory(const char* phase) const;
|
||||
|
||||
// ---- P11 B2: T0 (MG_Remote/CONTRACT-P11.md B2) --------------------------------------
|
||||
//
|
||||
// The client's Hello asked T0 (LinkTerms.adoptTier = 0 over shared segments).
|
||||
Bool AdoptT0Asked() const { return m_adoptT0Asked; }
|
||||
// This session runs T0 (asked, and granted at the first native bind).
|
||||
Bool AdoptT0() const { return m_adoptT0; }
|
||||
// THE GRANT, once per session, on the apply thread right after the first native bind and
|
||||
// BEFORE the caps that bind republishes: asked, the allow switch
|
||||
// (MOBILEGL_IPC_ALLOW_ADOPT_T0, default 1), AHardwareBuffer on this platform, a backend that
|
||||
// registers ImportExternal + SelfTestExternal, and that backend's POST self-test of the
|
||||
// sustained-lock pattern (run once per process on its live context, the verdict cached).
|
||||
// Granted sets kCapAdoptT0 in every later CapsSnapshot; not granted is one named line and
|
||||
// T2. A session that did not ask does nothing here (knob 2 is today's session byte for byte).
|
||||
void SettleAdoptT0AtBind();
|
||||
// T0's map_persistent, from the codec's arm through the verb sink, on the apply thread:
|
||||
// take the Offer for record `seq` from the aux socket (Server/AdoptInbox.h - bounded, never a
|
||||
// hang), read the AHB off its hop, and import it as `handle`'s store. False = this session is
|
||||
// not T0 (the codec's T2 decline answers); true = handled and `status` is the answer (OK, or
|
||||
// DECLINED with a named line).
|
||||
Bool AdoptStoreT0(const MG_Pipe::MGPHandleOnly& handle, Uint64 seq, Int32& status);
|
||||
// The arm's proof for this session (B2): stores imported and their bytes, declined.
|
||||
Uint64 T0StoresImported() const { return m_t0Stores; }
|
||||
Uint64 T0BytesImported() const { return m_t0Bytes; }
|
||||
Uint64 T0Declined() const { return m_t0Declined; }
|
||||
// 1 when this session asked T0 and was not granted it (allow switch, no AHardwareBuffer,
|
||||
// POST): counted whether the refusal was named (knob 0) or quiet (the default ask).
|
||||
Uint64 T0Refusals() const { return m_t0Refusals; }
|
||||
// The ask was the client's DEFAULT (kAdoptAskT0Default): a refusal is said at MGLOG_D.
|
||||
Bool AdoptT0Quiet() const { return m_adoptT0Quiet; }
|
||||
AdoptInbox& T0Inbox() { return m_adoptInbox; }
|
||||
|
||||
private:
|
||||
MobileGLResult BindDataConnection(Transport::ITransport& control, Transport::ILink& link,
|
||||
const Uint8* nonce);
|
||||
@@ -325,6 +357,18 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// the apply thread's event wait.
|
||||
std::atomic<Bool> m_applyStopRequested{false};
|
||||
std::atomic<Bool> m_controlStreamEnded{false};
|
||||
// P11 B2 (T0). Set by Accept from the Hello, by SettleAdoptT0AtBind on the apply thread;
|
||||
// the inbox and the counters are the apply thread's.
|
||||
Bool m_adoptT0Asked = false;
|
||||
Bool m_adoptT0Quiet = false;
|
||||
Uint8 m_adoptAsk = 2;
|
||||
Bool m_adoptT0Settled = false;
|
||||
Bool m_adoptT0 = false;
|
||||
AdoptInbox m_adoptInbox;
|
||||
Uint64 m_t0Stores = 0;
|
||||
Uint64 m_t0Bytes = 0;
|
||||
Uint64 m_t0Declined = 0;
|
||||
Uint64 m_t0Refusals = 0;
|
||||
};
|
||||
|
||||
// Leak-at-exit like every other MG_Remote singleton (ID-8): no frontend destructor may
|
||||
|
||||
@@ -101,10 +101,14 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// PH-6 (ID-P7-2) adds MOBILEGL_IPC_EVENT_WAIT_MS on the same argument: it is the server's
|
||||
// patience with a client that has stopped draining SEG_EVENT, nothing on the client reads
|
||||
// it, and scrubbing it would make a spawned server wait the default whatever the lane set.
|
||||
//
|
||||
// P11 B2 adds MOBILEGL_IPC_ALLOW_ADOPT_T0, the server's own T0 allow switch: only the server
|
||||
// reads it, and scrubbing it would make "allow switch off" unreachable on the spawn arm.
|
||||
// MOBILEGL_IPC_ADOPT_TIER itself still goes - the client's ask travels in its Hello.
|
||||
bool ShouldScrub(const char* entry) {
|
||||
static constexpr const char* kServerOwned[] = {
|
||||
"MOBILEGL_IPC_WIRE_DEFERRED_MB=", "MOBILEGL_IPC_SPIN_US=", "MOBILEGL_IPC_SERVER_AFFINITY=",
|
||||
"MOBILEGL_IPC_AUDIT=", "MOBILEGL_IPC_EVENT_WAIT_MS=",
|
||||
"MOBILEGL_IPC_AUDIT=", "MOBILEGL_IPC_EVENT_WAIT_MS=", "MOBILEGL_IPC_ALLOW_ADOPT_T0=",
|
||||
};
|
||||
for (const char* kept : kServerOwned) {
|
||||
if (std::strncmp(entry, kept, std::strlen(kept)) == 0) {
|
||||
|
||||
@@ -0,0 +1,225 @@
|
||||
// MobileGL - MobileGL/MG_Remote/Transport/AdoptT0.cpp
|
||||
// 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
|
||||
|
||||
#include "AdoptT0.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <cerrno>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include <android/hardware_buffer.h>
|
||||
#endif
|
||||
#if !defined(_WIN32)
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace MobileGL::MG_Remote::Transport::AdoptT0 {
|
||||
|
||||
namespace {
|
||||
std::atomic<const PlatformForTest*> g_testPlatform{nullptr};
|
||||
|
||||
std::string Format(const char* fmt, long long a, long long b = 0) {
|
||||
char buffer[256];
|
||||
std::snprintf(buffer, sizeof(buffer), fmt, a, b);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
|
||||
bool RealHasAhb() { return true; }
|
||||
|
||||
bool RealAllocateHeld(std::uint64_t size, const void* seed, HeldStore& out, std::string& why) {
|
||||
out = HeldStore{};
|
||||
if (size == 0 || size > 0xFFFFFFFFull) {
|
||||
why = Format("a BLOB AHardwareBuffer is at most 4 GiB wide and this store is %lld bytes",
|
||||
static_cast<long long>(size));
|
||||
return false;
|
||||
}
|
||||
AHardwareBuffer_Desc desc{};
|
||||
desc.width = static_cast<std::uint32_t>(size);
|
||||
desc.height = 1;
|
||||
desc.layers = 1;
|
||||
desc.format = AHARDWAREBUFFER_FORMAT_BLOB;
|
||||
desc.usage = AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN |
|
||||
AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER;
|
||||
AHardwareBuffer* ahb = nullptr;
|
||||
const int allocated = AHardwareBuffer_allocate(&desc, &ahb);
|
||||
if (allocated != 0 || ahb == nullptr) {
|
||||
why = Format("AHardwareBuffer_allocate(%lld bytes) rc=%lld", static_cast<long long>(size), allocated);
|
||||
return false;
|
||||
}
|
||||
void* ptr = nullptr;
|
||||
const int locked = AHardwareBuffer_lock(
|
||||
ahb, AHARDWAREBUFFER_USAGE_CPU_READ_OFTEN | AHARDWAREBUFFER_USAGE_CPU_WRITE_OFTEN, -1, nullptr, &ptr);
|
||||
if (locked != 0 || ptr == nullptr) {
|
||||
why = Format("AHardwareBuffer_lock rc=%lld", locked);
|
||||
AHardwareBuffer_release(ahb);
|
||||
return false;
|
||||
}
|
||||
if (seed != nullptr) {
|
||||
std::memcpy(ptr, seed, static_cast<std::size_t>(size));
|
||||
} else {
|
||||
std::memset(ptr, 0, static_cast<std::size_t>(size));
|
||||
}
|
||||
out.ahb = ahb;
|
||||
out.ptr = ptr;
|
||||
out.size = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
int RealMakeHop(const HeldStore* store, std::string& why) {
|
||||
int pair[2] = {-1, -1};
|
||||
if (::socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, pair) != 0) {
|
||||
why = Format("socketpair errno=%lld", errno);
|
||||
return -1;
|
||||
}
|
||||
if (store != nullptr && store->ahb != nullptr) {
|
||||
const int sent = AHardwareBuffer_sendHandleToUnixSocket(
|
||||
static_cast<const AHardwareBuffer*>(store->ahb), pair[0]);
|
||||
if (sent != 0) {
|
||||
why = Format("AHardwareBuffer_sendHandleToUnixSocket rc=%lld errno=%lld", sent, errno);
|
||||
::close(pair[0]);
|
||||
::close(pair[1]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
// The written message (and the descriptors it carries) stays queued on pair[1].
|
||||
::close(pair[0]);
|
||||
return pair[1];
|
||||
}
|
||||
|
||||
void RealReleaseHeld(HeldStore& store) {
|
||||
if (store.ahb != nullptr) {
|
||||
auto* ahb = static_cast<AHardwareBuffer*>(store.ahb);
|
||||
if (store.ptr != nullptr) (void)AHardwareBuffer_unlock(ahb, nullptr);
|
||||
AHardwareBuffer_release(ahb);
|
||||
}
|
||||
store = HeldStore{};
|
||||
}
|
||||
|
||||
bool RealReceiveFromHop(int hopFd, std::uint64_t size, void** outAhb, std::string& why) {
|
||||
*outAhb = nullptr;
|
||||
AHardwareBuffer* ahb = nullptr;
|
||||
const int received = AHardwareBuffer_recvHandleFromUnixSocket(hopFd, &ahb);
|
||||
if (received != 0 || ahb == nullptr) {
|
||||
why = Format("AHardwareBuffer_recvHandleFromUnixSocket rc=%lld errno=%lld", received, errno);
|
||||
return false;
|
||||
}
|
||||
AHardwareBuffer_Desc desc{};
|
||||
AHardwareBuffer_describe(ahb, &desc);
|
||||
if (desc.format != AHARDWAREBUFFER_FORMAT_BLOB || desc.width != size || desc.height != 1) {
|
||||
why = Format("the handle describes as format 0x%llx width %lld, not the BLOB its record's store needs",
|
||||
static_cast<long long>(desc.format), static_cast<long long>(desc.width));
|
||||
AHardwareBuffer_release(ahb);
|
||||
return false;
|
||||
}
|
||||
*outAhb = ahb;
|
||||
return true;
|
||||
}
|
||||
|
||||
void RealAcquireImported(void* ahb) {
|
||||
if (ahb != nullptr) AHardwareBuffer_acquire(static_cast<AHardwareBuffer*>(ahb));
|
||||
}
|
||||
|
||||
void RealReleaseImported(void* ahb) {
|
||||
if (ahb != nullptr) AHardwareBuffer_release(static_cast<AHardwareBuffer*>(ahb));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// No AHardwareBuffer: the server never grants T0 here, so a client never allocates. The
|
||||
// empty hop still works, so a flags-0 Offer is real on every POSIX host.
|
||||
bool RealHasAhb() { return false; }
|
||||
|
||||
bool RealAllocateHeld(std::uint64_t, const void*, HeldStore& out, std::string& why) {
|
||||
out = HeldStore{};
|
||||
why = "no AHardwareBuffer on this platform";
|
||||
return false;
|
||||
}
|
||||
|
||||
int RealMakeHop(const HeldStore* store, std::string& why) {
|
||||
#if defined(_WIN32)
|
||||
(void)store;
|
||||
why = "no AF_UNIX socketpair on this platform";
|
||||
return -1;
|
||||
#else
|
||||
if (store != nullptr && store->ahb != nullptr) {
|
||||
why = "no AHardwareBuffer on this platform";
|
||||
return -1;
|
||||
}
|
||||
int pair[2] = {-1, -1};
|
||||
if (::socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, pair) != 0) {
|
||||
why = Format("socketpair errno=%lld", errno);
|
||||
return -1;
|
||||
}
|
||||
::close(pair[0]);
|
||||
return pair[1];
|
||||
#endif
|
||||
}
|
||||
|
||||
void RealReleaseHeld(HeldStore& store) { store = HeldStore{}; }
|
||||
|
||||
bool RealReceiveFromHop(int, std::uint64_t, void** outAhb, std::string& why) {
|
||||
*outAhb = nullptr;
|
||||
why = "no AHardwareBuffer on this platform";
|
||||
return false;
|
||||
}
|
||||
|
||||
void RealAcquireImported(void*) {}
|
||||
void RealReleaseImported(void*) {}
|
||||
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
bool PlatformHasAhb() {
|
||||
const PlatformForTest* test = g_testPlatform.load(std::memory_order_acquire);
|
||||
return test != nullptr ? test->HasAhb() : RealHasAhb();
|
||||
}
|
||||
|
||||
bool AllocateHeld(std::uint64_t size, const void* seed, HeldStore& out, std::string& why) {
|
||||
const PlatformForTest* test = g_testPlatform.load(std::memory_order_acquire);
|
||||
return test != nullptr ? test->AllocateHeld(size, seed, out, why) : RealAllocateHeld(size, seed, out, why);
|
||||
}
|
||||
|
||||
int MakeHop(const HeldStore* store, std::string& why) {
|
||||
const PlatformForTest* test = g_testPlatform.load(std::memory_order_acquire);
|
||||
return test != nullptr ? test->MakeHop(store, why) : RealMakeHop(store, why);
|
||||
}
|
||||
|
||||
void ReleaseHeld(HeldStore& store) {
|
||||
const PlatformForTest* test = g_testPlatform.load(std::memory_order_acquire);
|
||||
if (test != nullptr) test->ReleaseHeld(store);
|
||||
else RealReleaseHeld(store);
|
||||
}
|
||||
|
||||
bool ReceiveFromHop(int hopFd, std::uint64_t size, void** outAhb, std::string& why) {
|
||||
const PlatformForTest* test = g_testPlatform.load(std::memory_order_acquire);
|
||||
return test != nullptr ? test->ReceiveFromHop(hopFd, size, outAhb, why)
|
||||
: RealReceiveFromHop(hopFd, size, outAhb, why);
|
||||
}
|
||||
|
||||
void AcquireImported(void* ahb) {
|
||||
const PlatformForTest* test = g_testPlatform.load(std::memory_order_acquire);
|
||||
if (test != nullptr) test->AcquireImported(ahb);
|
||||
else RealAcquireImported(ahb);
|
||||
}
|
||||
|
||||
void ReleaseImported(void* ahb) {
|
||||
const PlatformForTest* test = g_testPlatform.load(std::memory_order_acquire);
|
||||
if (test != nullptr) test->ReleaseImported(ahb);
|
||||
else RealReleaseImported(ahb);
|
||||
}
|
||||
|
||||
void SetPlatformForTest(const PlatformForTest* platform) {
|
||||
g_testPlatform.store(platform, std::memory_order_release);
|
||||
}
|
||||
|
||||
} // namespace MobileGL::MG_Remote::Transport::AdoptT0
|
||||
@@ -0,0 +1,110 @@
|
||||
// MobileGL - MobileGL/MG_Remote/Transport/AdoptT0.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
|
||||
|
||||
// P11 B2 (MG_Remote/CONTRACT-P11.md B2): T0, the zero-copy adoption of a persistently mapped
|
||||
// store. The CLIENT allocates the store as an AHardwareBuffer (AHB), keeps a CPU lock on it for
|
||||
// the store's life and uses that pointer as the adopted mapping; the SERVER imports the same
|
||||
// pages as the store's resident twin (Espryt glBufferStorageExternalEXT, Magma
|
||||
// VK_ANDROID_external_memory_android_hardware_buffer).
|
||||
//
|
||||
// HOW THE HANDLE CROSSES, AND WHY IT IS ORDERED WITH THE RECORDS THAT USE THE STORE. The adoption
|
||||
// rides the data-ring map_persistent record (not a control op, which the apply thread could
|
||||
// overtake under run-ahead). Its AHB travels over the session's aux socket as ONE descriptor: a
|
||||
// fresh socketpair end (the "hop") on which AHardwareBuffer_sendHandleToUnixSocket already wrote
|
||||
// the handle, with an Offer in the sideband naming the record's seq. The hop keeps the aux channel
|
||||
// uniform (one fd + sideband per message, FdPassing's shape on every route) and the AHB's own
|
||||
// message format off it. Step 1 of B2 proved both this and the direct form on the Redmi across
|
||||
// every route (shell, another app, same app, spawned child; 64 KiB to 128 MiB).
|
||||
//
|
||||
// Every T0 map_persistent is preceded by exactly one Offer for its seq - with the handle, or with
|
||||
// flags 0 when this client could not allocate one - so the server always has something to wait
|
||||
// for and never waits for nothing.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace MobileGL::MG_Remote::Transport::AdoptT0 {
|
||||
|
||||
// The aux sideband that travels with the hop descriptor.
|
||||
struct Offer {
|
||||
std::uint32_t magic = 0;
|
||||
std::uint32_t version = 0;
|
||||
std::uint64_t seq = 0; // the map_persistent record's seq (its reply slot id)
|
||||
std::uint64_t size = 0; // the store's bytes (the AHB's width)
|
||||
std::uint32_t flags = 0;
|
||||
std::uint32_t reserved = 0;
|
||||
};
|
||||
static_assert(sizeof(Offer) == 32, "the Offer is a fixed 32-byte sideband");
|
||||
inline constexpr std::uint32_t kOfferMagic = 0x3054474Du; // 'MGT0' on the wire
|
||||
inline constexpr std::uint32_t kOfferVersion = 1;
|
||||
// The hop carries an AHB. Clear = the client could not allocate one for this store: the
|
||||
// server answers DECLINED at once and the store runs T2.
|
||||
inline constexpr std::uint32_t kOfferHasBuffer = 1u;
|
||||
|
||||
// How long the apply thread waits for an Offer whose record it has decoded. The client queues
|
||||
// the Offer BEFORE it publishes the record, so the wait normally ends at once; the bound is
|
||||
// what turns a lost Offer into a named DECLINED instead of a hang.
|
||||
inline constexpr std::uint32_t kOfferWaitMs = 2000;
|
||||
|
||||
// True where AHardwareBuffer exists (Android). Everywhere else T0 is never granted.
|
||||
bool PlatformHasAhb();
|
||||
|
||||
// ---- client half ----------------------------------------------------------------------
|
||||
|
||||
// A store the client allocated. `ahb` is an AHardwareBuffer*, `ptr` its CPU lock, held until
|
||||
// ReleaseHeld.
|
||||
struct HeldStore {
|
||||
void* ahb = nullptr;
|
||||
void* ptr = nullptr;
|
||||
std::uint64_t size = 0;
|
||||
};
|
||||
|
||||
// Allocates a BLOB AHB of `size` bytes (CPU_READ_OFTEN | CPU_WRITE_OFTEN | GPU_DATA_BUFFER),
|
||||
// locks it for reading and writing - the lock is held for the store's life - and copies
|
||||
// `seed` (size bytes, may be null = zeros) into it. False with the reason in `why`.
|
||||
bool AllocateHeld(std::uint64_t size, const void* seed, HeldStore& out, std::string& why);
|
||||
|
||||
// A hop descriptor for `store`: a socketpair whose first end had the handle written on it
|
||||
// (AHardwareBuffer_sendHandleToUnixSocket) and was closed. Returns the other end, which the
|
||||
// caller shares over aux and closes. `store == nullptr` makes an empty hop (the flags-0
|
||||
// Offer's descriptor). -1 with `why` on failure.
|
||||
int MakeHop(const HeldStore* store, std::string& why);
|
||||
|
||||
// Unlocks and releases the client's reference. The server's import holds its own.
|
||||
void ReleaseHeld(HeldStore& store);
|
||||
|
||||
// ---- server half ----------------------------------------------------------------------
|
||||
|
||||
// Reads the handle a client wrote on `hopFd` (AHardwareBuffer_recvHandleFromUnixSocket) and
|
||||
// checks it is a BLOB of `size` bytes. On success *outAhb holds a reference the caller
|
||||
// releases with ReleaseImported. The caller closes hopFd.
|
||||
bool ReceiveFromHop(int hopFd, std::uint64_t size, void** outAhb, std::string& why);
|
||||
|
||||
void AcquireImported(void* ahb);
|
||||
void ReleaseImported(void* ahb);
|
||||
|
||||
// ---- test seam ------------------------------------------------------------------------
|
||||
|
||||
// A host has no AHardwareBuffer, so the host tests of T0's PROTOCOL (the Offer, its order
|
||||
// against the record, the inbox, the import call and the answers) run on a stand-in: every
|
||||
// function above dispatches to it while one is installed. Null restores the platform's own.
|
||||
// The GPU half of T0 is the device's to prove (B2's device gates).
|
||||
struct PlatformForTest {
|
||||
bool (*HasAhb)();
|
||||
bool (*AllocateHeld)(std::uint64_t size, const void* seed, HeldStore& out, std::string& why);
|
||||
int (*MakeHop)(const HeldStore* store, std::string& why);
|
||||
void (*ReleaseHeld)(HeldStore& store);
|
||||
bool (*ReceiveFromHop)(int hopFd, std::uint64_t size, void** outAhb, std::string& why);
|
||||
void (*AcquireImported)(void* ahb);
|
||||
void (*ReleaseImported)(void* ahb);
|
||||
};
|
||||
void SetPlatformForTest(const PlatformForTest* platform);
|
||||
|
||||
} // namespace MobileGL::MG_Remote::Transport::AdoptT0
|
||||
@@ -22,45 +22,63 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
const char* SideName(AdoptTierSide side) { return side == AdoptTierSide::Client ? "client" : "server"; }
|
||||
} // namespace
|
||||
|
||||
bool AdoptTierIsDefault() { return MG_Config::Ipc.AdoptTier == MG_Config::kAdoptTierUnset; }
|
||||
|
||||
bool AdoptTierWantsT0() { return MG_Config::Ipc.AdoptTier == 0 || AdoptTierIsDefault(); }
|
||||
|
||||
std::uint32_t AdoptTierAskFor(bool streamDataPlane) {
|
||||
if (streamDataPlane || !AdoptTierWantsT0()) return 2u;
|
||||
return AdoptTierIsDefault() ? kAdoptAskT0Default : 0u;
|
||||
}
|
||||
|
||||
std::uint32_t SettleAdoptTierAtHandshake(bool streamDataPlane, AdoptTierSide side) {
|
||||
const std::uint32_t knob = MG_Config::Ipc.AdoptTier;
|
||||
if (knob > 2) {
|
||||
// Unreachable through ConfigLoader (it admits 0..2); a direct assignment is the only
|
||||
// way here, and "P11 implements it" of a 7 would be a lie.
|
||||
if (knob > 2 && knob != MG_Config::kAdoptTierUnset) {
|
||||
// Unreachable through ConfigLoader (it admits 0..2 or leaves the knob unset); a direct
|
||||
// assignment is the only way here, and "T<n>" of a 7 would be a lie.
|
||||
SessionFail(MGFatalFamily::UnimplementedAdoptTier,
|
||||
"MGPipe: Fatal{UnimplementedAdoptTier, \"%u\"} - MOBILEGL_IPC_ADOPT_TIER=%u is not an "
|
||||
"adoption tier; the values are 0 and 1 (not implemented) and 2 (emulate, the default)",
|
||||
"adoption tier; the values are 0 (T0), 1 (closed) and 2 (emulate, the default)",
|
||||
static_cast<unsigned>(knob), static_cast<unsigned>(knob));
|
||||
}
|
||||
if (knob == 2) {
|
||||
g_settled.store(true, std::memory_order_release);
|
||||
return 2;
|
||||
}
|
||||
g_settled.store(true, std::memory_order_release);
|
||||
if (knob == 2) return 2;
|
||||
if (streamDataPlane) {
|
||||
// ONE LINE PER SESSION, on the side that holds the knob. The tcp lane's server is a
|
||||
// shared fixture that never sees the client's environment, so each side says it for
|
||||
// itself; neither side dies, because T2 is the only tier a stream can carry.
|
||||
// A1, UNCHANGED FOR A NAMED KNOB: ONE LINE PER SESSION, on the side that holds the knob.
|
||||
// The tcp lane's server is a shared fixture that never sees the client's environment,
|
||||
// so each side says it for itself; neither side dies, because T2 is the only tier a
|
||||
// stream carries. AN UNSET KNOB (T0 by default) SAYS IT AT MGLOG_D: every tcp session
|
||||
// would otherwise carry the line. The client counts it (ClientSession::T0Fallbacks).
|
||||
if (AdoptTierIsDefault()) {
|
||||
MGLOG_D("MG_Remote %s: T0 by default is not available on a stream data plane (tcp): the "
|
||||
"session runs T2 (MOBILEGL_IPC_ADOPT_TIER unset; set 0 to have this named)",
|
||||
SideName(side));
|
||||
return 2;
|
||||
}
|
||||
MGLOG_W("MG_Remote %s: Refuse{AdoptTierOnStream, \"T%u\"} - MOBILEGL_IPC_ADOPT_TIER=%u names a "
|
||||
"shared-mapping adoption tier and this session's data plane is a stream (tcp): the two "
|
||||
"sides share no memory to map, so the session runs T2 (emulate: the client keeps the "
|
||||
"shadow and pushes)",
|
||||
SideName(side), static_cast<unsigned>(knob), static_cast<unsigned>(knob));
|
||||
g_settled.store(true, std::memory_order_release);
|
||||
return 2;
|
||||
}
|
||||
if (side == AdoptTierSide::Server) {
|
||||
MGLOG_W("MG_Remote server: MOBILEGL_IPC_ADOPT_TIER=%u is the client's to settle on a shared-segment "
|
||||
"link (a client naming T0/T1 dies by name at its own handshake); this server serves T2",
|
||||
static_cast<unsigned>(knob));
|
||||
g_settled.store(true, std::memory_order_release);
|
||||
// B2: over shared segments the CLIENT'S ask (its Hello's LinkTerms.adoptTier) decides,
|
||||
// and the server grants T0 at its first native bind or names why not
|
||||
// (ServerSession::SettleAdoptT0AtBind). Its own knob says nothing about this session.
|
||||
return 2;
|
||||
}
|
||||
SessionFail(MGFatalFamily::UnimplementedAdoptTier,
|
||||
"MGPipe: Fatal{UnimplementedAdoptTier, \"T%u\"} - MOBILEGL_IPC_ADOPT_TIER=%u names a "
|
||||
"shared-mapping adoption tier no package implements yet (T0 is P11 package B's, T1 is "
|
||||
"closed); refused at the handshake over shared segments, before any record is emitted. "
|
||||
"Unset it or set 2 (emulate)",
|
||||
static_cast<unsigned>(knob), static_cast<unsigned>(knob));
|
||||
if (knob == 1) {
|
||||
MGLOG_W("MG_Remote client: Refuse{AdoptTierClosed, \"T1\"} - MOBILEGL_IPC_ADOPT_TIER=1 names T1 "
|
||||
"(the server exports an opaque fd), which P11 closed (ruling ID-P11-1: only Adreno Vulkan "
|
||||
"could run it); the session runs T2 (emulate). Set 0 for T0 or 2 for T2");
|
||||
return 2;
|
||||
}
|
||||
// knob 0 (or unset) over shared segments: asked in the Hello. Nothing is said yet - the
|
||||
// answer is the server's, at its first native bind, and a T0 this session cannot use is
|
||||
// named once (knob 0) or said at MGLOG_D (unset), at the first map_persistent
|
||||
// (ClientSession::AdoptT0).
|
||||
return AdoptTierAskFor(false);
|
||||
}
|
||||
|
||||
bool AdoptTierSettledAtHandshake() { return g_settled.load(std::memory_order_acquire); }
|
||||
|
||||
@@ -6,29 +6,33 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// P11 A1 (MG_Remote/CONTRACT-P11.md §1): THE PERSISTENT-MAP ADOPTION TIER IS SETTLED AT THE
|
||||
// HANDSHAKE, BY THE SIDE THAT KNOWS THE DATA PLANE, BEFORE THE FIRST map_persistent.
|
||||
// P11 A1 + B2 (MG_Remote/CONTRACT-P11.md §1 and B2): THE PERSISTENT-MAP ADOPTION TIER IS ASKED
|
||||
// AT THE HANDSHAKE, BY THE SIDE THAT KNOWS THE DATA PLANE, BEFORE THE FIRST map_persistent.
|
||||
//
|
||||
// Tier names follow docs/Disaggregated/design/07: T0 = the client allocates an AHardwareBuffer
|
||||
// and the server imports it; T1 = the server exports an opaque fd; T2 = the resource owner
|
||||
// declines and the client keeps the shadow and pushes. Only T2 is implemented (T0 is P11
|
||||
// package B's, T1 is closed), so MOBILEGL_IPC_ADOPT_TIER=0/1 is either refused by name or
|
||||
// fatal - never a silent T2, and never discovered at the first map_persistent:
|
||||
// and the server imports it; T1 = the server exports an opaque fd (CLOSED, ID-P11-1); T2 = the
|
||||
// resource owner declines and the client keeps the shadow and pushes.
|
||||
//
|
||||
// data plane side knob 0 / 1
|
||||
// Stream (tcp) either one line `Refuse{AdoptTierOnStream, "T<n>"}`, then T2. Never Fatal:
|
||||
// a stream has no memory the two sides share, so no tier but T2
|
||||
// can exist on it.
|
||||
// SharedSegments client Fatal{UnimplementedAdoptTier, "T<n>"} at the handshake, before any
|
||||
// record is emitted.
|
||||
// SharedSegments server one warning that the client settles the tier on this plane, then
|
||||
// T2. (inproc and fork share the client's environment, so the client
|
||||
// dies by name right after; a unix-socket server launched on its own
|
||||
// serves the T2 its client settled.)
|
||||
// MOBILEGL_IPC_ADOPT_TIER IS THE SWITCH (ruling ID-P11-14). UNSET - the default since 2026-09-29,
|
||||
// the user's decision - asks for T0 and falls back to T2 QUIETLY (MGLOG_D only, still counted),
|
||||
// so a tcp session or a host session is not one line longer; 0 asks for T0 BY NAME (the table
|
||||
// below); 1 is refused by name and runs T2; 2 is T2 byte for byte. T0 that this session cannot use
|
||||
// is never a Fatal - it is T2 plus one named line (knob 0) or one D line (unset):
|
||||
//
|
||||
// data plane side knob 0 knob 1
|
||||
// Stream (tcp) either `Refuse{AdoptTierOnStream, "T0"}`, T2 `Refuse{AdoptTierOnStream, "T1"}`, T2
|
||||
// (A1, unchanged: a stream shares no memory, so no tier but T2 exists)
|
||||
// SharedSegments client asks T0 in its Hello (LinkTerms. `Refuse{AdoptTierClosed, "T1"}`, asks T2
|
||||
// adoptTier = 0); whether it runs T0 is
|
||||
// read at the first map_persistent from
|
||||
// kCapAdoptT0 (ClientSession::AdoptT0)
|
||||
// SharedSegments server its own knob is not consulted: the client's ask decides, and the
|
||||
// server grants it at its first native bind (ServerSession::
|
||||
// SettleAdoptT0AtBind) or names why not
|
||||
//
|
||||
// In MG_Remote/Transport (the link-ratchet's SERVER partition) because both roles call it:
|
||||
// ServerSession::Accept and ClientSession's two Start halves. The at-use check the server's
|
||||
// applier and codec ask (Client::AdoptTierIsEmulate) reads the settlement back.
|
||||
// applier and codec ask on the T2 path (Client::AdoptTierIsEmulate) reads the settlement back.
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -38,9 +42,28 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
|
||||
enum class AdoptTierSide : std::uint8_t { Client, Server };
|
||||
|
||||
// Settles this session's tier from MOBILEGL_IPC_ADOPT_TIER and the negotiated data plane,
|
||||
// on `side`, and returns the tier the session runs (2 until package B). Logs at most one
|
||||
// line per call; aborts (SessionFail) only on the client over shared segments.
|
||||
// THE HELLO'S T0 ASK WHEN THE KNOB IS UNSET (LinkTerms.adoptTier, protocol.fbs): T0 as asked
|
||||
// by 0, except that the server names a refusal only at MGLOG_D. The ask travels because only
|
||||
// the server knows why it did not grant T0 (its allow switch, its platform, its POST).
|
||||
inline constexpr std::uint32_t kAdoptAskT0Default = 0x80;
|
||||
// An ask that is a T0 ask (0 by name, kAdoptAskT0Default by default).
|
||||
inline bool AdoptAskIsT0(std::uint32_t ask) { return ask == 0 || ask == kAdoptAskT0Default; }
|
||||
// This process's knob asks for T0 (0, or unset).
|
||||
bool AdoptTierWantsT0();
|
||||
// This process's knob is unset: T0 fallbacks are quiet.
|
||||
bool AdoptTierIsDefault();
|
||||
|
||||
// The tier the client's Hello asks for (LinkTerms.adoptTier): 0 when the knob says 0 and the
|
||||
// plane it proposes is shared segments, kAdoptAskT0Default when the knob is unset on shared
|
||||
// segments, else 2. Pure - the lines are the settle's.
|
||||
std::uint32_t AdoptTierAskFor(bool streamDataPlane);
|
||||
|
||||
// Settles this side's handshake answer from MOBILEGL_IPC_ADOPT_TIER and the negotiated data
|
||||
// plane and returns the ask this side made (client) or serves by its own knob (server):
|
||||
// AdoptTierAskFor's value for a client asking T0 over shared segments, 2 otherwise. Logs at
|
||||
// most one line per call (A1's stream refusal - at MGLOG_D when the knob is unset - and the
|
||||
// T1 refusal). Never aborts for 0/1/unset; any other value (only a direct assignment can
|
||||
// make one) is still Fatal{UnimplementedAdoptTier}.
|
||||
std::uint32_t SettleAdoptTierAtHandshake(bool streamDataPlane, AdoptTierSide side);
|
||||
|
||||
// True once a handshake in this process has settled the tier. The at-use check trusts a
|
||||
|
||||
@@ -1824,7 +1824,18 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
MGPipeApplyResourceDestroy(*static_cast<const MGPHandleOnly*>(payload));
|
||||
return true;
|
||||
|
||||
case MGPWireOp::MapPersistent:
|
||||
case MGPWireOp::MapPersistent: {
|
||||
// P11 B2 (CONTRACT-P11.md B2): A T0 SESSION'S ADOPTION RIDES THIS RECORD. The verb
|
||||
// sink takes the client's AHardwareBuffer for this seq off the aux socket and imports
|
||||
// it (Server/AdoptInbox.h says why that wait cannot hang the apply thread); it answers
|
||||
// for itself or says "not T0", and everything below is the T2 arm, unchanged.
|
||||
Int32 t0Status = ReplySink::kStatusDeclined;
|
||||
if (m_verbs != nullptr &&
|
||||
m_verbs->OnMapPersistent(*static_cast<const MGPHandleOnly*>(payload), seq, t0Status)) {
|
||||
PostReply(op, seq, t0Status, nullptr, 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// R-6 / R-2.4: A CONSTANT DECLINE IN P5, and the applier is not called at all.
|
||||
// Two reasons, and the second is the one worth writing down: the answer is a HOST
|
||||
// POINTER, which cannot cross; and MGPWireRec_MapPersistent's payload is a bare
|
||||
|
||||
@@ -505,6 +505,13 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
class WireVerbSink {
|
||||
public:
|
||||
virtual ~WireVerbSink() = default;
|
||||
// P11 B2 (CONTRACT-P11.md B2): map_persistent in a session that runs T0. True = the sink
|
||||
// handled it and `status` is the answer (OK: the client's AHardwareBuffer is now the
|
||||
// store; DECLINED: the store runs T2); false = not a T0 session, and the codec gives
|
||||
// today's constant decline. `seq` is the record's, which is what the store's Offer names.
|
||||
virtual Bool OnMapPersistent(const MG_Pipe::MGPHandleOnly&, Uint64 /*seq*/, Int32& /*status*/) {
|
||||
return false;
|
||||
}
|
||||
virtual Bool OnFenceCreate(const MG_Pipe::MGPHandleOnly&) { return false; }
|
||||
virtual Bool OnFenceDestroy(const MG_Pipe::MGPHandleOnly&) { return false; }
|
||||
virtual Bool OnFenceStatus(const MG_Pipe::MGPHandleOnly&, Uint32&) { return false; }
|
||||
|
||||
@@ -589,6 +589,18 @@ namespace MobileGL::MG_State::GLState {
|
||||
// illegal until P8/P9 make it mean "fully narrowed - nothing is dirty".
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
if (m_size != 0 && MG_Pipe::MGPipeResourceSubsystemEnabled() && m_resource.IsGpuResident()) {
|
||||
// P11 B2: A T0 STORE IS READ WHERE IT IS. Under split a store is resident only
|
||||
// when T0 adopted it - its pages ARE the client's AHardwareBuffer - so no bytes
|
||||
// need to come back: the readback's round trip is "done, no bytes". The server
|
||||
// lands every resident write it queued (GPU-ordered), waits for its GPU, answers,
|
||||
// and only then does this read the held mapping (monolith's adopted-store readback,
|
||||
// Managers.cpp's persistentMapped arm, by the same rule). The flag clears here
|
||||
// because no writeback will arrive to clear it (WritebackFromBackend).
|
||||
MG_Pipe::MGPipeEmitResourceReadback(*this);
|
||||
m_gpuWritePending = false;
|
||||
return;
|
||||
}
|
||||
if (m_size != 0 && MG_Pipe::MGPipeResourceSubsystemEnabled()) {
|
||||
const SizeT sliceBytes = MG_Remote::Client::BufferWritebackSliceBytes();
|
||||
if (sliceBytes != 0 && m_size > sliceBytes) {
|
||||
@@ -936,6 +948,12 @@ namespace MobileGL::MG_State::GLState {
|
||||
!(access & BufferMappingAccessBit::FlushExplicit) &&
|
||||
MG_Pipe::MGPipeResourceSubsystemEnabled()) {
|
||||
if (void* pushedBase = MG_Pipe::MGPipeEmitMapPersistent(*this)) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P11 B2 made this reachable (a T0 adoption), so the tracker lets go of the
|
||||
// shadow range WHILE THE SHADOW IS STILL OURS: AdoptPersistentMap frees it, and
|
||||
// an untrack after that would mprotect pages the buffer no longer owns.
|
||||
MG_Remote::Client::PersistentMapTracker::Instance().Forget(*this);
|
||||
#endif
|
||||
m_resource.AdoptPersistentMap(pushedBase);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// An adoption takes the buffer OUT of the push set and out of the
|
||||
|
||||
@@ -64,6 +64,18 @@ namespace MobileGL::MG_State::GLState {
|
||||
if (bindingPoint.GetBoundObject() == it->second) {
|
||||
bindingPoint.Bind(nullptr);
|
||||
bindingPoint.ClearRange();
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// An UNBIND, and the one writer of an indexed point that is not an
|
||||
// entry point (GL_Buffer.cpp's BindBuffer{Base,Range}_State and
|
||||
// Core.cpp's transform-feedback writers bump their own): without the
|
||||
// bump the target's window is never re-sent, the server goes on naming
|
||||
// this buffer's handle, and once its slot is reused at a newer
|
||||
// generation the next draw or dispatch that walks the window asks the
|
||||
// backend for the dead one - Espryt dies with Fatal{ProtocolCorruption,
|
||||
// "BackendSlotTable.Generation"} (DeletedBoundBufferScenario).
|
||||
NoteBindPointChanged(BufferBindPointTargets[static_cast<SizeT>(
|
||||
&bindingPointArray - m_bufferBindPointTargets.data())]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1325,6 +1325,13 @@ namespace MobileGL::MG_State {
|
||||
}
|
||||
|
||||
void GLContext::RestoreBoundTransformFeedbackState() {
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// The FOURTH writer of the transform-feedback binding points (a bind or a delete of
|
||||
// the bound transform-feedback object swaps the whole set in): it moves the generation
|
||||
// like the other three, so bit 17 cannot miss a swap whose two objects happen to carry
|
||||
// the same capture-span generation.
|
||||
NoteBufferBindPointChanged(BufferTarget::TransformFeedback);
|
||||
#endif
|
||||
const auto& object = m_transformFeedbackObjects[m_boundTransformFeedback];
|
||||
for (Uint i = 0; i < MAX_TRANSFORM_FEEDBACK_BUFFERS; ++i) {
|
||||
auto& point = m_bufferState.GetBindingPoint(BufferTarget::TransformFeedback, i);
|
||||
|
||||
@@ -538,13 +538,14 @@ TEST_F(SplitBufferSet, UnderSplitTheWritebackClearsThePendingFlagAndNotTheReques
|
||||
EXPECT_FALSE(buffer->HasOutstandingGpuWrite());
|
||||
}
|
||||
|
||||
// R-6's tier gate in P11 A1's shape (CONTRACT-P11 §1). T2 is the only implemented tier, and 0 / 1
|
||||
// are SETTLED AT THE HANDSHAKE by the data plane rather than discovered at the first
|
||||
// map_persistent: a stream refuses them by name and runs T2 on either side, a client over shared
|
||||
// segments dies there by name, a server over shared segments serves T2. The at-use check trusts a
|
||||
// settled session and still dies by name for a map_persistent no handshake settled. The session
|
||||
// halves are RemoteClientControls.AdoptTier*OverSharedSegments* and AdoptTierStreamTest.
|
||||
TEST_F(SplitBufferSet, OnlyAdoptTierTwoIsImplemented) {
|
||||
// The tier gate in P11 B2's shape (CONTRACT-P11 §1 and B2). 0 / 1 are SETTLED AT THE HANDSHAKE by
|
||||
// the data plane rather than discovered at the first map_persistent: a stream refuses them by name
|
||||
// and runs T2 on either side; over shared segments a client with 0 ASKS T0 (0), with 1 is refused
|
||||
// by name and asks T2, and a server serves by the client's ask (its own knob answers 2). None of
|
||||
// them dies any more (ID-P11-14). The at-use check trusts a settled session and still dies by
|
||||
// name for a map_persistent no handshake settled. The session halves are RemoteClientAdoptT0.*
|
||||
// and AdoptTierStreamTest.
|
||||
TEST_F(SplitBufferSet, TheAdoptTierIsSettledAtTheHandshakeAndNeverFatal) {
|
||||
namespace Tier = MG_Remote::Transport;
|
||||
EXPECT_TRUE(MG_Remote::Client::AdoptTierIsEmulate());
|
||||
for (const Uint32 tier : {0u, 1u}) {
|
||||
@@ -552,8 +553,11 @@ TEST_F(SplitBufferSet, OnlyAdoptTierTwoIsImplemented) {
|
||||
MG_Config::Ipc.AdoptTier = tier;
|
||||
Tier::ForgetAdoptTierSettlementForTest();
|
||||
EXPECT_DEATH(MG_Remote::Client::AdoptTierIsEmulate(), "UnimplementedAdoptTier.*no handshake settled");
|
||||
EXPECT_DEATH(Tier::SettleAdoptTierAtHandshake(false, Tier::AdoptTierSide::Client),
|
||||
"UnimplementedAdoptTier.*refused at the handshake over shared segments");
|
||||
Tier::ForgetAdoptTierSettlementForTest();
|
||||
EXPECT_EQ(Tier::SettleAdoptTierAtHandshake(false, Tier::AdoptTierSide::Client), tier == 0 ? 0u : 2u);
|
||||
EXPECT_EQ(Tier::AdoptTierAskFor(false), tier == 0 ? 0u : 2u);
|
||||
EXPECT_EQ(Tier::AdoptTierAskFor(true), 2u);
|
||||
EXPECT_TRUE(MG_Remote::Client::AdoptTierIsEmulate());
|
||||
for (const auto side : {Tier::AdoptTierSide::Client, Tier::AdoptTierSide::Server}) {
|
||||
Tier::ForgetAdoptTierSettlementForTest();
|
||||
EXPECT_EQ(Tier::SettleAdoptTierAtHandshake(true, side), 2u);
|
||||
@@ -563,6 +567,19 @@ TEST_F(SplitBufferSet, OnlyAdoptTierTwoIsImplemented) {
|
||||
EXPECT_EQ(Tier::SettleAdoptTierAtHandshake(false, Tier::AdoptTierSide::Server), 2u);
|
||||
EXPECT_TRUE(MG_Remote::Client::AdoptTierIsEmulate());
|
||||
}
|
||||
// UNSET (the default since 2026-09-29): a T0 ask of its own kind over shared segments, 2 over a
|
||||
// stream, and a session-free caller runs T2 quietly instead of dying - it never named a tier.
|
||||
MG_Config::Ipc.AdoptTier = MG_Config::kAdoptTierUnset;
|
||||
Tier::ForgetAdoptTierSettlementForTest();
|
||||
EXPECT_TRUE(MG_Remote::Client::AdoptTierIsEmulate());
|
||||
EXPECT_EQ(Tier::AdoptTierAskFor(false), Tier::kAdoptAskT0Default);
|
||||
EXPECT_EQ(Tier::AdoptTierAskFor(true), 2u);
|
||||
EXPECT_EQ(Tier::SettleAdoptTierAtHandshake(false, Tier::AdoptTierSide::Client), Tier::kAdoptAskT0Default);
|
||||
for (const auto side : {Tier::AdoptTierSide::Client, Tier::AdoptTierSide::Server}) {
|
||||
Tier::ForgetAdoptTierSettlementForTest();
|
||||
EXPECT_EQ(Tier::SettleAdoptTierAtHandshake(true, side), 2u);
|
||||
}
|
||||
EXPECT_TRUE(MG_Remote::Client::AdoptTierIsEmulate());
|
||||
MG_Config::Ipc.AdoptTier = 2;
|
||||
}
|
||||
|
||||
@@ -777,7 +794,7 @@ TEST(SplitBufferSet, BothEdgesOfAWriteMapPublishOneStateRecord) { MGL_SPLIT_ONLY
|
||||
TEST(SplitBufferSet, AZeroBlockSizeTurnsThePushOffRatherThanMakingItUnlimited) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, ADestroyedBufferLeavesTheSet) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, UnderSplitTheWritebackClearsThePendingFlagAndNotTheRequest) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, OnlyAdoptTierTwoIsImplemented) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, TheAdoptTierIsSettledAtTheHandshakeAndNeverFatal) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, ASubPageMapIsOneProtectedPageAndAWriteThroughItFaults) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, AShadowThatFailsThePageGranularTestKeepsTheInwardAlignmentAndItsEdges) {
|
||||
MGL_SPLIT_ONLY_OR_SKIP();
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
// MobileGL - MobileGL/MG_Test/Wire/AdoptInboxTest.cpp
|
||||
// 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
|
||||
|
||||
// P11 B2 (MG_Remote/CONTRACT-P11.md B2). Server::AdoptInbox - T0's Offers matched to their
|
||||
// map_persistent records BY SEQ, never by arrival order - over both aux channels the product has:
|
||||
// the in-process queue (inproc) and a real socket pair with SCM_RIGHTS (fork spawn / unix / fd:).
|
||||
//
|
||||
// Every case proves WHICH descriptor came back, not just that one did: each Offer's descriptor is
|
||||
// a pipe whose far end carries the Offer's own seq, so a mix-up reads the wrong number.
|
||||
|
||||
#include <MG_Remote/Server/AdoptInbox.h>
|
||||
#include <MG_Remote/Transport/AdoptT0.h>
|
||||
#include <MG_Remote/Transport/InProcessTransport.h>
|
||||
#include <MG_Remote/Transport/SocketTransport.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace MobileGL;
|
||||
using namespace MobileGL::MG_Remote;
|
||||
namespace T0 = MobileGL::MG_Remote::Transport::AdoptT0;
|
||||
|
||||
namespace {
|
||||
|
||||
struct Channel {
|
||||
std::unique_ptr<Transport::ITransport> client;
|
||||
std::unique_ptr<Transport::ITransport> server;
|
||||
};
|
||||
|
||||
Channel MakeChannel(bool socket) {
|
||||
Channel c;
|
||||
if (socket) {
|
||||
std::unique_ptr<Transport::SocketTransport> a, b;
|
||||
EXPECT_EQ(Transport::SocketTransport::CreatePair(a, b), MOBILEGL_OK);
|
||||
c.client = std::move(a);
|
||||
c.server = std::move(b);
|
||||
} else {
|
||||
std::unique_ptr<Transport::InProcessTransport> a, b;
|
||||
Transport::InProcessTransport::CreatePair(a, b);
|
||||
c.client = std::move(a);
|
||||
c.server = std::move(b);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
// An Offer for `seq` whose descriptor is a pipe's read end; the pipe carries `seq` itself.
|
||||
void SendOffer(Transport::ITransport& client, std::uint64_t seq, std::uint32_t flags = T0::kOfferHasBuffer) {
|
||||
int p[2] = {-1, -1};
|
||||
ASSERT_EQ(::pipe(p), 0);
|
||||
ASSERT_EQ(::write(p[1], &seq, sizeof(seq)), static_cast<ssize_t>(sizeof(seq)));
|
||||
::close(p[1]);
|
||||
T0::Offer offer{};
|
||||
offer.magic = T0::kOfferMagic;
|
||||
offer.version = T0::kOfferVersion;
|
||||
offer.seq = seq;
|
||||
offer.size = 4096;
|
||||
offer.flags = flags;
|
||||
ASSERT_EQ(client.ShareFd(p[0], MobileGLByteSpan{&offer, sizeof(offer)}), MOBILEGL_OK);
|
||||
::close(p[0]);
|
||||
}
|
||||
|
||||
// The seq the descriptor's pipe carries, and closes it.
|
||||
std::uint64_t SeqOf(int fd) {
|
||||
std::uint64_t seq = ~0ull;
|
||||
EXPECT_EQ(::read(fd, &seq, sizeof(seq)), static_cast<ssize_t>(sizeof(seq)));
|
||||
::close(fd);
|
||||
return seq;
|
||||
}
|
||||
|
||||
class AdoptInboxTest : public ::testing::TestWithParam<bool> {};
|
||||
|
||||
} // namespace
|
||||
|
||||
// In order: each Take finds its own Offer.
|
||||
TEST_P(AdoptInboxTest, OffersInOrderAreTakenByTheirOwnRecords) {
|
||||
Channel c = MakeChannel(GetParam());
|
||||
Server::AdoptInbox inbox;
|
||||
inbox.Attach(c.server.get());
|
||||
SendOffer(*c.client, 10);
|
||||
SendOffer(*c.client, 11);
|
||||
for (std::uint64_t seq : {10ull, 11ull}) {
|
||||
int fd = -1;
|
||||
T0::Offer offer{};
|
||||
std::string why;
|
||||
ASSERT_EQ(inbox.Take(seq, 1000, &fd, &offer, why), Server::AdoptInbox::Outcome::Taken) << why;
|
||||
EXPECT_EQ(offer.seq, seq);
|
||||
EXPECT_EQ(SeqOf(fd), seq);
|
||||
}
|
||||
EXPECT_EQ(inbox.Kept(), 0u);
|
||||
}
|
||||
|
||||
// OUT OF ORDER: the Offer for the later record arrives first. It is kept for that record, the
|
||||
// earlier record still gets its own, and the later one is then served from what was kept.
|
||||
TEST_P(AdoptInboxTest, AnOfferForALaterRecordIsKeptForItAndDoesNotAnswerAnEarlierOne) {
|
||||
Channel c = MakeChannel(GetParam());
|
||||
Server::AdoptInbox inbox;
|
||||
inbox.Attach(c.server.get());
|
||||
SendOffer(*c.client, 21);
|
||||
SendOffer(*c.client, 20);
|
||||
int fd = -1;
|
||||
T0::Offer offer{};
|
||||
std::string why;
|
||||
ASSERT_EQ(inbox.Take(20, 1000, &fd, &offer, why), Server::AdoptInbox::Outcome::Taken) << why;
|
||||
EXPECT_EQ(SeqOf(fd), 20u);
|
||||
EXPECT_EQ(inbox.Kept(), 1u);
|
||||
ASSERT_EQ(inbox.Take(21, 0, &fd, &offer, why), Server::AdoptInbox::Outcome::Taken) << why;
|
||||
EXPECT_EQ(SeqOf(fd), 21u);
|
||||
EXPECT_EQ(inbox.Kept(), 0u);
|
||||
}
|
||||
|
||||
// LATE: the record is being waited for when its Offer arrives.
|
||||
TEST_P(AdoptInboxTest, AnOfferThatArrivesDuringTheWaitIsTaken) {
|
||||
Channel c = MakeChannel(GetParam());
|
||||
Server::AdoptInbox inbox;
|
||||
inbox.Attach(c.server.get());
|
||||
std::thread late([&] {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
SendOffer(*c.client, 30);
|
||||
});
|
||||
int fd = -1;
|
||||
T0::Offer offer{};
|
||||
std::string why;
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
const auto outcome = inbox.Take(30, 2000, &fd, &offer, why);
|
||||
const auto waited = std::chrono::steady_clock::now() - start;
|
||||
late.join();
|
||||
ASSERT_EQ(outcome, Server::AdoptInbox::Outcome::Taken) << why;
|
||||
EXPECT_EQ(SeqOf(fd), 30u);
|
||||
EXPECT_GE(waited, std::chrono::milliseconds(150));
|
||||
}
|
||||
|
||||
// STALE: an Offer for a record that was already answered (its wait timed out) is closed and
|
||||
// counted, and does not answer the record being waited for.
|
||||
TEST_P(AdoptInboxTest, AnOfferForAnEarlierRecordIsStaleAndClosed) {
|
||||
Channel c = MakeChannel(GetParam());
|
||||
Server::AdoptInbox inbox;
|
||||
inbox.Attach(c.server.get());
|
||||
SendOffer(*c.client, 40);
|
||||
SendOffer(*c.client, 41);
|
||||
int fd = -1;
|
||||
T0::Offer offer{};
|
||||
std::string why;
|
||||
ASSERT_EQ(inbox.Take(41, 1000, &fd, &offer, why), Server::AdoptInbox::Outcome::Taken) << why;
|
||||
EXPECT_EQ(SeqOf(fd), 41u);
|
||||
EXPECT_EQ(inbox.StaleOffers(), 1u);
|
||||
}
|
||||
|
||||
// MISSING: nothing comes - a bounded TimedOut with a reason, never a hang.
|
||||
TEST_P(AdoptInboxTest, AnOfferThatNeverComesTimesOutWithinItsBound) {
|
||||
Channel c = MakeChannel(GetParam());
|
||||
Server::AdoptInbox inbox;
|
||||
inbox.Attach(c.server.get());
|
||||
int fd = -1;
|
||||
T0::Offer offer{};
|
||||
std::string why;
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
EXPECT_EQ(inbox.Take(50, 300, &fd, &offer, why), Server::AdoptInbox::Outcome::TimedOut);
|
||||
const auto waited = std::chrono::steady_clock::now() - start;
|
||||
EXPECT_EQ(fd, -1);
|
||||
EXPECT_NE(why.find("no store arrived"), std::string::npos) << why;
|
||||
EXPECT_LT(waited, std::chrono::milliseconds(2000));
|
||||
}
|
||||
|
||||
// A descriptor whose sideband is not an Offer (another sender on the channel) is closed and
|
||||
// counted, and the real Offer behind it still answers.
|
||||
TEST_P(AdoptInboxTest, ADescriptorThatIsNotAnOfferIsSkipped) {
|
||||
Channel c = MakeChannel(GetParam());
|
||||
Server::AdoptInbox inbox;
|
||||
inbox.Attach(c.server.get());
|
||||
int p[2] = {-1, -1};
|
||||
ASSERT_EQ(::pipe(p), 0);
|
||||
const std::uint32_t junk = 7;
|
||||
ASSERT_EQ(c.client->ShareFd(p[0], MobileGLByteSpan{&junk, sizeof(junk)}), MOBILEGL_OK);
|
||||
::close(p[0]);
|
||||
::close(p[1]);
|
||||
SendOffer(*c.client, 60);
|
||||
int fd = -1;
|
||||
T0::Offer offer{};
|
||||
std::string why;
|
||||
ASSERT_EQ(inbox.Take(60, 1000, &fd, &offer, why), Server::AdoptInbox::Outcome::Taken) << why;
|
||||
EXPECT_EQ(SeqOf(fd), 60u);
|
||||
EXPECT_EQ(inbox.MalformedOffers(), 1u);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(Channels, AdoptInboxTest, ::testing::Values(false, true),
|
||||
[](const ::testing::TestParamInfo<bool>& info) {
|
||||
return info.param ? std::string("socket") : std::string("inprocess");
|
||||
});
|
||||
@@ -151,6 +151,33 @@ TEST(AdoptTierStream, AClientNamingT0OrT1IsRefusedOnceAndItsMapPersistentIsDecli
|
||||
}
|
||||
}
|
||||
|
||||
// P11 B2: THE KNOB UNSET - T0 BY DEFAULT since 2026-09-29 - ON A STREAM. The Hello asks 2 (a stream
|
||||
// carries T2 only), the session runs T2, and nothing says so above MGLOG_D: every tcp session would
|
||||
// otherwise carry A1's line. The client still COUNTS the fallback (ClientSession::T0Fallbacks,
|
||||
// reported through PeerReport::pixel). The supervisor's own knob is unset as well (ServerSpawn
|
||||
// scrubs it), so its stream settle is quiet too.
|
||||
// RED-ONCE: log the unset stream settle at W instead of D -> one AdoptTierOnStream line, not 0.
|
||||
TEST(AdoptTierStream, AnUnsetKnobRunsT2OnAStreamQuietlyAndCountsTheFallback) {
|
||||
ServerProcess server;
|
||||
ASSERT_TRUE(LaunchSupervisor("adopt-unset", &server)) << server.Log();
|
||||
const auto body = [](Remote::Client::ClientSession& client, PeerReport& r) {
|
||||
MapPersistentThenARecord(client, r);
|
||||
r.pixel = static_cast<Uint32>(client.T0Fallbacks());
|
||||
};
|
||||
const PeerReport r = RunPeer(server.endpoint, body, /*stopCleanly=*/true, 30000, 0, nullptr,
|
||||
[] { MG_Config::Ipc.AdoptTier = MG_Config::kAdoptTierUnset; });
|
||||
const std::string client = ClientLog(server);
|
||||
ASSERT_EQ(r.started, 1) << "the session did not come up: " << r.note << "\n" << client;
|
||||
EXPECT_EQ(r.status, Remote::Wire::ReplySink::kStatusDeclined) << "a stream session runs T2\n" << client;
|
||||
EXPECT_EQ(r.applied, 1) << client;
|
||||
EXPECT_EQ(r.pixel, 1u) << "the stream's T0 fallback was not counted\n" << client;
|
||||
for (const char* line : {"AdoptTierOnStream", "T0 by default", "AdoptT0Unavailable", "T0 session totals"}) {
|
||||
EXPECT_EQ(Count(client, line), 0u) << "an unset knob's fallback is MGLOG_D only: " << line << "\n" << client;
|
||||
EXPECT_EQ(Count(server.Log(), line), 0u) << line << "\n" << server.Log();
|
||||
}
|
||||
EXPECT_EQ(Count(client, "Fatal{"), 0u) << client;
|
||||
}
|
||||
|
||||
TEST(AdoptTierStream, AServerNamingT0RefusesOncePerSessionAndServesT2) {
|
||||
ServerProcess server;
|
||||
const std::string peerBase = "/tmp/mgl-p11-adopt-server-peers-" + std::to_string(::getpid()) + ".log";
|
||||
|
||||
@@ -36,6 +36,10 @@ if (NOT WIN32)
|
||||
# P11 PAIR: the unix supervisors' pairing of a client's control and aux connections by the
|
||||
# nonce each presents first (Server/PairAcceptor), over real unix and TCP listeners.
|
||||
list(APPEND MOBILEGL_WIRE_TESTS PairAcceptorTest)
|
||||
# P11 B2: T0's Offers matched to their map_persistent records by seq (Server/AdoptInbox) over
|
||||
# the in-process queue and a real SCM_RIGHTS socket pair: in order, out of order, late, stale,
|
||||
# missing (bounded), not-an-Offer.
|
||||
list(APPEND MOBILEGL_WIRE_TESTS AdoptInboxTest)
|
||||
# P9 W3: the graded log forward - the level mapping both ways, the logger's level reaching the
|
||||
# forwarder, and the channel against a transport whose writes can be held (and a real socket
|
||||
# pair nobody reads). POSIX for the socket pair.
|
||||
|
||||
@@ -0,0 +1,386 @@
|
||||
// P11 B2 (MG_Remote/CONTRACT-P11.md B2): T0'S PROTOCOL ON THE HOST, over a live inproc session.
|
||||
//
|
||||
// A host has no AHardwareBuffer, so what these prove is the protocol, the negotiation and the
|
||||
// fallback - never GPU correctness, which is the device's (B2's device gates). Two halves:
|
||||
// * the real host platform: every T0 ask falls back to T2 by name (no AHB, the allow switch,
|
||||
// knob 1), and never dies - A1's handshake Fatal for SharedSegments + 0/1 is gone;
|
||||
// * a STAND-IN platform (a memfd for the AHB, AdoptT0::SetPlatformForTest) plus a stand-in
|
||||
// importer (MGPipeResourceOps::ImportExternal): the whole T0 path runs - the grant, the caps
|
||||
// bit, the client's store, the Offer on the real aux channel matched by seq, the import - and
|
||||
// the store lands with the client's bytes, including when its Offer comes after its record;
|
||||
// a lost Offer is a named DECLINED within the bounded wait, not a hang.
|
||||
#if MGTEST_HAVE_FORK
|
||||
#include <MG_Remote/Transport/AdoptT0.h>
|
||||
#include <MG_Remote/Transport/AdoptTier.h>
|
||||
#include <MG_Remote/Transport/FdPassing.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
namespace {
|
||||
namespace T0 = MobileGL::MG_Remote::Transport::AdoptT0;
|
||||
|
||||
constexpr Uint64 kT0Bytes = 64 * 1024;
|
||||
|
||||
// ---- the stand-in AHB: a memfd, mapped shared, reference-counted -------------------------
|
||||
struct FakeAhb {
|
||||
int fd = -1;
|
||||
void* map = nullptr;
|
||||
Uint64 size = 0;
|
||||
std::atomic<int> refs{1};
|
||||
};
|
||||
void FakeDrop(FakeAhb* f) {
|
||||
if (f != nullptr && --f->refs == 0) {
|
||||
if (f->map != nullptr) ::munmap(f->map, f->size);
|
||||
if (f->fd >= 0) ::close(f->fd);
|
||||
delete f;
|
||||
}
|
||||
}
|
||||
bool FakeHasAhb() { return true; }
|
||||
bool FakeAllocate(std::uint64_t size, const void* seed, T0::HeldStore& out, std::string& why) {
|
||||
auto* f = new FakeAhb;
|
||||
f->fd = static_cast<int>(::syscall(SYS_memfd_create, "t0-fake", 1u /*MFD_CLOEXEC*/));
|
||||
if (f->fd < 0 || ::ftruncate(f->fd, static_cast<off_t>(size)) != 0) {
|
||||
why = "memfd";
|
||||
FakeDrop(f);
|
||||
return false;
|
||||
}
|
||||
f->size = size;
|
||||
f->map = ::mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, f->fd, 0);
|
||||
if (f->map == MAP_FAILED) {
|
||||
f->map = nullptr;
|
||||
why = "mmap";
|
||||
FakeDrop(f);
|
||||
return false;
|
||||
}
|
||||
if (seed != nullptr) std::memcpy(f->map, seed, size);
|
||||
out.ahb = f;
|
||||
out.ptr = f->map;
|
||||
out.size = size;
|
||||
return true;
|
||||
}
|
||||
int FakeMakeHop(const T0::HeldStore* store, std::string& why) {
|
||||
int pair[2] = {-1, -1};
|
||||
if (::socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, pair) != 0) {
|
||||
why = "socketpair";
|
||||
return -1;
|
||||
}
|
||||
if (store != nullptr && store->ahb != nullptr) {
|
||||
auto* f = static_cast<FakeAhb*>(store->ahb);
|
||||
const Uint64 size = f->size;
|
||||
if (Transport::FdPassing::SendFd(pair[0], f->fd, MobileGLByteSpan{&size, sizeof(size)}) != MOBILEGL_OK) {
|
||||
why = "send";
|
||||
::close(pair[0]);
|
||||
::close(pair[1]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
::close(pair[0]);
|
||||
return pair[1];
|
||||
}
|
||||
void FakeReleaseHeld(T0::HeldStore& store) {
|
||||
FakeDrop(static_cast<FakeAhb*>(store.ahb));
|
||||
store = T0::HeldStore{};
|
||||
}
|
||||
bool FakeReceive(int hopFd, std::uint64_t size, void** outAhb, std::string& why) {
|
||||
*outAhb = nullptr;
|
||||
int fd = -1;
|
||||
Uint8 sideband[Transport::FdPassing::kMaxSidebandBytes] = {};
|
||||
std::uint64_t sidebandSize = 0;
|
||||
if (Transport::FdPassing::ReceiveFd(hopFd, &fd, MobileGLMutableByteSpan{sideband, sizeof(sideband)},
|
||||
&sidebandSize, 1000) != MOBILEGL_OK) {
|
||||
why = "no stand-in handle on the hop";
|
||||
return false;
|
||||
}
|
||||
auto* f = new FakeAhb;
|
||||
f->fd = fd;
|
||||
f->size = size;
|
||||
f->map = ::mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (f->map == MAP_FAILED) {
|
||||
f->map = nullptr;
|
||||
FakeDrop(f);
|
||||
why = "mmap";
|
||||
return false;
|
||||
}
|
||||
*outAhb = f;
|
||||
return true;
|
||||
}
|
||||
void FakeAcquire(void* ahb) { ++static_cast<FakeAhb*>(ahb)->refs; }
|
||||
void FakeRelease(void* ahb) { FakeDrop(static_cast<FakeAhb*>(ahb)); }
|
||||
|
||||
const T0::PlatformForTest kFakePlatform{&FakeHasAhb, &FakeAllocate, &FakeMakeHop, &FakeReleaseHeld,
|
||||
&FakeReceive, &FakeAcquire, &FakeRelease};
|
||||
|
||||
// ---- the stand-in importer: records what it was handed, keeps its own reference ----------
|
||||
struct FakeImports {
|
||||
MGPipeHandle handle{};
|
||||
Uint64 size = 0;
|
||||
Uint64 count = 0;
|
||||
std::vector<Uint8> bytes;
|
||||
void* held = nullptr;
|
||||
};
|
||||
FakeImports g_fakeImports;
|
||||
Bool FakeImportExternal(MGPipeHandle res, void* ahb, Uint64 size) {
|
||||
auto* f = static_cast<FakeAhb*>(ahb);
|
||||
g_fakeImports.handle = res;
|
||||
g_fakeImports.size = size;
|
||||
++g_fakeImports.count;
|
||||
const auto* first = static_cast<const Uint8*>(f->map);
|
||||
g_fakeImports.bytes.assign(first, first + size);
|
||||
T0::AcquireImported(ahb);
|
||||
g_fakeImports.held = ahb;
|
||||
return true;
|
||||
}
|
||||
Bool FakeSelfTest(char* why, Uint64 whyBytes) {
|
||||
std::snprintf(why, static_cast<size_t>(whyBytes), "stand-in platform (host protocol test, no GPU)");
|
||||
return true;
|
||||
}
|
||||
MGPipeResourceOps MakeFakeOps() {
|
||||
MGPipeResourceOps ops{};
|
||||
ops.ImportExternal = &FakeImportExternal;
|
||||
ops.SelfTestExternal = &FakeSelfTest;
|
||||
return ops;
|
||||
}
|
||||
MGPipeResourceOps g_fakeOps = MakeFakeOps();
|
||||
|
||||
// What the server's first native bind does for T0, on the apply thread like the real one: the
|
||||
// grant (and its POST), then the caps that bind republishes - which the client's make-current
|
||||
// adopts, as here.
|
||||
void GrantAtFirstBind() {
|
||||
if (Srv::ServerLoopInstance().RunProbeOnApplyThreadForTesting([](void*) {
|
||||
Srv::ServerSessionInstance().SettleAdoptT0AtBind();
|
||||
return Srv::ServerSessionInstance().PublishCapsSnapshot();
|
||||
}, nullptr) != MOBILEGL_OK) ::_exit(120);
|
||||
(void)ClientSessionInstance().PumpControlPlane();
|
||||
}
|
||||
|
||||
MGPHandleOnly MakeBufferStore(Uint32 slot, Uint64 bytes) {
|
||||
MGPResourceDesc desc{};
|
||||
desc.Resource = MGPipeHandle{slot, 1};
|
||||
desc.Target = MG_Pipe::kMGPipeResourceTargetBuffer;
|
||||
desc.Width = static_cast<Uint32>(bytes);
|
||||
desc.Height = desc.Depth = 1;
|
||||
if (!MGPipeRouteResourceCreate(desc)) ::_exit(121);
|
||||
(void)MGPipeRouteResourceRespecify(desc, nullptr);
|
||||
MGPHandleOnly handle{};
|
||||
handle.Handle = desc.Resource;
|
||||
handle.Kind = static_cast<Uint32>(MGPipeKind::Buffer);
|
||||
return handle;
|
||||
}
|
||||
|
||||
std::vector<Uint8> Pattern(Uint64 bytes, Uint8 salt) {
|
||||
std::vector<Uint8> out(bytes);
|
||||
for (Uint64 i = 0; i < bytes; ++i) out[i] = static_cast<Uint8>((i * 131u + salt) & 0xFF);
|
||||
return out;
|
||||
}
|
||||
|
||||
size_t CountOf(const std::string& log, const std::string& needle) {
|
||||
size_t n = 0;
|
||||
for (size_t at = log.find(needle); at != std::string::npos; at = log.find(needle, at + 1)) ++n;
|
||||
return n;
|
||||
}
|
||||
|
||||
// The grant with the stand-ins, the store, and the map_persistent: returns the adopted pointer.
|
||||
void* AdoptOneStore(Uint8 salt, std::vector<Uint8>& seed) {
|
||||
MG_Config::Ipc.AdoptTier = 0;
|
||||
T0::SetPlatformForTest(&kFakePlatform);
|
||||
MG_Pipe::MGPipeSetResourceOps(&g_fakeOps);
|
||||
StartControlSession();
|
||||
GrantAtFirstBind();
|
||||
seed = Pattern(kT0Bytes, salt);
|
||||
const MGPHandleOnly handle = MakeBufferStore(5, kT0Bytes);
|
||||
return MGPipeRouteMapPersistent(handle, kT0Bytes, seed.data());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// A1's "SharedSegments + 0 dies at the handshake" is GONE (ID-P11-14): knob 0 over shared segments
|
||||
// ASKS T0 in the Hello, and a server that does not grant it (here: no bind ever ran, so no
|
||||
// kCapAdoptT0) leaves the session on T2 with ONE named client line at the first map_persistent.
|
||||
// RED-ONCE: restore the client's SessionFail in SettleAdoptTierAtHandshake -> the child dies
|
||||
// before 'S'.
|
||||
TEST(RemoteClientAdoptT0, KnobZeroOverSharedSegmentsAsksT0AndFallsBackToT2ByNameWithoutAGrant) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.AdoptTier = 0;
|
||||
StartControlSession();
|
||||
if (!Srv::ServerSessionInstance().AdoptT0Asked()) ::_exit(130); // the Hello asked T0
|
||||
MGPHandleOnly handle{};
|
||||
handle.Kind = static_cast<Uint32>(MGPipeKind::Buffer);
|
||||
if (MGPipeRouteMapPersistent(handle, 64, nullptr) != nullptr) ::_exit(131);
|
||||
if (MGPipeRouteMapPersistent(handle, 64, nullptr) != nullptr) ::_exit(132);
|
||||
if (ClientSessionInstance().AdoptT0()) ::_exit(133);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
EXPECT_EQ(CountOf(child.Log, "Refuse{AdoptT0Unavailable, \"no kCapAdoptT0\"}"), 1u) << child.Log;
|
||||
EXPECT_EQ(child.Log.find("Fatal{"), std::string::npos) << child.Log;
|
||||
}
|
||||
|
||||
// Knob 2 (the default) is today's T2, byte for byte: the Hello asks 2, the server settles nothing at
|
||||
// its bind even where T0 would work (the stand-in platform and importer are installed), no caps bit,
|
||||
// map_persistent declines as before, and neither side prints a T0 line.
|
||||
// RED-ONCE: make AdoptTierAskFor ask 0 whatever the knob -> the stand-in grants and imports, 200/202.
|
||||
TEST(RemoteClientAdoptT0, KnobTwoIsTodaysT2WithNoT0Line) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.AdoptTier = 2;
|
||||
T0::SetPlatformForTest(&kFakePlatform);
|
||||
MG_Pipe::MGPipeSetResourceOps(&g_fakeOps);
|
||||
StartControlSession();
|
||||
GrantAtFirstBind();
|
||||
if (Srv::ServerSessionInstance().AdoptT0Asked()) ::_exit(200);
|
||||
if (Srv::ServerSessionInstance().AdoptT0()) ::_exit(201);
|
||||
const auto seed = Pattern(kT0Bytes, 0x55);
|
||||
const MGPHandleOnly handle = MakeBufferStore(5, kT0Bytes);
|
||||
if (MGPipeRouteMapPersistent(handle, kT0Bytes, seed.data()) != nullptr) ::_exit(202);
|
||||
if (g_fakeImports.count != 0) ::_exit(203);
|
||||
if (ClientSessionInstance().AdoptT0()) ::_exit(204);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
for (const char* line : {"T0 POST", "T0 granted", "AdoptT0", "T0 store", "T0 imported", "AdoptTier"})
|
||||
EXPECT_EQ(child.Log.find(line), std::string::npos) << line << "\n" << child.Log;
|
||||
EXPECT_EQ(child.Log.find("Fatal{"), std::string::npos) << child.Log;
|
||||
}
|
||||
|
||||
// THE KNOB UNSET - T0 BY DEFAULT, the user's decision of 2026-09-29 - over shared segments on the
|
||||
// host's own platform (no AHardwareBuffer): the Hello asks T0 of its default kind, the server
|
||||
// refuses it at its first bind and the client falls back at its first map_persistent - both
|
||||
// QUIETLY (MGLOG_D only: every host session would otherwise carry two lines), both COUNTED.
|
||||
// Knob 0's named lines are KnobZero... / NoAhardwareBuffer... above; this is the unset half.
|
||||
// RED-ONCE: log the unset path's fallbacks at W instead of D -> the line counts below are 1, not 0.
|
||||
TEST(RemoteClientAdoptT0, AnUnsetKnobFallsBackToT2QuietlyAndCountsIt) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.AdoptTier = MG_Config::kAdoptTierUnset;
|
||||
MG_Pipe::MGPipeSetResourceOps(&g_fakeOps); // a backend WITH the members: the platform decides
|
||||
StartControlSession();
|
||||
if (!Srv::ServerSessionInstance().AdoptT0Asked()) ::_exit(210); // the Hello asked T0 by default
|
||||
if (!Srv::ServerSessionInstance().AdoptT0Quiet()) ::_exit(211);
|
||||
GrantAtFirstBind();
|
||||
if (Srv::ServerSessionInstance().AdoptT0()) ::_exit(212);
|
||||
if (Srv::ServerSessionInstance().T0Refusals() != 1) ::_exit(213); // counted, not said
|
||||
const auto seed = Pattern(kT0Bytes, 0x66);
|
||||
const MGPHandleOnly handle = MakeBufferStore(5, kT0Bytes);
|
||||
if (MGPipeRouteMapPersistent(handle, kT0Bytes, seed.data()) != nullptr) ::_exit(214); // T2: declined
|
||||
if (ClientSessionInstance().AdoptT0()) ::_exit(215);
|
||||
if (ClientSessionInstance().T0Fallbacks() != 1) ::_exit(216); // counted, not said
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
for (const char* line : {"AdoptT0Unavailable", "T0 by default", "T0 POST", "T0 session totals", "Refuse{"})
|
||||
EXPECT_EQ(CountOf(child.Log, line), 0u) << "an unset knob's fallback is MGLOG_D only: " << line << "\n"
|
||||
<< child.Log;
|
||||
EXPECT_EQ(child.Log.find("Fatal{"), std::string::npos) << child.Log;
|
||||
}
|
||||
|
||||
// Knob 1 names T1, which P11 closed: one named refusal, the Hello asks T2, never a Fatal.
|
||||
TEST(RemoteClientAdoptT0, KnobOneIsRefusedByNameAndAsksT2) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.AdoptTier = 1;
|
||||
StartControlSession();
|
||||
if (Srv::ServerSessionInstance().AdoptT0Asked()) ::_exit(140);
|
||||
MGPHandleOnly handle{};
|
||||
handle.Kind = static_cast<Uint32>(MGPipeKind::Buffer);
|
||||
if (MGPipeRouteMapPersistent(handle, 64, nullptr) != nullptr) ::_exit(141);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
EXPECT_EQ(CountOf(child.Log, "Refuse{AdoptTierClosed, \"T1\"}"), 1u) << child.Log;
|
||||
EXPECT_EQ(child.Log.find("Fatal{"), std::string::npos) << child.Log;
|
||||
}
|
||||
|
||||
// The host's own platform: the grant refuses by name (no AHB) and the client falls back by name.
|
||||
TEST(RemoteClientAdoptT0, NoAhardwareBufferOnThisPlatformIsT2AndTwoNamedLines) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.AdoptTier = 0;
|
||||
MG_Pipe::MGPipeSetResourceOps(&g_fakeOps); // a backend WITH the members: the platform decides
|
||||
StartControlSession();
|
||||
GrantAtFirstBind();
|
||||
if (Srv::ServerSessionInstance().AdoptT0()) ::_exit(150);
|
||||
if (ClientSessionInstance().AdoptT0()) ::_exit(151);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
EXPECT_EQ(CountOf(child.Log, "Refuse{AdoptT0Unavailable, \"no AHardwareBuffer\"}"), 1u) << child.Log;
|
||||
EXPECT_EQ(CountOf(child.Log, "Refuse{AdoptT0Unavailable, \"no kCapAdoptT0\"}"), 1u) << child.Log;
|
||||
}
|
||||
|
||||
// The server's allow switch off: T2 and a named line, even where T0 would otherwise work.
|
||||
TEST(RemoteClientAdoptT0, TheServersAllowSwitchOffIsT2AndANamedLine) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.AllowAdoptT0 = 0;
|
||||
std::vector<Uint8> seed;
|
||||
if (AdoptOneStore(0x11, seed) != nullptr) ::_exit(160);
|
||||
if (g_fakeImports.count != 0) ::_exit(161);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
EXPECT_EQ(CountOf(child.Log, "Refuse{AdoptT0Unavailable, \"disallowed\"}"), 1u) << child.Log;
|
||||
EXPECT_NE(child.Log.find("MOBILEGL_IPC_ALLOW_ADOPT_T0=0"), std::string::npos) << child.Log;
|
||||
}
|
||||
|
||||
// THE WHOLE PATH: granted, the caps bit read, the store allocated and seeded from the shadow,
|
||||
// its Offer queued before its record, matched by seq, imported - and the importer holds exactly
|
||||
// the client's bytes, the client's pointer is the store, and both arms count it.
|
||||
// RED-ONCE (host): do not publish kCapAdoptT0 (ServerSession::PublishCapsSnapshot) -> the client
|
||||
// never adopts, 170.
|
||||
TEST(RemoteClientAdoptT0, AGrantedStoreLandsWithTheClientsBytes) {
|
||||
const auto child = RunInChild([] {
|
||||
std::vector<Uint8> seed;
|
||||
void* adopted = AdoptOneStore(0x22, seed);
|
||||
if (adopted == nullptr) ::_exit(170);
|
||||
if (std::memcmp(adopted, seed.data(), kT0Bytes) != 0) ::_exit(171);
|
||||
if (g_fakeImports.count != 1 || g_fakeImports.size != kT0Bytes) ::_exit(172);
|
||||
if (g_fakeImports.handle.Slot != 5 || g_fakeImports.handle.Gen != 1) ::_exit(173);
|
||||
if (g_fakeImports.bytes != seed) ::_exit(174);
|
||||
// The import and the client's pointer are one store: a write through either is the other's.
|
||||
static_cast<Uint8*>(adopted)[100] = 0xA5;
|
||||
if (static_cast<const Uint8*>(static_cast<FakeAhb*>(g_fakeImports.held)->map)[100] != 0xA5) ::_exit(175);
|
||||
if (ClientSessionInstance().T0StoresImported() != 1 || ClientSessionInstance().T0BytesImported() != kT0Bytes)
|
||||
::_exit(176);
|
||||
if (Srv::ServerSessionInstance().T0StoresImported() != 1) ::_exit(177);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
EXPECT_NE(child.Log.find("T0 granted"), std::string::npos) << child.Log;
|
||||
EXPECT_NE(child.Log.find("T0 imported store {slot=5, gen=1} - 65536 bytes"), std::string::npos) << child.Log;
|
||||
EXPECT_NE(child.Log.find("T0 store {slot=5, gen=1} adopted - 65536 bytes"), std::string::npos) << child.Log;
|
||||
EXPECT_EQ(child.Log.find("Fatal{"), std::string::npos) << child.Log;
|
||||
}
|
||||
|
||||
// ORDER: the Offer arrives 300 ms AFTER its record was published and decoded - the apply thread
|
||||
// waits for it (bounded) and the store still lands with the client's bytes.
|
||||
TEST(RemoteClientAdoptT0, AnOfferThatArrivesAfterItsRecordStillLands) {
|
||||
const auto child = RunInChild([] {
|
||||
ClientSession::SetT0OfferFaultForTest(300);
|
||||
std::vector<Uint8> seed;
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
void* adopted = AdoptOneStore(0x33, seed);
|
||||
const auto waited = std::chrono::steady_clock::now() - start;
|
||||
if (adopted == nullptr) ::_exit(180);
|
||||
if (g_fakeImports.bytes != seed) ::_exit(181);
|
||||
if (waited < std::chrono::milliseconds(300)) ::_exit(182); // it really waited for the late Offer
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
EXPECT_EQ(child.Log.find("AdoptT0NoStore"), std::string::npos) << child.Log;
|
||||
}
|
||||
|
||||
// A LOST Offer is a NAMED DECLINE within the bounded wait - never a hang: the store runs T2.
|
||||
TEST(RemoteClientAdoptT0, AnOfferThatNeverArrivesIsANamedDeclineNotAHang) {
|
||||
const auto child = RunInChild([] {
|
||||
ClientSession::SetT0OfferFaultForTest(-1);
|
||||
std::vector<Uint8> seed;
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
void* adopted = AdoptOneStore(0x44, seed);
|
||||
const auto waited = std::chrono::steady_clock::now() - start;
|
||||
if (adopted != nullptr) ::_exit(190);
|
||||
if (g_fakeImports.count != 0) ::_exit(191);
|
||||
if (waited > std::chrono::milliseconds(T0::kOfferWaitMs + 3000)) ::_exit(192);
|
||||
if (ClientSessionInstance().T0Declined() != 1) ::_exit(193);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
EXPECT_EQ(CountOf(child.Log, "Refuse{AdoptT0NoStore, \"record"), 1u) << child.Log;
|
||||
EXPECT_EQ(child.Log.find("Fatal{"), std::string::npos) << child.Log;
|
||||
}
|
||||
#endif
|
||||
@@ -324,54 +324,9 @@ TEST(RemoteClientControls, MapPersistentErrorIsNotADecline) {
|
||||
ExpectNamedAbort(child, "Fatal{ReplyError, \"map_persistent\"}");
|
||||
}
|
||||
|
||||
// P11 A1 (CONTRACT-P11 §1): MOBILEGL_IPC_ADOPT_TIER=0/1 OVER SHARED SEGMENTS DIES AT THE
|
||||
// HANDSHAKE, before any record. inproc is shared segments by construction, and this is the real
|
||||
// Start (the same StartOverTransportPair the lanes run). The child writes 'S' once Start returns
|
||||
// and 'M' once its map_persistent went out, so "died before the first map_persistent" is a fact
|
||||
// the parent reads rather than infers from the log. The stream half is AdoptTierStreamTest.
|
||||
//
|
||||
// RED-ONCE: move the check back to use (drop the client's SessionFail in
|
||||
// Transport::SettleAdoptTierAtHandshake and make Client::AdoptTierIsEmulate abort on 0/1 again)
|
||||
// -> the session comes up ('S'), the map_persistent goes out, and the child dies only when the
|
||||
// server's codec asks the tier.
|
||||
namespace {
|
||||
void ExpectDeathAtTheSharedSegmentHandshake(Uint32 tier) {
|
||||
int marks[2] = {-1, -1};
|
||||
ASSERT_EQ(::pipe(marks), 0);
|
||||
const auto child = RunInChild([&marks, tier] {
|
||||
::close(marks[0]);
|
||||
MG_Config::Ipc.AdoptTier = tier;
|
||||
StartControlSession();
|
||||
const char started = 'S';
|
||||
(void)!::write(marks[1], &started, 1);
|
||||
MGPHandleOnly handle{};
|
||||
handle.Kind = static_cast<Uint32>(MGPipeKind::Buffer);
|
||||
(void)MGPipeRouteMapPersistent(handle, 64, nullptr);
|
||||
const char sent = 'M';
|
||||
(void)!::write(marks[1], &sent, 1);
|
||||
});
|
||||
::close(marks[1]);
|
||||
std::string seen;
|
||||
char c = 0;
|
||||
while (::read(marks[0], &c, 1) == 1) seen.push_back(c);
|
||||
::close(marks[0]);
|
||||
const std::string word = "Fatal{UnimplementedAdoptTier, \"T" + std::to_string(tier) + "\"}";
|
||||
ExpectNamedAbort(child, word.c_str());
|
||||
EXPECT_EQ(seen, "") << "'S' = the session came up, 'M' = a map_persistent went out, both before "
|
||||
"the death; T" << tier << " over shared segments must die at the handshake\n"
|
||||
<< child.Log;
|
||||
EXPECT_NE(child.Log.find("refused at the handshake over shared segments"), std::string::npos)
|
||||
<< child.Log;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(RemoteClientControls, AdoptTierZeroOverSharedSegmentsDiesAtTheHandshakeBeforeAnyMapPersistent) {
|
||||
ExpectDeathAtTheSharedSegmentHandshake(0u);
|
||||
}
|
||||
|
||||
TEST(RemoteClientControls, AdoptTierOneOverSharedSegmentsDiesAtTheHandshakeBeforeAnyMapPersistent) {
|
||||
ExpectDeathAtTheSharedSegmentHandshake(1u);
|
||||
}
|
||||
// P11 A1's two handshake-Fatal cases (AdoptTier{Zero,One}OverSharedSegmentsDiesAtTheHandshake...)
|
||||
// are rewritten for B2's fallback semantics in RemoteClientAdoptT0.inc (ID-P11-14: a T0 this
|
||||
// session cannot use is T2 plus one named line, never a Fatal).
|
||||
|
||||
TEST(RemoteClientControls, AnIdenticalRepeatedMakeCurrentRepublishesNothing) {
|
||||
const auto child = RunInChild([] {
|
||||
|
||||
@@ -1721,6 +1721,7 @@ TEST(RemoteReadback, AReplyIsScatteredOnlyWhenItIsOkAndExactlyTheReadsExtent) {
|
||||
}
|
||||
|
||||
#include "RemoteClientControls.inc"
|
||||
#include "RemoteClientAdoptT0.inc"
|
||||
#include <MG_Impl/Pipe/FramebufferEmit.h>
|
||||
#include <MG_Impl/Pipe/TextureEmit.h>
|
||||
#include <MG_State/GLState/TextureState/TextureObject2D.h>
|
||||
|
||||
@@ -261,6 +261,68 @@ TEST(SessionHandshakeTest, WireLayoutMismatchReturnsNamedRefuseWithoutAborting)
|
||||
CheckHandshake(MOBILEGL_PROTOCOL_ABI_MAJOR, WireFingerprint() ^ 1, BuildFingerprint(),
|
||||
::MobileGL::Wire::DialMode::No, ::MobileGL::Wire::RefuseCode::WireFingerprint);
|
||||
}
|
||||
// P11 B2 (CONTRACT-P11 B2): CONTROL REVISION 5. A peer built at revision 4 - before
|
||||
// LinkTerms.adoptTier - carries the fingerprint its revision mixed, and is refused by name
|
||||
// (Refuse{WireFingerprint}), never read as a revision-5 Hello that happens to ask T2. The same shape
|
||||
// PAIR's 3 -> 4 had. RED ONCE by leaving MOBILEGL_PROTOCOL_CONTROL_REVISION at 4 with the schema
|
||||
// change: the two fingerprints are then equal and the Welcome goes out.
|
||||
TEST(SessionHandshakeTest, ARevisionFourPeerIsRefusedByNameAtRevisionFive) {
|
||||
static_assert(MOBILEGL_PROTOCOL_CONTROL_REVISION == 5, "B2 bumped the control revision 4 -> 5");
|
||||
auto inputs = CapsAbiFingerprintInputs();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
inputs.ControlSchemaRevision = (static_cast<Uint64>(4) << 32) | MG_Pipe::kMGPipeResourceRespecifyExtentCarrierRevision;
|
||||
#else
|
||||
inputs.ControlSchemaRevision = 4;
|
||||
#endif
|
||||
const Uint64 revisionFour = Transport::MixAbiFingerprint(inputs);
|
||||
ASSERT_NE(revisionFour, WireFingerprint());
|
||||
CheckHandshake(MOBILEGL_PROTOCOL_ABI_MAJOR, revisionFour, BuildFingerprint(), ::MobileGL::Wire::DialMode::Connect,
|
||||
::MobileGL::Wire::RefuseCode::WireFingerprint);
|
||||
}
|
||||
|
||||
// P11 B2: the Hello's adoptTier is an ASK of 2 or (shared segments) 0 - T1 is closed and never sent,
|
||||
// and anything else is not an ask this revision knows. Refuse{LinkTerms} by name; the echo of a
|
||||
// legal ask is the Welcome's.
|
||||
TEST(SessionHandshakeTest, AHelloAskingAnAdoptTierThatIsNotAnAskIsRefusedByName) {
|
||||
using namespace ::MobileGL::Wire;
|
||||
// 0x80 is the T0 ask of an unset knob (T0 by default, refusals quiet); 0x81 is not an ask.
|
||||
for (const Uint8 ask : {Uint8{0}, Uint8{1}, Uint8{2}, Uint8{7}, Uint8{0x80}, Uint8{0x81}}) {
|
||||
SCOPED_TRACE(static_cast<int>(ask));
|
||||
std::unique_ptr<Transport::InProcessTransport> client, server;
|
||||
Transport::InProcessTransport::CreatePair(client, server);
|
||||
::flatbuffers::FlatBufferBuilder builder(512);
|
||||
auto terms = CreateLinkTerms(builder, DataPlane::SharedSegments, WireForm::StructImage, 0, 0, 0, 0, ask);
|
||||
auto hello = CreateHelloDirect(builder, MOBILEGL_PROTOCOL_ABI_MAJOR, MOBILEGL_PROTOCOL_ABI_MINOR,
|
||||
BuildFingerprint(), 0, 1, nullptr, WireFingerprint(), WireFingerprint(),
|
||||
terms, nullptr, DialMode::No);
|
||||
auto root = CreateCtrlEnvelope(builder, CtrlMsg::Hello, hello.Union());
|
||||
FinishCtrlEnvelopeBuffer(builder, root);
|
||||
std::vector<Uint8> first(builder.GetBufferPointer(), builder.GetBufferPointer() + builder.GetSize());
|
||||
Server::ServerSession session;
|
||||
Transport::SessionSegmentSizes sizes;
|
||||
sizes.CmdRingBytes = 4096; sizes.StageBytes = 4096;
|
||||
sizes.ReplyBytes = 4096; sizes.EventRingBytes = 4096;
|
||||
session.SetSegmentSizes(sizes);
|
||||
const Bool legal = ask == 0 || ask == 2 || ask == 0x80;
|
||||
EXPECT_EQ(session.Accept(*server, &first), legal ? MOBILEGL_OK : MOBILEGL_ERR_PROTOCOL_MISMATCH);
|
||||
const auto reply = ReadHandshakeFrame(*client);
|
||||
ASSERT_FALSE(reply.empty());
|
||||
const auto* envelope = GetCtrlEnvelope(reply.data());
|
||||
if (legal) {
|
||||
ASSERT_NE(envelope->msg_as_Welcome(), nullptr);
|
||||
ASSERT_NE(envelope->msg_as_Welcome()->linkTerms(), nullptr);
|
||||
EXPECT_EQ(envelope->msg_as_Welcome()->linkTerms()->adoptTier(), ask) << "the Welcome echoes the ask";
|
||||
EXPECT_EQ(session.AdoptT0Asked(), ask == 0 || ask == 0x80);
|
||||
EXPECT_EQ(session.AdoptT0Quiet(), ask == 0x80) << "only the default ask is quiet";
|
||||
EXPECT_FALSE(session.AdoptT0()) << "no grant before the first native bind";
|
||||
} else {
|
||||
ASSERT_NE(envelope->msg_as_Refuse(), nullptr);
|
||||
EXPECT_EQ(envelope->msg_as_Refuse()->code(), RefuseCode::LinkTerms);
|
||||
}
|
||||
session.Close();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(SessionHandshakeTest, ConnectAcceptsDifferentBuildWithIdenticalWire) {
|
||||
ScopedHandshakeEnvironment required("MOBILEGL_IPC_REQUIRE_SAME_BUILD", "0");
|
||||
CheckHandshake(MOBILEGL_PROTOCOL_ABI_MAJOR, WireFingerprint(), "different-commit",
|
||||
|
||||
@@ -22,6 +22,17 @@ def mobileGlAbiFilters = {
|
||||
def mobileGlBuildServerSpike = {
|
||||
(rootProject.findProperty('mobilegl.buildServerSpike') ?: System.getenv('MOBILEGL_BUILD_SERVER_SPIKE') ?: 'OFF') as String
|
||||
}
|
||||
// P11 A3 opt-in, same rules as the spike above: -Pmobilegl.buildExtmemProbe=ON packages
|
||||
// tools/spikes/extmem_probe as libMobileGLExtmemProbe.so into the trace flavour only.
|
||||
def mobileGlBuildExtmemProbe = {
|
||||
(rootProject.findProperty('mobilegl.buildExtmemProbe') ?: System.getenv('MOBILEGL_BUILD_EXTMEM_PROBE') ?: 'OFF') as String
|
||||
}
|
||||
// P11 B2 step 1, spike only: -Pmobilegl.extmemProbeAsServer=ON also packages the probe AS
|
||||
// libMobileGLServer.so (the real server becomes libMobileGLServerReal.so), so the render server's
|
||||
// service and B1's broker run the AHB route probe in the server's place. Never for a real APK.
|
||||
def mobileGlExtmemProbeAsServer = {
|
||||
(rootProject.findProperty('mobilegl.extmemProbeAsServer') ?: 'OFF') as String
|
||||
}
|
||||
|
||||
// Shared native shape for BOTH plugin and trace APKs. The render server (libMobileGLServer.so and
|
||||
// the display server's JNI) is part of the split shape, and both flavors of a standalone plugin
|
||||
@@ -111,6 +122,8 @@ android {
|
||||
// grow a binary nothing loads. See mobileGlBuildServerSpike
|
||||
// above for the two ways to enable it.
|
||||
arguments "-DMOBILEGL_BUILD_SERVER_SPIKE=${mobileGlBuildServerSpike()}"
|
||||
arguments "-DMOBILEGL_BUILD_EXTMEM_PROBE=${mobileGlBuildExtmemProbe()}"
|
||||
arguments "-DMOBILEGL_EXTMEM_PROBE_AS_SERVER=${mobileGlExtmemProbeAsServer()}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,27 @@
|
||||
# 当前阶段:P11 进行中(2026-09-29)
|
||||
# 当前阶段:P8 进行中(2026-09-29 起)
|
||||
|
||||
> **更新 2026-09-29**。这一页只有摘要;计划、裁定与测量在 [`notes/p11/README.md`](notes/p11/README.md)(计划 [`PLAN-P11.md`](notes/p11/PLAN-P11.md)、裁定 [`INTEGRATOR-DECISIONS-P11.md`](notes/p11/INTEGRATOR-DECISIONS-P11.md))。上一阶段 P10 同日收官,见 [`notes/p10/README.md`](notes/p10/README.md)。
|
||||
> **更新 2026-09-29**。这一页只有摘要;计划与裁定在 [`notes/p8/PLAN-P8.md`](notes/p8/PLAN-P8.md)、[`notes/p8/INTEGRATOR-DECISIONS-P8.md`](notes/p8/INTEGRATOR-DECISIONS-P8.md)。上一阶段 P11 同日收官,见 [`notes/p11/README.md`](notes/p11/README.md)。
|
||||
|
||||
## 目标
|
||||
|
||||
大 buffer(≥ 16 MiB)的 persistent map 在 split 下诚实地落在它声明的档位上;同一台设备上从其他 app 启动的 GL 程序(Termux 一类)能走共享内存,并能导入 client 分配的 AHardwareBuffer(T0)。
|
||||
补齐 server 侧仿真缺口(Espryt 生成 mip、Espryt 暂存影子与 GPU 写、Magma wire indirect、CopyImage),并把 monolith 用例登记到 split 各臂;为 P13 删掉旧的「后端直接读前端」路径扫清前置。原范围已重定界(划掉保留在 [`notes/p8/README.md`](notes/p8/README.md))。
|
||||
|
||||
## 完成情况
|
||||
|
||||
| 项 | 状态 |
|
||||
|---|---|
|
||||
| 范围重划 | ✅ `gPipeInputs` 版本化与 T1 关闭;采纳基线三个数撤下,改为同会话重测(ID-P11-1) |
|
||||
| 合并 dev(重铸读回、局部上传、Magma 排序、Magma `eglSwapInterval`) | ✅ 两后端 × 单进程 / Split / Spawn / Tcp;push 单进程臂上的一个丢写已修;G1 换基线(ID-P11-6) |
|
||||
| A1 档位在握手时定 | ✅ Stream 上一行具名拒绝后 T2;共享段上 client 握手期具名 Fatal;无线上格式改动 |
|
||||
| A2 断言 arena 落在哪一档、三臂登记 | ✅ 两后端 |
|
||||
| A3 T0 在 app 域 | ✅ 两后端 GO(含 128 MiB 与持续锁定) |
|
||||
| A4 采纳基线(Adreno 830) | ✅ 采纳省 RSS 360–480 MB、不改帧时;split T2 在 MC 26.3 上 RSS 1.4–2×、p99 Espryt +37–42% / Magma 约 2.5×(`notes/p11/A-DEVICE.md`) |
|
||||
| B0 跨 app client 探针 | ✅ SELinux 挡连接,连上后共享段可用(`notes/p11/B0-CROSS-APP.md`) |
|
||||
| PAIR 连接按 nonce 配对 | ✅ 控制协议修订 3 → 4 |
|
||||
| helper 可行性探针 | ✅ 无 Context 的 `app_process` helper 经 Binder 拿到连接(依赖 ROM,`HSPIKE.md`) |
|
||||
| 合并 dev(M2) | ✅ KGSL 分段提交、零散写入按矩形(补齐 split 半边)、描述符池 |
|
||||
| B1 同机外部 client 走共享内存 | ✅ `fd:` 端点 + 令牌 broker + helper + 启动命令 + 外部 client 的 apply 线程策略;rd12 Espryt 约 119 vs tcp 40–53 fps |
|
||||
| B2 T0 零拷贝导入(可开关,`ADOPT_TIER` 0;默认 2 = 共享内存推送) | 下一步 |
|
||||
| 主机门(集成头) | ✅ 全绿,数字见 ID-P11-16(B1)与 ID-P11-15(M2) |
|
||||
| 只读核查与重定界 | ✅ 原 10 项里 6 项已完成、直接关闭(ID-P8-1) |
|
||||
| P8-0 普查(设备 + 主机) | 进行中 |
|
||||
| A 覆盖对齐 | 进行中 |
|
||||
| B Espryt 生成 mip | 进行中 |
|
||||
| C Espryt 暂存影子与 GPU 写 | 进行中 |
|
||||
| D Magma wire 原生 indirect | 进行中 |
|
||||
| E CopyImage 在 server store 上 | 进行中 |
|
||||
| F 死闩清理与重分类 | 进行中 |
|
||||
| G 大 blob 分片 | 等 P8-0 的测量 |
|
||||
|
||||
## 下一步
|
||||
|
||||
B2:T0 导入(两后端,经 B1 的通道;第一项真机检查是 AHardwareBuffer 的 dma-buf fd 跨 app 传递),保留开关。本阶段转出的两个 dev 缺陷(Espryt 零散写入、Magma rd12 映射耗尽)已在 dev 修好并经 M2 合入;其余转出项见 [`notes/DEBTS.md`](notes/DEBTS.md)。
|
||||
第一波七包并行(ID-P8-4);逐包集成进 `p8/main` 并跑整套门。
|
||||
|
||||
**阻塞**:没有需要决策的事项。
|
||||
**待用户决策**:[`DEBTS.md`](notes/DEBTS.md) 六项「需裁定」(CI 触发条件、`TCP_USER_TIMEOUT`、HyperOS 下 FCL 保活、Mali 复测、TLS、`IDLE_EXIT_S`)。
|
||||
|
||||
@@ -49,3 +49,4 @@
|
||||
| 15 | P7 | 真机画面 36/36;server 内存无界增长收住(主机 825 → 546 MiB) | [`notes/p7`](notes/p7/README.md) |
|
||||
| 16 | P12 | 审查后真机复测:Espryt SSIM 1.0;Magma 1.0 / 0.999999511;P12 定向 CTest 46/46;纹理上传回包等待 1→0(主机机制门,真机墙钟待测);**P12 已收官(09-29)**:跨机 TCP 门 (b) 通过(rd12 ssim 0.999883、稳态 17–22 fps);FCL 门 (a) 通过(Minecraft 上屏到 render server 窗口,杀 server 后 33–54 ms 闩住 device-lost) | [`notes/p12`](notes/p12/README.md) |
|
||||
| 17 | 五臂传输测量(2026-09-28,非阶段) | inproc/shm 重负载比 monolith 快 ~1/3;tcp localhost 瓶颈是 credit=1 + 唤醒税(SPIN_US=2000 → 2.9×);跨主机 hang 实为主机 xray TUN 代理造成;直连 Wi-Fi 稳态 rd12 17–22 fps、openra 105–133 fps | [`notes/perf-five-arm-20260928`](notes/perf-five-arm-20260928/README.md) |
|
||||
| 18 | P11 | 同机零拷贝(T0)MC 26.3 峰值内存 Espryt −41–42%、Magma −18–26%,ssim / 帧时 / CPU 不变;外部 client 走共享内存 rd12 Espryt 约 119 fps(TCP 40–53);split T2 相对单进程采纳 p99 Espryt +37–42%、Magma 约 2.5×。未量:M2 后 split server 上纹理无 GPU 写时 Espryt 自己按存储阈值取舍精确写入框,非 ring 路径可能多发几个小框 | [`notes/p11`](notes/p11/README.md) |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# 路线图(索引)
|
||||
|
||||
> **2026-09-29**:P0 到 P7、P12、P9、**P10** 已完成(P10:fence 轮询不再往返——server 报告完成的 fence、client 本地作答,真机两后端 0 次往返;最后一个 class-C 清零;credit 1/2/3 在设备 loopback 上量过、默认保持 1;契约 `MG_Remote/CONTRACT-P10.md`,G1 成立);下一阶段 **P11**(IPC 跑道)与 **P8**(monolith 跑道)。每个阶段的计划、验收结果、实测与报告在 `notes/<阶段>/`(点阶段名进入)。
|
||||
> **2026-09-29**:P0 到 P7、P12、P9、P10、**P11** 已完成——拆分路线走完。P11:同机大缓冲零拷贝(T0,默认开、用不了静默退回共享内存;MC 26.3 峰值内存 Espryt −41 %、Magma −18–26 %),同机其他 app 启动的 GL 程序(Termux 类)经 `app_process` helper 与令牌 broker 走共享内存,连接按 nonce 配对;契约 `MG_Remote/CONTRACT-P11.md`,G1 仅 Magma 空 uniform 修复 +224 字节 `.text`。当前阶段 **P8**(09-29 起,重定界:~~仿真路径下放与协议广度~~ → 补齐 server 侧仿真缺口与 split 覆盖,[`PLAN-P8.md`](notes/p8/PLAN-P8.md)),之后 P13。每个阶段的计划、验收结果、实测与报告在 `notes/<阶段>/`(点阶段名进入)。
|
||||
|
||||
## 目标
|
||||
|
||||
@@ -9,7 +9,7 @@ client(跑应用的一方)与 server(跑驱动的一方)可以在**不
|
||||
## 两条路线
|
||||
|
||||
- **单进程路线**:先把接口建起来,让单进程版本也受益(后端拥有自己的状态、可以挪到渲染线程)。P0 → P0.5 → P1 → P2 → P3a → P4a → P3b/P4b → P7 → P8 → P13。
|
||||
- **拆分路线**:在接口之上逐步拆开前后端。P5 → P5b → P5c → P5d → P5e → P5f → P6 → P6.5 → Ph → P12 → P9 → **P10** → P11。
|
||||
- **拆分路线**:在接口之上逐步拆开前后端。P5 → P5b → P5c → P5d → P5e → P5f → P6 → P6.5 → Ph → P12 → P9 → P10 → **P11**(走完)。
|
||||
|
||||
## 阶段一览
|
||||
|
||||
@@ -33,10 +33,10 @@ client(跑应用的一方)与 server(跑驱动的一方)可以在**不
|
||||
| [P3b / P4b](notes/p34b/README.md) | GLES 后端的深化与收尾 | 大部分 ✅,余项并行 |
|
||||
| [P7](notes/p7/README.md) | Vulkan 后端完整迁移;真机画面检查 36/36 通过 | ✅ 09-23 |
|
||||
| [**P12**](notes/p12/README.md) | **server 自己开窗口上屏,client 不需要窗口** | ✅ 09-29:出口门 B(跨机 TCP)✅ 09-28、A(FCL + 杀 server)✅ 09-29;契约 `MG_Remote/CONTRACT-P12.md`;G1 成立;余项进 [`DEBTS.md`](notes/DEBTS.md) |
|
||||
| [P8](notes/p8/README.md) | 把剩余的仿真路径挪到正确的一侧,补齐协议 | 待排 |
|
||||
| [**P8**](notes/p8/README.md) | ~~把剩余的仿真路径挪到正确的一侧,补齐协议~~ → **补齐 server 侧仿真缺口与 split 覆盖**:Espryt 生成 mip(RGB16F / RGB32F、存储窗口)、Espryt 暂存影子与 GPU 写对账、Magma wire 原生 indirect、CopyImage 在 server store 上处理、monolith 用例登记到 split 各臂;原范围 6 项前序阶段已完成([`PLAN-P8.md`](notes/p8/PLAN-P8.md)) | 进行中(09-29 起) |
|
||||
| [**P9**](notes/p9/README.md) | **反向通道:回读、日志、重铸不再同步等待 client** | ✅ 09-29:PACK-PBO 回读 fire-and-forget(两后端)、日志分级转发、重铸无拉取(`OnLog` / `OnTexturePullRequest` 删,回调 9 → 7),F1 / F2;契约 `MG_Remote/CONTRACT-P9.md`;G1 成立;事件量批处理无实测需求不做;余项进 [`DEBTS.md`](notes/DEBTS.md) |
|
||||
| [**P10**](notes/p10/README.md) | **同步对象、查询与帧节奏** | ✅ 09-29:fence 轮询由 server 报告本地作答(`kEventFenceSignaled`、`MOBILEGL_IPC_POLL_ESCALATE`;主机 Magma·tcp −37%,Adreno 830 上两后端 0 次往返);`SetSwapInterval` 转发、class C 清零;query / XFB / AsyncCompile 登记 split 各臂;credit 1/2/3 设备 loopback 在噪声内;契约 `MG_Remote/CONTRACT-P10.md`;G1 成立;余项进 [`DEBTS.md`](notes/DEBTS.md) |
|
||||
| [**P11**](notes/p11/README.md) | **同机大缓冲零拷贝共享** | 进行中(09-29):已合并 dev;采纳档位在握手时定;连接按 nonce 配对(修订 4);同机外部 client(Termux 类)经 helper 与令牌 broker 走共享内存(B1);下一步 T0 零拷贝(可开关) |
|
||||
| [**P11**](notes/p11/README.md) | **同机大缓冲零拷贝共享** | ✅ 09-29:T0 零拷贝导入(两后端,默认开,自测不过或 Stream 上静默退回 T2);同机外部 client 经 helper + 令牌 broker 走共享内存(B1);连接按 `PairBind` nonce 配对(修订 5);采纳档位在握手时定;契约 `MG_Remote/CONTRACT-P11.md`;余项进 [`DEBTS.md`](notes/DEBTS.md) |
|
||||
| [P13](notes/p13/README.md) | 删掉旧的"后端直接读前端"路径 | 待排 |
|
||||
|
||||
## 另见
|
||||
|
||||
@@ -58,7 +58,8 @@ CMake:`MOBILEGL_BUILD_DISAGGREGATED`(OFF)、`MOBILEGL_BUILD_DISAGGREGATED_
|
||||
| `MOBILEGL_IPC_EVENT_WAIT_MS` | 2000 | 反向事件遇满环时 server 等 client 排空的整笔预算(§11.7) |
|
||||
| `MOBILEGL_IPC_WIRE_DEFERRED_MB` | 64 | Magma wire 臂延迟回收的水位线;`0` 是 M2 阴性对照 |
|
||||
| `MOBILEGL_IPC_PERSISTENT_BLOCK_KB` / `_PERSISTENT_HASH_SUPPRESS` | 64 / 1 | persistent-map 推送粒度 / 只推变化的块;`0` 是对照 |
|
||||
| `MOBILEGL_IPC_ADOPT_TIER` | 2 | `auto/0/1/2`;T0 / T1 今天是 Fatal-at-use |
|
||||
| `MOBILEGL_IPC_ADOPT_TIER` | 未设 = T0 | 未设(用户 2026-09-29 定为缺省)= 能用就 T0,不能用(stream、无 AHB、POST 失败、server 不允许)安静回退 T2:只 MGLOG_D、照样计数;`0` = 点名要 T0,回退有具名行(A1 的 `Refuse{AdoptTierOnStream}` 等);`1` = T1 已关,具名拒绝后 T2;`2` = T2(P11 前的缺省)。`CONTRACT-P11.md` B2 |
|
||||
| `MOBILEGL_IPC_ALLOW_ADOPT_T0` | 1 | server 自有:`0` = 永不批准 T0(会话走 T2),经 `ServerSpawn` 保留 |
|
||||
| `MOBILEGL_IPC_STRICT_ERRORS` / `MOBILEGL_IPC_AUDIT` / `MOBILEGL_IPC_ROLE_SPLIT_STATE` | 0 / 0 / 0 | 残余输入读升级为 Fatal / 退休 staging 填 `0xDD` / 双块演练(P5f) |
|
||||
| `MOBILEGL_IPC_SPIN_US` / `MOBILEGL_IPC_SERVER_AFFINITY` | 50 / `auto` | park 前自旋预算 / apply 线程亲和(Redmi 内核忽略) |
|
||||
| `MOBILEGL_IPC_RESPAWN` | — | 具名拒绝:没有阶段实现 server 重启后的全量重推 |
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
# 仍开放的债务(跨阶段)
|
||||
|
||||
> 路线图只列"有债务、看这里"。每条写明去向;已关闭的历史债与当时的完整债务表见 [`p5b/README.md`](p5b/README.md) 末节。开放问题另见 [`OPEN-QUESTIONS.md`](OPEN-QUESTIONS.md)。更新:2026-09-29(P10 收官;P11 进行中)。
|
||||
> 路线图只列"有债务、看这里"。每条写明去向;已关闭的历史债与当时的完整债务表见 [`p5b/README.md`](p5b/README.md) 末节。开放问题另见 [`OPEN-QUESTIONS.md`](OPEN-QUESTIONS.md)。更新:2026-09-29(P11 收官;按债务审查重排)。去向「需裁定」= 等用户定;「可进行」= 随时可开的小修,不依赖别的阶段。
|
||||
|
||||
| 债务 | 去向 |
|
||||
|---|---|
|
||||
| CI 覆盖:`test.yml` / `apk.yml` 按分支名(`feat/disaggregated`、`codex/fix-github-ci`)切 `MOBILEGL_CI_DISAGGREGATED` 与车道(本次核对 `test.yml` 14 处、`apk.yml` 4 处);pull 构建只有 G1 与 monolith 对照,没有集成测试门(`TextureRemintPullScenario` 在 pull 上自 P9 红到 P11 M 才修);合入 `dev` 后 inproc 验收与 APK split 两臂随分支名关掉,build-linux-split / integration-split / retrace-split 无条件 | 需裁定:合入前是否加 pull 集成车道;合入 `dev` 后各车道的触发条件(顺带删 `feat/disaggregated` 触发器) |
|
||||
| P9 转出:`TCP_USER_TIMEOUT` = 5000 ms——client 停读控制超过 5 s 且有待发日志字节时内核断开连接;`PublishSessionFault` 的阻塞写对停读的 client 最多等同样 5 s(ID-P9-10)。风险场景:FCL 退后台暂停 + 跨机 TCP | 需裁定:建议调到几十秒、`PublishSessionFault` 改有界写;取值由用户定 |
|
||||
| P11 转出(B0 F1):HyperOS 熄屏冻结 server app 整个 uid。B1 已靠用户设置解决(server app 与 client 所在 app 电池都设「无限制」,ID-P11-16);剩 FCL 同机用法的保活 | 需裁定:只写须知 / app 内检测省电策略并引导 / 不管 |
|
||||
| P11 转出(B2):T0 只在红米一台 Adreno 上实测;Mali 等只有 spike B 的 shell 域证据(server 自测会在不支持的设备上退回 T2)。「respecify 时立即释放导入」的变异在 Espryt 上不红(驱动大概自己持有引用,未核实),带 fence 的释放保留 | 需裁定(受设备规矩所限):开一台 Mali 复测,或长期接受自测退回 |
|
||||
| P11 转出(B1):外部 client 的 apply 线程策略只在红米一台(两大核)上量过;Magma openra 两个数据面都卡在 server(约 285 fps),共享内存无收益 | 同上一行 |
|
||||
| P12 未做:TLS(开放问题 21 当时「令牌够,TLS 留作 P12 开放项」;P12 已收官) | 需裁定:正式放弃,或继续留作开放项 |
|
||||
| `MOBILEGL_IPC_IDLE_EXIT_S` 未解析(client EOF 时 server 已即时退出) | 需裁定:建议废弃;点头后删 `design/09-build-switches-counters.md:67` 与 `Config.h` 注释等处 |
|
||||
| P10 转出:`GL_ARB_gpu_shader_fp64` 按 server 的 `MOBILEGL_ADVERTISE_FP64` 宣告,fp64 收窄却在 client 的编译里;tcp 下 server 环境不同时两者不一致(同类的 `GL_KHR_parallel_shader_compile` 已修,做法见 `CapsMirror.cpp:72-101`,ID-P10-10) | 可进行(小修) |
|
||||
| P11 转出:client 与 server 共用日志前缀时,client 以 `"w"` 打开 `<base>.server.log` 写转发来的 server 日志(`MobileGL/MG_Util/Debug/Log.cpp:89`),截断 server 自己的文件;同机两个进程用同一前缀时同样互相截断 | 可进行(小修) |
|
||||
| P11 转出(B1):会话位被慢启动程序占着时,第二个 client 若 2 s 内发 Hello 得具名 `Refuse{Busy}`,更慢的只见发送失败(那条路径不读待发的拒绝);已写进契约 | 可进行(小修) |
|
||||
| P11 转出(B1):会话启动失败后 client 还多报一个误导性的 `Fatal{CapsBeforeFirstSnapshot}`(`CapsMirror.cpp:247`,早于 B1,helper 用户每次被拒都会看到) | 可进行(小修) |
|
||||
| P11 转出(B2):handle 臂的 CPU 读者(indirect、primitive restart、multi-draw rebase → `SplitHostBytes`)读采纳 / T0 映射前不先落完排队的常驻写;单进程大概也要同一条「读前先落」规则 | 可进行(小修;单进程那半 P8 开工时一并看) |
|
||||
| P11 转出(B2):server 准了 T0 而 client 选了 T2 时,每个存储的 `map_persistent` 等 2 s 再具名拒绝(产品里 grant 与 caps 一致,只在变异下见过) | 可进行(小修:每会话一个「client 不要 T0」提示) |
|
||||
| P9 转出:Espryt 重铸保留路径上 framebuffer clear 后 `imageLoad` 偶读旧值(主机 3/30,加 barrier 后 0/30;`TextureRemintPullScenario` case C 暂钉 barrier),疑 llvmpipe(ID-P9-11);P11 合并 dev 后 push 单进程臂上也见过一次,`ImageBindableRemintScenario` 同样钉 barrier(ID-P11-6) | 可进行(在红米上不加 barrier 归因) |
|
||||
| P12 未做:D8 窗口种类白名单——X11 / MetalLayer / Win32Hwnd / None 仍被接受(`SurfaceOpCodec.cpp:138-141`),`HandleFromToken` 把 token 强转为指针(`ServerLoop.cpp:1228`,经 `UnpackWindowHandle`;下游是否交给 EGL 未追到底) | 可进行(Ph 类小修) |
|
||||
| P12 未做:修后的横屏 server 窗口未重测 | 可进行(红米只读检查) |
|
||||
| P11 转出(M2,给 dev):dev 的 `DirectVulkan.SplitRecording.` 车道没有 `RESOURCE_LOCK`(dev 上 `MG_IntegrationTest/CMakeLists.txt` 第 609 行)、其用例读字面日志路径——`-j` 下可能互相截断;P11 线的副本已修。另:dev 的 `853c5f12` / `7030d307` 与 B2 的 `7784d6bb` 修同一处 | 下次向 dev 回流时带上;那两处取一份 |
|
||||
| 未接入内容分块的 record 类型:program archive 与 `draw_vbo` range 尾 | P6.5 sl 与 P8 共用的分片(开放问题 11) |
|
||||
| 仿真路径的具名拒绝:multi-draw client indices、RGB CPU mip 等(class C 已于 P10 清零) | P8 |
|
||||
| P10 转出:`GL_ARB_gpu_shader_fp64` 按 server 的 `MOBILEGL_ADVERTISE_FP64` 宣告,fp64 收窄却在 client 的编译里;tcp 下 server 环境不同时两者不一致(与已修的 `GL_KHR_parallel_shader_compile` 同类,挂点 `CapsMirror::Adopt`,ID-P10-10) | 小修,无触发报告 |
|
||||
| P10 转出(性能):设备上 tcp loopback 的 rd12 每帧 19.4 ms 中 ~11.2 ms 是生产者在 stream 传输里的停车(发送 + 环 / stage / ack 等待),credit 等待只有 ~0.2 ms(`notes/p10/C-MEASUREMENTS.md` §2,ID-P10-13) | 路线图推完后的性能工作 |
|
||||
| P11 转出(性能):设备上 MC 26.3,split T2 相对单进程采纳的 p99 Espryt +37–42%、Magma 约 2.5×,RSS 1.4–2×;其中一部分是线程落位——server apply 线程钉在 6–7 核,client GL 线程多半落到慢核,每帧 CPU 约 2.3×(`notes/p11/A-DEVICE.md`) | 路线图推完后的性能工作;RSS 由 B(T0)处理 |
|
||||
| P11 转出:client 与 server 共用日志前缀时,client 以 `"w"` 打开 `<base>.server.log` 写转发来的 server 日志,会截断 server 自己的文件(依赖 server 日志行的 P12 装置测试可能受影响) | 小修 |
|
||||
| P11 转出(B0 F1):HyperOS 熄屏时冻结 server app 的整个 uid(FGS 进程、supervisor、会话子进程同一 cgroup),在飞会话 120 s 后 `Fatal{BarrierTimeout}`;FCL 同机用法同样受影响(`notes/p11/B0-CROSS-APP.md`) | B1 的防冻结一项;FCL 侧另议 |
|
||||
| P11 转出(B1):会话位被一个慢启动程序占着时,第二个 client 若 2 s 内发 Hello 得具名 `Refuse{Busy}`,更慢的只见发送失败(那条路径不读待发的拒绝);已写进契约 | 小修 |
|
||||
| P11 转出(B1):会话启动失败后 client 还多报一个误导性的 `Fatal{CapsBeforeFirstSnapshot}`(早于 B1,helper 用户每次被拒都会看到) | 小修 |
|
||||
| P11 转出(B1):外部 client 的 apply 线程策略只在红米一台(两大核)上量过;Magma openra 两个数据面都卡在 server(约 285 fps),共享内存无收益 | 需要第二种拓扑的设备时再量 |
|
||||
| 仿真路径的具名拒绝:RGB CPU mip 等(class C 已于 P10 清零;multi-draw client indices 已不再拒绝——client 转成自有 buffer,`EmitTables.cpp:459`,`RefuseDrawByName` 只剩 NO_CONTEXT / INDEX_TYPE / INDEX_OFFSET / CLIENT_COMMANDS / UNBOUND_PARAMETER) | P8(开工时复核) |
|
||||
| P11 转出(M2):超过 stage 分块预算的大层按分片发出,没有写入框覆盖的分片仍带整框(server 要靠它拼层图),会把影子盖到 GPU 写过的地方;修法要一个两个 server 都跳过的「只定位」区域写法,控制协议修订 +1(split 专属,早于 P11) | 小包或 P8 |
|
||||
| P11 转出(M2):上传仍有两种有损形状,各记一次日志——一层的精确写入框超过 4096 个时按存储的矩形表覆盖发出;applier 一个条目累计超过 4096 个区域时并成并集框。纹理带 GPU 写时两者都会把影子盖进空隙 | 小修,无触发报告 |
|
||||
| P11 转出(M2):超过 stage 分块预算的大层按分片发出,没有写入框覆盖的分片仍带自己的整框(server 要靠它拼层图),server 会把这片的影子盖到 GPU 写过的地方;修法要一个两个 server 都跳过的「只定位」区域写法(split 专属,早于 P11) | 待排 |
|
||||
| P11 转出(M2,性能):split server 上纹理无 GPU 写时,Espryt 改为自己按存储的阈值取舍精确写入框,非 ring 路径上可能多发几个小框;设备上未量 | 记录 |
|
||||
| P11 转出(M2,给 dev):dev 的 `DirectVulkan.SplitRecording.` 车道没有 `RESOURCE_LOCK`、其用例读字面日志路径——`-j` 下可能互相截断;P11 线的副本已修 | 下次向 dev 回流时带上 |
|
||||
| P11 转出:pull 构建没有任何门跑集成测试(`TextureRemintPullScenario` 在 pull 上自 P9 起就是红的,P11 M 修) | CI / 门的覆盖,需裁定 |
|
||||
| `GetCaps` 的两个 blobref | 一旦运输,必须有 server → client 的 carrier rule,不能套 `SEG_STAGE` |
|
||||
| E1 对照的重定义(ID-122) | 无主(开放问题 24) |
|
||||
| `MOBILEGL_IPC_IDLE_EXIT_S` 未解析;`CONTRACT-P6.md` 仍把 `DynamicBackendParameters` 定宽记在 P7 名下(已由 P6.5 wf 落地) | 文档 / 小修 |
|
||||
| P12 未做(2026-09-29 收官时转入):DirectGLES `g_Display` / `g_Surface` / `g_Context` 仍是全局(每进程一个会话时不需要);cached-app freezer 的完整处理(文档从未定义);多 context;D8 窗口种类白名单(X11 / Win32Hwnd / None 仍被接受并把 token 强转为指针);TLS;server 窗口不转发输入;修后的横屏 server 窗口未重测 | 无主;D8 等 Windows / X11 client,其余等出现第二个会话 / 第二个 context 的需求 |
|
||||
| P9 转出:`TCP_USER_TIMEOUT` = 5000 ms——client 停读控制超过 5 s 且有待发日志字节时内核仍断开连接;`PublishSessionFault` 的阻塞写对停读的 client 最多等同样 5 s(ID-P9-10) | 传输策略,需裁定 |
|
||||
| P9 转出:Espryt 重铸保留路径上 framebuffer clear 后 `imageLoad` 偶读旧值(主机 3/30,加 barrier 后 0/30;`TextureRemintPullScenario` case C 暂钉 barrier),疑 llvmpipe(ID-P9-11);P11 合并 dev 后 push 单进程臂上也见过一次,`ImageBindableRemintScenario` 同样钉 barrier(ID-P11-6) | 待归因 |
|
||||
| P9 转出:Magma 每次 draw 对可写 SSBO / texel buffer / XFB 目标发整 buffer 的 `OnGpuWritten`(create-indirect 首帧 7,093 条),client 已自标同一批,冗余无害;`OnTextureWriteback`、`OnMipLevelsGenerated`、`OnCapsInvalidated` 仍无生产者 | 以后的收窄 / 清理候选(ID-P9-7) |
|
||||
| P10 转出(性能):设备上 tcp loopback 的 rd12 每帧 19.4 ms 中 ~11.2 ms 是生产者在 stream 传输里的停车(发送 + 环 / stage / ack 等待),credit 等待只有 ~0.2 ms(`notes/p10/C-MEASUREMENTS.md` §2,ID-P10-13) | 路线图推完后的性能工作 |
|
||||
| P11 转出(性能):设备上 MC 26.3,split T2 相对单进程采纳的 p99 Espryt +37–42%、Magma 约 2.5×;其中一部分是线程落位——server apply 线程钉在 6–7 核,client GL 线程多半落到慢核,每帧 CPU 约 2.3×(`notes/p11/A-DEVICE.md`)。RSS 一半已由 B2(T0)交付:峰值内存 Espryt −41–42%、Magma −18–26%(ID-P11-17) | 路线图推完后的性能工作(p99 与线程落位) |
|
||||
| P11 转出(B2,性能):`glBufferStorage(NULL)` 的采纳先把整块零存储当 `resource_subdata` 发一遍(T2 与 T0 都是;MC 26.3 8 个存储、441.5 MiB) | 路线图推完后的性能工作 |
|
||||
| P12 未做:DirectGLES `g_Display` / `g_Surface` / `g_Context` 仍是全局(每进程一个会话时不需要);cached-app freezer 的完整处理(文档从未定义);多 context;server 窗口不转发输入 | 等出现第二个会话 / 第二个 context 的需求 |
|
||||
| P9 转出:Magma 每次 draw 对可写 SSBO / texel buffer / XFB 目标发整 buffer 的 `OnGpuWritten`(create-indirect 首帧 7,093 条),client 已自标同一批,冗余无害;`OnMipLevelsGenerated`、`OnCapsInvalidated` 仍无生产者。`OnTextureWriteback` 也无生产者,但别删:CPU 三通道 mip 退路要它(`CONTRACT-P5B.md:255`) | 以后的收窄 / 清理候选(ID-P9-7) |
|
||||
| `MOBILEGL_PIPE_TEXEL_RETAIN_MB` 已无消费者,但在 pull 构建里 | P13(G1) |
|
||||
| 树外脚本:普查跑器、`wsl_p5_gate.sh` 等在 `~/w7/notes/`,git merge 不会传播 | 需要时入库 |
|
||||
| 临时 CI trigger | 合入 `dev` 前删除 `test.yml` / `apk.yml` 的 `feat/disaggregated` 触发器 |
|
||||
| 树外脚本:普查跑器、`wsl_p5_gate.sh` 等在 `~/w7/notes/`,git merge 不会传播;`~/w7/notes/p11/gate.sh` 是事实上的门 | 需要时入库 |
|
||||
|
||||
已关闭的历史债(P5 的 27 个 wrong-answer、`rsp` 残余读、P5b 的 inproc 依赖、ABI 指纹、默认 staging 装不下 128 MiB 上传、184 符号棘轮 CI 门)及当时的完整债务表见 [`notes/p5b/README.md`](p5b/README.md) 末节。
|
||||
|
||||
@@ -27,4 +27,4 @@ P0 已回答的不再列出(spike A 的域、spike B 的分档、`posix_spawn`
|
||||
21. **配对 / 认证的形式。** **已裁定(ID-P7-3,2026-09-22):令牌足够,不做 TLS。** 威胁模型是「任何人都能连的远程代码路径」而不是窃听:令牌常量时间比较、≥16 字节、无令牌只 loopback、数据面以 `Welcome.dataNonce` 绑定到已认证的控制连接、fork 前认证。TLS 作为 P12 的开放项保留。
|
||||
22. **client 平台范围。** 默认先 Linux + Android(现有 CI 能验),Windows client 第二批(`ShmSegmentWin32` 在;`pipe:` 具名拒绝作废、TCP 替代),macOS 仍不拆分。这决定 `ARCHITECTURE.md` §15.3 "Windows 机器不是正确性门"要不要改。
|
||||
23. **半开连接的检测。** Wi-Fi 掉线不产生挂断事件;dl 的闩取自描述符挂断,TCP 上需要 keepalive / 心跳超时并**由传输层报告为挂断**——这与"绝不取自 apply 超时"不矛盾,写清楚免得重吵。P6.5 ct。
|
||||
24. **E1 对照的重定义(ID-122)无主。** 建议并入 P6.5 的门设计:S8 的好路径断言(`SessionFaultCount() == 0`)已是它想表达的形状,缺的是一个能被证伪的负控。
|
||||
24. **E1 对照的重定义(ID-122)。** **已关闭(2026-09-29 债务审查)**:`10bfd29f` 把 E1 的像素竞速换成观测协议等待的负控 `scripts/ci/wait_boundary_negative_control.py`,由 `split_negative_controls.sh:174` 调用。
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
# P11 B2:T0 零拷贝导入(真机)
|
||||
|
||||
2026-09-29,Redmi `2f7cbe2e`(Adreno 830),默认环境、两个 app 的 HyperOS 电池设「无限制」、CPU 定频并回读、无解冻器。协议与行为见 `MobileGL/MG_Remote/CONTRACT-P11.md` B2 节;报告 `~/w7/notes/p11/b2-report.md`,证据 `~/w7/notes/p11/evidence/b2/`。
|
||||
|
||||
## 开关
|
||||
|
||||
`MOBILEGL_IPC_ADOPT_TIER`:**不设(默认,用户 2026-09-29)= 请求 T0**,本会话用不了(server 自测不通过、server 端 `MOBILEGL_IPC_ALLOW_ADOPT_T0=0`、Stream 数据面、没有 AHB)时静默退回 T2(只记 MGLOG_D、计数);`0` = 同样请求 T0,但退回时两端各一行具名日志;`1` = `Refuse{AdoptTierClosed}` 后 T2;`2` = 与之前完全相同(共享段 + client 推送,T2)。不 Fatal。默认开后在红米上不设开关复跑 MC 26.3 inproc:两后端都导入 8 个缓冲(462,946,304 字节)、ssim 通过、无 T0 相关的 W/E 行。控制协议修订 4 → 5(Hello 带 client 请求的档位,Welcome 回显)。
|
||||
|
||||
## 先验:AHB 的 fd 跨过每条路线(先于任何构建)
|
||||
|
||||
| 路线 | client → server | 结果 |
|
||||
|---|---|---|
|
||||
| shell → server app(B1 helper 的 `fd:`) | `shell` → `untrusted_app:c87` | 64 KiB、32 MiB、128 MiB 都通;server 的 GPU 读到 client 在从不解锁的锁下写入的字节;0 个 avc |
|
||||
| 另一个 app → server app | `c84` → `c87` | 通 |
|
||||
| 同 app(经 helper / 直连 / spawn 的子进程) | `c87` → `c87` | 通 |
|
||||
|
||||
## MC 26.3:开关 0 vs 2(3 次交错,中位)
|
||||
|
||||
内存口径 = 两进程 VmHWM(去重共享页)+ kgsl 驱动分配 + kgsl 导入(AHB 页只出现在导入里,RSS 看不到)。
|
||||
|
||||
| 后端 | 臂 | 开关 | p99 ms | GL / apply CPU ms/帧 | **峰值总内存 MB** | 稳态 MB |
|
||||
|---|---|---|---|---|---|---|
|
||||
| Espryt | inproc | 2 | 46.7 | 10.9 / 11.3 | 3010 | 2992 |
|
||||
| Espryt | inproc | 0 | 44.1 | 11.5 / 11.3 | **1758(−42 %)** | 1492 |
|
||||
| Espryt | spawn+shm | 2 | 44.5 | 10.5 / 11.2 | 3049 | 3029 |
|
||||
| Espryt | spawn+shm | 0 | 44.5 | 10.5 / 10.7 | **1789(−41 %)** | 1526 |
|
||||
| Magma | inproc | 2 | 75.6 | 15.9 / 20.1 | 2677 | 2669 |
|
||||
| Magma | inproc | 0 | 75.9 | 15.9 / 20.4 | **1971(−26 %)** | 1774 |
|
||||
| Magma | spawn+shm | 2 | 76.3 | 15.9 / 20.4 | 2731 | 2713 |
|
||||
| Magma | spawn+shm | 0 | 75.3 | 15.2 / 19.6 | **2244(−18 %)** | 1815 |
|
||||
|
||||
- ssim 开关 0 与 2 逐位相同:MC 26.3 Espryt 0.999684、Magma 0.999600;create-instancing 0.99998。每个开关 0 的会话 8 个大缓冲(441.5 MiB)全部导入。
|
||||
- 帧时与 CPU 不变;每帧 stage 字节几乎不变(1071 → 1052 KiB)——T0 省的是内存,不是上传量。
|
||||
- B1 的外部路线(另一个 app 经 helper)同样走 T0:Espryt 峰值 2830 → 1590 MB。
|
||||
|
||||
## T0 专属改动的 red-once(真机,Android 集成测试 + static-peek,inproc)
|
||||
|
||||
| 改动 | 变红的用例 | Espryt | Magma |
|
||||
|---|---|---|---|
|
||||
| 常驻写直接写进 AHB | `ADrawQueuedBeforeASubDataKeepsItsOwnBytes` | 红 | 红 |
|
||||
| respecify 时立即释放导入 | `ARespecifyWithADrawQueuedKeepsThatDrawsStore` | 绿(驱动大概自己持有引用,未核实;带 fence 的释放保留) | 红 |
|
||||
| 不发布 `kCapAdoptT0` | `TheArenaLandsInTheTierItsLaneDeclares` | 红 | 红 |
|
||||
| CPU 读跳过回读往返 | `ReadbackSeesTheLatestCpuWrite`、`GpuWriteIntoTheArenaIsReadBack` | 红 | 红 |
|
||||
@@ -20,3 +20,7 @@
|
||||
| ID-P11-14 | 2026-09-29 | **零拷贝必须可开关**(用户):开关即 `MOBILEGL_IPC_ADOPT_TIER`——`2`(默认)= 今天的共享内存 + client 推送(T2),`0` = T0 零拷贝导入。开了但本会话用不了(server 自测不通过、server 端禁用、Stream 数据面)→ 退回 T2 加一行具名日志,不 Fatal;A1 在共享段上对 0/1 的握手期 Fatal 随 B2 改成这个回退。server 端另设允许 / 禁止零拷贝的开关。默认值在 B2 真机门之后按数据再议。 | 零拷贝依赖 AHB 导入与 ROM 行为,必须能退回已验证的共享内存路径。 | `PLAN-P11.md` §2 B2;B2 实现 |
|
||||
| ID-P11-15 | 2026-09-29 | **合并 dev `c14283ee`**(M2:Espryt 零散写入按矩形上传、Magma 每 16384 次 draw 分段提交、Magma 描述符池几何增长与整槽回收),合并提交 `c3715998` 加 8 个跟进。要点:dev 的零散写入修复只在单进程成立——split 各臂的 client 仍发存储合并后的矩形表(跨过空隙),合并头上 30 例红(两后端、三臂);改为 client 发精确写入框、server 区域上限 256 → 4096、Espryt server 在纹理无 GPU 写时自行做原来的框 / 矩形取舍(`91454338`)。dev 在按句柄查纹理的 server 路径上补的「GPU 可能写过」标记是承重的(去掉帧缓冲附件那一处即 12 例红)。分段提交也覆盖 split server 的 draw / dispatch。描述符池:回收的围栏在 split server 上重核成立(只从 Present 等完整个槽或空闲排空到达,线上各 flush 点不到达);普查用例只在 Magma Split 跑(Spawn / Tcp 的池在 server 进程,按名跳过),要等 server 应用完再读;server 每 2048 个 set 回卷。link ratchet 171 → 172(dev 新的虚函数经纹理占位对象可达,重设基线)。G1:对旧基线 +108 / −81,具名 +25 / −0 与 dev 自己的增量相同,`.text` a56413 → a5b933,新基线已写。门(`de996d53`):unit 2676、split / spawn / tcp 408 / 325 / 337、Magma 238 / 215 / 191 / 629、gpu 2617×2、verify 2676 / 1330 / 1264、retrace 230 / 236(iterationrp 6 项)。 | 两边改的是同一条上传路径与同一套描述符管理,dev 的修复在 split 下还缺一半。 | `~/w7/notes/p11/m2-report.md` |
|
||||
| ID-P11-16 | 2026-09-29 | **B1 落地**(协议与行为见 `CONTRACT-P11.md` B1 节):`fd:<control>,<aux>` client 端点;两个 flavour 的 server app 都有导出的令牌 broker(令牌 ≥ 16 字节、核对运行中 server 自己的令牌,拒绝一律具名带退出码;server 只开 TCP 时走旁边的私有 abstract 监听);`app_process` helper(令牌走环境变量或文件、不走 argv,经隐藏 `IActivityManager` 发广播);server 界面「复制启动命令」「生成令牌」。**broker 在交出时就写好两条 `PairBind`**(ID-P11-12),helper 以 `MOBILEGL_IPC_FD_PAIRED=1` 告诉 client 跳过自己的;配对后的 unix 会话等 Hello 不设时限、以 EOF 为界(`kPairedUnixHelloWaitMs`),TCP 保留预认证时限——代价是一个永不发 Hello 的程序占着会话位直到它退出。**apply 线程策略按对端与数据面**:外部进程 + 共享段时 apply 线程在最低的那个大核、自旋 50 µs,唯一大核时不占它(退到别的大核或不绑);TCP、同 app spawn、inproc 不变(把 apply 放小核会把 TCP 从 51 拖到 27 fps)。server 把实际保留的核通过 broker 告诉 helper,helper 默认 `taskset` 避开它(`--keep-affinity` 关闭),核的规则只在 C++ 一处。用户须知:令牌 ≥ 16 字节、server 以离屏模式启动、HyperOS 电池对 server app 与 client 所在 app 都设「无限制」(否则熄屏或后台会被冻结)。真机(`df826f42` APK,默认环境、无解冻器):rd12 两后端 × 路线 (a)(b) ssim 全过、shm 全部胜 tcp(Espryt 119.3 / 53.2、118.7 / 39.8;Magma 36.4 / 20.3、32.5 / 20.4);程序晚 10 s 才初始化 EGL 仍能连上;插件 flavour 跑通。主机门(`8dfdd3ba`,之后只改了 Java 一行与契约):G1 0/0、ratchet 172、修订 4、卫生 12/12、unit 2692、各车道全绿;5 个 red-once。 | 用户点名的消费者是同机的原生程序;B0 / HSPIKE 已证明通道可行。 | `CONTRACT-P11.md` B1 节;`~/w7/notes/p11/b1-report.md` |
|
||||
| ID-P11-17 | 2026-09-29 | **B2 落地:T0 零拷贝导入**(协议与行为见 `CONTRACT-P11.md` B2 节,数据见 `B2-DEVICE.md`)。先验:AHB 的 fd 在 shell → server app、另一 app → server app、同 app(helper / 直连 / spawn 子进程)五条路线都跨得过,GPU 读到从不解锁的锁下写入的字节,0 个 avc。设计:领养搭数据环上已有的 `map_persistent` 记录,AHB 经 aux 套接字按记录序号配对,apply 线程处理该记录时最多等 2 s、超时对那一个缓冲具名拒绝、不挂死;server 起角色时做「持续锁定 + GPU 写 + 经持有的指针读回」自测,通过才发布 `kCapAdoptT0`;client 取 min(开关, caps, 数据面);Espryt `glBufferStorageExternalEXT`、Magma `VK_ANDROID_external_memory_android_hardware_buffer`,导入的缓冲不留 Espryt 暂存副本(读者逐一审过);释放由 server 自己的 fence / serial 门控;CPU 读前 server 落完常驻写并等 GPU。控制协议修订 4 → 5。MC 26.3 峰值总内存(含 kgsl 导入):Espryt −41–42 %(3.0 → 1.8 GB)、Magma −18–26 %;ssim、帧时、CPU 不变,每帧 stage 字节不变。T0 专属改动的 red-once 在真机上做(Android 集成测试 + static-peek,inproc)。 | 用户要的同机大缓冲零拷贝;A3 已证明 app 域可行。 | `CONTRACT-P11.md` B2 节;`B2-DEVICE.md`;`~/w7/notes/p11/b2-report.md` |
|
||||
| ID-P11-18 | 2026-09-29 | B2 过程中查出并修掉的三处:(1) **删除仍绑在索引绑定点上的 buffer**,前端清了绑定却没调 `NoteBindPointChanged`,server 留着旧句柄,槽位以新代号重用后 Espryt 在 `BackendSlotTable.Generation` 上 Fatal、Magma 静默丢掉那次 draw / dispatch(早于 B2,任何 split 会话都可能碰到)——四种索引目标加上交换 XFB 对象的路径都补上,`DeletedBoundBufferScenario` 两后端 × 单进程与三臂,去掉修复后 SSBO / uniform / 原子计数器红;(2) Magma 单进程在空的 uniform 绑定点上解引用空 buffer 而段错误(早于 B2),改为读零块,dev 同步修(`853c5f12`、测试 `7030d307`);这是本阶段 G1 唯一的变化:`.text` +224 字节、符号不变;(3) Espryt 的 split / spawn 集成用例没设 `MOBILEGL_ITEST_REQUIRE_GPU`,握手期 Fatal 被记成跳过、ctest 算通过——1106 条全部补上,未暴露新红。 | 前两个是真缺陷;第三个是门禁漏洞。 | `BufferState.cpp`、`UniformManager.cpp`、`MG_IntegrationTest/CMakeLists.txt` |
|
||||
| ID-P11-19 | 2026-09-29 | **零拷贝默认开**(用户,看过 B2 数据后):`MOBILEGL_IPC_ADOPT_TIER` 不设 = 请求 T0,用不了时静默退回 T2(MGLOG_D、计数);显式 `0` 保留具名日志行,`2` 与之前相同。不设时 client 发一个单独的请求值(`0x80`),server 才知道该安静;为记录这个值改了 `protocol.fbs`,按 pin 脚本的「修订号提交本身的修补」用 `--force` 重钉修订 5(修订 5 从未发布),未升到 6。 | 自测把关、用不了自动退回,开关仍可关。 | `CONTRACT-P11.md` B2 节;`design/09` |
|
||||
| ID-P11-20 | 2026-09-29 | **收官头 `0a117243`** 整套门:G1 符号增 0 减 0、`.text` `0xa5ba13`(相对 ID-P11-9 的增量是 M2 合入的 dev 修复与 ID-P11-18 的 +224 字节);fatal census 79(45 族词、7 refusal 词、0 未标)、link ratchet 172、spawn parity 0、协议修订 5、wire-declines 53/53;卫生 12/12;unit 2714;integration-split / spawn / tcp 427 / 346 / 348;integration-magma-split / spawn / tcp / full-split 251 / 228 / 197 / 636;integration-gpu monolith / inproc 2688 / 2688。verify 构建 unit / integration-verify / integration-verify-split 2714 / 1344 / 1278。主机 retrace 230 / 236(6 项仍是 iterationrp 的宿主 llvmpipe JIT 崩溃,monolith 同挂)。 | — | `~/w7/logs/p11/final-summary.log` |
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
# P11 — persistent map 与 ≥16 MiB 采纳(进行中)
|
||||
# P11 — persistent map 与 ≥16 MiB 采纳(已收官,2026-09-29)
|
||||
|
||||
> **2026-09-29 开工**。计划与范围重划 [`PLAN-P11.md`](PLAN-P11.md)(B 已排期:消费者是同机从其他 app 启动的 GL 程序);裁定 [`INTEGRATOR-DECISIONS-P11.md`](INTEGRATOR-DECISIONS-P11.md);真机测量 [`A-DEVICE.md`](A-DEVICE.md);协议 `MobileGL/MG_Remote/CONTRACT-P11.md`。已落地:合并 dev(两次)、A1 / A2、A3(T0 在 app 域两后端 GO)、A4(基线重测)、B0 / HSPIKE(跨 app 通道)、PAIR(连接按 nonce 配对,修订 4)、B1(同机外部 client 经 helper 与令牌 broker 走共享内存)。下一步:B2(T0,可开关)。
|
||||
> **2026-09-29 收官**。计划与范围重划 [`PLAN-P11.md`](PLAN-P11.md);裁定 [`INTEGRATOR-DECISIONS-P11.md`](INTEGRATOR-DECISIONS-P11.md)(ID-P11-1..20);协议 `MobileGL/MG_Remote/CONTRACT-P11.md`;测量 [`A-DEVICE.md`](A-DEVICE.md)、[`B0-CROSS-APP.md`](B0-CROSS-APP.md)、[`HSPIKE.md`](HSPIKE.md)、[`B2-DEVICE.md`](B2-DEVICE.md)。
|
||||
>
|
||||
> | 包 | 结果 |
|
||||
> |---|---|
|
||||
> | A1 / A2 | 采纳档位在握手时由知道数据面的一侧定;Stream 上具名拒绝后 T2;断言 arena 落在车道声明的档、三臂登记 |
|
||||
> | A3 / A4 | T0 在 app 域两后端 GO;采纳基线在 Adreno 830 上重测(省 RSS、不改帧时),路线图的三个数撤下 |
|
||||
> | B0 / HSPIKE | 跨 app 连 server 的 unix 端点被 SELinux 拒;无 Context 的 `app_process` helper 经 Binder 拿到连接(依赖 ROM) |
|
||||
> | PAIR | socket client 的两条连接按 `PairBind` nonce 配对,修订 3 → 4 |
|
||||
> | B1 | 同机外部 client(Termux 类)经 helper + 令牌 broker + `fd:` 端点走共享内存;rd12 Espryt 约 119 vs TCP 40–53 fps;外部 client 的 apply 核策略 |
|
||||
> | B2 | T0 零拷贝导入(两后端,同 app 与外部路线),**默认开**、用不了静默退回 T2;MC 26.3 峰值内存 Espryt −41–42 %、Magma −18–26 %,ssim / 帧时 / CPU 不变;修订 4 → 5 |
|
||||
> | M / M2 | 两次合并 dev(重铸读回、局部上传、Magma 排序与交换间隔、分段提交、零散写入、描述符池),补齐 split 半边 |
|
||||
> | 顺带修掉 | 删除仍绑定的 buffer 后 server 留旧句柄(Espryt Fatal / Magma 丢 draw);Magma 空 uniform 绑定段错误;Espryt split 用例的「跳过算通过」漏洞 |
|
||||
>
|
||||
> 门(收官头):见 ID-P11-20。
|
||||
>
|
||||
> 下面是该阶段在路线图上的原始范围与出口门(2026-09-24 从 [`ROADMAP.md`](../../ROADMAP.md) 阶段表移入,原文照录)。
|
||||
|
||||
@@ -13,5 +26,5 @@
|
||||
|
||||
- **阶段**:**P11** persistent map 与 ≥16 MiB 采纳
|
||||
- **状态**:待排,**同机臂专属、已让位**(2026-09-22)
|
||||
- **落地什么 / 范围**:T0 / T1 只对共享映射成立:`dataPlane = Stream` 上点名 T0 / T1 是具名拒绝并强制 T2(重审 §6 第 5 项),今天 `MOBILEGL_IPC_ADOPT_TIER` 0/1 已是 Fatal-at-use、`kSegAdopt` 只有枚举;前置开放问题 3。POST 探针档位选择(T0 主攻,Adreno 可选 T1,T2 回退);`SEG_ADOPT` 生命周期绑 `completedFrameSerial`;**`gPipeInputs` 版本化 / 双缓冲**(P5d 研究:draw barrier 延后一个 verb 的前提,须在 P3b/P4b 的句柄键控 twin 表之后)。**P5e 的更正**:P5e 退役 draw lockstep **没有**需要它——ra2 实测证明字段**值**已由 `SuppliedFieldMask` 分区,当时那次竞态在**元数据标量**上,修法是让守卫测事实而非断言未来(ID-135)。本行保留采纳存储的一般版本/时序问题;契约 §3.2 的 per-role stamp 已由 P5f 落地,不再是待办
|
||||
- **落地什么 / 范围**:T0 / T1 只对共享映射成立:`dataPlane = Stream` 上点名 T0 / T1 是具名拒绝并强制 T2(重审 §6 第 5 项),今天 `MOBILEGL_IPC_ADOPT_TIER` 0/1 已是 Fatal-at-use(**B2 起已过时**:T0 已实现,2026-09-29 起旋钮未设即 T0、回退安静,`=0` 点名、`=2` 为 T2,见 `MG_Remote/CONTRACT-P11.md` B2)、`kSegAdopt` 只有枚举;前置开放问题 3。POST 探针档位选择(T0 主攻,Adreno 可选 T1,T2 回退);`SEG_ADOPT` 生命周期绑 `completedFrameSerial`;**`gPipeInputs` 版本化 / 双缓冲**(P5d 研究:draw barrier 延后一个 verb 的前提,须在 P3b/P4b 的句柄键控 twin 表之后)。**P5e 的更正**:P5e 退役 draw lockstep **没有**需要它——ra2 实测证明字段**值**已由 `SuppliedFieldMask` 分区,当时那次竞态在**元数据标量**上,修法是让守卫测事实而非断言未来(ID-135)。本行保留采纳存储的一般版本/时序问题;契约 §3.2 的 per-role stamp 已由 P5f 落地,不再是待办
|
||||
- **验收门 / 证据**:`LargeArenaAdoptionScenario` 在所选档下绿;26.3 与两个 Create fixture SSIM ≥ 0.99;Adreno 830 上 p99 帧时与峰值 RSS 对采纳基线(163→21 ms / 40→115 fps / ~400 MB)回归不超过 10%
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# P8 集成者裁定日志(server 侧仿真缺口与 split 覆盖)
|
||||
|
||||
> 形式沿用 [`../p11/INTEGRATOR-DECISIONS-P11.md`](../p11/INTEGRATOR-DECISIONS-P11.md):一条裁定一个 ID,只记「定了什么、为什么、影响哪些文件」。计划见 [`PLAN-P8.md`](PLAN-P8.md)。
|
||||
|
||||
| ID | 日期 | 裁定 | 理由 | 影响 |
|
||||
|---|---|---|---|---|
|
||||
| ID-P8-1 | 2026-09-29 | **重定界**(用户批准):原范围在 `README.md` 与路线图行里划掉保留;方向改为补 server 侧缺口与 split 覆盖;原 10 项里 6 项与 2 个门、开放问题 9 关闭(`PLAN-P8.md`「已关闭」表)。 | 只读核查逐项对代码:split 可达的仿真拒绝只剩 Espryt 生成 mip 两名;client 侧工作已由 P5b–P9 完成。 | `ROADMAP.md`、`notes/p8/` |
|
||||
| ID-P8-2 | 2026-09-29 | 门改写:覆盖门 = 归一化后 split ⊆ monolith ∪ 豁免表;create-indirect 往返门 = 多帧设备 trace 加载帧非 `ResourceCreate` 等待 = 0。 | 原两门按字面不可达 / 是空的(trace 只 1 帧)。 | A 包、P8-0 |
|
||||
| ID-P8-3 | 2026-09-29 | G1 不变;各包 split 半边放在 `MOBILEGL_BUILD_DISAGGREGATED` 下。monolith 半边(例如 B2 的 CPU 滤波读陈旧影子)若 red-once 证实,在 dev 上单独修再合并(用户同意)。 | 沿用 P9 / P11 做法。 | B、C、E |
|
||||
| ID-P8-4 | 2026-09-29 | 第一波七包并行(P8-0、A、B、C、D、E、F,树 `~/w7/p8-<包>`,分支 `p8/<包>`,集成树 `~/w7/p9-main` 分支 `p8/main`);G 等 P8-0 的测量;C、D 为 P13 前置。设备只由 P8-0 使用(红米,约半天,用户同意)。 | 各包改动区域不重叠(`DirectGLES.cpp` 按行段分开)。 | 全部 |
|
||||
@@ -0,0 +1,44 @@
|
||||
# P8 计划(重定界,2026-09-29)
|
||||
|
||||
> 依据:只读核查(树外 `~/w7/notes/p8/AUDIT-P8.md`,审计树 `p11/main`)。用户 09-29 批准重定界并开工。原范围划掉保留在 [`README.md`](README.md)。裁定见 [`INTEGRATOR-DECISIONS-P8.md`](INTEGRATOR-DECISIONS-P8.md)。
|
||||
|
||||
## 结论
|
||||
|
||||
- 原方向"把仿真搬到 client"对剩下的工作不成立:三个真实缺口都在 server 侧(Espryt 生成 mip、Espryt 暂存影子与 GPU 写、Magma wire indirect)。
|
||||
- split 可达的 `UnmigratedEmulation` 只剩 Espryt 生成 mip 的两个名:`generate-mipmap-cpu-filter`(`DirectGLES.cpp:12907-12912`,RGB16F / RGB32F)与 `generate-mipmap-storage`(`DirectGLES.cpp:11631-11653`,存储检查比 GL 要求严)。
|
||||
- `MultiDraw*+CLIENT_INDICES` / `+INSTANCED` 四个 server 闩(`PipeApplier.cpp:972-978`)我们的 client 已发不出,只剩对外来 peer 的协议守卫。
|
||||
- 396 个只在 monolith 登记的用例,CI 的 A/B 步骤已用 inproc 全量重跑(`test.yml` Transport A/B),缺的是按名登记、spawn / tcp 两臂与武装断言。
|
||||
|
||||
## 已关闭(无需工作)
|
||||
|
||||
| 原项 | 由谁完成 | 证据 |
|
||||
|---|---|---|
|
||||
| `HostResolve.cpp` 最大索引扫描、`*IndirectCount` | `beba0256` 自有 buffer、`62bfe461` ClientFetchPlan;server 读自己的影子 | `ClientFetchPlan.h:203-240`、`DirectGLES.cpp:9533-9571`、`DirectVulkan.cpp:381-385` |
|
||||
| `Server/IndexHostMirror`、`index-mirror-bytes` | 不建:server 每个 buffer 已有 R-11 暂存影子,restart 重写从它读 | `DirectGLES.cpp:9198-9252` |
|
||||
| multi-draw client indices | client 拼成一个自有 EBO | `EmitTables.cpp:688-709`、`OwnedDrawInputs.h:51` |
|
||||
| `texture-remint-pull` | P9 W2 | [`../p9/W2-REMINT.md`](../p9/W2-REMINT.md) |
|
||||
| `kCapDriverOrderedXfbCapture` | 被 `kCapBackendOwnsXfbCapture`(P5b t2)取代 | `MGPipeTypes.h:124-135` |
|
||||
| viewport-array 回放(开放问题 9) | server 一次 draw 内按状态分组回放 | `DirectGLES.cpp:8421-8465` |
|
||||
| 门 `ClientArrayAfterComputeWriteScenario` | 改名 `ClientVertexArrayScenario.GpuWritten*`,已登记 split 各臂 | `ClientVertexArrayScenario.cpp:271` |
|
||||
| 门 trace split SSIM ≥ 0.99 | P7 最低 0.9935 | [`../p7/iris-census-1135c664.md`](../p7/iris-census-1135c664.md);出口再跑一次 |
|
||||
|
||||
## 包(第一波并行:P8-0、A、B、C、D、E、F;G 等 P8-0)
|
||||
|
||||
| 包 | 内容 | 门 | red-once |
|
||||
|---|---|---|---|
|
||||
| P8-0 普查 | 设备(红米,两后端)与主机的 trace 语料:monolith 下临时插桩计 5 个 `UnmigratedEmulation` 点、mip 窗口谓词、GPU 写过的 EBO / 参数被 CPU 读、CopyImage 到非可渲染格式的命中数;spawn 下 grep `Fatal{` / `Refuse{` / `MGWIRE-DECLINES`,`MOBILEGL_PIPE_STATS=1` 取逐 op 等待与最大暂存 blob。插桩不提交 | 普查报告:每名命中数与定性 | — |
|
||||
| B | Espryt 生成 mip:B1 存储检查改读计划窗口(`VerbMipBaseLevel` / `LevelCount`、MaxLevel、immutable);B2 RGB16F / RGB32F 在 server 完成(原生可渲染时 `glGenerateMipmap`,否则 server 从自己的层做 CPU 滤波),删 `cpu-filter` 闩,修 `PipeCatalogueTest` 名单 | 新 F1 用例:R11F_G11F_B10F / 深度 × {MAX_LEVEL 偏小、部分 TexStorage};RGB16F 仅采样与渲染目标 × 生成 mip;两后端 × split / spawn / tcp | B1 在当前头上 split 预期 `Fatal{UnmigratedEmulation,"generate-mipmap-storage"}`,不红就关 B1;B2 去掉新臂即 Fatal |
|
||||
| C | Espryt server 暂存影子与 GPU 写对账:被 draw / dispatch 写过的 buffer 标脏,CPU 读者(restart 重写、IndirectCount、原生 indirect 的 baseVertex、MultiDraw 重定基)先做 server 本地回读 | compute 写 EBO + restart 索引;compute 写参数 + `MultiDrawElementsIndirectCount` | 去掉对账即像素错;不红就关 C |
|
||||
| D | Magma wire 臂原生 `vkCmdDraw*Indirect[Count]`(`DirectVulkan.cpp:375-431`),CPU 展开只留在 monolith 也展开的场合 | create-indirect × Magma × split 每帧 `WaitForWireBufferHostAccess` 次数与毫秒 → 0,create-indirect / instancing SSIM 不变 | 强制 CPU 路径即等待 > 0 |
|
||||
| E | CopyImage 在 server store 上处理(复制 store 字节,或把目标层标 GPU 脏),不搬到 client;删 `DirectGLES.cpp:13118-13129` 过时注释与死闩 | copy 到 RGB16 / RGBA16_SNORM 后 `glGetTexImage`,强制影子路径开关 | 去掉即陈旧字节 |
|
||||
| A | 覆盖对齐:(a) 类用例登记到 split / spawn / tcp(tcp fixture 带 ENV);撤 `ClientSideIndices` 排除;豁免表(机制 / 单后端 / 无记录 / 进程内 peek);脚本强制归一化后 split ⊆ monolith ∪ 豁免 | 新脚本 rc 0;各 split 车道全绿 | 删一条登记即按名红 |
|
||||
| F | 重分类:`PipeApplier.cpp:972-978` 改 `ProtocolCorruption`;`WireDraw.inc:297` 去 `@P8`;Magma mip 着色器形状在 split 由 Fatal 改具名拒绝(与 monolith 一致);`kCapNeedsHost*` / `kCapViewportArray` 标保留位 | `fatal_census` / `PeerLatchTest` 绿 | PeerLatch 仍按名闩住 |
|
||||
| G | 大 blob(program archive、`draw_vbo` range 尾):P8-0 测得最大值大于 arena / 4 才做分片 | 测量报告 | — |
|
||||
|
||||
## 门(改写,ID-P8-2)
|
||||
|
||||
- **覆盖**:归一化前缀后 `DirectGLES.Split.*` ⊆ `DirectGLES.*` ∪ 豁免表(原因类必填),脚本强制;取代"逐名相同"(机制类、单后端、进程内 peek 用例天生只属 monolith,按字面不可达)。
|
||||
- **create-indirect 往返**:原 trace 只有 1 帧,门是空的;改为多帧设备 trace 上加载帧非 `ResourceCreate` 等待 = 0。
|
||||
- **trace split 双后端 SSIM ≥ 0.99**(含两个 `coherent_as_flush` fixture),出口再跑。
|
||||
- **P13 前置**:C、D 先于 P13 落地,否则删掉 monolith 臂后继承 split 臂的缺陷。
|
||||
- **G1**:pull 构建不变;split 半边在 `MOBILEGL_BUILD_DISAGGREGATED` 下。monolith 半边若 red-once 证实有缺陷,在 dev 上单独修再合并(ID-P8-3)。
|
||||
@@ -1,15 +1,28 @@
|
||||
# P8 — emulation 下放 + 索引宿主镜像 + 协议广度(待排)
|
||||
# P8 — ~~emulation 下放 + 索引宿主镜像 + 协议广度~~ → server 侧仿真缺口与 split 覆盖(进行中,2026-09-29 起)
|
||||
|
||||
> 尚未开工。本页保存该阶段在路线图上的完整范围与出口门(2026-09-24 从 [`ROADMAP.md`](../../ROADMAP.md) 阶段表移入,原文照录);阶段开工后,计划、裁定与报告都放在本目录。
|
||||
> **2026-09-29 重定界**(用户批准):只读核查发现原范围 10 项里 6 项已由前序阶段完成,剩下的缺口都在 server 侧,不是"搬到 client"。计划 [`PLAN-P8.md`](PLAN-P8.md);裁定 [`INTEGRATOR-DECISIONS-P8.md`](INTEGRATOR-DECISIONS-P8.md)。下面原范围照录并划掉,不删。
|
||||
|
||||
## 摘要
|
||||
## 重定界后的包
|
||||
|
||||
- monolith 跑道,P7 之后。把读前端字节的纯 CPU 变换下放到 client(`MG_Impl/Pipe/HostResolve.cpp`:最大索引扫描、`*IndirectCount` 解析);`Server/IndexHostMirror` **待重裁**(a6 实测宿主索引 span 无 producer);multi-draw client indices、CopyImage 镜像、`generate_mipmap` CPU 回退、`texture-remint-pull` 仿真下放;大 blob carrier 只剩 program archive 与 `draw_vbo` range 尾(与 P6.5 sl 共用分片)。
|
||||
- 门:`DirectGLES.Split.*` 与 `DirectGLES.*` 逐名相同;trace split 双后端 SSIM ≥ 0.99;`create-indirect` 上 roundtrips-per-frame 读零。
|
||||
| 包 | 内容 |
|
||||
|---|---|
|
||||
| P8-0 | 普查:设备与主机 trace 语料上各拒绝点 / 仿真谓词的命中数;split 日志与逐 op 等待 |
|
||||
| A | 覆盖对齐:monolith 用例登记到 split / spawn / tcp,豁免表 + 归一化名单门 |
|
||||
| B | Espryt 生成 mip:存储检查读计划窗口(B1);RGB16F / RGB32F 在 server 完成(B2) |
|
||||
| C | Espryt server 暂存影子与 GPU 写对账 |
|
||||
| D | Magma wire 臂原生 indirect(不再 CPU 展开 + 等 GPU 空闲) |
|
||||
| E | CopyImage 在 server store 上处理 |
|
||||
| F | 死闩清理与重分类(无行为变化) |
|
||||
| G | 大 blob 分片:按 P8-0 的测量决定做不做 |
|
||||
|
||||
## 阶段表行(原 `ROADMAP.md`)
|
||||
## 摘要(原文,已划掉)
|
||||
|
||||
- **阶段**:**P8** emulation 下放 + 索引宿主镜像 + 协议广度
|
||||
- **状态**:待排
|
||||
- **落地什么 / 范围**:`MG_Impl/Pipe/HostResolve.cpp`(~~client 数组范围~~ 已由 `beba0256` 落地为 owned buffer;最大索引扫描、`*IndirectCount` 解析,逐站点 reconcile);`Server/IndexHostMirror` **待重裁**(树里 0 处;a6 §6 实测宿主索引 span 无 producer、client 索引已是 owned buffer——按 `kCapNeedsHostIndexBytes` 的真实消费者重新裁定,不照抄 `ARCHITECTURE.md` §10.3);multi-draw client indices(`MultiDrawElements+CLIENT_INDICES` 仍具名拒绝);CopyImage 镜像搬到 client;viewport-array 回放验证;`generate_mipmap` 计划 + CPU 回退纹素;`texture-remint-pull` 仿真下放(15 处具名拒绝);大 blob carrier 只剩 **program archive 与 `draw_vbo` range 尾**(a6 §6;与 P6.5 sl 共用同一分片);`kCapDriverOrderedXfbCapture`(0 处);~~无 present fence tick~~ 只记在 P10
|
||||
- **验收门 / 证据**:`'^DirectGLES\.Split\.'` 与 `'^DirectGLES\.'` 逐名相同;trace split 双后端 SSIM ≥ 0.99 含两个 `coherent_as_flush` fixture;`ClientArrayAfterComputeWriteScenario`;`create-indirect` 上 `roundtrips-per-frame` 读零;`index-mirror-bytes` 逐用例发布
|
||||
- ~~monolith 跑道,P7 之后。把读前端字节的纯 CPU 变换下放到 client(`MG_Impl/Pipe/HostResolve.cpp`:最大索引扫描、`*IndirectCount` 解析);`Server/IndexHostMirror` **待重裁**(a6 实测宿主索引 span 无 producer);multi-draw client indices、CopyImage 镜像、`generate_mipmap` CPU 回退、`texture-remint-pull` 仿真下放;大 blob carrier 只剩 program archive 与 `draw_vbo` range 尾(与 P6.5 sl 共用分片)。~~
|
||||
- ~~门:`DirectGLES.Split.*` 与 `DirectGLES.*` 逐名相同;trace split 双后端 SSIM ≥ 0.99;`create-indirect` 上 roundtrips-per-frame 读零。~~
|
||||
|
||||
## 阶段表行(原 `ROADMAP.md`,已划掉)
|
||||
|
||||
- ~~**阶段**:**P8** emulation 下放 + 索引宿主镜像 + 协议广度~~
|
||||
- ~~**状态**:待排~~
|
||||
- ~~**落地什么 / 范围**:`MG_Impl/Pipe/HostResolve.cpp`(client 数组范围已由 `beba0256` 落地为 owned buffer;最大索引扫描、`*IndirectCount` 解析,逐站点 reconcile);`Server/IndexHostMirror` **待重裁**(树里 0 处;a6 §6 实测宿主索引 span 无 producer、client 索引已是 owned buffer——按 `kCapNeedsHostIndexBytes` 的真实消费者重新裁定,不照抄 `ARCHITECTURE.md` §10.3);multi-draw client indices(`MultiDrawElements+CLIENT_INDICES` 仍具名拒绝);CopyImage 镜像搬到 client;viewport-array 回放验证;`generate_mipmap` 计划 + CPU 回退纹素;`texture-remint-pull` 仿真下放(15 处具名拒绝);大 blob carrier 只剩 **program archive 与 `draw_vbo` range 尾**(a6 §6;与 P6.5 sl 共用同一分片);`kCapDriverOrderedXfbCapture`(0 处);无 present fence tick 只记在 P10~~
|
||||
- ~~**验收门 / 证据**:`'^DirectGLES\.Split\.'` 与 `'^DirectGLES\.'` 逐名相同;trace split 双后端 SSIM ≥ 0.99 含两个 `coherent_as_flush` fixture;`ClientArrayAfterComputeWriteScenario`;`create-indirect` 上 `roundtrips-per-frame` 读零;`index-mirror-bytes` 逐用例发布~~
|
||||
|
||||
@@ -198,6 +198,17 @@ LOCAL_REFUSAL_WORDS = {
|
||||
"AdoptTierOnStream":
|
||||
"Transport/AdoptTier.cpp (P11 A1) - either side refusing its OWN MOBILEGL_IPC_ADOPT_TIER=0/1 "
|
||||
"on a stream data plane and running T2; the session goes on, so no Refuse frame is sent",
|
||||
"AdoptTierClosed":
|
||||
"Transport/AdoptTier.cpp (P11 B2) - the CLIENT refusing its own MOBILEGL_IPC_ADOPT_TIER=1 (T1 "
|
||||
"was closed, ID-P11-1) and asking T2; the session goes on, so no Refuse frame is sent",
|
||||
"AdoptT0Unavailable":
|
||||
"ServerSession.cpp / ClientSession.cpp (P11 B2) - a session that asked T0 and cannot run it "
|
||||
"(the server's allow switch, no AHardwareBuffer, a failed POST, no kCapAdoptT0) runs T2; one "
|
||||
"line on each side, and the session goes on",
|
||||
"AdoptT0NoStore":
|
||||
"ServerSession.cpp / ClientSession.cpp (P11 B2) - one T0 map_persistent answered DECLINED "
|
||||
"because its store never reached the server (the Offer's bounded wait, or no hop socket on "
|
||||
"the client); that store runs T2 and the session goes on",
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,5 +2,6 @@
|
||||
"1": "7fc859f7fa756818401f4162e7d49a25d430b91e44d89c297321e3cb36c69638",
|
||||
"2": "b30928e6fc93ddc015fd86f634a6820f775a6f2f6de5a848d273981e706b2597",
|
||||
"3": "da09f0acb48cf245703f28556ef5a38bc9e25241ebbf7b6baa9ab1765b7ddd50",
|
||||
"4": "6357c3a07ae258d2825dc42bfd610712b15a38a3beb7a96b5f56ea2988705e7f"
|
||||
"4": "6357c3a07ae258d2825dc42bfd610712b15a38a3beb7a96b5f56ea2988705e7f",
|
||||
"5": "4632750fd68b889cb6df709df9d150f9910468c0c530399de01bef87ba793904"
|
||||
}
|
||||
|
||||
@@ -141,14 +141,12 @@ MAGMA_SERVER_ENV_KNOB_NO_TCP = (".ShaderMip1.", ".ShaderMip2.", ".DepthMip.",
|
||||
f".SplitRecording64.OversizedRecordingSplitScenario.{case}" for case in SPLIT_RECORDING_CASES)
|
||||
|
||||
|
||||
# P11 A1: THE MIRROR SHAPE - entries that exist on tcp ALONE, by construction. `.AdoptTier0.` runs
|
||||
# LargeArenaAdoptionScenario with MOBILEGL_IPC_ADOPT_TIER=0 on the CLIENT: a stream data plane
|
||||
# refuses that tier by name and runs T2 (the scenario is green there), while over shared segments -
|
||||
# the split and spawn arms - the same knob dies at the handshake by design (CONTRACT-P11 §1), so a
|
||||
# split or spawn copy could only ever be a death. Each tail must match at least one tcp entry, or
|
||||
# the exception names nothing. (The DirectGLES `.AdoptTier0.` twins need no entry: the Espryt
|
||||
# CASE pattern does not parse a middle segment, so they never enter that comparison.)
|
||||
MAGMA_TCP_ONLY = (".AdoptTier0.",)
|
||||
# THE MIRROR SHAPE - entries that exist on tcp ALONE, by construction. Each tail must match at least
|
||||
# one tcp entry, or the exception names nothing. P11 A1 put `.AdoptTier0.` here (over shared segments
|
||||
# MOBILEGL_IPC_ADOPT_TIER=0 died at the handshake); P11 B2 made that knob an ASK that falls back to T2
|
||||
# by name, so the Magma `.AdoptTier0.` lane now runs on all three arms with one case set and is
|
||||
# compared like any other. The mechanism stays for the next tcp-only lane.
|
||||
MAGMA_TCP_ONLY = ()
|
||||
|
||||
|
||||
def lane_names(build_dir, label):
|
||||
|
||||
@@ -128,12 +128,16 @@ the domain it actually got in the run-context header and repeats the caveat in
|
||||
the summary; record it with the results.
|
||||
|
||||
To answer the question for the real domain, the same binary has to be executed
|
||||
from an app process. That is **not implemented here**: the intended vehicle is
|
||||
the trace app's spike hook from the spike-A package — ship `extmem_probe` as a
|
||||
`jniLib`/asset, exec it from the app's own uid with its stdout redirected to
|
||||
`/sdcard/MG/extmem-probe.log`, and compare the summary table with the `adb
|
||||
shell` one. Any row that differs between the two is an SELinux/domain finding,
|
||||
not a driver finding.
|
||||
from an app process. The vehicle is the trace app's spike hook from the spike-A
|
||||
package: build the trace APK with `-Pmobilegl.buildExtmemProbe=ON` (packages the
|
||||
probe as `libMobileGLExtmemProbe.so`), put the options in
|
||||
`<output_dir>/spike-spawn.txt.args` (via `run-as`), then
|
||||
`am start ... --es output_dir <dir> --es mobilegl_spike_spawn libMobileGLExtmemProbe.so`.
|
||||
The hook execs `<lib> <marker>`; the probe takes the positional argument as the
|
||||
marker, reads `<marker>.args`, prints to `<marker>.stdout`, and writes a one-line
|
||||
verdict to the marker. Compare the summary table with the `adb shell` one (run the
|
||||
same `.so` from `/data/local/tmp`). Any row that differs between the two is an
|
||||
SELinux/domain finding, not a driver finding.
|
||||
|
||||
## Build and run
|
||||
|
||||
@@ -167,4 +171,31 @@ only on the devices.
|
||||
|
||||
Options: `--size=BYTES` (default 65536; the payload is split into 4 KiB regions,
|
||||
one per writer — A payload, B/C/D importer writes, E GPU fill, F in-process GL
|
||||
write), `--only-t0` / `--only-t1` / `--only-t3` / `--only-gles`, `--no-gles`.
|
||||
write), `--only-t0` / `--only-t1` / `--only-t3` / `--only-gles`, `--no-gles`,
|
||||
`--regions-at-end` (put the A..F window in the last 32 KiB of `--size`, so a large
|
||||
size proves the far end is mapped), `--sustained-lock[=ROUNDS]` (default 8) /
|
||||
`--only-sustained`: the **T0S** rows — the client locks the AHB once and never
|
||||
unlocks while, per round, it CPU-writes REG_A, the server's GPU reads it (Vulkan
|
||||
copy; GL compute on the `glBufferStorageExternalEXT` buffer) and fills REG_E / REG_F,
|
||||
and the client reads both fills through the still-held pointer; after the last
|
||||
round it unlocks and relocks once more (`after unlock+relock`), which separates
|
||||
"GPU writes never landed" from "the held mapping kept stale lines".
|
||||
|
||||
## Route mode (P11 B2 step 1)
|
||||
|
||||
Does a client's AHB cross the *real* B1 routes into the server app? A spike APK built with
|
||||
`-Pmobilegl.buildExtmemProbe=ON -Pmobilegl.extmemProbeAsServer=ON` packages the probe as
|
||||
`libMobileGLServer.so` (the real server becomes `libMobileGLServerReal.so`), so
|
||||
`MobileGLServerService` execs `libMobileGLServer.so <endpoint> --serve` = the probe's route server
|
||||
in the server app's own domain, and B1's broker connects to it and writes its PairBind pair.
|
||||
|
||||
* `--serve` (argv[2]): listen on `<endpoint>`; pair each two connections by their PairBind frame
|
||||
length (control 64 bytes, aux 68); per client variant receive the handle, import it into
|
||||
Vulkan and GL, and run the T0S rounds on the control connection. Rows `ROUTE-<variant>-<size>`.
|
||||
* `--route-client[=@endpoint]`: from `MOBILEGL_IPC_CONTROL=fd:<c>,<a>` (the B1 helper; presents
|
||||
its own PairBind pair unless `MOBILEGL_IPC_FD_PAIRED=1`) or by connecting itself (same app only).
|
||||
Two variants per run: `direct` (`AHardwareBuffer_sendHandleToUnixSocket` on the aux connection)
|
||||
and `hop` (sent on a fresh socketpair whose other end travels over aux by `SCM_RIGHTS`).
|
||||
`--size`, `--sustained-lock=N` (default 4), `--regions-at-end` as above.
|
||||
|
||||
Never ship an APK built with `extmemProbeAsServer`: it has no render server.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user