diff --git a/src/allocator/DRMDumb.cpp b/src/allocator/DRMDumb.cpp index 09cb37a..9170e4b 100644 --- a/src/allocator/DRMDumb.cpp +++ b/src/allocator/DRMDumb.cpp @@ -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 Aquamarine::CDRMDumbAllocator::create(int drmfd_, Hyprutils::Memory::CWeakPointer 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(new CDRMDumbAllocator(drmfd_, backend_)); a->self = a; + + backend_->log(AQ_LOG_DEBUG, "DRM Dumb: created a dumb allocator"); + return a; } diff --git a/src/backend/drm/DRM.cpp b/src/backend/drm/DRM.cpp index 592f6f0..f69a444 100644 --- a/src/backend/drm/DRM.cpp +++ b/src/backend/drm/DRM.cpp @@ -1935,44 +1935,36 @@ void Aquamarine::CDRMFB::drop() { uint32_t Aquamarine::CDRMFB::submitBuffer() { uint32_t newID = 0; - if (buffer->type() == eBufferType::BUFFER_TYPE_DMABUF) { - auto attrs = buffer->dmabuf(); - std::array mods = {0, 0, 0, 0}; - for (size_t i = 0; i < attrs.planes; ++i) { - mods[i] = attrs.modifier; - } + if (!buffer->dmabuf().success) + return 0; - if (backend->drmProps.supportsAddFb2Modifiers && attrs.modifier != DRM_FORMAT_MOD_INVALID) { - TRACE(backend->backend->log(AQ_LOG_TRACE, - std::format("drm: Using drmModeAddFB2WithModifiers to import buffer into KMS: Size {} with format {} and mod {}", attrs.size, - fourccToName(attrs.format), attrs.modifier))); - if (drmModeAddFB2WithModifiers(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), attrs.strides.data(), attrs.offsets.data(), mods.data(), - &newID, DRM_MODE_FB_MODIFIERS)) { - backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2WithModifiers"); - return 0; - } - } else { - if (attrs.modifier != DRM_FORMAT_MOD_INVALID && attrs.modifier != DRM_FORMAT_MOD_LINEAR) { - backend->backend->log(AQ_LOG_ERROR, "drm: drmModeAddFB2WithModifiers unsupported and buffer has explicit modifiers"); - return 0; - } + auto attrs = buffer->dmabuf(); + std::array mods = {0, 0, 0, 0}; + for (size_t i = 0; i < attrs.planes; ++i) { + mods[i] = attrs.modifier; + } - TRACE(backend->backend->log( - AQ_LOG_TRACE, - std::format("drm: Using drmModeAddFB2 to import buffer into KMS: Size {} with format {} and mod {}", attrs.size, fourccToName(attrs.format), attrs.modifier))); - - if (drmModeAddFB2(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), attrs.strides.data(), attrs.offsets.data(), &newID, 0)) { - backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2"); - return 0; - } + if (backend->drmProps.supportsAddFb2Modifiers && attrs.modifier != DRM_FORMAT_MOD_INVALID) { + TRACE(backend->backend->log(AQ_LOG_TRACE, + std::format("drm: Using drmModeAddFB2WithModifiers to import buffer into KMS: Size {} with format {} and mod {}", attrs.size, + fourccToName(attrs.format), attrs.modifier))); + if (drmModeAddFB2WithModifiers(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), attrs.strides.data(), attrs.offsets.data(), mods.data(), + &newID, DRM_MODE_FB_MODIFIERS)) { + backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2WithModifiers"); + 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 (attrs.modifier != DRM_FORMAT_MOD_INVALID && attrs.modifier != DRM_FORMAT_MOD_LINEAR) { + backend->backend->log(AQ_LOG_ERROR, "drm: drmModeAddFB2WithModifiers unsupported and buffer has explicit modifiers"); + return 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"); + TRACE(backend->backend->log( + AQ_LOG_TRACE, + std::format("drm: Using drmModeAddFB2 to import buffer into KMS: Size {} with format {} and mod {}", attrs.size, fourccToName(attrs.format), attrs.modifier))); + + if (drmModeAddFB2(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), attrs.strides.data(), attrs.offsets.data(), &newID, 0)) { + backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2"); return 0; } }