render: properly release rendered buffers (#9807)

* cleanup eglSync

* properly release buffers in renderer

* add renderingDoneCallback and use it in screencopy

* use static constructor for CEGLSync
This commit is contained in:
Ikalco 2025-04-30 11:35:25 -05:00 committed by GitHub
parent 5d005f11fa
commit 2ee5118d7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 119 additions and 161 deletions

View file

@ -3,7 +3,6 @@
#include "../macros.hpp"
#include "math/Math.hpp"
#include "../protocols/ColorManagement.hpp"
#include "sync/SyncReleaser.hpp"
#include "../Compositor.hpp"
#include "../config/ConfigValue.hpp"
#include "../config/ConfigManager.hpp"
@ -61,10 +60,6 @@ void CMonitor::onConnect(bool noRule) {
g_pEventLoopManager->doLater([] { g_pConfigManager->ensurePersistentWorkspacesPresent(); });
if (output->supportsExplicit) {
inTimeline = CSyncTimeline::create(output->getBackend()->drmFD());
}
listeners.frame = output->events.frame.registerListener([this](std::any d) { onMonitorFrame(); });
listeners.commit = output->events.commit.registerListener([this](std::any d) {
if (true) { // FIXME: E->state->committed & WLR_OUTPUT_STATE_BUFFER

View file

@ -139,10 +139,7 @@ class CMonitor {
SMonitorRule activeMonitorRule;
// explicit sync
SP<CSyncTimeline> inTimeline;
Hyprutils::OS::CFileDescriptor inFence;
SP<CEGLSync> eglSync;
uint64_t inTimelinePoint = 0;
Hyprutils::OS::CFileDescriptor inFence; // TODO: remove when aq uses CFileDescriptor
PHLMONITORREF self;

View file

@ -35,7 +35,10 @@ CSyncReleaser::~CSyncReleaser() {
m_timeline->signal(m_point);
}
CFileDescriptor CSyncReleaser::mergeSyncFds(const CFileDescriptor& fd1, const CFileDescriptor& fd2) {
static CFileDescriptor mergeSyncFds(const CFileDescriptor& fd1, const CFileDescriptor& fd2) {
// combines the fences of both sync_fds into a dma_fence_array (https://www.kernel.org/doc/html/latest/driver-api/dma-buf.html#c.dma_fence_array_create)
// with the signal_on_any param set to false, so the new sync_fd will "signal when all fences in the array signal."
struct sync_merge_data data{
.name = "merged release fence",
.fd2 = fd2.get(),
@ -51,13 +54,11 @@ CFileDescriptor CSyncReleaser::mergeSyncFds(const CFileDescriptor& fd1, const CF
return CFileDescriptor(data.fence);
}
void CSyncReleaser::addReleaseSync(SP<CEGLSync> sync) {
void CSyncReleaser::addSyncFileFd(const Hyprutils::OS::CFileDescriptor& syncFd) {
if (m_fd.isValid())
m_fd = mergeSyncFds(m_fd, sync->takeFD());
m_fd = mergeSyncFds(m_fd, syncFd);
else
m_fd = sync->fd().duplicate();
m_sync = sync;
m_fd = syncFd.duplicate();
}
void CSyncReleaser::drop() {

View file

@ -12,7 +12,6 @@
*/
class CSyncTimeline;
class CEGLSync;
class CSyncReleaser {
public:
@ -22,13 +21,11 @@ class CSyncReleaser {
// drops the releaser, will never signal anymore
void drop();
// wait for this gpu job to finish before releasing
Hyprutils::OS::CFileDescriptor mergeSyncFds(const Hyprutils::OS::CFileDescriptor& fd1, const Hyprutils::OS::CFileDescriptor& fd2);
void addReleaseSync(SP<CEGLSync> sync);
// wait for this sync_fd to signal before releasing
void addSyncFileFd(const Hyprutils::OS::CFileDescriptor& syncFd);
private:
SP<CSyncTimeline> m_timeline;
uint64_t m_point = 0;
Hyprutils::OS::CFileDescriptor m_fd;
SP<CEGLSync> m_sync;
};