Update cluster-refgui to support cluster-service
[AGL/meta-agl-devel.git] / meta-uhmi / meta-rvgpu / recipes-graphics / mesa-virtio / files / 0001-glBufferData-Update-resource-backing-memory.patch
1 From 6e23c8970762309d3f2b88f252333b2492aacd28 Mon Sep 17 00:00:00 2001
2 From: Andrii Pauk <Andrii.Pauk@opensynergy.com>
3 Date: Sat, 27 Feb 2021 17:42:00 +0200
4 Subject: [PATCH] glBufferData: Update resource backing memory.
5
6 Update buffer backing memory on buffer initialization with data.
7 This is workaround for UHMI project, where
8 VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D command is not implemented.
9
10 The problem is in the following use-case:
11 1) glBufferData --- reserves guest memory "backing" for resource,
12 but doesn't fill it with data. Instead, data is serialized into
13 virgl internal command and sent using VIRTIO_GPU_CMD_SUBMIT_3D
14 comand. This command is opaque for rproxy/rvdds and serialized cmd buffer
15 is just forwarded to virglrenderer, where it is deserialized and
16 used for initialization of internal "gpu" memory with this data.
17 2) glMapBuffer --- this calls TRANSFER_FROM_HOST_3D, which asks host/rproxy-->
18 rvdds/virglrenderer to update backing memory (on source) with buffer data.
19 And further this backing memory is mapped to guest application.
20 In case of UHMI, TRANSFER_FROM_HOST_3D is not implemented, thus the memory is
21 not "initialized".
22 3) Modify buffer memory, but not whole memory, just some chunks.
23 4) glUnmapBuffer --- this will trigger VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D
24 command, which will send to target whole buffer memory and will overwrite
25 previous memory. It's ok for modified in step 3 memory, but other is
26 just garbage (I always saw zero filled memory).
27
28 The above scenario produces artifacts on buffer-scene of glmark, in case of
29 "update-method=map", which forces glmark to use 1-4 flow.
30
31 As a workaround, fill buffer backing memory with data on step 1.
32
33 Issue: EXDCLXXII-420
34
35 Upstream-Status: Pending
36 ---
37  src/gallium/auxiliary/util/u_inlines.h       | 21 +++++++++++++++++++++
38  src/mesa/state_tracker/st_cb_bufferobjects.c |  4 +++-
39  2 files changed, 24 insertions(+), 1 deletion(-)
40
41 diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h
42 index dee6f8f..4745f7b 100644
43 --- a/src/gallium/auxiliary/util/u_inlines.h
44 +++ b/src/gallium/auxiliary/util/u_inlines.h
45 @@ -462,6 +462,27 @@ pipe_buffer_read(struct pipe_context *pipe,
46     pipe_buffer_unmap(pipe, src_transfer);
47  }
48  
49 +static inline void
50 +pipe_buffer_update_backing(struct pipe_context *pipe,
51 +                 struct pipe_resource *buf,
52 +                 unsigned offset,
53 +                 unsigned size,
54 +                 void *data)
55 +{
56 +   struct pipe_transfer *src_transfer;
57 +   ubyte *map;
58 +
59 +   map = (ubyte *) pipe_buffer_map_range(pipe,
60 +                                         buf,
61 +                                         offset, size,
62 +                                         PIPE_TRANSFER_WRITE,
63 +                                         &src_transfer);
64 +   if (!map)
65 +      return;
66 +
67 +   memcpy(map, data, size);
68 +   pipe_buffer_unmap(pipe, src_transfer);
69 +}
70  
71  /**
72   * Map a resource for reading/writing.
73 diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
74 index 5ebe94f..cb33c8c 100644
75 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c
76 +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
77 @@ -343,8 +343,10 @@ bufferobj_data(struct gl_context *ctx,
78        else {
79           st_obj->buffer = screen->resource_create(screen, &buffer);
80  
81 -         if (st_obj->buffer && data)
82 +         if (st_obj->buffer && data) {
83              pipe_buffer_write(pipe, st_obj->buffer, 0, size, data);
84 +            pipe_buffer_update_backing(pipe, st_obj->buffer, 0, size, data);
85 +         }
86        }
87  
88        if (!st_obj->buffer) {
89 -- 
90 2.7.4
91