renderer: nvidia checks and use glFinish on nvidia

fixes #3952 #3946
This commit is contained in:
Vaxry 2023-11-25 17:45:08 +00:00
parent 3fe6162af1
commit 6f733292bf
3 changed files with 51 additions and 2 deletions

View file

@ -99,7 +99,6 @@ set(CMAKE_ENABLE_EXPORTS TRUE)
message(STATUS "Checking deps...") message(STATUS "Checking deps...")
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
find_package(PkgConfig REQUIRED) find_package(PkgConfig REQUIRED)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-server wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1) # we do not check for wlroots, as we provide it ourselves pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-server wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1) # we do not check for wlroots, as we provide it ourselves

View file

@ -4,11 +4,51 @@
#include "../helpers/Region.hpp" #include "../helpers/Region.hpp"
#include <algorithm> #include <algorithm>
extern "C" {
#include <xf86drm.h>
}
CHyprRenderer::CHyprRenderer() { CHyprRenderer::CHyprRenderer() {
const auto ENV = getenv("WLR_DRM_NO_ATOMIC"); const auto ENV = getenv("WLR_DRM_NO_ATOMIC");
if (ENV && std::string(ENV) == "1") if (ENV && std::string(ENV) == "1")
m_bTearingEnvSatisfied = true; m_bTearingEnvSatisfied = true;
if (g_pCompositor->m_sWLRSession) {
wlr_device* dev;
wl_list_for_each(dev, &g_pCompositor->m_sWLRSession->devices, link) {
const auto DRMV = drmGetVersion(dev->fd);
std::string name = std::string{DRMV->name, DRMV->name_len};
std::transform(name.begin(), name.end(), name.begin(), tolower);
if (name.contains("nvidia"))
m_bNvidia = true;
Debug::log(LOG, "DRM driver information: {} v{}.{}.{} from {} description {}", name, DRMV->version_major, DRMV->version_minor, DRMV->version_patchlevel,
std::string{DRMV->date, DRMV->date_len}, std::string{DRMV->desc, DRMV->desc_len});
drmFreeVersion(DRMV);
}
} else {
Debug::log(LOG, "m_sWLRSession is null, omitting full DRM node checks");
const auto DRMV = drmGetVersion(g_pCompositor->m_iDRMFD);
std::string name = std::string{DRMV->name, DRMV->name_len};
std::transform(name.begin(), name.end(), name.begin(), tolower);
if (name.contains("nvidia"))
m_bNvidia = true;
Debug::log(LOG, "Primary DRM driver information: {} v{}.{}.{} from {} description {}", name, DRMV->version_major, DRMV->version_minor, DRMV->version_patchlevel,
std::string{DRMV->date, DRMV->date_len}, std::string{DRMV->desc, DRMV->desc_len});
drmFreeVersion(DRMV);
}
if (m_bNvidia)
Debug::log(WARN, "NVIDIA detected, please remember to follow nvidia instructions on the wiki");
} }
void renderSurface(struct wlr_surface* surface, int x, int y, void* data) { void renderSurface(struct wlr_surface* surface, int x, int y, void* data) {
@ -2284,7 +2324,10 @@ void CHyprRenderer::endRender() {
return; return;
} }
glFlush(); if (isNvidia())
glFinish();
else
glFlush();
if (m_eRenderMode == RENDER_MODE_NORMAL) if (m_eRenderMode == RENDER_MODE_NORMAL)
wlr_output_state_set_buffer(&PMONITOR->output->pending, m_pCurrentWlrBuffer); wlr_output_state_set_buffer(&PMONITOR->output->pending, m_pCurrentWlrBuffer);
@ -2304,4 +2347,8 @@ void CHyprRenderer::onRenderbufferDestroy(CRenderbuffer* rb) {
CRenderbuffer* CHyprRenderer::getCurrentRBO() { CRenderbuffer* CHyprRenderer::getCurrentRBO() {
return m_pCurrentRenderbuffer; return m_pCurrentRenderbuffer;
}
bool CHyprRenderer::isNvidia() {
return m_bNvidia;
} }

View file

@ -69,6 +69,7 @@ class CHyprRenderer {
void renderSoftwareCursors(CMonitor* pMonitor, const CRegion& damage, std::optional<Vector2D> overridePos = {}); void renderSoftwareCursors(CMonitor* pMonitor, const CRegion& damage, std::optional<Vector2D> overridePos = {});
void onRenderbufferDestroy(CRenderbuffer* rb); void onRenderbufferDestroy(CRenderbuffer* rb);
CRenderbuffer* getCurrentRBO(); CRenderbuffer* getCurrentRBO();
bool isNvidia();
bool beginRender(CMonitor* pMonitor, CRegion& damage, eRenderMode mode = RENDER_MODE_NORMAL, wlr_buffer* withBuffer = nullptr); bool beginRender(CMonitor* pMonitor, CRegion& damage, eRenderMode mode = RENDER_MODE_NORMAL, wlr_buffer* withBuffer = nullptr);
void endRender(); void endRender();
@ -121,6 +122,8 @@ class CHyprRenderer {
eRenderMode m_eRenderMode = RENDER_MODE_NORMAL; eRenderMode m_eRenderMode = RENDER_MODE_NORMAL;
int m_iLastBufferAge = 0; int m_iLastBufferAge = 0;
bool m_bNvidia = false;
CRenderbuffer* getOrCreateRenderbuffer(wlr_buffer* buffer, uint32_t fmt); CRenderbuffer* getOrCreateRenderbuffer(wlr_buffer* buffer, uint32_t fmt);
std::vector<std::unique_ptr<CRenderbuffer>> m_vRenderbuffers; std::vector<std::unique_ptr<CRenderbuffer>> m_vRenderbuffers;