move renderer to EGLRenderer

This commit is contained in:
Ikalco 2025-01-23 16:26:49 -06:00
parent 7fe006981f
commit 70c8bdf371
9 changed files with 88 additions and 76 deletions

View file

@ -63,6 +63,6 @@ namespace Aquamarine {
int drmfd = -1; int drmfd = -1;
friend class CDRMDumbBuffer; friend class CDRMDumbBuffer;
friend class CDRMRenderer; friend class CEGLRenderer;
}; };
}; };

View file

@ -66,6 +66,6 @@ namespace Aquamarine {
std::string drmName = ""; std::string drmName = "";
friend class CGBMBuffer; friend class CGBMBuffer;
friend class CDRMRenderer; friend class CEGLRenderer;
}; };
}; };

View file

@ -14,7 +14,7 @@ namespace Aquamarine {
class CDRMFB; class CDRMFB;
class CDRMOutput; class CDRMOutput;
struct SDRMConnector; struct SDRMConnector;
class CDRMRenderer; class CEGLRenderer;
class CDRMDumbAllocator; class CDRMDumbAllocator;
typedef std::function<void(void)> FIdleCallback; typedef std::function<void(void)> FIdleCallback;
@ -411,7 +411,7 @@ namespace Aquamarine {
struct { struct {
Hyprutils::Memory::CSharedPointer<IAllocator> allocator; Hyprutils::Memory::CSharedPointer<IAllocator> allocator;
Hyprutils::Memory::CSharedPointer<CDRMRenderer> renderer; // may be null if creation fails Hyprutils::Memory::CSharedPointer<CEGLRenderer> renderer; // may be null if creation fails
} rendererState; } rendererState;
Hyprutils::Memory::CWeakPointer<CBackend> backend; Hyprutils::Memory::CWeakPointer<CBackend> backend;

View file

@ -73,5 +73,4 @@ namespace Aquamarine {
private: private:
int locks = 0; int locks = 0;
}; };
}; };

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <aquamarine/backend/DRM.hpp> #include <aquamarine/backend/DRM.hpp>
#include <aquamarine/buffer/Buffer.hpp>
#include "FormatUtils.hpp" #include "FormatUtils.hpp"
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
@ -21,11 +22,11 @@ namespace Aquamarine {
GLuint target = GL_TEXTURE_2D; GLuint target = GL_TEXTURE_2D;
}; };
class CDRMRendererBufferAttachment : public IAttachment { class CEGLRendererBufferAttachment : public IAttachment {
public: public:
CDRMRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer, EGLImageKHR image, GLuint fbo_, CEGLRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CEGLRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer, EGLImageKHR image, GLuint fbo_,
GLuint rbo_, SGLTex tex); GLuint rbo_, SGLTex tex);
virtual ~CDRMRendererBufferAttachment() { virtual ~CEGLRendererBufferAttachment() {
; ;
} }
virtual eAttachmentType type() { virtual eAttachmentType type() {
@ -37,13 +38,13 @@ namespace Aquamarine {
SGLTex tex; SGLTex tex;
Hyprutils::Signal::CHyprSignalListener bufferDestroy; Hyprutils::Signal::CHyprSignalListener bufferDestroy;
Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer; Hyprutils::Memory::CWeakPointer<CEGLRenderer> renderer;
}; };
class CDRMRenderer { class CEGLRenderer {
public: public:
~CDRMRenderer(); ~CEGLRenderer();
static Hyprutils::Memory::CSharedPointer<CDRMRenderer> attempt(Hyprutils::Memory::CSharedPointer<CGBMAllocator> allocator_, static Hyprutils::Memory::CSharedPointer<CEGLRenderer> attempt(Hyprutils::Memory::CSharedPointer<CGBMAllocator> allocator_,
Hyprutils::Memory::CSharedPointer<CBackend> backend_); Hyprutils::Memory::CSharedPointer<CBackend> backend_);
int drmFD = -1; int drmFD = -1;
@ -60,7 +61,7 @@ namespace Aquamarine {
void setEGL(); void setEGL();
void restoreEGL(); void restoreEGL();
void onBufferAttachmentDrop(CDRMRendererBufferAttachment* attachment); void onBufferAttachmentDrop(CEGLRendererBufferAttachment* attachment);
struct { struct {
struct SShader { struct SShader {
@ -96,11 +97,11 @@ namespace Aquamarine {
SGLTex glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buf); SGLTex glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buf);
Hyprutils::Memory::CWeakPointer<CDRMRenderer> self; Hyprutils::Memory::CWeakPointer<CEGLRenderer> self;
std::vector<SGLFormat> formats; std::vector<SGLFormat> formats;
private: private:
CDRMRenderer() = default; CEGLRenderer() = default;
EGLImageKHR createEGLImage(const SDMABUFAttrs& attrs); EGLImageKHR createEGLImage(const SDMABUFAttrs& attrs);
std::optional<std::vector<std::pair<uint64_t, bool>>> getModsForFormat(EGLint format); std::optional<std::vector<std::pair<uint64_t, bool>>> getModsForFormat(EGLint format);
@ -112,4 +113,4 @@ namespace Aquamarine {
Hyprutils::Memory::CWeakPointer<CBackend> backend; Hyprutils::Memory::CWeakPointer<CBackend> backend;
}; };
}; };

View file

@ -2,6 +2,7 @@
#include <aquamarine/backend/Backend.hpp> #include <aquamarine/backend/Backend.hpp>
#include <aquamarine/backend/DRM.hpp> #include <aquamarine/backend/DRM.hpp>
#include <aquamarine/allocator/Swapchain.hpp> #include <aquamarine/allocator/Swapchain.hpp>
#include <aquamarine/renderer/EGLRenderer.hpp>
#include "FormatUtils.hpp" #include "FormatUtils.hpp"
#include "Shared.hpp" #include "Shared.hpp"
#include <fcntl.h> #include <fcntl.h>
@ -10,7 +11,6 @@
#include <unistd.h> #include <unistd.h>
#include <cstring> #include <cstring>
#include <sys/mman.h> #include <sys/mman.h>
#include "../backend/drm/Renderer.hpp"
using namespace Aquamarine; using namespace Aquamarine;
using namespace Hyprutils::Memory; using namespace Hyprutils::Memory;

View file

@ -3,12 +3,12 @@
#include <aquamarine/backend/Backend.hpp> #include <aquamarine/backend/Backend.hpp>
#include <aquamarine/backend/DRM.hpp> #include <aquamarine/backend/DRM.hpp>
#include <aquamarine/allocator/Swapchain.hpp> #include <aquamarine/allocator/Swapchain.hpp>
#include <aquamarine/renderer/EGLRenderer.hpp>
#include "FormatUtils.hpp" #include "FormatUtils.hpp"
#include "Shared.hpp" #include "Shared.hpp"
#include <xf86drm.h> #include <xf86drm.h>
#include <gbm.h> #include <gbm.h>
#include <unistd.h> #include <unistd.h>
#include "../backend/drm/Renderer.hpp"
using namespace Aquamarine; using namespace Aquamarine;
using namespace Hyprutils::Memory; using namespace Hyprutils::Memory;
@ -24,8 +24,7 @@ static SDRMFormat guessFormatFrom(std::vector<SDRMFormat> formats, bool cursor,
For cursors, don't, as these almost never support that. For cursors, don't, as these almost never support that.
*/ */
if (!scanout) { if (!scanout) {
if (auto it = if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB2101010 || f.drmFormat == DRM_FORMAT_ABGR2101010; });
std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB2101010 || f.drmFormat == DRM_FORMAT_ABGR2101010; });
it != formats.end()) it != formats.end())
return *it; return *it;
} }
@ -36,13 +35,11 @@ static SDRMFormat guessFormatFrom(std::vector<SDRMFormat> formats, bool cursor,
} }
if (!scanout || cursor /* don't set opaque for cursor plane */) { if (!scanout || cursor /* don't set opaque for cursor plane */) {
if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB8888 || f.drmFormat == DRM_FORMAT_ABGR8888; }); if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_ARGB8888 || f.drmFormat == DRM_FORMAT_ABGR8888; }); it != formats.end())
it != formats.end())
return *it; return *it;
} }
if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB8888 || f.drmFormat == DRM_FORMAT_XBGR8888; }); if (auto it = std::ranges::find_if(formats, [](const auto& f) { return f.drmFormat == DRM_FORMAT_XRGB8888 || f.drmFormat == DRM_FORMAT_XBGR8888; }); it != formats.end())
it != formats.end())
return *it; return *it;
for (auto const& f : formats) { for (auto const& f : formats) {

View file

@ -5,6 +5,7 @@
#include <aquamarine/backend/drm/Atomic.hpp> #include <aquamarine/backend/drm/Atomic.hpp>
#include <aquamarine/allocator/GBM.hpp> #include <aquamarine/allocator/GBM.hpp>
#include <aquamarine/allocator/DRMDumb.hpp> #include <aquamarine/allocator/DRMDumb.hpp>
#include <aquamarine/renderer/EGLRenderer.hpp>
#include <cstdint> #include <cstdint>
#include <format> #include <format>
#include <hyprutils/string/VarList.hpp> #include <hyprutils/string/VarList.hpp>
@ -32,7 +33,6 @@ extern "C" {
#include "FormatUtils.hpp" #include "FormatUtils.hpp"
#include "Shared.hpp" #include "Shared.hpp"
#include "hwdata.hpp" #include "hwdata.hpp"
#include "Renderer.hpp"
using namespace Aquamarine; using namespace Aquamarine;
using namespace Hyprutils::Memory; using namespace Hyprutils::Memory;
@ -562,7 +562,7 @@ bool Aquamarine::CDRMBackend::initMgpu() {
return false; return false;
} }
rendererState.renderer = CDRMRenderer::attempt(newAllocator, backend.lock()); rendererState.renderer = CEGLRenderer::attempt(newAllocator, backend.lock());
if (!rendererState.renderer) { if (!rendererState.renderer) {
backend->log(AQ_LOG_ERROR, "drm: initMgpu: no renderer"); backend->log(AQ_LOG_ERROR, "drm: initMgpu: no renderer");
@ -937,7 +937,7 @@ void Aquamarine::CDRMBackend::onReady() {
if (!a) if (!a)
backend->log(AQ_LOG_ERROR, "drm: onReady: no renderer for gl formats"); backend->log(AQ_LOG_ERROR, "drm: onReady: no renderer for gl formats");
else { else {
auto r = CDRMRenderer::attempt(a, backend.lock()); auto r = CEGLRenderer::attempt(a, backend.lock());
if (!r) if (!r)
backend->log(AQ_LOG_ERROR, "drm: onReady: no renderer for gl formats"); backend->log(AQ_LOG_ERROR, "drm: onReady: no renderer for gl formats");
else { else {

View file

@ -1,14 +1,14 @@
#include "Renderer.hpp"
#include <xf86drm.h> #include <xf86drm.h>
#include <xf86drmMode.h> #include <xf86drmMode.h>
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include "Math.hpp" #include "../backend/drm/Math.hpp"
#include "Shared.hpp" #include "Shared.hpp"
#include "FormatUtils.hpp" #include "FormatUtils.hpp"
#include <aquamarine/allocator/GBM.hpp> #include <aquamarine/allocator/GBM.hpp>
#include <aquamarine/renderer/EGLRenderer.hpp>
using namespace Aquamarine; using namespace Aquamarine;
using namespace Hyprutils::Memory; using namespace Hyprutils::Memory;
@ -108,7 +108,7 @@ inline void loadGLProc(void* pProc, const char* name) {
// ------------------- // -------------------
std::optional<std::vector<std::pair<uint64_t, bool>>> CDRMRenderer::getModsForFormat(EGLint format) { std::optional<std::vector<std::pair<uint64_t, bool>>> CEGLRenderer::getModsForFormat(EGLint format) {
// TODO: return std::expected when clang supports it // TODO: return std::expected when clang supports it
EGLint len = 0; EGLint len = 0;
@ -140,7 +140,7 @@ std::optional<std::vector<std::pair<uint64_t, bool>>> CDRMRenderer::getModsForFo
return result; return result;
} }
bool CDRMRenderer::initDRMFormats() { bool CEGLRenderer::initDRMFormats() {
std::vector<EGLint> formats; std::vector<EGLint> formats;
EGLint len = 0; EGLint len = 0;
@ -198,7 +198,7 @@ bool CDRMRenderer::initDRMFormats() {
return true; return true;
} }
Aquamarine::CDRMRenderer::~CDRMRenderer() { Aquamarine::CEGLRenderer::~CEGLRenderer() {
eglMakeCurrent(egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(egl.display, egl.context); eglDestroyContext(egl.display, egl.context);
@ -207,8 +207,8 @@ Aquamarine::CDRMRenderer::~CDRMRenderer() {
eglReleaseThread(); eglReleaseThread();
} }
SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAllocator> allocator_, SP<CBackend> backend_) { SP<CEGLRenderer> CEGLRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAllocator> allocator_, SP<CBackend> backend_) {
SP<CDRMRenderer> renderer = SP<CDRMRenderer>(new CDRMRenderer()); SP<CEGLRenderer> renderer = SP<CEGLRenderer>(new CEGLRenderer());
renderer->drmFD = allocator_->drmFD(); renderer->drmFD = allocator_->drmFD();
renderer->backend = backend_; renderer->backend = backend_;
gBackend = backend_; gBackend = backend_;
@ -216,14 +216,14 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
const std::string EGLEXTENSIONS = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS); const std::string EGLEXTENSIONS = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
if (!EGLEXTENSIONS.contains("KHR_platform_gbm")) { if (!EGLEXTENSIONS.contains("KHR_platform_gbm")) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no gbm support"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no gbm support");
return nullptr; return nullptr;
} }
// init egl // init egl
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) { if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, eglBindAPI failed"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, eglBindAPI failed");
return nullptr; return nullptr;
} }
@ -240,45 +240,45 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
loadGLProc(&renderer->egl.eglDupNativeFenceFDANDROID, "eglDupNativeFenceFDANDROID"); loadGLProc(&renderer->egl.eglDupNativeFenceFDANDROID, "eglDupNativeFenceFDANDROID");
if (!renderer->egl.eglCreateSyncKHR) { if (!renderer->egl.eglCreateSyncKHR) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglCreateSyncKHR"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglCreateSyncKHR");
return nullptr; return nullptr;
} }
if (!renderer->egl.eglDupNativeFenceFDANDROID) { if (!renderer->egl.eglDupNativeFenceFDANDROID) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglDupNativeFenceFDANDROID"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglDupNativeFenceFDANDROID");
return nullptr; return nullptr;
} }
if (!renderer->egl.eglGetPlatformDisplayEXT) { if (!renderer->egl.eglGetPlatformDisplayEXT) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglGetPlatformDisplayEXT"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglGetPlatformDisplayEXT");
return nullptr; return nullptr;
} }
if (!renderer->egl.eglCreateImageKHR) { if (!renderer->egl.eglCreateImageKHR) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglCreateImageKHR"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglCreateImageKHR");
return nullptr; return nullptr;
} }
if (!renderer->egl.eglQueryDmaBufFormatsEXT) { if (!renderer->egl.eglQueryDmaBufFormatsEXT) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglQueryDmaBufFormatsEXT"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglQueryDmaBufFormatsEXT");
return nullptr; return nullptr;
} }
if (!renderer->egl.eglQueryDmaBufModifiersEXT) { if (!renderer->egl.eglQueryDmaBufModifiersEXT) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no eglQueryDmaBufModifiersEXT"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no eglQueryDmaBufModifiersEXT");
return nullptr; return nullptr;
} }
std::vector<EGLint> attrs = {EGL_NONE}; std::vector<EGLint> attrs = {EGL_NONE};
renderer->egl.display = renderer->egl.eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR, allocator_->gbmDevice, attrs.data()); renderer->egl.display = renderer->egl.eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR, allocator_->gbmDevice, attrs.data());
if (renderer->egl.display == EGL_NO_DISPLAY) { if (renderer->egl.display == EGL_NO_DISPLAY) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, eglGetPlatformDisplayEXT failed"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, eglGetPlatformDisplayEXT failed");
return nullptr; return nullptr;
} }
EGLint major, minor; EGLint major, minor;
if (eglInitialize(renderer->egl.display, &major, &minor) == EGL_FALSE) { if (eglInitialize(renderer->egl.display, &major, &minor) == EGL_FALSE) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, eglInitialize failed"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, eglInitialize failed");
return nullptr; return nullptr;
} }
@ -297,12 +297,12 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
} }
if (!EGLEXTENSIONS2.contains("EXT_image_dma_buf_import_modifiers")) { if (!EGLEXTENSIONS2.contains("EXT_image_dma_buf_import_modifiers")) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no EXT_image_dma_buf_import_modifiers ext"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no EXT_image_dma_buf_import_modifiers ext");
return nullptr; return nullptr;
} }
if (!EGLEXTENSIONS2.contains("EXT_image_dma_buf_import")) { if (!EGLEXTENSIONS2.contains("EXT_image_dma_buf_import")) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, no EXT_image_dma_buf_import ext"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, no EXT_image_dma_buf_import ext");
return nullptr; return nullptr;
} }
@ -317,7 +317,7 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
renderer->egl.context = eglCreateContext(renderer->egl.display, EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, attrs.data()); renderer->egl.context = eglCreateContext(renderer->egl.display, EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, attrs.data());
if (renderer->egl.context == EGL_NO_CONTEXT) { if (renderer->egl.context == EGL_NO_CONTEXT) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, eglCreateContext failed"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, eglCreateContext failed");
return nullptr; return nullptr;
} }
@ -325,9 +325,9 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
EGLint priority = EGL_CONTEXT_PRIORITY_MEDIUM_IMG; EGLint priority = EGL_CONTEXT_PRIORITY_MEDIUM_IMG;
eglQueryContext(renderer->egl.display, renderer->egl.context, EGL_CONTEXT_PRIORITY_LEVEL_IMG, &priority); eglQueryContext(renderer->egl.display, renderer->egl.context, EGL_CONTEXT_PRIORITY_LEVEL_IMG, &priority);
if (priority != EGL_CONTEXT_PRIORITY_HIGH_IMG) if (priority != EGL_CONTEXT_PRIORITY_HIGH_IMG)
backend_->log(AQ_LOG_DEBUG, "CDRMRenderer: didnt get a high priority context"); backend_->log(AQ_LOG_DEBUG, "CEGLRenderer: didnt get a high priority context");
else else
backend_->log(AQ_LOG_DEBUG, "CDRMRenderer: got a high priority context"); backend_->log(AQ_LOG_DEBUG, "CEGLRenderer: got a high priority context");
} }
// init shaders // init shaders
@ -335,13 +335,13 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
renderer->setEGL(); renderer->setEGL();
if (!renderer->initDRMFormats()) { if (!renderer->initDRMFormats()) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, initDRMFormats failed"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, initDRMFormats failed");
return nullptr; return nullptr;
} }
renderer->gl.shader.program = createProgram(VERT_SRC, FRAG_SRC); renderer->gl.shader.program = createProgram(VERT_SRC, FRAG_SRC);
if (renderer->gl.shader.program == 0) { if (renderer->gl.shader.program == 0) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, shader failed"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, shader failed");
return nullptr; return nullptr;
} }
@ -352,7 +352,7 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
renderer->gl.shaderExt.program = createProgram(VERT_SRC, FRAG_SRC_EXT); renderer->gl.shaderExt.program = createProgram(VERT_SRC, FRAG_SRC_EXT);
if (renderer->gl.shaderExt.program == 0) { if (renderer->gl.shaderExt.program == 0) {
backend_->log(AQ_LOG_ERROR, "CDRMRenderer: fail, shaderExt failed"); backend_->log(AQ_LOG_ERROR, "CEGLRenderer: fail, shaderExt failed");
return nullptr; return nullptr;
} }
@ -363,22 +363,22 @@ SP<CDRMRenderer> CDRMRenderer::attempt(Hyprutils::Memory::CSharedPointer<CGBMAll
renderer->restoreEGL(); renderer->restoreEGL();
backend_->log(AQ_LOG_DEBUG, "CDRMRenderer: success"); backend_->log(AQ_LOG_DEBUG, "CEGLRenderer: success");
return renderer; return renderer;
} }
void CDRMRenderer::setEGL() { void CEGLRenderer::setEGL() {
savedEGLState.display = eglGetCurrentDisplay(); savedEGLState.display = eglGetCurrentDisplay();
savedEGLState.context = eglGetCurrentContext(); savedEGLState.context = eglGetCurrentContext();
savedEGLState.draw = eglGetCurrentSurface(EGL_DRAW); savedEGLState.draw = eglGetCurrentSurface(EGL_DRAW);
savedEGLState.read = eglGetCurrentSurface(EGL_READ); savedEGLState.read = eglGetCurrentSurface(EGL_READ);
if (!eglMakeCurrent(egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, egl.context)) if (!eglMakeCurrent(egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, egl.context))
backend->log(AQ_LOG_WARNING, "CDRMRenderer: setEGL eglMakeCurrent failed"); backend->log(AQ_LOG_WARNING, "CEGLRenderer: setEGL eglMakeCurrent failed");
} }
void CDRMRenderer::restoreEGL() { void CEGLRenderer::restoreEGL() {
EGLDisplay dpy = savedEGLState.display ? savedEGLState.display : egl.display; EGLDisplay dpy = savedEGLState.display ? savedEGLState.display : egl.display;
// egl can't handle this // egl can't handle this
@ -386,10 +386,10 @@ void CDRMRenderer::restoreEGL() {
return; return;
if (!eglMakeCurrent(dpy, savedEGLState.draw, savedEGLState.read, savedEGLState.context)) if (!eglMakeCurrent(dpy, savedEGLState.draw, savedEGLState.read, savedEGLState.context))
backend->log(AQ_LOG_WARNING, "CDRMRenderer: restoreEGL eglMakeCurrent failed"); backend->log(AQ_LOG_WARNING, "CEGLRenderer: restoreEGL eglMakeCurrent failed");
} }
EGLImageKHR CDRMRenderer::createEGLImage(const SDMABUFAttrs& attrs) { EGLImageKHR CEGLRenderer::createEGLImage(const SDMABUFAttrs& attrs) {
std::vector<uint32_t> attribs; std::vector<uint32_t> attribs;
attribs.push_back(EGL_WIDTH); attribs.push_back(EGL_WIDTH);
@ -407,11 +407,26 @@ EGLImageKHR CDRMRenderer::createEGLImage(const SDMABUFAttrs& attrs) {
EGLint pitch; EGLint pitch;
EGLint modlo; EGLint modlo;
EGLint modhi; EGLint modhi;
} attrNames[4] = { } attrNames[4] = {{.fd = EGL_DMA_BUF_PLANE0_FD_EXT,
{.fd = EGL_DMA_BUF_PLANE0_FD_EXT, .offset = EGL_DMA_BUF_PLANE0_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE0_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT}, .offset = EGL_DMA_BUF_PLANE0_OFFSET_EXT,
{.fd = EGL_DMA_BUF_PLANE1_FD_EXT, .offset = EGL_DMA_BUF_PLANE1_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE1_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT}, .pitch = EGL_DMA_BUF_PLANE0_PITCH_EXT,
{.fd = EGL_DMA_BUF_PLANE2_FD_EXT, .offset = EGL_DMA_BUF_PLANE2_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE2_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT}, .modlo = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT,
{.fd = EGL_DMA_BUF_PLANE3_FD_EXT, .offset = EGL_DMA_BUF_PLANE3_OFFSET_EXT, .pitch = EGL_DMA_BUF_PLANE3_PITCH_EXT, .modlo = EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT, .modhi = EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT}}; .modhi = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT},
{.fd = EGL_DMA_BUF_PLANE1_FD_EXT,
.offset = EGL_DMA_BUF_PLANE1_OFFSET_EXT,
.pitch = EGL_DMA_BUF_PLANE1_PITCH_EXT,
.modlo = EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT,
.modhi = EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT},
{.fd = EGL_DMA_BUF_PLANE2_FD_EXT,
.offset = EGL_DMA_BUF_PLANE2_OFFSET_EXT,
.pitch = EGL_DMA_BUF_PLANE2_PITCH_EXT,
.modlo = EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT,
.modhi = EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT},
{.fd = EGL_DMA_BUF_PLANE3_FD_EXT,
.offset = EGL_DMA_BUF_PLANE3_OFFSET_EXT,
.pitch = EGL_DMA_BUF_PLANE3_PITCH_EXT,
.modlo = EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT,
.modhi = EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT}};
for (int i = 0; i < attrs.planes; i++) { for (int i = 0; i < attrs.planes; i++) {
attribs.push_back(attrNames[i].fd); attribs.push_back(attrNames[i].fd);
@ -453,7 +468,7 @@ EGLImageKHR CDRMRenderer::createEGLImage(const SDMABUFAttrs& attrs) {
} \ } \
} }
SGLTex CDRMRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buffa) { SGLTex CEGLRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buffa) {
SGLTex tex; SGLTex tex;
const auto dma = buffa->dmabuf(); const auto dma = buffa->dmabuf();
@ -469,7 +484,7 @@ SGLTex CDRMRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buffa) {
if (fmt.drmFormat != dma.format || fmt.modifier != dma.modifier) if (fmt.drmFormat != dma.format || fmt.modifier != dma.modifier)
continue; continue;
backend->log(AQ_LOG_DEBUG, std::format("CDRMRenderer::glTex: found format+mod, external = {}", fmt.external)); backend->log(AQ_LOG_DEBUG, std::format("CEGLRenderer::glTex: found format+mod, external = {}", fmt.external));
external = fmt.external; external = fmt.external;
break; break;
} }
@ -494,7 +509,7 @@ inline const float fullVerts[] = {
0, 1, // bottom left 0, 1, // bottom left
}; };
void CDRMRenderer::waitOnSync(int fd) { void CEGLRenderer::waitOnSync(int fd) {
TRACE(backend->log(AQ_LOG_TRACE, std::format("EGL (waitOnSync): attempting to wait on fd {}", fd))); TRACE(backend->log(AQ_LOG_TRACE, std::format("EGL (waitOnSync): attempting to wait on fd {}", fd)));
std::vector<EGLint> attribs; std::vector<EGLint> attribs;
@ -529,7 +544,7 @@ void CDRMRenderer::waitOnSync(int fd) {
TRACE(backend->log(AQ_LOG_TRACE, "EGL (waitOnSync): failed to destroy sync")); TRACE(backend->log(AQ_LOG_TRACE, "EGL (waitOnSync): failed to destroy sync"));
} }
int CDRMRenderer::recreateBlitSync() { int CEGLRenderer::recreateBlitSync() {
TRACE(backend->log(AQ_LOG_TRACE, "EGL (recreateBlitSync): recreating blit sync")); TRACE(backend->log(AQ_LOG_TRACE, "EGL (recreateBlitSync): recreating blit sync"));
if (egl.lastBlitSync) { if (egl.lastBlitSync) {
@ -571,7 +586,7 @@ int CDRMRenderer::recreateBlitSync() {
return fd; return fd;
} }
void CDRMRenderer::clearBuffer(IBuffer* buf) { void CEGLRenderer::clearBuffer(IBuffer* buf) {
setEGL(); setEGL();
auto dmabuf = buf->dmabuf(); auto dmabuf = buf->dmabuf();
@ -617,7 +632,7 @@ void CDRMRenderer::clearBuffer(IBuffer* buf) {
restoreEGL(); restoreEGL();
} }
CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, int waitFD) { CEGLRenderer::SBlitResult CEGLRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, int waitFD) {
setEGL(); setEGL();
if (from->dmabuf().size != to->dmabuf().size) { if (from->dmabuf().size != to->dmabuf().size) {
@ -640,7 +655,7 @@ CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, i
auto attachment = from->attachments.get(AQ_ATTACHMENT_DRM_RENDERER_DATA); auto attachment = from->attachments.get(AQ_ATTACHMENT_DRM_RENDERER_DATA);
if (attachment) { if (attachment) {
TRACE(backend->log(AQ_LOG_TRACE, "EGL (blit): From attachment found")); TRACE(backend->log(AQ_LOG_TRACE, "EGL (blit): From attachment found"));
auto att = (CDRMRendererBufferAttachment*)attachment.get(); auto att = (CEGLRendererBufferAttachment*)attachment.get();
fromTex = att->tex; fromTex = att->tex;
} }
@ -650,7 +665,7 @@ CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, i
// should never remove anything, but JIC. We'll leak an EGLImage if this removes anything. // should never remove anything, but JIC. We'll leak an EGLImage if this removes anything.
from->attachments.removeByType(AQ_ATTACHMENT_DRM_RENDERER_DATA); from->attachments.removeByType(AQ_ATTACHMENT_DRM_RENDERER_DATA);
from->attachments.add(makeShared<CDRMRendererBufferAttachment>(self, from, nullptr, 0, 0, fromTex)); from->attachments.add(makeShared<CEGLRendererBufferAttachment>(self, from, nullptr, 0, 0, fromTex));
} }
} }
@ -674,7 +689,7 @@ CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, i
auto attachment = to->attachments.get(AQ_ATTACHMENT_DRM_RENDERER_DATA); auto attachment = to->attachments.get(AQ_ATTACHMENT_DRM_RENDERER_DATA);
if (attachment) { if (attachment) {
TRACE(backend->log(AQ_LOG_TRACE, "EGL (blit): To attachment found")); TRACE(backend->log(AQ_LOG_TRACE, "EGL (blit): To attachment found"));
auto att = (CDRMRendererBufferAttachment*)attachment.get(); auto att = (CEGLRendererBufferAttachment*)attachment.get();
rboImage = att->eglImage; rboImage = att->eglImage;
fboID = att->fbo; fboID = att->fbo;
rboID = att->rbo; rboID = att->rbo;
@ -705,7 +720,7 @@ CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, i
// should never remove anything, but JIC. We'll leak an RBO and FBO if this removes anything. // should never remove anything, but JIC. We'll leak an RBO and FBO if this removes anything.
to->attachments.removeByType(AQ_ATTACHMENT_DRM_RENDERER_DATA); to->attachments.removeByType(AQ_ATTACHMENT_DRM_RENDERER_DATA);
to->attachments.add(makeShared<CDRMRendererBufferAttachment>(self, to, rboImage, fboID, rboID, SGLTex{})); to->attachments.add(makeShared<CEGLRendererBufferAttachment>(self, to, rboImage, fboID, rboID, SGLTex{}));
} }
} }
@ -791,7 +806,7 @@ CDRMRenderer::SBlitResult CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to, i
return {.success = true, .syncFD = explicitFD == -1 ? std::nullopt : std::optional<int>{explicitFD}}; return {.success = true, .syncFD = explicitFD == -1 ? std::nullopt : std::optional<int>{explicitFD}};
} }
void CDRMRenderer::onBufferAttachmentDrop(CDRMRendererBufferAttachment* attachment) { void CEGLRenderer::onBufferAttachmentDrop(CEGLRendererBufferAttachment* attachment) {
setEGL(); setEGL();
TRACE(backend->log(AQ_LOG_TRACE, TRACE(backend->log(AQ_LOG_TRACE,
@ -811,7 +826,7 @@ void CDRMRenderer::onBufferAttachmentDrop(CDRMRendererBufferAttachment* attachme
restoreEGL(); restoreEGL();
} }
bool CDRMRenderer::verifyDestinationDMABUF(const SDMABUFAttrs& attrs) { bool CEGLRenderer::verifyDestinationDMABUF(const SDMABUFAttrs& attrs) {
for (auto const& fmt : formats) { for (auto const& fmt : formats) {
if (fmt.drmFormat != attrs.format) if (fmt.drmFormat != attrs.format)
continue; continue;
@ -826,7 +841,7 @@ bool CDRMRenderer::verifyDestinationDMABUF(const SDMABUFAttrs& attrs) {
return false; return false;
} }
CDRMRendererBufferAttachment::CDRMRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer, CEGLRendererBufferAttachment::CEGLRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CEGLRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer,
EGLImageKHR image, GLuint fbo_, GLuint rbo_, SGLTex tex_) : EGLImageKHR image, GLuint fbo_, GLuint rbo_, SGLTex tex_) :
eglImage(image), fbo(fbo_), rbo(rbo_), renderer(renderer_), tex(tex_) { eglImage(image), fbo(fbo_), rbo(rbo_), renderer(renderer_), tex(tex_) {
bufferDestroy = buffer->events.destroy.registerListener([this](std::any d) { renderer->onBufferAttachmentDrop(this); }); bufferDestroy = buffer->events.destroy.registerListener([this](std::any d) { renderer->onBufferAttachmentDrop(this); });