From db348ac4526d0f60f91cf100feafb50b557bcd20 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Wed, 1 Jan 2025 11:31:00 +0100 Subject: [PATCH] gallium/vl: Add rgba compute shader It only supports blending mode that va frontend expects, so prefer the old fragment shader and only use the compute shader when gfx is not supported. Reviewed-by: Leo Liu Part-of: --- src/gallium/auxiliary/vl/vl_compositor.c | 5 ++- src/gallium/auxiliary/vl/vl_compositor_cs.c | 46 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/vl/vl_compositor.c b/src/gallium/auxiliary/vl/vl_compositor.c index bcd1039aee7..70d1bb79226 100644 --- a/src/gallium/auxiliary/vl/vl_compositor.c +++ b/src/gallium/auxiliary/vl/vl_compositor.c @@ -688,7 +688,10 @@ vl_compositor_set_rgba_layer(struct vl_compositor_state *s, return; s->used_layers |= 1 << layer; - s->layers[layer].fs = c->fs_rgba; + if (c->fs_rgba) + s->layers[layer].fs = c->fs_rgba; + else if (c->cs_rgba) + s->layers[layer].cs = c->cs_rgba; s->layers[layer].samplers[0] = c->sampler_linear; s->layers[layer].samplers[1] = NULL; s->layers[layer].samplers[2] = NULL; diff --git a/src/gallium/auxiliary/vl/vl_compositor_cs.c b/src/gallium/auxiliary/vl/vl_compositor_cs.c index 3271a90a4cf..3ca2368446d 100644 --- a/src/gallium/auxiliary/vl/vl_compositor_cs.c +++ b/src/gallium/auxiliary/vl/vl_compositor_cs.c @@ -277,6 +277,21 @@ static inline nir_def *cs_fetch_texel(struct cs_shader *s, nir_def *coords, unsi return nir_tex_deref(b, tex_deref, tex_deref, nir_channels(b, coords, mask)); } +static inline nir_def *cs_image_load(struct cs_shader *s, nir_def *pos) +{ + /* + imageLoad(image, pos.xy); + */ + nir_builder *b = &s->b; + nir_def *zero = nir_imm_int(b, 0); + nir_def *sample = nir_imm_int(b, 0); + pos = nir_pad_vector_imm_int(b, pos, 0, 4); + enum glsl_sampler_dim sampler_dim = s->array ? GLSL_SAMPLER_DIM_2D : GLSL_SAMPLER_DIM_RECT; + return nir_image_deref_load(b, 4, 32, &nir_build_deref_var(b, s->image)->def, pos, sample, zero, + .image_dim = sampler_dim, + .image_array = s->array); +} + static inline void cs_image_store(struct cs_shader *s, nir_def *pos, nir_def *color) { /* @@ -574,6 +589,29 @@ static nir_def *create_weave_shader(struct vl_compositor *c, bool rgb, bool y) return cs_create_shader_state(c, &s); } +static void *create_rgba_shader(struct vl_compositor *c) +{ + struct cs_shader s = { + .name = "rgba", + .num_samplers = 1, + }; + nir_builder *b = &s.b; + + nir_def *ipos = cs_create_shader(c, &s); + nir_def *pos = cs_tex_coords(&s, ipos, COORDS_LUMA); + nir_def *pos_out = cs_translate(&s, ipos); + + nir_def *col = cs_fetch_texel(&s, pos, 0); + nir_def *blend = cs_image_load(&s, pos_out); + + nir_def *color = nir_flrp(b, blend, col, nir_channel(b, col, 3)); + color = nir_vector_insert_imm(b, color, s.fone, 3); + + cs_image_store(&s, pos_out, color); + + return cs_create_shader_state(c, &s); +} + static void cs_launch(struct vl_compositor *c, void *cs, @@ -840,6 +878,12 @@ bool vl_compositor_cs_init_shaders(struct vl_compositor *c) return false; } + c->cs_rgba = create_rgba_shader(c); + if (!c->cs_rgba) { + debug_printf("Unable to create rgba compute shader.\n"); + return false; + } + c->cs_yuv.weave.y = create_weave_shader(c, false, true); c->cs_yuv.weave.uv = create_weave_shader(c, false, false); c->cs_yuv.progressive.y = create_yuv_progressive_shader(c, VL_COMPOSITOR_PLANE_Y); @@ -877,6 +921,8 @@ void vl_compositor_cs_cleanup_shaders(struct vl_compositor *c) c->pipe->delete_compute_state(c->pipe, c->cs_video_buffer); if (c->cs_weave_rgb) c->pipe->delete_compute_state(c->pipe, c->cs_weave_rgb); + if (c->cs_rgba) + c->pipe->delete_compute_state(c->pipe, c->cs_rgba); if (c->cs_yuv.weave.y) c->pipe->delete_compute_state(c->pipe, c->cs_yuv.weave.y); if (c->cs_yuv.weave.uv)