Skip to content

Commit

Permalink
Merge pull request #248 from vially/bufferdetect
Browse files Browse the repository at this point in the history
Implement buffer API autodetection
  • Loading branch information
Cloudef committed Apr 5, 2017
2 parents 1364e92 + 4c1cd18 commit a7a3db8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ ENV VARIABLES
+-----------------------+-----------------------------------------------------+
| ``WLC_DRM_DEVICE`` | Device to use in DRM mode. (card0 default) |
+-----------------------+-----------------------------------------------------+
| ``WLC_USE_EGLDEVICE`` | Set 1 to force EGL streams instead of GBM. |
| ``WLC_BUFFER_API`` | Force buffer API to ``GBM`` or ``EGL``. |
+-----------------------+-----------------------------------------------------+
| ``WLC_SHM`` | Set 1 to force EGL clients to use shared memory. |
+-----------------------+-----------------------------------------------------+
Expand Down Expand Up @@ -110,12 +110,12 @@ The permissions will be dropped runtime.
BUFFER API
----------

``wlc`` supports both ``GBM`` and ``EGL streams`` buffer APIs. ``GBM`` is used by default and is supported by most GPU drivers except the NVIDIA proprietary driver.
``wlc`` supports both ``GBM`` and ``EGL`` streams buffer APIs. The buffer API is auto-detected based on the driver used by the DRM device.

If you have a NVIDIA GPU using the proprietary driver you need to:
- ``GBM`` is supported by most GPU drivers except the NVIDIA proprietary driver.
- ``EGL`` is only supported by the NVIDIA proprietary. If you have a NVIDIA GPU using the proprietary driver you need to enable DRM KMS using the ``nvidia-drm.modeset=1`` kernel parameter.

- enable DRM KMS using the ``nvidia-drm.modeset=1`` kernel parameter
- enable the ``EGL streams`` support by setting the ``WLC_USE_EGLDEVICE`` environment variable: ``export WLC_USE_EGLDEVICE=1``
You can force a given buffer API by setting the ``WLC_BUFFER_API`` environment variable to ``GBM`` or ``EGL``.

ISSUES
------
Expand Down
20 changes: 19 additions & 1 deletion src/platform/backend/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,26 @@ update_outputs(struct chck_pool *outputs)
return count;
}

static bool
use_egldevice(int drm_fd)
{
const char *buffer_api = getenv("WLC_BUFFER_API");
if (chck_cstr_is_empty(buffer_api)) {
drmVersion *version;
if (!(version = drmGetVersion(drm_fd)))
return false;

bool use_egl = chck_cstreq(version->name, "nvidia-drm");
drmFreeVersion(version);
return use_egl;
}

return chck_cstreq(buffer_api, "EGL");
}

bool
wlc_drm(struct wlc_backend *backend)
{
chck_cstr_to_bool(getenv("WLC_USE_EGLDEVICE"), &drm.use_egldevice);
drm.fd = -1;

const char *device = getenv("WLC_DRM_DEVICE");
Expand All @@ -611,6 +627,8 @@ wlc_drm(struct wlc_backend *backend)
if (drm.fd < 0)
goto card_open_fail;

drm.use_egldevice = use_egldevice(drm.fd);

if (!drm.use_egldevice) {
/* GBM will load a dri driver, but even though they need symbols from
* libglapi, in some version of Mesa they are not linked to it. Since
Expand Down

0 comments on commit a7a3db8

Please sign in to comment.