mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-17 15:03:25 +09:00
[Feature] (SharedImage): a glFlush publishes an image producer's accesses, so Xwayland's glamor gets implicit sync
This commit is contained in:
@@ -684,6 +684,17 @@ namespace MobileGL::MG_Remote::Client {
|
||||
return session->EmitSharedImage(op, -1, nullptr, nullptr);
|
||||
}
|
||||
|
||||
Bool BackendObject_Remote::FlushSharedImageAccesses() {
|
||||
ClientSession* session = ClientSession::Active();
|
||||
if (session == nullptr || !session->Started()) return false;
|
||||
if (m_sharedImageFlushedAt != 0 && session->LastPublishedSeq() == m_sharedImageFlushedAt) return true;
|
||||
MG_Pipe::MGPSharedImageOp op{};
|
||||
op.Op = MG_Pipe::kMGPSharedImageFlush;
|
||||
const Bool published = session->EmitSharedImage(op, -1, nullptr, nullptr);
|
||||
m_sharedImageFlushedAt = session->LastPublishedSeq();
|
||||
return published;
|
||||
}
|
||||
|
||||
// NO strong CreateRemoteBackendObject() lives here, and the reason is a link fact, not an
|
||||
// oversight. v1's Init.cpp calls MG_Remote::Client::CreateRemoteBackendObject() and ships a
|
||||
// __attribute__((weak)) placeholder for it beside ServerLoop that aborts by name; its comment
|
||||
|
||||
@@ -94,6 +94,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
Bool QueryBufferAge(Bool damageRegionFollows, EGLint* age) override;
|
||||
Bool SetDamageRegion(const MG_Util::Damage::Region& region) override;
|
||||
Bool AttachSharedImageToTexture(Uint64 textureLifetimeId, Uint64 id) override;
|
||||
Bool FlushSharedImageAccesses() override;
|
||||
|
||||
// Copies the caps mirror's FormatCapabilityCache into the base class's
|
||||
// m_formatCapabilities. Public because CapsMirror's adoption hook is a free function
|
||||
@@ -122,6 +123,10 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// geometry adopted before it returns, and every refusal named in this process's log.
|
||||
Bool CreateServerOwnedWindowSurface(EGLSurface surface, const MG_Backend::WindowHandle& handle);
|
||||
|
||||
// The stream position right after the last shared-image Flush record: a flush with nothing
|
||||
// published since has nothing new to fence and costs no round trip.
|
||||
Uint64 m_sharedImageFlushedAt = 0;
|
||||
|
||||
// The generation of the snapshot m_formatCapabilities was filled from. Exposed only
|
||||
// through the log line on a refresh: a cache that silently stopped tracking the mirror
|
||||
// is exactly the shape trap 2 exists to prevent.
|
||||
|
||||
@@ -1586,6 +1586,13 @@ namespace MobileGL::MG_Remote::Server {
|
||||
if (backend == nullptr) return false;
|
||||
return backend->SetCurrentDamageRegion(DamageOfRecord(op.DamageCount, op.Damage));
|
||||
}
|
||||
case MG_Pipe::kMGPSharedImageFlush: {
|
||||
// The answer is posted after the fence is published: the client commits the buffer to
|
||||
// its compositor only after this returns, so the compositor's session finds the write.
|
||||
MG_Backend::BackendObject* backend = ServerLoopInstance().Backend();
|
||||
if (backend == nullptr) return false;
|
||||
return backend->PublishSharedImageAccesses();
|
||||
}
|
||||
case MG_Pipe::kMGPSharedImageAttach: {
|
||||
SI::ImageRef image = holder.Get(op.ImageId);
|
||||
if (image == nullptr) return false;
|
||||
|
||||
@@ -394,6 +394,15 @@ namespace MobileGL::MG_Remote::Server::SharedImages {
|
||||
m_images.clear();
|
||||
}
|
||||
|
||||
void ReadTracker::PublishFrameAsWrite(int fence) {
|
||||
for (const auto& [id, image] : m_images) {
|
||||
PublishWrite(*image, Dup(fence));
|
||||
PublishRead(*image, Dup(fence));
|
||||
}
|
||||
CloseFd(fence);
|
||||
m_images.clear();
|
||||
}
|
||||
|
||||
void SessionHolder::Hold(const ImageRef& image) {
|
||||
if (image == nullptr) return;
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
@@ -134,6 +134,12 @@ namespace MobileGL::MG_Remote::Server::SharedImages {
|
||||
void NoteRead(const ImageRef& image);
|
||||
// Takes ownership of `fence` (a sync_file for the frame, -1 if it has completed).
|
||||
void PublishFrame(int fence);
|
||||
// IMPLICIT SYNC BY FLUSH: a session that renders into images as well as sampling them, with
|
||||
// no swap and no explicit write (an X server's glamor) ends its frame at glFlush. Every image
|
||||
// it used since its last boundary gets `fence` both as a write - the generation moves, so the
|
||||
// next reader waits for it - and as a read, so the next writer waits for it too. Takes
|
||||
// ownership of `fence` (-1: the work has completed; the generation still moves).
|
||||
void PublishFrameAsWrite(int fence);
|
||||
SizeT Pending() const { return m_images.size(); }
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user