Mesa (master): zink: add VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA for WSI allocations

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Nov 3 10:13:50 UTC 2020


Module: Mesa
Branch: master
Commit: 92022f2846e009527a898c8618864766e75d8e50
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=92022f2846e009527a898c8618864766e75d8e50

Author: Iago Toral Quiroga <itoral at igalia.com>
Date:   Fri Oct 30 10:44:17 2020 +0100

zink: add VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA for WSI allocations

Since Zink doesn't use swapchains to create presentable images, drivers
lose the capacity to identify memory allocations for them, which is a problem
when the underlying platform has special requirements for these, such as
needing to allocate them on a particular device. Including this struct in the
pNext chain, which is the same thing that the Mesa Vulkan WSI code does when
allocating memory for swapchain images, gives drivers a chance to identify
and handle these memory allocations properly.

v2: follow Zink's conventions for pNext chains (Mike)
v3: add scanout parameter for VkImage creation (Daniel)
v4: don't add a dependency on vulkan util (Erik)
v5: include vulkan directory for Zink builds

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com> (v2)
Reviewed-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7378>

---

 src/gallium/drivers/zink/meson.build     |  2 +-
 src/gallium/drivers/zink/zink_resource.c | 28 +++++++++++++++++++++++++++-
 src/meson.build                          |  2 +-
 src/vulkan/meson.build                   |  1 +
 4 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/zink/meson.build b/src/gallium/drivers/zink/meson.build
index 0790b48e877..4b90f2242d2 100644
--- a/src/gallium/drivers/zink/meson.build
+++ b/src/gallium/drivers/zink/meson.build
@@ -64,7 +64,7 @@ libzink = static_library(
   'zink',
   [files_libzink, zink_device_info, zink_nir_algebraic_c],
   gnu_symbol_visibility : 'hidden',
-  include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux],
+  include_directories : [inc_include, inc_src, inc_mapi, inc_mesa, inc_gallium, inc_gallium_aux, inc_vulkan_wsi, inc_vulkan_util],
   dependencies: [dep_vulkan, idep_nir_headers],
 )
 
diff --git a/src/gallium/drivers/zink/zink_resource.c b/src/gallium/drivers/zink/zink_resource.c
index 88bc347ad6b..99bcd579f27 100644
--- a/src/gallium/drivers/zink/zink_resource.c
+++ b/src/gallium/drivers/zink/zink_resource.c
@@ -27,6 +27,8 @@
 #include "zink_context.h"
 #include "zink_screen.h"
 
+#include "vulkan/wsi/wsi_common.h"
+
 #include "util/slab.h"
 #include "util/u_debug.h"
 #include "util/format/u_format.h"
@@ -225,6 +227,15 @@ resource_create(struct pipe_screen *pscreen,
       ici.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
       res->layout = VK_IMAGE_LAYOUT_UNDEFINED;
 
+      struct wsi_image_create_info image_wsi_info = {
+         VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA,
+         NULL,
+         .scanout = true,
+      };
+
+      if (templ->bind & PIPE_BIND_SCANOUT)
+         ici.pNext = &image_wsi_info;
+
       VkResult result = vkCreateImage(screen->dev, &ici, NULL, &res->image);
       if (result != VK_SUCCESS) {
          FREE(res);
@@ -250,6 +261,8 @@ resource_create(struct pipe_screen *pscreen,
    if (templ->bind & PIPE_BIND_SHARED) {
       emai.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO;
       emai.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
+
+      emai.pNext = mai.pNext;
       mai.pNext = &emai;
    }
 
@@ -263,7 +276,20 @@ resource_create(struct pipe_screen *pscreen,
       imfi.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
       imfi.fd = whandle->handle;
 
-      emai.pNext = &imfi;
+      imfi.pNext = mai.pNext;
+      mai.pNext = &imfi;
+   }
+
+   struct wsi_memory_allocate_info memory_wsi_info = {
+      VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA,
+      NULL,
+   };
+
+   if (templ->bind & PIPE_BIND_SCANOUT) {
+      memory_wsi_info.implicit_sync = true;
+
+      memory_wsi_info.pNext = mai.pNext;
+      mai.pNext = &memory_wsi_info;
    }
 
    if (vkAllocateMemory(screen->dev, &mai, NULL, &res->mem) != VK_SUCCESS)
diff --git a/src/meson.build b/src/meson.build
index a175e33cd4f..895d6277dc2 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -67,7 +67,7 @@ endif
 if with_platform_wayland
   subdir('egl/wayland/wayland-drm')
 endif
-if with_any_vk
+if with_any_vk or with_gallium_zink
   subdir('vulkan')
 endif
 if with_gallium_radeonsi or with_amd_vk
diff --git a/src/vulkan/meson.build b/src/vulkan/meson.build
index 7a0661363aa..abb6617c9b4 100644
--- a/src/vulkan/meson.build
+++ b/src/vulkan/meson.build
@@ -22,6 +22,7 @@ vk_api_xml = files('registry/vk.xml')
 vulkan_icd_symbols = files('vulkan-icd-symbols.txt')
 
 inc_vulkan_wsi = include_directories('wsi')
+inc_vulkan_util = include_directories('util')
 
 vulkan_wsi_args = []
 vulkan_wsi_deps = []



More information about the mesa-commit mailing list