mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-29 05:40:12 -04:00
backend/drm: introduce wlr_drm_bo_handle_table
Using GBM to import DRM dumb buffers tends to not work well. By
using GBM we're calling some driver-specific functions in Mesa.
These functions check whether Mesa can work with the buffer.
Sometimes Mesa has requirements which differ from DRM dumb buffers
and the GBM import will fail (e.g. on amdgpu).
Instead, drop GBM and use drmPrimeFDToHandle directly. But there's
a twist: BO handles are not ref'counted by the kernel and need to
be ref'counted in user-space [1]. libdrm usually performs this
bookkeeping and is used under-the-hood by Mesa.
We can't re-use libdrm for this task without using driver-specific
APIs. So let's just re-implement the ref'counting logic in wlroots.
The wlroots implementation is inspired from amdgpu's in libdrm [2].
Closes: https://github.com/swaywm/wlroots/issues/2916
[1]: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/110
[2]: 1a4c0ec9ae/amdgpu/handle_table.c
This commit is contained in:
parent
749b3c00f0
commit
5dfaf5ea9c
13 changed files with 189 additions and 134 deletions
|
|
@ -2,7 +2,6 @@
|
|||
#include <drm_fourcc.h>
|
||||
#include <drm_mode.h>
|
||||
#include <drm.h>
|
||||
#include <gbm.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
|
@ -175,56 +174,6 @@ const char *conn_get_name(uint32_t type_id) {
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t get_fb_for_bo(struct gbm_bo *bo, bool with_modifiers) {
|
||||
struct gbm_device *gbm = gbm_bo_get_device(bo);
|
||||
|
||||
int fd = gbm_device_get_fd(gbm);
|
||||
uint32_t width = gbm_bo_get_width(bo);
|
||||
uint32_t height = gbm_bo_get_height(bo);
|
||||
uint32_t format = gbm_bo_get_format(bo);
|
||||
|
||||
uint32_t handles[4] = {0};
|
||||
uint32_t strides[4] = {0};
|
||||
uint32_t offsets[4] = {0};
|
||||
uint64_t modifiers[4] = {0};
|
||||
for (int i = 0; i < gbm_bo_get_plane_count(bo); i++) {
|
||||
handles[i] = gbm_bo_get_handle_for_plane(bo, i).u32;
|
||||
strides[i] = gbm_bo_get_stride_for_plane(bo, i);
|
||||
offsets[i] = gbm_bo_get_offset(bo, i);
|
||||
// KMS requires all BO planes to have the same modifier
|
||||
modifiers[i] = gbm_bo_get_modifier(bo);
|
||||
}
|
||||
|
||||
uint32_t id = 0;
|
||||
if (with_modifiers && gbm_bo_get_modifier(bo) != DRM_FORMAT_MOD_INVALID) {
|
||||
if (drmModeAddFB2WithModifiers(fd, width, height, format, handles,
|
||||
strides, offsets, modifiers, &id, DRM_MODE_FB_MODIFIERS)) {
|
||||
wlr_log_errno(WLR_ERROR, "Unable to add DRM framebuffer");
|
||||
}
|
||||
} else {
|
||||
int ret = drmModeAddFB2(fd, width, height, format, handles, strides,
|
||||
offsets, &id, 0);
|
||||
if (ret != 0 && gbm_bo_get_format(bo) == GBM_FORMAT_ARGB8888 &&
|
||||
gbm_bo_get_plane_count(bo) == 1) {
|
||||
// Some big-endian machines don't support drmModeAddFB2. Try a
|
||||
// last-resort fallback for ARGB8888 buffers, like Xorg's
|
||||
// modesetting driver does.
|
||||
wlr_log(WLR_DEBUG, "drmModeAddFB2 failed (%s), falling back to "
|
||||
"legacy drmModeAddFB", strerror(-ret));
|
||||
|
||||
uint32_t depth = 32;
|
||||
uint32_t bpp = gbm_bo_get_bpp(bo);
|
||||
ret = drmModeAddFB(fd, width, height, depth, bpp, strides[0],
|
||||
handles[0], &id);
|
||||
}
|
||||
if (ret != 0) {
|
||||
wlr_log(WLR_ERROR, "Unable to add DRM framebuffer: %s", strerror(-ret));
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
static bool is_taken(size_t n, const uint32_t arr[static n], uint32_t key) {
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
if (arr[i] == key) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue