gallium: add an interface for memory allocations.
authorDave Airlie <airlied@redhat.com>
Fri, 19 Jun 2020 06:24:48 +0000 (16:24 +1000)
committerDave Airlie <airlied@redhat.com>
Mon, 17 Aug 2020 04:30:49 +0000 (14:30 +1000)
In order to support vulkan over gallium for the sw renderers,
there needs to be a vulkan-like memory allocation API.

It doesn't need to be overly complicated for the needs of the sw
renderers.

The vallium layer will allocate resources and memory separately
and bind them via this API.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6082>

src/gallium/include/pipe/p_screen.h
src/gallium/include/pipe/p_state.h

index a4b07c8ee251bc7985957f541a4ec238af00a1c7..3002689aeed6e7a263d299bab382a871e9014109 100644 (file)
@@ -511,6 +511,47 @@ struct pipe_screen {
     *                  should be.
     */
    void (*finalize_nir)(struct pipe_screen *screen, void *nir, bool optimize);
+
+   /*Separated memory/resource allocations interfaces for Vulkan */
+
+   /**
+    * Create a resource, and retrieve the required size for it but don't allocate
+    * any backing memory.
+    */
+   struct pipe_resource * (*resource_create_unbacked)(struct pipe_screen *,
+                                                      const struct pipe_resource *templat,
+                                                      uint64_t *size_required);
+
+   /**
+    * Allocate backing memory to be bound to resources.
+    */
+   struct pipe_memory_allocation *(*allocate_memory)(struct pipe_screen *screen,
+                                                     uint64_t size);
+   /**
+    * Free previously allocated backing memory.
+    */
+   void (*free_memory)(struct pipe_screen *screen,
+                       struct pipe_memory_allocation *);
+
+   /**
+    * Bind memory to a resource.
+    */
+   void (*resource_bind_backing)(struct pipe_screen *screen,
+                                 struct pipe_resource *pt,
+                                 struct pipe_memory_allocation *pmem,
+                                 uint64_t offset);
+
+   /**
+    * Map backing memory.
+    */
+   void *(*map_memory)(struct pipe_screen *screen,
+                       struct pipe_memory_allocation *pmem);
+
+   /**
+    * Unmap backing memory.
+    */
+   void (*unmap_memory)(struct pipe_screen *screen,
+                        struct pipe_memory_allocation *pmem);
 };
 
 
index 6f1d4c6309c2e9086e15491b40cdb234eb46a693..f38cb411dbbe8aac9eecfe05194e6e4c0827d7e6 100644 (file)
@@ -574,6 +574,10 @@ struct pipe_resource
    struct pipe_screen *screen; /**< screen that this texture belongs to */
 };
 
+/**
+ * Opaque object used for separate resource/memory allocations.
+ */
+struct pipe_memory_allocation;
 
 /**
  * Transfer object.  For data transfer to/from a resource.