From 9e74d0aea7614eaf238ef07261129026572337e7 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 15 Sep 2025 12:44:12 +0100 Subject: [PATCH] renderer: clamp blur:passes 1-8 fixes some UB and dumb things ref #11707 --- src/render/OpenGL.cpp | 10 ++++++---- src/render/pass/Pass.cpp | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 9f51abaf..c5ba69a1 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -1848,11 +1848,13 @@ CFramebuffer* CHyprOpenGLImpl::blurFramebufferWithDamage(float a, CRegion* origi static auto PBLURVIBRANCY = CConfigValue("decoration:blur:vibrancy"); static auto PBLURVIBRANCYDARKNESS = CConfigValue("decoration:blur:vibrancy_darkness"); + const auto BLUR_PASSES = std::clamp(*PBLURPASSES, sc(1), sc(8)); + // prep damage CRegion damage{*originalDamage}; damage.transform(wlTransformToHyprutils(invertTransform(m_renderData.pMonitor->m_transform)), m_renderData.pMonitor->m_transformedSize.x, m_renderData.pMonitor->m_transformedSize.y); - damage.expand(*PBLURPASSES > 10 ? pow(2, 15) : std::clamp(*PBLURSIZE, sc(1), sc(40)) * pow(2, *PBLURPASSES)); + damage.expand(std::clamp(*PBLURSIZE, sc(1), sc(40)) * pow(2, BLUR_PASSES)); // helper const auto PMIRRORFB = &m_renderData.pCurrentMonData->mirrorFB; @@ -1934,7 +1936,7 @@ CFramebuffer* CHyprOpenGLImpl::blurFramebufferWithDamage(float a, CRegion* origi pShader->setUniformFloat(SHADER_RADIUS, *PBLURSIZE * a); // this makes the blursize change with a if (pShader == &m_shaders->m_shBLUR1) { m_shaders->m_shBLUR1.setUniformFloat2(SHADER_HALFPIXEL, 0.5f / (m_renderData.pMonitor->m_pixelSize.x / 2.f), 0.5f / (m_renderData.pMonitor->m_pixelSize.y / 2.f)); - m_shaders->m_shBLUR1.setUniformInt(SHADER_PASSES, *PBLURPASSES); + m_shaders->m_shBLUR1.setUniformInt(SHADER_PASSES, BLUR_PASSES); m_shaders->m_shBLUR1.setUniformFloat(SHADER_VIBRANCY, *PBLURVIBRANCY); m_shaders->m_shBLUR1.setUniformFloat(SHADER_VIBRANCY_DARKNESS, *PBLURVIBRANCYDARKNESS); } else @@ -1967,12 +1969,12 @@ CFramebuffer* CHyprOpenGLImpl::blurFramebufferWithDamage(float a, CRegion* origi CRegion tempDamage{damage}; // and draw - for (auto i = 1; i <= *PBLURPASSES; ++i) { + for (auto i = 1; i <= BLUR_PASSES; ++i) { tempDamage = damage.copy().scale(1.f / (1 << i)); drawPass(&m_shaders->m_shBLUR1, &tempDamage); // down } - for (auto i = *PBLURPASSES - 1; i >= 0; --i) { + for (auto i = BLUR_PASSES - 1; i >= 0; --i) { tempDamage = damage.copy().scale(1.f / (1 << i)); // when upsampling we make the region twice as big drawPass(&m_shaders->m_shBLUR2, &tempDamage); // up } diff --git a/src/render/pass/Pass.cpp b/src/render/pass/Pass.cpp index f7ee6a71..3e14d787 100644 --- a/src/render/pass/Pass.cpp +++ b/src/render/pass/Pass.cpp @@ -294,7 +294,10 @@ float CRenderPass::oneBlurRadius() { // TODO: is this exact range correct? static auto PBLURSIZE = CConfigValue("decoration:blur:size"); static auto PBLURPASSES = CConfigValue("decoration:blur:passes"); - return *PBLURPASSES > 10 ? pow(2, 15) : std::clamp(*PBLURSIZE, sc(1), sc(40)) * pow(2, *PBLURPASSES); // is this 2^pass? I don't know but it works... I think. + + const auto BLUR_PASSES = std::clamp(*PBLURPASSES, sc(1), sc(8)); + + return std::clamp(*PBLURSIZE, sc(1), sc(40)) * pow(2, BLUR_PASSES); // is this 2^pass? I don't know but it works... I think. } void CRenderPass::removeAllOfType(const std::string& type) {