v3dv: memory management stubs
authorAlejandro Piñeiro <apinheiro@igalia.com>
Wed, 27 Nov 2019 21:08:51 +0000 (22:08 +0100)
committerMarge Bot <eric+marge@anholt.net>
Tue, 13 Oct 2020 21:21:25 +0000 (21:21 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>

src/broadcom/vulkan/v3dv_device.c
src/broadcom/vulkan/v3dv_private.h

index bd6a0ea..a1b70a3 100644 (file)
@@ -498,3 +498,105 @@ v3dv_DestroyDebugReportCallbackEXT(VkInstance _instance,
    vk_destroy_debug_report_callback(&instance->debug_report_callbacks,
                                     _callback, pAllocator, &instance->alloc);
 }
+
+VkResult
+v3dv_AllocateMemory(VkDevice _device,
+                    const VkMemoryAllocateInfo *pAllocateInfo,
+                    const VkAllocationCallbacks *pAllocator,
+                    VkDeviceMemory *pMem)
+{
+   V3DV_FROM_HANDLE(v3dv_device, device, _device);
+   struct v3dv_device_memory *mem;
+   /* struct v3dv_physical_device *pdevice = &device->instance->physicalDevice; */
+
+   assert(pAllocateInfo->sType == VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO);
+
+   /* The Vulkan 1.0.33 spec says "allocationSize must be greater than 0". */
+   assert(pAllocateInfo->allocationSize > 0);
+
+   if (pAllocateInfo->allocationSize > MAX_MEMORY_ALLOCATION_SIZE)
+      return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+   mem = vk_alloc2(&device->alloc, pAllocator, sizeof(*mem), 8,
+                   VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+   if (mem == NULL)
+      return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
+
+   /* FIXME: assert(pAllocateInfo->memoryTypeIndex < pdevice->memory.type_count); */
+   /* FIXME: mem->type = &pdevice->memory.types[pAllocateInfo->memoryTypeIndex]; */
+   mem->map = NULL;
+   mem->map_size = 0;
+
+   /* FIXME: stub */
+
+   return VK_SUCCESS;
+}
+
+void
+v3dv_FreeMemory(VkDevice _device,
+                VkDeviceMemory _mem,
+                const VkAllocationCallbacks *pAllocator)
+{
+   V3DV_FROM_HANDLE(v3dv_device, device, _device);
+   V3DV_FROM_HANDLE(v3dv_device_memory, mem, _mem);
+
+   if (mem == NULL)
+      return;
+
+   if (mem->map)
+      v3dv_UnmapMemory(_device, _mem);
+
+   /* FIXME: stub */
+
+   vk_free2(&device->alloc, pAllocator, mem);
+}
+
+VkResult
+v3dv_MapMemory(VkDevice _device,
+               VkDeviceMemory _memory,
+               VkDeviceSize offset,
+               VkDeviceSize size,
+               VkMemoryMapFlags flags,
+               void **ppData)
+{
+   V3DV_FROM_HANDLE(v3dv_device, device, _device);
+   V3DV_FROM_HANDLE(v3dv_device_memory, mem, _memory);
+
+   if (mem == NULL) {
+      *ppData = NULL;
+      return VK_SUCCESS;
+   }
+
+   /* FIXME: stub */
+
+   return vk_error(device->instance, VK_ERROR_MEMORY_MAP_FAILED);
+}
+
+void
+v3dv_UnmapMemory(VkDevice _device,
+                 VkDeviceMemory _memory)
+{
+   /* FIXME: stub */
+}
+
+VkResult
+v3dv_FlushMappedMemoryRanges(VkDevice _device,
+                             uint32_t memoryRangeCount,
+                             const VkMappedMemoryRange *pMemoryRanges)
+{
+   /* FIXME: stub (although note that both radv and tu just returns success
+    * here. Pending further research)
+    */
+   return VK_SUCCESS;
+}
+
+VkResult
+v3dv_InvalidateMappedMemoryRanges(VkDevice _device,
+                                  uint32_t memoryRangeCount,
+                                  const VkMappedMemoryRange *pMemoryRanges)
+{
+   /* FIXME: stub (although note that both radv and tu just returns success
+    * here. Pending further research)
+    */
+   return VK_SUCCESS;
+}
index f6ec1fe..653652f 100644 (file)
 
 #include "vk_alloc.h"
 
+/*
+ * FIXME: confirm value
+ *
+ * FIXME: seems like a good idea having something like this, as anv, but both
+ * tu/radv doesn't check for this issue. Need to revisit.
+ */
+#define MAX_MEMORY_ALLOCATION_SIZE (1ull << 31)
+
 struct v3dv_instance;
 
 struct v3dv_device {
@@ -123,6 +131,14 @@ struct v3dv_cmd_buffer {
    /* FIXME: stub */
 };
 
+struct v3dv_device_memory {
+   /* FIXME: stub */
+   /* FIXME: likely would include links to structures similar to v3d_bo
+    * (perhaps we should refactor existing v3d_bo?) */
+   VkDeviceSize map_size;
+   void *map;
+};
+
 uint32_t v3dv_physical_device_api_version(struct v3dv_physical_device *dev);
 
 int v3dv_get_instance_entrypoint_index(const char *name);
@@ -173,6 +189,20 @@ void v3dv_loge_v(const char *format, va_list va);
       return (__VkType) _obj;                           \
    }
 
+#define V3DV_DEFINE_NONDISP_HANDLE_CASTS(__v3dv_type, __VkType)              \
+                                                                           \
+   static inline struct __v3dv_type *                                       \
+   __v3dv_type ## _from_handle(__VkType _handle)                            \
+   {                                                                       \
+      return (struct __v3dv_type *)(uintptr_t) _handle;                     \
+   }                                                                       \
+                                                                           \
+   static inline __VkType                                                  \
+   __v3dv_type ## _to_handle(struct __v3dv_type *_obj)                       \
+   {                                                                       \
+      return (__VkType)(uintptr_t) _obj;                                   \
+   }
+
 #define V3DV_FROM_HANDLE(__v3dv_type, __name, __handle)                        \
    struct __v3dv_type *__name = __v3dv_type ## _from_handle(__handle)
 
@@ -182,5 +212,6 @@ V3DV_DEFINE_HANDLE_CASTS(v3dv_instance, VkInstance)
 V3DV_DEFINE_HANDLE_CASTS(v3dv_physical_device, VkPhysicalDevice)
 V3DV_DEFINE_HANDLE_CASTS(v3dv_queue, VkQueue)
 
+V3DV_DEFINE_NONDISP_HANDLE_CASTS(v3dv_device_memory, VkDeviceMemory)
 
 #endif /* V3DV_PRIVATE_H */