[Perf] (MG_Pipe, MG_Remote/Client): a texture respecify for a CONFIRMED object stops waiting - the row pays its round trip once, at first use - and the frame drops from 130.9 s to 31.3 s

- The predicate is one function again: MGPipeResourceRespecifyWantsItsReply (PipeRoute.h) is read
  by the wire emitter, so the two halves of this row cannot disagree about whether an answer is
  owed. The buffer half never owes one (both call sites discard the Bool, PipeFill.cpp:1105/:1142);
  the texture half owes one exactly until MGPipeHandleIsPublished, and that latch is set only by an
  ACCEPTED create - which EmitResourceRespecify already sends, blocking, when it is clear
  (TextureEmit.h:869-879). So the object pays once, at first use, and every record after it is
  fire-and-forget.
- MEASURED on the device, same frame, same 101,421,396 B staged, stock power policy: waits
  25,154 -> 4,543 and wall 130.9 s -> 31.3 s. The op split is the proof of what changed and what
  did not: waits by_op 3=20611 -> absent (only 2=4536, 5=6, 9=1 remain), while the RECORDS sent
  are unchanged - frame-sent still shows 3=20633 and 103,094 records total. The round trips went
  away; the work did not.
- It also lands on an independent prediction: an audit run beside this work (mgl-device/scratch/
  scheme-review.md) computed 4,543 remaining waits and a 24-37 s credible range (midpoint ~30 s)
  from the archived logs, a host-inproc round trip of 35.4 us and a measured 43.1 MiB/s link.
  Measured: 31.3 s, at the midpoint.
- Cumulative on that frame since this work started: 43,232 waits / 221.5 s -> 4,543 / 31.3 s (7.1x).
  What is left is the create row (4,536 waits, ~23 s) - the confirmation itself, not waste - plus
  hard floors of ~13.4 s client CPU and ~2.2 s of transfer. Going below that means batching the
  create row, which keeps real answers.
- TWO DEBTS, STATED: (1) the invalidation guard for the one silent-loss case is NOT wired; the
  audit confirmed independently that no production path can drop a texture record today, and if
  one appears the notice it needs is protocol-surface (a tenth reverse callback). (2) No SSIM or
  visual check has been taken since these rows stopped asking - frame-sent agreement is strong
  evidence but it is not a picture.
- Two stale controls in older cases were fixed rather than left: the item-B gate now names the
  CREATE row (its old total-based control only moved because a respecify was still waiting), and
  the by-op measurement asserts records-sent for the rows that deliberately stopped waiting.
  RemoteClientTest 169/169; red-once for the predicate is forcing it back to "always wait".
This commit is contained in:
BZLZHH
2026-09-25 23:29:08 +08:00
parent f2b55b9d2d
commit 82ed1df90e
5 changed files with 119 additions and 29 deletions
+34
View File
@@ -88,6 +88,8 @@
#include "MGPipe.h"
#include "PipeApply.h"
// P12: MGPipeHandleIsPublished, the latch the respecify predicate below reads.
#include "PipeMutation.h"
namespace MobileGL::MG_Pipe {
@@ -271,6 +273,38 @@ namespace MobileGL::MG_Pipe {
MGP_ResourceCreate(&desc, &reply);
return MGPipeTakeReplyBool(reply, "resource_create");
}
// P12: WHICH RESPECIFIES STILL WAIT - one predicate, read by the wire emitter, so the two
// halves of this row cannot disagree about whether an answer is owed.
//
// THE BUFFER HALF NEVER DOES. Both call sites discard its Bool outright
// (PipeFill.cpp:1105 and :1142: `MGPipeRouteResourceRespecify(desc, nullptr);`), so the wait
// bought a value that was thrown away - on the device run this row was the second largest
// source of round trips in one frame, at ~5 ms each.
//
// THE TEXTURE HALF WAITS EXACTLY UNTIL THE OBJECT IS CONFIRMED, and "confirmed" is
// MGPipeHandleIsPublished: the latch is set only when the object's create was ACCEPTED, and
// the applier keeps texture records across a make-current (PipeFill.cpp:3756-3759), so for a
// published object the acceptance this row asks for is a fact the client already holds. The
// confirmation itself is paid once, at first use: EmitResourceRespecify sends a create when
// the latch is clear (TextureEmit.h:869-879), and that create is blocking.
//
// AND WHEN THE LATCH IS CLEAR THIS RETURNS TRUE, which is the whole fallback. It also covers
// the one place the two ends' consumer gates are worded differently - the client asks
// "any bit of the family" (PipeFill.cpp:1577-1595) while the applier asks "bit 10"
// (PipeApply.cpp:1408-1419) - because a create refused by the narrower server gate leaves the
// latch clear, so every later row for that object keeps taking the real answer. The cost of
// that case is throughput, never silence.
inline Bool MGPipeResourceRespecifyWantsItsReply(const MGPResourceDesc& desc) {
#if MOBILEGL_BUILD_DISAGGREGATED
if (MGPipeInstalledArm() != MGPipeRouteArm::kClientWire) return true;
if (static_cast<MGPipeResourceTarget>(desc.Target) == MGPipeResourceTarget::Buffer)
return false;
return !MGPipeHandleIsPublished(MGPipeKind::Texture, desc.Resource);
#else
(void)desc;
return true;
#endif
}
inline Bool MGPipeRouteResourceRespecify(const MGPResourceDesc& desc, const void* initialBytes,
const MGPRespecifiedLevel* level = nullptr) {
return gMGPipeRouteEscapes.ResourceRespecify(&desc, initialBytes, level);
+17 -17
View File
@@ -470,25 +470,25 @@ namespace MobileGL::MG_Remote::Client {
} else {
MG_Pipe::MGPipeClearRespecifiedLevel(record);
}
// P12: THE BUFFER HALF'S ANSWER IS READ BY NOBODY. Both call sites discard this
// record's Bool outright (PipeFill.cpp:1105 and :1142: `MGPipeRouteResourceRespecify(
// desc, nullptr);`), so for a buffer the wait buys a value that is thrown away - pure
// cost, and on the device run this row was the second largest source of round trips in
// the frame. It goes fire-and-forget, with the same provisional-accept shape
// resource_subdata has had since item B.
// P12: WHETHER THIS RECORD OWES AN ANSWER IS ONE PREDICATE, and it lives beside the
// route (PipeRoute.h, MGPipeResourceRespecifyWantsItsReply) so the emitter and the wire
// cannot disagree about it. The two halves are argued there; the short version is that the
// buffer half's Bool is discarded at both call sites, and the texture half's is owed
// until the object's create has been accepted - the confirmation it pays at first use.
//
// THE TEXTURE HALF KEEPS ITS ANSWER, and that is deliberate rather than left over:
// there the Bool is the self-heal trigger AND the gate on the acceptance mirror, and
// advancing that mirror on an answer nobody waited for is exactly ID-18 M3
// (TextureEmit.h:885-888: "a refused respecify must leave LastDesc naming the
// descriptor that actually landed, or the next identical call is suppressed against a
// record that was never stored"). A texture respecify still waits until that mirror
// can be advanced on something better than a provisional accept.
const Bool bufferHalf =
static_cast<MG_Pipe::MGPipeResourceTarget>(record.Target) ==
MG_Pipe::MGPipeResourceTarget::Buffer;
// WHAT A PROVISIONAL ACCEPT DOES TO THE TEXTURE HALF, stated here because it is a
// deliberate trade rather than an oversight: the emitter's acceptance mirror
// (entry.LastDesc) now advances on an answer nobody waited for. ID-18 M3
// (TextureEmit.h:885-888) forbids exactly that for a record whose verdict is UNKNOWN -
// "the next identical call is suppressed against a record that was never stored" - and
// what makes it safe here is that the object is PUBLISHED: the client is not guessing,
// it is reading a latch the server set by accepting this handle's create. The residue
// is the one case where the server loses a record it had, which today has no production
// path (PipeApply.cpp:1593's only callers are tests), and whose guard is the
// invalidation notice the route's notes call ①.
const Bool wantsReply = MG_Pipe::MGPipeResourceRespecifyWantsItsReply(record);
Int32 status = Wire::ReplySink::kStatusError;
if (bufferHalf) {
if (!wantsReply) {
const Uint64 seq = session.EmitAndWaitTails(
MGPWireOp::ResourceRespecify, &record, sizeof(record), nullptr, 0, nullptr, 0,
&status, nullptr, /*wantReply=*/false);
+42 -11
View File
@@ -894,24 +894,32 @@ TEST(RemoteClientControls, TextureUploadsStopOwningAReplyOnTheWireArm) {
MG_State::pGLContext = MakeUnique<MG_State::GLState::GLContext>();
Uint8 pixels[4 * 4 * 4];
std::memset(pixels, 0x21, sizeof(pixels));
// THE CONTROL ROW, NAMED RATHER THAN TOTALLED, AND MEASURED ACROSS THE WHOLE SETUP. The
// object's create is the one record an object always pays for (kWaitReply in
// PipeCalls.def), so ITS counter is the live control - and the baseline goes in before
// GenTextures, because which call publishes the twin (generate, bind or the storage
// definition) is the emitter's business and not this case's. The previous version of this
// control read the session TOTAL and only moved because a respecify was still waiting;
// that row is fire-and-forget for a confirmed object now, which is what made the stale
// control visible instead of silently wrong.
const Uint32 uploadOp = static_cast<Uint32>(MGPWireOp::ResourceSubData);
const Uint32 createOp = static_cast<Uint32>(MGPWireOp::ResourceCreate);
const Uint64 createWaitsBefore = Transport::LinkMetricsReplyWaitsFor(createOp);
GLuint texture = 0;
MG_Impl::GLImpl::GenTextures(1, &texture);
MG_Impl::GLImpl::BindTexture(0x0DE1, texture);
// THE CONTROL ROW. resource_create is kWaitReply (PipeCalls.def), so it owns a reply
// slot and this counter MUST move on it.
const auto beforeCreate = Transport::LinkMetricsReplyWaits();
MG_Impl::GLImpl::TexImage2D(0x0DE1, 0, 0x8058, 4, 4, 0, 0x1908, 0x1401, pixels);
MGP_FILL(DrawArrays);
if (Transport::LinkMetricsReplyWaits() <= beforeCreate) ::_exit(140);
if (Transport::LinkMetricsReplyWaitsFor(createOp) <= createWaitsBefore) ::_exit(140);
// THE ROW UNDER TEST. A second write into the same level is a pure resource_subdata: the
// resource is created, so no create crosses, and the level is dirty again - the only
// record it can produce is the one item B is about.
const auto beforeRecords = ClientWireRecordsEmitted();
const auto beforeWaits = Transport::LinkMetricsReplyWaits();
const Uint64 uploadRecordsBefore = Transport::LinkMetricsRecordsFor(uploadOp);
const Uint64 uploadWaitsBefore = Transport::LinkMetricsReplyWaitsFor(uploadOp);
MG_Impl::GLImpl::TexSubImage2D(0x0DE1, 0, 0, 0, 2, 2, 0x1908, 0x1401, pixels);
MGP_FILL(DrawArrays);
if (ClientWireRecordsEmitted() <= beforeRecords) ::_exit(141);
if (Transport::LinkMetricsReplyWaits() != beforeWaits) ::_exit(142);
if (Transport::LinkMetricsRecordsFor(uploadOp) <= uploadRecordsBefore) ::_exit(141);
if (Transport::LinkMetricsReplyWaitsFor(uploadOp) != uploadWaitsBefore) ::_exit(142);
ClientSessionInstance().Stop();
});
ExpectChildSuccess(child);
@@ -1038,7 +1046,11 @@ TEST(RemoteClientControls, ReplyWaitsByOpForAnAtlasShapedLoad) {
::_exit(148);
if (Transport::LinkMetricsReplyWaitsFor(static_cast<Uint32>(MGPWireOp::ResourceCreate)) == 0)
::_exit(144);
if (Transport::LinkMetricsReplyWaitsFor(static_cast<Uint32>(MGPWireOp::ResourceRespecify)) == 0)
// AND ResourceRespecify FOLLOWS SetTextureParams OFF THAT LIST FOR THE SAME REASON (P12/R3):
// for a confirmed object it is fire-and-forget too. What must still hold is that its RECORDS
// go out - a zero on both lines would mean the emitter stopped sending, which is a different
// and much worse change than this one.
if (Transport::LinkMetricsRecordsFor(static_cast<Uint32>(MGPWireOp::ResourceRespecify)) == 0)
::_exit(145);
// AND SetTextureParams IS DELIBERATELY NOT ON THAT LIST ANY MORE (P12). It was the control
// that proved this counter was live; the first-use confirmation moved the row to
@@ -1138,7 +1150,21 @@ TEST(RemoteClientControls, ABufferRespecifyTakesNoReplyWhileATextureOneStillDoes
MGP_FILL(DrawArrays);
if (Transport::LinkMetricsRecordsFor(respecifyOp) <= recordsBefore) ::_exit(154);
if (Transport::LinkMetricsReplyWaitsFor(respecifyOp) != waitsBefore) ::_exit(155);
// ---- the TEXTURE half: the deliberate exception ----
// ---- the TEXTURE half, part 1: the PREDICATE both halves read (P12/R3) ----
// An unpublished texture still owes its answer - that is the first-use confirmation - and a
// buffer never does. Asserted directly rather than through a record, because the only way to
// produce an unpublished texture on the wire is to make the server REFUSE its create, and a
// malformed descriptor would trip the applier's wire report instead of testing this.
if (MG_Pipe::MGPipeInstalledArm() != MG_Pipe::MGPipeRouteArm::kClientWire) ::_exit(157);
MGPResourceDesc unpublished{};
unpublished.Target = static_cast<Uint8>(MG_Pipe::MGPipeResourceTarget::Tex2D);
if (!MG_Pipe::MGPipeResourceRespecifyWantsItsReply(unpublished)) ::_exit(158);
MGPResourceDesc bufferDesc{};
if (MG_Pipe::MGPipeResourceRespecifyWantsItsReply(bufferDesc)) ::_exit(159);
// ---- the TEXTURE half, part 2: CONFIRMED, end to end ----
// GenTextures + a storage definition publishes the object (its create is accepted, and the
// create is blocking). A SECOND storage definition on that same object is a real change, so
// the record must go out - and must not take a reply.
Uint8 pixels[8 * 8 * 4];
std::memset(pixels, 0x21, sizeof(pixels));
GLuint texture = 0;
@@ -1146,7 +1172,12 @@ TEST(RemoteClientControls, ABufferRespecifyTakesNoReplyWhileATextureOneStillDoes
MG_Impl::GLImpl::BindTexture(0x0DE1, texture);
MG_Impl::GLImpl::TexImage2D(0x0DE1, 0, 0x8058, 8, 8, 0, 0x1908, 0x1401, pixels);
MGP_FILL(DrawArrays);
if (Transport::LinkMetricsReplyWaitsFor(respecifyOp) == waitsBefore) ::_exit(156);
const Uint64 confirmedRecords = Transport::LinkMetricsRecordsFor(respecifyOp);
const Uint64 confirmedWaits = Transport::LinkMetricsReplyWaitsFor(respecifyOp);
MG_Impl::GLImpl::TexImage2D(0x0DE1, 0, 0x8058, 16, 16, 0, 0x1908, 0x1401, pixels);
MGP_FILL(DrawArrays);
if (Transport::LinkMetricsRecordsFor(respecifyOp) <= confirmedRecords) ::_exit(160);
if (Transport::LinkMetricsReplyWaitsFor(respecifyOp) != confirmedWaits) ::_exit(161);
ClientSessionInstance().Stop();
});
ExpectChildSuccess(child);