summaryrefslogtreecommitdiff
path: root/src/protocols/core
diff options
context:
space:
mode:
authorTom Englund <tomenglund26@gmail.com>2025-11-06 14:25:49 +0100
committerGitHub <noreply@github.com>2025-11-06 13:25:49 +0000
commit8e8bfbb0b146fb1f3234b2a3e3e92b63989e1993 (patch)
tree87c63793663c6b57293a3f9ee20405090105fef7 /src/protocols/core
parentc757fd375cce299e3da922190ddf1a0622ce807c (diff)
protocols: add Fifo-v1 and commit-timing-v1 (#12052)
* protocols: add Fifo-v1 introduce fifo-v1 * fifo: only present locked surfaces dont present to unlocked surfaces and commit pending states from the fifo protocol. * fifo: cformat cformat * protocols: add committiming and surface state queue introduce CSurfaceStateQueue and commit-timing-v1 * fifo: schedule a frame if waiting on barrier if we are waiting on a barrier the state doesnt commit until the next refresh cycle meaning the monitor might have no pending damage and we never get onPresented to unlock the barrier, moment 22. so schedule a frame. * fifo: properly check monitor intersection check for m_enteredoutputs or monitor intersection if client hasnt bound one yet, and dont fifo lock it until the surface is mapped. * buffer: try to merge states before committing them try to merge states before committing them meaning way less churn and surface commits if a surface sends multiple small ones while we wait for buffer readyness from either fifo locks or simply fences. * buffer: dont commit states past the buffer certain changes are relative to the buffer attached, cant go beyond it and apply those onto the next buffer. * buffer: set the lockmask directly cant use .lock since the state hasnt been queued yet, set the lockmask directly when exporting buffer fence. * fifo: dont fifo lock on tearing dont fifo lock on tearing. * buffer: queue the state directly queue the state directly and use the .lock function instead of directly modify the lockMask on the state. * buffer: revert creating texture at commit time fifo barriers introduces such long wait that upon commit time a race happends with current xdg configure implentation that the buffer and image is actually destroyed when entering commitState, doing it at buffer creation time with EGL_PRESERVED_KHR means it sticks around until we are done. so revert 82759d4 and 32f3233 for now. * buffer: rename enum and lockreasons eLockReason and LOCK_REASON_NONE. * fifo: workaround direct scanout lock workaround cursor commits causing fifo to get forever locked, this entire thing needs to be worked out.
Diffstat (limited to 'src/protocols/core')
-rw-r--r--src/protocols/core/Compositor.cpp80
-rw-r--r--src/protocols/core/Compositor.hpp16
-rw-r--r--src/protocols/core/Shm.cpp4
-rw-r--r--src/protocols/core/Shm.hpp1
4 files changed, 51 insertions, 50 deletions
diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp
index 8ad2a373..06a4587f 100644
--- a/src/protocols/core/Compositor.cpp
+++ b/src/protocols/core/Compositor.cpp
@@ -91,10 +91,12 @@ CWLSurfaceResource::CWLSurfaceResource(SP<CWlSurface> resource_) : m_resource(re
if (buf && buf->m_buffer) {
m_pending.buffer = CHLBufferReference(buf->m_buffer.lock());
+ m_pending.texture = buf->m_buffer->m_texture;
m_pending.size = buf->m_buffer->size;
m_pending.bufferSize = buf->m_buffer->size;
} else {
- m_pending.buffer = {};
+ m_pending.buffer = {};
+ m_pending.texture.reset();
m_pending.size = Vector2D{};
m_pending.bufferSize = Vector2D{};
}
@@ -134,23 +136,33 @@ CWLSurfaceResource::CWLSurfaceResource(SP<CWlSurface> resource_) : m_resource(re
commitState(m_pending);
// remove any pending states.
- while (!m_pendingStates.empty()) {
- m_pendingStates.pop();
- }
-
- m_pendingWaiting = false;
+ m_stateQueue.clear();
m_pending.reset();
return;
}
- // save state while we wait for buffer to become ready to read
- const auto& state = m_pendingStates.emplace(makeUnique<SSurfaceState>(m_pending));
+ // save state while we wait for buffer to become ready
+ auto state = m_stateQueue.enqueue(makeUnique<SSurfaceState>(m_pending));
m_pending.reset();
- if (!m_pendingWaiting) {
- m_pendingWaiting = true;
- scheduleState(state);
+ // fifo and fences first
+ m_events.stateCommit.emit(state);
+
+ if (state->buffer && state->buffer->type() == Aquamarine::BUFFER_TYPE_DMABUF && state->buffer->dmabuf().success && !state->updated.bits.acquire) {
+ state->buffer->m_syncFd = dc<CDMABuffer*>(state->buffer.m_buffer.get())->exportSyncFile();
+ if (state->buffer->m_syncFd.isValid())
+ m_stateQueue.lock(state, LOCK_REASON_FENCE);
}
+
+ // now for timer.
+ m_events.stateCommit2.emit(state);
+
+ if (state->rejected) {
+ m_stateQueue.dropState(state);
+ return;
+ }
+
+ scheduleState(state);
});
m_resource->setDamage([this](CWlSurface* r, int32_t x, int32_t y, int32_t w, int32_t h) {
@@ -479,43 +491,25 @@ CBox CWLSurfaceResource::extends() {
}
void CWLSurfaceResource::scheduleState(WP<SSurfaceState> state) {
- auto whenReadable = [this, surf = m_self, state] {
- if (!surf || state.expired() || m_pendingStates.empty())
+ auto whenReadable = [this, surf = m_self](auto state, auto reason) {
+ if (!surf || !state)
return;
- while (!m_pendingStates.empty() && m_pendingStates.front() != state) {
- commitState(*m_pendingStates.front());
- m_pendingStates.pop();
- }
-
- commitState(*m_pendingStates.front());
- m_pendingStates.pop();
-
- // If more states are queued, schedule next state
- if (!m_pendingStates.empty()) {
- scheduleState(m_pendingStates.front());
- } else {
- m_pendingWaiting = false;
- }
+ m_stateQueue.unlock(state, reason);
};
if (state->updated.bits.acquire) {
// wait on acquire point for this surface, from explicit sync protocol
- state->acquire.addWaiter(std::move(whenReadable));
+ state->acquire.addWaiter([state, whenReadable]() { whenReadable(state, LOCK_REASON_FENCE); });
} else if (state->buffer && state->buffer->isSynchronous()) {
// synchronous (shm) buffers can be read immediately
- whenReadable();
- } else if (state->buffer && state->buffer->type() == Aquamarine::BUFFER_TYPE_DMABUF && state->buffer->dmabuf().success) {
+ m_stateQueue.unlock(state);
+ } else if (state->buffer && state->buffer->m_syncFd.isValid()) {
// async buffer and is dmabuf, then we can wait on implicit fences
- auto syncFd = dc<CDMABuffer*>(state->buffer.m_buffer.get())->exportSyncFile();
-
- if (syncFd.isValid())
- g_pEventLoopManager->doOnReadable(std::move(syncFd), std::move(whenReadable));
- else
- whenReadable();
+ g_pEventLoopManager->doOnReadable(std::move(state->buffer->m_syncFd), [state, whenReadable]() { whenReadable(state, LOCK_REASON_FENCE); });
} else {
// state commit without a buffer.
- whenReadable();
+ m_stateQueue.unlock(state);
}
}
@@ -526,8 +520,6 @@ void CWLSurfaceResource::commitState(SSurfaceState& state) {
if (m_current.buffer) {
if (m_current.buffer->isSynchronous())
m_current.updateSynchronousTexture(lastTexture);
- else if (!m_current.buffer->isSynchronous() && state.updated.bits.buffer) // only get a new texture when a new buffer arrived
- m_current.texture = m_current.buffer->createTexture();
// if the surface is a cursor, update the shm buffer
// TODO: don't update the entire texture
@@ -558,6 +550,13 @@ void CWLSurfaceResource::commitState(SSurfaceState& state) {
nullptr);
}
+ if (m_current.updated.bits.damage) {
+ // damage is always relative to the current commit
+ m_current.updated.bits.damage = false;
+ m_current.damage.clear();
+ m_current.bufferDamage.clear();
+ }
+
// release the buffer if it's synchronous (SHM) as updateSynchronousTexture() has copied the buffer data to a GPU tex
// if it doesn't have a role, we can't release it yet, in case it gets turned into a cursor.
if (m_current.buffer && m_current.buffer->isSynchronous() && m_role->role() != SURFACE_ROLE_UNASSIGNED)
@@ -667,7 +666,8 @@ CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : m_re
return;
}
- RESOURCE->m_self = RESOURCE;
+ RESOURCE->m_self = RESOURCE;
+ RESOURCE->m_stateQueue = CSurfaceStateQueue(RESOURCE);
LOGM(LOG, "New wl_surface with id {} at {:x}", id, (uintptr_t)RESOURCE.get());
diff --git a/src/protocols/core/Compositor.hpp b/src/protocols/core/Compositor.hpp
index dc61917d..d6cc9206 100644
--- a/src/protocols/core/Compositor.hpp
+++ b/src/protocols/core/Compositor.hpp
@@ -13,6 +13,7 @@
#include <cstdint>
#include "../WaylandProtocol.hpp"
#include "../../render/Texture.hpp"
+#include "protocols/types/SurfaceStateQueue.hpp"
#include "wayland.hpp"
#include "../../helpers/signal/Signal.hpp"
#include "../../helpers/math/Math.hpp"
@@ -29,6 +30,8 @@ class CWLSurfaceResource;
class CWLSubsurfaceResource;
class CViewportResource;
class CDRMSyncobjSurfaceResource;
+class CFifoResource;
+class CCommitTimerResource;
class CColorManagementSurface;
class CFrogColorManagementSurface;
class CContentType;
@@ -89,8 +92,10 @@ class CWLSurfaceResource {
void resetRole();
struct {
- CSignalT<> precommit; // before commit
- CSignalT<> commit; // after commit
+ CSignalT<> precommit; // before commit
+ CSignalT<WP<SSurfaceState>> stateCommit; // when placing state in queue
+ CSignalT<WP<SSurfaceState>> stateCommit2; // when placing state in queue used for commit timing so we apply fifo/fences first.
+ CSignalT<> commit; // after commit
CSignalT<> map;
CSignalT<> unmap;
CSignalT<SP<CWLSubsurfaceResource>> newSubsurface;
@@ -101,8 +106,7 @@ class CWLSurfaceResource {
SSurfaceState m_current;
SSurfaceState m_pending;
- std::queue<UP<SSurfaceState>> m_pendingStates;
- bool m_pendingWaiting = false;
+ CSurfaceStateQueue m_stateQueue;
WP<CWLSurfaceResource> m_self;
WP<CWLSurface> m_hlSurface;
@@ -110,7 +114,9 @@ class CWLSurfaceResource {
bool m_mapped = false;
std::vector<WP<CWLSubsurfaceResource>> m_subsurfaces;
SP<ISurfaceRole> m_role;
- WP<CDRMSyncobjSurfaceResource> m_syncobj; // may not be present
+ WP<CDRMSyncobjSurfaceResource> m_syncobj; // may not be present
+ WP<CFifoResource> m_fifo; // may not be present
+ WP<CCommitTimerResource> m_commitTimer; // may not be present
WP<CColorManagementSurface> m_colorManagement;
WP<CContentType> m_contentType;
diff --git a/src/protocols/core/Shm.cpp b/src/protocols/core/Shm.cpp
index 30189d8b..43c087bc 100644
--- a/src/protocols/core/Shm.cpp
+++ b/src/protocols/core/Shm.cpp
@@ -69,10 +69,6 @@ void CWLSHMBuffer::endDataPtr() {
;
}
-SP<CTexture> CWLSHMBuffer::createTexture() {
- return nullptr;
-}
-
bool CWLSHMBuffer::good() {
return true;
}
diff --git a/src/protocols/core/Shm.hpp b/src/protocols/core/Shm.hpp
index fba3de8d..37210398 100644
--- a/src/protocols/core/Shm.hpp
+++ b/src/protocols/core/Shm.hpp
@@ -43,7 +43,6 @@ class CWLSHMBuffer : public IHLBuffer {
virtual Aquamarine::SSHMAttrs shm();
virtual std::tuple<uint8_t*, uint32_t, size_t> beginDataPtr(uint32_t flags);
virtual void endDataPtr();
- virtual SP<CTexture> createTexture();
bool good();