vk: Split the memory requirements/binding functions
authorJason Ekstrand <jason.ekstrand@intel.com>
Tue, 14 Jul 2015 21:59:39 +0000 (14:59 -0700)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 14 Jul 2015 21:59:39 +0000 (14:59 -0700)
include/vulkan/vulkan.h
src/vulkan/device.c
src/vulkan/x11.c

index 2ace82ed3a043731a4bfb4bb9410a6416b4d2e0e..68704a43fb44eee54c65623b7ceec1cdf1cd2772 100644 (file)
@@ -2017,8 +2017,10 @@ typedef VkResult (VKAPI *PFN_vkUnmapMemory)(VkDevice device, VkDeviceMemory mem)
 typedef VkResult (VKAPI *PFN_vkFlushMappedMemoryRanges)(VkDevice device, uint32_t memRangeCount, const VkMappedMemoryRange* pMemRanges);
 typedef VkResult (VKAPI *PFN_vkInvalidateMappedMemoryRanges)(VkDevice device, uint32_t memRangeCount, const VkMappedMemoryRange* pMemRanges);
 typedef VkResult (VKAPI *PFN_vkDestroyObject)(VkDevice device, VkObjectType objType, VkObject object);
-typedef VkResult (VKAPI *PFN_vkBindObjectMemory)(VkDevice device, VkObjectType objType, VkObject object, VkDeviceMemory mem, VkDeviceSize memOffset);
-typedef VkResult (VKAPI *PFN_vkGetObjectMemoryRequirements)(VkDevice device, VkObjectType objType, VkObject object, VkMemoryRequirements* pMemoryRequirements);
+typedef VkResult (VKAPI *PFN_vkBindBufferMemory)(VkDevice device, VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memOffset);
+typedef VkResult (VKAPI *PFN_vkBindImageMemory)(VkDevice device, VkImage image, VkDeviceMemory mem, VkDeviceSize memOffset);
+typedef VkResult (VKAPI *PFN_vkGetBufferMemoryRequirements)(VkDevice device, VkBuffer buffer, VkMemoryRequirements* pMemoryRequirements);
+typedef VkResult (VKAPI *PFN_vkGetImageMemoryRequirements)(VkDevice device, VkImage image, VkMemoryRequirements* pMemoryRequirements);
 typedef VkResult (VKAPI *PFN_vkQueueBindSparseBufferMemory)(VkQueue queue, VkBuffer buffer, VkDeviceSize rangeOffset, VkDeviceSize rangeSize, VkDeviceMemory mem, VkDeviceSize memOffset);
 typedef VkResult (VKAPI *PFN_vkQueueBindSparseImageMemory)(VkQueue queue, VkImage image, const VkImageMemoryBindInfo* pBindInfo, VkDeviceMemory mem, VkDeviceSize memOffset);
 typedef VkResult (VKAPI *PFN_vkCreateFence)(VkDevice device, const VkFenceCreateInfo* pCreateInfo, VkFence* pFence);
@@ -2267,17 +2269,26 @@ VkResult VKAPI vkDestroyObject(
     VkObjectType                                objType,
     VkObject                                    object);
 
-VkResult VKAPI vkBindObjectMemory(
+VkResult VKAPI vkBindBufferMemory(
     VkDevice                                    device,
-    VkObjectType                                objType,
-    VkObject                                    object,
+    VkBuffer                                    buffer,
     VkDeviceMemory                              mem,
     VkDeviceSize                                memOffset);
 
-VkResult VKAPI vkGetObjectMemoryRequirements(
+VkResult VKAPI vkBindImageMemory(
     VkDevice                                    device,
-    VkObjectType                                objType,
-    VkObject                                    object,
+    VkImage                                     image,
+    VkDeviceMemory                              mem,
+    VkDeviceSize                                memOffset);
+
+VkResult VKAPI vkGetBufferMemoryRequirements(
+    VkDevice                                    device,
+    VkBuffer                                    buffer,
+    VkMemoryRequirements*                       pMemoryRequirements);
+
+VkResult VKAPI vkGetImageMemoryRequirements(
+    VkDevice                                    device,
+    VkImage                                     image,
     VkMemoryRequirements*                       pMemoryRequirements);
 
 VkResult VKAPI vkQueueBindSparseBufferMemory(
index 2aa9aee9e506497ccee2e57891d199b3d40c45c2..d566bb0b092b8d78568a4de2f00815c8a97df2dd 100644 (file)
@@ -1282,12 +1282,12 @@ VkResult anv_DestroyObject(
    }
 }
 
-VkResult anv_GetObjectMemoryRequirements(
+VkResult anv_GetBufferMemoryRequirements(
     VkDevice                                    device,
-    VkObjectType                                objType,
-    VkObject                                    object,
+    VkBuffer                                    _buffer,
     VkMemoryRequirements*                       pMemoryRequirements)
 {
+   ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
 
    /* The Vulkan spec (git aaed022) says:
     *
@@ -1300,52 +1300,62 @@ VkResult anv_GetObjectMemoryRequirements(
     */
    pMemoryRequirements->memoryTypeBits = 1;
 
-   switch (objType) {
-   case VK_OBJECT_TYPE_BUFFER: {
-      struct anv_buffer *buffer = anv_buffer_from_handle(object);
-      pMemoryRequirements->size = buffer->size;
-      pMemoryRequirements->alignment = 16;
-      break;
-   }
-   case VK_OBJECT_TYPE_IMAGE: {
-      struct anv_image *image = anv_image_from_handle(object);
-      pMemoryRequirements->size = image->size;
-      pMemoryRequirements->alignment = image->alignment;
-      break;
-   }
-   default:
-      pMemoryRequirements->size = 0;
-      break;
-   }
+   pMemoryRequirements->size = buffer->size;
+   pMemoryRequirements->alignment = 16;
 
    return VK_SUCCESS;
 }
 
-VkResult anv_BindObjectMemory(
+VkResult anv_GetImageMemoryRequirements(
     VkDevice                                    device,
-    VkObjectType                                objType,
-    VkObject                                    object,
+    VkImage                                     _image,
+    VkMemoryRequirements*                       pMemoryRequirements)
+{
+   ANV_FROM_HANDLE(anv_image, image, _image);
+
+   /* The Vulkan spec (git aaed022) says:
+    *
+    *    memoryTypeBits is a bitfield and contains one bit set for every
+    *    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.
+    */
+   pMemoryRequirements->memoryTypeBits = 1;
+
+   pMemoryRequirements->size = image->size;
+   pMemoryRequirements->alignment = image->alignment;
+
+   return VK_SUCCESS;
+}
+
+VkResult anv_BindBufferMemory(
+    VkDevice                                    device,
+    VkBuffer                                    _buffer,
     VkDeviceMemory                              _mem,
     VkDeviceSize                                memOffset)
 {
    ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
-   struct anv_buffer *buffer;
-   struct anv_image *image;
+   ANV_FROM_HANDLE(anv_buffer, buffer, _buffer);
 
-   switch (objType) {
-   case VK_OBJECT_TYPE_BUFFER:
-      buffer = anv_buffer_from_handle(object);
-      buffer->bo = &mem->bo;
-      buffer->offset = memOffset;
-      break;
-   case VK_OBJECT_TYPE_IMAGE:
-      image = anv_image_from_handle(object);
-      image->bo = &mem->bo;
-      image->offset = memOffset;
-      break;
-   default:
-      break;
-   }
+   buffer->bo = &mem->bo;
+   buffer->offset = memOffset;
+
+   return VK_SUCCESS;
+}
+
+VkResult anv_BindImageMemory(
+    VkDevice                                    device,
+    VkImage                                     _image,
+    VkDeviceMemory                              _mem,
+    VkDeviceSize                                memOffset)
+{
+   ANV_FROM_HANDLE(anv_device_memory, mem, _mem);
+   ANV_FROM_HANDLE(anv_image, image, _image);
+
+   image->bo = &mem->bo;
+   image->offset = memOffset;
 
    return VK_SUCCESS;
 }
index 7b6cee011a4e77dae66efd972b621632a0109727..d1eaab3bf46c30363ce06f9f3276a2a8084f8c51 100644 (file)
@@ -148,10 +148,9 @@ VkResult anv_CreateSwapChainWSI(
                       },
                       (VkDeviceMemory *) &memory);
 
-      anv_BindObjectMemory(VK_NULL_HANDLE,
-                           VK_OBJECT_TYPE_IMAGE,
-                           (VkImage) image,
-                           (VkDeviceMemory) memory, 0);
+      anv_BindImageMemory(VK_NULL_HANDLE,
+                          anv_image_to_handle(image),
+                          anv_device_memory_to_handle(memory), 0);
 
       ret = anv_gem_set_tiling(device, memory->bo.gem_handle,
                                surface->stride, I915_TILING_X);