Commit b6227aa9 authored by Benjamin Otte's avatar Benjamin Otte

gdk: Add GDK_VULKAN env variable

Also add 2 flags:

GDK_VULKAN="disable" will disable Vulkan usage.

GDK_VULKAN="validate" will enable VK_LAYER_LUNARG_standard_validation.
parent e11a6a0e
......@@ -150,6 +150,11 @@ static const GDebugKey gdk_gl_keys[] = {
{ "gles", GDK_GL_GLES },
};
static const GDebugKey gdk_vulkan_keys[] = {
{ "disable", GDK_VULKAN_DISABLE },
{ "validate", GDK_VULKAN_VALIDATE },
};
#ifdef G_ENABLE_DEBUG
static const GDebugKey gdk_debug_keys[] = {
{ "events", GDK_DEBUG_EVENTS },
......@@ -276,7 +281,7 @@ void
gdk_pre_parse (void)
{
const char *rendering_mode;
const gchar *gl_string;
const gchar *gl_string, *vulkan_string;
gdk_initialized = TRUE;
......@@ -305,6 +310,12 @@ gdk_pre_parse (void)
(GDebugKey *) gdk_gl_keys,
G_N_ELEMENTS (gdk_gl_keys));
vulkan_string = getenv("GDK_VULKAN");
if (vulkan_string != NULL)
_gdk_vulkan_flags = g_parse_debug_string (vulkan_string,
(GDebugKey *) gdk_vulkan_keys,
G_N_ELEMENTS (gdk_vulkan_keys));
if (getenv ("GDK_NATIVE_WINDOWS"))
{
g_warning ("The GDK_NATIVE_WINDOWS environment variable is not supported in GTK3.\n"
......
......@@ -35,4 +35,5 @@ gchar *_gdk_display_name = NULL;
gchar *_gdk_display_arg_name = NULL;
gboolean _gdk_disable_multidevice = FALSE;
guint _gdk_gl_flags = 0;
guint _gdk_vulkan_flags = 0;
GdkRenderingMode _gdk_rendering_mode = GDK_RENDERING_MODE_SIMILAR;
......@@ -88,11 +88,17 @@ typedef enum {
GDK_GL_GLES = 1 << 6
} GdkGLFlags;
typedef enum {
GDK_VULKAN_DISABLE = 1 << 0,
GDK_VULKAN_VALIDATE = 1 << 1,
} GdkVulkanFlags;
extern GList *_gdk_default_filters;
extern GdkWindow *_gdk_parent_root;
extern guint _gdk_debug_flags;
extern guint _gdk_gl_flags;
extern guint _gdk_vulkan_flags;
extern GdkRenderingMode _gdk_rendering_mode;
#ifdef G_ENABLE_DEBUG
......
......@@ -457,6 +457,9 @@ gdk_display_create_vulkan_instance (GdkDisplay *display,
GError **error)
{
uint32_t i;
GPtrArray *used_layers;
gboolean validate = FALSE;
VkResult res;
if (GDK_DISPLAY_GET_CLASS (display)->vk_extension_name == NULL)
{
......@@ -484,6 +487,8 @@ gdk_display_create_vulkan_instance (GdkDisplay *display,
VkLayerProperties layers[n_layers];
GDK_VK_CHECK (vkEnumerateInstanceLayerProperties, &n_layers, layers);
used_layers = g_ptr_array_new ();
for (i = 0; i < n_layers; i++)
{
GDK_NOTE (VULKAN, g_print ("Layer available: %s v%u.%u.%u (%s)\n",
......@@ -492,37 +497,58 @@ gdk_display_create_vulkan_instance (GdkDisplay *display,
VK_VERSION_MINOR (layers[i].specVersion),
VK_VERSION_PATCH (layers[i].specVersion),
layers[i].description));
if ((_gdk_vulkan_flags & GDK_VULKAN_VALIDATE) &&
g_str_equal (layers[i].layerName, "VK_LAYER_LUNARG_standard_validation"))
{
g_ptr_array_add (used_layers, (gpointer) "VK_LAYER_LUNARG_standard_validation");
validate = TRUE;
}
}
if (GDK_VK_CHECK (vkCreateInstance, &(VkInstanceCreateInfo) {
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
NULL,
0,
&(VkApplicationInfo) {
VK_STRUCTURE_TYPE_APPLICATION_INFO,
NULL,
g_get_application_name (),
0,
"GTK+",
VK_MAKE_VERSION (GDK_MAJOR_VERSION, GDK_MINOR_VERSION, GDK_MICRO_VERSION),
VK_API_VERSION_1_0 },
0,
NULL,
2,
(const char *const *) &(const char *[2]) {
VK_KHR_SURFACE_EXTENSION_NAME,
GDK_DISPLAY_GET_CLASS (display)->vk_extension_name
},
},
NULL,
&display->vk_instance) != VK_SUCCESS)
if ((_gdk_vulkan_flags & GDK_VULKAN_VALIDATE) && !validate)
{
g_set_error_literal (error, GDK_VULKAN_ERROR, GDK_VULKAN_ERROR_UNSUPPORTED,
"Could not create a Vulkan instance.");
g_warning ("Vulkan validation layers were requested, but not found. Running without.");
}
res = GDK_VK_CHECK (vkCreateInstance, &(VkInstanceCreateInfo) {
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
NULL,
0,
&(VkApplicationInfo) {
VK_STRUCTURE_TYPE_APPLICATION_INFO,
NULL,
g_get_application_name (),
0,
"GTK+",
VK_MAKE_VERSION (GDK_MAJOR_VERSION, GDK_MINOR_VERSION, GDK_MICRO_VERSION),
VK_API_VERSION_1_0 },
used_layers->len,
(const char * const *) used_layers->pdata,
2,
(const char *const *) &(const char *[2]) {
VK_KHR_SURFACE_EXTENSION_NAME,
GDK_DISPLAY_GET_CLASS (display)->vk_extension_name
},
},
NULL,
&display->vk_instance);
g_ptr_array_free (used_layers, TRUE);
if (res != VK_SUCCESS)
{
g_set_error (error, GDK_VULKAN_ERROR, GDK_VULKAN_ERROR_UNSUPPORTED,
"Could not create a Vulkan instance: %s", gdk_vulkan_strerror (res));
return FALSE;
}
return gdk_display_create_vulkan_device (display, error);
if (!gdk_display_create_vulkan_device (display, error))
{
vkDestroyInstance (display->vk_instance, NULL);
display->vk_instance = VK_NULL_HANDLE;
return FALSE;
}
return TRUE;
}
gboolean
......
......@@ -2705,6 +2705,13 @@ gdk_window_create_vulkan_context (GdkWindow *window,
g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (_gdk_vulkan_flags & GDK_VULKAN_DISABLE)
{
g_set_error_literal (error, GDK_VULKAN_ERROR, GDK_VULKAN_ERROR_NOT_AVAILABLE,
_("Vulkan support disabled via GDK_DEBUG"));
return NULL;
}
display = gdk_window_get_display (window);
if (GDK_DISPLAY_GET_CLASS (display)->vk_extension_name == NULL)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment