mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-18 07:23:24 +09:00
[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:
@@ -861,15 +861,23 @@ namespace MobileGL::MG_Remote::Client {
|
||||
ReadbackBytesPerPixel(format, type);
|
||||
}
|
||||
|
||||
void ApplyReadbackByteSwap(void* pixels, Uint64 bytes, GLenum type,
|
||||
const PixelStoreParameters& pack) {
|
||||
if (!pack.SwapBytes || pixels == nullptr) return;
|
||||
// GL_PACK_SWAP_BYTES as the width of the byte group it reverses for `type`, 0 when there
|
||||
// is nothing to reverse. One rule for both places a swap happens: the reply form swaps
|
||||
// here, and the pack-buffer form (P9) carries the number to the server, which swaps there.
|
||||
Uint32 ReadbackSwapGroup(GLenum type, const PixelStoreParameters& pack) {
|
||||
if (!pack.SwapBytes) return 0;
|
||||
const auto dataType = MG_Util::ConvertGLEnumToTexturePixelDataType(type);
|
||||
SizeT group = MG_Util::GetSizedTexturePixelDataTypeSize(dataType);
|
||||
if (group == 0) group = MG_Util::GetBaseTexturePixelDataTypeSize(dataType);
|
||||
// This packed depth/stencil type contains two independent 32-bit words.
|
||||
if (type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV) group = 4;
|
||||
if (group <= 1) return;
|
||||
return group <= 1 ? 0 : static_cast<Uint32>(group);
|
||||
}
|
||||
|
||||
void ApplyReadbackByteSwap(void* pixels, Uint64 bytes, GLenum type,
|
||||
const PixelStoreParameters& pack) {
|
||||
const SizeT group = ReadbackSwapGroup(type, pack);
|
||||
if (group == 0 || pixels == nullptr) return;
|
||||
auto* data = static_cast<Uint8*>(pixels);
|
||||
for (Uint64 at = 0; at + group <= bytes; at += group) {
|
||||
for (SizeT i = 0; i < group / 2; ++i) {
|
||||
@@ -963,6 +971,56 @@ namespace MobileGL::MG_Remote::Client {
|
||||
return;
|
||||
}
|
||||
|
||||
// One band's source record, the same for both destinations below.
|
||||
const auto bandInfo = [&](const ReadbackBand& band, Uint64 bandBytes) {
|
||||
MG_Pipe::MGPReadbackInfo info{};
|
||||
info.Res = MG_Pipe::kMGPipeNullHandle; // "the bound read surface answers"
|
||||
info.Box = MG_Pipe::MGPBox{ReadbackBandOrigin(x, band.FirstColumn),
|
||||
ReadbackBandOrigin(y, band.FirstRow), 0,
|
||||
static_cast<Uint32>(band.Columns),
|
||||
static_cast<Uint32>(band.Rows), 1};
|
||||
info.Format = static_cast<Uint32>(format);
|
||||
info.Type = static_cast<Uint32>(type);
|
||||
info.Target = 0;
|
||||
info.Level = 0;
|
||||
info.DstOffset = 0;
|
||||
info.DstSize = bandBytes;
|
||||
return info;
|
||||
};
|
||||
|
||||
// P9 (W1, CONTRACT-P9.md §1): A PACK BUFFER IS ANSWERED BY NOTHING. Each band crosses
|
||||
// as read_pixels_to_buffer naming the buffer and the band's place in it - the
|
||||
// layout above, per band - and the client neither waits nor copies: the server lands
|
||||
// the rows, and the mark (taken first, like every producer row's) is what sends the
|
||||
// next CPU read of the buffer through resource_readback. The bands are the reply
|
||||
// form's for the SERVER's sake, not the wire's: the server reads each one into its
|
||||
// scratch before landing it, and the reply cap is the bound it already enforces on
|
||||
// that scratch (PH-3). The monolith arm is untouched - it maps the driver PBO back
|
||||
// inside its own ReadPixels, as it always has.
|
||||
if (pbo) {
|
||||
const MG_Pipe::MGPipeHandle target = PackBufferReadbackTarget(pbo, pboOffset + layout.End);
|
||||
if (!MG_Pipe::MGPipeHandleIsNull(target)) {
|
||||
MarkReadPixelsPackBuffer();
|
||||
const Uint32 swapGroup = ReadbackSwapGroup(type, pack);
|
||||
ForEachReadbackBand(static_cast<Uint64>(width), static_cast<Uint64>(height), plan,
|
||||
[&](const ReadbackBand& band) {
|
||||
MG_Pipe::MGPReadbackToBuffer record{};
|
||||
record.Src = bandInfo(band, TightReadbackBytes(static_cast<GLsizei>(band.Columns),
|
||||
static_cast<GLsizei>(band.Rows),
|
||||
format, type));
|
||||
record.Dst = target;
|
||||
record.DstBase = pboOffset + layout.Start + band.FirstRow * layout.RowStride +
|
||||
band.FirstColumn * bytesPerPixel;
|
||||
record.RowStride = layout.RowStride;
|
||||
record.ImageStride = 0;
|
||||
record.SwapGroup = swapGroup;
|
||||
session.EmitAndWait(MG_Pipe::MGPWireOp::ReadPixelsToBuffer, &record,
|
||||
sizeof(record), nullptr, 0, nullptr, 0, nullptr);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// THE COMMON CASE KEEPS THE ZERO-COPY. A neutral pack state means the destination
|
||||
// layout IS the tight layout, so each band's reply lands straight in the
|
||||
// application's buffer at the band's tight offset (whole-width bands and single-row
|
||||
@@ -983,18 +1041,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
const Uint64 bandBytes = TightReadbackBytes(static_cast<GLsizei>(band.Columns),
|
||||
static_cast<GLsizei>(band.Rows),
|
||||
format, type);
|
||||
MG_Pipe::MGPReadbackInfo info{};
|
||||
info.Res = MG_Pipe::kMGPipeNullHandle; // "the bound read surface answers"
|
||||
info.Box = MG_Pipe::MGPBox{ReadbackBandOrigin(x, band.FirstColumn),
|
||||
ReadbackBandOrigin(y, band.FirstRow), 0,
|
||||
static_cast<Uint32>(band.Columns),
|
||||
static_cast<Uint32>(band.Rows), 1};
|
||||
info.Format = static_cast<Uint32>(format);
|
||||
info.Type = static_cast<Uint32>(type);
|
||||
info.Target = 0;
|
||||
info.Level = 0;
|
||||
info.DstOffset = 0;
|
||||
info.DstSize = bandBytes;
|
||||
MG_Pipe::MGPReadbackInfo info = bandInfo(band, bandBytes);
|
||||
|
||||
// CHECKED BEFORE THE EMISSION, not after the answer (ID-47), through S1's
|
||||
// helper, for every record. The plan makes it true by construction; it stays
|
||||
|
||||
@@ -253,6 +253,19 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// UnmigratedVerbFatal), and it is what gives the hole a red spelling before the
|
||||
// transport arrives.
|
||||
if (!buffer.HasOutstandingGpuWrite()) return;
|
||||
// P9 F1 (CONTRACT-P9.md §4): THE DEVICE WENT AWAY WITH THE WRITE STILL OWED. A lost device
|
||||
// DECLINES every record, so the readback that was to bring the GPU's bytes back was never
|
||||
// sent - and the shadow the caller is about to read holds whatever the buffer held BEFORE
|
||||
// the write (for a pack-buffer read, the bytes before the pixels). Returning it would be the
|
||||
// one outcome the reverse channel exists to prevent: stale bytes that look like a
|
||||
// successful read. It is the reply form's ReadbackDeclined, arriving one call later.
|
||||
if (ClientSession::DeviceLost()) {
|
||||
SessionFail(MGFatalFamily::ReadbackDeclined, "MGPipe: Fatal{ReadbackDeclined, \"buffer-writeback\"} - buffer %u "
|
||||
"still owes a GPU write (a pack-buffer read or a shader store) and the device is "
|
||||
"lost, so its readback was declined; its shadow holds the bytes from before the "
|
||||
"write and is not returned as the GPU's",
|
||||
buffer.GetExternalIndex());
|
||||
}
|
||||
SessionFail(MGFatalFamily::UnimplementedWritebackWait, "MGPipe: Fatal{UnimplementedWritebackWait} - a ClientSession is active and buffer %u "
|
||||
"still has an outstanding GPU write after its readback was emitted. The wait is "
|
||||
"ClientSession::EmitAndWait's (R-3: the reply slot id IS the record seq); P5 package "
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
// Included in EmitTables.cpp's client-only anonymous namespace.
|
||||
// The server returns owned tight pixels. Only the client interprets PACK state
|
||||
// and application pointers; PBO rows are ordinary buffer uploads after the reply.
|
||||
// and application pointers. A pack-buffer destination (P9) is answered by nothing: the
|
||||
// client sends the layout it computed and the server lands the rows in the buffer; the
|
||||
// reply form's "PBO rows are ordinary buffer uploads after the reply" remains the arm for
|
||||
// a buffer PackBufferReadbackTarget refuses.
|
||||
struct ReadbackLayout {
|
||||
Uint64 RowBytes = 0, RowStride = 0, ImageStride = 0, Start = 0, End = 0, Tight = 0;
|
||||
};
|
||||
@@ -41,6 +44,30 @@
|
||||
"Pixel packing exceeds the destination or its addressable range."));
|
||||
}
|
||||
|
||||
// P9 (W1, MG_Remote/CONTRACT-P9.md §1): MAY A READ INTO THIS PACK BUFFER GO WITHOUT A
|
||||
// REPLY? The answer is the buffer's handle when it may - the read then crosses as
|
||||
// read_pixels_to_buffer / get_texture_image_to_buffer, lands server-side, and the buffer
|
||||
// is marked GPU-written - and the null handle when the reply-slot form has to carry it.
|
||||
// `end` is the last byte past the application's offset the read touches.
|
||||
//
|
||||
// Each refusal is a case the mark cannot keep its promise in, not a preference:
|
||||
// - MOBILEGL_IPC_PBO_READBACK_SYNC=1, the A/B and red-once arm;
|
||||
// - no readback route (BufferWritebackIsReachable: no size, or the resource family
|
||||
// is not on the wire), so SyncGpuWrites would clear the mark with nothing fetched;
|
||||
// - a MAPPED buffer. Only a persistent mapping can be live across a read, and its
|
||||
// reader takes the bytes straight from the pointer through no call this side sees:
|
||||
// no SyncGpuWrites would ever run for it, and the pixels would never arrive;
|
||||
// - a range MGPSubData cannot name (a buffer offset stops at 2^31-1);
|
||||
// - a buffer that never crossed: it has no handle for the server to write into, and
|
||||
// the reply form's UploadSubData is what creates it.
|
||||
MG_Pipe::MGPipeHandle PackBufferReadbackTarget(const SharedPtr<MG_State::GLState::BufferObject>& pbo,
|
||||
Uint64 end) {
|
||||
if (!pbo || MG_Config::Ipc.PboReadbackSync != 0) return MG_Pipe::kMGPipeNullHandle;
|
||||
if (!BufferWritebackIsReachable(*pbo) || pbo->IsMapped()) return MG_Pipe::kMGPipeNullHandle;
|
||||
if (end > 0x7FFFFFFFull) return MG_Pipe::kMGPipeNullHandle;
|
||||
return MG_Pipe::MGPipeSlots().FindByLifetimeId(MG_Pipe::MGPipeKind::Buffer, pbo->GetLifetimeId());
|
||||
}
|
||||
|
||||
void EmitGetTextureImage(const SharedPtr<MG_State::GLState::ITextureObject>& texture,
|
||||
TextureUploadTarget uploadTarget, GLint level, GLenum format,
|
||||
GLenum type, GLsizei bufSize, void* pixels) {
|
||||
@@ -80,6 +107,29 @@
|
||||
info.Type = type;
|
||||
info.Target = wholeCube ? GL_TEXTURE_CUBE_MAP : MG_Util::ConvertTextureUploadTargetToGLEnum(uploadTarget);
|
||||
info.Level = static_cast<Uint16>(level);
|
||||
// P9 (W1): into a pack buffer, ONE record and no wait. The whole level crosses at
|
||||
// once - there is no reply slot to fit, and the server reads the whole level for
|
||||
// every window of the reply form anyway - and the rows land in the buffer at the
|
||||
// layout computed above. The mark goes first, like every producer row's: the set
|
||||
// describes the work the record is about to start.
|
||||
if (pbo) {
|
||||
const MG_Pipe::MGPipeHandle target = PackBufferReadbackTarget(pbo, pboOffset + layout.End);
|
||||
if (!MG_Pipe::MGPipeHandleIsNull(target)) {
|
||||
MarkReadPixelsPackBuffer();
|
||||
MG_Pipe::MGPReadbackToBuffer record{};
|
||||
record.Src = info;
|
||||
record.Src.DstOffset = 0;
|
||||
record.Src.DstSize = tight;
|
||||
record.Dst = target;
|
||||
record.DstBase = pboOffset + layout.Start;
|
||||
record.RowStride = layout.RowStride;
|
||||
record.ImageStride = layout.ImageStride;
|
||||
record.SwapGroup = ReadbackSwapGroup(type, pack);
|
||||
session.EmitAndWait(MG_Pipe::MGPWireOp::GetTextureImageToBuffer, &record,
|
||||
sizeof(record), nullptr, 0, nullptr, 0, nullptr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Vector<Uint8> bytes(static_cast<SizeT>(tight));
|
||||
const Uint64 capacity = session.MaxReplyBytes();
|
||||
if (!capacity) Wire::WireProtocolFatal("GetTextureImage.reply", "zero reply capacity");
|
||||
|
||||
@@ -393,14 +393,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
image.DstOffset = 0;
|
||||
image.DstSize = tight;
|
||||
Vector<Uint8> bytes;
|
||||
Bool ok = false;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (m_backend && m_backend->GetBackendType() == BackendType::DirectGLES)
|
||||
ok = MG_Backend::DirectGLES::ReadTextureImageWire(image, bytes);
|
||||
else if (m_backend && m_backend->GetBackendType() == BackendType::DirectVulkan &&
|
||||
MG_Backend::DirectVulkan::pVulkanRenderer)
|
||||
ok = MG_Backend::DirectVulkan::pVulkanRenderer->ReadTextureImageWire(image, bytes);
|
||||
#endif
|
||||
const Bool ok = ReadTextureImageTight(image, bytes);
|
||||
if (!ok || bytes.size() != tight) {
|
||||
replies->PostReply(seq, Wire::ReplySink::kStatusError, nullptr, 0);
|
||||
return false;
|
||||
@@ -470,13 +463,29 @@ namespace MobileGL::MG_Remote::Server {
|
||||
static_cast<unsigned long long>(bpp));
|
||||
}
|
||||
|
||||
const MG_Backend::GlobalBackendFunctionsTable* table = Table("read_pixels");
|
||||
if (table == nullptr || table->GL.ReadPixels == nullptr) {
|
||||
if (!ReadBoundFramebufferTight(info, tight)) {
|
||||
// A well-formed call can still be unsupported by this server; return the
|
||||
// established decline status after the peer-controlled size has been checked.
|
||||
replies->PostReply(seq, Wire::ReplySink::kStatusDeclined, nullptr, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
// m-7: the answer is written into the slot HERE, mid-apply, while the verb stamp is still
|
||||
// up - and that is safe for exactly one reason, which is the contract's and is stated so it
|
||||
// is not mistaken for luck: the client reaches a reply slot ONLY through appliedSeq
|
||||
// (ReplySlot.h's ORDERING clause), never by polling the slot's own stamp, and s1's
|
||||
// SessionConsumer::ApplyOne publishes appliedSeq only AFTER PipeApplier::ApplyOne has run
|
||||
// LeaveApplier() and (on the joint tree) dropped the ScopedApplierEntry. So by the time the
|
||||
// client is allowed to look at this slot, the apply-side gPipeInputs flag is already down.
|
||||
replies->PostReply(seq, Wire::ReplySink::kStatusOk, m_readbackScratch.data(), tight);
|
||||
m_readbackBytes += tight;
|
||||
++m_readbacks;
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool ServerVerbSink::ReadBoundFramebufferTight(const MG_Pipe::MGPReadbackInfo& info, Uint64 tight) {
|
||||
const MG_Backend::GlobalBackendFunctionsTable* table = Table("read_pixels");
|
||||
if (table == nullptr || table->GL.ReadPixels == nullptr) return false;
|
||||
if (tight > m_readbackScratch.size()) {
|
||||
m_readbackScratch.resize(static_cast<SizeT>(tight));
|
||||
}
|
||||
@@ -501,20 +510,183 @@ namespace MobileGL::MG_Remote::Server {
|
||||
MG_Pipe::MGPPixelPackState restorePack{};
|
||||
restorePack.Pack = savedPack;
|
||||
MG_Pipe::MGPipeApplySetPixelPackState(restorePack);
|
||||
|
||||
// m-7: the answer is written into the slot HERE, mid-apply, while the verb stamp is still
|
||||
// up - and that is safe for exactly one reason, which is the contract's and is stated so it
|
||||
// is not mistaken for luck: the client reaches a reply slot ONLY through appliedSeq
|
||||
// (ReplySlot.h's ORDERING clause), never by polling the slot's own stamp, and s1's
|
||||
// SessionConsumer::ApplyOne publishes appliedSeq only AFTER PipeApplier::ApplyOne has run
|
||||
// LeaveApplier() and (on the joint tree) dropped the ScopedApplierEntry. So by the time the
|
||||
// client is allowed to look at this slot, the apply-side gPipeInputs flag is already down.
|
||||
replies->PostReply(seq, Wire::ReplySink::kStatusOk, m_readbackScratch.data(), tight);
|
||||
m_readbackBytes += tight;
|
||||
++m_readbacks;
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool ServerVerbSink::ReadTextureImageTight(const MG_Pipe::MGPReadbackInfo& image, Vector<Uint8>& bytes) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (m_backend && m_backend->GetBackendType() == BackendType::DirectGLES)
|
||||
return MG_Backend::DirectGLES::ReadTextureImageWire(image, bytes);
|
||||
if (m_backend && m_backend->GetBackendType() == BackendType::DirectVulkan &&
|
||||
MG_Backend::DirectVulkan::pVulkanRenderer)
|
||||
return MG_Backend::DirectVulkan::pVulkanRenderer->ReadTextureImageWire(image, bytes);
|
||||
#endif
|
||||
(void)image;
|
||||
(void)bytes;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---- P9 (W1, MG_Remote/CONTRACT-P9.md §1): the pack-buffer readbacks ------------------------
|
||||
//
|
||||
// WHY THE ROWS GO THROUGH THE APPLIER'S BUFFER-WRITE GATE AND NOT THROUGH THE DRIVER'S OWN
|
||||
// PBO READ. Monolith binds the driver buffer as GL_PIXEL_PACK_BUFFER and lets glReadPixels
|
||||
// write it, then maps the whole store back into the frontend shadow (DirectGLES.cpp's
|
||||
// "PBO used, mapping buffer to client memory"). A server has two stores per buffer - the
|
||||
// backend's (GL buffer / VkBuffer) and R-11's staged shadow that every later drain uploads
|
||||
// from - and a driver-side write reaches only the first: the next queued range drained from
|
||||
// the shadow would then land OLD bytes over the pixels on Espryt, and Magma has no pack path
|
||||
// in its ReadPixels at all. MGPipeApplyResourceSubData is the one write both backends already
|
||||
// take from the server (Ops_H_SubData adopts into the staged shadow and queues the range;
|
||||
// WriteWireBuffer orders the copy against in-flight reads), so the rows are exactly what a
|
||||
// client glBufferSubData of the same bytes would have been - same serial bump, same epoch
|
||||
// bump, same ordering against the records that follow.
|
||||
//
|
||||
// THE READ IS THE REPLY FORM'S, byte for byte (ReadBoundFramebufferTight /
|
||||
// ReadTextureImageTight), so the two forms cannot disagree about what a pixel is; only the
|
||||
// destination moved. The PACK layout is the client's arithmetic (ReadbackLayout) carried in
|
||||
// the record, and the byte swap is applied to the tight bytes first, exactly where the client
|
||||
// applied it to its reply.
|
||||
//
|
||||
// A FAILED READ IS LOUD. The reply form's failures reach the client as ERROR / DECLINED and
|
||||
// end in a named Fatal there (RequireReadbackReplyComplete: "a blocking readback has no pixels
|
||||
// to return"); this form has no reply to carry them, and a pack buffer left holding its old
|
||||
// bytes is the same silently wrong answer. So the refusal latches here, under the same family
|
||||
// words.
|
||||
|
||||
Bool ServerVerbSink::LandReadbackInBuffer(const MG_Pipe::MGPReadbackToBuffer& record, Uint8* tight,
|
||||
Uint64 bytesPerPixel, const char* call) {
|
||||
const MG_Pipe::MGPBox& box = record.Src.Box;
|
||||
const Uint64 rowBytes = static_cast<Uint64>(box.W) * bytesPerPixel;
|
||||
const Uint64 rows = box.H;
|
||||
const Uint64 images = box.D;
|
||||
const Uint64 tightBytes = rowBytes * rows * images; // the caller proved this fits
|
||||
if (record.RowStride < rowBytes || (images > 1 && record.ImageStride < record.RowStride)) {
|
||||
return SessionLatch(MGFatalFamily::ProtocolCorruption, "MGPipe: Fatal{ProtocolCorruption, \"%s.layout\"} row stride %llu "
|
||||
"is narrower than a tight row (%llu) or image stride %llu narrower than a row; the "
|
||||
"client's ReadbackLayout never produces either",
|
||||
call, static_cast<unsigned long long>(record.RowStride),
|
||||
static_cast<unsigned long long>(rowBytes),
|
||||
static_cast<unsigned long long>(record.ImageStride));
|
||||
}
|
||||
if (record.SwapGroup != 0) {
|
||||
const Uint64 group = record.SwapGroup;
|
||||
if (group != 2 && group != 4 && group != 8) {
|
||||
return SessionLatch(MGFatalFamily::ProtocolCorruption, "MGPipe: Fatal{ProtocolCorruption, \"%s.SwapGroup\"} %llu is "
|
||||
"not a byte group GL_PACK_SWAP_BYTES can reverse (2, 4 or 8)",
|
||||
call, static_cast<unsigned long long>(group));
|
||||
}
|
||||
for (Uint64 at = 0; at + group <= tightBytes; at += group) {
|
||||
for (Uint64 i = 0; i < group / 2; ++i) std::swap(tight[at + i], tight[at + group - 1 - i]);
|
||||
}
|
||||
}
|
||||
|
||||
// ONE WRITE PER CONTIGUOUS RUN: the whole read when the layout is tight (the common
|
||||
// case - a neutral pack state, or an image-packed read of whole images), one per image
|
||||
// when only the rows are tight, one per row otherwise. The bytes between rows are the
|
||||
// application's (GL_PACK_ROW_LENGTH / ALIGNMENT padding) and are never written.
|
||||
const Bool rowsTight = record.RowStride == rowBytes;
|
||||
const Bool imagesTight = images == 1 || record.ImageStride == rowBytes * rows;
|
||||
const Uint64 runBytes = rowsTight ? (imagesTight ? tightBytes : rowBytes * rows) : rowBytes;
|
||||
const Uint64 runsPerImage = rowsTight ? 1 : rows;
|
||||
const Uint64 imageRuns = rowsTight && imagesTight ? 1 : images;
|
||||
constexpr Uint64 kUint64Max = std::numeric_limits<Uint64>::max();
|
||||
for (Uint64 z = 0; z < imageRuns; ++z) {
|
||||
for (Uint64 r = 0; r < runsPerImage; ++r) {
|
||||
// DstBase + z * ImageStride + r * RowStride, checked: a peer can write any
|
||||
// three numbers, and a wrapped offset would name bytes the range gate below
|
||||
// then accepts.
|
||||
if ((z != 0 && record.ImageStride > (kUint64Max - record.DstBase) / z) ||
|
||||
(r != 0 && record.RowStride > kUint64Max / r)) {
|
||||
return Wire::WireProtocolLatch(call, "destination offset overflows");
|
||||
}
|
||||
const Uint64 imageBase = record.DstBase + z * record.ImageStride;
|
||||
if (r * record.RowStride > kUint64Max - imageBase) {
|
||||
return Wire::WireProtocolLatch(call, "destination offset overflows");
|
||||
}
|
||||
const Uint64 offset = imageBase + r * record.RowStride;
|
||||
MG_Pipe::MGPSubData write{};
|
||||
write.Res = record.Dst;
|
||||
write.Target = MG_Pipe::kMGPipeResourceTargetBuffer;
|
||||
// HasLiveHostWrites stays 0 and that is the client's fact, not a default: the
|
||||
// client takes this form only for a pack buffer it does not map (EmitTables.cpp,
|
||||
// PackBufferReadbackIsAsync), so "no live host writer" is what a glBufferSubData
|
||||
// of the same bytes would have said.
|
||||
if (!MG_Pipe::MGPipeSetSubDataBufferRange(write, offset, runBytes)) {
|
||||
return Wire::WireProtocolLatchAt(call, offset, 0x7FFFFFFFull);
|
||||
}
|
||||
const Uint8* bytes = tight + (z * runsPerImage + r) * runBytes;
|
||||
++m_bufferReadbackWrites;
|
||||
// The acceptance is the applier's (a dead handle is a counted no-op, a range
|
||||
// past the store a trip wire), so a refused write ends the landing here.
|
||||
if (!MG_Pipe::MGPipeApplyResourceSubData(write, bytes, nullptr)) return false;
|
||||
}
|
||||
}
|
||||
++m_bufferReadbacks;
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool ServerVerbSink::OnReadPixelsToBuffer(const MG_Pipe::MGPReadbackToBuffer& record) {
|
||||
const MG_Pipe::MGPReadbackInfo& info = record.Src;
|
||||
const Uint64 bpp = static_cast<Uint64>(MG_Util::GetInputBytesPerPixel(
|
||||
MG_Util::ConvertGLEnumToTextureInputFormat(static_cast<GLenum>(info.Format)),
|
||||
MG_Util::ConvertGLEnumToTexturePixelDataType(static_cast<GLenum>(info.Type))));
|
||||
// The reply form's shape checks, and its PH-3 bound: the scratch is sized from the
|
||||
// record, so the SERVER's own maxReplyBytes caps it exactly as it caps an answer - the
|
||||
// client bands this form by the same number (PlanReadbackBands), so no correct client
|
||||
// is refused by it.
|
||||
if (bpp == 0 || info.Box.W == 0 || info.Box.H == 0 || info.Box.D != 1 ||
|
||||
info.Box.W > static_cast<Uint32>(std::numeric_limits<GLsizei>::max()) ||
|
||||
info.Box.H > static_cast<Uint32>(std::numeric_limits<GLsizei>::max())) {
|
||||
return Wire::WireProtocolLatch("ReadPixelsToBuffer.extent", "invalid read box or format");
|
||||
}
|
||||
constexpr Uint64 kUint64Max = std::numeric_limits<Uint64>::max();
|
||||
const Uint64 width = info.Box.W;
|
||||
const Uint64 height = info.Box.H;
|
||||
if (width > kUint64Max / height || width * height > kUint64Max / bpp) {
|
||||
return Wire::WireProtocolLatch("ReadPixelsToBuffer.extent", "tight extent overflows");
|
||||
}
|
||||
const Uint64 tight = width * height * bpp;
|
||||
if (m_maxReplyBytes == 0 || tight > m_maxReplyBytes ||
|
||||
tight > static_cast<Uint64>(std::numeric_limits<SizeT>::max())) {
|
||||
return Wire::WireProtocolLatchAt("ReadPixelsToBuffer.extent", tight, m_maxReplyBytes);
|
||||
}
|
||||
if (info.DstOffset != 0 || info.DstSize != tight) {
|
||||
return Wire::WireProtocolLatchAt("ReadPixelsToBuffer.Src.DstSize", info.DstSize, tight);
|
||||
}
|
||||
if (!ReadBoundFramebufferTight(info, tight)) {
|
||||
return SessionLatch(MGFatalFamily::ReadbackDeclined, "MGPipe: Fatal{ReadbackDeclined, \"ReadPixelsToBuffer\"} - the server "
|
||||
"has no GL.ReadPixels; the pack buffer would keep bytes the application is "
|
||||
"about to read as pixels, and there is no reply to carry the decline");
|
||||
}
|
||||
return LandReadbackInBuffer(record, m_readbackScratch.data(), bpp, "ReadPixelsToBuffer");
|
||||
}
|
||||
|
||||
Bool ServerVerbSink::OnGetTextureImageToBuffer(const MG_Pipe::MGPReadbackToBuffer& record) {
|
||||
const MG_Pipe::MGPReadbackInfo& info = record.Src;
|
||||
const Uint64 bpp = static_cast<Uint64>(MG_Util::GetInputBytesPerPixel(
|
||||
MG_Util::ConvertGLEnumToTextureInputFormat(info.Format),
|
||||
MG_Util::ConvertGLEnumToTexturePixelDataType(info.Type)));
|
||||
if (!bpp || !info.Box.W || !info.Box.H || !info.Box.D || info.Box.X || info.Box.Y || info.Box.Z) {
|
||||
return Wire::WireProtocolLatch("GetTextureImageToBuffer.extent", "invalid tight image extent");
|
||||
}
|
||||
const Uint64 tight = static_cast<Uint64>(info.Box.W) * info.Box.H * info.Box.D * bpp;
|
||||
if (tight / bpp / info.Box.W / info.Box.H != info.Box.D) {
|
||||
return Wire::WireProtocolLatch("GetTextureImageToBuffer.extent", "tight extent overflows");
|
||||
}
|
||||
if (info.DstOffset != 0 || info.DstSize != tight) {
|
||||
return Wire::WireProtocolLatchAt("GetTextureImageToBuffer.Src.DstSize", info.DstSize, tight);
|
||||
}
|
||||
Vector<Uint8> bytes;
|
||||
if (!ReadTextureImageTight(info, bytes) || bytes.size() != tight) {
|
||||
return SessionLatch(MGFatalFamily::ReplyError, "MGPipe: Fatal{ReplyError, \"GetTextureImageToBuffer\"} - the level "
|
||||
"could not be read (%llu of %llu bytes); the reply form answers ERROR here, and "
|
||||
"this form has no reply to carry it",
|
||||
static_cast<unsigned long long>(bytes.size()),
|
||||
static_cast<unsigned long long>(tight));
|
||||
}
|
||||
return LandReadbackInBuffer(record, bytes.data(), bpp, "GetTextureImageToBuffer");
|
||||
}
|
||||
|
||||
// P5b's server-side stub shape (CONTRACT-P5B.md): the same line the client's class-C table
|
||||
// raises (EmitTables.cpp UnmigratedVerbFatal) and the same family the census greps, so a
|
||||
// slot flipped on the client ahead of its server half aborts BY NAME on the apply thread
|
||||
|
||||
@@ -173,6 +173,10 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Wire::ReplySink* replies) override;
|
||||
Bool OnGetTextureImage(const MG_Pipe::MGPReadbackInfo& info, Uint64 seq,
|
||||
Wire::ReplySink* replies) override;
|
||||
// P9 (CONTRACT-P9.md §1): the pack-buffer halves. Nothing is answered; the tight pixels
|
||||
// land in record.Dst through the applier's buffer-write gate.
|
||||
Bool OnReadPixelsToBuffer(const MG_Pipe::MGPReadbackToBuffer& record) override;
|
||||
Bool OnGetTextureImageToBuffer(const MG_Pipe::MGPReadbackToBuffer& record) override;
|
||||
Bool OnDrawVbo(const MG_Pipe::MGPDrawInfo& info, const MG_Pipe::MGPDrawRange* ranges,
|
||||
const MG_Pipe::MGHostSpan* userIndices,
|
||||
const MG_Pipe::MGPDrawIndirect* indirect) override;
|
||||
@@ -247,6 +251,10 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Uint64 Presents() const { return m_presents; }
|
||||
Uint64 LastPresentSerial() const { return m_lastPresentSerial; }
|
||||
Uint64 ReadbackBytes() const { return m_readbackBytes; }
|
||||
// P9: pack-buffer readbacks that landed in their buffer (both ops), and the buffer-write
|
||||
// records they took. Readbacks() above counts only the reply-slot form.
|
||||
Uint64 BufferReadbacks() const { return m_bufferReadbacks; }
|
||||
Uint64 BufferReadbackWrites() const { return m_bufferReadbackWrites; }
|
||||
// ---- P5b package i1's tallies. R-16: a probe may not arm against a stub, and on a
|
||||
// split build "the scenario passed" is also what a scenario that never left the
|
||||
// monolith path looks like - so the lane asserts the number that only this sink can
|
||||
@@ -294,6 +302,18 @@ namespace MobileGL::MG_Remote::Server {
|
||||
private:
|
||||
const MG_Backend::GlobalBackendFunctionsTable* Table(const char* verb) const;
|
||||
|
||||
// read_pixels' read, shared by the reply form and the pack-buffer form: the bound read
|
||||
// framebuffer, NEUTRAL pack state (ID-49), `tight` bytes into m_readbackScratch. False
|
||||
// when this server has no GL.ReadPixels - the caller owns what that means.
|
||||
Bool ReadBoundFramebufferTight(const MG_Pipe::MGPReadbackInfo& info, Uint64 tight);
|
||||
// get_texture_image's read, shared the same way: the whole level into `bytes`.
|
||||
Bool ReadTextureImageTight(const MG_Pipe::MGPReadbackInfo& image, Vector<Uint8>& bytes);
|
||||
// P9: `tight` holds Src's pixels, tightly packed; land them in record.Dst at the
|
||||
// record's layout through MGPipeApplyResourceSubData, one write per contiguous run.
|
||||
// `call` names the op in a refusal.
|
||||
Bool LandReadbackInBuffer(const MG_Pipe::MGPReadbackToBuffer& record, Uint8* tight,
|
||||
Uint64 bytesPerPixel, const char* call);
|
||||
|
||||
struct FenceEntry {
|
||||
Uint32 Gen = 0;
|
||||
Bool Live = false;
|
||||
@@ -321,6 +341,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Uint64 m_presents = 0;
|
||||
Uint64 m_lastPresentSerial = 0;
|
||||
Uint64 m_readbackBytes = 0;
|
||||
Uint64 m_bufferReadbacks = 0;
|
||||
Uint64 m_bufferReadbackWrites = 0;
|
||||
Uint64 m_imageBinds = 0;
|
||||
Uint64 m_dispatches = 0;
|
||||
Uint64 m_memoryBarriers = 0;
|
||||
|
||||
@@ -261,7 +261,9 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
X(ObjectDeath, MGPHandleOnly) \
|
||||
X(SetContextValues, MGPContextValues) \
|
||||
X(SetProgramBindings, MGPProgramBindings) \
|
||||
X(DeleteStreamOutput, MGPStreamOutputBind)
|
||||
X(DeleteStreamOutput, MGPStreamOutputBind) \
|
||||
X(ReadPixelsToBuffer, MGPReadbackToBuffer) \
|
||||
X(GetTextureImageToBuffer, MGPReadbackToBuffer)
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -2461,6 +2463,17 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
case MGPWireOp::DeleteStreamOutput:
|
||||
return m_verbs && m_verbs->OnDeleteStreamOutput(*static_cast<const MGPStreamOutputBind*>(payload));
|
||||
|
||||
// P9 (CONTRACT-P9.md §1): the pack-buffer readbacks. No reply sink on purpose - the
|
||||
// destination is a resource handle and nothing is answered - so a sink that wanted
|
||||
// one could only be reading the wrong row.
|
||||
case MGPWireOp::ReadPixelsToBuffer:
|
||||
return m_verbs != nullptr &&
|
||||
m_verbs->OnReadPixelsToBuffer(*static_cast<const MGPReadbackToBuffer*>(payload));
|
||||
|
||||
case MGPWireOp::GetTextureImageToBuffer:
|
||||
return m_verbs != nullptr &&
|
||||
m_verbs->OnGetTextureImageToBuffer(*static_cast<const MGPReadbackToBuffer*>(payload));
|
||||
|
||||
case MGPWireOp::SetStorageBlockBinding: {
|
||||
// The block name is the ONE string on the wire (CONTRACT-P5B.md i1): a kHasBlob
|
||||
// record whose blob is the NUL-terminated name, Size = strlen + 1, staged whole in
|
||||
|
||||
@@ -543,6 +543,10 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
virtual Bool OnGetTextureImage(const MG_Pipe::MGPReadbackInfo&, Uint64, ReplySink*) {
|
||||
return false;
|
||||
}
|
||||
// P9 (CONTRACT-P9.md §1): the same two reads with a pack buffer as the destination. No
|
||||
// seq and no sink - nothing is answered; the rows land in `Dst` on this side.
|
||||
virtual Bool OnReadPixelsToBuffer(const MG_Pipe::MGPReadbackToBuffer&) { return false; }
|
||||
virtual Bool OnGetTextureImageToBuffer(const MG_Pipe::MGPReadbackToBuffer&) { return false; }
|
||||
// `ranges` is info.NumDraws entries. `userIndices` is null unless the record set
|
||||
// kDrawHasUserIndices; `indirect` is null unless it set kDrawIsIndirect (P5b d1,
|
||||
// CONTRACT-P5B.md). The layout refuses a record that sets both, so at most one of the
|
||||
|
||||
Reference in New Issue
Block a user