util/vulkan: Move Vulkan utilities to src/vulkan/util
authorAlex Smith <asmith@feralinteractive.com>
Tue, 6 Jun 2017 11:31:05 +0000 (12:31 +0100)
committerJason Ekstrand <jason.ekstrand@intel.com>
Tue, 6 Jun 2017 15:17:13 +0000 (08:17 -0700)
We have Vulkan utilities in both src/util and src/vulkan/util. The
latter seems a more appropriate place for Vulkan-specific things, so
move them there.

v2: Android build system changes (from Tapani Pälli)

Signed-off-by: Alex Smith <asmith@feralinteractive.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
Acked-by: Jason Ekstrand <jason@jlekstrand.net>
24 files changed:
Android.common.mk
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_formats.c
src/amd/vulkan/radv_private.h
src/amd/vulkan/radv_wsi.c
src/intel/Android.vulkan.mk
src/intel/vulkan/anv_device.c
src/intel/vulkan/anv_formats.c
src/intel/vulkan/anv_pass.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/anv_queue.c
src/intel/vulkan/anv_wsi.c
src/intel/vulkan/genX_cmd_buffer.c
src/util/Makefile.sources
src/util/vk_alloc.h [deleted file]
src/util/vk_util.h [deleted file]
src/vulkan/Android.mk
src/vulkan/Makefile.am
src/vulkan/Makefile.sources
src/vulkan/util/vk_alloc.h [new file with mode: 0644]
src/vulkan/util/vk_util.h [new file with mode: 0644]
src/vulkan/wsi/wsi_common.h
src/vulkan/wsi/wsi_common_wayland.c
src/vulkan/wsi/wsi_common_x11.c

index 44ad97b6be21386bf46507f9ff4ea22ff78ec0ab..6bd30816bc41d5e21e6d58faa0419f522b480800 100644 (file)
@@ -37,6 +37,7 @@ LOCAL_CFLAGS += \
        -Wno-missing-field-initializers \
        -Wno-initializer-overrides \
        -Wno-mismatched-tags \
        -Wno-missing-field-initializers \
        -Wno-initializer-overrides \
        -Wno-mismatched-tags \
+       -DVERSION=\"$(MESA_VERSION)\" \
        -DPACKAGE_VERSION=\"$(MESA_VERSION)\" \
        -DPACKAGE_BUGREPORT=\"https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa\"
 
        -DPACKAGE_VERSION=\"$(MESA_VERSION)\" \
        -DPACKAGE_BUGREPORT=\"https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa\"
 
index 887916f558f27a11e6c68af153717874b02e2073..a812527ebe446c1b4f4484662158388dc453ca95 100644 (file)
@@ -33,7 +33,7 @@
 #include "radv_cs.h"
 #include "util/disk_cache.h"
 #include "util/strtod.h"
 #include "radv_cs.h"
 #include "util/disk_cache.h"
 #include "util/strtod.h"
-#include "util/vk_util.h"
+#include "vk_util.h"
 #include <xf86drm.h>
 #include <amdgpu.h>
 #include <amdgpu_drm.h>
 #include <xf86drm.h>
 #include <amdgpu.h>
 #include <amdgpu_drm.h>
index 6cff0a5384e7f6ec78b07449525e2cf5062f71e1..b13adb9abdcb40b80fc4fe25b53eca88b75bc968 100644 (file)
@@ -28,7 +28,8 @@
 #include "sid.h"
 #include "r600d_common.h"
 
 #include "sid.h"
 #include "r600d_common.h"
 
-#include "util/vk_util.h"
+#include "vk_util.h"
+
 #include "util/u_half.h"
 #include "util/format_srgb.h"
 #include "util/format_r11g11b10f.h"
 #include "util/u_half.h"
 #include "util/format_srgb.h"
 #include "util/format_r11g11b10f.h"
index ed80ba79e7fce473990b80751cfbeb00f0f54000..a3920a72702eaa5f238ebeff2600e22b10ea5a18 100644 (file)
@@ -47,8 +47,8 @@
 #include "compiler/shader_enums.h"
 #include "util/macros.h"
 #include "util/list.h"
 #include "compiler/shader_enums.h"
 #include "util/macros.h"
 #include "util/list.h"
-#include "util/vk_alloc.h"
 #include "main/macros.h"
 #include "main/macros.h"
+#include "vk_alloc.h"
 
 #include "radv_radeon_winsys.h"
 #include "ac_binary.h"
 
 #include "radv_radeon_winsys.h"
 #include "ac_binary.h"
index 51fe159aaf80e5a5daf0c22cfcf543f46817439a..cdb04ca96282bb8fe697ff8415e8a1d7f7563807 100644 (file)
@@ -26,7 +26,7 @@
 #include "radv_private.h"
 #include "radv_meta.h"
 #include "wsi_common.h"
 #include "radv_private.h"
 #include "radv_meta.h"
 #include "wsi_common.h"
-#include "util/vk_util.h"
+#include "vk_util.h"
 
 static const struct wsi_callbacks wsi_cbs = {
    .get_phys_device_format_properties = radv_GetPhysicalDeviceFormatProperties,
 
 static const struct wsi_callbacks wsi_cbs = {
    .get_phys_device_format_properties = radv_GetPhysicalDeviceFormatProperties,
index 2ede3f75b3206dcd251ba4f2c470cabd46cbf69a..e31c4391df02aa5fb1638f5a1d43ead4c9ba7b2a 100644 (file)
@@ -31,6 +31,7 @@ VULKAN_COMMON_INCLUDES := \
        $(MESA_TOP)/src/gallium/include \
        $(MESA_TOP)/src/mesa \
        $(MESA_TOP)/src/vulkan/wsi \
        $(MESA_TOP)/src/gallium/include \
        $(MESA_TOP)/src/mesa \
        $(MESA_TOP)/src/vulkan/wsi \
+       $(MESA_TOP)/src/vulkan/util \
        $(MESA_TOP)/src/intel \
        $(MESA_TOP)/src/intel/vulkan
 
        $(MESA_TOP)/src/intel \
        $(MESA_TOP)/src/intel/vulkan
 
index ab484ed0f9aeee796c2ee56003860e7527cc81f2..52e5d7b0252ae69fdce10249ede6bcadc7ef71b0 100644 (file)
@@ -35,7 +35,7 @@
 #include "util/debug.h"
 #include "util/build_id.h"
 #include "util/mesa-sha1.h"
 #include "util/debug.h"
 #include "util/build_id.h"
 #include "util/mesa-sha1.h"
-#include "util/vk_util.h"
+#include "vk_util.h"
 
 #include "genxml/gen7_pack.h"
 
 
 #include "genxml/gen7_pack.h"
 
index 25801e8b065c70c7c4ca53e53990bad8441eb621..104d4f7a5fe74ae0e9463f604595f7df282c5c48 100644 (file)
@@ -23,8 +23,7 @@
 
 #include "anv_private.h"
 #include "vk_format_info.h"
 
 #include "anv_private.h"
 #include "vk_format_info.h"
-
-#include "util/vk_util.h"
+#include "vk_util.h"
 
 /*
  * gcc-4 and earlier don't allow compound literals where a constant
 
 /*
  * gcc-4 and earlier don't allow compound literals where a constant
index 93f14830cc5ec8381709a7ae2156510291f06d94..1b30c1409d980a1a1bc5b4301f9b8d815fea2c13 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "anv_private.h"
 
 
 #include "anv_private.h"
 
-#include "util/vk_util.h"
+#include "vk_util.h"
 
 static unsigned
 num_subpass_attachments(const VkSubpassDescription *desc)
 
 static unsigned
 num_subpass_attachments(const VkSubpassDescription *desc)
index c261faa78b828082fb92922908cfcb9820006dad..fe6ac3bc1bdb33da3221882ab62e4f85305562c9 100644 (file)
@@ -47,7 +47,7 @@
 #include "util/macros.h"
 #include "util/list.h"
 #include "util/u_vector.h"
 #include "util/macros.h"
 #include "util/list.h"
 #include "util/u_vector.h"
-#include "util/vk_alloc.h"
+#include "vk_alloc.h"
 
 /* Pre-declarations needed for WSI entrypoints */
 struct wl_surface;
 
 /* Pre-declarations needed for WSI entrypoints */
 struct wl_surface;
index be7fd31008106db4e7244942d8b2215a578db4eb..fd4d36297f0a48e8f4b0b0d3072573106d1285f4 100644 (file)
@@ -30,7 +30,7 @@
 #include <sys/eventfd.h>
 
 #include "anv_private.h"
 #include <sys/eventfd.h>
 
 #include "anv_private.h"
-#include "util/vk_util.h"
+#include "vk_util.h"
 
 #include "genxml/gen7_pack.h"
 
 
 #include "genxml/gen7_pack.h"
 
index 7575f58ff2411f30a310f3ad4b9d87f69aeb2b5c..9369f26a8fa0f5c3955150caf5e92cbd4d1595fd 100644 (file)
@@ -24,7 +24,7 @@
 #include "anv_private.h"
 #include "wsi_common.h"
 #include "vk_format_info.h"
 #include "anv_private.h"
 #include "wsi_common.h"
 #include "vk_format_info.h"
-#include "util/vk_util.h"
+#include "vk_util.h"
 
 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
 static const struct wsi_callbacks wsi_cbs = {
 
 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
 static const struct wsi_callbacks wsi_cbs = {
index 072d0d50325f0afaa2902ab7bfdaeb24d6c62f99..59430a24eb9ad7256b1048a0069ce9e5240c183e 100644 (file)
@@ -26,7 +26,7 @@
 
 #include "anv_private.h"
 #include "vk_format_info.h"
 
 #include "anv_private.h"
 #include "vk_format_info.h"
-#include "util/vk_util.h"
+#include "vk_util.h"
 
 #include "common/gen_l3_config.h"
 #include "genxml/gen_macros.h"
 
 #include "common/gen_l3_config.h"
 #include "genxml/gen_macros.h"
index e9057343dc2604d69dcabad32ecadd736292e095..e9f820a3ee06babad9b866036f7502c982bb27e9 100644 (file)
@@ -51,9 +51,7 @@ MESA_UTIL_FILES := \
        u_string.h \
        u_thread.h \
        u_vector.c \
        u_string.h \
        u_thread.h \
        u_vector.c \
-       u_vector.h \
-       vk_alloc.h \
-       vk_util.h
+       u_vector.h
 
 MESA_UTIL_GENERATED_FILES = \
        format_srgb.c
 
 MESA_UTIL_GENERATED_FILES = \
        format_srgb.c
diff --git a/src/util/vk_alloc.h b/src/util/vk_alloc.h
deleted file mode 100644 (file)
index 2915021..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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 <string.h>
-#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)
-{
-   if (data == NULL)
-      return;
-
-   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_zalloc2(const VkAllocationCallbacks *parent_alloc,
-           const VkAllocationCallbacks *alloc,
-           size_t size, size_t align,
-           VkSystemAllocationScope scope)
-{
-   void *mem = vk_alloc2(parent_alloc, alloc, size, align, scope);
-   if (mem == NULL)
-      return NULL;
-
-   memset(mem, 0, size);
-
-   return mem;
-}
-
-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
diff --git a/src/util/vk_util.h b/src/util/vk_util.h
deleted file mode 100644 (file)
index 5ff1f00..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright © 2017 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_UTIL_H
-#define VK_UTIL_H
-
-/* common inlines and macros for vulkan drivers */
-
-#include <vulkan/vulkan.h>
-
-struct vk_struct_common {
-    VkStructureType sType;
-    struct vk_struct_common *pNext;
-};
-
-#define vk_foreach_struct(__iter, __start) \
-   for (struct vk_struct_common *__iter = (struct vk_struct_common *)(__start); \
-        __iter; __iter = __iter->pNext)
-
-#define vk_foreach_struct_const(__iter, __start) \
-   for (const struct vk_struct_common *__iter = (const struct vk_struct_common *)(__start); \
-        __iter; __iter = __iter->pNext)
-
-/**
- * A wrapper for a Vulkan output array. A Vulkan output array is one that
- * follows the convention of the parameters to
- * vkGetPhysicalDeviceQueueFamilyProperties().
- *
- * Example Usage:
- *
- *    VkResult
- *    vkGetPhysicalDeviceQueueFamilyProperties(
- *       VkPhysicalDevice           physicalDevice,
- *       uint32_t*                  pQueueFamilyPropertyCount,
- *       VkQueueFamilyProperties*   pQueueFamilyProperties)
- *    {
- *       VK_OUTARRAY_MAKE(props, pQueueFamilyProperties,
- *                         pQueueFamilyPropertyCount);
- *
- *       vk_outarray_append(&props, p) {
- *          p->queueFlags = ...;
- *          p->queueCount = ...;
- *       }
- *
- *       vk_outarray_append(&props, p) {
- *          p->queueFlags = ...;
- *          p->queueCount = ...;
- *       }
- *
- *       return vk_outarray_status(&props);
- *    }
- */
-struct __vk_outarray {
-   /** May be null. */
-   void *data;
-
-   /**
-    * Capacity, in number of elements. Capacity is unlimited (UINT32_MAX) if
-    * data is null.
-    */
-   uint32_t cap;
-
-   /**
-    * Count of elements successfully written to the array. Every write is
-    * considered successful if data is null.
-    */
-   uint32_t *filled_len;
-
-   /**
-    * Count of elements that would have been written to the array if its
-    * capacity were sufficient. Vulkan functions often return VK_INCOMPLETE
-    * when `*filled_len < wanted_len`.
-    */
-   uint32_t wanted_len;
-};
-
-static inline void
-__vk_outarray_init(struct __vk_outarray *a,
-                   void *data, uint32_t *restrict len)
-{
-   a->data = data;
-   a->cap = *len;
-   a->filled_len = len;
-   *a->filled_len = 0;
-   a->wanted_len = 0;
-
-   if (a->data == NULL)
-      a->cap = UINT32_MAX;
-}
-
-static inline VkResult
-__vk_outarray_status(const struct __vk_outarray *a)
-{
-   if (*a->filled_len < a->wanted_len)
-      return VK_INCOMPLETE;
-   else
-      return VK_SUCCESS;
-}
-
-static inline void *
-__vk_outarray_next(struct __vk_outarray *a, size_t elem_size)
-{
-   void *p = NULL;
-
-   a->wanted_len += 1;
-
-   if (*a->filled_len >= a->cap)
-      return NULL;
-
-   if (a->data != NULL)
-      p = a->data + (*a->filled_len) * elem_size;
-
-   *a->filled_len += 1;
-
-   return p;
-}
-
-#define vk_outarray(elem_t) \
-   struct { \
-      struct __vk_outarray base; \
-      elem_t meta[]; \
-   }
-
-#define vk_outarray_typeof_elem(a) __typeof__((a)->meta[0])
-#define vk_outarray_sizeof_elem(a) sizeof((a)->meta[0])
-
-#define vk_outarray_init(a, data, len) \
-   __vk_outarray_init(&(a)->base, (data), (len))
-
-#define VK_OUTARRAY_MAKE(name, data, len) \
-   vk_outarray(__typeof__((data)[0])) name; \
-   vk_outarray_init(&name, (data), (len))
-
-#define vk_outarray_status(a) \
-   __vk_outarray_status(&(a)->base)
-
-#define vk_outarray_next(a) \
-   ((vk_outarray_typeof_elem(a) *) \
-      __vk_outarray_next(&(a)->base, vk_outarray_sizeof_elem(a)))
-
-/**
- * Append to a Vulkan output array.
- *
- * This is a block-based macro. For example:
- *
- *    vk_outarray_append(&a, elem) {
- *       elem->foo = ...;
- *       elem->bar = ...;
- *    }
- *
- * The array `a` has type `vk_outarray(elem_t) *`. It is usually declared with
- * VK_OUTARRAY_MAKE(). The variable `elem` is block-scoped and has type
- * `elem_t *`.
- *
- * The macro unconditionally increments the array's `wanted_len`. If the array
- * is not full, then the macro also increment its `filled_len` and then
- * executes the block. When the block is executed, `elem` is non-null and
- * points to the newly appended element.
- */
-#define vk_outarray_append(a, elem) \
-   for (vk_outarray_typeof_elem(a) *elem = vk_outarray_next(a); \
-        elem != NULL; elem = NULL)
-
-static inline void *
-__vk_find_struct(void *start, VkStructureType sType)
-{
-   vk_foreach_struct(s, start) {
-      if (s->sType == sType)
-         return s;
-   }
-
-   return NULL;
-}
-
-#define vk_find_struct(__start, __sType) \
-   __vk_find_struct((__start), VK_STRUCTURE_TYPE_##__sType)
-
-#define vk_find_struct_const(__start, __sType) \
-   (const void *)__vk_find_struct((void *)(__start), VK_STRUCTURE_TYPE_##__sType)
-
-#endif /* VK_UTIL_H */
index 7653f34c68a50e130f606e00136ba4ae30f22b5a..8eb42ece8786d2269ad62da4a5168c534f96377f 100644 (file)
@@ -41,6 +41,8 @@ LOCAL_C_INCLUDES := \
 LOCAL_GENERATED_SOURCES := $(addprefix $(intermediates)/, \
        $(VULKAN_UTIL_GENERATED_FILES))
 
 LOCAL_GENERATED_SOURCES := $(addprefix $(intermediates)/, \
        $(VULKAN_UTIL_GENERATED_FILES))
 
+LOCAL_SRC_FILES := $(VULKAN_UTIL_FILES))
+
 vulkan_api_xml = $(MESA_TOP)/src/vulkan/registry/vk.xml
 
 $(LOCAL_GENERATED_SOURCES): $(MESA_TOP)/src/vulkan/util/gen_enum_to_str.py $(vulkan_api_xml)
 vulkan_api_xml = $(MESA_TOP)/src/vulkan/registry/vk.xml
 
 $(LOCAL_GENERATED_SOURCES): $(MESA_TOP)/src/vulkan/util/gen_enum_to_str.py $(vulkan_api_xml)
index 71fb2d97bba8bc50883b0c0aa1c611e7df065529..c897a07d6a8b33c3cb36234e1a35de271924c9be 100644 (file)
@@ -11,6 +11,10 @@ PYTHON_GEN = $(AM_V_GEN)$(PYTHON2) $(PYTHON_FLAGS)
 EXTRA_DIST = \
        util/gen_enum_to_str.py
 
 EXTRA_DIST = \
        util/gen_enum_to_str.py
 
+VULKAN_UTIL_SOURCES = \
+       $(VULKAN_UTIL_FILES) \
+       $(VULKAN_UTIL_GENERATED_FILES)
+
 BUILT_SOURCES = \
        $(VULKAN_UTIL_GENERATED_FILES)
 
 BUILT_SOURCES = \
        $(VULKAN_UTIL_GENERATED_FILES)
 
@@ -18,12 +22,13 @@ util/vk_enum_to_str.c util/vk_enum_to_str.h: util/gen_enum_to_str.py $(vulkan_ap
        $(MKDIR_GEN)
        $(PYTHON_GEN) $(srcdir)/util/gen_enum_to_str.py --xml $(vulkan_api_xml) --outdir $(top_builddir)/src/vulkan/util
 
        $(MKDIR_GEN)
        $(PYTHON_GEN) $(srcdir)/util/gen_enum_to_str.py --xml $(vulkan_api_xml) --outdir $(top_builddir)/src/vulkan/util
 
-libvulkan_util_la_SOURCES = $(VULKAN_UTIL_GENERATED_FILES)
+libvulkan_util_la_SOURCES = $(VULKAN_UTIL_SOURCES)
 
 AM_CPPFLAGS = \
        $(DEFINES) \
        -I$(top_srcdir)/include \
        -I$(top_srcdir)/src \
 
 AM_CPPFLAGS = \
        $(DEFINES) \
        -I$(top_srcdir)/include \
        -I$(top_srcdir)/src \
+       -I$(top_srcdir)/src/vulkan/util \
        -I$(top_srcdir)/src/gallium/auxiliary \
        -I$(top_srcdir)/src/gallium/include
 
        -I$(top_srcdir)/src/gallium/auxiliary \
        -I$(top_srcdir)/src/gallium/include
 
index 63f4ac116204daf4432cdd24bfd4f6f246aa7a81..9962c1b077dbb883e42763ecb9f7ab5bac6f98ed 100644 (file)
@@ -15,6 +15,10 @@ VULKAN_WSI_X11_FILES := \
        wsi/wsi_common_x11.c \
        wsi/wsi_common_x11.h
 
        wsi/wsi_common_x11.c \
        wsi/wsi_common_x11.h
 
+VULKAN_UTIL_FILES := \
+       util/vk_alloc.h \
+       util/vk_util.h
+
 VULKAN_UTIL_GENERATED_FILES := \
        util/vk_enum_to_str.c \
        util/vk_enum_to_str.h
 VULKAN_UTIL_GENERATED_FILES := \
        util/vk_enum_to_str.c \
        util/vk_enum_to_str.h
diff --git a/src/vulkan/util/vk_alloc.h b/src/vulkan/util/vk_alloc.h
new file mode 100644 (file)
index 0000000..2915021
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * 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 <string.h>
+#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)
+{
+   if (data == NULL)
+      return;
+
+   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_zalloc2(const VkAllocationCallbacks *parent_alloc,
+           const VkAllocationCallbacks *alloc,
+           size_t size, size_t align,
+           VkSystemAllocationScope scope)
+{
+   void *mem = vk_alloc2(parent_alloc, alloc, size, align, scope);
+   if (mem == NULL)
+      return NULL;
+
+   memset(mem, 0, size);
+
+   return mem;
+}
+
+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
diff --git a/src/vulkan/util/vk_util.h b/src/vulkan/util/vk_util.h
new file mode 100644 (file)
index 0000000..5ff1f00
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * Copyright © 2017 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_UTIL_H
+#define VK_UTIL_H
+
+/* common inlines and macros for vulkan drivers */
+
+#include <vulkan/vulkan.h>
+
+struct vk_struct_common {
+    VkStructureType sType;
+    struct vk_struct_common *pNext;
+};
+
+#define vk_foreach_struct(__iter, __start) \
+   for (struct vk_struct_common *__iter = (struct vk_struct_common *)(__start); \
+        __iter; __iter = __iter->pNext)
+
+#define vk_foreach_struct_const(__iter, __start) \
+   for (const struct vk_struct_common *__iter = (const struct vk_struct_common *)(__start); \
+        __iter; __iter = __iter->pNext)
+
+/**
+ * A wrapper for a Vulkan output array. A Vulkan output array is one that
+ * follows the convention of the parameters to
+ * vkGetPhysicalDeviceQueueFamilyProperties().
+ *
+ * Example Usage:
+ *
+ *    VkResult
+ *    vkGetPhysicalDeviceQueueFamilyProperties(
+ *       VkPhysicalDevice           physicalDevice,
+ *       uint32_t*                  pQueueFamilyPropertyCount,
+ *       VkQueueFamilyProperties*   pQueueFamilyProperties)
+ *    {
+ *       VK_OUTARRAY_MAKE(props, pQueueFamilyProperties,
+ *                         pQueueFamilyPropertyCount);
+ *
+ *       vk_outarray_append(&props, p) {
+ *          p->queueFlags = ...;
+ *          p->queueCount = ...;
+ *       }
+ *
+ *       vk_outarray_append(&props, p) {
+ *          p->queueFlags = ...;
+ *          p->queueCount = ...;
+ *       }
+ *
+ *       return vk_outarray_status(&props);
+ *    }
+ */
+struct __vk_outarray {
+   /** May be null. */
+   void *data;
+
+   /**
+    * Capacity, in number of elements. Capacity is unlimited (UINT32_MAX) if
+    * data is null.
+    */
+   uint32_t cap;
+
+   /**
+    * Count of elements successfully written to the array. Every write is
+    * considered successful if data is null.
+    */
+   uint32_t *filled_len;
+
+   /**
+    * Count of elements that would have been written to the array if its
+    * capacity were sufficient. Vulkan functions often return VK_INCOMPLETE
+    * when `*filled_len < wanted_len`.
+    */
+   uint32_t wanted_len;
+};
+
+static inline void
+__vk_outarray_init(struct __vk_outarray *a,
+                   void *data, uint32_t *restrict len)
+{
+   a->data = data;
+   a->cap = *len;
+   a->filled_len = len;
+   *a->filled_len = 0;
+   a->wanted_len = 0;
+
+   if (a->data == NULL)
+      a->cap = UINT32_MAX;
+}
+
+static inline VkResult
+__vk_outarray_status(const struct __vk_outarray *a)
+{
+   if (*a->filled_len < a->wanted_len)
+      return VK_INCOMPLETE;
+   else
+      return VK_SUCCESS;
+}
+
+static inline void *
+__vk_outarray_next(struct __vk_outarray *a, size_t elem_size)
+{
+   void *p = NULL;
+
+   a->wanted_len += 1;
+
+   if (*a->filled_len >= a->cap)
+      return NULL;
+
+   if (a->data != NULL)
+      p = a->data + (*a->filled_len) * elem_size;
+
+   *a->filled_len += 1;
+
+   return p;
+}
+
+#define vk_outarray(elem_t) \
+   struct { \
+      struct __vk_outarray base; \
+      elem_t meta[]; \
+   }
+
+#define vk_outarray_typeof_elem(a) __typeof__((a)->meta[0])
+#define vk_outarray_sizeof_elem(a) sizeof((a)->meta[0])
+
+#define vk_outarray_init(a, data, len) \
+   __vk_outarray_init(&(a)->base, (data), (len))
+
+#define VK_OUTARRAY_MAKE(name, data, len) \
+   vk_outarray(__typeof__((data)[0])) name; \
+   vk_outarray_init(&name, (data), (len))
+
+#define vk_outarray_status(a) \
+   __vk_outarray_status(&(a)->base)
+
+#define vk_outarray_next(a) \
+   ((vk_outarray_typeof_elem(a) *) \
+      __vk_outarray_next(&(a)->base, vk_outarray_sizeof_elem(a)))
+
+/**
+ * Append to a Vulkan output array.
+ *
+ * This is a block-based macro. For example:
+ *
+ *    vk_outarray_append(&a, elem) {
+ *       elem->foo = ...;
+ *       elem->bar = ...;
+ *    }
+ *
+ * The array `a` has type `vk_outarray(elem_t) *`. It is usually declared with
+ * VK_OUTARRAY_MAKE(). The variable `elem` is block-scoped and has type
+ * `elem_t *`.
+ *
+ * The macro unconditionally increments the array's `wanted_len`. If the array
+ * is not full, then the macro also increment its `filled_len` and then
+ * executes the block. When the block is executed, `elem` is non-null and
+ * points to the newly appended element.
+ */
+#define vk_outarray_append(a, elem) \
+   for (vk_outarray_typeof_elem(a) *elem = vk_outarray_next(a); \
+        elem != NULL; elem = NULL)
+
+static inline void *
+__vk_find_struct(void *start, VkStructureType sType)
+{
+   vk_foreach_struct(s, start) {
+      if (s->sType == sType)
+         return s;
+   }
+
+   return NULL;
+}
+
+#define vk_find_struct(__start, __sType) \
+   __vk_find_struct((__start), VK_STRUCTURE_TYPE_##__sType)
+
+#define vk_find_struct_const(__start, __sType) \
+   (const void *)__vk_find_struct((void *)(__start), VK_STRUCTURE_TYPE_##__sType)
+
+#endif /* VK_UTIL_H */
index 8aee9c735136a87872ecb75807649e1c8eafc6f6..8166b7dd3441eaae89720805741b9bbd1cfc5c54 100644 (file)
@@ -26,7 +26,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 
 #include <stdint.h>
 #include <stdbool.h>
 
-#include "util/vk_alloc.h"
+#include "vk_alloc.h"
 #include <vulkan/vulkan.h>
 #include <vulkan/vk_icd.h>
 
 #include <vulkan/vulkan.h>
 #include <vulkan/vk_icd.h>
 
index 644ed62b414f2fb01c30f848fcee9b0d9b063d07..dd283a121117a7c0bf6522e2aee46f99a1604213 100644 (file)
@@ -31,7 +31,7 @@
 #include <string.h>
 #include <pthread.h>
 
 #include <string.h>
 #include <pthread.h>
 
-#include "util/vk_util.h"
+#include "vk_util.h"
 #include "wsi_common_wayland.h"
 #include "wayland-drm-client-protocol.h"
 
 #include "wsi_common_wayland.h"
 #include "wayland-drm-client-protocol.h"
 
index 5be56f1232fbb2fd9a2c29a294771bbbb1b67458..ecdaf914344943f7ab5fb14320c5442fd1a67f01 100644 (file)
@@ -38,7 +38,7 @@
 #include <xf86drm.h>
 #include "util/hash_table.h"
 
 #include <xf86drm.h>
 #include "util/hash_table.h"
 
-#include "util/vk_util.h"
+#include "vk_util.h"
 #include "wsi_common.h"
 #include "wsi_common_x11.h"
 #include "wsi_common_queue.h"
 #include "wsi_common.h"
 #include "wsi_common_x11.h"
 #include "wsi_common_queue.h"