Hello,

I am emailing a patch I have done to mesa to enable UIF tiling for scannout 
when compositor supports it.
The current architecture was forcing me to copy from Linear to UIF to rener 
glxgears using gamescope in the Pi5, with this patch I am able to skip that 
copy phase.

Please take a look at this one and if possible enable my account to create a 
fork so I can submit more patches when needed in gitlab. Username is Ericky14.

Link to patch in a git repo as well: https://github.com/Ericky14/mesa
From 0e17800815e6591109daf364745fa6af1f345d60 Mon Sep 17 00:00:00 2001
From: Ericky Dos Santos <[email protected]>
Date: Sat, 14 Feb 2026 20:49:14 -0500
Subject: [PATCH] v3d: Allow UIF tiling for scanout when compositor supports it

When a compositor advertises UIF modifier support, allow GL resources
with PIPE_BIND_SCANOUT to use tiled (UIF) layout instead of forcing
linear. This enables zero-copy import from GL applications into
compositors like gamescope on Raspberry Pi 5.
---
 src/gallium/drivers/v3d/v3d_resource.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/v3d/v3d_resource.c b/src/gallium/drivers/v3d/v3d_resource.c
index 1b583ba..88a53be 100644
--- a/src/gallium/drivers/v3d/v3d_resource.c
+++ b/src/gallium/drivers/v3d/v3d_resource.c
@@ -834,14 +834,20 @@ v3d_resource_create_with_modifiers(struct pipe_screen *pscreen,
                 should_tile = false;
 #endif
 
-        /* If using the old-school SCANOUT flag, we don't know what the screen
-         * might support other than linear. Just force linear.
+        /* If using the old-school SCANOUT flag without explicit modifiers,
+         * we don't know what the screen might support other than linear.
+         * But if the compositor provided explicit modifiers including UIF,
+         * trust those and allow tiling for better V3D sampling performance.
          */
-        if (tmpl->bind & PIPE_BIND_SCANOUT)
+        bool has_explicit_modifiers = !(count == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID);
+        bool compositor_supports_uif = has_explicit_modifiers &&
+                drm_find_modifier(DRM_FORMAT_MOD_BROADCOM_UIF, modifiers, count);
+        
+        if ((tmpl->bind & PIPE_BIND_SCANOUT) && !compositor_supports_uif)
                 should_tile = false;
 
         /* No user-specified modifier; determine our own. */
-        if (count == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID) {
+        if (!has_explicit_modifiers) {
                 rsc->tiled = should_tile;
         } else if (should_tile &&
                    drm_find_modifier(DRM_FORMAT_MOD_BROADCOM_UIF,
@@ -858,8 +864,12 @@ v3d_resource_create_with_modifiers(struct pipe_screen *pscreen,
 
         v3d_setup_slices(screen, rsc, 0, tmpl->bind & PIPE_BIND_SHARED);
 
-        if (screen->ro && (tmpl->bind & PIPE_BIND_SCANOUT)) {
-                assert(!rsc->tiled);
+        /* Only use renderonly path for LINEAR scanout buffers.
+         * When using UIF (tiled) with compositor explicit modifier support,
+         * allocate directly from V3D and let the compositor handle the
+         * LINEAR scanout conversion (e.g., gamescope's scanout copy).
+         */
+        if (screen->ro && (tmpl->bind & PIPE_BIND_SCANOUT) && !rsc->tiled) {
                 struct winsys_handle handle;
                 uint32_t scanout_height =
                         align(rsc->size + V3D_TFU_READAHEAD_SIZE, 4096) / 4096;
-- 
2.51.0

Reply via email to