Mesa (17.1): anv: Add valid_bufer_usage to the memory type metadata

Juan Antonio Suárez Romero jasuarez at kemper.freedesktop.org
Sat Jun 3 17:04:08 UTC 2017


Module: Mesa
Branch: 17.1
Commit: 0f042901e3cd451f9a7630376083a805328aebe3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0f042901e3cd451f9a7630376083a805328aebe3

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Wed May 17 11:14:06 2017 -0700

anv: Add valid_bufer_usage to the memory type metadata

Instead of returning valid types as just a number, we now walk the list
and check the buffer's usage against the usage flags we store in the new
anv_memory_type structure.  Currently, valid_buffer_usage == ~0.

Reviewed-by: Nanley Chery <nanley.g.chery at intel.com>
Cc: "17.1" <mesa-stable at lists.freedesktop.org>
(cherry picked from commit f7736ccf53eaeb66c4270afe0916e2cb29ab8667)
[Juan A. Suarez: resolve trivial conflicts]
Signed-off-by: Juan A. Suarez Romero <jasuarez at igalia.com>

Conflicts:
	src/intel/vulkan/anv_device.c
	src/intel/vulkan/anv_private.h

---

 src/intel/vulkan/anv_device.c  | 21 +++++++++++++++------
 src/intel/vulkan/anv_private.h | 13 +++++++++++--
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 0add7812ab..e8ddf9faee 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -117,12 +117,13 @@ anv_physical_device_init_heaps(struct anv_physical_device *device, int fd)
        * both cached and coherent at the same time.
        */
       device->memory.type_count = 1;
-      device->memory.types[0] = (VkMemoryType) {
+      device->memory.types[0] = (struct anv_memory_type) {
          .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
                           VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
                           VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
                           VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
          .heapIndex = 0,
+         .valid_buffer_usage = ~0,
       };
    } else {
       /* The spec requires that we expose a host-visible, coherent memory
@@ -131,17 +132,19 @@ anv_physical_device_init_heaps(struct anv_physical_device *device, int fd)
        * coherent but uncached (WC though).
        */
       device->memory.type_count = 2;
-      device->memory.types[0] = (VkMemoryType) {
+      device->memory.types[0] = (struct anv_memory_type) {
          .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
                           VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
                           VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
          .heapIndex = 0,
+         .valid_buffer_usage = ~0,
       };
-      device->memory.types[1] = (VkMemoryType) {
+      device->memory.types[1] = (struct anv_memory_type) {
          .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
                           VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
                           VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
          .heapIndex = 0,
+         .valid_buffer_usage = ~0,
       };
    }
 
@@ -1792,6 +1795,7 @@ void anv_GetBufferMemoryRequirements(
 {
    ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
    ANV_FROM_HANDLE(anv_device, device, _device);
+   struct anv_physical_device *pdevice = &device->instance->physicalDevice;
 
    /* The Vulkan spec (git aaed022) says:
     *
@@ -1799,13 +1803,17 @@ void anv_GetBufferMemoryRequirements(
     *    supported memory type for the resource. The bit `1<<i` is set if and
     *    only if the memory type `i` in the VkPhysicalDeviceMemoryProperties
     *    structure for the physical device is supported.
-    *
-    * We support exactly one memory type on LLC, two on non-LLC.
     */
-   pMemoryRequirements->memoryTypeBits = device->info.has_llc ? 1 : 3;
+   uint32_t memory_types = 0;
+   for (uint32_t i = 0; i < pdevice->memory.type_count; i++) {
+      uint32_t valid_usage = pdevice->memory.types[i].valid_buffer_usage;
+      if ((valid_usage & buffer->usage) == buffer->usage)
+         memory_types |= (1u << i);
+   }
 
    pMemoryRequirements->size = buffer->size;
    pMemoryRequirements->alignment = 16;
+   pMemoryRequirements->memoryTypeBits = memory_types;
 }
 
 void anv_GetImageMemoryRequirements(
@@ -1860,6 +1868,7 @@ VkResult anv_BindBufferMemory(
    ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
 
    if (mem) {
+      assert((buffer->usage & mem->type->valid_buffer_usage) == buffer->usage);
       buffer->bo = &mem->bo;
       buffer->offset = memoryOffset;
    } else {
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 21432b4c35..61f90ea1ae 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -604,6 +604,15 @@ struct anv_bo *anv_scratch_pool_alloc(struct anv_device *device,
                                       gl_shader_stage stage,
                                       unsigned per_thread_scratch);
 
+struct anv_memory_type {
+   /* Standard bits passed on to the client */
+   VkMemoryPropertyFlags   propertyFlags;
+   uint32_t                heapIndex;
+
+   /* Driver-internal book-keeping */
+   VkBufferUsageFlags      valid_buffer_usage;
+};
+
 struct anv_physical_device {
     VK_LOADER_DATA                              _loader_data;
 
@@ -633,7 +642,7 @@ struct anv_physical_device {
 
     struct {
       uint32_t                                  type_count;
-      VkMemoryType                              types[VK_MAX_MEMORY_TYPES];
+      struct anv_memory_type                    types[VK_MAX_MEMORY_TYPES];
       uint32_t                                  heap_count;
       VkMemoryHeap                              heaps[VK_MAX_MEMORY_HEAPS];
     } memory;
@@ -971,7 +980,7 @@ _anv_combine_address(struct anv_batch *batch, void *location,
 
 struct anv_device_memory {
    struct anv_bo                                bo;
-   VkMemoryType *                               type;
+   struct anv_memory_type *                     type;
    VkDeviceSize                                 map_size;
    void *                                       map;
 };




More information about the mesa-commit mailing list