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 revert82759d4and32f3233for 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.
This commit is contained in:
parent
c757fd375c
commit
8e8bfbb0b1
26 changed files with 750 additions and 120 deletions
|
|
@ -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());
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue