meta-core/recipes-graphics/mesa: Backport a fix from 22.2.5
[AGL/meta-agl.git] / meta-agl-bsp / meta-core / recipes-graphics / mesa / mesa / 0001-virgl-don-t-a-use-staging-when-a-resources-created-w.patch
1 From f50ff0b5cf2bfedfc2fd660ccfbfd5cfc3c131d1 Mon Sep 17 00:00:00 2001
2 From: Marius Vlad <marius.vlad@collabora.com>
3 Date: Tue, 28 Mar 2023 15:33:26 +0300
4 Subject: [PATCH] virgl: don't a use staging when a resources created with the
5  shared flag
6
7 There seems to be a problem with running firefox by using Xwayland that
8 results in a shared resources being not always tagged as using staging.
9
10 As a result one process tries to map the resource that was allocated as
11 one that uses staging without actually using the staging resource, and
12 hence the mapped range only accounts for the small region that we have
13 to allocated because a zero-allocation doesn't work, but the application
14 mapping the resource assumes that a properly sized range is mapped, and
15 consequently this results in invalid memory access.
16
17 To work around this issue disable creating staging for resources that
18 are created by using shared binding. It is not clear to me whether this
19 is the best fix, but it seems to quell the issue.
20
21 Fixes: c9d99b7eec7ec14d6d71d381a424b6280d75a882
22 virgl: Fix texture transfers by using a staging resource
23
24 Related: https://gitlab.freedesktop.org/virgl/virglrenderer/-/issues/291
25 Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19655>
26 (cherry picked from commit e496d24cb2d5339566c08c79a8aa7809c240613c)
27
28 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
29 (cherry picked from commit 39e9ea1419beb22ab7f4913b6d55f845f94d689a)
30 ---
31  src/gallium/drivers/virgl/virgl_resource.c | 1 +
32  1 file changed, 1 insertion(+)
33
34 diff --git a/src/gallium/drivers/virgl/virgl_resource.c b/src/gallium/drivers/virgl/virgl_resource.c
35 index 7185c9a90ff..257b790d437 100644
36 --- a/src/gallium/drivers/virgl/virgl_resource.c
37 +++ b/src/gallium/drivers/virgl/virgl_resource.c
38 @@ -100,6 +100,7 @@ static bool virgl_can_copy_transfer_from_host(struct virgl_screen *vs,
39  {
40     return virgl_can_use_staging(vs, res) &&
41           !is_stencil_array(res) &&
42 +        !(bind & VIRGL_BIND_SHARED) &&
43           virgl_has_readback_format(&vs->base, pipe_to_virgl_format(res->b.format), false) &&
44           ((!(vs->caps.caps.v2.capability_bits & VIRGL_CAP_FAKE_FP64)) ||
45            virgl_can_readback_from_rendertarget(vs, res) ||
46 -- 
47 2.35.1
48