Mesa (master): zink: For MoltenVk added vkFlushMappedMemoryRanges() to vkMapMemory() to fix empty mapped memory.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 6 17:20:10 UTC 2020


Module: Mesa
Branch: master
Commit: 81597759beff0729057887340e219e87448d1a4c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=81597759beff0729057887340e219e87448d1a4c

Author: Duncan Hopkins <duncan at thefoundry.co.uk>
Date:   Wed Aug 14 11:11:19 2019 +0100

zink: For MoltenVk added vkFlushMappedMemoryRanges() to vkMapMemory() to fix empty mapped memory.

On MoltenVK/MacOS when mapping memory that should already have content it does not appear until flushed.
This noticably effects vertex attribute uploads to descrete devices.
Did also try to add the Coherent memory flag, which did work, until there the Coherent type could only be used for transfer usage only.

This is a known limitation of MoltenVK.
See https://github.com/KhronosGroup/MoltenVK/blob/master/Docs/MoltenVK_Runtime_UserGuide.md#known-moltenvk-limitations

Seen when using MoltenVK 1.0.121, 1.2.131

Acked-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7470>

---

 src/gallium/drivers/zink/zink_resource.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c
index 6e78236a912..dc7b6694b52 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -514,6 +514,25 @@ zink_transfer_map(struct pipe_context *pctx,
       if (result != VK_SUCCESS)
          return NULL;
 
+#if defined(__APPLE__)
+      if (!(usage & PIPE_MAP_DISCARD_WHOLE_RESOURCE)) {
+         // Work around for MoltenVk limitation
+         // MoltenVk returns blank memory ranges when there should be data present
+         // This is a known limitation of MoltenVK.
+         // See https://github.com/KhronosGroup/MoltenVK/blob/master/Docs/MoltenVK_Runtime_UserGuide.md#known-moltenvk-limitations
+         VkMappedMemoryRange range = {
+            VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
+            NULL,
+            res->mem,
+            res->offset,
+            res->size
+         };
+         result = vkFlushMappedMemoryRanges(screen->dev, 1, &range);
+         if (result != VK_SUCCESS)
+            return NULL;
+      }
+#endif
+
       trans->base.stride = 0;
       trans->base.layer_stride = 0;
       ptr = ((uint8_t *)ptr) + box->x;



More information about the mesa-commit mailing list