Skip to content

Commit

Permalink
gpu: Disable the ubershader when shaders aren't nonuniform
Browse files Browse the repository at this point in the history
If shaders don't support nonuniform indexing, we emulate it via if/else
ladders (or switch ladders) which get inlined by the GLSL compiles and
massively blow up the code.

And that makes compilation of the shaders take minutes and results in
shader code that isn't necessarily faster.

So we disable it on GL entirely and on Vulkan if the required features
aren't available.

As it's only an optimization and does not fall back to Cairo anymore,
this should be fine.
  • Loading branch information
Benjamin Otte committed Jan 7, 2024
1 parent c0d49f2 commit 03cd652
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions gdk/gdkdisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,17 @@ gdk_display_create_vulkan_context (GdkDisplay *self,
NULL);
}

gboolean
gdk_display_has_vulkan_feature (GdkDisplay *self,
GdkVulkanFeatures feature)
{
#ifdef GDK_RENDERING_VULKAN
return !!(self->vulkan_features & feature);
#else
return FALSE;
#endif
}

static void
gdk_display_init_gl (GdkDisplay *self)
{
Expand Down
2 changes: 2 additions & 0 deletions gdk/gdkdisplayprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ void _gdk_display_unpause_events (GdkDisplay *display

void gdk_display_init_dmabuf (GdkDisplay *self);

gboolean gdk_display_has_vulkan_feature (GdkDisplay *self,
GdkVulkanFeatures feature);
GdkVulkanContext * gdk_display_create_vulkan_context (GdkDisplay *self,
GError **error);

Expand Down
7 changes: 7 additions & 0 deletions gsk/gpu/gsknglrenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ gsk_ngl_renderer_create_context (GskGpuRenderer *renderer,
gdk_gl_context_make_current (context);

*supported = -1;

/* Shader compilation takes too long when texture() and get_float() calls
* use if/else ladders to avoid non-uniform indexing.
* And that is always true with GL.
*/
*supported &= ~GSK_GPU_OPTIMIZE_UBER;

if (!gdk_gl_context_check_version (context, "4.2", "9.9") &&
!epoxy_has_gl_extension ("GL_EXT_base_instance") &&
!epoxy_has_gl_extension ("GL_ARB_base_instance"))
Expand Down
9 changes: 9 additions & 0 deletions gsk/gpu/gskvulkanrenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ gsk_vulkan_renderer_create_context (GskGpuRenderer *renderer,

*supported = -1;

/* Shader compilation takes too long when texture() and get_float() calls
* use if/else ladders to avoid non-uniform indexing.
* This is true when we use the Vulkan 1.0 shaders, but works with the Vulkan 1.2
* shaders.
*/
if (!gdk_display_has_vulkan_feature (display, GDK_VULKAN_FEATURE_DYNAMIC_INDEXING) ||
!gdk_display_has_vulkan_feature (display, GDK_VULKAN_FEATURE_NONUNIFORM_INDEXING))
*supported &= ~GSK_GPU_OPTIMIZE_UBER;

return GDK_DRAW_CONTEXT (context);
}

Expand Down

0 comments on commit 03cd652

Please sign in to comment.