From cca0f48b74e87f86244f5773c42d9ade84683f3b Mon Sep 17 00:00:00 2001 From: vaxerski Date: Tue, 18 Mar 2025 11:30:01 +0000 Subject: [PATCH] renderer: add an option to disable cm and auto-skip cm if not necessary fixes #9641 adds render:cm_enabled default true --- src/config/ConfigDescriptions.hpp | 6 ++++++ src/config/ConfigManager.cpp | 1 + src/managers/ProtocolManager.cpp | 10 +++++++--- src/render/OpenGL.cpp | 15 ++++++++++----- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index cdb69446c..1cfbf0e1a 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -1378,6 +1378,12 @@ inline static const std::vector CONFIG_OPTIONS = { .type = CONFIG_OPTION_BOOL, .data = SConfigOptionDescription::SBoolData{true}, }, + SConfigOptionDescription{ + .value = "render:cm_enabled", + .description = "Enable Color Management pipelines (requires restart to fully take effect)", + .type = CONFIG_OPTION_BOOL, + .data = SConfigOptionDescription::SBoolData{true}, + }, /* * cursor: diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 1c36876d0..82fe2d418 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -692,6 +692,7 @@ CConfigManager::CConfigManager() { registerConfigVar("render:xp_mode", Hyprlang::INT{0}); registerConfigVar("render:ctm_animation", Hyprlang::INT{2}); registerConfigVar("render:cm_fs_passthrough", Hyprlang::INT{1}); + registerConfigVar("render:cm_enabled", Hyprlang::INT{1}); registerConfigVar("ecosystem:no_update_news", Hyprlang::INT{0}); registerConfigVar("ecosystem:no_donation_nag", Hyprlang::INT{0}); diff --git a/src/managers/ProtocolManager.cpp b/src/managers/ProtocolManager.cpp index 992ace204..06987daeb 100644 --- a/src/managers/ProtocolManager.cpp +++ b/src/managers/ProtocolManager.cpp @@ -98,6 +98,7 @@ void CProtocolManager::onMonitorModeChange(PHLMONITOR pMonitor) { CProtocolManager::CProtocolManager() { static const auto PENABLEEXPLICIT = CConfigValue("render:explicit_sync"); + static const auto PENABLECM = CConfigValue("render:cm_enabled"); static const auto PENABLEXXCM = CConfigValue("experimental:xx_color_management_v4"); static const auto PDEBUGCM = CConfigValue("debug:full_cm_proto"); @@ -181,14 +182,17 @@ CProtocolManager::CProtocolManager() { PROTO::ctm = makeUnique(&hyprland_ctm_control_manager_v1_interface, 2, "CTMControl"); PROTO::hyprlandSurface = makeUnique(&hyprland_surface_manager_v1_interface, 2, "HyprlandSurface"); PROTO::contentType = makeUnique(&wp_content_type_manager_v1_interface, 1, "ContentType"); - PROTO::colorManagement = makeUnique(&wp_color_manager_v1_interface, 1, "ColorManagement", *PDEBUGCM); - // please read the top of this file before adding another protocol - if (*PENABLEXXCM) { + if (*PENABLECM) + PROTO::colorManagement = makeUnique(&wp_color_manager_v1_interface, 1, "ColorManagement", *PDEBUGCM); + + if (*PENABLEXXCM && *PENABLECM) { PROTO::xxColorManagement = makeUnique(&xx_color_manager_v4_interface, 1, "XXColorManagement"); PROTO::frogColorManagement = makeUnique(&frog_color_management_factory_v1_interface, 1, "FrogColorManagement"); } + // ! please read the top of this file before adding another protocol + for (auto const& b : g_pCompositor->m_pAqBackend->getImplementations()) { if (b->type() != Aquamarine::AQ_BACKEND_DRM) continue; diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 137e4a8f2..e2f72fff9 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -1320,8 +1320,9 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(SP tex, const CB CBox newBox = box; m_RenderData.renderModif.applyToBox(newBox); - static auto PDT = CConfigValue("debug:damage_tracking"); - static auto PPASS = CConfigValue("render:cm_fs_passthrough"); + static const auto PDT = CConfigValue("debug:damage_tracking"); + static const auto PPASS = CConfigValue("render:cm_fs_passthrough"); + static const auto PENABLECM = CConfigValue("render:cm_enabled"); // get the needed transform for this texture const bool TRANSFORMS_MATCH = wlTransformToHyprutils(m_RenderData.pMonitor->transform) == tex->m_eTransform; // FIXME: combine them properly!!! @@ -1378,8 +1379,12 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(SP tex, const CB glTexParameteri(tex->m_iTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } - const bool skipCM = !m_RenderData.surface /* No surface - no point in CM */ - || !m_bCMSupported /* CM unsupported - hw failed to compile the shader probably */ + const bool SURFACE_HAS_CM = m_RenderData.surface && m_RenderData.surface->colorManagement && m_RenderData.surface->colorManagement->hasImageDescription(); + + const bool skipCM = !*PENABLECM /* CM disabled by the user */ + || !m_RenderData.surface /* No surface - no point in CM */ + || !m_bCMSupported /* CM unsupported - hw failed to compile the shader probably */ + || (!SURFACE_HAS_CM && m_RenderData.pMonitor->imageDescription == SImageDescription{}) /* Surface doesn't have CM and monitor isn't CM'd */ || (*PPASS && m_RenderData.pMonitor->activeWorkspace && m_RenderData.pMonitor->activeWorkspace->m_bHasFullscreenWindow && m_RenderData.pMonitor->activeWorkspace->m_efFullscreenMode == FSMODE_FULLSCREEN) /* Fullscreen window with pass cm enabled */; @@ -1391,7 +1396,7 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(SP tex, const CB glUseProgram(shader->program); glUniform1i(shader->texType, texType); const auto imageDescription = - m_RenderData.surface.valid() && m_RenderData.surface->colorManagement.valid() ? m_RenderData.surface->colorManagement->imageDescription() : SImageDescription{}; + m_RenderData.surface && m_RenderData.surface->colorManagement ? m_RenderData.surface->colorManagement->imageDescription() : SImageDescription{}; glUniform1i(shader->sourceTF, imageDescription.transferFunction); glUniform1i(shader->targetTF, m_RenderData.pMonitor->imageDescription.transferFunction); const auto sourcePrimaries =