mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-19 16:01:57 +09:00
[Feat] (P13 W4a): Espryt monolith takes the record arm for buffers, indirect, client arrays, binding points and fp64 through an in-process verb port
This commit is contained in:
@@ -35,6 +35,8 @@
|
||||
#include "PersistentMapTracker.h"
|
||||
|
||||
#include "../Server/ServerLoop.h"
|
||||
#include "../Server/PipeApplier.h"
|
||||
#include <MG_Backend/BackendObjects.h>
|
||||
|
||||
#include <MG_Util/Converters/GLToMG/TextureEnumConverter.h>
|
||||
#include <MG_Util/Converters/MGToGL/TextureEnumConverter.h>
|
||||
@@ -239,6 +241,87 @@ namespace MobileGL::MG_Remote::Client {
|
||||
MG_Pipe::MGPipeDrainDeferredDestroys();
|
||||
}
|
||||
|
||||
// ---- P13 W4: THE MONOLITH VERB PORT ----------------------------------------------
|
||||
//
|
||||
// Monolith's record arm (MG_Config::RecordArmAliasesFrontend) reads the verb's own state -
|
||||
// VerbIndirectBuffer, VerbDispatchIndirectBuffer, ... - and nothing in monolith wrote it:
|
||||
// ServerVerbSink is its only writer, and monolith never decoded a verb record. So the
|
||||
// ported slots run THESE emitters - the same plan, the same pre-verb hooks in the same
|
||||
// order (persistent-map push, owned client-memory inputs, the GPU-write marks) - and hand
|
||||
// the planned record, in this process and on this thread, to a ServerVerbSink bound to
|
||||
// the one backend object, which stamps the verb state exactly as the apply thread does
|
||||
// and calls the backend's REAL table (ServerVerbSink::Table, never gBackendFunctionsTable,
|
||||
// so nothing re-enters this port). One planner and one sink body serve both shapes: the
|
||||
// monolith record arm is the split record arm minus the codec and the ring.
|
||||
Bool g_monolithVerbPort = false;
|
||||
|
||||
Server::ServerVerbSink& MonolithVerbSink() {
|
||||
// Leaked at exit like every other MG_Remote singleton (ID-8).
|
||||
static Server::ServerVerbSink& sink = *new Server::ServerVerbSink();
|
||||
return sink;
|
||||
}
|
||||
|
||||
// The session a ported verb emits through - or null, which is the monolith port.
|
||||
ClientSession* VerbSessionFor(const char* slot) {
|
||||
if (g_monolithVerbPort) return nullptr;
|
||||
return &RequireSession(slot);
|
||||
}
|
||||
|
||||
void ApplyOnMonolithPort(MG_Pipe::MGPWireOp op, const void* payload, const Wire::WireTail* tails,
|
||||
Uint32 tailCount) {
|
||||
Server::ServerVerbSink& sink = MonolithVerbSink();
|
||||
MG_Backend::BackendObject* backend = MG_Backend::pActiveBackendObject.get();
|
||||
if (sink.Backend() != backend) sink.SetBackend(backend);
|
||||
Bool applied = false;
|
||||
const char* row = nullptr;
|
||||
switch (op) {
|
||||
case MG_Pipe::MGPWireOp::DrawVbo: {
|
||||
row = "draw_vbo";
|
||||
const auto& info = *static_cast<const MG_Pipe::MGPDrawInfo*>(payload);
|
||||
const auto* ranges = (tailCount > 0 && tails[0].Size != 0)
|
||||
? static_cast<const MG_Pipe::MGPDrawRange*>(tails[0].Bytes)
|
||||
: nullptr;
|
||||
const auto* indirect = ((info.Flags & MG_Pipe::kDrawIsIndirect) != 0 && tailCount > 1)
|
||||
? static_cast<const MG_Pipe::MGPDrawIndirect*>(tails[1].Bytes)
|
||||
: nullptr;
|
||||
applied = sink.OnDrawVbo(info, ranges, nullptr, indirect);
|
||||
break;
|
||||
}
|
||||
case MG_Pipe::MGPWireOp::LaunchGrid:
|
||||
row = "launch_grid";
|
||||
applied = sink.OnLaunchGrid(*static_cast<const MG_Pipe::MGPGridInfo*>(payload));
|
||||
break;
|
||||
default:
|
||||
// A slot InstallMonolithVerbPort routes here whose row this switch does not know:
|
||||
// the two lists drifted, and falling through to the driver would be the very
|
||||
// "ran the other arm and looked fine" this port exists to end.
|
||||
UnmigratedVerbFatal("MonolithVerbPort");
|
||||
}
|
||||
if (!applied) {
|
||||
MGLOG_E_ONCE("MGPipe: the monolith verb port's %s was declined by the sink; nothing was "
|
||||
"drawn or dispatched",
|
||||
row);
|
||||
}
|
||||
}
|
||||
|
||||
// The emission of a ported verb: the session's, or the port's.
|
||||
void EmitVerbTails(ClientSession* session, MG_Pipe::MGPWireOp op, const void* payload, Uint64 payloadBytes,
|
||||
const Wire::WireTail* tails, Uint32 tailCount) {
|
||||
if (session != nullptr) {
|
||||
session->EmitAndWaitTails(op, payload, payloadBytes, tails, tailCount, nullptr, 0, nullptr);
|
||||
return;
|
||||
}
|
||||
ApplyOnMonolithPort(op, payload, tails, tailCount);
|
||||
}
|
||||
void EmitVerbNoTail(ClientSession* session, MG_Pipe::MGPWireOp op, const void* payload,
|
||||
Uint64 payloadBytes) {
|
||||
if (session != nullptr) {
|
||||
session->EmitAndWait(op, payload, payloadBytes, nullptr, 0, nullptr, 0, nullptr);
|
||||
return;
|
||||
}
|
||||
ApplyOnMonolithPort(op, payload, nullptr, 0);
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// CLASS B - the five slots the verb census measured (CONTRACT-P5.md §7)
|
||||
// =============================================================================
|
||||
@@ -519,7 +602,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
const MG_Pipe::MGPDrawRange* ranges, Uint32 numDraws,
|
||||
const void* clientIndices, Uint64 clientIndexBytes,
|
||||
const MG_Pipe::MGPDrawIndirect* indirect) {
|
||||
ClientSession& session = RequireSession(slot);
|
||||
ClientSession* session = VerbSessionFor(slot);
|
||||
PersistentMapTracker::Instance().PushDrawConsumers();
|
||||
MG_Pipe::MGPipeDrainDeferredDestroys();
|
||||
// Snapshot before marking THIS draw's potential GPU writes: resolving
|
||||
@@ -554,8 +637,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
tails[1] = {indirect, sizeof(*indirect)};
|
||||
tailCount = 2;
|
||||
}
|
||||
session.EmitAndWaitTails(MG_Pipe::MGPWireOp::DrawVbo, &info, sizeof(info), tails,
|
||||
tailCount, nullptr, 0, nullptr);
|
||||
EmitVerbTails(session, MG_Pipe::MGPWireOp::DrawVbo, &info, sizeof(info), tails, tailCount);
|
||||
}
|
||||
|
||||
// ---- the single-draw indexed family: DrawElements, DrawElementsBaseVertex, the two
|
||||
@@ -1293,7 +1375,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// carried both calls before its Fatal precisely so that the package which flipped this
|
||||
// slot would inherit a call site that was already correct.
|
||||
void EmitDispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ) {
|
||||
ClientSession& session = RequireSession("DispatchCompute");
|
||||
ClientSession* session = VerbSessionFor("DispatchCompute");
|
||||
PersistentMapTracker::Instance().PushDrawConsumers();
|
||||
MarkGpuWritesForDispatch();
|
||||
|
||||
@@ -1307,12 +1389,11 @@ namespace MobileGL::MG_Remote::Client {
|
||||
record.IndirectBuffer = MG_Pipe::kMGPipeNullHandle;
|
||||
record.IndirectOffset = 0;
|
||||
record.IsIndirect = 0;
|
||||
session.EmitAndWait(MG_Pipe::MGPWireOp::LaunchGrid, &record, sizeof(record), nullptr, 0,
|
||||
nullptr, 0, nullptr);
|
||||
EmitVerbNoTail(session, MG_Pipe::MGPWireOp::LaunchGrid, &record, sizeof(record));
|
||||
}
|
||||
|
||||
void EmitDispatchComputeIndirect(GLintptr indirect) {
|
||||
ClientSession& session = RequireSession("DispatchComputeIndirect");
|
||||
ClientSession* session = VerbSessionFor("DispatchComputeIndirect");
|
||||
PersistentMapTracker::Instance().PushDrawConsumers();
|
||||
MarkGpuWritesForDispatch();
|
||||
|
||||
@@ -1333,8 +1414,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
MG_Pipe::MGPipeKind::Buffer, bound->GetLifetimeId());
|
||||
}
|
||||
}
|
||||
session.EmitAndWait(MG_Pipe::MGPWireOp::LaunchGrid, &record, sizeof(record), nullptr, 0,
|
||||
nullptr, 0, nullptr);
|
||||
EmitVerbNoTail(session, MG_Pipe::MGPWireOp::LaunchGrid, &record, sizeof(record));
|
||||
}
|
||||
|
||||
// glMemoryBarrier / glMemoryBarrierByRegion. The bits cross VERBATIM: the frontend has
|
||||
@@ -2125,6 +2205,36 @@ namespace MobileGL::MG_Remote::Client {
|
||||
return table;
|
||||
}
|
||||
|
||||
void InstallMonolithVerbPort(MG_Backend::GlobalBackendFunctionsTable& table) {
|
||||
// P13 W4a: the draw and dispatch families. Later W4 steps add their verbs here AND to
|
||||
// ApplyOnMonolithPort's switch, in the same commit.
|
||||
table.GL.DrawArrays = &EmitDrawArrays;
|
||||
table.GL.DrawElements = &EmitDrawElements;
|
||||
table.GL.DrawElementsBaseVertex = &EmitDrawElementsBaseVertex;
|
||||
table.GL.DrawRangeElements = &EmitDrawRangeElements;
|
||||
table.GL.DrawRangeElementsBaseVertex = &EmitDrawRangeElementsBaseVertex;
|
||||
table.GL.DrawElementsInstanced = &EmitDrawElementsInstanced;
|
||||
table.GL.DrawElementsInstancedBaseVertex = &EmitDrawElementsInstancedBaseVertex;
|
||||
table.GL.DrawElementsInstancedBaseInstance = &EmitDrawElementsInstancedBaseInstance;
|
||||
table.GL.DrawElementsInstancedBaseVertexBaseInstance = &EmitDrawElementsInstancedBaseVertexBaseInstance;
|
||||
table.GL.DrawArraysInstanced = &EmitDrawArraysInstanced;
|
||||
table.GL.DrawArraysInstancedBaseInstance = &EmitDrawArraysInstancedBaseInstance;
|
||||
table.GL.MultiDrawArrays = &EmitMultiDrawArrays;
|
||||
table.GL.MultiDrawElements = &EmitMultiDrawElements;
|
||||
table.GL.MultiDrawElementsBaseVertex = &EmitMultiDrawElementsBaseVertex;
|
||||
table.GL.DrawArraysIndirect = &EmitDrawArraysIndirect;
|
||||
table.GL.DrawElementsIndirect = &EmitDrawElementsIndirect;
|
||||
table.GL.MultiDrawArraysIndirect = &EmitMultiDrawArraysIndirect;
|
||||
table.GL.MultiDrawElementsIndirect = &EmitMultiDrawElementsIndirect;
|
||||
table.GL.MultiDrawArraysIndirectCount = &EmitMultiDrawArraysIndirectCount;
|
||||
table.GL.MultiDrawElementsIndirectCount = &EmitMultiDrawElementsIndirectCount;
|
||||
table.GL.DispatchCompute = &EmitDispatchCompute;
|
||||
table.GL.DispatchComputeIndirect = &EmitDispatchComputeIndirect;
|
||||
g_monolithVerbPort = true;
|
||||
}
|
||||
|
||||
Bool MonolithVerbPortInstalled() { return g_monolithVerbPort; }
|
||||
|
||||
Uint32 ImplementedVerbCount() { return kEmittedSlots; }
|
||||
Uint32 LocallyAnsweredSlotCount() { return kLocallyAnsweredSlots; }
|
||||
Uint32 UnmigratedSlotCount() { return kUnmigratedSlots; }
|
||||
|
||||
@@ -88,6 +88,13 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// that the message wording lives in exactly one place.
|
||||
[[noreturn]] void UnmigratedVerbFatal(const char* slot);
|
||||
|
||||
// P13 W4: monolith's record arm. Overwrites the ported verb slots of the backend's own
|
||||
// table with this file's emitters, which hand their planned record to an in-process
|
||||
// ServerVerbSink instead of a session (EmitTables.cpp, "THE MONOLITH VERB PORT"). Installed
|
||||
// by MG_Backend's bring-up when MG_Config::RecordArmAliasesFrontend() holds.
|
||||
void InstallMonolithVerbPort(MG_Backend::GlobalBackendFunctionsTable& table);
|
||||
Bool MonolithVerbPortInstalled();
|
||||
|
||||
// How many of the 71 slots have a real emitter. Reported at bring-up and asserted by the
|
||||
// gate: a table that silently loses an emitter should not be able to look the same as one
|
||||
// that never had it.
|
||||
|
||||
@@ -124,7 +124,9 @@ namespace MobileGL::MG_Remote::Client {
|
||||
} // namespace
|
||||
|
||||
Bool GpuWriteSetIsClientSide() {
|
||||
return MG_Config::Transport != MG_Config::TransportMode::Monolith;
|
||||
// P13 W4a: wherever the backend reads records - every wire, and monolith's record arm -
|
||||
// the client owns the conservative set; the backend marks only its own twins.
|
||||
return MG_Config::DataArmIsRecord();
|
||||
}
|
||||
|
||||
Bool ImageUnitIsAWritableBufferTexture(const ImageTextureBinding& binding) {
|
||||
|
||||
@@ -704,7 +704,9 @@ namespace MobileGL::MG_Remote::Client {
|
||||
}
|
||||
|
||||
Bool PersistentMapTracker::PushIsArmed() {
|
||||
return MG_Config::Transport != MG_Config::TransportMode::Monolith;
|
||||
// P13 W4a: the record arm's buffer reads never ask the frontend object to sync a map, so
|
||||
// the client pushes the mapped span wherever that arm runs - monolith's included.
|
||||
return MG_Config::DataArmIsRecord();
|
||||
}
|
||||
|
||||
// P5d round 3 (package D): the body this forwards to is now one relaxed load of the apply
|
||||
|
||||
@@ -152,6 +152,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// The server's private backend. Null until ServerLoop::CreateBackend has run, and a
|
||||
// verb that arrives before then declines by name rather than dereferencing.
|
||||
void SetBackend(MG_Backend::BackendObject* backend);
|
||||
MG_Backend::BackendObject* Backend() const { return m_backend; }
|
||||
void SetMaxReplyBytes(Uint64 bytes) { m_maxReplyBytes = bytes; }
|
||||
|
||||
// P11 B2: T0's map_persistent - ServerSession::AdoptStoreT0 (it owns the aux socket).
|
||||
|
||||
@@ -120,6 +120,22 @@ namespace MobileGL::MG_Remote::Server {
|
||||
return shadow.Bytes.data();
|
||||
}
|
||||
|
||||
// P13 W4a: a COPY even in a non-copying store - the fallback for a GPU-written store on
|
||||
// monolith's record arm that never recorded the shadow base it aliases (Managers.cpp's
|
||||
// RefreshAliasedStoreFromGpu). Whole-store, covered, and dropped with the key.
|
||||
const Uint8* AdoptPrivateCopy(const void* key, SizeT width, const void* bytes, SizeT size) {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
Shadow& shadow = m_shadows[key];
|
||||
shadow.SessionKey = CurrentStagedBucket().SessionKey;
|
||||
if (shadow.Bytes.size() < std::max(width, size)) shadow.Bytes.resize(std::max(width, size), 0);
|
||||
if (size != 0 && bytes != nullptr) {
|
||||
std::memcpy(shadow.Bytes.data(), bytes, size);
|
||||
CoverageAdd(shadow.Covered, 0, size);
|
||||
}
|
||||
m_any.store(true, std::memory_order_release);
|
||||
return shadow.Bytes.data();
|
||||
}
|
||||
|
||||
void Drop(const void* key) {
|
||||
if (!m_any.load(std::memory_order_acquire)) return;
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
Reference in New Issue
Block a user