mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-19 07:51:57 +09:00
Pipe: fire-and-forget is async - mipmap, copies, XFB span and storage-block rows to kWaitNone, inproc creates and PBO readbacks stop waiting, and the default dual block lets a barriered verb cost one wait (FCL BSL: ~40 sync points/frame).
This commit is contained in:
@@ -769,28 +769,16 @@ TEST(PipeCatalogue, EveryRowCarriesTheWaitClassTheContractGivesIt) {
|
||||
<< WireOpNameForDiag(op);
|
||||
}
|
||||
|
||||
// kWaitApplied: the rows whose apply STILL reads a BARRIER_PULLED row or probes the client
|
||||
// allocator, so the client parks in its own wait and CONTRACT-P5C's semantics hold for them
|
||||
// unchanged - their pulls count into rsp and their probes are legal inside a scope. Two of
|
||||
// them are trailing items and are expected to leave this list in a later package:
|
||||
// generate_mipmap the moment tx2 resolves the texture from VerbMipRes instead of the active
|
||||
// unit, and set_storage_block_binding the moment pg resolves it through
|
||||
// MGPStorageBlockBinding::ShaderCso. When they do, THIS list is what has to be edited.
|
||||
// kWaitApplied: only applier_reset is left. P15 (user decision: everything fire-and-forget
|
||||
// is async) moved generate_mipmap, resource_copy_region, copy_framebuffer_to_texture,
|
||||
// set_storage_block_binding and the five stream-output rows to kWaitNone: their applies
|
||||
// resolve everything from the record's own handles (VerbMipRes, VerbCopyTexDst, the copy's
|
||||
// endpoints, the storage-block program CSO, the P5f server-side span), and the dual-block
|
||||
// census - where any client-filled read is a named Fatal - is empty. applier_reset keeps its
|
||||
// wait: it is once per make-current and its apply probes the client allocator, which is only
|
||||
// legal inside a parked scope.
|
||||
const MGPWireOp appliedRows[] = {
|
||||
MGPWireOp::ApplierReset, MGPWireOp::GenerateMipmap,
|
||||
MGPWireOp::SetStorageBlockBinding, MGPWireOp::BeginStreamOutput,
|
||||
MGPWireOp::EndStreamOutput, MGPWireOp::PauseStreamOutput,
|
||||
MGPWireOp::ResumeStreamOutput, MGPWireOp::BindStreamOutput,
|
||||
MGPWireOp::CopyFramebufferToTexture,
|
||||
// P5e (gl), ID-118. resource_copy_region JOINED THIS SET, and it is the retiring phase
|
||||
// of a field that put it here: its verb is CopyImageSubData, whose apply reads
|
||||
// GetTextureObject, and that row retires in P7. An unbarriered record reading client
|
||||
// memory is an unconditional Fatal, so leaving it kWaitNone would have meant a real
|
||||
// defect standing for two phases - or an exception hand-written into a DERIVED
|
||||
// allowlist, which is the same thing with a comment on it. It sits beside
|
||||
// copy_framebuffer_to_texture here for the reason it took that class: same verb class,
|
||||
// no reply slot, and zero calls per frame in the measured scene.
|
||||
MGPWireOp::ResourceCopyRegion,
|
||||
MGPWireOp::ApplierReset,
|
||||
};
|
||||
for (const MGPWireOp op : appliedRows) {
|
||||
EXPECT_EQ(MGPipeWaitClassFor(op), kWaitApplied) << WireOpNameForDiag(op);
|
||||
@@ -812,12 +800,17 @@ TEST(PipeCatalogue, EveryRowCarriesTheWaitClassTheContractGivesIt) {
|
||||
MGPWireOp::CreateShaderState, MGPWireOp::SetDrawProgram,
|
||||
// P9: the pack-buffer readbacks - the point of the two rows is that nothing waits.
|
||||
MGPWireOp::ReadPixelsToBuffer, MGPWireOp::GetTextureImageToBuffer,
|
||||
// P15: fire-and-forget.
|
||||
MGPWireOp::GenerateMipmap, MGPWireOp::ResourceCopyRegion, MGPWireOp::CopyFramebufferToTexture,
|
||||
MGPWireOp::SetStorageBlockBinding, MGPWireOp::BeginStreamOutput, MGPWireOp::EndStreamOutput,
|
||||
MGPWireOp::PauseStreamOutput, MGPWireOp::ResumeStreamOutput, MGPWireOp::BindStreamOutput,
|
||||
};
|
||||
for (const MGPWireOp op : noneRows) {
|
||||
EXPECT_EQ(MGPipeWaitClassFor(op), kWaitNone) << WireOpNameForDiag(op);
|
||||
}
|
||||
|
||||
// The partition, by count. 15 + 1 + 10 = 26 rows wait (shared_image made the reply rows 15); every other row of the catalogue does
|
||||
// The partition, by count. 15 + 1 + 1 = 17 rows wait (shared_image made the reply rows 15; P15
|
||||
// left one kWaitApplied row); every other row of the catalogue does
|
||||
// not. A row that changed class moves two of these numbers at once - which is why the
|
||||
// kWaitApplied count went 9 -> 10 and the kWaitNone offset 24 -> 25 in the SAME commit that
|
||||
// moved resource_copy_region (P5e gl, ID-118).
|
||||
@@ -832,9 +825,9 @@ TEST(PipeCatalogue, EveryRowCarriesTheWaitClassTheContractGivesIt) {
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(reply, 15u);
|
||||
EXPECT_EQ(applied, 10u);
|
||||
EXPECT_EQ(applied, 1u);
|
||||
EXPECT_EQ(present, 1u);
|
||||
EXPECT_EQ(none, static_cast<SizeT>(kMGPipeCallCount) - 26u);
|
||||
EXPECT_EQ(none, static_cast<SizeT>(kMGPipeCallCount) - 17u);
|
||||
EXPECT_EQ(other, 0u) << "a row carries the kWaitClassCount terminator as its class";
|
||||
|
||||
// And the reply half of the partition BOTH WAYS, over the whole catalogue: exactly the rows
|
||||
|
||||
@@ -16,7 +16,7 @@ struct E1BoundaryPeer : Codec::WireVerbSink {
|
||||
while (!bell.entered.load() && !clientReturned.load()) std::this_thread::yield();
|
||||
return true;
|
||||
}
|
||||
Bool OnGenerateMipmap(const MGPMipPlan&) override { return Apply(MGPWireOp::GenerateMipmap); }
|
||||
Bool OnApplierReset(const MGPApplierReset&) override { return Apply(MGPWireOp::ApplierReset); }
|
||||
Bool OnClear(const MGPClear&) override { return Apply(MGPWireOp::Clear); }
|
||||
void Install() {
|
||||
if (Srv::ServerLoopInstance().RunProbeOnApplyThreadForTesting([](void* self) {
|
||||
@@ -49,10 +49,11 @@ void CheckE1Boundary(Bool serverCap, MGPWireOp op, Bool expectWait, const char*
|
||||
peer.Install();
|
||||
const Uint64 before = session.Control()->submittedSeq.load();
|
||||
producer.*PeerMember(ProducerBellTag{}) = &bell;
|
||||
const MGPMipPlan mip{};
|
||||
const MGPApplierReset reset{};
|
||||
const MGPClear clear{};
|
||||
const Uint64 seq = op == MGPWireOp::GenerateMipmap
|
||||
? session.EmitAndWait(op, &mip, sizeof(mip), nullptr, 0, nullptr, 0, nullptr)
|
||||
// P15: applier_reset is the one kWaitApplied row left (generate_mipmap went async).
|
||||
const Uint64 seq = op == MGPWireOp::ApplierReset
|
||||
? session.EmitAndWait(op, &reset, sizeof(reset), nullptr, 0, nullptr, 0, nullptr)
|
||||
: session.EmitAndWait(op, &clear, sizeof(clear), nullptr, 0, nullptr, 0, nullptr);
|
||||
// Observe BEFORE allowing the peer to complete a non-waiting emission.
|
||||
const Bool parked = bell.entered.load();
|
||||
@@ -63,7 +64,7 @@ void CheckE1Boundary(Bool serverCap, MGPWireOp op, Bool expectWait, const char*
|
||||
if (seq <= before || peer.seen.load() != 1 || session.Control()->Progress.appliedSeq.load() < seq) ::_exit(86);
|
||||
const Bool correct = expectWait ? parked && appliedBeforeReturn : !parked && !appliedBeforeReturn;
|
||||
std::printf("E1 observation: op=%s cap=%u barrier=%u parked=%u applied_before_return=%u emitted=1 peer_seen=1\n",
|
||||
op == MGPWireOp::GenerateMipmap ? "GenerateMipmap" : "Clear",
|
||||
op == MGPWireOp::ApplierReset ? "ApplierReset" : "Clear",
|
||||
static_cast<unsigned>(serverCap), MG_Config::Ipc.VerbBarrier,
|
||||
static_cast<unsigned>(parked), static_cast<unsigned>(appliedBeforeReturn));
|
||||
std::fflush(stdout);
|
||||
@@ -80,9 +81,9 @@ void CheckE1Boundary(Bool serverCap, MGPWireOp op, Bool expectWait, const char*
|
||||
|
||||
TEST(RemoteWaitBoundaryControl, AppliedClassWaitsWithRunAheadCap) {
|
||||
#if MGTEST_HAVE_FORK
|
||||
ASSERT_EQ(MGPipeWaitClassFor(MGPWireOp::GenerateMipmap), kWaitApplied);
|
||||
CheckE1Boundary(true, MGPWireOp::GenerateMipmap, true,
|
||||
"E1 wait boundary: GenerateMipmap returned before apply");
|
||||
ASSERT_EQ(MGPipeWaitClassFor(MGPWireOp::ApplierReset), kWaitApplied);
|
||||
CheckE1Boundary(true, MGPWireOp::ApplierReset, true,
|
||||
"E1 wait boundary: ApplierReset returned before apply");
|
||||
#else
|
||||
GTEST_SKIP() << "E1 requires POSIX child isolation";
|
||||
#endif
|
||||
|
||||
@@ -2587,6 +2587,9 @@ void StartRunAheadSession() {
|
||||
::alarm(15);
|
||||
MG_Config::Transport = MG_Config::TransportMode::InProcess;
|
||||
MG_Config::Ipc.RunAhead = 1;
|
||||
// The run-ahead guards below are the SHARED-block rules; the dual block (the default since
|
||||
// P15) makes a barriered fill the client's own and is covered by DualBlockScenario.
|
||||
MG_Config::Ipc.RoleSplitState = false;
|
||||
Srv::ServerSessionInstance().SetCapabilityBits(
|
||||
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply));
|
||||
Srv::ServerSessionInstance().SetConsumedSubsystems(kMGPipeSubsystemsMigratedAtP4a);
|
||||
@@ -2828,6 +2831,91 @@ TEST(RemoteRunAhead, AnIndexedDrawVerbIsUnbarrieredAndTouchesPipeInputsNotAtAll)
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// P15: FIRE-AND-FORGET IS THE DEFAULT. The texture-op copies, mip generation and the transform
|
||||
// feedback span calls owe the client no answer, so under run-ahead each publishes and returns.
|
||||
// The wait classes are pinned at compile time (the red: put any of them back to kWaitApplied and
|
||||
// this file stops compiling); the case below proves the client really does not wait on them.
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::GenerateMipmap) == kWaitNone);
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::ResourceCopyRegion) == kWaitNone);
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::CopyFramebufferToTexture) == kWaitNone);
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::BeginStreamOutput) == kWaitNone);
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::EndStreamOutput) == kWaitNone);
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::PauseStreamOutput) == kWaitNone);
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::ResumeStreamOutput) == kWaitNone);
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::BindStreamOutput) == kWaitNone);
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::SetStorageBlockBinding) == kWaitNone);
|
||||
|
||||
struct AcceptAllPeer : Codec::WireVerbSink {
|
||||
Bool OnGenerateMipmap(const MGPMipPlan&) override { return true; }
|
||||
Bool OnResourceCopyRegion(const MGPCopyRegion&) override { return true; }
|
||||
Bool OnCopyFramebufferToTexture(const MGPCopyFromFramebuffer&) override { return true; }
|
||||
Bool OnBeginStreamOutput(const MGPStreamOutputBegin&) override { return true; }
|
||||
Bool OnEndStreamOutput(const MGPXfbAccounting&) override { return true; }
|
||||
Bool OnPauseStreamOutput(const MGPStreamOutputControl&) override { return true; }
|
||||
Bool OnResumeStreamOutput(const MGPStreamOutputControl&) override { return true; }
|
||||
Bool OnBindStreamOutput(const MGPStreamOutputBind&) override { return true; }
|
||||
void Install() {
|
||||
if (Srv::ServerLoopInstance().RunProbeOnApplyThreadForTesting(
|
||||
[](void* self) {
|
||||
auto& decoder = Srv::ServerSessionInstance().Applier().*PeerMember(DecoderTag{});
|
||||
decoder.SetVerbSink(static_cast<AcceptAllPeer*>(self));
|
||||
return MOBILEGL_OK;
|
||||
},
|
||||
this) != MOBILEGL_OK) {
|
||||
::_exit(82);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST(RemoteRunAhead, FireAndForgetRowsDoNotWaitForTheirApply) {
|
||||
const auto child = RunInChild([] {
|
||||
StartRunAheadSession();
|
||||
AcceptAllPeer peer;
|
||||
peer.Install();
|
||||
ClientSession& session = ClientSessionInstance();
|
||||
const Uint64 before = session.RecordWaits();
|
||||
const auto emit = [&](MGPWireOp op, const auto& payload) {
|
||||
session.EmitAndWait(op, &payload, sizeof(payload), nullptr, 0, nullptr, 0, nullptr);
|
||||
};
|
||||
emit(MGPWireOp::GenerateMipmap, MGPMipPlan{});
|
||||
emit(MGPWireOp::ResourceCopyRegion, MGPCopyRegion{});
|
||||
emit(MGPWireOp::CopyFramebufferToTexture, MGPCopyFromFramebuffer{});
|
||||
emit(MGPWireOp::BindStreamOutput, MGPStreamOutputBind{});
|
||||
emit(MGPWireOp::BeginStreamOutput, MGPStreamOutputBegin{});
|
||||
emit(MGPWireOp::PauseStreamOutput, MGPStreamOutputControl{});
|
||||
emit(MGPWireOp::ResumeStreamOutput, MGPStreamOutputControl{});
|
||||
emit(MGPWireOp::EndStreamOutput, MGPXfbAccounting{});
|
||||
if (session.RecordWaits() != before) ::_exit(121);
|
||||
session.Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// P15: a create is fire-and-forget under run-ahead. The handle is the client's own allocation
|
||||
// and the server's accept is derivable (it declines only protocol corruption or a family with no
|
||||
// consumer, which the client never emits for), so the call publishes and returns with a
|
||||
// provisional accept instead of waiting for the answer.
|
||||
//
|
||||
// THE RED (done once while writing it): drop Wire_ResourceCreate's run-ahead fast path and the
|
||||
// call takes the blocking path, so RecordWaits() moves and the child exits 112.
|
||||
TEST(RemoteRunAhead, AResourceCreateDoesNotWaitForItsAnswer) {
|
||||
const auto child = RunInChild([] {
|
||||
StartRunAheadSession();
|
||||
ClientSession& session = ClientSessionInstance();
|
||||
const Uint64 before = session.RecordWaits();
|
||||
MG_Pipe::MGPResourceDesc desc{};
|
||||
desc.Resource = MG_Pipe::MGPipeHandle{MG_Pipe::kMGPipeFirstAllocatableSlot, 1};
|
||||
desc.Target = MG_Pipe::kMGPipeResourceTargetBuffer;
|
||||
desc.Width = 64;
|
||||
MG_Pipe::MGPReplySlot reply = MG_Pipe::MGPipeMintReplySlot();
|
||||
MG_Pipe::gMGPipeScreen.ResourceCreate(&desc, &reply);
|
||||
if (!MG_Pipe::MGPipeTakeReplyBool(reply, "resource_create")) ::_exit(111);
|
||||
if (session.RecordWaits() != before) ::_exit(112);
|
||||
session.Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// P15: the blit family. Every blit reaches the validate point as BlitNamedFramebuffer and
|
||||
// publishes one `blit` record (kWaitNone, stamped as BlitFramebuffer), so it is unbarriered: no
|
||||
// fill and no applier quiesce. A barriered answer here was a forced wait once per frame on FCL
|
||||
|
||||
Reference in New Issue
Block a user