drm/renderer: properly save texture data in attachment

This commit is contained in:
Vaxry 2024-07-12 17:31:28 +02:00
parent 45bea6dab2
commit 59fc21940d
2 changed files with 23 additions and 20 deletions

View file

@ -474,8 +474,8 @@ EGLImageKHR CDRMRenderer::createEGLImage(const SDMABUFAttrs& attrs) {
} \ } \
} }
CDRMRenderer::GLTex CDRMRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buffa) { SGLTex CDRMRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buffa) {
GLTex tex; SGLTex tex;
const auto dma = buffa->dmabuf(); const auto dma = buffa->dmabuf();
@ -490,7 +490,7 @@ CDRMRenderer::GLTex CDRMRenderer::glTex(Hyprutils::Memory::CSharedPointer<IBuffe
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 = {}", external)); backend->log(AQ_LOG_DEBUG, std::format("CDRMRenderer::glTex: found format+mod, external = {}", fmt.external));
external = fmt.external; external = fmt.external;
break; break;
} }
@ -528,13 +528,13 @@ bool CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to) {
// both from and to have the same AQ_ATTACHMENT_DRM_RENDERER_DATA. // both from and to have the same AQ_ATTACHMENT_DRM_RENDERER_DATA.
// Those buffers always come from different swapchains, so it's OK. // Those buffers always come from different swapchains, so it's OK.
GLTex fromTex; SGLTex fromTex;
{ {
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 = (CDRMRendererBufferAttachment*)attachment.get();
fromTex = {att->eglImage, att->texid}; fromTex = att->tex;
} }
if (!fromTex.image) { if (!fromTex.image) {
@ -543,7 +543,7 @@ bool CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to) {
// 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, fromTex.image, 0, 0, fromTex.texid)); from->attachments.add(makeShared<CDRMRendererBufferAttachment>(self, from, nullptr, 0, 0, fromTex));
} }
} }
@ -598,7 +598,7 @@ bool CDRMRenderer::blit(SP<IBuffer> from, SP<IBuffer> to) {
// 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, 0)); to->attachments.add(makeShared<CDRMRendererBufferAttachment>(self, to, rboImage, fboID, rboID, SGLTex{}));
} }
} }
@ -686,14 +686,16 @@ void CDRMRenderer::onBufferAttachmentDrop(CDRMRendererBufferAttachment* attachme
TRACE(backend->log(AQ_LOG_TRACE, TRACE(backend->log(AQ_LOG_TRACE,
std::format("EGL (onBufferAttachmentDrop): dropping fbo {} rbo {} image 0x{:x}", attachment->fbo, attachment->rbo, (uintptr_t)attachment->eglImage))); std::format("EGL (onBufferAttachmentDrop): dropping fbo {} rbo {} image 0x{:x}", attachment->fbo, attachment->rbo, (uintptr_t)attachment->eglImage)));
if (attachment->texid) if (attachment->tex.texid)
GLCALL(glDeleteTextures(1, &attachment->texid)); GLCALL(glDeleteTextures(1, &attachment->tex.texid));
if (attachment->rbo) if (attachment->rbo)
GLCALL(glDeleteRenderbuffers(1, &attachment->rbo)); GLCALL(glDeleteRenderbuffers(1, &attachment->rbo));
if (attachment->fbo) if (attachment->fbo)
GLCALL(glDeleteFramebuffers(1, &attachment->fbo)); GLCALL(glDeleteFramebuffers(1, &attachment->fbo));
if (attachment->eglImage) if (attachment->eglImage)
egl.eglDestroyImageKHR(egl.display, attachment->eglImage); egl.eglDestroyImageKHR(egl.display, attachment->eglImage);
if (attachment->tex.image)
egl.eglDestroyImageKHR(egl.display, attachment->tex.image);
restoreEGL(); restoreEGL();
} }
@ -719,7 +721,7 @@ bool CDRMRenderer::verifyDestinationDMABUF(const SDMABUFAttrs& attrs) {
} }
CDRMRendererBufferAttachment::CDRMRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer, CDRMRendererBufferAttachment::CDRMRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer,
EGLImageKHR image, GLuint fbo_, GLuint rbo_, GLuint texid_) : EGLImageKHR image, GLuint fbo_, GLuint rbo_, SGLTex tex_) :
eglImage(image), fbo(fbo_), rbo(rbo_), renderer(renderer_), texid(texid_) { 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); });
} }

View file

@ -11,10 +11,16 @@
#include <vector> #include <vector>
namespace Aquamarine { namespace Aquamarine {
struct SGLTex {
EGLImage image = nullptr;
GLuint texid = 0;
GLuint target = GL_TEXTURE_2D;
};
class CDRMRendererBufferAttachment : public IAttachment { class CDRMRendererBufferAttachment : public IAttachment {
public: public:
CDRMRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer, EGLImageKHR image, GLuint fbo_, CDRMRendererBufferAttachment(Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer_, Hyprutils::Memory::CSharedPointer<IBuffer> buffer, EGLImageKHR image, GLuint fbo_,
GLuint rbo_, GLuint texid_); GLuint rbo_, SGLTex tex);
virtual ~CDRMRendererBufferAttachment() { virtual ~CDRMRendererBufferAttachment() {
; ;
} }
@ -23,7 +29,8 @@ namespace Aquamarine {
} }
EGLImageKHR eglImage = nullptr; EGLImageKHR eglImage = nullptr;
GLuint fbo = 0, rbo = 0, texid = 0; GLuint fbo = 0, rbo = 0;
SGLTex tex;
Hyprutils::Signal::CHyprSignalListener bufferDestroy; Hyprutils::Signal::CHyprSignalListener bufferDestroy;
Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer; Hyprutils::Memory::CWeakPointer<CDRMRenderer> renderer;
@ -73,19 +80,13 @@ namespace Aquamarine {
EGLSurface draw = nullptr, read = nullptr; EGLSurface draw = nullptr, read = nullptr;
} savedEGLState; } savedEGLState;
struct GLTex {
EGLImage image = nullptr;
GLuint texid = 0;
GLuint target = GL_TEXTURE_2D;
};
struct GLFormat { struct GLFormat {
uint32_t drmFormat = 0; uint32_t drmFormat = 0;
uint64_t modifier = 0; uint64_t modifier = 0;
bool external = false; bool external = false;
}; };
GLTex glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buf); SGLTex glTex(Hyprutils::Memory::CSharedPointer<IBuffer> buf);
Hyprutils::Memory::CWeakPointer<CDRMRenderer> self; Hyprutils::Memory::CWeakPointer<CDRMRenderer> self;
std::vector<GLFormat> formats; std::vector<GLFormat> formats;