Skip to content

Commit

Permalink
fix nvidia crasherino lmao
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Jul 20, 2024
1 parent 360673e commit 9235728
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Compositor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class CCompositor {
bool m_bReadyToProcess = false;
bool m_bSessionActive = true;
bool m_bDPMSStateON = true;
bool m_bUnsafeState = false; // unsafe state is when there is no monitors.
bool m_bUnsafeState = false; // unsafe state is when there is no monitors.
bool m_bNextIsUnsafe = false;
CMonitor* m_pUnsafeOutput = nullptr; // fallback output for the unsafe state
bool m_bExitTriggered = false; // For exit dispatcher
Expand Down
3 changes: 1 addition & 2 deletions src/managers/CursorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ void CCursorManager::setXCursor(const std::string& name) {
return;
}

m_vCursorBuffers.emplace_back(
makeShared<CCursorBuffer>(xcursor.defaultCursor->pixels.data(), xcursor.defaultCursor->size, xcursor.defaultCursor->hotspot));
m_vCursorBuffers.emplace_back(makeShared<CCursorBuffer>(xcursor.defaultCursor->pixels.data(), xcursor.defaultCursor->size, xcursor.defaultCursor->hotspot));

g_pPointerManager->setCursorBuffer(getCursorBuffer(), xcursor.defaultCursor->hotspot / scale, scale);
if (m_vCursorBuffers.size() > 1)
Expand Down
5 changes: 4 additions & 1 deletion src/managers/PointerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ SP<Aquamarine::IBuffer> CPointerManager::renderHWCursorBuffer(SP<CPointerManager
g_pHyprOpenGL->m_RenderData.pMonitor = state->monitor.get();

const auto RBO = g_pHyprRenderer->getOrCreateRenderbuffer(buf, state->monitor->cursorSwapchain->currentOptions().format);
if (!RBO)
return nullptr;

RBO->bind();

g_pHyprOpenGL->beginSimple(state->monitor.get(), damage, RBO);
Expand All @@ -410,7 +413,7 @@ SP<Aquamarine::IBuffer> CPointerManager::renderHWCursorBuffer(SP<CPointerManager
glFlush();
g_pHyprOpenGL->m_RenderData.pMonitor = nullptr;

g_pHyprRenderer->onRenderbufferDestroy(RBO);
g_pHyprRenderer->onRenderbufferDestroy(RBO.get());

return buf;
}
Expand Down
5 changes: 3 additions & 2 deletions src/render/OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) {
return false;
}

void CHyprOpenGLImpl::beginSimple(CMonitor* pMonitor, const CRegion& damage, CRenderbuffer* rb, CFramebuffer* fb) {
void CHyprOpenGLImpl::beginSimple(CMonitor* pMonitor, const CRegion& damage, SP<CRenderbuffer> rb, CFramebuffer* fb) {
m_RenderData.pMonitor = pMonitor;

#ifndef GLES2
Expand Down Expand Up @@ -1558,7 +1558,8 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o

// prep damage
CRegion damage{*originalDamage};
damage.transform(wlTransformToHyprutils(invertTransform(m_RenderData.pMonitor->transform)), m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y);
damage.transform(wlTransformToHyprutils(invertTransform(m_RenderData.pMonitor->transform)), m_RenderData.pMonitor->vecTransformedSize.x,
m_RenderData.pMonitor->vecTransformedSize.y);
damage.expand(*PBLURPASSES > 10 ? pow(2, 15) : std::clamp(*PBLURSIZE, (int64_t)1, (int64_t)40) * pow(2, *PBLURPASSES));

// helper
Expand Down
2 changes: 1 addition & 1 deletion src/render/OpenGL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class CHyprOpenGLImpl {
CHyprOpenGLImpl();

void begin(CMonitor*, const CRegion& damage, CFramebuffer* fb = nullptr, std::optional<CRegion> finalDamage = {});
void beginSimple(CMonitor*, const CRegion& damage, CRenderbuffer* rb = nullptr, CFramebuffer* fb = nullptr);
void beginSimple(CMonitor*, const CRegion& damage, SP<CRenderbuffer> rb = nullptr, CFramebuffer* fb = nullptr);
void end();

void renderRect(CBox*, const CColor&, int round = 0);
Expand Down
18 changes: 14 additions & 4 deletions src/render/Renderbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ CRenderbuffer::CRenderbuffer(SP<Aquamarine::IBuffer> buffer, uint32_t format) :
auto dma = buffer->dmabuf();

m_iImage = g_pHyprOpenGL->createEGLImage(dma);
if (m_iImage == EGL_NO_IMAGE_KHR)
throw std::runtime_error("createEGLImage failed");
if (m_iImage == EGL_NO_IMAGE_KHR) {
Debug::log(ERR, "rb: createEGLImage failed");
return;
}

glGenRenderbuffers(1, &m_iRBO);
glBindRenderbuffer(GL_RENDERBUFFER, m_iRBO);
Expand All @@ -35,12 +37,20 @@ CRenderbuffer::CRenderbuffer(SP<Aquamarine::IBuffer> buffer, uint32_t format) :
m_sFramebuffer.bind();
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_iRBO);

if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
throw std::runtime_error("rbo: glCheckFramebufferStatus failed");
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
Debug::log(ERR, "rbo: glCheckFramebufferStatus failed");
return;
}

glBindFramebuffer(GL_FRAMEBUFFER, 0);

listeners.destroyBuffer = buffer->events.destroy.registerListener([this](std::any d) { g_pHyprRenderer->onRenderbufferDestroy(this); });

m_bGood = true;
}

bool CRenderbuffer::good() {
return m_bGood;
}

void CRenderbuffer::bind() {
Expand Down
2 changes: 2 additions & 0 deletions src/render/Renderbuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CRenderbuffer {
CRenderbuffer(SP<Aquamarine::IBuffer> buffer, uint32_t format);
~CRenderbuffer();

bool good();
void bind();
void bindFB();
void unbind();
Expand All @@ -23,6 +24,7 @@ class CRenderbuffer {
GLuint m_iRBO = 0;
CFramebuffer m_sFramebuffer;
uint32_t m_uDrmFormat = 0;
bool m_bGood = false;

struct {
CHyprSignalListener destroyBuffer;
Expand Down
14 changes: 10 additions & 4 deletions src/render/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2541,13 +2541,19 @@ void CHyprRenderer::recheckSolitaryForMonitor(CMonitor* pMonitor) {
pMonitor->solitaryClient = PCANDIDATE;
}

CRenderbuffer* CHyprRenderer::getOrCreateRenderbuffer(SP<Aquamarine::IBuffer> buffer, uint32_t fmt) {
SP<CRenderbuffer> CHyprRenderer::getOrCreateRenderbuffer(SP<Aquamarine::IBuffer> buffer, uint32_t fmt) {
auto it = std::find_if(m_vRenderbuffers.begin(), m_vRenderbuffers.end(), [&](const auto& other) { return other->m_pHLBuffer == buffer; });

if (it != m_vRenderbuffers.end())
return it->get();
return *it;

return m_vRenderbuffers.emplace_back(std::make_unique<CRenderbuffer>(buffer, fmt)).get();
auto buf = makeShared<CRenderbuffer>(buffer, fmt);

if (!buf->good())
return nullptr;

m_vRenderbuffers.emplace_back(buf);
return buf;
}

void CHyprRenderer::makeEGLCurrent() {
Expand Down Expand Up @@ -2650,7 +2656,7 @@ void CHyprRenderer::onRenderbufferDestroy(CRenderbuffer* rb) {
std::erase_if(m_vRenderbuffers, [&](const auto& rbo) { return rbo.get() == rb; });
}

CRenderbuffer* CHyprRenderer::getCurrentRBO() {
SP<CRenderbuffer> CHyprRenderer::getCurrentRBO() {
return m_pCurrentRenderbuffer;
}

Expand Down
36 changes: 18 additions & 18 deletions src/render/Renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CHyprRenderer {
void setCursorSurface(SP<CWLSurface> surf, int hotspotX, int hotspotY, bool force = false);
void setCursorFromName(const std::string& name, bool force = false);
void onRenderbufferDestroy(CRenderbuffer* rb);
CRenderbuffer* getCurrentRBO();
SP<CRenderbuffer> getCurrentRBO();
bool isNvidia();
void makeEGLCurrent();
void unsetEGL();
Expand Down Expand Up @@ -107,21 +107,21 @@ class CHyprRenderer {
} m_sLastCursorData;

private:
void arrangeLayerArray(CMonitor*, const std::vector<PHLLSREF>&, bool, CBox*);
void renderWorkspaceWindowsFullscreen(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special)
void renderWorkspaceWindows(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special)
void renderWindow(PHLWINDOW, CMonitor*, timespec*, bool, eRenderPassMode, bool ignorePosition = false, bool ignoreAllGeometry = false);
void renderLayer(PHLLS, CMonitor*, timespec*, bool popups = false);
void renderSessionLockSurface(SSessionLockSurface*, CMonitor*, timespec*);
void renderDragIcon(CMonitor*, timespec*);
void renderIMEPopup(CInputPopup*, CMonitor*, timespec*);
void renderWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const CBox& geometry);
void sendFrameEventsToWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now); // sends frame displayed events but doesn't actually render anything
void renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f);

bool m_bCursorHidden = false;
bool m_bCursorHasSurface = false;
CRenderbuffer* m_pCurrentRenderbuffer = nullptr;
void arrangeLayerArray(CMonitor*, const std::vector<PHLLSREF>&, bool, CBox*);
void renderWorkspaceWindowsFullscreen(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special)
void renderWorkspaceWindows(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special)
void renderWindow(PHLWINDOW, CMonitor*, timespec*, bool, eRenderPassMode, bool ignorePosition = false, bool ignoreAllGeometry = false);
void renderLayer(PHLLS, CMonitor*, timespec*, bool popups = false);
void renderSessionLockSurface(SSessionLockSurface*, CMonitor*, timespec*);
void renderDragIcon(CMonitor*, timespec*);
void renderIMEPopup(CInputPopup*, CMonitor*, timespec*);
void renderWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const CBox& geometry);
void sendFrameEventsToWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now); // sends frame displayed events but doesn't actually render anything
void renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f);

bool m_bCursorHidden = false;
bool m_bCursorHasSurface = false;
SP<CRenderbuffer> m_pCurrentRenderbuffer = nullptr;
SP<Aquamarine::IBuffer> m_pCurrentBuffer;
eRenderMode m_eRenderMode = RENDER_MODE_NORMAL;

Expand All @@ -133,8 +133,8 @@ class CHyprRenderer {
bool hiddenOnKeyboard = false;
} m_sCursorHiddenConditions;

CRenderbuffer* getOrCreateRenderbuffer(SP<Aquamarine::IBuffer> buffer, uint32_t fmt);
std::vector<std::unique_ptr<CRenderbuffer>> m_vRenderbuffers;
SP<CRenderbuffer> getOrCreateRenderbuffer(SP<Aquamarine::IBuffer> buffer, uint32_t fmt);
std::vector<SP<CRenderbuffer>> m_vRenderbuffers;

friend class CHyprOpenGLImpl;
friend class CToplevelExportProtocolManager;
Expand Down
2 changes: 1 addition & 1 deletion src/render/Texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CTexture {
GLenum m_iTarget = GL_TEXTURE_2D;
GLuint m_iTexID = 0;
Vector2D m_vSize;
void* m_pEglImage = nullptr;
void* m_pEglImage = nullptr;

private:
void createFromShm(uint32_t drmFormat, uint8_t* pixels, uint32_t stride, const Vector2D& size);
Expand Down

0 comments on commit 9235728

Please sign in to comment.