IOPresentment associates more than one pipe client with our display (measured on a macOS 26 guest: two per WindowServer, and another for a batch of transactions), and any of them may submit. The framebuffer kept only the last associated client: the host's answer to a PRESENT_SURFACE went to it alone, so a transaction submitted on another client never completed, and two such held its submits for five seconds each. And any client's close cleared the hooks of whichever client was current. The framebuffer now keeps every associated client (RgfxPipeClients.hpp, tested natively): each COMPLETE goes to all of them, and the one whose transaction it answers takes it, as each already ignores seqnos it did not post; a VBLANK goes to each client registered for them; a close removes only its own client. When the last client goes with an IOSurface shown, the framebuffer asks the host for the scanout again (PRESENT_SURFACE 0). Otherwise the display stays on a dead WindowServer's last frame while its successor, which composites on the CPU after a Metal crash (measured), draws into the scanout unseen.
62 lines
2.5 KiB
C++
62 lines
2.5 KiB
C++
// The display pipe's clients (RgfxPipeClients.hpp), built natively: every associated client is
|
|
// served, and the last one's going shows the scanout again where a surface was shown.
|
|
#include <cstdio>
|
|
|
|
#include "RgfxPipeClients.hpp"
|
|
|
|
static int g_checks = 0, g_failed = 0;
|
|
#define CHECK(e) \
|
|
do { \
|
|
g_checks++; \
|
|
if (!(e)) { \
|
|
g_failed++; \
|
|
std::fprintf(stderr, "%s:%d: CHECK(%s) failed\n", __FILE__, __LINE__, #e); \
|
|
} \
|
|
} while (0)
|
|
|
|
int main()
|
|
{
|
|
int a = 0, b = 0, c = 0;
|
|
const int *out[3] = {};
|
|
bool scanout = true;
|
|
|
|
// Two clients associate (IOPresentment's pair): both are served, the first not replaced.
|
|
RgfxPipeClients<const int *, 2> pipes;
|
|
CHECK(pipes.add(&a) && pipes.add(&b) && pipes.add(&a));
|
|
CHECK(pipes.count() == 2 && pipes.all(out) == 2 && out[0] == &a && out[1] == &b);
|
|
CHECK(!pipes.add(&c)); // no room
|
|
CHECK(pipes.holds(&a) && pipes.holds(&b) && !pipes.holds(&c));
|
|
|
|
// VBLANKs go to the clients registered for them only.
|
|
CHECK(!pipes.anyVblank());
|
|
pipes.setVblank(&b, true);
|
|
CHECK(pipes.anyVblank() && pipes.wantingVblank(out) == 1 && out[0] == &b);
|
|
pipes.setVblank(&c, true); // not held: nothing
|
|
CHECK(pipes.wantingVblank(out) == 1);
|
|
|
|
// A surface shown; one client goes: the other still shows it, nothing to ask.
|
|
pipes.shows(0x77);
|
|
CHECK(pipes.remove(&a, &scanout) && !scanout && pipes.shown() == 0x77);
|
|
CHECK(!pipes.remove(&a, &scanout) && !scanout); // gone already
|
|
// The last goes: the scanout is asked for, once.
|
|
CHECK(pipes.remove(&b, &scanout) && scanout && pipes.shown() == 0);
|
|
CHECK(!pipes.anyVblank() && pipes.count() == 0);
|
|
|
|
// The last going while the display shows the scanout asks nothing.
|
|
CHECK(pipes.add(&c));
|
|
CHECK(pipes.remove(&c, &scanout) && !scanout);
|
|
|
|
// A slot freed takes a new client, with no VBLANK registration of the old one's.
|
|
CHECK(pipes.add(&a));
|
|
pipes.setVblank(&a, true);
|
|
CHECK(pipes.remove(&a, &scanout));
|
|
CHECK(pipes.add(&b) && !pipes.anyVblank());
|
|
|
|
if (g_failed) {
|
|
std::fprintf(stderr, "pipe_clients_test: %d of %d checks failed\n", g_failed, g_checks);
|
|
return 1;
|
|
}
|
|
std::printf("pipe_clients_test: OK (%d checks)\n", g_checks);
|
|
return 0;
|
|
}
|