mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-18 23:43:23 +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:
@@ -330,7 +330,10 @@ TEST_F(FieldOwnershipTest, VerbBoundaryOpsCoverEveryVerbShapedCall) {
|
||||
EXPECT_EQ(MGPipeVerbForWireOp(MGPWireOp::QueryCounter), MGPipeVerb::QueryCounterTimestamp);
|
||||
EXPECT_EQ(MGPipeVerbForWireOp(MGPWireOp::QueryTimestamp), MGPipeVerb::GetGpuTimestampNs);
|
||||
EXPECT_EQ(MGPipeVerbForWireOp(MGPWireOp::DeleteStreamOutput), MGPipeVerb::DeleteTransformFeedback);
|
||||
EXPECT_EQ(kMGPipeVerbBoundaryOpCount, SizeT{32});
|
||||
// P9: the pack-buffer halves stamp as the verbs they reproduce.
|
||||
EXPECT_EQ(MGPipeVerbForWireOp(MGPWireOp::ReadPixelsToBuffer), MGPipeVerb::ReadPixels);
|
||||
EXPECT_EQ(MGPipeVerbForWireOp(MGPWireOp::GetTextureImageToBuffer), MGPipeVerb::GetTextureImage);
|
||||
EXPECT_EQ(kMGPipeVerbBoundaryOpCount, SizeT{34});
|
||||
EXPECT_EQ(kMGPipeVerbBoundaryExemptCount, SizeT{3});
|
||||
|
||||
// Present is class B (it is emitted in P5) and is STILL not a verb boundary:
|
||||
|
||||
@@ -152,11 +152,12 @@ TEST(PipeCatalogue, GeneratedTablesHoldTheWholeCatalogue) {
|
||||
EXPECT_EQ(ClassCount<kCtxQuery>(), 8u);
|
||||
EXPECT_EQ(ClassCount<kCtxCso>(), 13u);
|
||||
EXPECT_EQ(ClassCount<kCtxState>(), 19u);
|
||||
EXPECT_EQ(ClassCount<kCtxObject>(), 10u);
|
||||
// + P9's get_texture_image_to_buffer (MG_Remote/CONTRACT-P9.md §1), beside get_texture_image.
|
||||
EXPECT_EQ(ClassCount<kCtxObject>(), 11u);
|
||||
// 13 + the five P5b-appended verbs (MG_Remote/CONTRACT-P5B.md): bind_shader_image,
|
||||
// patch_parameter, bind_stream_output, set_storage_block_binding,
|
||||
// copy_framebuffer_to_texture.
|
||||
EXPECT_EQ(ClassCount<kCtxVerb>(), 19u);
|
||||
// copy_framebuffer_to_texture; + delete_stream_output; + P9's read_pixels_to_buffer.
|
||||
EXPECT_EQ(ClassCount<kCtxVerb>(), 20u);
|
||||
}
|
||||
|
||||
// A row nobody has migrated is null - which is exactly what "this subsystem has not been
|
||||
@@ -639,7 +640,14 @@ TEST(PipeCatalogue, LateArrivalsAreAppendedWithoutRenumbering) {
|
||||
// exactly as set_shader_buffers has sat catalogued-and-dead since P4a.
|
||||
EXPECT_EQ(static_cast<Uint16>(MGPWireOp::SetProgramBindings), 80);
|
||||
EXPECT_EQ(static_cast<Uint16>(MGPWireOp::DeleteStreamOutput), 81);
|
||||
EXPECT_EQ(static_cast<Uint16>(MGPWireOp::kOpCount), 82);
|
||||
// P9 (MG_Remote/CONTRACT-P9.md §1) appended the two pack-buffer readbacks, by the same rule:
|
||||
// opcodes 82..83, one payload, no flag at all - no reply slot, no blob, no tail.
|
||||
EXPECT_EQ(static_cast<Uint16>(MGPWireOp::ReadPixelsToBuffer), 82);
|
||||
EXPECT_EQ(static_cast<Uint16>(MGPWireOp::GetTextureImageToBuffer), 83);
|
||||
EXPECT_EQ(static_cast<Uint16>(MGPWireOp::kOpCount), 84);
|
||||
EXPECT_EQ(MGPipeCallFlagsFor(MGPWireOp::ReadPixelsToBuffer), static_cast<Uint32>(kNone));
|
||||
EXPECT_EQ(MGPipeCallFlagsFor(MGPWireOp::GetTextureImageToBuffer), static_cast<Uint32>(kNone));
|
||||
EXPECT_EQ(sizeof(MGPReadbackToBuffer), 104u);
|
||||
EXPECT_EQ(MGPipeCallFlagsFor(MGPWireOp::SetProgramBindings),
|
||||
static_cast<Uint32>(kVarTail | kHostSpan));
|
||||
EXPECT_EQ(MGPipeCallFlagsFor(MGPWireOp::ApplierReset), static_cast<Uint32>(kNone));
|
||||
@@ -792,6 +800,8 @@ TEST(PipeCatalogue, EveryRowCarriesTheWaitClassTheContractGivesIt) {
|
||||
MGPWireOp::SetProgramBindings, MGPWireOp::SetShaderBuffers,
|
||||
MGPWireOp::SetVertexBuffers, MGPWireOp::SetFramebufferState,
|
||||
MGPWireOp::CreateShaderState, MGPWireOp::SetDrawProgram,
|
||||
// P9: the pack-buffer readbacks - the point of the two rows is that nothing waits.
|
||||
MGPWireOp::ReadPixelsToBuffer, MGPWireOp::GetTextureImageToBuffer,
|
||||
};
|
||||
for (const MGPWireOp op : noneRows) {
|
||||
EXPECT_EQ(MGPipeWaitClassFor(op), kWaitNone) << WireOpNameForDiag(op);
|
||||
@@ -1025,8 +1035,9 @@ TEST(PipeCatalogue, SixValueStructsHaveFieldLists) {
|
||||
// the two TAIL ELEMENT types beside it, MGPProgramSamplerUnit and MGPProgramStorageOverride
|
||||
// (MG_Remote/CONTRACT-P5E.md §1) - the tails are listed for the same reason MGPBufferRange
|
||||
// and MGPVertexAttribWire are: the comparator has to see INTO an element whose members
|
||||
// include an MGHostSpan and a pad word, or it would memcmp the padding: 82.
|
||||
EXPECT_EQ(kMGPipeVerifiedPayloadCount, 82u);
|
||||
// include an MGHostSpan and a pad word, or it would memcmp the padding: 82. P9 appended the
|
||||
// pack-buffer readbacks' one payload, MGPReadbackToBuffer (CONTRACT-P9.md §1): 83.
|
||||
EXPECT_EQ(kMGPipeVerifiedPayloadCount, 83u);
|
||||
static_assert(MGPipeHasFieldVerifier<RenderStateParameters>::value);
|
||||
static_assert(MGPipeHasFieldVerifier<PixelStoreParameters>::value);
|
||||
static_assert(MGPipeHasFieldVerifier<PerBufferBlendState>::value);
|
||||
|
||||
@@ -277,6 +277,20 @@ namespace {
|
||||
FramebufferCopies.push_back(copy);
|
||||
return true;
|
||||
}
|
||||
// P9 (CONTRACT-P9.md §1): the pack-buffer readbacks, one recorder for both rows and
|
||||
// the op each arrived through, so a swapped dispatch arm is visible.
|
||||
Bool OnReadPixelsToBuffer(const MGPReadbackToBuffer& record) override {
|
||||
BufferReadbacks.push_back(record);
|
||||
BufferReadbackOps.push_back(MGPWireOp::ReadPixelsToBuffer);
|
||||
return true;
|
||||
}
|
||||
Bool OnGetTextureImageToBuffer(const MGPReadbackToBuffer& record) override {
|
||||
BufferReadbacks.push_back(record);
|
||||
BufferReadbackOps.push_back(MGPWireOp::GetTextureImageToBuffer);
|
||||
return true;
|
||||
}
|
||||
std::vector<MGPReadbackToBuffer> BufferReadbacks;
|
||||
std::vector<MGPWireOp> BufferReadbackOps;
|
||||
// ---- P5c's rows (CONTRACT-P5C.md §5): the two control records, recorded the same
|
||||
// way so a round trip asserts the arm and the record intact.
|
||||
Bool OnApplierReset(const MGPApplierReset& reset) override {
|
||||
@@ -1635,6 +1649,50 @@ TEST_F(PipeWireCodecTest, CopyFramebufferToTextureReachesTheSinkForBothForms) {
|
||||
EXPECT_EQ(wire.Sink().FramebufferCopies[1].Width, 64);
|
||||
}
|
||||
|
||||
// P9 (CONTRACT-P9.md §1): both pack-buffer rows reach their own sink arm with the record
|
||||
// intact, and neither takes a reply slot - the decoder hands no seq and no sink, and the
|
||||
// reply-slot readback counter the reply form moves stays at zero.
|
||||
TEST_F(PipeWireCodecTest, PackBufferReadbacksReachTheirOwnArmsAndPostNoReply) {
|
||||
Wire2 wire;
|
||||
MGPReadbackToBuffer pixels{};
|
||||
pixels.Src.Box = MGPBox{3, 5, 0, 16, 8, 1};
|
||||
pixels.Src.Format = 0x1908; // GL_RGBA
|
||||
pixels.Src.Type = 0x1401; // GL_UNSIGNED_BYTE
|
||||
pixels.Src.DstSize = 16u * 8u * 4u;
|
||||
pixels.Dst = MakeHandle(41);
|
||||
pixels.DstBase = 12;
|
||||
pixels.RowStride = 80;
|
||||
pixels.SwapGroup = 0;
|
||||
MGPReadbackToBuffer image = pixels;
|
||||
image.Src.Res = MakeHandle(7);
|
||||
image.Src.Box = MGPBox{0, 0, 0, 4, 4, 6};
|
||||
image.Src.Target = 0x8513; // GL_TEXTURE_CUBE_MAP
|
||||
image.Src.DstSize = 4u * 4u * 6u * 4u;
|
||||
image.ImageStride = 4u * 80u;
|
||||
image.SwapGroup = 4;
|
||||
ASSERT_NE(wire.Encoder().EncodeRecord(MGPWireOp::ReadPixelsToBuffer, &pixels, sizeof(pixels)),
|
||||
kInvalidSeq);
|
||||
ASSERT_NE(wire.Encoder().EncodeRecord(MGPWireOp::GetTextureImageToBuffer, &image, sizeof(image)),
|
||||
kInvalidSeq);
|
||||
bool applied = false;
|
||||
ASSERT_TRUE(wire.PumpOne(&applied));
|
||||
EXPECT_TRUE(applied);
|
||||
ASSERT_TRUE(wire.PumpOne(&applied));
|
||||
EXPECT_TRUE(applied);
|
||||
ASSERT_EQ(wire.Sink().BufferReadbacks.size(), 2u);
|
||||
EXPECT_EQ(wire.Sink().BufferReadbackOps[0], MGPWireOp::ReadPixelsToBuffer);
|
||||
EXPECT_EQ(wire.Sink().BufferReadbackOps[1], MGPWireOp::GetTextureImageToBuffer);
|
||||
EXPECT_EQ(wire.Sink().BufferReadbacks[0].Dst.Slot, pixels.Dst.Slot);
|
||||
EXPECT_EQ(wire.Sink().BufferReadbacks[0].Src.Box.X, 3);
|
||||
EXPECT_EQ(wire.Sink().BufferReadbacks[0].DstBase, 12u);
|
||||
EXPECT_EQ(wire.Sink().BufferReadbacks[0].RowStride, 80u);
|
||||
EXPECT_EQ(wire.Sink().BufferReadbacks[1].Src.Res.Slot, image.Src.Res.Slot);
|
||||
EXPECT_EQ(wire.Sink().BufferReadbacks[1].Src.Box.D, 6u);
|
||||
EXPECT_EQ(wire.Sink().BufferReadbacks[1].ImageStride, 320u);
|
||||
EXPECT_EQ(wire.Sink().BufferReadbacks[1].SwapGroup, 4u);
|
||||
EXPECT_TRUE(wire.Sink().Readbacks.empty()) << "a pack-buffer read reached the reply-slot arm";
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
// CreateShaderState's seven blobs
|
||||
// =====================================================================================
|
||||
|
||||
@@ -869,6 +869,65 @@ TEST(RemoteClientControls, DeviceLostRespecifyDoesNotDieOfTheUncarriedBytesCheck
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
// P9 F1 (CONTRACT-P9.md §4): the device is lost with a pack-buffer read still owed
|
||||
// =====================================================================================
|
||||
//
|
||||
// A glReadPixels into a pack buffer is answered by nothing (read_pixels_to_buffer) and marks the
|
||||
// buffer GPU-written; the bytes arrive only when a CPU read fetches them. If the server dies in
|
||||
// between, that fetch is DECLINED - and the client shadow still holds what the buffer held
|
||||
// before the read. The peer below plays a server that took the read and died before landing
|
||||
// it: it counts the record and writes nothing. The map that follows must end BY NAME, never
|
||||
// hand the old bytes back as pixels.
|
||||
//
|
||||
// THE REDS, RUN ONCE: with MOBILEGL_IPC_PBO_READBACK_SYNC=1 the read takes the reply form, the
|
||||
// peer sees no pack-buffer record and the child exits 151; without AwaitBufferWriteback's
|
||||
// device-lost arm the child still aborts, but as Fatal{UnimplementedWritebackWait}, which names
|
||||
// a missing wait rather than a lost device.
|
||||
struct PackReadPeer : Codec::WireVerbSink {
|
||||
std::atomic<Uint32> packReads{0};
|
||||
Bool OnReadPixelsToBuffer(const MGPReadbackToBuffer&) override {
|
||||
packReads.fetch_add(1);
|
||||
return true;
|
||||
}
|
||||
void Install() {
|
||||
auto rc = Srv::ServerLoopInstance().RunProbeOnApplyThreadForTesting([](void* self) {
|
||||
auto& decoder = Srv::ServerSessionInstance().Applier().*PeerMember(DecoderTag{});
|
||||
decoder.SetVerbSink(static_cast<PackReadPeer*>(self));
|
||||
return MOBILEGL_OK;
|
||||
}, this);
|
||||
if (rc != MOBILEGL_OK) ::_exit(150);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(RemoteClientControls, APackReadOwedWhenTheDeviceIsLostNeverReadsBackAsTheOldBytes) {
|
||||
const auto child = RunInChild([] {
|
||||
StartControlSession();
|
||||
PackReadPeer peer;
|
||||
peer.Install();
|
||||
MG_Config::Features.PipePush |= kMGPipeSubsystemResources;
|
||||
MG_State::pGLContext = MakeUnique<MG_State::GLState::GLContext>();
|
||||
constexpr GLenum kPixelPackBuffer = 0x88EB;
|
||||
GLuint buffer = 0;
|
||||
MG_Impl::GLImpl::GenBuffers(1, &buffer);
|
||||
MG_Impl::GLImpl::BindBuffer(kPixelPackBuffer, buffer);
|
||||
Uint8 before[64];
|
||||
std::memset(before, 0x5a, sizeof(before));
|
||||
MG_Impl::GLImpl::BufferData(kPixelPackBuffer, sizeof(before), before, 0x88EA /* STREAM_READ */);
|
||||
// 4x4 RGBA8 = the whole buffer, read to offset 0.
|
||||
RemoteEmitTable().GL.ReadPixels(0, 0, 4, 4, 0x1908, 0x1401, nullptr);
|
||||
ClientSessionInstance().WaitForApplyToCatchUp("F1 pack read");
|
||||
if (peer.packReads.load() != 1) ::_exit(151);
|
||||
ClientSessionInstance().LatchDeviceLost("RemoteClientControls: the server died with the pack read owed");
|
||||
Uint8 after[64];
|
||||
std::memset(after, 0, sizeof(after));
|
||||
MG_Impl::GLImpl::GetBufferSubData(kPixelPackBuffer, 0, sizeof(after), after);
|
||||
// Reaching here means the read returned: the bytes are the ones from BEFORE the pixels.
|
||||
::_exit(152);
|
||||
});
|
||||
ExpectNamedAbort(child, "Fatal{ReadbackDeclined, \"buffer-writeback\"}");
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
// P12 item B: the texture half stops owning a reply on the wire arm
|
||||
// =====================================================================================
|
||||
|
||||
Reference in New Issue
Block a user