--- /dev/null
+From afd8b2f498a417de6ecdbd13045d97c9ecf4391b Mon Sep 17 00:00:00 2001
+From: Simon Ser <contact@emersion.fr>
+Date: Mon, 14 Dec 2020 18:32:47 +0100
+Subject: [PATCH] dri: add createImageWithModifiers2 interface
+
+With the addition of createImageWithModifiers usage flags were
+dropped, as it was believed at the time that modifers will be a
+full replacement for the usage flags. This has turned out to be
+untrue, as modifiers are not able to describe buffer placement.
+
+Add a new version of the interface, that allows to specifiy
+use flags in addition to the modifier.
+
+Signed-off-by: Simon Ser <contact@emersion.fr>
+Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
+Reviewed-by: Daniel Stone <daniels@collabora.com>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8106>
+Upstream-Status: Applied [https://gitlab.freedesktop.org/mesa/mesa/-/commit/afd8b2f498a417de6ecdbd13045d97c9ecf4391b]
+---
+ include/GL/internal/dri_interface.h | 24 +++++++++++++++++++++++-
+ 1 file changed, 23 insertions(+), 1 deletion(-)
+
+diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
+index 9b85e67ce49..a7d9903f94e 100644
+--- a/include/GL/internal/dri_interface.h
++++ b/include/GL/internal/dri_interface.h
+@@ -1328,7 +1328,7 @@ struct __DRIdri2ExtensionRec {
+ * extensions.
+ */
+ #define __DRI_IMAGE "DRI_IMAGE"
+-#define __DRI_IMAGE_VERSION 18
++#define __DRI_IMAGE_VERSION 19
+
+ /**
+ * These formats correspond to the similarly named MESA_FORMAT_*
+@@ -1803,6 +1803,28 @@ struct __DRIimageExtensionRec {
+ uint32_t flags,
+ unsigned *error,
+ void *loaderPrivate);
++
++ /**
++ * Creates an image with implementation's favorite modifiers and the
++ * provided usage flags.
++ *
++ * This acts like createImageWithModifiers except usage is also specified.
++ *
++ * The created image should be destroyed with destroyImage().
++ *
++ * Returns the new DRIimage. The chosen modifier can be obtained later on
++ * and passed back to things like the kernel's AddFB2 interface.
++ *
++ * \sa __DRIimageRec::createImage
++ *
++ * \since 19
++ */
++ __DRIimage *(*createImageWithModifiers2)(__DRIscreen *screen,
++ int width, int height, int format,
++ const uint64_t *modifiers,
++ const unsigned int modifier_count,
++ unsigned int use,
++ void *loaderPrivate);
+ };
+
+
+--
+2.31.1
+
--- /dev/null
+From cb9ae4273d680ab34fc2ca933c4f960e7f086275 Mon Sep 17 00:00:00 2001
+From: Lucas Stach <l.stach@pengutronix.de>
+Date: Tue, 15 Dec 2020 14:39:32 +0100
+Subject: [PATCH] dri: add loader_dri_create_image helper
+
+The DRI image extension already has two different ways to allocate an
+image (with and without a modifier) and will soon grow a third one.
+Add a helper, which handles calling the appropriate implementation to
+get rid of code duplication in the winsys.
+
+This convert the two obvious call sites (GBM dri and EGL wayland)
+that profit from the code dedup.
+
+Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
+Reviewed-by: Daniel Stone <daniels@collabora.com>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8106>
+Upstream-Status: Applied [https://gitlab.freedesktop.org/mesa/mesa/-/commit/cb9ae4273d680ab34fc2ca933c4f960e7f086275]
+---
+ src/egl/drivers/dri2/platform_wayland.c | 60 +++++++---------------
+ src/gbm/backends/dri/gbm_dri.c | 53 +++++--------------
+ src/loader/Makefile.sources | 2 +
+ src/loader/loader_dri_helper.c | 68 +++++++++++++++++++++++++
+ src/loader/loader_dri_helper.h | 33 ++++++++++++
+ src/loader/meson.build | 2 +-
+ 6 files changed, 134 insertions(+), 84 deletions(-)
+ create mode 100644 src/loader/loader_dri_helper.c
+ create mode 100644 src/loader/loader_dri_helper.h
+
+diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
+index 26b6711952c..180380b4c4c 100644
+--- a/src/egl/drivers/dri2/platform_wayland.c
++++ b/src/egl/drivers/dri2/platform_wayland.c
+@@ -40,6 +40,7 @@
+ #include <sys/mman.h>
+
+ #include "egl_dri2.h"
++#include "loader_dri_helper.h"
+ #include "loader.h"
+ #include "util/u_vector.h"
+ #include "util/anon_file.h"
+@@ -578,28 +579,16 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
+ dri2_surf->back->linear_copy == NULL) {
+ /* The LINEAR modifier should be a perfect alias of the LINEAR use
+ * flag; try the new interface first before the old, then fall back. */
+- if (dri2_dpy->image->base.version >= 15 &&
+- dri2_dpy->image->createImageWithModifiers) {
+- uint64_t linear_mod = DRM_FORMAT_MOD_LINEAR;
+-
+- dri2_surf->back->linear_copy =
+- dri2_dpy->image->createImageWithModifiers(dri2_dpy->dri_screen,
+- dri2_surf->base.Width,
+- dri2_surf->base.Height,
+- linear_dri_image_format,
+- &linear_mod,
+- 1,
+- NULL);
+- } else {
+- dri2_surf->back->linear_copy =
+- dri2_dpy->image->createImage(dri2_dpy->dri_screen,
+- dri2_surf->base.Width,
+- dri2_surf->base.Height,
+- linear_dri_image_format,
+- use_flags |
+- __DRI_IMAGE_USE_LINEAR,
+- NULL);
+- }
++ uint64_t linear_mod = DRM_FORMAT_MOD_LINEAR;
++
++ dri2_surf->back->linear_copy =
++ loader_dri_create_image(dri2_dpy->dri_screen, dri2_dpy->image,
++ dri2_surf->base.Width,
++ dri2_surf->base.Height,
++ linear_dri_image_format,
++ use_flags | __DRI_IMAGE_USE_LINEAR,
++ &linear_mod, 1, NULL);
++
+ if (dri2_surf->back->linear_copy == NULL)
+ return -1;
+ }
+@@ -609,26 +598,13 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
+ * createImageWithModifiers, then fall back to the old createImage,
+ * and hope it allocates an image which is acceptable to the winsys.
+ */
+- if (num_modifiers && dri2_dpy->image->base.version >= 15 &&
+- dri2_dpy->image->createImageWithModifiers) {
+- dri2_surf->back->dri_image =
+- dri2_dpy->image->createImageWithModifiers(dri2_dpy->dri_screen,
+- dri2_surf->base.Width,
+- dri2_surf->base.Height,
+- dri_image_format,
+- modifiers,
+- num_modifiers,
+- NULL);
+- } else {
+- dri2_surf->back->dri_image =
+- dri2_dpy->image->createImage(dri2_dpy->dri_screen,
+- dri2_surf->base.Width,
+- dri2_surf->base.Height,
+- dri_image_format,
+- dri2_dpy->is_different_gpu ?
+- 0 : use_flags,
+- NULL);
+- }
++ dri2_surf->back->dri_image =
++ loader_dri_create_image(dri2_dpy->dri_screen, dri2_dpy->image,
++ dri2_surf->base.Width,
++ dri2_surf->base.Height,
++ dri_image_format,
++ dri2_dpy->is_different_gpu ? 0 : use_flags,
++ modifiers, num_modifiers, NULL);
+
+ dri2_surf->back->age = 0;
+ }
+diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
+index 751b2e56497..dff0b3c7ecf 100644
+--- a/src/gbm/backends/dri/gbm_dri.c
++++ b/src/gbm/backends/dri/gbm_dri.c
+@@ -47,6 +47,7 @@
+ #include "gbm_driint.h"
+
+ #include "gbmint.h"
++#include "loader_dri_helper.h"
+ #include "loader.h"
+ #include "util/debug.h"
+ #include "util/macros.h"
+@@ -1151,8 +1152,7 @@ gbm_dri_bo_create(struct gbm_device *gbm,
+ struct gbm_dri_device *dri = gbm_dri_device(gbm);
+ struct gbm_dri_bo *bo;
+ int dri_format;
+- unsigned dri_use = 0, i;
+- bool has_valid_modifier;
++ unsigned dri_use = 0;
+
+ /* Callers of this may specify a modifier, or a dri usage, but not both. The
+ * newer modifier interface deprecates the older usage flags.
+@@ -1191,50 +1191,21 @@ gbm_dri_bo_create(struct gbm_device *gbm,
+ /* Gallium drivers requires shared in order to get the handle/stride */
+ dri_use |= __DRI_IMAGE_USE_SHARE;
+
+- if (modifiers) {
+- if (!dri->image || dri->image->base.version < 14 ||
+- !dri->image->createImageWithModifiers) {
+- errno = ENOSYS;
+- goto failed;
+- }
+-
+- /* It's acceptable to create an image with INVALID modifier in the list,
+- * but it cannot be on the only modifier (since it will certainly fail
+- * later). While we could easily catch this after modifier creation, doing
+- * the check here is a convenient debug check likely pointing at whatever
+- * interface the client is using to build its modifier list.
+- */
+- has_valid_modifier = false;
+- for (i = 0; i < count; i++) {
+- if (modifiers[i] != DRM_FORMAT_MOD_INVALID) {
+- has_valid_modifier = true;
+- break;
+- }
+- }
+- if (!has_valid_modifier) {
+- errno = EINVAL;
+- goto failed;
+- }
+-
+- bo->image =
+- dri->image->createImageWithModifiers(dri->screen,
+- width, height,
+- dri_format,
+- modifiers, count,
+- bo);
+-
+- if (bo->image) {
+- /* The client passed in a list of invalid modifiers */
+- assert(gbm_dri_bo_get_modifier(&bo->base) != DRM_FORMAT_MOD_INVALID);
+- }
+- } else {
+- bo->image = dri->image->createImage(dri->screen, width, height,
+- dri_format, dri_use, bo);
++ if (modifiers && (dri->image->base.version < 14 ||
++ !dri->image->createImageWithModifiers)) {
++ errno = ENOSYS;
++ return NULL;
+ }
+
++ bo->image = loader_dri_create_image(dri->screen, dri->image, width, height,
++ dri_format, dri_use, modifiers, count,
++ bo);
+ if (bo->image == NULL)
+ goto failed;
+
++ if (modifiers)
++ assert(gbm_dri_bo_get_modifier(&bo->base) != DRM_FORMAT_MOD_INVALID);
++
+ dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
+ &bo->base.handle.s32);
+ dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE,
+diff --git a/src/loader/Makefile.sources b/src/loader/Makefile.sources
+index b61ef1cd943..6627222ac30 100644
+--- a/src/loader/Makefile.sources
++++ b/src/loader/Makefile.sources
+@@ -1,4 +1,6 @@
+ LOADER_C_FILES := \
++ loader_dri_helper.c \
++ loader_dri_helper.h \
+ loader.c \
+ loader.h \
+ pci_id_driver_map.c \
+diff --git a/src/loader/loader_dri_helper.c b/src/loader/loader_dri_helper.c
+new file mode 100644
+index 00000000000..21419f087d6
+--- /dev/null
++++ b/src/loader/loader_dri_helper.c
+@@ -0,0 +1,68 @@
++/*
++ * Permission to use, copy, modify, distribute, and sell this software and its
++ * documentation for any purpose is hereby granted without fee, provided that
++ * the above copyright notice appear in all copies and that both that copyright
++ * notice and this permission notice appear in supporting documentation, and
++ * that the name of the copyright holders not be used in advertising or
++ * publicity pertaining to distribution of the software without specific,
++ * written prior permission. The copyright holders make no representations
++ * about the suitability of this software for any purpose. It is provided "as
++ * is" without express or implied warranty.
++ *
++ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
++ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
++ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
++ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
++ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
++ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
++ * OF THIS SOFTWARE.
++ */
++
++#include <errno.h>
++#include <stdbool.h>
++#include <stdio.h>
++#include <sys/types.h>
++
++#include <GL/gl.h> /* dri_interface needs GL types */
++#include <GL/internal/dri_interface.h>
++
++#include "drm-uapi/drm_fourcc.h"
++#include "loader_dri_helper.h"
++
++__DRIimage *loader_dri_create_image(__DRIscreen *screen,
++ const __DRIimageExtension *image,
++ uint32_t width, uint32_t height,
++ uint32_t dri_format, uint32_t dri_usage,
++ const uint64_t *modifiers,
++ unsigned int modifiers_count,
++ void *loaderPrivate)
++{
++ if (modifiers &&
++ image->base.version > 14 && image->createImageWithModifiers) {
++ bool has_valid_modifier = false;
++ int i;
++
++ /* It's acceptable to create an image with INVALID modifier in the list,
++ * but it cannot be on the only modifier (since it will certainly fail
++ * later). While we could easily catch this after modifier creation, doing
++ * the check here is a convenient debug check likely pointing at whatever
++ * interface the client is using to build its modifier list.
++ */
++ for (i = 0; i < modifiers_count; i++) {
++ if (modifiers[i] != DRM_FORMAT_MOD_INVALID) {
++ has_valid_modifier = true;
++ break;
++ }
++ }
++ if (!has_valid_modifier)
++ return NULL;
++
++ return image->createImageWithModifiers(screen, width, height,
++ dri_format, modifiers,
++ modifiers_count, loaderPrivate);
++ }
++
++ /* No modifier given or fallback to the legacy createImage allowed */
++ return image->createImage(screen, width, height, dri_format, dri_usage,
++ loaderPrivate);
++}
+diff --git a/src/loader/loader_dri_helper.h b/src/loader/loader_dri_helper.h
+new file mode 100644
+index 00000000000..e0aae69477b
+--- /dev/null
++++ b/src/loader/loader_dri_helper.h
+@@ -0,0 +1,33 @@
++/*
++ * Permission to use, copy, modify, distribute, and sell this software and its
++ * documentation for any purpose is hereby granted without fee, provided that
++ * the above copyright notice appear in all copies and that both that copyright
++ * notice and this permission notice appear in supporting documentation, and
++ * that the name of the copyright holders not be used in advertising or
++ * publicity pertaining to distribution of the software without specific,
++ * written prior permission. The copyright holders make no representations
++ * about the suitability of this software for any purpose. It is provided "as
++ * is" without express or implied warranty.
++ *
++ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
++ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
++ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
++ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
++ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
++ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
++ * OF THIS SOFTWARE.
++ */
++
++#include <stdbool.h>
++#include <sys/types.h>
++
++#include <GL/gl.h> /* dri_interface needs GL types */
++#include <GL/internal/dri_interface.h>
++
++__DRIimage *loader_dri_create_image(__DRIscreen *screen,
++ const __DRIimageExtension *image,
++ uint32_t width, uint32_t height,
++ uint32_t dri_format, uint32_t dri_usage,
++ const uint64_t *modifiers,
++ unsigned int modifiers_count,
++ void *loaderPrivate);
+diff --git a/src/loader/meson.build b/src/loader/meson.build
+index 34a43e33f09..57a93c3aa17 100644
+--- a/src/loader/meson.build
++++ b/src/loader/meson.build
+@@ -47,7 +47,7 @@ endif
+
+ libloader = static_library(
+ 'loader',
+- ['loader.c', 'pci_id_driver_map.c'],
++ ['loader_dri_helper.c', 'loader.c', 'pci_id_driver_map.c'],
+ c_args : loader_c_args,
+ gnu_symbol_visibility : 'hidden',
+ include_directories : [inc_include, inc_src, inc_util],
+--
+2.31.1
+
+++ /dev/null
-From 00add4be8620175ccc69869e22479962dacdce9d Mon Sep 17 00:00:00 2001
-From: Lucas Stach <l.stach@pengutronix.de>
-Date: Fri, 13 Nov 2020 14:38:41 +0100
-Subject: [PATCH 2/6] dri: bring back use flags for createImageWithModifiers
-
-createImageWithModifiers dropped the use flags that were present with
-the createImage interface as it was believed at the time that all those
-use flags could be expressed as a modifier. This turned out to be untrue,
-as there are some use flags like SCANOUT and the BACKBUFFER hint that
-won't ever get a eqivalent modifier expression.
-
-Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
-
-Upstream-Status: Submitted [https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7603]
----
- include/GL/internal/dri_interface.h | 1 +
- src/egl/drivers/dri2/platform_wayland.c | 4 ++--
- src/gallium/frontends/dri/dri2.c | 5 ++---
- src/gbm/backends/dri/gbm_dri.c | 2 +-
- src/loader/loader_dri3_helper.c | 3 +++
- src/mesa/drivers/dri/i965/intel_screen.c | 2 +-
- 6 files changed, 10 insertions(+), 7 deletions(-)
-
-diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
-index 39d5dd07533..222821428d0 100644
---- a/include/GL/internal/dri_interface.h
-+++ b/include/GL/internal/dri_interface.h
-@@ -1678,6 +1678,7 @@ struct __DRIimageExtensionRec {
- int width, int height, int format,
- const uint64_t *modifiers,
- const unsigned int modifier_count,
-+ unsigned int use,
- void *loaderPrivate);
-
- /*
-diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
-index c0b26c4b623..bb508cbe421 100644
---- a/src/egl/drivers/dri2/platform_wayland.c
-+++ b/src/egl/drivers/dri2/platform_wayland.c
-@@ -595,7 +595,7 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
- dri2_surf->base.Height,
- linear_dri_image_format,
- &linear_mod,
-- 1,
-+ 1, use_flags,
- NULL);
- } else {
- dri2_surf->back->linear_copy =
-@@ -624,7 +624,7 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
- dri2_surf->base.Height,
- dri_image_format,
- modifiers,
-- num_modifiers,
-+ num_modifiers, use_flags,
- NULL);
- } else {
- dri2_surf->back->dri_image =
-diff --git a/src/gallium/frontends/dri/dri2.c b/src/gallium/frontends/dri/dri2.c
-index 1cd42cd8114..1f1e7a9a65e 100644
---- a/src/gallium/frontends/dri/dri2.c
-+++ b/src/gallium/frontends/dri/dri2.c
-@@ -1074,12 +1074,11 @@ static __DRIimage *
- dri2_create_image_with_modifiers(__DRIscreen *dri_screen,
- int width, int height, int format,
- const uint64_t *modifiers,
-- const unsigned count,
-+ const unsigned count, unsigned int use,
- void *loaderPrivate)
- {
- return dri2_create_image_common(dri_screen, width, height, format,
-- __DRI_IMAGE_USE_SHARE, modifiers, count,
-- loaderPrivate);
-+ use, modifiers, count, loaderPrivate);
- }
-
- static bool
-diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
-index b5634741554..aff3a107e7d 100644
---- a/src/gbm/backends/dri/gbm_dri.c
-+++ b/src/gbm/backends/dri/gbm_dri.c
-@@ -1173,7 +1173,7 @@ gbm_dri_bo_create(struct gbm_device *gbm,
- width, height,
- dri_format,
- modifiers, count,
-- bo);
-+ dri_use, bo);
-
- if (bo->image) {
- /* The client passed in a list of invalid modifiers */
-diff --git a/src/loader/loader_dri3_helper.c b/src/loader/loader_dri3_helper.c
-index ccf8d1795e7..6fc6a2b705a 100644
---- a/src/loader/loader_dri3_helper.c
-+++ b/src/loader/loader_dri3_helper.c
-@@ -1407,6 +1407,9 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
- format,
- modifiers,
- count,
-+ __DRI_IMAGE_USE_SHARE |
-+ __DRI_IMAGE_USE_SCANOUT |
-+ __DRI_IMAGE_USE_BACKBUFFER,
- buffer);
- }
-
-diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
-index 4492d43c040..4511b962eef 100644
---- a/src/mesa/drivers/dri/i965/intel_screen.c
-+++ b/src/mesa/drivers/dri/i965/intel_screen.c
-@@ -893,7 +893,7 @@ static __DRIimage *
- intel_create_image_with_modifiers(__DRIscreen *dri_screen,
- int width, int height, int format,
- const uint64_t *modifiers,
-- const unsigned count,
-+ const unsigned count, unsigned int use,
- void *loaderPrivate)
- {
- return intel_create_image_common(dri_screen, width, height, format, 0,
---
-2.26.2
-
--- /dev/null
+From 8fd5b16efc60ad666b05ec745109d0a482b6157b Mon Sep 17 00:00:00 2001
+From: Lucas Stach <l.stach@pengutronix.de>
+Date: Tue, 15 Dec 2020 14:52:28 +0100
+Subject: [PATCH] loader/dri3: convert to loader_dri_create_image
+
+Get rid of the code duplication and makes it easier to hook in a
+new createImageWithModifiers2, but obscures the code flow a bit.
+
+Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
+Reviewed-by: Daniel Stone <daniels@collabora.com>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8106>
+Upstream-Status: Applied [https://gitlab.freedesktop.org/mesa/mesa/-/commit/8fd5b16efc60ad666b05ec745109d0a482b6157b]
+---
+ src/loader/loader_dri3_helper.c | 40 ++++++++++-----------------------
+ 1 file changed, 12 insertions(+), 28 deletions(-)
+
+diff --git a/src/loader/loader_dri3_helper.c b/src/loader/loader_dri3_helper.c
+index 6c4b704ae5b..c5e340e6942 100644
+--- a/src/loader/loader_dri3_helper.c
++++ b/src/loader/loader_dri3_helper.c
+@@ -34,6 +34,7 @@
+
+ #include <X11/Xlib-xcb.h>
+
++#include "loader_dri_helper.h"
+ #include "loader_dri3_helper.h"
+ #include "util/macros.h"
+ #include "drm-uapi/drm_fourcc.h"
+@@ -1314,6 +1315,8 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
+ struct xshmfence *shm_fence;
+ int buffer_fds[4], fence_fd;
+ int num_planes = 0;
++ uint64_t *modifiers = NULL;
++ uint32_t count = 0;
+ int i, mod;
+ int ret;
+
+@@ -1348,8 +1351,6 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
+ xcb_dri3_get_supported_modifiers_cookie_t mod_cookie;
+ xcb_dri3_get_supported_modifiers_reply_t *mod_reply;
+ xcb_generic_error_t *error = NULL;
+- uint64_t *modifiers = NULL;
+- uint32_t count = 0;
+
+ mod_cookie = xcb_dri3_get_supported_modifiers(draw->conn,
+ draw->window,
+@@ -1395,34 +1396,17 @@ dri3_alloc_render_buffer(struct loader_dri3_drawable *draw, unsigned int format,
+ }
+
+ free(mod_reply);
+-
+- /* don't use createImageWithModifiers() if we have no
+- * modifiers, other things depend on the use flags when
+- * there are no modifiers to know that a buffer can be
+- * shared.
+- */
+- if (modifiers) {
+- buffer->image = draw->ext->image->createImageWithModifiers(draw->dri_screen,
+- width, height,
+- format,
+- modifiers,
+- count,
+- buffer);
+- }
+-
+- free(modifiers);
+ }
+ #endif
+- if (!buffer->image)
+- buffer->image = draw->ext->image->createImage(draw->dri_screen,
+- width, height,
+- format,
+- __DRI_IMAGE_USE_SHARE |
+- __DRI_IMAGE_USE_SCANOUT |
+- __DRI_IMAGE_USE_BACKBUFFER |
+- (draw->is_protected_content ?
+- __DRI_IMAGE_USE_PROTECTED : 0),
+- buffer);
++ buffer->image = loader_dri_create_image(draw->dri_screen, draw->ext->image,
++ width, height, format,
++ __DRI_IMAGE_USE_SHARE |
++ __DRI_IMAGE_USE_SCANOUT |
++ __DRI_IMAGE_USE_BACKBUFFER |
++ (draw->is_protected_content ?
++ __DRI_IMAGE_USE_PROTECTED : 0),
++ modifiers, count, buffer);
++ free(modifiers);
+
+ pixmap_buffer = buffer->image;
+
+--
+2.31.1
+
--- /dev/null
+From c03e79d7831f253b16d6f52f2fb959eb02257a8b Mon Sep 17 00:00:00 2001
+From: Lucas Stach <l.stach@pengutronix.de>
+Date: Tue, 15 Dec 2020 14:59:21 +0100
+Subject: [PATCH] loader/dri: hook up createImageWithModifiers2
+
+Call into the new modifiers with usage createImage variant when available
+to provide the DRI implementation with more context about the allocation.
+
+Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
+Reviewed-by: Daniel Stone <daniels@collabora.com>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8106>
+Upstream-Status: Applied [https://gitlab.freedesktop.org/mesa/mesa/-/commit/c03e79d7831f253b16d6f52f2fb959eb02257a8b]
+---
+ src/loader/loader_dri_helper.c | 12 +++++++++---
+ 1 file changed, 9 insertions(+), 3 deletions(-)
+
+diff --git a/src/loader/loader_dri_helper.c b/src/loader/loader_dri_helper.c
+index 21419f087d6..972ca2da26a 100644
+--- a/src/loader/loader_dri_helper.c
++++ b/src/loader/loader_dri_helper.c
+@@ -57,9 +57,15 @@ __DRIimage *loader_dri_create_image(__DRIscreen *screen,
+ if (!has_valid_modifier)
+ return NULL;
+
+- return image->createImageWithModifiers(screen, width, height,
+- dri_format, modifiers,
+- modifiers_count, loaderPrivate);
++ if (image->base.version >= 19 && image->createImageWithModifiers2)
++ return image->createImageWithModifiers2(screen, width, height,
++ dri_format, modifiers,
++ modifiers_count, dri_usage,
++ loaderPrivate);
++ else
++ return image->createImageWithModifiers(screen, width, height,
++ dri_format, modifiers,
++ modifiers_count, loaderPrivate);
+ }
+
+ /* No modifier given or fallback to the legacy createImage allowed */
+--
+2.31.1
+
+++ /dev/null
-From 570908323e02c4558f5a9abc2d82621056cd65ab Mon Sep 17 00:00:00 2001
-From: Lucas Stach <l.stach@pengutronix.de>
-Date: Tue, 17 Nov 2020 12:08:13 +0100
-Subject: [PATCH 5/6] etnaviv: compact etna_state_updates
-
-Just reclaim a bit of screen real estate, purely cosmetic change.
-
-Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
-
-Upstream-Status: Submitted [https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7603]
----
- src/gallium/drivers/etnaviv/etnaviv_state.c | 18 ++++++------------
- 1 file changed, 6 insertions(+), 12 deletions(-)
-
-diff --git a/src/gallium/drivers/etnaviv/etnaviv_state.c b/src/gallium/drivers/etnaviv/etnaviv_state.c
-index 1b4a7040b50..84fea58ecb5 100644
---- a/src/gallium/drivers/etnaviv/etnaviv_state.c
-+++ b/src/gallium/drivers/etnaviv/etnaviv_state.c
-@@ -749,24 +749,18 @@ struct etna_state_updater {
- static const struct etna_state_updater etna_state_updates[] = {
- {
- etna_shader_update_vertex, ETNA_DIRTY_SHADER | ETNA_DIRTY_VERTEX_ELEMENTS,
-- },
-- {
-+ }, {
- etna_shader_link, ETNA_DIRTY_SHADER,
-- },
-- {
-+ }, {
- etna_update_blend, ETNA_DIRTY_BLEND | ETNA_DIRTY_FRAMEBUFFER
-- },
-- {
-+ }, {
- etna_update_blend_color, ETNA_DIRTY_BLEND_COLOR | ETNA_DIRTY_FRAMEBUFFER,
-- },
-- {
-+ }, {
- etna_update_ts_config, ETNA_DIRTY_DERIVE_TS,
-- },
-- {
-+ }, {
- etna_update_clipping, ETNA_DIRTY_SCISSOR | ETNA_DIRTY_FRAMEBUFFER |
- ETNA_DIRTY_RASTERIZER | ETNA_DIRTY_VIEWPORT,
-- },
-- {
-+ }, {
- etna_update_zsa, ETNA_DIRTY_ZSA | ETNA_DIRTY_SHADER,
- }
- };
---
-2.26.2
-
-From 96106df17897b862b87937d6222a3e6483f45480 Mon Sep 17 00:00:00 2001
+From 3701cb9439058e71c1981bd80c5a9e1383815b08 Mon Sep 17 00:00:00 2001
From: Lucas Stach <l.stach@pengutronix.de>
Date: Fri, 13 Nov 2020 14:26:23 +0100
-Subject: [PATCH 1/6] frontend/dri: copy image use in dup_image
+Subject: [PATCH] gallium/dri: copy image use in dup_image
Don't lose the use flags when dup'ing an image.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
-
-Upstream-Status: Submitted [https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7603]
+Reviewed-by: Daniel Stone <daniels@collabora.com>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8106>
+Upstream-Status: Applied [https://gitlab.freedesktop.org/mesa/mesa/-/commit/3701cb9439058e71c1981bd80c5a9e1383815b08]
---
src/gallium/frontends/dri/dri2.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/gallium/frontends/dri/dri2.c b/src/gallium/frontends/dri/dri2.c
-index 0c0168497a2..1cd42cd8114 100644
+index 9999b31b022..08a9ed9693c 100644
--- a/src/gallium/frontends/dri/dri2.c
+++ b/src/gallium/frontends/dri/dri2.c
-@@ -1312,6 +1312,7 @@ dri2_dup_image(__DRIimage *image, void *loaderPrivate)
+@@ -1326,6 +1326,7 @@ dri2_dup_image(__DRIimage *image, void *loaderPrivate)
img->dri_format = image->dri_format;
/* This should be 0 for sub images, but dup is also used for base images. */
img->dri_components = image->dri_components;
img->loader_private = loaderPrivate;
img->sPriv = image->sPriv;
+--
+2.31.1
+
--- /dev/null
+From 77fcf700826d6637e4e407c73c209f3b1718a26e Mon Sep 17 00:00:00 2001
+From: Lucas Stach <l.stach@pengutronix.de>
+Date: Thu, 20 May 2021 18:07:12 +0200
+Subject: [PATCH] dri: don't call modifier interfaces when modifiers_count is 0
+
+The wayland EGL platform sets the modifier count to 0 in some cases
+to signal that modifiers should not be used, even if a list of modifiers
+is present. The loader_dri_create_image helper didn't handle this case
+properly and called the modifierful driver interface with a 0 modifier
+count, leading to the obvious outcome of the driver being unable to
+allocate an image.
+
+Fixes: cb9ae4273d68 ("dri: add loader_dri_create_image helper")
+Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10903>
+Upstream-Status: Applied [https://gitlab.freedesktop.org/mesa/mesa/-/commit/77fcf700826d6637e4e407c73c209f3b1718a26e]
+---
+ src/loader/loader_dri_helper.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/loader/loader_dri_helper.c b/src/loader/loader_dri_helper.c
+index 972ca2da26a..ff6ce35953f 100644
+--- a/src/loader/loader_dri_helper.c
++++ b/src/loader/loader_dri_helper.c
+@@ -37,7 +37,7 @@ __DRIimage *loader_dri_create_image(__DRIscreen *screen,
+ unsigned int modifiers_count,
+ void *loaderPrivate)
+ {
+- if (modifiers &&
++ if (modifiers && modifiers_count > 0 &&
+ image->base.version > 14 && image->createImageWithModifiers) {
+ bool has_valid_modifier = false;
+ int i;
+--
+2.31.1
+
-From 587aac46dbadf2aca1489aadd4216e592e11e17b Mon Sep 17 00:00:00 2001
+From 3824429da0e0e68b78534b1e0ab7e386bcb2b2e2 Mon Sep 17 00:00:00 2001
From: Lucas Stach <l.stach@pengutronix.de>
Date: Fri, 13 Nov 2020 14:59:52 +0100
-Subject: [PATCH 3/6] frontend/dri: add EXPLICIT_FLUSH hint in
+Subject: [PATCH] frontend/dri: add EXPLICIT_FLUSH hint in
dri2_resource_get_param
dri2_resource_get_param() is called from two different places right now.
Make sure to always add this hint when appropriate.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
-
-Upstream-Status: Submitted [https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7603]
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7603>
+Upstream-Status: Applied [https://gitlab.freedesktop.org/mesa/mesa/-/commit/3824429da0e0e68b78534b1e0ab7e386bcb2b2e2]
---
src/gallium/frontends/dri/dri2.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/gallium/frontends/dri/dri2.c b/src/gallium/frontends/dri/dri2.c
-index 1f1e7a9a65e..7851ebceb3e 100644
+index 0220513368e..8ed47c25825 100644
--- a/src/gallium/frontends/dri/dri2.c
+++ b/src/gallium/frontends/dri/dri2.c
-@@ -1198,6 +1198,9 @@ dri2_resource_get_param(__DRIimage *image, enum pipe_resource_param param,
+@@ -1252,6 +1252,9 @@ dri2_resource_get_param(__DRIimage *image, enum pipe_resource_param param,
if (!pscreen->resource_get_param)
return false;
return pscreen->resource_get_param(pscreen, NULL, image->texture,
image->plane, 0, 0, param, handle_usage,
value);
-@@ -1242,9 +1245,6 @@ dri2_query_image_by_resource_param(__DRIimage *image, int attrib, int *value)
+@@ -1296,9 +1299,6 @@ dri2_query_image_by_resource_param(__DRIimage *image, int attrib, int *value)
handle_usage = PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE;
return false;
--
-2.26.2
+2.31.1
-From 59f74212bbb5e28badd0775929e42856c9a01d35 Mon Sep 17 00:00:00 2001
+From 1c539bbb06f318d2bd0f93701b532f77894e391d Mon Sep 17 00:00:00 2001
From: Lucas Stach <l.stach@pengutronix.de>
Date: Fri, 13 Nov 2020 15:03:37 +0100
-Subject: [PATCH 4/6] etnaviv: remove double assigment of surface->texture
+Subject: [PATCH] etnaviv: remove double assigment of surface->texture
surf->base.texture is already assigned earlier via a proper
pipe_resource_reference call. Remove the superfluous assignement.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
-
-Upstream-Status: Submitted [https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7603]
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7603>
+Upstream-Status: Applied [https://gitlab.freedesktop.org/mesa/mesa/-/commit/1c539bbb06f318d2bd0f93701b532f77894e391d]
---
src/gallium/drivers/etnaviv/etnaviv_surface.c | 1 -
1 file changed, 1 deletion(-)
surf->base.width = rsc->levels[level].width;
surf->base.height = rsc->levels[level].height;
--
-2.26.2
+2.31.1
-From 537c7a6ea3fd2e5a6433e52b406ba39b89f520d9 Mon Sep 17 00:00:00 2001
+From 7b9d8d1936d72af6fd1bfd30afed354bb76b4c0c Mon Sep 17 00:00:00 2001
From: Lucas Stach <l.stach@pengutronix.de>
Date: Fri, 13 Nov 2020 15:05:55 +0100
-Subject: [PATCH 6/6] etnaviv: flush used render buffers on context flush when
+Subject: [PATCH] etnaviv: flush used render buffers on context flush when
neccessary
Some resources like backbuffers are explicitly flushed by the frontend
PIPE_HANDLE_USAGE_EXPLICIT_FLUSH flag set.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
-
-Upstream-Status: Submitted [https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7603]
+Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
+Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7603>
+Upstream-Status: Applied [https://gitlab.freedesktop.org/mesa/mesa/-/commit/7b9d8d1936d72af6fd1bfd30afed354bb76b4c0c]
---
src/gallium/drivers/etnaviv/etnaviv_context.c | 16 ++++++++++++++++
src/gallium/drivers/etnaviv/etnaviv_context.h | 3 +++
src/gallium/drivers/etnaviv/etnaviv_resource.c | 7 +++++++
src/gallium/drivers/etnaviv/etnaviv_resource.h | 2 ++
- src/gallium/drivers/etnaviv/etnaviv_state.c | 17 +++++++++++++++++
- 5 files changed, 45 insertions(+)
+ src/gallium/drivers/etnaviv/etnaviv_state.c | 18 ++++++++++++++++++
+ 5 files changed, 46 insertions(+)
diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.c b/src/gallium/drivers/etnaviv/etnaviv_context.c
-index 9c334a450c6..80c5d430419 100644
+index 4dd9e427ea1..581edc78d2f 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.c
-@@ -128,6 +128,9 @@ etna_context_destroy(struct pipe_context *pctx)
+@@ -129,6 +129,9 @@ etna_context_destroy(struct pipe_context *pctx)
_mesa_set_destroy(ctx->used_resources_write, NULL);
}
mtx_unlock(&ctx->lock);
if (ctx->dummy_desc_bo)
-@@ -475,6 +478,14 @@ etna_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence,
+@@ -490,6 +493,14 @@ etna_flush(struct pipe_context *pctx, struct pipe_fence_handle **fence,
list_for_each_entry(struct etna_acc_query, aq, &ctx->active_acc_queries, node)
etna_acc_query_suspend(aq, ctx);
etna_cmd_stream_flush(ctx->stream, ctx->in_fence_fd,
(flags & PIPE_FLUSH_FENCE_FD) ? &out_fence_fd : NULL);
-@@ -581,6 +592,11 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
+@@ -596,6 +607,11 @@ etna_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
if (!ctx->used_resources_write)
goto fail;
/* context ctxate setup */
diff --git a/src/gallium/drivers/etnaviv/etnaviv_context.h b/src/gallium/drivers/etnaviv/etnaviv_context.h
-index dd6af3d93e6..112902aac8a 100644
+index 72000f2122b..21e4d3f33ca 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_context.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_context.h
@@ -206,6 +206,9 @@ struct etna_context {
enum etna_resource_status status;
diff --git a/src/gallium/drivers/etnaviv/etnaviv_state.c b/src/gallium/drivers/etnaviv/etnaviv_state.c
-index 84fea58ecb5..5848735ab14 100644
+index 44b1c4f8fab..1ad839799f2 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_state.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_state.c
-@@ -741,6 +741,21 @@ etna_update_zsa(struct etna_context *ctx)
+@@ -753,6 +753,21 @@ etna_update_zsa(struct etna_context *ctx)
return true;
}
struct etna_state_updater {
bool (*update)(struct etna_context *ctx);
uint32_t dirty;
-@@ -762,6 +777,8 @@ static const struct etna_state_updater etna_state_updates[] = {
- ETNA_DIRTY_RASTERIZER | ETNA_DIRTY_VIEWPORT,
- }, {
+@@ -780,6 +795,9 @@ static const struct etna_state_updater etna_state_updates[] = {
+ },
+ {
etna_update_zsa, ETNA_DIRTY_ZSA | ETNA_DIRTY_SHADER,
-+ }, {
++ },
++ {
+ etna_record_flush_resources, ETNA_DIRTY_FRAMEBUFFER,
}
};
--
-2.26.2
+2.31.1
FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
SRC_URI_append_use-mainline-bsp = " \
- file://0001-frontend-dri-copy-image-use-in-dup_image.patch \
- file://0002-dri-bring-back-use-flags-for-createImageWithModifier.patch \
- file://0003-frontend-dri-add-EXPLICIT_FLUSH-hint-in-dri2_resourc.patch \
- file://0004-etnaviv-remove-double-assigment-of-surface-texture.patch \
- file://0005-etnaviv-compact-etna_state_updates.patch \
- file://0006-etnaviv-flush-used-render-buffers-on-context-flush-w.patch \
+ file://0001-dri-add-createImageWithModifiers2-interface.patch \
+ file://0002-dri-add-loader_dri_create_image-helper.patch \
+ file://0003-loader-dri3-convert-to-loader_dri_create_image.patch \
+ file://0004-loader-dri-hook-up-createImageWithModifiers2.patch \
+ file://0005-gallium-dri-copy-image-use-in-dup_image.patch \
+ file://0006-dri-don-t-call-modifier-interfaces-when-modifiers_co.patch \
+ file://0007-frontend-dri-add-EXPLICIT_FLUSH-hint-in-dri2_resourc.patch \
+ file://0008-etnaviv-remove-double-assigment-of-surface-texture.patch \
+ file://0009-etnaviv-flush-used-render-buffers-on-context-flush-w.patch \
"
PROVIDES_remove_imxgpu = "virtual/egl"