From a3f35964baf40d746318831f65ada478800d9c53 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Thu, 27 Jun 2024 13:18:43 +0200 Subject: [PATCH] gallium/vl: Init shaders on first use It takes significant amount of time at va context creation, and most of the time the postproc pipelines are not used anyway. This reduces total time it takes to run all libva-utils tests on my machine from 38s to 28s. Reviewed-by: Leo Liu Part-of: --- src/gallium/auxiliary/vl/vl_compositor.c | 28 +++++++++++++++++++----- src/gallium/auxiliary/vl/vl_compositor.h | 2 ++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/gallium/auxiliary/vl/vl_compositor.c b/src/gallium/auxiliary/vl/vl_compositor.c index fb368cb8796..c0a9e625f65 100644 --- a/src/gallium/auxiliary/vl/vl_compositor.c +++ b/src/gallium/auxiliary/vl/vl_compositor.c @@ -35,6 +35,9 @@ init_shaders(struct vl_compositor *c) { assert(c); + if (c->shaders_initialized) + return true; + if (c->pipe_cs_composit_supported) { if (!vl_compositor_cs_init_shaders(c)) return false; @@ -96,6 +99,8 @@ init_shaders(struct vl_compositor *c) } } + c->shaders_initialized = true; + return true; } @@ -103,6 +108,9 @@ static void cleanup_shaders(struct vl_compositor *c) { assert(c); + if (!c->shaders_initialized) + return; + if (c->pipe_cs_composit_supported) { vl_compositor_cs_cleanup_shaders(c); } else if (c->pipe_gfx_supported) { @@ -332,6 +340,9 @@ set_yuv_layer(struct vl_compositor_state *s, struct vl_compositor *c, assert(layer < VL_COMPOSITOR_MAX_LAYERS); + if (!init_shaders(c)) + return; + s->used_layers |= 1 << layer; sampler_views = buffer->get_sampler_view_components(buffer); for (i = 0; i < 3; ++i) { @@ -391,6 +402,9 @@ set_rgb_to_yuv_layer(struct vl_compositor_state *s, struct vl_compositor *c, assert(layer < VL_COMPOSITOR_MAX_LAYERS); + if (!init_shaders(c)) + return; + s->used_layers |= 1 << layer; if (c->pipe_cs_composit_supported) @@ -550,6 +564,9 @@ vl_compositor_set_buffer_layer(struct vl_compositor_state *s, assert(layer < VL_COMPOSITOR_MAX_LAYERS); + if (!init_shaders(c)) + return; + s->used_layers |= 1 << layer; sampler_views = buffer->get_sampler_view_components(buffer); for (i = 0; i < 3; ++i) { @@ -616,6 +633,9 @@ vl_compositor_set_palette_layer(struct vl_compositor_state *s, assert(layer < VL_COMPOSITOR_MAX_LAYERS); + if (!init_shaders(c)) + return; + s->used_layers |= 1 << layer; s->layers[layer].fs = include_color_conversion ? @@ -647,6 +667,9 @@ vl_compositor_set_rgba_layer(struct vl_compositor_state *s, assert(layer < VL_COMPOSITOR_MAX_LAYERS); + if (!init_shaders(c)) + return; + s->used_layers |= 1 << layer; s->layers[layer].fs = c->fs_rgba; s->layers[layer].samplers[0] = c->sampler_linear; @@ -782,11 +805,6 @@ vl_compositor_init(struct vl_compositor *c, struct pipe_context *pipe) return false; } - if (!init_shaders(c)) { - cleanup_pipe_state(c); - return false; - } - if (!init_buffers(c)) { cleanup_shaders(c); cleanup_pipe_state(c); diff --git a/src/gallium/auxiliary/vl/vl_compositor.h b/src/gallium/auxiliary/vl/vl_compositor.h index 8e49008be44..a700b34cffb 100644 --- a/src/gallium/auxiliary/vl/vl_compositor.h +++ b/src/gallium/auxiliary/vl/vl_compositor.h @@ -182,6 +182,8 @@ struct vl_compositor void *y; void *uv; } cs_rgb_yuv; + + bool shaders_initialized; }; /**