Mesa (main): venus: implement vn_buffer_cache_get_memory_requirements

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Oct 28 00:33:48 UTC 2021


Module: Mesa
Branch: main
Commit: af505ff3c8ce498998dc155271652ca6e77a63d0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=af505ff3c8ce498998dc155271652ca6e77a63d0

Author: Yiwei Zhang <zzyiwei at chromium.org>
Date:   Mon Oct 18 23:36:11 2021 +0000

venus: implement vn_buffer_cache_get_memory_requirements

Signed-off-by: Yiwei Zhang <zzyiwei at chromium.org>
Reviewed-by: Chia-I Wu <olvaffe at gmail.com>
Reviewed-by: Ryan Neph <ryanneph at google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13428>

---

 src/virtio/vulkan/vn_buffer.c | 46 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/src/virtio/vulkan/vn_buffer.c b/src/virtio/vulkan/vn_buffer.c
index 00392a9a988..3a0ef283399 100644
--- a/src/virtio/vulkan/vn_buffer.c
+++ b/src/virtio/vulkan/vn_buffer.c
@@ -19,6 +19,14 @@
 
 /* buffer commands */
 
+static inline bool
+vn_buffer_create_info_can_be_cached(const VkBufferCreateInfo *create_info)
+{
+   /* cache only VK_SHARING_MODE_EXCLUSIVE and without pNext for simplicity */
+   return (create_info->pNext == NULL) &&
+          (create_info->sharingMode == VK_SHARING_MODE_EXCLUSIVE);
+}
+
 static VkResult
 vn_buffer_cache_entries_create(struct vn_device *dev,
                                struct vn_buffer_cache_entry **out_entries,
@@ -117,6 +125,44 @@ vn_buffer_cache_get_memory_requirements(
    const VkBufferCreateInfo *create_info,
    struct vn_buffer_memory_requirements *out)
 {
+   if (create_info->size > cache->max_buffer_size)
+      return false;
+
+   if (!vn_buffer_create_info_can_be_cached(create_info))
+      return false;
+
+   /* 12.7. Resource Memory Association
+    *
+    * The memoryTypeBits member is identical for all VkBuffer objects created
+    * with the same value for the flags and usage members in the
+    * VkBufferCreateInfo structure and the handleTypes member of the
+    * VkExternalMemoryBufferCreateInfo structure passed to vkCreateBuffer.
+    * Further, if usage1 and usage2 of type VkBufferUsageFlags are such that
+    * the bits set in usage2 are a subset of the bits set in usage1, and they
+    * have the same flags and VkExternalMemoryBufferCreateInfo::handleTypes,
+    * then the bits set in memoryTypeBits returned for usage1 must be a subset
+    * of the bits set in memoryTypeBits returned for usage2, for all values of
+    * flags.
+    */
+   for (uint32_t i = 0; i < cache->entry_count; i++) {
+      const struct vn_buffer_cache_entry *entry = &cache->entries[i];
+      if ((entry->create_info->flags == create_info->flags) &&
+          ((entry->create_info->usage & create_info->usage) ==
+           create_info->usage)) {
+         *out = entry->requirements;
+
+         /* XXX This is based on below implementation defined behavior:
+          *
+          *    req.size <= align64(info.size, req.alignment)
+          *
+          * TODO Fix the spec to guarantee above.
+          */
+         out->memory.memoryRequirements.size = align64(
+            create_info->size, out->memory.memoryRequirements.alignment);
+         return true;
+      }
+   }
+
    return false;
 }
 



More information about the mesa-commit mailing list