mirror of
https://github.com/hyprwm/aquamarine.git
synced 2024-11-17 10:46:00 +01:00
e
This commit is contained in:
parent
d3b58683cc
commit
ce8047e19e
2 changed files with 46 additions and 37 deletions
|
@ -30,6 +30,7 @@ Aquamarine::CDRMDumbBuffer::CDRMDumbBuffer(const SAllocatorBufferParams& params,
|
||||||
|
|
||||||
attrs.size = pixelSize;
|
attrs.size = pixelSize;
|
||||||
attrs.strides.at(0) = stride;
|
attrs.strides.at(0) = stride;
|
||||||
|
attrs.planes = 1;
|
||||||
|
|
||||||
uint64_t offset = 0;
|
uint64_t offset = 0;
|
||||||
if (int ret = drmModeMapDumbBuffer(allocator->drmFD(), handle, &offset); ret < 0) {
|
if (int ret = drmModeMapDumbBuffer(allocator->drmFD(), handle, &offset); ret < 0) {
|
||||||
|
@ -69,10 +70,7 @@ Aquamarine::CDRMDumbBuffer::~CDRMDumbBuffer() {
|
||||||
if (data)
|
if (data)
|
||||||
munmap(data, size);
|
munmap(data, size);
|
||||||
|
|
||||||
drm_mode_destroy_dumb request = {
|
drmModeDestroyDumbBuffer(allocator->drmFD(), handle);
|
||||||
.handle = handle,
|
|
||||||
};
|
|
||||||
drmIoctl(allocator->drmFD(), DRM_IOCTL_MODE_DESTROY_DUMB, &request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eBufferCapability Aquamarine::CDRMDumbBuffer::caps() {
|
eBufferCapability Aquamarine::CDRMDumbBuffer::caps() {
|
||||||
|
@ -112,8 +110,27 @@ Aquamarine::CDRMDumbAllocator::~CDRMDumbAllocator() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SP<CDRMDumbAllocator> Aquamarine::CDRMDumbAllocator::create(int drmfd_, Hyprutils::Memory::CWeakPointer<CBackend> backend_) {
|
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_));
|
auto a = SP<CDRMDumbAllocator>(new CDRMDumbAllocator(drmfd_, backend_));
|
||||||
a->self = a;
|
a->self = a;
|
||||||
|
|
||||||
|
backend_->log(AQ_LOG_DEBUG, "DRM Dumb: created a dumb allocator");
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1935,44 +1935,36 @@ void Aquamarine::CDRMFB::drop() {
|
||||||
uint32_t Aquamarine::CDRMFB::submitBuffer() {
|
uint32_t Aquamarine::CDRMFB::submitBuffer() {
|
||||||
uint32_t newID = 0;
|
uint32_t newID = 0;
|
||||||
|
|
||||||
if (buffer->type() == eBufferType::BUFFER_TYPE_DMABUF) {
|
if (!buffer->dmabuf().success)
|
||||||
auto attrs = buffer->dmabuf();
|
return 0;
|
||||||
std::array<uint64_t, 4> mods = {0, 0, 0, 0};
|
|
||||||
for (size_t i = 0; i < attrs.planes; ++i) {
|
|
||||||
mods[i] = attrs.modifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backend->drmProps.supportsAddFb2Modifiers && attrs.modifier != DRM_FORMAT_MOD_INVALID) {
|
auto attrs = buffer->dmabuf();
|
||||||
TRACE(backend->backend->log(AQ_LOG_TRACE,
|
std::array<uint64_t, 4> mods = {0, 0, 0, 0};
|
||||||
std::format("drm: Using drmModeAddFB2WithModifiers to import buffer into KMS: Size {} with format {} and mod {}", attrs.size,
|
for (size_t i = 0; i < attrs.planes; ++i) {
|
||||||
fourccToName(attrs.format), attrs.modifier)));
|
mods[i] = 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
TRACE(backend->backend->log(
|
if (backend->drmProps.supportsAddFb2Modifiers && attrs.modifier != DRM_FORMAT_MOD_INVALID) {
|
||||||
AQ_LOG_TRACE,
|
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)));
|
std::format("drm: Using drmModeAddFB2WithModifiers 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)) {
|
if (drmModeAddFB2WithModifiers(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), attrs.strides.data(), attrs.offsets.data(), mods.data(),
|
||||||
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2");
|
&newID, DRM_MODE_FB_MODIFIERS)) {
|
||||||
return 0;
|
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a buffer with drmModeAddFB2WithModifiers");
|
||||||
}
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
auto attrs = buffer->shm();
|
if (attrs.modifier != DRM_FORMAT_MOD_INVALID && attrs.modifier != DRM_FORMAT_MOD_LINEAR) {
|
||||||
const uint32_t strides[4] = {(uint32_t)attrs.stride, 0, 0, 0};
|
backend->backend->log(AQ_LOG_ERROR, "drm: drmModeAddFB2WithModifiers unsupported and buffer has explicit modifiers");
|
||||||
const uint32_t offsets[4] = {0, 0, 0, 0};
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (drmModeAddFB2(backend->gpu->fd, attrs.size.x, attrs.size.y, attrs.format, boHandles.data(), strides, offsets, &newID, 0)) {
|
TRACE(backend->backend->log(
|
||||||
backend->backend->log(AQ_LOG_ERROR, "drm: Failed to submit a shm buffer with drmModeAddFB2");
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue