[Feat] (MG_Remote): a read into a pixel pack buffer crosses as read_pixels_to_buffer / get_texture_image_to_buffer and waits for nothing - the server lands the rows through the buffer-write gate on both backends, the client marks the buffer GPU-written, and a device lost with the write still owed ends in Fatal{ReadbackDeclined, "buffer-writeback"}

This commit is contained in:
2026-09-29 02:02:29 -04:00
parent ad705a7392
commit 6485ae1dc0
28 changed files with 1152 additions and 58 deletions
+4 -1
View File
@@ -163,7 +163,10 @@
X(QueryDestroy, DeleteBackendQuery) \
X(QueryCounter, QueryCounterTimestamp) \
X(QueryTimestamp, GetGpuTimestampNs) \
X(DeleteStreamOutput, DeleteTransformFeedback)
X(DeleteStreamOutput, DeleteTransformFeedback) \
/* P9 (CONTRACT-P9.md §1): the pack-buffer halves stamp as the verb they reproduce. */ \
X(ReadPixelsToBuffer, ReadPixels) \
X(GetTextureImageToBuffer, GetTextureImage)
// X(Op, Why) - verb-shaped calls that are deliberately NOT stamp points.
//
+32
View File
@@ -1625,6 +1625,38 @@ namespace MobileGL::MG_Pipe {
};
MGP_ASSERT_POD(MGPReadbackInfo, 64);
// P9 (W1, MG_Remote/CONTRACT-P9.md §1): read_pixels_to_buffer / get_texture_image_to_buffer,
// the two readbacks whose destination is a bound GL_PIXEL_PACK_BUFFER. The destination is
// the pack buffer's RESOURCE HANDLE (CONTRACT-P5 row 23: "a PBO destination is a resource
// handle and needs no Seg field"), so nothing comes back and the client does not wait: the
// server reads exactly the tight pixels the reply-slot form would have answered and writes
// them into Dst row by row through the applier's ordinary buffer-write gate, and the client
// marks Dst GPU-written (GpuWritePending.h row 4). A later CPU read of Dst reaches the bytes
// through resource_readback, like any other buffer the GPU wrote.
//
// Src the reply form's record, unchanged: the box, format, type, target and
// level; Src.DstOffset / Src.DstSize are 0 / the tight w*h*d*bpp extent
// and are checked, not used for placement.
// Dst the pack buffer.
// DstBase byte offset in Dst of the first texel of the first row of the first image:
// the application's offset plus GL_PACK_SKIP_{PIXELS,ROWS,IMAGES} already
// applied, because the layout arithmetic is the client's (ReadbackLayout).
// RowStride bytes between two rows in Dst (GL_PACK_ROW_LENGTH and GL_PACK_ALIGNMENT
// applied). Never smaller than a tight row.
// ImageStride bytes between two images in Dst (GL_PACK_IMAGE_HEIGHT applied). Only read
// when Src.Box.D > 1.
// SwapGroup GL_PACK_SWAP_BYTES as the width of the byte group to reverse (2, 4 or 8),
// 0 for no swap - the client's ApplyReadbackByteSwap rule, precomputed there so
// the server does not re-derive the type table.
struct MGPReadbackToBuffer {
MGPReadbackInfo Src;
MGPipeHandle Dst;
Uint64 DstBase, RowStride, ImageStride;
Uint32 SwapGroup;
Uint32 Pad0;
};
MGP_ASSERT_POD(MGPReadbackToBuffer, 104);
// ---------------------------------------------------------------------------------
// Commands
// ---------------------------------------------------------------------------------
+18 -2
View File
@@ -140,9 +140,14 @@
// this one describes what happened to it since. It lands with a NULL ROUTE and a sink that
// refuses it by name until package pg wires the emitter, exactly as set_shader_buffers has
// sat catalogued-and-dead since P4a. 80 unique records.
// - delete_stream_output (opcode 81) took the XFB object's deletion across; 81 records.
// - P9 (MG_Remote/CONTRACT-P9.md §1) appended TWO more (opcodes 82..83):
// read_pixels_to_buffer and get_texture_image_to_buffer, the pack-buffer halves of the two
// readbacks, answered by nothing (ID-57's fire-and-forget). Like P5b's five they reach
// WireVerbSink only and have no monolith producer. 83 unique records.
// ---------------------------------------------------------------------------------------
#define MGP_CALL_LIST_DOCUMENTED_COUNT 81
#define MGP_CALL_LIST_DOCUMENTED_COUNT 83
// clang-format off
#define MGP_CALL_LIST(X) \
@@ -339,7 +344,18 @@
/* ---- names only handles and values is exactly what rule F admits. ---- */ \
X(SetProgramBindings, MGPProgramBindings, kCtxState, kVarTail|kHostSpan, kWaitNone) \
/* Deletion carries the GL argument and its never-reused capture identity. */ \
X(DeleteStreamOutput, MGPStreamOutputBind, kCtxVerb, kNone, kWaitNone)
X(DeleteStreamOutput, MGPStreamOutputBind, kCtxVerb, kNone, kWaitNone) \
/* ---- APPENDED BY P9 (MG_Remote/CONTRACT-P9.md §1), opcodes 82..83: the pack-buffer ---- */ \
/* ---- halves of read_pixels and get_texture_image. The reply-slot rows above keep every ---- */ \
/* ---- read into client memory; a read whose destination is a bound PIXEL_PACK_BUFFER ---- */ \
/* ---- crosses as one of these instead, names the buffer by handle, and is answered by ---- */ \
/* ---- nothing - the server lands the rows in the buffer and the client marks it ---- */ \
/* ---- GPU-written (ID-57's fire-and-forget). kWaitNone: the apply reads only server ---- */ \
/* ---- state and the record, and no BARRIER_PULLED row is left for it to read. Neither ---- */ \
/* ---- has an MGPipeApply* entry point or a monolith producer: monolith reads into its ---- */ \
/* ---- driver PBO inside the backend's own ReadPixels, as before (G1). ---- */ \
X(ReadPixelsToBuffer, MGPReadbackToBuffer, kCtxVerb, kNone, kWaitNone) \
X(GetTextureImageToBuffer, MGPReadbackToBuffer, kCtxObject, kNone, kWaitNone)
// clang-format on
// Explicitly NOT migrated (plan 4.4.6 / appendix A "explicit deletions"):
+6 -1
View File
@@ -230,6 +230,10 @@
#define MGP_FIELDS_MGPReadbackInfo(F) \
F(Res) F(Box) F(Format) F(Type) F(Target) F(Level) F(DstOffset) F(DstSize)
// P9 (CONTRACT-P9.md §1): the pack-buffer readback. Src is one field, as MGPSubData's box is.
#define MGP_FIELDS_MGPReadbackToBuffer(F) \
F(Src) F(Dst) F(DstBase) F(RowStride) F(ImageStride) F(SwapGroup)
#define MGP_FIELDS_MGPDrawInfo(F) \
F(Mode) F(IndexSize) F(Flags) F(InstanceCount) F(StartInstance) F(RestartIndex) F(DrawIdOffset) \
F(IndexResource) F(MinIndex) F(MaxIndex) F(XfbCpuCapturedVertices) F(NumDraws)
@@ -412,7 +416,8 @@
P(MGPStreamOutputTargets) P(MGPGlobalConstants) P(MGPAttribValue) P(MGPVertexAttribDefaults) \
P(MGPPixelPackState) P(MGPPatchState) P(ResidualValueBlock) P(MGPResidualValueState) \
P(MGPSubRegion) P(MGPSubData) P(MGPSubDataComplete) P(MGPFlushRange) P(MGPReadback) \
P(MGPCopyRegion) P(MGPBlit) P(MGPClear) P(MGPMipPlan) P(MGPReadbackInfo) P(MGPDrawInfo) \
P(MGPCopyRegion) P(MGPBlit) P(MGPClear) P(MGPMipPlan) P(MGPReadbackInfo) P(MGPReadbackToBuffer) \
P(MGPDrawInfo) \
P(MGPDrawRange) P(MGPDrawIndirect) P(MGPGridInfo) P(MGPMemoryBarrier) P(MGPStreamOutputBegin) \
P(MGPXfbAccounting) P(MGPStreamOutputControl) P(MGPFlush) P(MGPPresent) P(MGPSwapInterval) \
P(MGPSurfaceInfo) \
@@ -301,12 +301,14 @@ constexpr MGPipeVerb MGPipeVerbForWireOp(MGPWireOp op) {
case MGPWireOp::QueryCounter: return MGPipeVerb::QueryCounterTimestamp;
case MGPWireOp::QueryTimestamp: return MGPipeVerb::GetGpuTimestampNs;
case MGPWireOp::DeleteStreamOutput: return MGPipeVerb::DeleteTransformFeedback;
case MGPWireOp::ReadPixelsToBuffer: return MGPipeVerb::ReadPixels;
case MGPWireOp::GetTextureImageToBuffer: return MGPipeVerb::GetTextureImage;
default:
return MGPipeVerb::kVerbCount;
}
}
inline constexpr SizeT kMGPipeVerbBoundaryOpCount = 32;
inline constexpr SizeT kMGPipeVerbBoundaryOpCount = 34;
inline constexpr SizeT kMGPipeVerbBoundaryExemptCount = 3;
// ---- THE §7 ALLOWLIST, DERIVED RATHER THAN WRITTEN (ID-116) --------------------------
+5 -3
View File
@@ -29,7 +29,7 @@ struct MGPipeScreen {
void (*ApplierReset)(const MGPApplierReset* payload);
};
// context: 69 calls. A null entry means the backend does not implement this
// context: 71 calls. A null entry means the backend does not implement this
// call and the frontend keeps its own path (plan B section 4.1).
struct MGPipeContext {
void (*QueryCreate)(const MGPQueryDesc* payload);
@@ -101,11 +101,13 @@ struct MGPipeContext {
void (*SetContextValues)(const MGPContextValues* payload);
void (*SetProgramBindings)(const MGPProgramBindings* payload, const void* varTail, Uint32 varTailCount);
void (*DeleteStreamOutput)(const MGPStreamOutputBind* payload);
void (*ReadPixelsToBuffer)(const MGPReadbackToBuffer* payload);
void (*GetTextureImageToBuffer)(const MGPReadbackToBuffer* payload);
};
inline constexpr SizeT kMGPipeScreenCallCount = 12;
inline constexpr SizeT kMGPipeContextCallCount = 69;
inline constexpr SizeT kMGPipeCallCount = 81;
inline constexpr SizeT kMGPipeContextCallCount = 71;
inline constexpr SizeT kMGPipeCallCount = 83;
// A table that is not exactly its call count of function pointers has grown a
// member that no generator knows about.
@@ -340,3 +340,11 @@ inline void MGP_SetProgramBindings(const MGPProgramBindings* payload, const void
inline void MGP_DeleteStreamOutput(const MGPStreamOutputBind* payload) {
gMGPipeContext.DeleteStreamOutput(payload);
}
inline void MGP_ReadPixelsToBuffer(const MGPReadbackToBuffer* payload) {
gMGPipeContext.ReadPixelsToBuffer(payload);
}
inline void MGP_GetTextureImageToBuffer(const MGPReadbackToBuffer* payload) {
gMGPipeContext.GetTextureImageToBuffer(payload);
}
+9 -1
View File
@@ -95,6 +95,7 @@ inline Bool MGPipeVerify(const MGPBlit& a, const MGPBlit& b, const char** outFie
inline Bool MGPipeVerify(const MGPClear& a, const MGPClear& b, const char** outField);
inline Bool MGPipeVerify(const MGPMipPlan& a, const MGPMipPlan& b, const char** outField);
inline Bool MGPipeVerify(const MGPReadbackInfo& a, const MGPReadbackInfo& b, const char** outField);
inline Bool MGPipeVerify(const MGPReadbackToBuffer& a, const MGPReadbackToBuffer& b, const char** outField);
inline Bool MGPipeVerify(const MGPDrawInfo& a, const MGPDrawInfo& b, const char** outField);
inline Bool MGPipeVerify(const MGPDrawRange& a, const MGPDrawRange& b, const char** outField);
inline Bool MGPipeVerify(const MGPDrawIndirect& a, const MGPDrawIndirect& b, const char** outField);
@@ -230,6 +231,8 @@ struct MGPipeHasFieldVerifier<MGPMipPlan> : std::true_type {};
template <>
struct MGPipeHasFieldVerifier<MGPReadbackInfo> : std::true_type {};
template <>
struct MGPipeHasFieldVerifier<MGPReadbackToBuffer> : std::true_type {};
template <>
struct MGPipeHasFieldVerifier<MGPDrawInfo> : std::true_type {};
template <>
struct MGPipeHasFieldVerifier<MGPDrawRange> : std::true_type {};
@@ -592,6 +595,11 @@ inline Bool MGPipeVerify(const MGPReadbackInfo& a, const MGPReadbackInfo& b, con
return true;
}
inline Bool MGPipeVerify(const MGPReadbackToBuffer& a, const MGPReadbackToBuffer& b, const char** outField) {
MGP_FIELDS_MGPReadbackToBuffer(MGP_VERIFY_FIELD)
return true;
}
inline Bool MGPipeVerify(const MGPDrawInfo& a, const MGPDrawInfo& b, const char** outField) {
MGP_FIELDS_MGPDrawInfo(MGP_VERIFY_FIELD)
return true;
@@ -749,4 +757,4 @@ inline Bool MGPipeVerify(const MGPVertexBindingPointWire& a, const MGPVertexBind
#undef MGP_VERIFY_FIELD
inline constexpr SizeT kMGPipeVerifiedPayloadCount = 82;
inline constexpr SizeT kMGPipeVerifiedPayloadCount = 83;
+31 -1
View File
@@ -151,7 +151,9 @@ enum class MGPWireOp : Uint16 {
SetContextValues = 79,
SetProgramBindings = 80,
DeleteStreamOutput = 81,
kOpCount = 82,
ReadPixelsToBuffer = 82,
GetTextureImageToBuffer = 83,
kOpCount = 84,
};
// THE FLAGS, EXPORTED ONCE, INDEXED BY OPCODE (P5 R-13.4). MGPWireRecHeader::Flags is
@@ -254,6 +256,8 @@ inline constexpr Uint32 kMGPipeCallFlags[static_cast<SizeT>(MGPWireOp::kOpCount)
/* 79 SetContextValues */ static_cast<Uint32>(kNone),
/* 80 SetProgramBindings */ static_cast<Uint32>(kVarTail | kHostSpan),
/* 81 DeleteStreamOutput */ static_cast<Uint32>(kNone),
/* 82 ReadPixelsToBuffer */ static_cast<Uint32>(kNone),
/* 83 GetTextureImageToBuffer */ static_cast<Uint32>(kNone),
};
static_assert(sizeof(kMGPipeCallFlags) / sizeof(kMGPipeCallFlags[0]) ==
static_cast<SizeT>(MGPWireOp::kOpCount),
@@ -355,6 +359,8 @@ inline constexpr Uint8 kMGPipeCallClasses[static_cast<SizeT>(MGPWireOp::kOpCount
/* 79 SetContextValues */ static_cast<Uint8>(kCtxState),
/* 80 SetProgramBindings */ static_cast<Uint8>(kCtxState),
/* 81 DeleteStreamOutput */ static_cast<Uint8>(kCtxVerb),
/* 82 ReadPixelsToBuffer */ static_cast<Uint8>(kCtxVerb),
/* 83 GetTextureImageToBuffer */ static_cast<Uint8>(kCtxObject),
};
static_assert(sizeof(kMGPipeCallClasses) / sizeof(kMGPipeCallClasses[0]) ==
static_cast<SizeT>(MGPWireOp::kOpCount),
@@ -460,6 +466,8 @@ inline constexpr Uint8 kMGPipeWaitClasses[static_cast<SizeT>(MGPWireOp::kOpCount
/* 79 SetContextValues */ static_cast<Uint8>(kWaitNone),
/* 80 SetProgramBindings */ static_cast<Uint8>(kWaitNone),
/* 81 DeleteStreamOutput */ static_cast<Uint8>(kWaitNone),
/* 82 ReadPixelsToBuffer */ static_cast<Uint8>(kWaitNone),
/* 83 GetTextureImageToBuffer */ static_cast<Uint8>(kWaitNone),
};
static_assert(sizeof(kMGPipeWaitClasses) / sizeof(kMGPipeWaitClasses[0]) ==
static_cast<SizeT>(MGPWireOp::kOpCount),
@@ -1174,6 +1182,22 @@ static_assert(sizeof(MGPWireRec_DeleteStreamOutput) ==
((sizeof(MGPWireRecHeader) + sizeof(MGPStreamOutputBind) + 7u) & ~SizeT(7u)),
"MGPWireRec_DeleteStreamOutput gained padding; the wire format moved");
struct alignas(8) MGPWireRec_ReadPixelsToBuffer {
MGPWireRecHeader Header;
MGPReadbackToBuffer Payload;
};
static_assert(sizeof(MGPWireRec_ReadPixelsToBuffer) ==
((sizeof(MGPWireRecHeader) + sizeof(MGPReadbackToBuffer) + 7u) & ~SizeT(7u)),
"MGPWireRec_ReadPixelsToBuffer gained padding; the wire format moved");
struct alignas(8) MGPWireRec_GetTextureImageToBuffer {
MGPWireRecHeader Header;
MGPReadbackToBuffer Payload;
};
static_assert(sizeof(MGPWireRec_GetTextureImageToBuffer) ==
((sizeof(MGPWireRecHeader) + sizeof(MGPReadbackToBuffer) + 7u) & ~SizeT(7u)),
"MGPWireRec_GetTextureImageToBuffer gained padding; the wire format moved");
[[noreturn]] inline void MGPipeWireProtocolFatal(const char* call, Uint64 size, Uint64 remaining) {
MGLOG_F("MGPipe: protocol corruption applying %s: size=%llu remaining=%llu", call,
static_cast<unsigned long long>(size), static_cast<unsigned long long>(remaining));
@@ -1466,6 +1490,12 @@ inline Bool MGPipeApplyWireRecord(MGPWireOp op, const void* record, Uint64 size,
case MGPWireOp::DeleteStreamOutput:
MGP_WIRE_CHECK_BOUNDS(MGPWireRec_DeleteStreamOutput, "DeleteStreamOutput");
break;
case MGPWireOp::ReadPixelsToBuffer:
MGP_WIRE_CHECK_BOUNDS(MGPWireRec_ReadPixelsToBuffer, "ReadPixelsToBuffer");
break;
case MGPWireOp::GetTextureImageToBuffer:
MGP_WIRE_CHECK_BOUNDS(MGPWireRec_GetTextureImageToBuffer, "GetTextureImageToBuffer");
break;
case MGPWireOp::kInvalid:
case MGPWireOp::kOpCount:
default:
@@ -329,6 +329,13 @@ inline constexpr WireLayoutMember kMGPipeWireLayoutMembers[] = {
{"MGPReadbackInfo.Level", offsetof(MGPReadbackInfo, Level), sizeof(((MGPReadbackInfo*)nullptr)->Level)},
{"MGPReadbackInfo.DstOffset", offsetof(MGPReadbackInfo, DstOffset), sizeof(((MGPReadbackInfo*)nullptr)->DstOffset)},
{"MGPReadbackInfo.DstSize", offsetof(MGPReadbackInfo, DstSize), sizeof(((MGPReadbackInfo*)nullptr)->DstSize)},
{"MGPReadbackToBuffer", 0, sizeof(MGPReadbackToBuffer)},
{"MGPReadbackToBuffer.Src", offsetof(MGPReadbackToBuffer, Src), sizeof(((MGPReadbackToBuffer*)nullptr)->Src)},
{"MGPReadbackToBuffer.Dst", offsetof(MGPReadbackToBuffer, Dst), sizeof(((MGPReadbackToBuffer*)nullptr)->Dst)},
{"MGPReadbackToBuffer.DstBase", offsetof(MGPReadbackToBuffer, DstBase), sizeof(((MGPReadbackToBuffer*)nullptr)->DstBase)},
{"MGPReadbackToBuffer.RowStride", offsetof(MGPReadbackToBuffer, RowStride), sizeof(((MGPReadbackToBuffer*)nullptr)->RowStride)},
{"MGPReadbackToBuffer.ImageStride", offsetof(MGPReadbackToBuffer, ImageStride), sizeof(((MGPReadbackToBuffer*)nullptr)->ImageStride)},
{"MGPReadbackToBuffer.SwapGroup", offsetof(MGPReadbackToBuffer, SwapGroup), sizeof(((MGPReadbackToBuffer*)nullptr)->SwapGroup)},
{"MGPDrawInfo", 0, sizeof(MGPDrawInfo)},
{"MGPDrawInfo.Mode", offsetof(MGPDrawInfo, Mode), sizeof(((MGPDrawInfo*)nullptr)->Mode)},
{"MGPDrawInfo.IndexSize", offsetof(MGPDrawInfo, IndexSize), sizeof(((MGPDrawInfo*)nullptr)->IndexSize)},
@@ -753,4 +760,6 @@ inline constexpr WireCallLayout kMGPipeWireCallLayouts[] = {
{"SetContextValues", "MGPContextValues", static_cast<Uint64>(MGPWireOp::SetContextValues), static_cast<Uint64>(kNone), static_cast<Uint64>(kWaitNone)},
{"SetProgramBindings", "MGPProgramBindings", static_cast<Uint64>(MGPWireOp::SetProgramBindings), static_cast<Uint64>(kVarTail | kHostSpan), static_cast<Uint64>(kWaitNone)},
{"DeleteStreamOutput", "MGPStreamOutputBind", static_cast<Uint64>(MGPWireOp::DeleteStreamOutput), static_cast<Uint64>(kNone), static_cast<Uint64>(kWaitNone)},
{"ReadPixelsToBuffer", "MGPReadbackToBuffer", static_cast<Uint64>(MGPWireOp::ReadPixelsToBuffer), static_cast<Uint64>(kNone), static_cast<Uint64>(kWaitNone)},
{"GetTextureImageToBuffer", "MGPReadbackToBuffer", static_cast<Uint64>(MGPWireOp::GetTextureImageToBuffer), static_cast<Uint64>(kNone), static_cast<Uint64>(kWaitNone)},
};