mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-17 15:03:25 +09:00
[Fix] (Client): make a readback on a lost device a no-op instead of a Fatal that kills the client
This commit is contained in:
@@ -900,7 +900,15 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// The same predicate at the call site, with the named Fatal each failure mode owns.
|
||||
// status > expected cannot reach here: EmitAndWait already aborts Fatal{ReplyTooLarge} on
|
||||
// an oversize reply, so the only failures left are a wrong status or a SHORT one.
|
||||
void RequireReadbackReplyComplete(Int32 status, Uint64 replySize, Uint64 expected) {
|
||||
//
|
||||
// A LOST DEVICE IS NOT ONE OF THOSE FAILURES. Once the session is device-lost every verb
|
||||
// is declined by EmitAndWait itself, and the GL answer for a lost context is that its
|
||||
// commands do nothing: the read writes no pixel and the application learns of the loss
|
||||
// from glGetGraphicsResetStatus. Dying here instead turned a server-side GPU fault into a
|
||||
// crash of the client (Chrome's in-process GPU thread took the browser with it). False:
|
||||
// the caller leaves the destination untouched and returns.
|
||||
Bool RequireReadbackReplyComplete(Int32 status, Uint64 replySize, Uint64 expected) {
|
||||
if (status != Wire::ReplySink::kStatusOk && ClientSession::DeviceLost()) return false;
|
||||
if (status == Wire::ReplySink::kStatusError) {
|
||||
SessionFail(MGFatalFamily::ReplyError, "MGPipe: Fatal{ReplyError, \"ReadPixels\"} - the readback answered ERROR; "
|
||||
"the destination is left untouched rather than filled with stale bytes");
|
||||
@@ -922,6 +930,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
static_cast<unsigned long long>(replySize),
|
||||
static_cast<unsigned long long>(expected));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#include "TextureReadbackEmit.inc"
|
||||
@@ -1068,7 +1077,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// M2 / codex 11: an OK reply that arrived short, or a DECLINE/ERROR, must not
|
||||
// be handed back as pixels. The Fatal aborts before the application reads the
|
||||
// buffer, so the bytes EmitAndWait already copied are never observed.
|
||||
RequireReadbackReplyComplete(status, replySize, bandBytes);
|
||||
if (!RequireReadbackReplyComplete(status, replySize, bandBytes)) return;
|
||||
ApplyReadbackByteSwap(at, bandBytes, type, pack);
|
||||
return;
|
||||
}
|
||||
@@ -1078,7 +1087,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
0, bounce.data(), bandBytes, &status, &replySize);
|
||||
// BEFORE THE SCATTER, so a short or non-OK reply never reaches the application's
|
||||
// pointer at all (the bounce is the only thing that held the partial bytes).
|
||||
RequireReadbackReplyComplete(status, replySize, bandBytes);
|
||||
if (!RequireReadbackReplyComplete(status, replySize, bandBytes)) return;
|
||||
ApplyReadbackByteSwap(bounce.data(), bandBytes, type, pack);
|
||||
if (pbo) {
|
||||
// pixels is an offset, never a host pointer. Upload only the requested
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
Uint64 received = 0;
|
||||
session.EmitAndWait(MG_Pipe::MGPWireOp::GetTextureImage, &info, sizeof(info), nullptr, 0,
|
||||
bytes.data() + offset, info.DstSize, &status, &received);
|
||||
RequireReadbackReplyComplete(status, received, info.DstSize);
|
||||
if (!RequireReadbackReplyComplete(status, received, info.DstSize)) return;
|
||||
offset += info.DstSize;
|
||||
}
|
||||
ApplyReadbackByteSwap(bytes.data(), tight, type, pack);
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
#include <Config.h>
|
||||
#include <MG_Remote/Client/ClientSession.h>
|
||||
#include <MG_Remote/Client/EmitTables.h>
|
||||
#include <MG_Remote/FatalFunnel.h>
|
||||
#include <MG_Remote/Server/ServerLoop.h>
|
||||
#include <MG_Remote/Server/ServerSpawn.h>
|
||||
@@ -1234,6 +1235,34 @@ TEST(ServerSpawnTest, AKilledServerLatchesDeviceLostFromTheHangupAndNotFromADead
|
||||
(void)Server::ReapServer(session.server, 5000, &exitCode);
|
||||
}
|
||||
|
||||
// A LOST DEVICE MAKES A READBACK A NO-OP, NOT A CRASH. Once the session is device-lost every verb
|
||||
// is declined, and the read used to treat that DECLINE as Fatal{ReadbackDeclined} - so the first
|
||||
// glReadPixels after a server-side GPU fault aborted the client (Chrome's in-process GPU thread
|
||||
// took the whole browser with it). GL's answer for a lost context is that the read writes nothing
|
||||
// and glGetGraphicsResetStatus reports the reset. Red once by dropping the device-lost arm of
|
||||
// RequireReadbackReplyComplete: this case dies of SIGABRT.
|
||||
TEST(ServerSpawnTest, AReadbackOnALostDeviceWritesNothingAndDoesNotAbort) {
|
||||
Session session;
|
||||
ASSERT_TRUE(Bring("lostread", &session));
|
||||
ASSERT_EQ(Handshake(session), MOBILEGL_OK);
|
||||
Transport::Doorbell* bell = Client::ClientSessionInstance().SelfDoorbellForTest();
|
||||
ASSERT_NE(bell, nullptr);
|
||||
ASSERT_EQ(::kill(session.server.pid, SIGKILL), 0);
|
||||
for (int attempt = 0; attempt < 200 && !bell->PeerHungUp(); ++attempt) (void)bell->Park(10);
|
||||
ASSERT_TRUE(bell->PeerHungUp());
|
||||
Client::ClientSessionInstance().LatchDeviceLost("the test killed the server");
|
||||
ASSERT_TRUE(Client::ClientSession::DeviceLost());
|
||||
|
||||
std::uint8_t pixels[4] = {0x5A, 0x5A, 0x5A, 0x5A};
|
||||
Client::RemoteEmitTable().GL.ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
EXPECT_EQ(pixels[0], 0x5A);
|
||||
EXPECT_EQ(pixels[3], 0x5A) << "a lost context's read wrote into the destination";
|
||||
|
||||
Client::ClientSessionInstance().Stop();
|
||||
int exitCode = -1;
|
||||
(void)Server::ReapServer(session.server, 5000, &exitCode);
|
||||
}
|
||||
|
||||
TEST(ServerSpawnTest, AnOrderlyStopIsNotADeviceLoss) {
|
||||
// The session-level control: a clean shutdown must leave the latch disarmed, or every exit
|
||||
// would report a context reset and the status would mean nothing.
|
||||
|
||||
Reference in New Issue
Block a user