vulkan: update to SDK 0.10.2
authorMatthew Waters <matthew@centricular.com>
Tue, 29 Dec 2015 05:05:17 +0000 (16:05 +1100)
committerMatthew Waters <matthew@centricular.com>
Tue, 16 Feb 2016 14:13:43 +0000 (01:13 +1100)
20 files changed:
ext/vulkan/vk.h
ext/vulkan/vkapi.h [new file with mode: 0644]
ext/vulkan/vkdevice.c
ext/vulkan/vkdevice.h
ext/vulkan/vkdisplay.c
ext/vulkan/vkdisplay.h
ext/vulkan/vkimagememory.c
ext/vulkan/vkinstance.c
ext/vulkan/vkmacros.h [new file with mode: 0644]
ext/vulkan/vkmemory.c
ext/vulkan/vkmemory.h
ext/vulkan/vkswapper.c
ext/vulkan/vkswapper.h
ext/vulkan/vkutils.c
ext/vulkan/vkwindow.c
ext/vulkan/vkwindow.h
ext/vulkan/xcb/vkdisplay_xcb.c
ext/vulkan/xcb/vkdisplay_xcb.h
ext/vulkan/xcb/vkwindow_xcb.c
ext/vulkan/xcb/vkwindow_xcb.h

index 556de5c..a311215 100644 (file)
 
 #include <gst/gst.h>
 
-#define VK_PROTOTYPES
-#include <vulkan/vulkan.h>
-#include <vulkan/vk_debug_report_lunarg.h>
-#include <vulkan/vk_ext_khr_swapchain.h>
-#include <vulkan/vk_ext_khr_device_swapchain.h>
-
-#include "vkconfig.h"
-#include "vk_fwd.h"
+#include "vkapi.h"
 
 #include "vkerror.h"
 #include "vkinstance.h"
diff --git a/ext/vulkan/vkapi.h b/ext/vulkan/vkapi.h
new file mode 100644 (file)
index 0000000..1768f16
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * GStreamer
+ * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _VK_API_H_
+#define _VK_API_H_
+
+#define VK_PROTOTYPES
+
+#include "vkconfig.h"
+#include "vk_fwd.h"
+#include "vkmacros.h"
+
+/* Need these defined to have access to winsys functions before including vulkan.h */
+#if GST_VULKAN_HAVE_WINDOW_XCB
+#ifndef VK_USE_PLATFORM_XCB_KHR
+#define VK_USE_PLATFORM_XCB_KHR
+#endif
+#endif
+
+#include <vulkan/vulkan.h>
+#include <vulkan/vk_lunarg_debug_report.h>
+
+#include "vkerror.h"
+#include "vkinstance.h"
+#include "vkdevice.h"
+#include "vkqueue.h"
+#include "vkdisplay.h"
+#include "vkwindow.h"
+#include "vkswapper.h"
+#include "vkmemory.h"
+#include "vkimagememory.h"
+#include "vkutils.h"
+
+#endif /* _VK_H_ */
index 0eeb462..7a75736 100644 (file)
 #include <string.h>
 
 static const char *device_validation_layers[] = {
-  "Threading",
-  "MemTracker",
-  "ObjectTracker",
-  "DrawState",
-  "ParamChecker",
-  "ShaderChecker",
-  "Swapchain",
-  "DeviceLimits",
-  "Image",
+  "VK_LAYER_LUNARG_Threading",
+  "VK_LAYER_LUNARG_MemTracker",
+  "VK_LAYER_LUNARG_ObjectTracker",
+  "VK_LAYER_LUNARG_DrawState",
+  "VK_LAYER_LUNARG_ParamChecker",
+  "VK_LAYER_LUNARG_Swapchain",
+  "VK_LAYER_LUNARG_DeviceLimits",
+  "VK_LAYER_LUNARG_Image",
 };
 
 #define GST_CAT_DEFAULT gst_vulkan_device_debug
@@ -90,17 +89,17 @@ gst_vulkan_device_finalize (GObject * object)
   g_free (device->queue_family_props);
   device->queue_family_props = NULL;
 
-  if (device->cmd_pool.handle)
-    vkDestroyCommandPool (device->device, device->cmd_pool);
-  device->cmd_pool.handle = 0;
+  if (device->cmd_pool)
+    vkDestroyCommandPool (device->device, device->cmd_pool, NULL);
+  device->cmd_pool = VK_NULL_HANDLE;
 
   if (device->device)
-    vkDestroyDevice (device->device);
-  device->device = NULL;
+    vkDestroyDevice (device->device, NULL);
+  device->device = VK_NULL_HANDLE;
 
   if (device->instance)
     gst_object_unref (device->instance);
-  device->instance = NULL;
+  device->instance = VK_NULL_HANDLE;
 }
 
 static const gchar *
@@ -127,7 +126,6 @@ _physical_device_info (GstVulkanDevice * device, GError ** error)
 {
   VkPhysicalDeviceProperties props;
   VkPhysicalDevice gpu;
-  VkResult err;
 
   gpu = gst_vulkan_device_get_physical_device (device);
   if (!gpu) {
@@ -137,15 +135,12 @@ _physical_device_info (GstVulkanDevice * device, GError ** error)
     return FALSE;
   }
 
-  err = vkGetPhysicalDeviceProperties (gpu, &props);
-  if (gst_vulkan_error_to_g_error (err, error,
-          "vkGetPhysicalDeviceProperties") < 0)
-    return FALSE;
+  vkGetPhysicalDeviceProperties (gpu, &props);
 
   GST_INFO_OBJECT (device, "device name %s type %s api version %u, "
       "driver version %u vendor ID 0x%x, device ID 0x%x", props.deviceName,
       _device_type_to_string (props.deviceType), props.apiVersion,
-      props.driverVersion, props.vendorId, props.deviceId);
+      props.driverVersion, props.vendorID, props.deviceID);
 
   return TRUE;
 }
@@ -230,54 +225,36 @@ gst_vulkan_device_open (GstVulkanDevice * device, GError ** error)
   }
 
   for (uint32_t i = 0; i < device_extension_count; i++) {
-    if (!strcmp ("VK_EXT_KHR_device_swapchain", device_extensions[i].extName)) {
+    if (!strcmp (VK_KHR_SWAPCHAIN_EXTENSION_NAME,
+            device_extensions[i].extensionName)) {
       have_swapchain_ext = TRUE;
       extension_names[enabled_extension_count++] =
-          "VK_EXT_KHR_device_swapchain";
+          (gchar *) VK_KHR_SWAPCHAIN_EXTENSION_NAME;
     }
     g_assert (enabled_extension_count < 64);
   }
   if (!have_swapchain_ext) {
-    g_error ("vkEnumerateDeviceExtensionProperties failed to find the "
-        "\"VK_EXT_KHR_device_swapchain\" extension.\n\nDo you have a compatible "
+    g_error ("vkEnumerateDeviceExtensionProperties failed to find the \""
+        VK_KHR_SWAPCHAIN_EXTENSION_NAME
+        "\" extension.\n\nDo you have a compatible "
         "Vulkan installable client driver (ICD) installed?\nPlease "
         "look at the Getting Started guide for additional "
         "information.\nvkCreateInstance Failure");
   }
   g_free (device_extensions);
 
-  err = vkGetPhysicalDeviceProperties (gpu, &device->gpu_props);
-  if (gst_vulkan_error_to_g_error (err, error,
-          "vkGetPhysicalDeviceProperties") < 0)
-    goto error;
-
-  err = vkGetPhysicalDeviceMemoryProperties (gpu, &device->memory_properties);
-  if (gst_vulkan_error_to_g_error (err, error,
-          "vkGetPhysicalDeviceProperties") < 0)
-    goto error;
-
-  err = vkGetPhysicalDeviceFeatures (gpu, &device->gpu_features);
-  if (gst_vulkan_error_to_g_error (err, error,
-          "vkGetPhysicalDeviceFeatures") < 0)
-    goto error;
+  vkGetPhysicalDeviceProperties (gpu, &device->gpu_props);
+  vkGetPhysicalDeviceMemoryProperties (gpu, &device->memory_properties);
+  vkGetPhysicalDeviceFeatures (gpu, &device->gpu_features);
 
-  /* Call with NULL data to get count */
-  err =
-      vkGetPhysicalDeviceQueueFamilyProperties (gpu, &device->n_queue_families,
+  vkGetPhysicalDeviceQueueFamilyProperties (gpu, &device->n_queue_families,
       NULL);
-  if (gst_vulkan_error_to_g_error (err, error,
-          "vkGetPhysicalDeviceQueueFamilyProperties") < 0)
-    goto error;
   g_assert (device->n_queue_families >= 1);
 
   device->queue_family_props =
       g_new0 (VkQueueFamilyProperties, device->n_queue_families);
-  err =
-      vkGetPhysicalDeviceQueueFamilyProperties (gpu, &device->n_queue_families,
+  vkGetPhysicalDeviceQueueFamilyProperties (gpu, &device->n_queue_families,
       device->queue_family_props);
-  if (gst_vulkan_error_to_g_error (err, error,
-          "vkGetPhysicalDeviceQueueFamilyProperties") < 0)
-    goto error;
 
   /* FIXME: allow overriding/selecting */
   for (i = 0; i < device->n_queue_families; i++) {
@@ -304,29 +281,30 @@ gst_vulkan_device_open (GstVulkanDevice * device, GError ** error)
 
     device_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
     device_info.pNext = NULL;
-    device_info.queueRecordCount = 1;
-    device_info.pRequestedQueues = &queue_info;
-    device_info.layerCount = enabled_layer_count;
+    device_info.queueCreateInfoCount = 1;
+    device_info.pQueueCreateInfos = &queue_info;
+    device_info.enabledLayerNameCount = enabled_layer_count;
     device_info.ppEnabledLayerNames =
         (const char *const *) device_validation_layers;
-    device_info.extensionCount = enabled_extension_count;
+    device_info.enabledExtensionNameCount = enabled_extension_count;
     device_info.ppEnabledExtensionNames = (const char *const *) extension_names;
     device_info.pEnabledFeatures = NULL;
 
-    err = vkCreateDevice (gpu, &device_info, &device->device);
+    err = vkCreateDevice (gpu, &device_info, NULL, &device->device);
     if (gst_vulkan_error_to_g_error (err, error, "vkCreateDevice") < 0)
       goto error;
   }
   {
-    VkCmdPoolCreateInfo cmd_pool_info = { 0, };
+    VkCommandPoolCreateInfo cmd_pool_info = { 0, };
 
-    cmd_pool_info.sType = VK_STRUCTURE_TYPE_CMD_POOL_CREATE_INFO;
+    cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
     cmd_pool_info.pNext = NULL;
     cmd_pool_info.queueFamilyIndex = device->queue_family_id;
     cmd_pool_info.flags = 0;
 
     err =
-        vkCreateCommandPool (device->device, &cmd_pool_info, &device->cmd_pool);
+        vkCreateCommandPool (device->device, &cmd_pool_info, NULL,
+        &device->cmd_pool);
     if (gst_vulkan_error_to_g_error (err, error, "vkCreateCommandPool") < 0)
       goto error;
   }
@@ -346,7 +324,6 @@ gst_vulkan_device_get_queue (GstVulkanDevice * device, guint32 queue_family,
     guint32 queue_i, GError ** error)
 {
   GstVulkanQueue *ret;
-  VkResult err;
 
   g_return_val_if_fail (GST_IS_VULKAN_DEVICE (device), NULL);
   g_return_val_if_fail (device->device != NULL, NULL);
@@ -359,11 +336,7 @@ gst_vulkan_device_get_queue (GstVulkanDevice * device, guint32 queue_family,
   ret->family = queue_family;
   ret->index = queue_i;
 
-  err = vkGetDeviceQueue (device->device, queue_family, queue_i, &ret->queue);
-  if (gst_vulkan_error_to_g_error (err, error, "vkGetDeviceQueue") < 0) {
-    gst_object_unref (ret);
-    return NULL;
-  }
+  vkGetDeviceQueue (device->device, queue_family, queue_i, &ret->queue);
 
   return ret;
 }
@@ -404,18 +377,18 @@ gst_vulkan_device_get_physical_device (GstVulkanDevice * device)
 
 gboolean
 gst_vulkan_device_create_cmd_buffer (GstVulkanDevice * device,
-    VkCmdBuffer * cmd, GError ** error)
+    VkCommandBuffer * cmd, GError ** error)
 {
   VkResult err;
-  VkCmdBufferCreateInfo cmd_info = { 0, };
+  VkCommandBufferAllocateInfo cmd_info = { 0, };
 
-  cmd_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_CREATE_INFO;
+  cmd_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
   cmd_info.pNext = NULL;
-  cmd_info.cmdPool = device->cmd_pool;
-  cmd_info.level = VK_CMD_BUFFER_LEVEL_PRIMARY;
-  cmd_info.flags = 0;
+  cmd_info.commandPool = device->cmd_pool;
+  cmd_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
+  cmd_info.bufferCount = 1;
 
-  err = vkCreateCommandBuffer (device->device, &cmd_info, cmd);
+  err = vkAllocateCommandBuffers (device->device, &cmd_info, cmd);
   if (gst_vulkan_error_to_g_error (err, error, "vkCreateCommandBuffer") < 0)
     return FALSE;
 
index d514e31..155aaba 100644 (file)
@@ -52,7 +52,7 @@ struct _GstVulkanDevice
   guint32 queue_family_id;
   guint32 n_queues;
 
-  VkCmdPool cmd_pool;
+  VkCommandPool cmd_pool;
 
   GstVulkanDevicePrivate *priv;
 };
@@ -75,7 +75,7 @@ GstVulkanQueue *    gst_vulkan_device_get_queue             (GstVulkanDevice * d
                                                              GError ** error);
 VkPhysicalDevice    gst_vulkan_device_get_physical_device   (GstVulkanDevice * device);
 gboolean            gst_vulkan_device_create_cmd_buffer     (GstVulkanDevice * device,
-                                                             VkCmdBuffer * cmd,
+                                                             VkCommandBuffer * cmd,
                                                              GError ** error);
 
 G_END_DECLS
index dcf3b55..af36a40 100644 (file)
@@ -69,8 +69,6 @@ enum
 static void gst_vulkan_display_finalize (GObject * object);
 static gpointer gst_vulkan_display_default_get_handle (GstVulkanDisplay *
     display);
-static gpointer gst_vulkan_display_default_get_platform_handle (GstVulkanDisplay
-    * display);
 static GstVulkanWindow
     * gst_vulkan_display_default_create_window (GstVulkanDisplay * display);
 
@@ -115,7 +113,6 @@ gst_vulkan_display_class_init (GstVulkanDisplayClass * klass)
   g_type_class_add_private (klass, sizeof (GstVulkanDisplayPrivate));
 
   klass->get_handle = gst_vulkan_display_default_get_handle;
-  klass->get_platform_handle = gst_vulkan_display_default_get_platform_handle;
   klass->create_window = gst_vulkan_display_default_create_window;
 
   G_OBJECT_CLASS (klass)->finalize = gst_vulkan_display_finalize;
@@ -165,6 +162,26 @@ gst_vulkan_display_finalize (GObject * object)
   G_OBJECT_CLASS (gst_vulkan_display_parent_class)->finalize (object);
 }
 
+GstVulkanDisplay *
+gst_vulkan_display_new_with_type (GstVulkanInstance * instance,
+    GstVulkanDisplayType type)
+{
+  GstVulkanDisplay *display = NULL;
+
+  _init_debug ();
+
+#if GST_VULKAN_HAVE_WINDOW_XCB
+  if (!display && type & GST_VULKAN_DISPLAY_TYPE_XCB) {
+    display = GST_VULKAN_DISPLAY (gst_vulkan_display_xcb_new (NULL));
+  }
+#endif
+
+  if (display)
+    display->instance = gst_object_ref (instance);
+
+  return display;
+}
+
 /**
  * gst_vulkan_display_new:
  *
@@ -173,33 +190,20 @@ gst_vulkan_display_finalize (GObject * object)
  * Since: 1.10
  */
 GstVulkanDisplay *
-gst_vulkan_display_new (void)
+gst_vulkan_display_new (GstVulkanInstance * instance)
 {
+  GstVulkanDisplayType type;
   GstVulkanDisplay *display = NULL;
-  const gchar *user_choice, *platform_choice;
 
-  _init_debug ();
-
-  user_choice = g_getenv ("GST_GL_WINDOW");
-  platform_choice = g_getenv ("GST_GL_PLATFORM");
-  GST_INFO ("creating a display, user choice:%s (platform: %s)",
-      GST_STR_NULL (user_choice), GST_STR_NULL (platform_choice));
+  type = gst_vulkan_display_choose_type (instance);
+  display = gst_vulkan_display_new_with_type (instance, type);
 
-#if GST_VULKAN_HAVE_WINDOW_XCB
-  if (!display && (!user_choice || g_strstr_len (user_choice, 3, "xcb")))
-    display = GST_VULKAN_DISPLAY (gst_vulkan_display_xcb_new (NULL));
-#endif
-#if GST_VULKAN_HAVE_WINDOW_X11
-  if (!display && (!user_choice || g_strstr_len (user_choice, 3, "x11")))
-    display = GST_VULKAN_DISPLAY (gst_vulkan_display_x11_new (NULL));
-#endif
   if (!display) {
-    /* subclass returned a NULL window */
-    GST_WARNING ("Could not create display. user specified %s "
-        "(platform: %s), creating dummy",
-        GST_STR_NULL (user_choice), GST_STR_NULL (platform_choice));
+    /* subclass returned a NULL display */
+    GST_FIXME ("creating dummy display");
 
     display = g_object_new (GST_TYPE_VULKAN_DISPLAY, NULL);
+    display->instance = gst_object_ref (instance);
   }
 
   return display;
@@ -232,33 +236,6 @@ gst_vulkan_display_default_get_handle (GstVulkanDisplay * display)
 }
 
 /**
- * gst_vulkan_display_get_platform_handle:
- * @display: a #GstVulkanDisplay
- *
- * Returns: the winsys specific handle of @display for use with the
- * VK_EXT_KHR_swapchain extension.
- *
- * Since: 1.10
- */
-gpointer
-gst_vulkan_display_get_platform_handle (GstVulkanDisplay * display)
-{
-  GstVulkanDisplayClass *klass;
-
-  g_return_val_if_fail (GST_IS_VULKAN_DISPLAY (display), NULL);
-  klass = GST_VULKAN_DISPLAY_GET_CLASS (display);
-  g_return_val_if_fail (klass->get_handle != NULL, NULL);
-
-  return klass->get_platform_handle (display);
-}
-
-static gpointer
-gst_vulkan_display_default_get_platform_handle (GstVulkanDisplay * display)
-{
-  return (gpointer) gst_vulkan_display_get_handle (display);
-}
-
-/**
  * gst_vulkan_display_get_handle_type:
  * @display: a #GstVulkanDisplay
  *
@@ -382,3 +359,50 @@ gst_context_get_vulkan_display (GstContext * context,
 
   return ret;
 }
+
+GstVulkanDisplayType
+gst_vulkan_display_choose_type (GstVulkanInstance * instance)
+{
+  const gchar *window_str;
+  GstVulkanDisplayType type = GST_VULKAN_DISPLAY_TYPE_NONE;
+  GstVulkanDisplayType first_supported = GST_VULKAN_DISPLAY_TYPE_NONE;
+
+  window_str = g_getenv ("GST_VULKAN_WINDOW");
+
+  /* FIXME: enumerate instance extensions for the supported winsys' */
+
+#define CHOOSE_WINSYS(lname,uname) \
+  G_STMT_START { \
+    if (!type && g_strcmp0 (window_str, G_STRINGIFY (lname)) == 0) { \
+      type = G_PASTE(GST_VULKAN_DISPLAY_TYPE_,uname); \
+    } \
+    if (!first_supported) \
+      first_supported = G_PASTE(GST_VULKAN_DISPLAY_TYPE_,uname); \
+  } G_STMT_END
+
+#if GST_VULKAN_HAVE_WINDOW_XCB
+  CHOOSE_WINSYS (xcb, XCB);
+#endif
+
+#undef CHOOSE_WINSYS
+
+  if (type)
+    return type;
+
+  if (first_supported)
+    return first_supported;
+
+  return GST_VULKAN_DISPLAY_TYPE_NONE;
+}
+
+const gchar *
+gst_vulkan_display_type_to_extension_string (GstVulkanDisplayType type)
+{
+  if (type == GST_VULKAN_DISPLAY_TYPE_NONE)
+    return NULL;
+
+  if (type & GST_VULKAN_DISPLAY_TYPE_XCB)
+    return VK_KHR_XCB_SURFACE_EXTENSION_NAME;
+
+  return NULL;
+}
index 9a1f65a..b1487fb 100644 (file)
@@ -66,6 +66,8 @@ struct _GstVulkanDisplay
 
   GstVulkanDisplayType      type;
 
+  GstVulkanInstance        *instance;
+
   /* <protected> */
   GList                    *windows;        /* OBJECT lock */
   GMainContext             *main_context;
@@ -81,15 +83,18 @@ struct _GstVulkanDisplayClass
   GstObjectClass object_class;
 
   gpointer          (*get_handle)           (GstVulkanDisplay * display);
-  gpointer          (*get_platform_handle)  (GstVulkanDisplay * display); /* default chains up to @get_handle */
   GstVulkanWindow * (*create_window)        (GstVulkanDisplay * display);
 };
 
-GstVulkanDisplay *      gst_vulkan_display_new (void);
+GstVulkanDisplay *      gst_vulkan_display_new                      (GstVulkanInstance *instance);
+GstVulkanDisplay *      gst_vulkan_display_new_with_type            (GstVulkanInstance *instance,
+                                                                     GstVulkanDisplayType type);
+GstVulkanDisplayType    gst_vulkan_display_choose_type              (GstVulkanInstance *instance);
+const gchar *           gst_vulkan_display_type_to_extension_string (GstVulkanDisplayType type);
+
 
 gpointer                gst_vulkan_display_get_handle               (GstVulkanDisplay * display);
 GstVulkanDisplayType    gst_vulkan_display_get_handle_type          (GstVulkanDisplay * display);
-gpointer                gst_vulkan_display_get_platform_handle      (GstVulkanDisplay * display);
 GstVulkanWindow *       gst_vulkan_display_create_window            (GstVulkanDisplay * display);
 
 gboolean                gst_context_get_vulkan_display              (GstContext * context,
index 2e13acd..6759e01 100644 (file)
@@ -108,17 +108,13 @@ _view_create_info (VkImage image, VkFormat format, VkImageViewCreateInfo * info)
   info->pNext = NULL;
   info->image = image;
   info->format = format;
-  info->channels.r = VK_CHANNEL_SWIZZLE_R;
-  info->channels.g = VK_CHANNEL_SWIZZLE_G;
-  info->channels.b = VK_CHANNEL_SWIZZLE_B;
-  info->channels.a = VK_CHANNEL_SWIZZLE_A;
-  info->subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
-  info->subresourceRange.baseMipLevel = 0;
-  info->subresourceRange.mipLevels = 1;
-  info->subresourceRange.baseArrayLayer = 0;
-  info->subresourceRange.arraySize = 1;
   info->viewType = VK_IMAGE_VIEW_TYPE_2D;
   info->flags = 0;
+
+  GST_VK_COMPONENT_MAPPING (info->components, VK_COMPONENT_SWIZZLE_R,
+      VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A);
+  GST_VK_IMAGE_SUBRESOURCE_RANGE (info->subresourceRange,
+      VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1);
 }
 
 static gboolean
@@ -131,8 +127,8 @@ _find_memory_type_index_with_type_properties (GstVulkanDevice * device,
   for (i = 0; i < 32; i++) {
     if ((typeBits & 1) == 1) {
       /* Type is available, does it match user properties? */
-      if ((device->memory_properties.
-              memoryTypes[i].propertyFlags & properties) == properties) {
+      if ((device->memory_properties.memoryTypes[i].
+              propertyFlags & properties) == properties) {
         *typeIndex = i;
         return TRUE;
       }
@@ -153,16 +149,14 @@ _create_info_from_args (VkImageCreateInfo * info, VkFormat format, gsize width,
   info->pNext = NULL;
   info->imageType = VK_IMAGE_TYPE_2D;
   info->format = format;
-  info->extent.width = (gint32) width;
-  info->extent.height = (gint32) height;
-  info->extent.depth = 1;
+  GST_VK_EXTENT3D (info->extent, width, height, 1);
   info->mipLevels = 1;
-  info->arraySize = 1;
+  info->arrayLayers = 1;
   info->samples = 1;
   info->tiling = tiling;
   info->usage = usage;
   info->sharingMode = VK_SHARING_MODE_EXCLUSIVE;
-  info->queueFamilyCount = 0;
+  info->queueFamilyIndexCount = 0;
   info->pQueueFamilyIndices = NULL;
   info->initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
 
@@ -223,17 +217,11 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
     goto error;
   }
 
-  err = vkCreateImage (device->device, &image_info, &image);
+  err = vkCreateImage (device->device, &image_info, NULL, &image);
   if (gst_vulkan_error_to_g_error (err, &error, "vkCreateImage") < 0)
     goto vk_error;
 
-  err =
-      vkGetImageMemoryRequirements (device->device, image, &mem->requirements);
-  if (gst_vulkan_error_to_g_error (err, &error,
-          "vkGetImageMemoryRequirements") < 0) {
-    vkDestroyImage (device->device, image);
-    goto vk_error;
-  }
+  vkGetImageMemoryRequirements (device->device, image, &mem->requirements);
 
   params.align = mem->requirements.alignment;
   _vk_image_mem_init (mem, allocator, parent, device, &params,
@@ -241,11 +229,8 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
   mem->create_info = image_info;
   mem->image = image;
 
-  err = vkGetPhysicalDeviceImageFormatProperties (gpu, format, VK_IMAGE_TYPE_2D,
+  vkGetPhysicalDeviceImageFormatProperties (gpu, format, VK_IMAGE_TYPE_2D,
       tiling, usage, 0, &mem->format_properties);
-  if (gst_vulkan_error_to_g_error (err, &error,
-          "vkGetPhysicalDeviceImageFormatProperties") < 0)
-    goto vk_error;
 
   if (!_find_memory_type_index_with_type_properties (device,
           mem->requirements.memoryTypeBits, mem_prop_flags,
@@ -273,7 +258,7 @@ _vk_image_mem_new_alloc (GstAllocator * allocator, GstMemory * parent,
   if (usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
           VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) {
     _view_create_info (mem->image, format, &view_info);
-    err = vkCreateImageView (device->device, &view_info, &mem->view);
+    err = vkCreateImageView (device->device, &view_info, NULL, &mem->view);
     if (gst_vulkan_error_to_g_error (err, &error, "vkCreateImageView") < 0)
       goto vk_error;
   }
@@ -311,14 +296,7 @@ _vk_image_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
   gpu = gst_vulkan_device_get_physical_device (device);
   mem->image = image;
 
-  err =
-      vkGetImageMemoryRequirements (device->device, mem->image,
-      &mem->requirements);
-  if (gst_vulkan_error_to_g_error (err, &error,
-          "vkGetImageMemoryRequirements") < 0) {
-    vkDestroyImage (device->device, image);
-    goto vk_error;
-  }
+  vkGetImageMemoryRequirements (device->device, mem->image, &mem->requirements);
 
   params.flags = GST_MEMORY_FLAG_NOT_MAPPABLE | GST_MEMORY_FLAG_READONLY;
   _vk_image_mem_init (mem, allocator, parent, device, &params,
@@ -340,7 +318,7 @@ _vk_image_mem_new_wrapped (GstAllocator * allocator, GstMemory * parent,
   if (usage & (VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_STORAGE_BIT |
           VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)) {
     _view_create_info (mem->image, format, &view_info);
-    err = vkCreateImageView (device->device, &view_info, &mem->view);
+    err = vkCreateImageView (device->device, &view_info, NULL, &mem->view);
     if (gst_vulkan_error_to_g_error (err, &error, "vkCreateImageView") < 0)
       goto vk_error;
   }
@@ -425,13 +403,13 @@ _vk_image_mem_free (GstAllocator * allocator, GstMemory * memory)
   GstVulkanImageMemory *mem = (GstVulkanImageMemory *) memory;
 
   GST_CAT_TRACE (GST_CAT_VULKAN_IMAGE_MEMORY, "freeing image memory:%p "
-      "id:%" G_GUINT64_FORMAT, mem, mem->image.handle);
+      "id:%" G_GUINT64_FORMAT, mem, (guint64) mem->image);
 
-  if (mem->image.handle && !mem->wrapped)
-    vkDestroyImage (mem->device->device, mem->image);
+  if (mem->image && !mem->wrapped)
+    vkDestroyImage (mem->device->device, mem->image, NULL);
 
-  if (mem->view.handle)
-    vkDestroyImageView (mem->device->device, mem->view);
+  if (mem->view)
+    vkDestroyImageView (mem->device->device, mem->view, NULL);
 
   if (mem->vk_mem)
     gst_memory_unref ((GstMemory *) mem->vk_mem);
@@ -450,26 +428,29 @@ gst_vulkan_image_memory_set_layout (GstVulkanImageMemory * vk_mem,
 
   barrier->sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
   barrier->pNext = NULL;
-  barrier->outputMask = 0;
-  barrier->inputMask = 0;
+  barrier->dstAccessMask = 0;
+  barrier->srcAccessMask = 0;
   barrier->oldLayout = vk_mem->image_layout;
   barrier->newLayout = image_layout;
   barrier->image = vk_mem->image;
-  barrier->subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR;
-  barrier->subresourceRange.baseMipLevel = 0;
-  barrier->subresourceRange.mipLevels = 1;
-  barrier->subresourceRange.baseArrayLayer = 0;
-  barrier->subresourceRange.arraySize = 0;
-
-  if (image_layout == VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL) {
-    /* Make sure anything that was copying from this image has completed */
-    barrier->inputMask = VK_MEMORY_INPUT_TRANSFER_BIT;
+  GST_VK_IMAGE_SUBRESOURCE_RANGE (barrier->subresourceRange,
+      VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1);
+
+  if (image_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) {
+    barrier->dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
+  }
+
+  if (image_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) {
+    barrier->dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
+  }
+
+  if (image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) {
+    barrier->dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
   }
 
   if (image_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) {
-    /* Make sure any Copy or CPU writes to image are flushed */
-    barrier->outputMask =
-        VK_MEMORY_OUTPUT_HOST_WRITE_BIT | VK_MEMORY_OUTPUT_TRANSFER_BIT;
+    barrier->dstAccessMask =
+        VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT;
   }
 
   /* FIXME: what if the barrier is never submitted or is submitted out of order? */
index 7ded8f9..958479c 100644 (file)
 #define APP_SHORT_NAME "GStreamer"
 
 static const char *instance_validation_layers[] = {
-  "Threading",
-  "MemTracker",
-  "ObjectTracker",
-  "DrawState",
-  "ParamChecker",
-  "ShaderChecker",
-  "Swapchain",
-  "DeviceLimits",
-  "Image",
+  "VK_LAYER_LUNARG_Threading",
+  "VK_LAYER_LUNARG_MemTracker",
+  "VK_LAYER_LUNARG_ObjectTracker",
+  "VK_LAYER_LUNARG_DrawState",
+  "VK_LAYER_LUNARG_ParamChecker",
+  "VK_LAYER_LUNARG_Swapchain",
+  "VK_LAYER_LUNARG_DeviceLimits",
+  "VK_LAYER_LUNARG_Image",
 };
 
 #define GST_CAT_DEFAULT gst_vulkan_instance_debug
@@ -100,7 +99,7 @@ gst_vulkan_instance_finalize (GObject * object)
   instance->priv->opened = FALSE;
 
   if (instance->instance)
-    vkDestroyInstance (instance->instance);
+    vkDestroyInstance (instance->instance, NULL);
   instance->instance = NULL;
 }
 
@@ -210,21 +209,23 @@ gst_vulkan_instance_open (GstVulkanInstance * instance, GError ** error)
 
   /* TODO: allow outside selection */
   for (uint32_t i = 0; i < instance_extension_count; i++) {
-    if (!g_strcmp0 ("VK_EXT_KHR_swapchain", instance_extensions[i].extName)) {
+    if (!g_strcmp0 (VK_KHR_SURFACE_EXTENSION_NAME,
+            instance_extensions[i].extensionName)) {
       have_swapchain_ext = TRUE;
       extension_names[enabled_extension_count++] =
-          (gchar *) "VK_EXT_KHR_swapchain";
+          (gchar *) VK_KHR_SURFACE_EXTENSION_NAME;
     }
     if (!g_strcmp0 (VK_DEBUG_REPORT_EXTENSION_NAME,
-            instance_extensions[i].extName)) {
+            instance_extensions[i].extensionName)) {
       extension_names[enabled_extension_count++] =
           (gchar *) VK_DEBUG_REPORT_EXTENSION_NAME;
     }
     g_assert (enabled_extension_count < 64);
   }
   if (!have_swapchain_ext) {
-    g_error ("vkEnumerateInstanceExtensionProperties failed to find the "
-        "\"VK_EXT_KHR_swapchain\" extension.\n\nDo you have a compatible "
+    g_error ("vkEnumerateInstanceExtensionProperties failed to find the \""
+        VK_KHR_SURFACE_EXTENSION_NAME
+        "\" extension.\n\nDo you have a compatible "
         "Vulkan installable client driver (ICD) installed?\nPlease "
         "look at the Getting Started guide for additional "
         "information.\nvkCreateInstance Failure");
@@ -236,23 +237,22 @@ gst_vulkan_instance_open (GstVulkanInstance * instance, GError ** error)
 
     app.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
     app.pNext = NULL;
-    app.pAppName = APP_SHORT_NAME;
-    app.appVersion = 0;
+    app.pApplicationName = APP_SHORT_NAME;
+    app.applicationVersion = 0;
     app.pEngineName = APP_SHORT_NAME;
     app.engineVersion = 0;
     app.apiVersion = VK_API_VERSION;
 
     inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
     inst_info.pNext = NULL;
-    inst_info.pAppInfo = &app;
-    inst_info.pAllocCb = NULL;
-    inst_info.layerCount = enabled_layer_count;
+    inst_info.pApplicationInfo = &app;
+    inst_info.enabledLayerNameCount = enabled_layer_count;
     inst_info.ppEnabledLayerNames =
         (const char *const *) instance_validation_layers;
-    inst_info.extensionCount = enabled_extension_count;
+    inst_info.enabledExtensionNameCount = enabled_extension_count;
     inst_info.ppEnabledExtensionNames = (const char *const *) extension_names;
 
-    err = vkCreateInstance (&inst_info, &instance->instance);
+    err = vkCreateInstance (&inst_info, NULL, &instance->instance);
     if (gst_vulkan_error_to_g_error (err, error, "vkCreateInstance") < 0) {
       g_free (instance_layers);
       g_free (instance_extensions);
diff --git a/ext/vulkan/vkmacros.h b/ext/vulkan/vkmacros.h
new file mode 100644 (file)
index 0000000..f94d9e1
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * GStreamer
+ * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef _VK_MACROS_H_
+#define _VK_MACROS_H_
+
+#include <gst/gst.h>
+#include <vk.h>
+
+G_BEGIN_DECLS
+
+#define GST_VK_COMPONENT_MAPPING(component, r_, g_, b_, a_) \
+  G_STMT_START { \
+    component.r = r_; \
+    component.g = g_; \
+    component.b = b_; \
+    component.a = a_; \
+  } G_STMT_END
+
+#define GST_VK_EXTENT3D(extent,w,h,d) \
+  G_STMT_START { \
+    extent.width = w; \
+    extent.height = h; \
+    extent.depth = d; \
+  } G_STMT_END
+
+#define GST_VK_IMAGE_SUBRESOURCE(sub,a,m,l) \
+    G_STMT_START { \
+      sub.aspectMask = a; \
+      sub.mipLevel = m; \
+      sub.arrayLayer = l; \
+    } G_STMT_END
+
+#define GST_VK_IMAGE_SUBRESOURCE_LAYERS(res,aspect_,mip,base_layer,layer_count) \
+  G_STMT_START { \
+    res.aspectMask = aspect_; \
+    res.mipLevel = mip; \
+    res.baseArrayLayer = base_layer; \
+    res.layerCount = layer_count; \
+  } G_STMT_END
+
+#define GST_VK_IMAGE_SUBRESOURCE_RANGE(range, aspect, mip_lvl, mip_lvl_count, array, layer_count) \
+  G_STMT_START { \
+    range.aspectMask = aspect; \
+    range.baseMipLevel = mip_lvl; \
+    range.levelCount = mip_lvl_count; \
+    range.baseArrayLayer = array; \
+    range.layerCount = layer_count; \
+  } G_STMT_END
+
+#define GST_VK_OFFSET3D(offset,x_,y_,z_) \
+  G_STMT_START { \
+    offset.x = x_; \
+    offset.y = y_; \
+    offset.z = z_; \
+  } G_STMT_END
+
+G_END_DECLS
+
+#endif /*_VK_UTILS_H_ */
index 552ea4c..b1c2b3a 100644 (file)
@@ -55,25 +55,21 @@ _memory_properties_to_string (VkMemoryPropertyFlags prop_bits)
   } G_STMT_END
 
   s = g_string_new (NULL);
+  if (prop_bits & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT) {
+    STR_APPEND (s, "device-local");
+  }
   if (prop_bits & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) {
     STR_APPEND (s, "host-visible");
-    if (prop_bits & VK_MEMORY_PROPERTY_HOST_NON_COHERENT_BIT) {
-      STR_APPEND (s, "host-incoherent");
-    } else {
+    if (prop_bits & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) {
       STR_APPEND (s, "host-coherent");
-    }
-    if (prop_bits & VK_MEMORY_PROPERTY_HOST_UNCACHED_BIT) {
-      STR_APPEND (s, "host-uncached");
     } else {
-      STR_APPEND (s, "host-cached");
+      STR_APPEND (s, "host-incoherent");
     }
-    if (prop_bits & VK_MEMORY_PROPERTY_HOST_WRITE_COMBINED_BIT) {
-      STR_APPEND (s, "host-write-combined");
+    if (prop_bits & VK_MEMORY_PROPERTY_HOST_CACHED_BIT) {
+      STR_APPEND (s, "host-cached");
     } else {
-      STR_APPEND (s, "host-write-uncombined");
+      STR_APPEND (s, "host-uncached");
     }
-  } else {
-    STR_APPEND (s, "device-only");
   }
 
   if (prop_bits & VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT) {
@@ -107,7 +103,7 @@ _vk_mem_init (GstVulkanMemory * mem, GstAllocator * allocator,
       align, offset, size);
 
   mem->device = gst_object_ref (device);
-  mem->alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOC_INFO;
+  mem->alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
   mem->alloc_info.pNext = NULL;
   mem->alloc_info.allocationSize = (VkDeviceSize) mem->mem.maxsize;
   mem->alloc_info.memoryTypeIndex = memory_type_index;
@@ -139,7 +135,8 @@ _vk_mem_new (GstAllocator * allocator, GstMemory * parent,
   _vk_mem_init (mem, allocator, parent, device, memory_type_index, params,
       size, mem_props_flags, user_data, notify);
 
-  err = vkAllocMemory (device->device, &mem->alloc_info, &mem->mem_ptr);
+  err =
+      vkAllocateMemory (device->device, &mem->alloc_info, NULL, &mem->mem_ptr);
   if (gst_vulkan_error_to_g_error (err, &error, "vkAllocMemory") < 0) {
     GST_CAT_ERROR (GST_CAT_VULKAN_MEMORY, "Failed to allocate device memory %s",
         error->message);
@@ -213,14 +210,14 @@ _vk_mem_free (GstAllocator * allocator, GstMemory * memory)
   GstVulkanMemory *mem = (GstVulkanMemory *) memory;
 
   GST_CAT_TRACE (GST_CAT_VULKAN_MEMORY, "freeing buffer memory:%p "
-      "id:%" G_GUINT64_FORMAT, mem, mem->mem_ptr.handle);
+      "id:%" G_GUINT64_FORMAT, mem, (guint64) mem->mem_ptr);
 
   g_mutex_clear (&mem->lock);
 
   if (mem->notify)
     mem->notify (mem->user_data);
 
-  vkFreeMemory (mem->device->device, mem->mem_ptr);
+  vkFreeMemory (mem->device->device, mem->mem_ptr, NULL);
 
   gst_object_unref (mem->device);
 }
index 6983e83..b77c995 100644 (file)
@@ -43,21 +43,21 @@ GType gst_vulkan_memory_allocator_get_type(void);
 
 struct _GstVulkanMemory
 {
-  GstMemory             mem;
+  GstMemory                 mem;
 
-  GstVulkanDevice      *device;
+  GstVulkanDevice          *device;
 
-  VkDeviceMemory        mem_ptr;
+  VkDeviceMemory            mem_ptr;
 
   /* <protected> */
-  GMutex                lock;
+  GMutex                    lock;
 
   /* <private> */
-  GDestroyNotify        notify;
-  gpointer              user_data;
+  GDestroyNotify            notify;
+  gpointer                  user_data;
 
-  VkMemoryAllocInfo     alloc_info;
-  VkMemoryPropertyFlags properties;
+  VkMemoryAllocateInfo    alloc_info;
+  VkMemoryPropertyFlags     properties;
 };
 
 /**
index 3de4841..94c4a7e 100644 (file)
@@ -68,9 +68,12 @@ _get_function_table (GstVulkanSwapper * swapper)
 
   GET_PROC_ADDRESS_REQUIRED (swapper, instance,
       GetPhysicalDeviceSurfaceSupportKHR);
-  GET_PROC_ADDRESS_REQUIRED (swapper, device, GetSurfacePropertiesKHR);
-  GET_PROC_ADDRESS_REQUIRED (swapper, device, GetSurfaceFormatsKHR);
-  GET_PROC_ADDRESS_REQUIRED (swapper, device, GetSurfacePresentModesKHR);
+  GET_PROC_ADDRESS_REQUIRED (swapper, device,
+      GetPhysicalDeviceSurfaceCapabilitiesKHR);
+  GET_PROC_ADDRESS_REQUIRED (swapper, device,
+      GetPhysicalDeviceSurfaceFormatsKHR);
+  GET_PROC_ADDRESS_REQUIRED (swapper, device,
+      GetPhysicalDeviceSurfacePresentModesKHR);
   GET_PROC_ADDRESS_REQUIRED (swapper, device, CreateSwapchainKHR);
   GET_PROC_ADDRESS_REQUIRED (swapper, device, DestroySwapchainKHR);
   GET_PROC_ADDRESS_REQUIRED (swapper, device, GetSwapchainImagesKHR);
@@ -84,57 +87,6 @@ _get_function_table (GstVulkanSwapper * swapper)
 #undef GET_PROC_ADDRESS_REQUIRED
 }
 
-static VkPlatformKHR
-_gst_display_type_to_vk_platform (GstVulkanDisplayType dtype)
-{
-  VkPlatformKHR ret = -1;
-
-  if (dtype == GST_VULKAN_DISPLAY_TYPE_ANY)
-    return -1;
-  if (dtype == GST_VULKAN_DISPLAY_TYPE_NONE)
-    return -1;
-
-#if GST_VULKAN_HAVE_WINDOW_X11
-  if ((dtype & GST_VULKAN_DISPLAY_TYPE_X11) == dtype)
-    ret = VK_PLATFORM_X11_KHR;
-#endif
-
-#if GST_VULKAN_HAVE_WINDOW_XCB
-  if ((dtype & GST_VULKAN_DISPLAY_TYPE_XCB) == dtype)
-    ret = VK_PLATFORM_XCB_KHR;
-#endif
-
-  return ret;
-}
-
-static gboolean
-_get_window_surface_description (GstVulkanSwapper * swapper,
-    VkSurfaceDescriptionWindowKHR * desc)
-{
-  GstVulkanDisplay *display = gst_vulkan_window_get_display (swapper->window);
-  GstVulkanDisplayType dtype = gst_vulkan_display_get_handle_type (display);
-
-  g_return_val_if_fail (desc != NULL, FALSE);
-
-  desc->sType = VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_KHR;
-  desc->pNext = NULL;
-  desc->platform = _gst_display_type_to_vk_platform (dtype);
-  if (desc->platform == -1) {
-    GST_ERROR_OBJECT (swapper, "Failed to retrieve platform from display");
-    gst_object_unref (display);
-    return FALSE;
-  }
-
-  desc->pPlatformHandle = gst_vulkan_display_get_platform_handle (display);
-  desc->pPlatformWindow =
-      gst_vulkan_window_get_platform_handle (swapper->window);
-
-  gst_object_unref (display);
-
-  /* XXX: might be a little too strict */
-  return desc->pPlatformHandle != NULL && desc->pPlatformWindow != NULL;
-}
-
 static GstVideoFormat
 _vk_format_to_video_format (VkFormat format)
 {
@@ -195,11 +147,22 @@ _add_vk_format_to_list (GValue * list, VkFormat format)
 }
 
 static gboolean
+_vulkan_swapper_ensure_surface (GstVulkanSwapper * swapper, GError ** error)
+{
+  if (!swapper->surface) {
+    if (!(swapper->surface =
+            gst_vulkan_window_get_surface (swapper->window, error))) {
+      return FALSE;
+    }
+  }
+
+  return TRUE;
+}
+
+static gboolean
 _vulkan_swapper_retrieve_surface_properties (GstVulkanSwapper * swapper,
     GError ** error)
 {
-  VkSurfaceDescriptionWindowKHR surface_desc;
-  VkDevice device = swapper->device->device;
   guint32 i, present_queue = -1, graphics_queue = -1;
   VkPhysicalDevice gpu;
   VkResult err;
@@ -207,23 +170,19 @@ _vulkan_swapper_retrieve_surface_properties (GstVulkanSwapper * swapper,
   if (swapper->surf_formats)
     return TRUE;
 
-  gpu = gst_vulkan_device_get_physical_device (swapper->device);
-
-  if (!_get_window_surface_description (swapper,
-          (VkSurfaceDescriptionWindowKHR *) & surface_desc)) {
-    g_set_error (error, GST_VULKAN_ERROR,
-        GST_VULKAN_ERROR_INITIALIZATION_FAILED,
-        "Failed to retrieve platform description");
+  if (!_vulkan_swapper_ensure_surface (swapper, error))
     return FALSE;
-  }
+
+  gpu = gst_vulkan_device_get_physical_device (swapper->device);
 
   for (i = 0; i < swapper->device->n_queues; i++) {
-    VkBool32 supports_present;
+    gboolean supports_present;
 
-    swapper->GetPhysicalDeviceSurfaceSupportKHR (gpu, i,
-        (VkSurfaceDescriptionKHR *) & surface_desc, &supports_present);
-    if ((swapper->device->queue_family_props[i].
-            queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) {
+    supports_present =
+        gst_vulkan_window_get_presentation_support (swapper->window,
+        swapper->device, i);
+    if ((swapper->device->
+            queue_family_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) {
       if (supports_present) {
         /* found one that supports both */
         graphics_queue = present_queue = i;
@@ -238,6 +197,7 @@ _vulkan_swapper_retrieve_surface_properties (GstVulkanSwapper * swapper,
   }
 
   if (graphics_queue != present_queue) {
+    /* FIXME: add support for separate graphics/present queues */
     g_set_error (error, GST_VULKAN_ERROR,
         GST_VULKAN_ERROR_INITIALIZATION_FAILED,
         "Failed to find a compatible present/graphics queue");
@@ -249,42 +209,41 @@ _vulkan_swapper_retrieve_surface_properties (GstVulkanSwapper * swapper,
     return FALSE;
 
   err =
-      swapper->GetSurfacePropertiesKHR (device,
-      (VkSurfaceDescriptionKHR *) & surface_desc, &swapper->surf_props);
-  if (gst_vulkan_error_to_g_error (err, error, "vkGetSurfacePropertiesKHR") < 0)
+      swapper->GetPhysicalDeviceSurfaceCapabilitiesKHR (gpu, swapper->surface,
+      &swapper->surf_props);
+  if (gst_vulkan_error_to_g_error (err, error,
+          "GetPhysicalDeviceSurfaceCapabilitiesKHR") < 0)
     return FALSE;
 
   err =
-      swapper->GetSurfaceFormatsKHR (device,
-      (VkSurfaceDescriptionKHR *) & surface_desc, &swapper->n_surf_formats,
-      NULL);
-  if (gst_vulkan_error_to_g_error (err, error, "vkGetSurfaceFormatsKHR") < 0)
+      swapper->GetPhysicalDeviceSurfaceFormatsKHR (gpu, swapper->surface,
+      &swapper->n_surf_formats, NULL);
+  if (gst_vulkan_error_to_g_error (err, error,
+          "GetPhysicalDeviceSurfaceFormatsKHR") < 0)
     return FALSE;
 
   swapper->surf_formats = g_new0 (VkSurfaceFormatKHR, swapper->n_surf_formats);
   err =
-      swapper->GetSurfaceFormatsKHR (device,
-      (VkSurfaceDescriptionKHR *) & surface_desc, &swapper->n_surf_formats,
-      swapper->surf_formats);
-  if (gst_vulkan_error_to_g_error (err, error, "vkGetSurfaceFormatsKHR") < 0)
+      swapper->GetPhysicalDeviceSurfaceFormatsKHR (gpu, swapper->surface,
+      &swapper->n_surf_formats, swapper->surf_formats);
+  if (gst_vulkan_error_to_g_error (err, error,
+          "GetPhysicalDeviceSurfaceFormatsKHR") < 0)
     return FALSE;
 
   err =
-      swapper->GetSurfacePresentModesKHR (device,
-      (VkSurfaceDescriptionKHR *) & surface_desc,
+      swapper->GetPhysicalDeviceSurfacePresentModesKHR (gpu, swapper->surface,
       &swapper->n_surf_present_modes, NULL);
   if (gst_vulkan_error_to_g_error (err, error,
-          "vkGetSurfacePresentModesKHR") < 0)
+          "GetPhysicalDeviceSurfacePresentModesKHR") < 0)
     return FALSE;
 
   swapper->surf_present_modes =
       g_new0 (VkPresentModeKHR, swapper->n_surf_present_modes);
   err =
-      swapper->GetSurfacePresentModesKHR (device,
-      (VkSurfaceDescriptionKHR *) & surface_desc,
+      swapper->GetPhysicalDeviceSurfacePresentModesKHR (gpu, swapper->surface,
       &swapper->n_surf_present_modes, swapper->surf_present_modes);
   if (gst_vulkan_error_to_g_error (err, error,
-          "vkGetSurfacePresentModesKHR") < 0)
+          "GetPhysicalDeviceSurfacePresentModesKHR") < 0)
     return FALSE;
 
   return TRUE;
@@ -313,9 +272,10 @@ gst_vulkan_swapper_finalize (GObject * object)
   }
   swapper->swap_chain_images = NULL;
 
-  if (swapper->swap_chain.handle)
-    swapper->DestroySwapchainKHR (swapper->device->device, swapper->swap_chain);
-  swapper->swap_chain.handle = 0;
+  if (swapper->swap_chain)
+    swapper->DestroySwapchainKHR (swapper->device->device, swapper->swap_chain,
+        NULL);
+  swapper->swap_chain = VK_NULL_HANDLE;
 
   if (swapper->queue)
     gst_object_unref (swapper->queue);
@@ -435,9 +395,9 @@ gst_vulkan_swapper_get_supported_caps (GstVulkanSwapper * swapper,
 }
 
 static gboolean
-_swapper_set_image_layout_with_cmd (GstVulkanSwapper * swapper, VkCmdBuffer cmd,
-    GstVulkanImageMemory * image, VkImageLayout new_image_layout,
-    GError ** error)
+_swapper_set_image_layout_with_cmd (GstVulkanSwapper * swapper,
+    VkCommandBuffer cmd, GstVulkanImageMemory * image,
+    VkImageLayout new_image_layout, GError ** error)
 {
   VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
   VkPipelineStageFlags dest_stages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
@@ -463,7 +423,7 @@ _new_fence (GstVulkanDevice * device, VkFence * fence, GError ** error)
   fence_info.pNext = NULL;
   fence_info.flags = 0;
 
-  err = vkCreateFence (device->device, &fence_info, fence);
+  err = vkCreateFence (device->device, &fence_info, NULL, fence);
   if (gst_vulkan_error_to_g_error (err, error, "vkCreateFence") < 0)
     return FALSE;
 
@@ -475,7 +435,7 @@ _swapper_set_image_layout (GstVulkanSwapper * swapper,
     GstVulkanImageMemory * image, VkImageLayout new_image_layout,
     GError ** error)
 {
-  VkCmdBuffer cmd;
+  VkCommandBuffer cmd;
   VkFence fence;
   VkResult err;
 
@@ -486,15 +446,17 @@ _swapper_set_image_layout (GstVulkanSwapper * swapper,
     return FALSE;
 
   {
-    VkCmdBufferBeginInfo cmd_buf_info = { 0, };
+    VkCommandBufferBeginInfo cmd_buf_info = { 0, };
 
-    cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
+    cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
     cmd_buf_info.pNext = NULL;
-    cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
-        VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
-    cmd_buf_info.renderPass.handle = VK_NULL_HANDLE;
+    cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
+    cmd_buf_info.renderPass = VK_NULL_HANDLE;
     cmd_buf_info.subpass = 0;
-    cmd_buf_info.framebuffer.handle = VK_NULL_HANDLE;
+    cmd_buf_info.framebuffer = VK_NULL_HANDLE;
+    cmd_buf_info.occlusionQueryEnable = FALSE;
+    cmd_buf_info.queryFlags = 0;
+    cmd_buf_info.pipelineStatistics = 0;
 
     err = vkBeginCommandBuffer (cmd, &cmd_buf_info);
     if (gst_vulkan_error_to_g_error (err, error, "vkBeginCommandBuffer") < 0)
@@ -509,16 +471,30 @@ _swapper_set_image_layout (GstVulkanSwapper * swapper,
   if (gst_vulkan_error_to_g_error (err, error, "vkEndCommandBuffer") < 0)
     return FALSE;
 
-  err = vkQueueSubmit (swapper->queue->queue, 1, &cmd, fence);
-  if (gst_vulkan_error_to_g_error (err, error, "vkQueueSubmit") < 0)
-    return FALSE;
+  {
+    VkSubmitInfo submit_info = { 0, };
+
+    submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
+    submit_info.pNext = NULL;
+    submit_info.waitSemaphoreCount = 0;
+    submit_info.pWaitSemaphores = NULL;
+    submit_info.commandBufferCount = 1;
+    submit_info.pCommandBuffers = &cmd;
+    submit_info.signalSemaphoreCount = 0;
+    submit_info.pSignalSemaphores = NULL;
+
+    err = vkQueueSubmit (swapper->queue->queue, 1, &submit_info, fence);
+    if (gst_vulkan_error_to_g_error (err, error, "vkQueueSubmit") < 0)
+      return FALSE;
+  }
 
   err = vkWaitForFences (swapper->device->device, 1, &fence, TRUE, -1);
   if (gst_vulkan_error_to_g_error (err, error, "vkWaitForFences") < 0)
     return FALSE;
-  vkDestroyCommandBuffer (swapper->device->device, cmd);
+  vkFreeCommandBuffers (swapper->device->device, swapper->device->cmd_pool, 1,
+      &cmd);
 
-  vkDestroyFence (swapper->device->device, fence);
+  vkDestroyFence (swapper->device->device, fence, NULL);
 
   return TRUE;
 }
@@ -528,28 +504,27 @@ _allocate_swapchain (GstVulkanSwapper * swapper, GstCaps * caps,
     GError ** error)
 {
   VkSurfaceTransformFlagsKHR preTransform;
-  VkSurfaceDescriptionWindowKHR surface_desc;
+  VkCompositeAlphaFlagsKHR alpha_flags;
   VkPresentModeKHR present_mode;
   VkImageUsageFlags usage = 0;
   VkColorSpaceKHR color_space;
   VkImage *swap_chain_images;
   VkExtent2D swapchain_dims;
   guint32 n_images_wanted;
+  VkPhysicalDevice gpu;
   VkFormat format;
   VkResult err;
   guint32 i;
 
-  if (!_get_window_surface_description (swapper, &surface_desc)) {
-    g_set_error (error, GST_VULKAN_ERROR,
-        GST_VULKAN_ERROR_INITIALIZATION_FAILED,
-        "Failed to retrieve platform description");
+  if (!_vulkan_swapper_ensure_surface (swapper, error))
     return FALSE;
-  }
 
+  gpu = gst_vulkan_device_get_physical_device (swapper->device);
   err =
-      swapper->GetSurfacePropertiesKHR (swapper->device->device,
-      (VkSurfaceDescriptionKHR *) & surface_desc, &swapper->surf_props);
-  if (gst_vulkan_error_to_g_error (err, error, "vkGetSurfacePropertiesKHR") < 0)
+      swapper->GetPhysicalDeviceSurfaceCapabilitiesKHR (gpu,
+      swapper->surface, &swapper->surf_props);
+  if (gst_vulkan_error_to_g_error (err, error,
+          "GetPhysicalDeviceSurfaceCapabilitiesKHR") < 0)
     return FALSE;
 
   /* width and height are either both -1, or both not -1. */
@@ -589,9 +564,9 @@ _allocate_swapchain (GstVulkanSwapper * swapper, GstCaps * caps,
     n_images_wanted = swapper->surf_props.maxImageCount;
   }
 
-  if (swapper->
-      surf_props.supportedTransforms & VK_SURFACE_TRANSFORM_NONE_BIT_KHR) {
-    preTransform = VK_SURFACE_TRANSFORM_NONE_KHR;
+  if (swapper->surf_props.
+      supportedTransforms & VK_SURFACE_TRANSFORM_NONE_BIT_KHR) {
+    preTransform = VK_SURFACE_TRANSFORM_NONE_BIT_KHR;
   } else {
     preTransform = swapper->surf_props.currentTransform;
   }
@@ -600,17 +575,38 @@ _allocate_swapchain (GstVulkanSwapper * swapper, GstCaps * caps,
       _vk_format_from_video_format (GST_VIDEO_INFO_FORMAT (&swapper->v_info));
   color_space = _vk_color_space_from_video_info (&swapper->v_info);
 
+#if 0
+  /* FIXME: unsupported by LunarG's driver */
+  g_print ("alpha flags 0x%x\n",
+      (guint) swapper->surf_props.supportedCompositeAlpha);
+
+  if ((swapper->surf_props.supportedCompositeAlpha &
+          VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR) != 0) {
+    alpha_flags = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
+  } else if ((swapper->surf_props.supportedCompositeAlpha &
+          VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR) != 0) {
+    alpha_flags = VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR;
+  } else {
+    g_set_error (error, GST_VULKAN_ERROR,
+        GST_VULKAN_ERROR_INITIALIZATION_FAILED,
+        "Incorrect alpha flags available for the swap images");
+    return FALSE;
+  }
+#else
+  alpha_flags = 0;
+#endif
+
   if ((swapper->surf_props.supportedUsageFlags &
-          VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT) != 0) {
-    usage |= VK_IMAGE_USAGE_TRANSFER_DESTINATION_BIT;
+          VK_IMAGE_USAGE_TRANSFER_DST_BIT) != 0) {
+    usage |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
   } else {
     g_set_error (error, GST_VULKAN_ERROR,
         GST_VULKAN_ERROR_INITIALIZATION_FAILED,
         "Incorrect usage flags available for the swap images");
     return FALSE;
   }
-  if ((swapper->surf_props.
-          supportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
+  if ((swapper->
+          surf_props.supportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
       != 0) {
     usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
   } else {
@@ -622,30 +618,38 @@ _allocate_swapchain (GstVulkanSwapper * swapper, GstCaps * caps,
 
   {
     VkSwapchainCreateInfoKHR swap_chain_info = { 0, };
+    VkSwapchainKHR old_swap_chain;
+
+    old_swap_chain = swapper->swap_chain;
 
     swap_chain_info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
     swap_chain_info.pNext = NULL;
-    swap_chain_info.pSurfaceDescription =
-        (const VkSurfaceDescriptionKHR *) &surface_desc;
+    swap_chain_info.surface = swapper->surface;
     swap_chain_info.minImageCount = n_images_wanted;
     swap_chain_info.imageFormat = format;
     swap_chain_info.imageColorSpace = color_space;
     swap_chain_info.imageExtent = swapchain_dims;
-    swap_chain_info.imageUsageFlags = usage;
-    swap_chain_info.preTransform = preTransform;
-    swap_chain_info.imageArraySize = 1;
-    swap_chain_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
-    swap_chain_info.queueFamilyCount = 0;
+    swap_chain_info.imageArrayLayers = 1;
+    swap_chain_info.imageUsage = usage;
+    swap_chain_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
+    swap_chain_info.queueFamilyIndexCount = 0;
     swap_chain_info.pQueueFamilyIndices = NULL;
+    swap_chain_info.preTransform = preTransform;
     swap_chain_info.presentMode = present_mode;
-    swap_chain_info.oldSwapchain = swapper->swap_chain;
+    swap_chain_info.compositeAlpha = alpha_flags;
     swap_chain_info.clipped = TRUE;
+    swap_chain_info.oldSwapchain = swapper->swap_chain;
 
     err =
         swapper->CreateSwapchainKHR (swapper->device->device, &swap_chain_info,
-        &swapper->swap_chain);
+        NULL, &swapper->swap_chain);
     if (gst_vulkan_error_to_g_error (err, error, "vkCreateSwapchainKHR") < 0)
       return FALSE;
+
+    if (old_swap_chain != VK_NULL_HANDLE) {
+      swapper->DestroySwapchainKHR (swapper->device->device, old_swap_chain,
+          NULL);
+    }
   }
 
   err =
@@ -722,7 +726,7 @@ gst_vulkan_swapper_set_caps (GstVulkanSwapper * swapper, GstCaps * caps,
 
 struct cmd_data
 {
-  VkCmdBuffer cmd;
+  VkCommandBuffer cmd;
   VkFence fence;
   GDestroyNotify notify;
   gpointer data;
@@ -732,24 +736,18 @@ static gboolean
 _build_render_buffer_cmd (GstVulkanSwapper * swapper, guint32 swap_idx,
     GstBuffer * buffer, struct cmd_data *cmd_data, GError ** error)
 {
-#define IMAGE_SUBRESOURCE(sub,a,m,l) \
-    G_STMT_START { \
-      sub.aspect = a; \
-      sub.mipLevel = m; \
-      sub.arrayLayer = l; \
-    } G_STMT_END
   VkImageSubresource subres = { 0, };
   GstVulkanImageMemory *swap_mem, *staging;
   GstMapInfo staging_map_info;
   VkSubresourceLayout layout;
   GstVideoFrame vframe;
   guint8 *src, *dest;
-  VkCmdBuffer cmd;
+  VkCommandBuffer cmd;
   guint32 wt, ht;
   VkResult err;
   gsize h;
 
-  IMAGE_SUBRESOURCE (subres, VK_IMAGE_ASPECT_COLOR, 0, 0);
+  GST_VK_IMAGE_SUBRESOURCE (subres, VK_IMAGE_ASPECT_COLOR_BIT, 0, 0);
 
   g_return_val_if_fail (swap_idx < swapper->n_swap_chain_images, FALSE);
   swap_mem = swapper->swap_chain_images[swap_idx];
@@ -767,7 +765,7 @@ _build_render_buffer_cmd (GstVulkanSwapper * swapper, guint32 swap_idx,
       (GstVulkanImageMemory *) gst_vulkan_image_memory_alloc (swapper->device,
       swap_mem->create_info.format, GST_VIDEO_FRAME_COMP_WIDTH (&vframe, 0),
       GST_VIDEO_FRAME_COMP_HEIGHT (&vframe, 0), VK_IMAGE_TILING_LINEAR,
-      VK_IMAGE_USAGE_TRANSFER_SOURCE_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
+      VK_IMAGE_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
 
   if (!staging) {
     g_set_error (error, GST_VULKAN_ERROR, GST_VULKAN_ERROR_MEMORY_MAP_FAILED,
@@ -784,15 +782,8 @@ _build_render_buffer_cmd (GstVulkanSwapper * swapper, guint32 swap_idx,
     return FALSE;
   }
 
-  err = vkGetImageSubresourceLayout (swapper->device->device, staging->image,
-      &subres, &layout);
-  if (gst_vulkan_error_to_g_error (err, error,
-          "vkGetImageSubresourceLayout") < 0) {
-    gst_video_frame_unmap (&vframe);
-    gst_memory_unmap ((GstMemory *) staging, &staging_map_info);
-    gst_memory_unref ((GstMemory *) staging);
-    return FALSE;
-  }
+  vkGetImageSubresourceLayout (swapper->device->device, staging->image, &subres,
+      &layout);
 
   /* FIXME: multi-planar formats */
   dest = staging_map_info.data;
@@ -809,15 +800,17 @@ _build_render_buffer_cmd (GstVulkanSwapper * swapper, guint32 swap_idx,
   gst_memory_unmap ((GstMemory *) staging, &staging_map_info);
 
   {
-    VkCmdBufferBeginInfo cmd_buf_info = { 0, };
+    VkCommandBufferBeginInfo cmd_buf_info = { 0, };
 
-    cmd_buf_info.sType = VK_STRUCTURE_TYPE_CMD_BUFFER_BEGIN_INFO;
+    cmd_buf_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
     cmd_buf_info.pNext = NULL;
-    cmd_buf_info.flags = VK_CMD_BUFFER_OPTIMIZE_SMALL_BATCH_BIT |
-        VK_CMD_BUFFER_OPTIMIZE_ONE_TIME_SUBMIT_BIT;
-    cmd_buf_info.renderPass.handle = VK_NULL_HANDLE;
+    cmd_buf_info.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
+    cmd_buf_info.renderPass = VK_NULL_HANDLE;
     cmd_buf_info.subpass = 0;
-    cmd_buf_info.framebuffer.handle = VK_NULL_HANDLE;
+    cmd_buf_info.framebuffer = VK_NULL_HANDLE;
+    cmd_buf_info.occlusionQueryEnable = FALSE;
+    cmd_buf_info.queryFlags = 0;
+    cmd_buf_info.pipelineStatistics = 0;
 
     err = vkBeginCommandBuffer (cmd, &cmd_buf_info);
     if (gst_vulkan_error_to_g_error (err, error, "vkBeginCommandBuffer") < 0)
@@ -825,33 +818,14 @@ _build_render_buffer_cmd (GstVulkanSwapper * swapper, guint32 swap_idx,
   }
 
   if (!_swapper_set_image_layout_with_cmd (swapper, cmd, swap_mem,
-          VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL, error)) {
+          VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, error)) {
     return FALSE;
   }
 
   if (!_swapper_set_image_layout_with_cmd (swapper, cmd, staging,
-          VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, error)) {
+          VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, error)) {
     return FALSE;
   }
-#define SUBRESOURCE_COPY(res,aspect_,mip,layer,size) \
-  G_STMT_START { \
-    res.aspect = aspect_; \
-    res.mipLevel = mip; \
-    res.arrayLayer = layer; \
-    res.arraySize = size; \
-  } G_STMT_END
-#define OFFSET3D(offset,x_,y_,z_) \
-  G_STMT_START { \
-    offset.x = x_; \
-    offset.y = y_; \
-    offset.z = z_; \
-  } G_STMT_END
-#define EXTENT3D(extent,w,h,d) \
-  G_STMT_START { \
-    extent.width = w; \
-    extent.height = h; \
-    extent.depth = d; \
-  } G_STMT_END
 
   /* FIXME: center rect */
 #if 0
@@ -860,20 +834,21 @@ _build_render_buffer_cmd (GstVulkanSwapper * swapper, guint32 swap_idx,
   {
     VkImageBlit blit_image = { 0, };
 
-    SUBRESOURCE_COPY (blit_image.srcSubresource, VK_IMAGE_ASPECT_COLOR, 0, 0,
-        1);
-    OFFSET3D (blit_image.srcOffset, 0, 0, 0);
-    EXTENT3D (blit_image.extent, GST_VIDEO_INFO_WIDTH (&swapper->v_info),
+    GST_VK_IMAGE_SUBRESOURCE_LAYERS (blit_image.srcSubresource,
+        VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1);
+    GST_VK_OFFSET3D (blit_image.srcOffset, 0, 0, 0);
+    GST_VK_EXTENT3D (blit_image.srcExtent,
+        GST_VIDEO_INFO_WIDTH (&swapper->v_info),
         GST_VIDEO_INFO_HEIGHT (&swapper->v_info), 1);
-    SUBRESOURCE_COPY (blit_image.destSubresource, VK_IMAGE_ASPECT_COLOR, 0, 0,
-        1);
-    OFFSET3D (blit_image.destOffset, 0, 0, 0);
-    EXTENT3D (blit_image.extent, swap_mem->create_info.extent.width,
+    GST_VK_IMAGE_SUBRESOURCE_LAYERS (blit_image.dstSubresource,
+        VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1);
+    GST_VK_OFFSET3D (blit_image.dstOffset, 0, 0, 0);
+    GST_VK_EXTENT3D (blit_image.dstExtent, swap_mem->create_info.extent.width,
         swap_mem->create_info.extent.height, 1);
 
     /* FIXME: copy */
     vkCmdBlitImage (cmd, staging->image,
-        VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, swap_mem->image,
+        VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, swap_mem->image,
         VK_IMAGE_LAYOUT_GENERAL, 1, &blit_image, VK_TEX_FILTER_LINEAR);
   }
 #else
@@ -885,23 +860,23 @@ _build_render_buffer_cmd (GstVulkanSwapper * swapper, guint32 swap_idx,
   {
     VkImageCopy copy_image = { 0, };
 
-    SUBRESOURCE_COPY (copy_image.srcSubresource, VK_IMAGE_ASPECT_COLOR, 0, 0,
-        1);
-    OFFSET3D (copy_image.srcOffset, 0, 0, 0);
-    SUBRESOURCE_COPY (copy_image.destSubresource, VK_IMAGE_ASPECT_COLOR, 0, 0,
-        1);
-    OFFSET3D (copy_image.destOffset, 0, 0, 0);
-    EXTENT3D (copy_image.extent, wt, ht, 1);
+    GST_VK_IMAGE_SUBRESOURCE_LAYERS (copy_image.srcSubresource,
+        VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1);
+    GST_VK_OFFSET3D (copy_image.srcOffset, 0, 0, 0);
+    GST_VK_IMAGE_SUBRESOURCE_LAYERS (copy_image.dstSubresource,
+        VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1);
+    GST_VK_OFFSET3D (copy_image.dstOffset, 0, 0, 0);
+    GST_VK_EXTENT3D (copy_image.extent, wt, ht, 1);
 
     /* FIXME: copy */
     vkCmdCopyImage (cmd, staging->image,
-        VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL, swap_mem->image,
+        VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, swap_mem->image,
         VK_IMAGE_LAYOUT_GENERAL, 1, &copy_image);
   }
 #endif
 
   if (!_swapper_set_image_layout_with_cmd (swapper, cmd, staging,
-          VK_IMAGE_LAYOUT_PRESENT_SOURCE_KHR, error)) {
+          VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, error)) {
     return FALSE;
   }
 
@@ -917,12 +892,6 @@ _build_render_buffer_cmd (GstVulkanSwapper * swapper, guint32 swap_idx,
     return FALSE;
   }
 
-  err =
-      vkQueueSubmit (swapper->queue->queue, 1, &cmd_data->cmd, cmd_data->fence);
-  if (gst_vulkan_error_to_g_error (err, error, "vkQueueSubmit") < 0) {
-    return FALSE;
-  }
-
   return TRUE;
 }
 
@@ -935,7 +904,7 @@ _render_buffer_unlocked (GstVulkanSwapper * swapper,
   VkPresentInfoKHR present;
   struct cmd_data cmd_data = { 0, };
   guint32 swap_idx;
-  VkResult err;
+  VkResult err, present_err;
 
   semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
   semaphore_info.pNext = NULL;
@@ -957,18 +926,18 @@ _render_buffer_unlocked (GstVulkanSwapper * swapper,
 
 reacquire:
   err = vkCreateSemaphore (swapper->device->device, &semaphore_info,
-      &semaphore);
+      NULL, &semaphore);
   if (gst_vulkan_error_to_g_error (err, error, "vkCreateSemaphore") < 0)
     goto error;
 
   err =
       swapper->AcquireNextImageKHR (swapper->device->device,
-      swapper->swap_chain, -1, semaphore, &swap_idx);
+      swapper->swap_chain, -1, semaphore, VK_NULL_HANDLE, &swap_idx);
   /* TODO: Deal with the VK_SUBOPTIMAL_KHR and VK_ERROR_OUT_OF_DATE_KHR */
   if (err == VK_ERROR_OUT_OF_DATE_KHR) {
     GST_DEBUG_OBJECT (swapper, "out of date frame acquired");
 
-    vkDestroySemaphore (swapper->device->device, semaphore);
+    vkDestroySemaphore (swapper->device->device, semaphore, NULL);
     if (!_swapchain_resize (swapper, error))
       goto error;
     goto reacquire;
@@ -980,13 +949,33 @@ reacquire:
   if (!_build_render_buffer_cmd (swapper, swap_idx, buffer, &cmd_data, error))
     goto error;
 
-  vkQueueWaitSemaphore (swapper->queue->queue, semaphore);
+  {
+    VkSubmitInfo submit_info = { 0, };
+
+    submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
+    submit_info.pNext = NULL;
+    submit_info.waitSemaphoreCount = 1;
+    submit_info.pWaitSemaphores = &semaphore;
+    submit_info.commandBufferCount = 1;
+    submit_info.pCommandBuffers = &cmd_data.cmd;
+    submit_info.signalSemaphoreCount = 0;
+    submit_info.pSignalSemaphores = NULL;
+
+    err =
+        vkQueueSubmit (swapper->queue->queue, 1, &submit_info, cmd_data.fence);
+    if (gst_vulkan_error_to_g_error (err, error, "vkQueueSubmit") < 0) {
+      return FALSE;
+    }
+  }
 
   present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
   present.pNext = NULL;
+  present.waitSemaphoreCount = 1;
+  present.pWaitSemaphores = &semaphore;
   present.swapchainCount = 1;
-  present.swapchains = &swapper->swap_chain;
-  present.imageIndices = &swap_idx;
+  present.pSwapchains = &swapper->swap_chain;
+  present.pImageIndices = &swap_idx;
+  present.pResults = &present_err;
 
   err = swapper->QueuePresentKHR (swapper->queue->queue, &present);
   if (err == VK_ERROR_OUT_OF_DATE_KHR) {
@@ -995,16 +984,17 @@ reacquire:
     if (!_swapchain_resize (swapper, error))
       goto error;
 
-    vkDestroySemaphore (swapper->device->device, semaphore);
+    vkDestroySemaphore (swapper->device->device, semaphore, NULL);
     if (cmd_data.cmd)
-      vkDestroyCommandBuffer (swapper->device->device, cmd_data.cmd);
-    cmd_data.cmd = NULL;
-    if (cmd_data.fence.handle)
-      vkDestroyFence (swapper->device->device, cmd_data.fence);
-    cmd_data.fence.handle = 0;
+      vkFreeCommandBuffers (swapper->device->device, swapper->device->cmd_pool,
+          1, &cmd_data.cmd);
+    cmd_data.cmd = VK_NULL_HANDLE;
+    if (cmd_data.fence)
+      vkDestroyFence (swapper->device->device, cmd_data.fence, NULL);
+    cmd_data.fence = VK_NULL_HANDLE;
     if (cmd_data.notify)
       cmd_data.notify (cmd_data.data);
-    cmd_data.notify = NULL;
+    cmd_data.notify = VK_NULL_HANDLE;
 
     goto reacquire;
   } else if (gst_vulkan_error_to_g_error (err, error, "vkQueuePresentKHR") < 0)
@@ -1014,24 +1004,26 @@ reacquire:
   if (gst_vulkan_error_to_g_error (err, error, "vkWaitForFences") < 0)
     goto error;
 
-  if (semaphore.handle)
-    vkDestroySemaphore (swapper->device->device, semaphore);
+  if (semaphore)
+    vkDestroySemaphore (swapper->device->device, semaphore, NULL);
   if (cmd_data.cmd)
-    vkDestroyCommandBuffer (swapper->device->device, cmd_data.cmd);
-  if (cmd_data.fence.handle)
-    vkDestroyFence (swapper->device->device, cmd_data.fence);
+    vkFreeCommandBuffers (swapper->device->device, swapper->device->cmd_pool,
+        1, &cmd_data.cmd);
+  if (cmd_data.fence)
+    vkDestroyFence (swapper->device->device, cmd_data.fence, NULL);
   if (cmd_data.notify)
     cmd_data.notify (cmd_data.data);
   return TRUE;
 
 error:
   {
-    if (semaphore.handle)
-      vkDestroySemaphore (swapper->device->device, semaphore);
+    if (semaphore)
+      vkDestroySemaphore (swapper->device->device, semaphore, NULL);
     if (cmd_data.cmd)
-      vkDestroyCommandBuffer (swapper->device->device, cmd_data.cmd);
-    if (cmd_data.fence.handle)
-      vkDestroyFence (swapper->device->device, cmd_data.fence);
+      vkFreeCommandBuffers (swapper->device->device, swapper->device->cmd_pool,
+          1, &cmd_data.cmd);
+    if (cmd_data.fence)
+      vkDestroyFence (swapper->device->device, cmd_data.fence, NULL);
     if (cmd_data.notify)
       cmd_data.notify (cmd_data.data);
     return FALSE;
index 043c0a2..1ffb493 100644 (file)
@@ -24,8 +24,6 @@
 #include <gst/video/video.h>
 
 #include <vk.h>
-#include <vulkan/vk_ext_khr_swapchain.h>
-#include <vulkan/vk_ext_khr_device_swapchain.h>
 
 G_BEGIN_DECLS
 
@@ -45,7 +43,9 @@ struct _GstVulkanSwapper
   GstVulkanWindow *window;
   GstVulkanQueue *queue;
 
-  VkSurfacePropertiesKHR surf_props;
+  VkSurfaceKHR    surface;
+
+  VkSurfaceCapabilitiesKHR surf_props;
   VkSurfaceFormatKHR *surf_formats;
   guint32 n_surf_formats;
   VkPresentModeKHR *surf_present_modes;
@@ -59,9 +59,9 @@ struct _GstVulkanSwapper
   GstVideoInfo v_info;
 
   PFN_vkGetPhysicalDeviceSurfaceSupportKHR GetPhysicalDeviceSurfaceSupportKHR;
-  PFN_vkGetSurfacePropertiesKHR GetSurfacePropertiesKHR;
-  PFN_vkGetSurfaceFormatsKHR GetSurfaceFormatsKHR;
-  PFN_vkGetSurfacePresentModesKHR GetSurfacePresentModesKHR;
+  PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR GetPhysicalDeviceSurfaceCapabilitiesKHR;
+  PFN_vkGetPhysicalDeviceSurfaceFormatsKHR GetPhysicalDeviceSurfaceFormatsKHR;
+  PFN_vkGetPhysicalDeviceSurfacePresentModesKHR GetPhysicalDeviceSurfacePresentModesKHR;
   PFN_vkCreateSwapchainKHR CreateSwapchainKHR;
   PFN_vkDestroySwapchainKHR DestroySwapchainKHR;
   PFN_vkGetSwapchainImagesKHR GetSwapchainImagesKHR;
index e83a91e..c9652be 100644 (file)
@@ -194,35 +194,38 @@ gst_vulkan_ensure_element_data (gpointer element,
   /*  1) Check if the element already has a context of the specific
    *     type.
    */
-  if (!*display_ptr) {
-    _vk_display_context_query (element, display_ptr);
+  if (!*instance_ptr) {
+    _vk_gst_context_query (element, GST_VULKAN_INSTANCE_CONTEXT_TYPE_STR);
 
     /* Neighbour found and it updated the display */
-    if (!*display_ptr) {
+    if (!*instance_ptr) {
       GstContext *context;
 
       /* If no neighboor, or application not interested, use system default */
-      *display_ptr = gst_vulkan_display_new ();
+      *instance_ptr = gst_vulkan_instance_new ();
 
-      context = gst_context_new (GST_VULKAN_DISPLAY_CONTEXT_TYPE_STR, TRUE);
-      gst_context_set_vulkan_display (context, *display_ptr);
+      context = gst_context_new (GST_VULKAN_INSTANCE_CONTEXT_TYPE_STR, TRUE);
+      gst_context_set_vulkan_instance (context, *instance_ptr);
 
       _vk_context_propagate (element, context);
     }
   }
 
-  if (!*instance_ptr) {
-    _vk_gst_context_query (element, GST_VULKAN_INSTANCE_CONTEXT_TYPE_STR);
+  if (!*display_ptr) {
+    _vk_display_context_query (element, display_ptr);
 
     /* Neighbour found and it updated the display */
-    if (!*instance_ptr) {
+    if (!*display_ptr) {
       GstContext *context;
 
+      /* instance is required before the display */
+      g_return_val_if_fail (*instance_ptr != NULL, FALSE);
+
       /* If no neighboor, or application not interested, use system default */
-      *instance_ptr = gst_vulkan_instance_new ();
+      *display_ptr = gst_vulkan_display_new (*instance_ptr);
 
-      context = gst_context_new (GST_VULKAN_INSTANCE_CONTEXT_TYPE_STR, TRUE);
-      gst_context_set_vulkan_instance (context, *instance_ptr);
+      context = gst_context_new (GST_VULKAN_DISPLAY_CONTEXT_TYPE_STR, TRUE);
+      gst_context_set_vulkan_display (context, *display_ptr);
 
       _vk_context_propagate (element, context);
     }
index 83e3b4d..caa3c47 100644 (file)
@@ -214,16 +214,29 @@ gst_vulkan_window_get_display (GstVulkanWindow * window)
   return gst_object_ref (window->display);
 }
 
-gpointer
-gst_vulkan_window_get_platform_handle (GstVulkanWindow * window)
+VkSurfaceKHR
+gst_vulkan_window_get_surface (GstVulkanWindow * window, GError ** error)
 {
   GstVulkanWindowClass *klass;
 
   g_return_val_if_fail (GST_IS_VULKAN_WINDOW (window), NULL);
   klass = GST_VULKAN_WINDOW_GET_CLASS (window);
-  g_return_val_if_fail (klass->get_platform_handle != NULL, NULL);
+  g_return_val_if_fail (klass->get_surface != NULL, NULL);
 
-  return klass->get_platform_handle (window);
+  return klass->get_surface (window, error);
+}
+
+gboolean
+gst_vulkan_window_get_presentation_support (GstVulkanWindow * window,
+    GstVulkanDevice * device, guint32 queue_family_idx)
+{
+  GstVulkanWindowClass *klass;
+
+  g_return_val_if_fail (GST_IS_VULKAN_WINDOW (window), FALSE);
+  klass = GST_VULKAN_WINDOW_GET_CLASS (window);
+  g_return_val_if_fail (klass->get_presentation_support != NULL, FALSE);
+
+  return klass->get_presentation_support (window, device, queue_family_idx);
 }
 
 gboolean
index 8dd7c4e..58be80a 100644 (file)
@@ -78,25 +78,37 @@ struct _GstVulkanWindow {
 struct _GstVulkanWindowClass {
   GstObjectClass parent_class;
 
-  gboolean (*open)               (GstVulkanWindow *window, GError **error);
-  void     (*close)              (GstVulkanWindow *window);
+  gboolean      (*open)                         (GstVulkanWindow *window,
+                                                 GError **error);
+  void          (*close)                        (GstVulkanWindow *window);
 
-  gpointer (*get_platform_handle) (GstVulkanWindow *window);
+  VkSurfaceKHR  (*get_surface)                  (GstVulkanWindow *window,
+                                                 GError **error);
+  gboolean      (*get_presentation_support)     (GstVulkanWindow *window,
+                                                 GstVulkanDevice *device,
+                                                 guint32 queue_family_idx);
 
   /*< private >*/
   gpointer _reserved[GST_PADDING];
 };
 
-GstVulkanWindow *  gst_vulkan_window_new                    (GstVulkanDisplay *display);
+GstVulkanWindow *  gst_vulkan_window_new                            (GstVulkanDisplay *display);
 
-GstVulkanDisplay * gst_vulkan_window_get_display            (GstVulkanWindow *window);
-gpointer           gst_vulkan_window_get_platform_handle    (GstVulkanWindow *window);
+GstVulkanDisplay * gst_vulkan_window_get_display                    (GstVulkanWindow *window);
+VkSurfaceKHR       gst_vulkan_window_get_surface                    (GstVulkanWindow *window,
+                                                                     GError **error);
+gboolean           gst_vulkan_window_get_presentation_support       (GstVulkanWindow *window,
+                                                                     GstVulkanDevice *device,
+                                                                     guint32 queue_family_idx);
 
-gboolean           gst_vulkan_window_open                   (GstVulkanWindow * window, GError ** error);
-void               gst_vulkan_window_close                  (GstVulkanWindow * window);
+gboolean           gst_vulkan_window_open                           (GstVulkanWindow *window,
+                                                                     GError ** error);
+void               gst_vulkan_window_close                          (GstVulkanWindow *window);
 
-void               gst_vulkan_window_resize                 (GstVulkanWindow * window, gint width, gint height);
-void               gst_vulkan_window_redraw                 (GstVulkanWindow * window);
+void               gst_vulkan_window_resize                         (GstVulkanWindow *window,
+                                                                     gint width,
+                                                                     gint height);
+void               gst_vulkan_window_redraw                         (GstVulkanWindow *window);
 
 G_END_DECLS
 
index c1d761c..763f5d5 100644 (file)
@@ -33,16 +33,12 @@ G_DEFINE_TYPE (GstVulkanDisplayXCB, gst_vulkan_display_xcb,
 
 static void gst_vulkan_display_xcb_finalize (GObject * object);
 static gpointer gst_vulkan_display_xcb_get_handle (GstVulkanDisplay * display);
-static gpointer gst_vulkan_display_xcb_get_platform_handle (GstVulkanDisplay *
-    display);
 
 static void
 gst_vulkan_display_xcb_class_init (GstVulkanDisplayXCBClass * klass)
 {
   GST_VULKAN_DISPLAY_CLASS (klass)->get_handle =
       GST_DEBUG_FUNCPTR (gst_vulkan_display_xcb_get_handle);
-  GST_VULKAN_DISPLAY_CLASS (klass)->get_platform_handle =
-      GST_DEBUG_FUNCPTR (gst_vulkan_display_xcb_get_platform_handle);
 
   G_OBJECT_CLASS (klass)->finalize = gst_vulkan_display_xcb_finalize;
 }
@@ -63,9 +59,9 @@ gst_vulkan_display_xcb_finalize (GObject * object)
 
   G_OBJECT_CLASS (gst_vulkan_display_xcb_parent_class)->finalize (object);
 
-  if (!display_xcb->foreign_display && display_xcb->platform_handle.connection)
-    xcb_disconnect (display_xcb->platform_handle.connection);
-  display_xcb->platform_handle.connection = NULL;
+  if (!display_xcb->foreign_display && display_xcb->connection)
+    xcb_disconnect (display_xcb->connection);
+  display_xcb->connection = NULL;
 }
 
 static xcb_screen_t *
@@ -135,9 +131,9 @@ gst_vulkan_display_xcb_new_with_connection (xcb_connection_t * connection,
 
   ret = g_object_new (GST_TYPE_VULKAN_DISPLAY_XCB, NULL);
 
-  ret->platform_handle.connection = connection;
+  ret->connection = connection;
   ret->screen = _get_screen_from_connection (connection, screen_no);
-  ret->platform_handle.root = ret->screen->root;
+  ret->root_window = ret->screen->root;
   ret->foreign_display = TRUE;
 
   return ret;
@@ -146,12 +142,5 @@ gst_vulkan_display_xcb_new_with_connection (xcb_connection_t * connection,
 static gpointer
 gst_vulkan_display_xcb_get_handle (GstVulkanDisplay * display)
 {
-  return (gpointer) GST_VULKAN_DISPLAY_XCB (display)->platform_handle.
-      connection;
-}
-
-static gpointer
-gst_vulkan_display_xcb_get_platform_handle (GstVulkanDisplay * display)
-{
-  return &GST_VULKAN_DISPLAY_XCB (display)->platform_handle;
+  return (gpointer) GST_VULKAN_DISPLAY_XCB_CONNECTION (display);
 }
index 8770b0a..7c0f1ec 100644 (file)
 #include <xcb/xcb.h>
 
 #include <vk.h>
+#ifndef VK_USE_PLATFORM_XCB_KHR
+#error "VK_USE_PLATFORM_XCB_KHR not defined before including this header"
+#error "Either include vkapi.h or define VK_USE_PLATFORM_XCB_KHR before including this header"
+#endif
+#include <vulkan/vulkan.h>
 
 G_BEGIN_DECLS
 
@@ -41,16 +46,10 @@ GType gst_vulkan_display_xcb_get_type (void);
 typedef struct _GstVulkanDisplayXCB GstVulkanDisplayXCB;
 typedef struct _GstVulkanDisplayXCBClass GstVulkanDisplayXCBClass;
 
-#define GST_VULKAN_DISPLAY_XCB_CONNECTION(d) (GST_VULKAN_DISPLAY_XCB(d)->platform_handle.connection)
-#define GST_VULKAN_DISPLAY_XCB_ROOT_WINDOW(d) (GST_VULKAN_DISPLAY_XCB(d)->platform_handle.root)
+#define GST_VULKAN_DISPLAY_XCB_CONNECTION(d) (GST_VULKAN_DISPLAY_XCB(d)->connection)
+#define GST_VULKAN_DISPLAY_XCB_ROOT_WINDOW(d) (GST_VULKAN_DISPLAY_XCB(d)->root_window)
 #define GST_VULKAN_DISPLAY_XCB_SCREEN(d) (GST_VULKAN_DISPLAY_XCB(d)->screen)
 
-struct _GstVkPlatformHandleXCBKHR
-{
-  xcb_connection_t* connection;
-  xcb_window_t      root;
-};
-
 /**
  * GstVulkanDisplayXCB:
  *
@@ -61,12 +60,13 @@ struct _GstVulkanDisplayXCB
 {
   GstVulkanDisplay          parent;
 
+  xcb_connection_t *connection;
+  xcb_window_t      root_window;
+  xcb_screen_t     *screen;
+
   /* <private> */
   gboolean foreign_display;
 
-  struct _GstVkPlatformHandleXCBKHR platform_handle;
-  xcb_screen_t *screen;
-
   GSource *event_source;
 };
 
index 9576a7e..686c715 100644 (file)
@@ -68,10 +68,13 @@ struct _GstVulkanWindowXCBPrivate
   xcb_intern_atom_reply_t *atom_wm_delete_window;
 };
 
-static gpointer gst_vulkan_window_xcb_get_platform_window (GstVulkanWindow *
-    window);
-gboolean gst_vulkan_window_xcb_open (GstVulkanWindow * window, GError ** error);
-void gst_vulkan_window_xcb_close (GstVulkanWindow * window);
+static VkSurfaceKHR gst_vulkan_window_xcb_get_surface (GstVulkanWindow * window,
+    GError ** error);
+static gboolean gst_vulkan_window_xcb_get_presentation_support (GstVulkanWindow
+    * window, GstVulkanDevice * device, guint32 queue_family_idx);
+static gboolean gst_vulkan_window_xcb_open (GstVulkanWindow * window,
+    GError ** error);
+static void gst_vulkan_window_xcb_close (GstVulkanWindow * window);
 
 static void
 gst_vulkan_window_xcb_finalize (GObject * object)
@@ -91,7 +94,9 @@ gst_vulkan_window_xcb_class_init (GstVulkanWindowXCBClass * klass)
 
   window_class->open = GST_DEBUG_FUNCPTR (gst_vulkan_window_xcb_open);
   window_class->close = GST_DEBUG_FUNCPTR (gst_vulkan_window_xcb_close);
-  window_class->get_platform_handle = gst_vulkan_window_xcb_get_platform_window;
+  window_class->get_surface = gst_vulkan_window_xcb_get_surface;
+  window_class->get_presentation_support =
+      gst_vulkan_window_xcb_get_presentation_support;
 }
 
 static void
@@ -122,7 +127,8 @@ gst_vulkan_window_xcb_show (GstVulkanWindow * window)
 {
   GstVulkanWindowXCB *window_xcb = GST_VULKAN_WINDOW_XCB (window);
   GstVulkanDisplayXCB *display_xcb = GST_VULKAN_DISPLAY_XCB (window->display);
-  xcb_connection_t *connection = display_xcb->platform_handle.connection;
+  xcb_connection_t *connection =
+      GST_VULKAN_DISPLAY_XCB_CONNECTION (display_xcb);
 
   if (!window_xcb->visible) {
     xcb_map_window (connection, window_xcb->win_id);
@@ -135,7 +141,8 @@ gst_vulkan_window_xcb_hide (GstVulkanWindow * window)
 {
   GstVulkanWindowXCB *window_xcb = GST_VULKAN_WINDOW_XCB (window);
   GstVulkanDisplayXCB *display_xcb = GST_VULKAN_DISPLAY_XCB (window->display);
-  xcb_connection_t *connection = display_xcb->platform_handle.connection;
+  xcb_connection_t *connection =
+      GST_VULKAN_DISPLAY_XCB_CONNECTION (display_xcb);
 
   if (window_xcb->visible) {
     xcb_unmap_window (connection, window_xcb->win_id);
@@ -195,20 +202,46 @@ gst_vulkan_window_xcb_create_window (GstVulkanWindowXCB * window_xcb)
   return TRUE;
 }
 
-static gpointer
-gst_vulkan_window_xcb_get_platform_window (GstVulkanWindow * window)
+static VkSurfaceKHR
+gst_vulkan_window_xcb_get_surface (GstVulkanWindow * window, GError ** error)
 {
-  return &GST_VULKAN_WINDOW_XCB (window)->win_id;
+  VkSurfaceKHR ret;
+  VkResult err;
+
+  err = vkCreateXcbSurfaceKHR (window->display->instance->instance,
+      GST_VULKAN_DISPLAY_XCB_CONNECTION (window->display),
+      GST_VULKAN_WINDOW_XCB (window)->win_id, NULL, &ret);
+  if (gst_vulkan_error_to_g_error (err, error, "vkCreateXcbSurfaceKHR") < 0)
+    return NULL;
+
+  return ret;
 }
 
-gboolean
+static gboolean
+gst_vulkan_window_xcb_get_presentation_support (GstVulkanWindow * window,
+    GstVulkanDevice * device, guint32 queue_family_idx)
+{
+  VkPhysicalDevice gpu;
+  xcb_screen_t *screen;
+
+  screen = GST_VULKAN_DISPLAY_XCB_SCREEN (window->display);
+
+  gpu = gst_vulkan_device_get_physical_device (device);
+  if (vkGetPhysicalDeviceXcbPresentationSupportKHR (gpu, queue_family_idx,
+          GST_VULKAN_DISPLAY_XCB_CONNECTION (window->display),
+          screen->root_visual))
+    return TRUE;
+  return FALSE;
+}
+
+static gboolean
 gst_vulkan_window_xcb_open (GstVulkanWindow * window, GError ** error)
 {
   GstVulkanWindowXCB *window_xcb = GST_VULKAN_WINDOW_XCB (window);
   GstVulkanDisplayXCB *display_xcb = (GstVulkanDisplayXCB *) window->display;
   xcb_connection_t *connection;
 
-  connection = display_xcb->platform_handle.connection;
+  connection = GST_VULKAN_DISPLAY_XCB_CONNECTION (display_xcb);
   if (connection == NULL) {
     g_set_error (error, GST_VULKAN_WINDOW_ERROR,
         GST_VULKAN_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
@@ -225,7 +258,7 @@ failure:
   return FALSE;
 }
 
-void
+static void
 gst_vulkan_window_xcb_close (GstVulkanWindow * window)
 {
   GstVulkanWindowXCB *window_xcb = GST_VULKAN_WINDOW_XCB (window);
index fc9c70d..517a488 100644 (file)
@@ -76,9 +76,6 @@ GType gst_vulkan_window_xcb_get_type     (void);
 
 GstVulkanWindowXCB * gst_vulkan_window_xcb_new (GstVulkanDisplay * display);
 
-void gst_vulkan_window_xcb_trap_x_errors (void);
-gint gst_vulkan_window_xcb_untrap_x_errors (void);
-
 gboolean gst_vulkan_window_xcb_create_window (GstVulkanWindowXCB * window_xcb);
 
 G_END_DECLS