From cac883a39c777ff2609f52881132ca0a7eecd7a6 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Nov 2024 19:00:02 +0000 Subject: [PATCH] maybe dont kill the kernel --- include/aquamarine/allocator/DRMDumb.hpp | 4 ++-- include/aquamarine/buffer/Buffer.hpp | 2 +- src/allocator/DRMDumb.cpp | 15 ++++++++++++++- src/backend/drm/DRM.cpp | 11 ++++++----- src/buffer/Buffer.cpp | 2 +- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/aquamarine/allocator/DRMDumb.hpp b/include/aquamarine/allocator/DRMDumb.hpp index 65d8173..8006fed 100644 --- a/include/aquamarine/allocator/DRMDumb.hpp +++ b/include/aquamarine/allocator/DRMDumb.hpp @@ -19,7 +19,7 @@ namespace Aquamarine { virtual SSHMAttrs shm(); virtual std::tuple beginDataPtr(uint32_t flags); virtual void endDataPtr(); - virtual uint32_t drmHandle(); + virtual uint32_t drmID(); private: CDRMDumbBuffer(const SAllocatorBufferParams& params, Hyprutils::Memory::CWeakPointer allocator_, @@ -28,7 +28,7 @@ namespace Aquamarine { Hyprutils::Memory::CWeakPointer allocator; // - uint32_t drmID = 0; + uint32_t idrmID = 0; Hyprutils::Math::Vector2D pixelSize; uint32_t stride = 0, handle = 0; uint64_t size = 0; diff --git a/include/aquamarine/buffer/Buffer.hpp b/include/aquamarine/buffer/Buffer.hpp index 158ee9e..eba2558 100644 --- a/include/aquamarine/buffer/Buffer.hpp +++ b/include/aquamarine/buffer/Buffer.hpp @@ -60,7 +60,7 @@ namespace Aquamarine { virtual void lock(); virtual void unlock(); virtual bool locked(); - virtual uint32_t drmHandle(); + virtual uint32_t drmID(); Hyprutils::Math::Vector2D size; bool opaque = false; diff --git a/src/allocator/DRMDumb.cpp b/src/allocator/DRMDumb.cpp index 9c54f72..e93c9aa 100644 --- a/src/allocator/DRMDumb.cpp +++ b/src/allocator/DRMDumb.cpp @@ -39,6 +39,16 @@ Aquamarine::CDRMDumbBuffer::CDRMDumbBuffer(const SAllocatorBufferParams& params, attrs.fd = request.handle; attrs.stride = stride; + uint32_t handles[4] = {handle, 0, 0, 0}; + uint32_t strides[4] = {stride, 0, 0, 0}; + uint32_t offsets[4] = {0, 0, 0, 0}; + + // these buffers are tied to drm... we need to import them here. CDRMFB will not be clean anymore... weeee... + if (int ret = drmModeAddFB2(allocator->drmFD(), params.size.x, params.size.y, params.format, handles, strides, offsets, &idrmID, 0); ret < 0) { + allocator->backend->log(AQ_LOG_ERROR, std::format("failed to drmModeAddFB2 a drm_dumb buffer: {}", strerror(-ret))); + return; + } + drm_mode_map_dumb request2 = { .handle = handle, }; @@ -69,6 +79,9 @@ Aquamarine::CDRMDumbBuffer::~CDRMDumbBuffer() { if (data) munmap(data, size); + if (idrmID) + drmModeRmFB(allocator->drmFD(), idrmID); + drm_mode_destroy_dumb request = { .handle = handle, }; @@ -107,7 +120,7 @@ void Aquamarine::CDRMDumbBuffer::endDataPtr() { ; // nothing to do } -uint32_t Aquamarine::CDRMDumbBuffer::drmHandle() { +uint32_t Aquamarine::CDRMDumbBuffer::drmID() { return handle; } diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp index 1290980..3032c8a 100644 --- a/src/backend/drm/DRM.cpp +++ b/src/backend/drm/DRM.cpp @@ -1826,7 +1826,7 @@ Aquamarine::CDRMFB::CDRMFB(SP buffer_, Hyprutils::Memory::CWeakPointer< void Aquamarine::CDRMFB::import() { auto attrs = buffer->dmabuf(); - if (!attrs.success && !buffer->drmHandle()) { + if (!attrs.success && !buffer->drmID()) { backend->backend->log(AQ_LOG_ERROR, "drm: Buffer submitted has no dmabuf or a drm handle"); return; } @@ -1838,7 +1838,7 @@ void Aquamarine::CDRMFB::import() { // TODO: check format - if (!buffer->drmHandle()) { + if (!buffer->drmID()) { for (int i = 0; i < attrs.planes; ++i) { int ret = drmPrimeFDToHandle(backend->gpu->fd, attrs.fds.at(i), &boHandles[i]); if (ret) { @@ -1849,10 +1849,11 @@ void Aquamarine::CDRMFB::import() { TRACE(backend->backend->log(AQ_LOG_TRACE, std::format("drm: CDRMFB: plane {} has fd {}, got handle {}", i, attrs.fds.at(i), boHandles.at(i)))); } - } else - boHandles = {buffer->drmHandle(), 0, 0, 0}; - id = submitBuffer(); + id = submitBuffer(); + } else + id = buffer->drmID(); + if (!id) { backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer to KMS"); buffer->attachments.add(makeShared()); diff --git a/src/buffer/Buffer.cpp b/src/buffer/Buffer.cpp index e0b0243..2ef5b41 100644 --- a/src/buffer/Buffer.cpp +++ b/src/buffer/Buffer.cpp @@ -40,6 +40,6 @@ bool Aquamarine::IBuffer::locked() { return locks; } -uint32_t Aquamarine::IBuffer::drmHandle() { +uint32_t Aquamarine::IBuffer::drmID() { return 0; }