From 855b1cba40ab972dc7c03ccd76ff5aacbeed099d Mon Sep 17 00:00:00 2001 From: Pppp1116 Date: Thu, 26 Mar 2026 00:08:49 +0000 Subject: renderer: small fixes in OpenGL.cpp and OpenGL.hpp (#13842) * render: add EGL error details to dmabuf query failures * linux-dmabuf: tighten plane modifier checks and feedback safety --- src/protocols/LinuxDMABUF.cpp | 12 +++++++----- src/render/OpenGL.cpp | 30 +++++++++++++++++++++--------- src/render/OpenGL.hpp | 2 +- 3 files changed, 29 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/protocols/LinuxDMABUF.cpp b/src/protocols/LinuxDMABUF.cpp index 0a395a1f..5013fb99 100644 --- a/src/protocols/LinuxDMABUF.cpp +++ b/src/protocols/LinuxDMABUF.cpp @@ -166,7 +166,8 @@ CLinuxDMABUFParamsResource::CLinuxDMABUFParamsResource(UP(modHi) << 32) | modLo; - if (m_resource->version() >= 5 && m_attrs->modifier && m_attrs->modifier != modifier) { + const bool anyPlaneSet = std::ranges::any_of(m_attrs->fds, [](int planeFD) { return planeFD != -1; }); + if (m_resource->version() >= 5 && anyPlaneSet && m_attrs->modifier != modifier) { r->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT, "planes have different modifiers"); return; } @@ -268,7 +269,7 @@ bool CLinuxDMABUFParamsResource::commence() { uint32_t handle = 0; if (drmPrimeFDToHandle(PROTO::linuxDma->m_mainDeviceFD.get(), m_attrs->fds.at(i), &handle)) { - LOGM(Log::ERR, "Failed to import dmabuf fd"); + LOGM(Log::ERR, "Failed to import dmabuf fd {} on plane {}", m_attrs->fds.at(i), i); return false; } @@ -311,10 +312,11 @@ bool CLinuxDMABUFParamsResource::verify() { } for (size_t i = 0; i < sc(m_attrs->planes); ++i) { - if (sc(m_attrs->offsets.at(i)) + sc(m_attrs->strides.at(i)) * m_attrs->size.y > UINT32_MAX) { + const auto computedSize = sc(m_attrs->offsets.at(i)) + sc(m_attrs->strides.at(i)) * m_attrs->size.y; + if (computedSize > UINT32_MAX) { m_resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS, std::format("size overflow on plane {}: offset {} + stride {} * height {} = {}, overflows UINT32_MAX", i, sc(m_attrs->offsets.at(i)), - sc(m_attrs->strides.at(i)), m_attrs->size.y, sc(m_attrs->offsets.at(i)) + sc(m_attrs->strides.at(i)))); + sc(m_attrs->strides.at(i)), m_attrs->size.y, computedSize)); return false; } } @@ -349,7 +351,7 @@ void CLinuxDMABUFFeedbackResource::sendTranche(SDMABUFTranche& tranche) { m_resource->sendTrancheFlags(sc(tranche.flags)); wl_array indices = { - .size = tranche.indices.size() * sizeof(tranche.indices.at(0)), + .size = tranche.indices.size() * sizeof(std::vector::value_type), .data = tranche.indices.data(), }; m_resource->sendTrancheFormats(&indices); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index d466dc82..16e892ca 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -120,7 +120,7 @@ static int openRenderNode(int drmFd) { drmVersion* render_version = drmGetVersion(drmFd); if (render_version && render_version->name) { - Log::logger->log(Log::DEBUG, "DRM dev versionName", render_version->name); + Log::logger->log(Log::DEBUG, "DRM dev versionName {}", render_version->name); if (strcmp(render_version->name, "evdi") == 0) { free(renderName); // NOLINT(cppcoreguidelines-no-malloc) renderName = strdup("/dev/dri/card0"); @@ -409,14 +409,14 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() : m_drmFD(g_pCompositor->m_drmRenderNode.fd > m_pressedHistoryKilled <<= 1; m_pressedHistoryKilled |= killing ? 1 : 0; #if POINTER_PRESSED_HISTORY_LENGTH < 32 - m_pressedHistoryKilled &= (1 >> POINTER_PRESSED_HISTORY_LENGTH) - 1; + m_pressedHistoryKilled &= (1U << POINTER_PRESSED_HISTORY_LENGTH) - 1; #endif // shift touch flag in m_pressedHistoryTouched <<= 1; m_pressedHistoryTouched |= touch ? 1 : 0; #if POINTER_PRESSED_HISTORY_LENGTH < 32 - m_pressedHistoryTouched &= (1 >> POINTER_PRESSED_HISTORY_LENGTH) - 1; + m_pressedHistoryTouched &= (1U << POINTER_PRESSED_HISTORY_LENGTH) - 1; #endif }; @@ -474,7 +474,11 @@ std::optional> CHyprOpenGLImpl::getModsForFormat(EGLint fo mods.resize(len); external.resize(len); - m_proc.eglQueryDmaBufModifiersEXT(m_eglDisplay, format, len, mods.data(), external.data(), &len); + if (!m_proc.eglQueryDmaBufModifiersEXT(m_eglDisplay, format, len, mods.data(), external.data(), &len)) { + const auto err = eglGetError(); + Log::logger->log(Log::ERR, "EGL: Failed to query mods (2) for format 0x{:x}, eglGetError: 0x{:x}", format, err); + return std::nullopt; + } std::vector result; // reserve number of elements to avoid reallocations @@ -516,9 +520,17 @@ void CHyprOpenGLImpl::initDRMFormats() { Log::logger->log(Log::WARN, "EGL: No mod support"); } else { EGLint len = 0; - m_proc.eglQueryDmaBufFormatsEXT(m_eglDisplay, 0, nullptr, &len); + if (!m_proc.eglQueryDmaBufFormatsEXT(m_eglDisplay, 0, nullptr, &len)) { + const auto err = eglGetError(); + Log::logger->log(Log::ERR, "EGL: Failed to query formats, eglGetError: 0x{:x}", err); + return; + } formats.resize(len); - m_proc.eglQueryDmaBufFormatsEXT(m_eglDisplay, len, formats.data(), &len); + if (!m_proc.eglQueryDmaBufFormatsEXT(m_eglDisplay, len, formats.data(), &len)) { + const auto err = eglGetError(); + Log::logger->log(Log::ERR, "EGL: Failed to query formats (2), eglGetError: 0x{:x}", err); + return; + } } if (formats.empty()) { @@ -750,6 +762,7 @@ void CHyprOpenGLImpl::begin(PHLMONITOR pMonitor, const CRegion& damage_, SP("cursor:zoom_disable_aa"); auto& m_renderData = g_pHyprRenderer->m_renderData; + const auto PMONITOR = m_renderData.pMonitor; TRACY_GPU_ZONE("RenderEnd"); g_pHyprRenderer->m_renderData.currentWindow.reset(); @@ -825,9 +838,8 @@ void CHyprOpenGLImpl::end() { // if we dropped to offMain, release it now. // if there is a plugin constantly using it, this might be a bit slow, // but I haven't seen a single plugin yet use these, so it's better to drop a bit of vram. - if UNLIKELY (g_pHyprRenderer->m_renderData.pMonitor && g_pHyprRenderer->m_renderData.pMonitor->m_offMainFB && - g_pHyprRenderer->m_renderData.pMonitor->m_offMainFB->isAllocated()) - g_pHyprRenderer->m_renderData.pMonitor->m_offMainFB->release(); + if UNLIKELY (PMONITOR && PMONITOR->m_offMainFB && PMONITOR->m_offMainFB->isAllocated()) + PMONITOR->m_offMainFB->release(); static const auto GLDEBUG = CConfigValue("debug:gl_debugging"); diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index 66339fdb..e92d4822 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -342,7 +342,7 @@ class CHyprOpenGLImpl { bool m_cmSupported = true; SP m_finalScreenShader; - GLuint m_currentProgram; + GLuint m_currentProgram = 0; void initDRMFormats(); void initEGL(bool gbm); -- cgit v1.2.3