This commit is contained in:
Vaxry 2024-11-09 19:52:00 +00:00
parent d3b58683cc
commit ce8047e19e
2 changed files with 46 additions and 37 deletions

View file

@ -30,6 +30,7 @@ Aquamarine::CDRMDumbBuffer::CDRMDumbBuffer(const SAllocatorBufferParams& params,
attrs.size = pixelSize;
attrs.strides.at(0) = stride;
attrs.planes = 1;
uint64_t offset = 0;
if (int ret = drmModeMapDumbBuffer(allocator->drmFD(), handle, &offset); ret < 0) {
@ -69,10 +70,7 @@ Aquamarine::CDRMDumbBuffer::~CDRMDumbBuffer() {
if (data)
munmap(data, size);
drm_mode_destroy_dumb request = {
.handle = handle,
};
drmIoctl(allocator->drmFD(), DRM_IOCTL_MODE_DESTROY_DUMB, &request);
drmModeDestroyDumbBuffer(allocator->drmFD(), handle);
}
eBufferCapability Aquamarine::CDRMDumbBuffer::caps() {
@ -112,8 +110,27 @@ Aquamarine::CDRMDumbAllocator::~CDRMDumbAllocator() {
}
SP<CDRMDumbAllocator> Aquamarine::CDRMDumbAllocator::create(int drmfd_, Hyprutils::Memory::CWeakPointer<CBackend> backend_) {
if (drmGetNodeTypeFromFd(drmfd_) != DRM_NODE_PRIMARY) {
backend_->log(AQ_LOG_ERROR, "DRM Dumb: Cannot create allocator when drmfd is not the primary node");
return nullptr;
}
uint64_t hasDumb = 0;
if (drmGetCap(drmfd_, DRM_CAP_DUMB_BUFFER, &hasDumb) < 0) {
backend_->log(AQ_LOG_ERROR, "DRM Dumb: Failed to query hasDumb");
return nullptr;
}
if (!hasDumb) {
backend_->log(AQ_LOG_ERROR, "DRM Dumb: hasDumb is false, gpu driver doesn't support dumb buffers!");
return nullptr;
}
auto a = SP<CDRMDumbAllocator>(new CDRMDumbAllocator(drmfd_, backend_));
a->self = a;
backend_->log(AQ_LOG_DEBUG, "DRM Dumb: created a dumb allocator");
return a;
}

View file

@ -1935,7 +1935,9 @@ void Aquamarine::CDRMFB::drop() {
uint32_t Aquamarine::CDRMFB::submitBuffer() {
uint32_t newID = 0;
if (buffer->type() == eBufferType::BUFFER_TYPE_DMABUF) {
if (!buffer->dmabuf().success)
return 0;
auto attrs = buffer->dmabuf();
std::array<uint64_t, 4> mods = {0, 0, 0, 0};
for (size_t i = 0; i < attrs.planes; ++i) {
@ -1966,16 +1968,6 @@ uint32_t Aquamarine::CDRMFB::submitBuffer() {
return 0;
}
}
} else {
auto attrs = buffer->shm();
const uint32_t strides[4] = {(uint32_t)attrs.stride, 0, 0, 0};
const uint32_t offsets[4] = {0, 0, 0, 0};
if (drmModeAddFB2(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), strides, offsets, &newID, 0)) {
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a shm buffer with drmModeAddFB2");
return 0;
}
}
return newID;
}