renderer: clamp blur:passes 1-8

fixes some UB and dumb things

ref #11707
This commit is contained in:
Vaxry 2025-09-15 12:44:12 +01:00
parent 559024c331
commit 9e74d0aea7
No known key found for this signature in database
GPG key ID: 665806380871D640
2 changed files with 10 additions and 5 deletions

View file

@ -1848,11 +1848,13 @@ CFramebuffer* CHyprOpenGLImpl::blurFramebufferWithDamage(float a, CRegion* origi
static auto PBLURVIBRANCY = CConfigValue<Hyprlang::FLOAT>("decoration:blur:vibrancy");
static auto PBLURVIBRANCYDARKNESS = CConfigValue<Hyprlang::FLOAT>("decoration:blur:vibrancy_darkness");
const auto BLUR_PASSES = std::clamp(*PBLURPASSES, sc<int64_t>(1), sc<int64_t>(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<int64_t>(1), sc<int64_t>(40)) * pow(2, *PBLURPASSES));
damage.expand(std::clamp(*PBLURSIZE, sc<int64_t>(1), sc<int64_t>(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
}

View file

@ -294,7 +294,10 @@ float CRenderPass::oneBlurRadius() {
// TODO: is this exact range correct?
static auto PBLURSIZE = CConfigValue<Hyprlang::INT>("decoration:blur:size");
static auto PBLURPASSES = CConfigValue<Hyprlang::INT>("decoration:blur:passes");
return *PBLURPASSES > 10 ? pow(2, 15) : std::clamp(*PBLURSIZE, sc<int64_t>(1), sc<int64_t>(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<int64_t>(1), sc<int64_t>(8));
return std::clamp(*PBLURSIZE, sc<int64_t>(1), sc<int64_t>(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) {