mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-17 23:13:22 +09:00
[Fix] (EGL, SharedImage): real EGL native fences publish a dma-buf producer's writes, so Chrome's GPU process frames reach the compositor.
This commit is contained in:
@@ -707,6 +707,19 @@ namespace MobileGL::MG_Remote::Client {
|
||||
return published;
|
||||
}
|
||||
|
||||
Bool BackendObject_Remote::CreateNativeFence(int* fence) {
|
||||
*fence = -1;
|
||||
ClientSession* session = ClientSession::Active();
|
||||
if (session == nullptr || !session->Started()) return false;
|
||||
MG_Pipe::MGPSharedImageOp op{};
|
||||
op.Op = MG_Pipe::kMGPSharedImageNativeFence;
|
||||
MG_Pipe::MGPSharedImageReply reply{};
|
||||
if (!session->EmitSharedImage(op, -1, &reply, fence)) return false;
|
||||
// It published what a flush would: a flush right after it has nothing new to say.
|
||||
m_sharedImageFlushedAt = session->LastPublishedSeq();
|
||||
return true;
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@@ -96,6 +96,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
Bool SetDamageRegion(const MG_Util::Damage::Region& region) override;
|
||||
Bool AttachSharedImageToTexture(Uint64 textureLifetimeId, Uint64 id) override;
|
||||
Bool FlushSharedImageAccesses() override;
|
||||
Bool CreateNativeFence(int* fence) override;
|
||||
|
||||
// Copies the caps mirror's FormatCapabilityCache into the base class's
|
||||
// m_formatCapabilities. Public because CapsMirror's adoption hook is a free function
|
||||
|
||||
@@ -3067,6 +3067,9 @@ namespace MobileGL::MG_Remote::Client {
|
||||
if (status != Wire::ReplySink::kStatusOk || returned != sizeof(answer)) return false;
|
||||
if (reply != nullptr) *reply = answer;
|
||||
if (receivedFd == nullptr) return true;
|
||||
// A native fence's answer says whether a descriptor follows (none: the work completed).
|
||||
if (op.Op == MG_Pipe::kMGPSharedImageNativeFence && answer.Format != MG_Pipe::kMGPNativeFenceFdFollows)
|
||||
return true;
|
||||
#if defined(_WIN32)
|
||||
return false;
|
||||
#else
|
||||
|
||||
@@ -1480,6 +1480,20 @@ namespace MobileGL::MG_Remote::Server {
|
||||
return true;
|
||||
}
|
||||
|
||||
ServerVerbSink::OwnedFd& ServerVerbSink::OwnedFd::operator=(OwnedFd&& other) noexcept {
|
||||
if (this != &other) Reset(std::exchange(other.fd, -1));
|
||||
return *this;
|
||||
}
|
||||
|
||||
ServerVerbSink::OwnedFd::~OwnedFd() { Reset(-1); }
|
||||
|
||||
void ServerVerbSink::OwnedFd::Reset(int next) {
|
||||
#if !defined(_WIN32)
|
||||
if (fd >= 0) ::close(fd);
|
||||
#endif
|
||||
fd = next;
|
||||
}
|
||||
|
||||
// P14 S1. THE RING'S DOOR INTO THE SESSION'S CONTEXT TABLE.
|
||||
//
|
||||
// The record carries the client's current context token and this is where a session's
|
||||
@@ -1593,6 +1607,38 @@ namespace MobileGL::MG_Remote::Server {
|
||||
if (backend == nullptr) return false;
|
||||
return backend->PublishSharedImageAccesses();
|
||||
}
|
||||
case MG_Pipe::kMGPSharedImageNativeFence: {
|
||||
// A descriptor of the session's work, and an image writer's flush (MGPipeTypes.h). Like
|
||||
// an Allocate's, the descriptor goes out BEFORE the reply is posted.
|
||||
MG_Backend::BackendObject* backend = ServerLoopInstance().Backend();
|
||||
if (backend == nullptr) return false;
|
||||
int fence = -1;
|
||||
if (!backend->ExportNativeFence(&fence)) return false;
|
||||
#if !defined(_WIN32)
|
||||
if (fence >= 0) {
|
||||
m_lastNativeFence.Reset(::dup(fence));
|
||||
} else if (m_lastNativeFence.fd >= 0) {
|
||||
fence = ::dup(m_lastNativeFence.fd);
|
||||
}
|
||||
#endif
|
||||
reply.Format = 0;
|
||||
if (fence < 0) return true;
|
||||
Transport::ITransport* transport = session->ControlTransport();
|
||||
MG_Pipe::MGPSharedImageFdOffer offer{MG_Pipe::kMGPSharedImageFdMagic, 1, seq, 0, 0};
|
||||
const MobileGLResult shared = transport != nullptr
|
||||
? transport->ShareFd(fence, MobileGLByteSpan{&offer, sizeof(offer)})
|
||||
: MOBILEGL_ERR_NOT_INITIALIZED;
|
||||
#if !defined(_WIN32)
|
||||
::close(fence);
|
||||
#endif
|
||||
if (shared != MOBILEGL_OK) {
|
||||
MGLOG_E_ONCE("MG_Remote server: a native fence could not be sent on the aux socket (rc=%d)",
|
||||
static_cast<int>(shared));
|
||||
return false;
|
||||
}
|
||||
reply.Format = MG_Pipe::kMGPNativeFenceFdFollows;
|
||||
return true;
|
||||
}
|
||||
case MG_Pipe::kMGPSharedImageAttach: {
|
||||
SI::ImageRef image = holder.Get(op.ImageId);
|
||||
if (image == nullptr) return false;
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include "../Wire/PipeWireCodec.h"
|
||||
|
||||
#include <deque>
|
||||
#include <utility>
|
||||
|
||||
namespace MobileGL::MG_Remote::Server {
|
||||
|
||||
@@ -413,6 +414,20 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Vector<GLint> m_multiBaseVertices;
|
||||
LastDrawRecord m_lastDraw{};
|
||||
Uint64 m_drawRecords = 0;
|
||||
// The newest native fence (shared_image NativeFence) this session handed out, kept so a
|
||||
// later fence with nothing left to export still answers with a descriptor: by then this
|
||||
// one has signaled (the backend waited the work out), and a signaled sync_file stays so.
|
||||
struct OwnedFd {
|
||||
int fd = -1;
|
||||
OwnedFd() = default;
|
||||
OwnedFd(const OwnedFd&) = delete;
|
||||
OwnedFd& operator=(const OwnedFd&) = delete;
|
||||
OwnedFd(OwnedFd&& other) noexcept : fd(std::exchange(other.fd, -1)) {}
|
||||
OwnedFd& operator=(OwnedFd&& other) noexcept;
|
||||
~OwnedFd();
|
||||
void Reset(int next);
|
||||
};
|
||||
OwnedFd m_lastNativeFence;
|
||||
};
|
||||
|
||||
class PipeApplier {
|
||||
|
||||
Reference in New Issue
Block a user