summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Osipenko <dmitry.osipenko@collabora.com>2022-08-05 16:30:22 +0300
committerDylan Baker <dylan.c.baker@intel.com>2022-08-11 10:30:38 -0700
commit7dadb0a81a164bda3546299a038ab804571d5d68 (patch)
tree3686c2d16b48c3668eea16478034284c4b7eb0c8
parenta544df2afc695df907c8f40c80633aa1170d5d4c (diff)
downloadmesa-7dadb0a81a164bda3546299a038ab804571d5d68.tar.gz
virgl: Fix unmapping of blob resources
OpenGL API calls like glClearBufferData() result in mapping/unmapping of a given buffer by Mesa and unmapping of a host blob fails in virglrenderer because VirGL driver uses command that is intended for unmapping of a guest buffer. In particular this causes problem for the "Total War: Warhammer" game that gets GL_OUT_OF_MEMORY error due to the failed unmapping command. Fix this by setting the mapping usage flag in accordance to the resource flags, allowing virgl_buffer_transfer_unmap() to differentiate host buffer from guest. Fixes: 3b54e5837a152364 ("virgl: support PIPE_CAP_BUFFER_MAP_PERSISTENT_COHERENT") Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17914> (cherry picked from commit 46396e97bea603a5cef8177b66a760a11a78af2a)
-rw-r--r--.pick_status.json2
-rw-r--r--src/gallium/drivers/virgl/virgl_resource.c12
2 files changed, 13 insertions, 1 deletions
diff --git a/.pick_status.json b/.pick_status.json
index 8121b46bb62..fcf2dbcc571 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -1579,7 +1579,7 @@
"description": "virgl: Fix unmapping of blob resources",
"nominated": true,
"nomination_type": 1,
- "resolution": 0,
+ "resolution": 1,
"main_sha": null,
"because_sha": "3b54e5837a15236407f5ea0c98dfe3f23c6fe7b1"
},
diff --git a/src/gallium/drivers/virgl/virgl_resource.c b/src/gallium/drivers/virgl/virgl_resource.c
index 6e3ff80e9e4..461c1768ed8 100644
--- a/src/gallium/drivers/virgl/virgl_resource.c
+++ b/src/gallium/drivers/virgl/virgl_resource.c
@@ -493,6 +493,18 @@ virgl_resource_transfer_map(struct pipe_context *ctx,
/* Multisampled resources require resolve before mapping. */
assert(resource->nr_samples <= 1);
+ /* If virgl resource was created using persistence and coherency flags,
+ * then its memory mapping can be only made in accordance to these
+ * flags. We record the "usage" flags in struct virgl_transfer and
+ * then virgl_buffer_transfer_unmap() uses them to differentiate
+ * unmapping of a host blob resource from guest.
+ */
+ if (resource->flags & PIPE_RESOURCE_FLAG_MAP_PERSISTENT)
+ usage |= PIPE_MAP_PERSISTENT;
+
+ if (resource->flags & PIPE_RESOURCE_FLAG_MAP_COHERENT)
+ usage |= PIPE_MAP_COHERENT;
+
trans = virgl_resource_create_transfer(vctx, resource,
&vres->metadata, level, usage, box);