Skip to content

Commit

Permalink
panfrost patches
Browse files Browse the repository at this point in the history
  • Loading branch information
SolDev69 committed Dec 28, 2023
1 parent f41084c commit 10da4b3
Show file tree
Hide file tree
Showing 27 changed files with 606 additions and 146 deletions.
145 changes: 111 additions & 34 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,59 +1,136 @@
`Mesa <https://mesa3d.org>`_ - The 3D Graphics Library
======================================================

Valhall v10 "CSF" support branch—for Mali G710/G610.

Note that firmware is required for these GPUs, for RK3588 try
downloading the file from the Rockchip `libmali
<https://github.com/JeffyCN/rockchip_mirrors/tree/libmali/firmware/g610>`_
repo, and placing it in ``/lib/firmware/``.

Windowing system support
------------------------

Panfrost Wayland compositor (wlroots):

#. Panfrost Wayland clients
#. Panfrost X11 clients via Xwayland [1]_
#. Blob X11 clients via Xwayland + dri2to3 [2]_

Panfrost Wayland compositor (non-wlroots):

#. Panfrost Wayland clients
#. Panfrost X11 clients via Xwayland
#. Blob Wayland clients
#. Blob X11 clients via Xwayland + dri2to3 [2]_

Blob Wayland compositor:

#. Panfrost Wayland clients
#. Blob Wayland clients

Panfrost Xorg server: [3]_

#. Panfrost X11 clients
#. Blob X11 clients

Blob Xorg server:

#. Panfrost X11 clients
#. Blob X11 clients

Applications using KMS/DRM will also work.

.. [1] Requires ``CONFIG_DRM_IGNORE_IOTCL_PERMIT`` to be disabled in
the kernel configuration. The option is broken and should never
be enabled anyway.
.. [2] See https://gitlab.com/panfork/dri2to3
.. [3] For Radxa Debian/Ubuntu, the ``xserver-xorg-core`` version
installed by default is not compatible with Panfrost. But note
that upstream Xorg does not work will the blob, so Mesa must be
installed so that it is used by default. (see the "Usage"
section below). To switch between the upstream and Rockchip
versions, run:
.. code-block:: sh
$ sudo apt install xserver-xorg-core="$(apt-cache show xserver-xorg-core | grep Version | grep -v "$(dpkg -s xserver-xorg-core | grep Version)" | cut -d" " -f2)"
Broken combinations:

#. Panfrost wlroots + Blob Wayland does not work because wlroots does
not expose the ``mali_buffer_sharing`` protocol. This might be
fixable.
#. Blob Wayland compositor + Panfrost X11 does not work because the
blob does not expose the required protocols for Xwayland
acceleration to work

Source
------

This repository lives at https://gitlab.freedesktop.org/mesa/mesa.
Other repositories are likely forks, and code found there is not supported.
This repository lives at https://gitlab.com/panfork/mesa, and is a
fork, so not supported by upstream.

Upstream source is at https://gitlab.freedesktop.org/mesa/mesa.

Build & install
---------------
Depdendencies
-------------

You can find more information in our documentation (`docs/install.rst
<https://mesa3d.org/install.html>`_), but the recommended way is to use
Meson (`docs/meson.rst <https://mesa3d.org/meson.html>`_):
For Debian-based distributions:

.. code-block:: sh
$ mkdir build
$ cd build
$ meson ..
$ sudo apt install build-essential meson git python3-mako libexpat1-dev bison flex libwayland-egl-backend-dev libxext-dev libxfixes-dev libxcb-glx0-dev libxcb-shm0-dev libxcb-dri2-0-dev libxcb-dri3-dev libxcb-present-dev libxshmfence-dev libxxf86vm-dev libxrandr-dev
Also needed is ``libdrm`` and ``wayland-protocols``, but those
packages are too old in Debian Bullseye, and must be compiled from
source:

.. code-block:: sh
$ git clone https://gitlab.freedesktop.org/mesa/drm
$ mkdir drm/build
$ cd drm/build
$ meson
$ sudo ninja install
.. code-block:: sh
$ git clone https://gitlab.freedesktop.org/wayland/wayland-protocols
$ mkdir wayland-protocols/build
$ cd wayland-protocols/build
$ git checkout 1.24
$ meson
$ sudo ninja install
Build & install
---------------

Support
-------
To install to ``/opt/panfrost``:

Many Mesa devs hang on IRC; if you're not sure which channel is
appropriate, you should ask your question on `OFTC's #dri-devel
<irc://irc.oftc.net/dri-devel>`_, someone will redirect you if
necessary.
Remember that not everyone is in the same timezone as you, so it might
take a while before someone qualified sees your question.
To figure out who you're talking to, or which nick to ping for your
question, check out `Who's Who on IRC
<https://dri.freedesktop.org/wiki/WhosWho/>`_.
.. code-block:: sh
The next best option is to ask your question in an email to the
mailing lists: `mesa-dev\@lists.freedesktop.org
<https://lists.freedesktop.org/mailman/listinfo/mesa-dev>`_
$ mkdir build
$ cd build
$ meson -Dgallium-drivers=panfrost -Dvulkan-drivers= -Dllvm=disabled --prefix=/opt/panfrost
$ sudo ninja install
Usage
-----

Bug reports
-----------
To run an application with Panfrost (note the windowing system support
section above):

If you think something isn't working properly, please file a bug report
(`docs/bugs.rst <https://mesa3d.org/bugs.html>`_).
.. code-block:: sh
$ LD_LIBRARY_PATH=/opt/panfrost/lib/aarch64-linux-gnu glmark2-es2-wayland
Contributing
------------
To use Panfrost by default, add the directory where you installed it
to the library search path:

Contributions are welcome, and step-by-step instructions can be found in our
documentation (`docs/submittingpatches.rst
<https://mesa3d.org/submittingpatches.html>`_).
.. code-block:: sh
Note that Mesa uses gitlab for patches submission, review and discussions.
$ echo /opt/panfrost/lib/aarch64-linux-gnu | sudo tee /etc/ld.so.conf.d/0-panfrost.conf
$ sudo ldconfig
7 changes: 7 additions & 0 deletions include/drm-uapi/drm_fourcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,13 @@ drm_fourcc_canonicalize_nvidia_format_mod(__u64 modifier)
*/
#define AFBC_FORMAT_MOD_USM (1ULL << 12)

/* AFBC native swizzle
*
* Indicates that the buffer is using RGBA component order regardless of the
* actual format.
*/
#define AFBC_FORMAT_MOD_NATIVE_SWIZZLE (1ULL << 32)

/*
* Arm Fixed-Rate Compression (AFRC) modifiers
*
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/glsl/standalone_scaffolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ void initialize_context_to_defaults(struct gl_context *ctx, gl_api api)
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxUniformComponents = 1024;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxInputComponents = 0; /* not used */
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxOutputComponents = 0; /* not used */
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxAtomicBuffers = 16;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxAtomicCounters = 16;
ctx->Const.Program[MESA_SHADER_COMPUTE].MaxShaderStorageBlocks = 16;

/* Set up default shader compiler options. */
struct gl_shader_compiler_options options;
Expand Down
4 changes: 4 additions & 0 deletions src/drm-shim/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ drm_shim_ioctl(int fd, unsigned long request, void *arg)
ASSERTED int type = _IOC_TYPE(request);
int nr = _IOC_NR(request);

/* Used by kbase; do not claim to be a kbase FD */
if (type == 0x80)
return -EINVAL;

assert(type == DRM_IOCTL_BASE);

if (nr >= DRM_COMMAND_BASE && nr < DRM_COMMAND_END) {
Expand Down
2 changes: 2 additions & 0 deletions src/egl/drivers/dri2/egl_dri2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3322,6 +3322,8 @@ dri2_query_wayland_buffer_wl(_EGLDisplay *disp,
const struct wl_drm_components_descriptor *format;

buffer = wayland_drm_buffer_get(dri2_dpy->wl_server_drm, buffer_resource);
if (!buffer)
buffer = wayland_drm_buffer_get(dri2_dpy->wl_server_mali, buffer_resource);
if (!buffer)
return EGL_FALSE;

Expand Down
4 changes: 4 additions & 0 deletions src/egl/drivers/dri2/egl_dri2.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,11 @@ struct dri2_egl_display {
struct wl_display *wl_dpy_wrapper;
struct wl_registry *wl_registry;
struct wl_drm *wl_server_drm;
struct wl_drm *wl_server_mali;
struct wl_drm *wl_drm;
struct wl_drm *wl_mali;
uint32_t wl_drm_version, wl_drm_name;
uint32_t wl_mali_version, wl_mali_name;
struct wl_shm *wl_shm;
struct wl_event_queue *wl_queue;
struct zwp_linux_dmabuf_v1 *wl_dmabuf;
Expand Down Expand Up @@ -345,6 +348,7 @@ struct dri2_egl_surface {
struct wl_surface *wl_surface_wrapper;
struct wl_display *wl_dpy_wrapper;
struct wl_drm *wl_drm_wrapper;
struct wl_drm *wl_mali_wrapper;
struct wl_callback *throttle_callback;
struct zwp_linux_dmabuf_feedback_v1 *wl_dmabuf_feedback;
struct dmabuf_feedback dmabuf_feedback, pending_dmabuf_feedback;
Expand Down
92 changes: 91 additions & 1 deletion src/egl/drivers/dri2/platform_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ dri2_wl_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
dri2_surf->base.PresentOpaque);
assert(visual_idx != -1);

if (dri2_dpy->wl_dmabuf || dri2_dpy->wl_drm) {
if (dri2_dpy->wl_dmabuf || dri2_dpy->wl_drm || dri2_dpy->wl_mali) {
dri2_surf->format = dri2_wl_visuals[visual_idx].wl_drm_format;
} else {
assert(dri2_dpy->wl_shm);
Expand All @@ -771,6 +771,16 @@ dri2_wl_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
dri2_surf->wl_queue);
}

if (dri2_dpy->wl_mali) {
dri2_surf->wl_mali_wrapper = wl_proxy_create_wrapper(dri2_dpy->wl_mali);
if (!dri2_surf->wl_mali_wrapper) {
_eglError(EGL_BAD_ALLOC, "dri2_create_surface");
goto cleanup_queue;
}
wl_proxy_set_queue((struct wl_proxy *)dri2_surf->wl_mali_wrapper,
dri2_surf->wl_queue);
}

dri2_surf->wl_dpy_wrapper = wl_proxy_create_wrapper(dri2_dpy->wl_dpy);
if (!dri2_surf->wl_dpy_wrapper) {
_eglError(EGL_BAD_ALLOC, "dri2_create_surface");
Expand Down Expand Up @@ -907,6 +917,8 @@ dri2_wl_destroy_surface(_EGLDisplay *disp, _EGLSurface *surf)
wl_proxy_wrapper_destroy(dri2_surf->wl_dpy_wrapper);
if (dri2_surf->wl_drm_wrapper)
wl_proxy_wrapper_destroy(dri2_surf->wl_drm_wrapper);
if (dri2_surf->wl_mali_wrapper)
wl_proxy_wrapper_destroy(dri2_surf->wl_mali_wrapper);
if (dri2_surf->wl_dmabuf_feedback) {
zwp_linux_dmabuf_feedback_v1_destroy(dri2_surf->wl_dmabuf_feedback);
dmabuf_feedback_fini(&dri2_surf->dmabuf_feedback);
Expand Down Expand Up @@ -1503,6 +1515,26 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy,
ret = zwp_linux_buffer_params_v1_create_immed(params, width, height,
fourcc, 0);
zwp_linux_buffer_params_v1_destroy(params);
} else if (dri2_surf->wl_mali_wrapper || dri2_dpy->wl_mali) {
struct wl_drm *wl_mali =
dri2_surf ? dri2_surf->wl_mali_wrapper : dri2_dpy->wl_mali;
int fd = -1, stride;

if (num_planes > 1)
return NULL;

query = dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_FD, &fd);
query &= dri2_dpy->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
if (!query) {
if (fd >= 0)
close(fd);
return NULL;
}

ret = mali_buffer_sharing_create_buffer((void *)wl_mali,
width, height, stride,
fourcc, 0, 0, fd);
close(fd);
} else {
struct wl_drm *wl_drm =
dri2_surf ? dri2_surf->wl_drm_wrapper : dri2_dpy->wl_drm;
Expand Down Expand Up @@ -1776,6 +1808,62 @@ drm_handle_device(void *data, struct wl_drm *drm, const char *device)
}
}

static void
mali_handle_device(void *data, struct mali_buffer_sharing *drm, const char *device)
{
struct dri2_egl_display *dri2_dpy = data;
drm_magic_t magic;

// hack
//printf("device '%s'\n", device);
dri2_dpy->device_name = strdup("/dev/dri/card0");

dri2_dpy->fd = loader_open_device(dri2_dpy->device_name);
if (dri2_dpy->fd == -1) {
_eglLog(_EGL_WARNING, "wayland-egl: could not open %s (%s)",
dri2_dpy->device_name, strerror(errno));
free(dri2_dpy->device_name);
dri2_dpy->device_name = NULL;
return;
}

if (drmGetNodeTypeFromFd(dri2_dpy->fd) == DRM_NODE_RENDER) {
dri2_dpy->authenticated = true;
} else {
roundtrip(dri2_dpy);
if (drmGetMagic(dri2_dpy->fd, &magic)) {
close(dri2_dpy->fd);
dri2_dpy->fd = -1;
free(dri2_dpy->device_name);
dri2_dpy->device_name = NULL;
_eglLog(_EGL_WARNING, "wayland-egl: drmGetMagic failed");
return;
}

mali_buffer_sharing_auth((void *)dri2_dpy->wl_mali, magic);
roundtrip(dri2_dpy);
// We don't get a callback
dri2_dpy->authenticated = true;
}

int supported_fourcc[] = {
WL_DRM_FORMAT_ABGR16F,
WL_DRM_FORMAT_ABGR2101010,
WL_DRM_FORMAT_XRGB8888,
WL_DRM_FORMAT_ARGB8888,
WL_DRM_FORMAT_ABGR8888,
WL_DRM_FORMAT_XBGR8888,
WL_DRM_FORMAT_RGB565,
};

for (unsigned i = 0; i < ARRAY_SIZE(supported_fourcc); ++i) {
int visual_idx = dri2_wl_visual_idx_from_fourcc(supported_fourcc[i]);
assert(visual_idx != -1);

BITSET_SET(dri2_dpy->formats.formats_bitmap, visual_idx);
}
}

static void
drm_handle_format(void *data, struct wl_drm *drm, uint32_t format)
{
Expand Down Expand Up @@ -2836,6 +2924,8 @@ dri2_teardown_wayland(struct dri2_egl_display *dri2_dpy)
dri2_wl_formats_fini(&dri2_dpy->formats);
if (dri2_dpy->wl_drm)
wl_drm_destroy(dri2_dpy->wl_drm);
if (dri2_dpy->wl_mali)
wl_drm_destroy(dri2_dpy->wl_mali);
if (dri2_dpy->wl_dmabuf)
zwp_linux_dmabuf_v1_destroy(dri2_dpy->wl_dmabuf);
if (dri2_dpy->wl_shm)
Expand Down
5 changes: 5 additions & 0 deletions src/gallium/auxiliary/cso_cache/cso_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,11 @@ cso_single_sampler(struct cso_context *cso, enum pipe_shader_type shader_stage,
}
}

void
cso_set_max_sampler(struct cso_context *ctx, int max_sampler_seen)
{
ctx->max_sampler_seen = max_sampler_seen;
}

/**
* Send staged sampler state to the driver.
Expand Down
3 changes: 3 additions & 0 deletions src/gallium/auxiliary/cso_cache/cso_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ void
cso_single_sampler(struct cso_context *cso, enum pipe_shader_type shader_stage,
unsigned idx, const struct pipe_sampler_state *states);

void
cso_set_max_sampler(struct cso_context *ctx, int max_sampler_seen);

void
cso_single_sampler_done(struct cso_context *cso,
enum pipe_shader_type shader_stage);
Expand Down
Loading

0 comments on commit 10da4b3

Please sign in to comment.