[Mesa-dev] [PATCH 07/11] vulkan: add vk_alloc.h shared allocation inlines.

Dave Airlie airlied at gmail.com
Mon Oct 17 02:07:18 UTC 2016


From: Dave Airlie <airlied at redhat.com>

vulkan allocation allows for overriding the allocator used,
add some macros for anv/radv to share for this.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 configure.ac                 |  5 ++-
 src/Makefile.am              |  4 +++
 src/vulkan/Makefile.am       | 26 +++++++++++++++
 src/vulkan/Makefile.sources  |  2 ++
 src/vulkan/common/vk_alloc.h | 75 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 111 insertions(+), 1 deletion(-)
 create mode 100644 src/vulkan/Makefile.am
 create mode 100644 src/vulkan/Makefile.sources
 create mode 100644 src/vulkan/common/vk_alloc.h

diff --git a/configure.ac b/configure.ac
index b414edd..37cc306 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2693,6 +2693,8 @@ VA_MINOR=`$PKG_CONFIG --modversion libva | $SED -n 's/.*\.\(.*\)\..*$/\1/p'`
 AC_SUBST([VA_MAJOR], $VA_MAJOR)
 AC_SUBST([VA_MINOR], $VA_MINOR)
 
+AM_CONDITIONAL(HAVE_VULKAN_COMMON, test "x$VULKAN_DRIVERS" != "x")
+
 AC_SUBST([XVMC_MAJOR], 1)
 AC_SUBST([XVMC_MINOR], 0)
 
@@ -2851,7 +2853,8 @@ AC_CONFIG_FILES([Makefile
 		src/mesa/drivers/x11/Makefile
 		src/mesa/main/tests/Makefile
 		src/util/Makefile
-		src/util/tests/hash_table/Makefile])
+		src/util/tests/hash_table/Makefile
+		src/vulkan/Makefile])
 
 AC_OUTPUT
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 17c8798..10e0826 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -74,6 +74,10 @@ endif
 # include only conditionally ?
 SUBDIRS += compiler
 
+if HAVE_VULKAN_COMMON
+SUBDIRS += vulkan
+endif
+
 if HAVE_AMD_DRIVERS
 SUBDIRS += amd
 endif
diff --git a/src/vulkan/Makefile.am b/src/vulkan/Makefile.am
new file mode 100644
index 0000000..abe8404
--- /dev/null
+++ b/src/vulkan/Makefile.am
@@ -0,0 +1,26 @@
+# Copyright © 2016 Red Hat.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice (including the next
+# paragraph) shall be included in all copies or substantial portions of the
+# Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+
+include Makefile.sources
+
+noinst_LTLIBRARIES =
+
+EXTRA_DIST = $(COMMON_HEADER_FILES)
diff --git a/src/vulkan/Makefile.sources b/src/vulkan/Makefile.sources
new file mode 100644
index 0000000..a73bf99
--- /dev/null
+++ b/src/vulkan/Makefile.sources
@@ -0,0 +1,2 @@
+COMMON_HEADER_FILES = \
+	common/vk_alloc.h
diff --git a/src/vulkan/common/vk_alloc.h b/src/vulkan/common/vk_alloc.h
new file mode 100644
index 0000000..a8e21ca
--- /dev/null
+++ b/src/vulkan/common/vk_alloc.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+#ifndef VK_ALLOC_H
+#define VK_ALLOC_H
+
+/* common allocation inlines for vulkan drivers */
+
+#include <vulkan/vulkan.h>
+
+static inline void *
+vk_alloc(const VkAllocationCallbacks *alloc,
+         size_t size, size_t align,
+         VkSystemAllocationScope scope)
+{
+   return alloc->pfnAllocation(alloc->pUserData, size, align, scope);
+}
+
+static inline void *
+vk_realloc(const VkAllocationCallbacks *alloc,
+           void *ptr, size_t size, size_t align,
+           VkSystemAllocationScope scope)
+{
+   return alloc->pfnReallocation(alloc->pUserData, ptr, size, align, scope);
+}
+
+static inline void
+vk_free(const VkAllocationCallbacks *alloc, void *data)
+{
+   alloc->pfnFree(alloc->pUserData, data);
+}
+
+static inline void *
+vk_alloc2(const VkAllocationCallbacks *parent_alloc,
+          const VkAllocationCallbacks *alloc,
+          size_t size, size_t align,
+          VkSystemAllocationScope scope)
+{
+   if (alloc)
+      return vk_alloc(alloc, size, align, scope);
+   else
+      return vk_alloc(parent_alloc, size, align, scope);
+}
+
+static inline void
+vk_free2(const VkAllocationCallbacks *parent_alloc,
+         const VkAllocationCallbacks *alloc,
+         void *data)
+{
+   if (alloc)
+      vk_free(alloc, data);
+   else
+      vk_free(parent_alloc, data);
+}
+
+#endif
-- 
2.5.5



More information about the mesa-dev mailing list