tearing: cleanup vars and avoid rendering before drm is ready

This commit is contained in:
vaxerski 2023-09-30 17:07:50 +01:00
parent e2b72b2975
commit a2a29a60e5
6 changed files with 37 additions and 33 deletions

View file

@ -72,7 +72,7 @@ std::string monitorsRequest(HyprCtl::eHyprCtlOutputFormat format) {
m->specialWorkspaceID, escapeJSONStrings(getWorkspaceNameFromSpecialID(m->specialWorkspaceID)), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, m->specialWorkspaceID, escapeJSONStrings(getWorkspaceNameFromSpecialID(m->specialWorkspaceID)), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y,
(int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "true" : "false"), (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "true" : "false"),
(m->dpmsStatus ? "true" : "false"), (m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED ? "true" : "false"), (m->dpmsStatus ? "true" : "false"), (m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED ? "true" : "false"),
m->activelyTearing ? "true" : "false"); m->tearingState.activelyTearing ? "true" : "false");
} }
trimTrailingComma(result); trimTrailingComma(result);
@ -93,7 +93,7 @@ std::string monitorsRequest(HyprCtl::eHyprCtlOutputFormat format) {
(m->output->serial ? m->output->serial : ""), m->activeWorkspace, g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName, m->specialWorkspaceID, (m->output->serial ? m->output->serial : ""), m->activeWorkspace, g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName, m->specialWorkspaceID,
getWorkspaceNameFromSpecialID(m->specialWorkspaceID), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, getWorkspaceNameFromSpecialID(m->specialWorkspaceID), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x,
(int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus,
(int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED), m->activelyTearing); (int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED), m->tearingState.activelyTearing);
} }
} }

View file

@ -149,19 +149,22 @@ void Events::listener_monitorFrame(void* owner, void* data) {
if (!PMONITOR->m_bEnabled) if (!PMONITOR->m_bEnabled)
return; return;
if (PMONITOR->ignoreNextFlipEvent) { PMONITOR->tearingState.busy = false;
PMONITOR->ignoreNextFlipEvent = false;
return;
}
PMONITOR->renderingFromVblankEvent = true; if (PMONITOR->tearingState.activelyTearing) {
if (!PMONITOR->tearingState.frameScheduledWhileBusy)
return; // we did not schedule a frame yet to be displayed, but we are tearing. Why render?
PMONITOR->tearingState.nextRenderTorn = true;
}
static auto* const PENABLERAT = &g_pConfigManager->getConfigValuePtr("misc:render_ahead_of_time")->intValue; static auto* const PENABLERAT = &g_pConfigManager->getConfigValuePtr("misc:render_ahead_of_time")->intValue;
static auto* const PRATSAFE = &g_pConfigManager->getConfigValuePtr("misc:render_ahead_safezone")->intValue; static auto* const PRATSAFE = &g_pConfigManager->getConfigValuePtr("misc:render_ahead_safezone")->intValue;
PMONITOR->lastPresentationTimer.reset(); PMONITOR->lastPresentationTimer.reset();
if (*PENABLERAT) { if (*PENABLERAT && !PMONITOR->tearingState.nextRenderTorn) {
if (!PMONITOR->RATScheduled) { if (!PMONITOR->RATScheduled) {
// render // render
g_pHyprRenderer->renderMonitor(PMONITOR); g_pHyprRenderer->renderMonitor(PMONITOR);
@ -188,8 +191,6 @@ void Events::listener_monitorFrame(void* owner, void* data) {
} else { } else {
g_pHyprRenderer->renderMonitor(PMONITOR); g_pHyprRenderer->renderMonitor(PMONITOR);
} }
PMONITOR->renderingFromVblankEvent = false;
} }
void Events::listener_monitorDestroy(void* owner, void* data) { void Events::listener_monitorDestroy(void* owner, void* data) {

View file

@ -40,7 +40,7 @@ void CMonitor::onConnect(bool noRule) {
hyprListener_monitorCommit.initCallback(&output->events.commit, &Events::listener_monitorCommit, this); hyprListener_monitorCommit.initCallback(&output->events.commit, &Events::listener_monitorCommit, this);
hyprListener_monitorBind.initCallback(&output->events.bind, &Events::listener_monitorBind, this); hyprListener_monitorBind.initCallback(&output->events.bind, &Events::listener_monitorBind, this);
canTear = wlr_backend_is_drm(output->backend); // tearing only works on drm tearingState.canTear = wlr_backend_is_drm(output->backend); // tearing only works on drm
if (m_bEnabled) { if (m_bEnabled) {
wlr_output_enable(output, 1); wlr_output_enable(output, 1);

View file

@ -82,12 +82,16 @@ class CMonitor {
CRegion lastFrameDamage; // stores last frame damage CRegion lastFrameDamage; // stores last frame damage
// for tearing // for tearing
CWindow* solitaryClient = nullptr; CWindow* solitaryClient = nullptr;
bool canTear = false;
bool nextRenderTorn = false; struct {
bool ignoreNextFlipEvent = false; bool canTear = false;
bool renderingFromVblankEvent = false; bool nextRenderTorn = false;
bool activelyTearing = false; bool activelyTearing = false;
bool busy = false;
bool frameScheduledWhileBusy = false;
} tearingState;
// for the special workspace. 0 means not open. // for the special workspace. 0 means not open.
int specialWorkspaceID = 0; int specialWorkspaceID = 0;

View file

@ -249,14 +249,19 @@ void Events::listener_commitSubsurface(void* owner, void* data) {
if (pNode->pWindowOwner) { if (pNode->pWindowOwner) {
// tearing: if solitary, redraw it. This still might be a single surface window // tearing: if solitary, redraw it. This still might be a single surface window
const auto PMONITOR = g_pCompositor->getMonitorFromID(pNode->pWindowOwner->m_iMonitorID); const auto PMONITOR = g_pCompositor->getMonitorFromID(pNode->pWindowOwner->m_iMonitorID);
if (PMONITOR->solitaryClient == pNode->pWindowOwner && pNode->pWindowOwner->canBeTorn() && PMONITOR->canTear) { if (PMONITOR->solitaryClient == pNode->pWindowOwner && pNode->pWindowOwner->canBeTorn() && PMONITOR->tearingState.canTear) {
CRegion damageBox; CRegion damageBox;
wlr_surface_get_effective_damage(pNode->pSurface->wlr(), damageBox.pixman()); wlr_surface_get_effective_damage(pNode->pSurface->wlr(), damageBox.pixman());
if (!damageBox.empty()) { if (!damageBox.empty()) {
PMONITOR->nextRenderTorn = true;
g_pHyprRenderer->renderMonitor(PMONITOR); if (PMONITOR->tearingState.busy) {
PMONITOR->tearingState.frameScheduledWhileBusy = true;
} else {
PMONITOR->tearingState.nextRenderTorn = true;
g_pHyprRenderer->renderMonitor(PMONITOR);
}
} }
} }
} }

View file

@ -846,10 +846,9 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
// tearing and DS first // tearing and DS first
bool shouldTear = false; bool shouldTear = false;
bool canTear = *PTEARINGENABLED && g_pHyprOpenGL->m_RenderData.mouseZoomFactor == 1.0;
recheckSolitaryForMonitor(pMonitor); recheckSolitaryForMonitor(pMonitor);
if (pMonitor->nextRenderTorn) { if (pMonitor->tearingState.nextRenderTorn) {
pMonitor->nextRenderTorn = false; pMonitor->tearingState.nextRenderTorn = false;
if (!*PTEARINGENABLED) { if (!*PTEARINGENABLED) {
Debug::log(WARN, "Tearing commit requested but the master switch general:allow_tearing is off, ignoring"); Debug::log(WARN, "Tearing commit requested but the master switch general:allow_tearing is off, ignoring");
@ -861,18 +860,13 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
return; return;
} }
if (!pMonitor->canTear) { if (!pMonitor->tearingState.canTear) {
Debug::log(WARN, "Tearing commit requested but monitor doesn't support it, ignoring"); Debug::log(WARN, "Tearing commit requested but monitor doesn't support it, ignoring");
return; return;
} }
if (pMonitor->solitaryClient) if (pMonitor->solitaryClient)
shouldTear = true; shouldTear = true;
} else {
// if this is a non-tearing commit, and we are in a state where we should tear
// then this is a vblank commit that we should ignore
if (canTear && pMonitor->solitaryClient && pMonitor->canTear && pMonitor->solitaryClient->canBeTorn() && pMonitor->renderingFromVblankEvent)
return;
} }
if (!*PNODIRECTSCANOUT && !shouldTear) { if (!*PNODIRECTSCANOUT && !shouldTear) {
@ -884,12 +878,12 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
} }
} }
if (pMonitor->activelyTearing != shouldTear) { if (pMonitor->tearingState.activelyTearing != shouldTear) {
// change of state // change of state
pMonitor->activelyTearing = shouldTear; pMonitor->tearingState.activelyTearing = shouldTear;
for (auto& m : g_pCompositor->m_vMonitors) { for (auto& m : g_pCompositor->m_vMonitors) {
wlr_output_lock_software_cursors(m->output, pMonitor->activelyTearing); wlr_output_lock_software_cursors(m->output, pMonitor->tearingState.activelyTearing);
} }
} }
@ -1090,7 +1084,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) {
} }
if (shouldTear) if (shouldTear)
pMonitor->ignoreNextFlipEvent = true; pMonitor->tearingState.busy = true;
wlr_damage_ring_rotate(&pMonitor->damage); wlr_damage_ring_rotate(&pMonitor->damage);