forked from AuroraMiddleware/gtk
Merge branch 'gbsneto/vulkan-fixes' into 'master'
Implement VK_KHR_incremental_present See merge request GNOME/gtk!1116
This commit is contained in:
commit
cb3b6ff624
@ -64,6 +64,9 @@ struct _GdkVulkanContextPrivate {
|
||||
guint n_images;
|
||||
VkImage *images;
|
||||
cairo_region_t **regions;
|
||||
|
||||
gboolean has_present_region;
|
||||
|
||||
#endif
|
||||
|
||||
guint32 draw_index;
|
||||
@ -385,6 +388,26 @@ gdk_vulkan_context_check_swapchain (GdkVulkanContext *context,
|
||||
return res == VK_SUCCESS;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
device_supports_incremental_present (VkPhysicalDevice device)
|
||||
{
|
||||
VkExtensionProperties *extensions;
|
||||
uint32_t n_device_extensions;
|
||||
|
||||
vkEnumerateDeviceExtensionProperties (device, NULL, &n_device_extensions, NULL);
|
||||
|
||||
extensions = g_newa (VkExtensionProperties, n_device_extensions);
|
||||
vkEnumerateDeviceExtensionProperties (device, NULL, &n_device_extensions, extensions);
|
||||
|
||||
for (uint32_t i = 0; i < n_device_extensions; i++)
|
||||
{
|
||||
if (g_str_equal (extensions[i].extensionName, VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_vulkan_context_begin_frame (GdkDrawContext *draw_context,
|
||||
cairo_region_t *region)
|
||||
@ -414,6 +437,29 @@ gdk_vulkan_context_end_frame (GdkDrawContext *draw_context,
|
||||
{
|
||||
GdkVulkanContext *context = GDK_VULKAN_CONTEXT (draw_context);
|
||||
GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
|
||||
VkPresentRegionsKHR *regionsptr = VK_NULL_HANDLE;
|
||||
VkPresentRegionsKHR regions;
|
||||
cairo_rectangle_int_t extents;
|
||||
|
||||
cairo_region_get_extents (painted, &extents);
|
||||
|
||||
regions = (VkPresentRegionsKHR) {
|
||||
.sType = VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR,
|
||||
.swapchainCount = 1,
|
||||
.pRegions = &(VkPresentRegionKHR) {
|
||||
.rectangleCount = 1,
|
||||
.pRectangles = &(VkRectLayerKHR) {
|
||||
.layer = 0,
|
||||
.offset.x = extents.x,
|
||||
.offset.y = extents.y,
|
||||
.extent.width = extents.width,
|
||||
.extent.height = extents.height,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
if (priv->has_present_region)
|
||||
regionsptr = ®ions;
|
||||
|
||||
GDK_VK_CHECK (vkQueuePresentKHR, gdk_vulkan_context_get_queue (context),
|
||||
&(VkPresentInfoKHR) {
|
||||
@ -429,6 +475,7 @@ gdk_vulkan_context_end_frame (GdkDrawContext *draw_context,
|
||||
.pImageIndices = (uint32_t[]) {
|
||||
priv->draw_index
|
||||
},
|
||||
.pNext = regionsptr,
|
||||
});
|
||||
|
||||
cairo_region_destroy (priv->regions[priv->draw_index]);
|
||||
@ -491,11 +538,12 @@ gdk_vulkan_context_real_init (GInitable *initable,
|
||||
{
|
||||
GdkVulkanContext *context = GDK_VULKAN_CONTEXT (initable);
|
||||
GdkVulkanContextPrivate *priv = gdk_vulkan_context_get_instance_private (context);
|
||||
GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
|
||||
VkResult res;
|
||||
VkBool32 supported;
|
||||
uint32_t i;
|
||||
|
||||
priv->vulkan_ref = gdk_display_ref_vulkan (gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context)), error);
|
||||
priv->vulkan_ref = gdk_display_ref_vulkan (display, error);
|
||||
if (!priv->vulkan_ref)
|
||||
return FALSE;
|
||||
|
||||
@ -543,6 +591,7 @@ gdk_vulkan_context_real_init (GInitable *initable,
|
||||
goto out_surface;
|
||||
}
|
||||
priv->image_format = formats[i];
|
||||
priv->has_present_region = device_supports_incremental_present (display->vk_physical_device);
|
||||
|
||||
if (!gdk_vulkan_context_check_swapchain (context, error))
|
||||
goto out_surface;
|
||||
@ -866,11 +915,20 @@ gdk_display_create_vulkan_device (GdkDisplay *display,
|
||||
vkGetPhysicalDeviceQueueFamilyProperties (devices[i], &n_queue_props, NULL);
|
||||
VkQueueFamilyProperties *queue_props = g_newa (VkQueueFamilyProperties, n_queue_props);
|
||||
vkGetPhysicalDeviceQueueFamilyProperties (devices[i], &n_queue_props, queue_props);
|
||||
|
||||
for (j = 0; j < n_queue_props; j++)
|
||||
{
|
||||
if (queue_props[j].queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
||||
{
|
||||
GPtrArray *device_extensions;
|
||||
gboolean has_incremental_present;
|
||||
|
||||
has_incremental_present = device_supports_incremental_present (devices[i]);
|
||||
|
||||
device_extensions = g_ptr_array_new ();
|
||||
g_ptr_array_add (device_extensions, (gpointer) VK_KHR_SWAPCHAIN_EXTENSION_NAME);
|
||||
if (has_incremental_present)
|
||||
g_ptr_array_add (device_extensions, (gpointer) VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
|
||||
|
||||
GDK_DISPLAY_NOTE (display, VULKAN, g_print ("Using Vulkan device %u, queue %u\n", i, j));
|
||||
if (GDK_VK_CHECK (vkCreateDevice, devices[i],
|
||||
&(VkDeviceCreateInfo) {
|
||||
@ -886,14 +944,17 @@ gdk_display_create_vulkan_device (GdkDisplay *display,
|
||||
},
|
||||
0,
|
||||
NULL,
|
||||
1,
|
||||
(const char * const []) {
|
||||
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
|
||||
},
|
||||
device_extensions->len,
|
||||
(const gchar * const *) device_extensions->pdata
|
||||
},
|
||||
NULL,
|
||||
&display->vk_device) != VK_SUCCESS)
|
||||
continue;
|
||||
{
|
||||
g_ptr_array_unref (device_extensions);
|
||||
continue;
|
||||
}
|
||||
|
||||
g_ptr_array_unref (device_extensions);
|
||||
|
||||
display->vk_physical_device = devices[i];
|
||||
vkGetDeviceQueue(display->vk_device, j, 0, &display->vk_queue);
|
||||
|
@ -416,8 +416,8 @@ gdk_registry_handle_global (void *data,
|
||||
if (strcmp (interface, "wl_compositor") == 0)
|
||||
{
|
||||
display_wayland->compositor =
|
||||
wl_registry_bind (display_wayland->wl_registry, id, &wl_compositor_interface, MIN (version, 3));
|
||||
display_wayland->compositor_version = MIN (version, 3);
|
||||
wl_registry_bind (display_wayland->wl_registry, id, &wl_compositor_interface, MIN (version, 4));
|
||||
display_wayland->compositor_version = MIN (version, 4);
|
||||
}
|
||||
else if (strcmp (interface, "wl_shm") == 0)
|
||||
{
|
||||
|
@ -142,13 +142,15 @@ gsk_vulkan_uploader_get_copy_buffer (GskVulkanUploader *self)
|
||||
void
|
||||
gsk_vulkan_uploader_upload (GskVulkanUploader *self)
|
||||
{
|
||||
VkPipelineStageFlagBits host_and_transfer_bits = VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||
|
||||
if (self->before_buffer_barriers->len > 0 || self->before_image_barriers->len > 0)
|
||||
{
|
||||
VkCommandBuffer command_buffer;
|
||||
|
||||
command_buffer = gsk_vulkan_command_pool_get_buffer (self->command_pool);
|
||||
vkCmdPipelineBarrier (command_buffer,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | host_and_transfer_bits,
|
||||
VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
0,
|
||||
0, NULL,
|
||||
@ -164,7 +166,7 @@ gsk_vulkan_uploader_upload (GskVulkanUploader *self)
|
||||
{
|
||||
VkCommandBuffer command_buffer = gsk_vulkan_uploader_get_copy_buffer (self);
|
||||
vkCmdPipelineBarrier (command_buffer,
|
||||
VK_PIPELINE_STAGE_HOST_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT,
|
||||
host_and_transfer_bits,
|
||||
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
|
||||
0,
|
||||
0, NULL,
|
||||
|
@ -172,7 +172,7 @@ gsk_vulkan_render_pass_new (GdkVulkanContext *context,
|
||||
.samples = VK_SAMPLE_COUNT_1_BIT,
|
||||
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
||||
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
||||
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||
.initialLayout = VK_IMAGE_LAYOUT_GENERAL,
|
||||
.finalLayout = final_layout
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user