Skip to content

Commit

Permalink
syncobj: remove early buffer release
Browse files Browse the repository at this point in the history
remove early buffer release config that previously tried to workaround
flickers while it was more of an syncobj issue, it also cant be used
since the buffer really is used for release point syncing in the
renderer later. and use std::move instead of std::exchange to avoid a
local temporar copy being created inside std::exchange.
  • Loading branch information
gulafaran committed Feb 24, 2025
1 parent e156ace commit e331b6c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
6 changes: 0 additions & 6 deletions src/config/ConfigDescriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1348,12 +1348,6 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
.type = CONFIG_OPTION_INT,
.data = SConfigOptionDescription::SRangeData{2, 0, 2},
},
SConfigOptionDescription{
.value = "render:allow_early_buffer_release",
.description = "Allow early buffer release event. Fixes stuttering and missing frames for some apps. May cause graphical glitches and memory leaks in others",
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{true},
},

/*
* cursor:
Expand Down
1 change: 0 additions & 1 deletion src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ CConfigManager::CConfigManager() {
m_pConfig->addConfigValue("render:expand_undersized_textures", Hyprlang::INT{1});
m_pConfig->addConfigValue("render:xp_mode", Hyprlang::INT{0});
m_pConfig->addConfigValue("render:ctm_animation", Hyprlang::INT{2});
m_pConfig->addConfigValue("render:allow_early_buffer_release", Hyprlang::INT{1});

m_pConfig->addConfigValue("ecosystem:no_update_news", Hyprlang::INT{0});
m_pConfig->addConfigValue("ecosystem:no_donation_nag", Hyprlang::INT{0});
Expand Down
12 changes: 8 additions & 4 deletions src/protocols/DRMSyncobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ CDRMSyncobjSurfaceResource::CDRMSyncobjSurfaceResource(UP<CWpLinuxDrmSyncobjSurf
});

listeners.surfaceRoleCommit = surface->events.roleCommit.registerListener([this](std::any d) {
if (pendingAcquire.resource)
acquire = std::exchange(pendingAcquire, {});
if (pendingAcquire.resource) {
acquire = std::move(pendingAcquire);
pendingAcquire = {};
}

if (pendingRelease.resource)
release = std::exchange(pendingRelease, {});
if (pendingRelease.resource) {
release = std::move(pendingRelease);
pendingRelease = {};
}
});
}

Expand Down
23 changes: 9 additions & 14 deletions src/protocols/core/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "../PresentationTime.hpp"
#include "../DRMSyncobj.hpp"
#include "../../render/Renderer.hpp"
#include "config/ConfigValue.hpp"
#include <cstring>

class CDefaultSurfaceRole : public ISurfaceRole {
Expand Down Expand Up @@ -422,14 +421,12 @@ void CWLSurfaceResource::commitPendingState() {
if (stateLocked && syncobj)
return;

static auto PDROP = CConfigValue<Hyprlang::INT>("render:allow_early_buffer_release");
auto const previousBuffer = current.buffer;
current = pending;
auto const previousBuffer = current.buffer;
current = pending;
pending.damage.clear();
pending.bufferDamage.clear();
pending.newBuffer = false;
if (!*PDROP)
dropPendingBuffer(); // at this point current.buffer holds the same SP and we don't use pending anymore
dropPendingBuffer(); // at this point current.buffer holds the same SP and we don't use pending anymore

events.roleCommit.emit();

Expand All @@ -447,14 +444,6 @@ void CWLSurfaceResource::commitPendingState() {
// TODO: don't update the entire texture
if (role->role() == SURFACE_ROLE_CURSOR && !DAMAGE.empty())
updateCursorShm(DAMAGE);

// release the buffer if it's synchronous as update() has done everything thats needed
// so we can let the app know we're done.
// Some clients aren't ready to receive a release this early. Should be fine to release it on the next commitPendingState.
if (current.buffer->buffer->isSynchronous() && *PDROP) {
dropCurrentBuffer();
dropPendingBuffer(); // at this point current.buffer holds the same SP and we don't use pending anymore
}
}

// TODO: we should _accumulate_ and not replace above if sync
Expand All @@ -478,6 +467,12 @@ void CWLSurfaceResource::commitPendingState() {
nullptr);
}

// fifo mode requires us to drop the current buffer before next commit
// otherwise release points arent being sent and we dont recieve new acquire
// and release points.
if (syncobj)
dropCurrentBuffer();

// for async buffers, we can only release the buffer once we are unrefing it from current.
// if the backend took it, ref it with the lambda. Otherwise, the end of this scope will release it.
if (previousBuffer && previousBuffer->buffer && !previousBuffer->buffer->isSynchronous()) {
Expand Down

0 comments on commit e331b6c

Please sign in to comment.