vkswapper: iterate over the device queue's using the new iteration API

This commit is contained in:
Matthew Waters 2016-02-16 11:51:28 +11:00
parent ca8f2b0826
commit a3aa0d11ec

View file

@ -159,11 +159,50 @@ _vulkan_swapper_ensure_surface (GstVulkanSwapper * swapper, GError ** error)
return TRUE; return TRUE;
} }
struct choose_data
{
GstVulkanSwapper *swapper;
GstVulkanQueue *graphics_queue;
GstVulkanQueue *present_queue;
};
static gboolean
_choose_queue (GstVulkanDevice * device, GstVulkanQueue * queue,
struct choose_data *data)
{
guint flags = device->queue_family_props[queue->family].queueFlags;
gboolean supports_present;
supports_present =
gst_vulkan_window_get_presentation_support (data->swapper->window,
device, queue->index);
if ((flags & VK_QUEUE_GRAPHICS_BIT) != 0) {
if (supports_present) {
/* found one that supports both */
if (data->graphics_queue)
gst_object_unref (data->graphics_queue);
data->graphics_queue = gst_object_ref (queue);
if (data->present_queue)
gst_object_unref (data->present_queue);
data->present_queue = gst_object_ref (queue);
return FALSE;
}
if (!data->graphics_queue)
data->present_queue = gst_object_ref (queue);
} else if (supports_present) {
if (!data->present_queue)
data->present_queue = gst_object_ref (queue);
}
return TRUE;
}
static gboolean static gboolean
_vulkan_swapper_retrieve_surface_properties (GstVulkanSwapper * swapper, _vulkan_swapper_retrieve_surface_properties (GstVulkanSwapper * swapper,
GError ** error) GError ** error)
{ {
guint32 i, present_queue = -1, graphics_queue = -1; struct choose_data data;
VkPhysicalDevice gpu; VkPhysicalDevice gpu;
VkResult err; VkResult err;
@ -175,38 +214,30 @@ _vulkan_swapper_retrieve_surface_properties (GstVulkanSwapper * swapper,
gpu = gst_vulkan_device_get_physical_device (swapper->device); gpu = gst_vulkan_device_get_physical_device (swapper->device);
for (i = 0; i < swapper->device->n_queues; i++) { data.swapper = swapper;
gboolean supports_present; data.present_queue = NULL;
data.graphics_queue = NULL;
supports_present = gst_vulkan_device_foreach_queue (swapper->device,
gst_vulkan_window_get_presentation_support (swapper->window, (GstVulkanDeviceForEachQueueFunc) _choose_queue, &data);
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;
break;
}
if (graphics_queue != -1)
graphics_queue = i;
} else if (supports_present) {
if (present_queue != -1)
present_queue = i;
}
}
if (graphics_queue != present_queue) { if (data.graphics_queue != data.present_queue) {
/* FIXME: add support for separate graphics/present queues */ /* FIXME: add support for separate graphics/present queues */
g_set_error (error, GST_VULKAN_ERROR, g_set_error (error, GST_VULKAN_ERROR,
VK_ERROR_INITIALIZATION_FAILED, VK_ERROR_INITIALIZATION_FAILED,
"Failed to find a compatible present/graphics queue"); "Failed to find a compatible present/graphics queue");
if (data.present_queue)
gst_object_unref (data.present_queue);
if (data.graphics_queue)
gst_object_unref (data.graphics_queue);
return FALSE; return FALSE;
} }
if (!(swapper->queue = gst_vulkan_device_get_queue (swapper->device, swapper->queue = gst_object_ref (data.present_queue);
swapper->device->queue_family_id, graphics_queue, error))) if (data.present_queue)
return FALSE; gst_object_unref (data.present_queue);
if (data.graphics_queue)
gst_object_unref (data.graphics_queue);
err = err =
swapper->GetPhysicalDeviceSurfaceCapabilitiesKHR (gpu, swapper->surface, swapper->GetPhysicalDeviceSurfaceCapabilitiesKHR (gpu, swapper->surface,