From a50a46acf5b21cd2bace4786e3e11fdc9426a26d Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 21 Aug 2023 10:31:40 +0200 Subject: [PATCH] gallium/auxiliary/vl: Support chroma sample location in compute shaders Used only in YUV to RGB video_buffer shader for now. Acked-by: Leo Liu Reviewed-by: Thong Thai Part-of: --- src/gallium/auxiliary/vl/vl_compositor.c | 2 +- src/gallium/auxiliary/vl/vl_compositor.h | 12 +++++++ src/gallium/auxiliary/vl/vl_compositor_cs.c | 37 ++++++++++++++++++--- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/gallium/auxiliary/vl/vl_compositor.c b/src/gallium/auxiliary/vl/vl_compositor.c index d081bec1fb6..95b6e42636c 100644 --- a/src/gallium/auxiliary/vl/vl_compositor.c +++ b/src/gallium/auxiliary/vl/vl_compositor.c @@ -827,7 +827,7 @@ vl_compositor_init_state(struct vl_compositor_state *s, struct pipe_context *pip pipe->screen, PIPE_BIND_CONSTANT_BUFFER, PIPE_USAGE_DEFAULT, - sizeof(csc_matrix) + 10*sizeof(float) + 10*sizeof(int) + sizeof(csc_matrix) + 12*sizeof(float) + 10*sizeof(int) ); if (!s->shader_params) diff --git a/src/gallium/auxiliary/vl/vl_compositor.h b/src/gallium/auxiliary/vl/vl_compositor.h index 5fd2410bfa1..91ea5c5c720 100644 --- a/src/gallium/auxiliary/vl/vl_compositor.h +++ b/src/gallium/auxiliary/vl/vl_compositor.h @@ -68,6 +68,17 @@ enum vl_compositor_rotation VL_COMPOSITOR_ROTATE_270 }; +/* chroma sample location */ +enum vl_compositor_chroma_location +{ + VL_COMPOSITOR_LOCATION_NONE = 0, + VL_COMPOSITOR_LOCATION_VERTICAL_TOP = (1 << 0), + VL_COMPOSITOR_LOCATION_VERTICAL_CENTER = (1 << 1), + VL_COMPOSITOR_LOCATION_VERTICAL_BOTTOM = (1 << 2), + VL_COMPOSITOR_LOCATION_HORIZONTAL_LEFT = (1 << 3), + VL_COMPOSITOR_LOCATION_HORIZONTAL_CENTER = (1 << 4) +}; + struct vl_compositor_layer { bool clearing; @@ -102,6 +113,7 @@ struct vl_compositor_state unsigned used_layers:VL_COMPOSITOR_MAX_LAYERS; struct vl_compositor_layer layers[VL_COMPOSITOR_MAX_LAYERS]; bool interlaced; + unsigned chroma_location; }; struct vl_compositor diff --git a/src/gallium/auxiliary/vl/vl_compositor_cs.c b/src/gallium/auxiliary/vl/vl_compositor_cs.c index 2caa529965b..598f79b655b 100644 --- a/src/gallium/auxiliary/vl/vl_compositor_cs.c +++ b/src/gallium/auxiliary/vl/vl_compositor_cs.c @@ -46,6 +46,8 @@ struct cs_viewport { float clamp_y; float chroma_clamp_x; float chroma_clamp_y; + float chroma_offset_x; + float chroma_offset_y; }; const char *compute_shader_video_buffer = @@ -57,7 +59,7 @@ const char *compute_shader_video_buffer = "DCL SV[0], THREAD_ID\n" "DCL SV[1], BLOCK_ID\n" - "DCL CONST[0..7]\n" + "DCL CONST[0..8]\n" "DCL SVIEW[0..2], RECT, FLOAT\n" "DCL SAMP[0..2]\n" @@ -80,12 +82,13 @@ const char *compute_shader_video_buffer = /* Translate */ "UADD TEMP[2].xy, TEMP[0].xyyy, -CONST[5].xyxy\n" "U2F TEMP[2].xy, TEMP[2].xyyy\n" - "MUL TEMP[3].xy, TEMP[2].xyyy, CONST[6].xyyy\n" - "TRUNC TEMP[3].xy, TEMP[3].xyyy\n" /* Texture offset */ "ADD TEMP[2].xy, TEMP[2].xyxy, IMM[1].yyyy\n" - "ADD TEMP[3].xy, TEMP[3].xyxy, IMM[1].yyyy\n" + + /* Chroma offset + subsampling */ + "ADD TEMP[3].xy, TEMP[2].xyyy, CONST[8].xyxy\n" + "MUL TEMP[3].xy, TEMP[3].xyyy, CONST[6].xyxy\n" /* Scale */ "DIV TEMP[2].xy, TEMP[2].xyyy, CONST[3].zwww\n" @@ -813,6 +816,26 @@ calc_drawn_area(struct vl_compositor_state *s, return result; } +static inline float +chroma_offset_x(unsigned location) +{ + if (location & VL_COMPOSITOR_LOCATION_HORIZONTAL_LEFT) + return 0.5f; + else + return 0.0f; +} + +static inline float +chroma_offset_y(unsigned location) +{ + if (location & VL_COMPOSITOR_LOCATION_VERTICAL_TOP) + return 0.5f; + else if (location & VL_COMPOSITOR_LOCATION_VERTICAL_BOTTOM) + return -0.5f; + else + return 0.0f; +} + static bool set_viewport(struct vl_compositor_state *s, struct cs_viewport *drawn, @@ -824,7 +847,7 @@ set_viewport(struct vl_compositor_state *s, void *ptr = pipe_buffer_map_range(s->pipe, s->shader_params, sizeof(vl_csc_matrix) + sizeof(float) * 2, - sizeof(float) * 10 + sizeof(int) * 8, + sizeof(float) * 12 + sizeof(int) * 8, PIPE_MAP_WRITE | PIPE_MAP_DISCARD_RANGE, &buf_transfer); @@ -871,6 +894,8 @@ set_viewport(struct vl_compositor_state *s, *ptr_float++ = drawn->clamp_y; *ptr_float++ = drawn->chroma_clamp_x; *ptr_float++ = drawn->chroma_clamp_y; + *ptr_float++ = drawn->chroma_offset_x; + *ptr_float++ = drawn->chroma_offset_y; pipe_buffer_unmap(s->pipe, buf_transfer); @@ -916,6 +941,8 @@ draw_layers(struct vl_compositor *c, (layer->src.br.x - layer->src.tl.x) - 0.5; drawn.chroma_clamp_y = (float)sampler1->texture->height0 * (layer->src.br.y - layer->src.tl.y) - 0.5; + drawn.chroma_offset_x = chroma_offset_x(s->chroma_location); + drawn.chroma_offset_y = chroma_offset_y(s->chroma_location); set_viewport(s, &drawn, samplers); c->pipe->bind_sampler_states(c->pipe, PIPE_SHADER_COMPUTE, 0,