Skip to content

Commit b63c4cc

Browse files
committed
remove syncReleaser and properly release buffers in renderer
1 parent 571090f commit b63c4cc

File tree

11 files changed

+45
-162
lines changed

11 files changed

+45
-162
lines changed

src/helpers/Monitor.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "../macros.hpp"
44
#include "math/Math.hpp"
55
#include "../protocols/ColorManagement.hpp"
6-
#include "sync/SyncReleaser.hpp"
76
#include "../Compositor.hpp"
87
#include "../config/ConfigValue.hpp"
98
#include "../protocols/GammaControl.hpp"

src/helpers/sync/SyncReleaser.cpp

-65
This file was deleted.

src/helpers/sync/SyncReleaser.hpp

-34
This file was deleted.

src/protocols/DRMSyncobj.cpp

-10
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ WP<CSyncTimeline> CDRMSyncPointState::timeline() {
1919
return m_timeline;
2020
}
2121

22-
UP<CSyncReleaser> CDRMSyncPointState::createSyncRelease() {
23-
if (m_releaseTaken)
24-
Debug::log(ERR, "CDRMSyncPointState: creating a sync releaser on an already created SyncRelease");
25-
26-
m_releaseTaken = true;
27-
return makeUnique<CSyncReleaser>(m_timeline, m_point);
28-
}
29-
3022
bool CDRMSyncPointState::addWaiter(const std::function<void()>& waiter) {
3123
m_acquireCommitted = true;
3224
return m_timeline->addWaiter(waiter, m_point, 0u);
@@ -107,8 +99,6 @@ CDRMSyncobjSurfaceResource::CDRMSyncobjSurfaceResource(UP<CWpLinuxDrmSyncobjSurf
10799

108100
surface->pending.buffer.release = pendingRelease;
109101
pendingRelease = {};
110-
111-
surface->pending.buffer->syncReleaser = surface->pending.buffer.release.createSyncRelease();
112102
});
113103
}
114104

src/protocols/DRMSyncobj.hpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <vector>
44
#include "WaylandProtocol.hpp"
5-
#include "../helpers/sync/SyncReleaser.hpp"
65
#include "linux-drm-syncobj-v1.hpp"
76
#include "../helpers/signal/Signal.hpp"
87
#include <hyprutils/os/FileDescriptor.hpp>
@@ -17,13 +16,12 @@ class CDRMSyncPointState {
1716
CDRMSyncPointState(SP<CSyncTimeline> timeline_, uint64_t point_);
1817
~CDRMSyncPointState() = default;
1918

20-
const uint64_t& point();
21-
WP<CSyncTimeline> timeline();
22-
Hyprutils::Memory::CUniquePointer<CSyncReleaser> createSyncRelease();
23-
bool addWaiter(const std::function<void()>& waiter);
24-
bool comitted();
25-
Hyprutils::OS::CFileDescriptor exportAsFD();
26-
void signal();
19+
const uint64_t& point();
20+
WP<CSyncTimeline> timeline();
21+
bool addWaiter(const std::function<void()>& waiter);
22+
bool comitted();
23+
Hyprutils::OS::CFileDescriptor exportAsFD();
24+
void signal();
2725

2826
operator bool() const {
2927
return m_timeline;

src/protocols/core/Compositor.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "Subcompositor.hpp"
88
#include "../Viewporter.hpp"
99
#include "../../helpers/Monitor.hpp"
10-
#include "../../helpers/sync/SyncReleaser.hpp"
1110
#include "../../managers/eventLoop/EventLoopManager.hpp"
1211
#include "../PresentationTime.hpp"
1312
#include "../DRMSyncobj.hpp"
@@ -526,8 +525,7 @@ void CWLSurfaceResource::commitState(SSurfaceState& state) {
526525
nullptr);
527526
}
528527

529-
// release the buffer if it's synchronous (SHM) as update() has done everything thats needed
530-
// so we can let the app know we're done.
528+
// release the buffer if it's synchronous (SHM) as updateSynchronousTexture() has copied the buffer data to a GPU tex
531529
// if it doesn't have a role, we can't release it yet, in case it gets turned into a cursor.
532530
if (current.buffer && current.buffer->isSynchronous() && role->role() != SURFACE_ROLE_UNASSIGNED)
533531
dropCurrentBuffer();
@@ -580,12 +578,6 @@ void CWLSurfaceResource::presentFeedback(timespec* when, PHLMONITOR pMonitor, bo
580578
else
581579
FEEDBACK->presented();
582580
PROTO::presentation->queueData(FEEDBACK);
583-
584-
if (!pMonitor || !pMonitor->inTimeline || !syncobj)
585-
return;
586-
587-
// attach explicit sync
588-
g_pHyprRenderer->explicitPresented.emplace_back(self.lock());
589581
}
590582

591583
CWLCompositorResource::CWLCompositorResource(SP<CWlCompositor> resource_) : resource(resource_) {

src/protocols/types/Buffer.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "Buffer.hpp"
2+
#include "../DRMSyncobj.hpp"
23

34
IHLBuffer::~IHLBuffer() {
45
if (locked() && resource)
@@ -7,6 +8,11 @@ IHLBuffer::~IHLBuffer() {
78

89
void IHLBuffer::sendRelease() {
910
resource->sendRelease();
11+
for (auto const& point : releasePoints) {
12+
if (point && point->timeline())
13+
point->signal();
14+
}
15+
releasePoints.clear();
1016
}
1117

1218
void IHLBuffer::lock() {
@@ -18,10 +24,8 @@ void IHLBuffer::unlock() {
1824

1925
ASSERT(nLocks >= 0);
2026

21-
if (nLocks == 0) {
27+
if (nLocks == 0)
2228
sendRelease();
23-
syncReleaser.reset();
24-
}
2529
}
2630

2731
bool IHLBuffer::locked() {
@@ -40,6 +44,12 @@ void IHLBuffer::onBackendRelease(const std::function<void()>& fn) {
4044
});
4145
}
4246

47+
void IHLBuffer::addReleasePoint(UP<CDRMSyncPointState> point) {
48+
ASSERT(locked());
49+
if (point && point->timeline())
50+
releasePoints.push_back(std::move(point));
51+
}
52+
4353
CHLBufferReference::CHLBufferReference() : buffer(nullptr) {
4454
;
4555
}

src/protocols/types/Buffer.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@ class IHLBuffer : public Aquamarine::IBuffer {
2424
virtual bool locked();
2525

2626
void onBackendRelease(const std::function<void()>& fn);
27+
void addReleasePoint(UP<CDRMSyncPointState> point);
2728

2829
SP<CTexture> texture;
2930
bool opaque = false;
3031
SP<CWLBufferResource> resource;
31-
UP<CSyncReleaser> syncReleaser;
3232

3333
struct {
3434
CHyprSignalListener backendRelease;
3535
CHyprSignalListener backendRelease2; // for explicit ds
3636
} hlEvents;
3737

3838
private:
39-
int nLocks = 0;
39+
std::vector<UP<CDRMSyncPointState>> releasePoints;
40+
int nLocks = 0;
4041

4142
friend class CHLBufferReference;
4243
};

src/render/Renderer.cpp

+7-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "Renderer.hpp"
22
#include "../Compositor.hpp"
33
#include "../helpers/math/Math.hpp"
4-
#include "../helpers/sync/SyncReleaser.hpp"
54
#include <algorithm>
65
#include <aquamarine/output/Output.hpp>
76
#include <filesystem>
@@ -1543,25 +1542,6 @@ bool CHyprRenderer::commitPendingAndDoExplicitSync(PHLMONITOR pMonitor) {
15431542
}
15441543
}
15451544

1546-
auto explicitOptions = getExplicitSyncSettings(pMonitor->output);
1547-
if (!explicitOptions.explicitEnabled)
1548-
return ok;
1549-
1550-
Debug::log(TRACE, "Explicit: {} presented", explicitPresented.size());
1551-
1552-
if (!pMonitor->eglSync)
1553-
Debug::log(TRACE, "Explicit: can't add sync, monitor has no EGLSync");
1554-
else {
1555-
for (auto const& e : explicitPresented) {
1556-
if (!e->current.buffer || !e->current.buffer->syncReleaser)
1557-
continue;
1558-
1559-
e->current.buffer->syncReleaser->addReleaseSync(pMonitor->eglSync);
1560-
}
1561-
}
1562-
1563-
explicitPresented.clear();
1564-
15651545
return ok;
15661546
}
15671547

@@ -2290,6 +2270,11 @@ void CHyprRenderer::endRender() {
22902270
return;
22912271
}
22922272

2273+
// release all CHLBufferRefernce (with buf locks) when EGLSync is signalled,
2274+
// meaning that when opengl rendering is done we send release for all used buffers
2275+
PMONITOR->inTimeline->addWaiter([prevbfs = std::move(usedBuffers)]() mutable { prevbfs.clear(); }, PMONITOR->inTimelinePoint, 0u);
2276+
usedBuffers.clear();
2277+
22932278
if (m_eRenderMode == RENDER_MODE_NORMAL && explicitOptions.explicitKMSEnabled) {
22942279
PMONITOR->inFence = CFileDescriptor{PMONITOR->inTimeline->exportAsSyncFileFD(PMONITOR->inTimelinePoint)};
22952280
if (!PMONITOR->inFence.isValid()) {
@@ -2304,6 +2289,8 @@ void CHyprRenderer::endRender() {
23042289
glFinish();
23052290
else
23062291
glFlush();
2292+
2293+
usedBuffers.clear();
23072294
}
23082295
}
23092296

src/render/Renderer.hpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,20 @@ class CHyprRenderer {
9090

9191
bool m_bBlockSurfaceFeedback = false;
9292
bool m_bRenderingSnapshot = false;
93-
PHLMONITORREF m_pMostHzMonitor;
94-
bool m_bDirectScanoutBlocked = false;
93+
PHLMONITORREF m_pMostHzMonitor;
94+
bool m_bDirectScanoutBlocked = false;
9595

96-
void setSurfaceScanoutMode(SP<CWLSurfaceResource> surface, PHLMONITOR monitor); // nullptr monitor resets
97-
void initiateManualCrash();
96+
void setSurfaceScanoutMode(SP<CWLSurfaceResource> surface, PHLMONITOR monitor); // nullptr monitor resets
97+
void initiateManualCrash();
9898

99-
bool m_bCrashingInProgress = false;
100-
float m_fCrashingDistort = 0.5f;
101-
wl_event_source* m_pCrashingLoop = nullptr;
102-
wl_event_source* m_pCursorTicker = nullptr;
99+
bool m_bCrashingInProgress = false;
100+
float m_fCrashingDistort = 0.5f;
101+
wl_event_source* m_pCrashingLoop = nullptr;
102+
wl_event_source* m_pCursorTicker = nullptr;
103103

104-
CTimer m_tRenderTimer;
104+
CTimer m_tRenderTimer;
105105

106-
std::vector<SP<CWLSurfaceResource>> explicitPresented;
106+
std::vector<CHLBufferReference> usedBuffers;
107107

108108
struct {
109109
int hotspotX = 0;

src/render/pass/SurfacePassElement.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ void CSurfacePassElement::draw(const CRegion& damage) {
129129
if (!g_pHyprRenderer->m_bBlockSurfaceFeedback)
130130
data.surface->presentFeedback(data.when, data.pMonitor->self.lock());
131131

132+
// add async (dmabuf) buffers to usedBuffers so we can handle release later
133+
// sync (shm) buffers will be released in commitState, so no need to track them here
134+
if (data.surface->current.buffer && !data.surface->current.buffer->isSynchronous())
135+
g_pHyprRenderer->usedBuffers.emplace_back(data.surface->current.buffer);
136+
132137
g_pHyprOpenGL->blend(true);
133138
}
134139

0 commit comments

Comments
 (0)