[Mesa-dev] [PATCH 06/13] radeon/vcn: add jpeg decode implementation

Leo Liu leo.liu at amd.com
Thu Aug 16 17:19:43 UTC 2018



On 08/16/2018 12:06 PM, boyuan.zhang at amd.com wrote:
> From: Boyuan Zhang <boyuan.zhang at amd.com>
>
> Add a new file to handle VCN Jpeg decode specific functions. Use Jpeg
> specific cmd sending function in end_frame call.
>
> Signed-off-by: Boyuan Zhang <boyuan.zhang at amd.com>
> ---
>   src/gallium/drivers/radeon/Makefile.sources      |  1 +
>   src/gallium/drivers/radeon/meson.build           |  1 +
>   src/gallium/drivers/radeon/radeon_vcn_dec.c      | 32 ++++++--
>   src/gallium/drivers/radeon/radeon_vcn_dec.h      |  4 +
>   src/gallium/drivers/radeon/radeon_vcn_dec_jpeg.c | 99 ++++++++++++++++++++++++
>   5 files changed, 130 insertions(+), 7 deletions(-)
>   create mode 100644 src/gallium/drivers/radeon/radeon_vcn_dec_jpeg.c
>
> diff --git a/src/gallium/drivers/radeon/Makefile.sources b/src/gallium/drivers/radeon/Makefile.sources
> index f8ee860..e3ee82c 100644
> --- a/src/gallium/drivers/radeon/Makefile.sources
> +++ b/src/gallium/drivers/radeon/Makefile.sources
> @@ -10,6 +10,7 @@ C_SOURCES := \
>   	r600_texture.c \
>   	radeon_uvd.c \
>   	radeon_uvd.h \
> +	radeon_vcn_dec_jpeg.c \
>   	radeon_vcn_dec.c \
>   	radeon_vcn_dec.h \
>   	radeon_vcn_enc_1_2.c \
> diff --git a/src/gallium/drivers/radeon/meson.build b/src/gallium/drivers/radeon/meson.build
> index 582a5ff..c984a75 100644
> --- a/src/gallium/drivers/radeon/meson.build
> +++ b/src/gallium/drivers/radeon/meson.build
> @@ -33,6 +33,7 @@ files_libradeon = files(
>     'radeon_vcn_enc_1_2.c',
>     'radeon_vcn_enc.c',
>     'radeon_vcn_enc.h',
> +  'radeon_vcn_dec_jpeg.c',
>     'radeon_vcn_dec.c',
>     'radeon_vcn_dec.h',
>     'radeon_uvd_enc_1_1.c',
> diff --git a/src/gallium/drivers/radeon/radeon_vcn_dec.c b/src/gallium/drivers/radeon/radeon_vcn_dec.c
> index 30a8952..861a40e 100644
> --- a/src/gallium/drivers/radeon/radeon_vcn_dec.c
> +++ b/src/gallium/drivers/radeon/radeon_vcn_dec.c
> @@ -991,6 +991,10 @@ static unsigned calc_dpb_size(struct radeon_decoder *dec)
>   		dpb_size = MAX2(dpb_size, 30 * 1024 * 1024);
>   		break;
>   
> +	case PIPE_VIDEO_FORMAT_JPEG:
> +		dpb_size = 0;
> +		break;
> +
>   	default:
>   		// something is missing here
>   		assert(0);
> @@ -1078,6 +1082,7 @@ static void radeon_dec_decode_bitstream(struct pipe_video_codec *decoder,
>   				  const unsigned *sizes)
>   {
>   	struct radeon_decoder *dec = (struct radeon_decoder*)decoder;
> +	enum pipe_video_format format = u_reduce_video_profile(picture->profile);
>   	unsigned i;
>   
>   	assert(decoder);
> @@ -1089,6 +1094,9 @@ static void radeon_dec_decode_bitstream(struct pipe_video_codec *decoder,
>   		struct rvid_buffer *buf = &dec->bs_buffers[dec->cur_buffer];
>   		unsigned new_size = dec->bs_size + sizes[i];
>   
> +		if (format == PIPE_VIDEO_FORMAT_JPEG)
> +			new_size += 2; /* save for EOI */
> +
>   		if (new_size > buf->res->buf->size) {
>   			dec->ws->buffer_unmap(buf->res->buf);
>   			if (!si_vid_resize_buffer(dec->screen, dec->cs, buf, new_size)) {
> @@ -1108,6 +1116,13 @@ static void radeon_dec_decode_bitstream(struct pipe_video_codec *decoder,
>   		dec->bs_size += sizes[i];
>   		dec->bs_ptr += sizes[i];
>   	}
> +
> +	if (format == PIPE_VIDEO_FORMAT_JPEG) {
> +		((uint8_t *)dec->bs_ptr)[0] = 0xff;	/* EOI */
> +		((uint8_t *)dec->bs_ptr)[1] = 0xd9;
> +		dec->bs_size += 2;
> +		dec->bs_ptr += 2;
> +	}
Can this also be moved to ST?

With handleVASliceDataBufferType() after

buffers[num_buffers] = buf->data;
sizes[num_buffers] = buf->size;
++num_buffers;

by increasing the buffers size to 3.


Regards,
Leo



>   }
>   
>   /**
> @@ -1270,14 +1285,14 @@ struct pipe_video_codec *radeon_create_decoder(struct pipe_context *context,
>   	}
>   
>   	dpb_size = calc_dpb_size(dec);
> -
> -	if (!si_vid_create_buffer(dec->screen, &dec->dpb, dpb_size, PIPE_USAGE_DEFAULT)) {
> -		RVID_ERR("Can't allocated dpb.\n");
> -		goto error;
> +	if (dpb_size) {
> +		if (!si_vid_create_buffer(dec->screen, &dec->dpb, dpb_size, PIPE_USAGE_DEFAULT)) {
> +			RVID_ERR("Can't allocated dpb.\n");
> +			goto error;
> +		}
> +		si_vid_clear_buffer(context, &dec->dpb);
>   	}
>   
> -	si_vid_clear_buffer(context, &dec->dpb);
> -
>   	if (dec->stream_type == RDECODE_CODEC_H264_PERF) {
>   		unsigned ctx_size = calc_ctx_size_h264_perf(dec);
>   		if (!si_vid_create_buffer(dec->screen, &dec->ctx, ctx_size, PIPE_USAGE_DEFAULT)) {
> @@ -1304,7 +1319,10 @@ struct pipe_video_codec *radeon_create_decoder(struct pipe_context *context,
>   
>   	next_buffer(dec);
>   
> -	dec->send_cmd = send_cmd_dec;
> +	if (stream_type == RDECODE_CODEC_JPEG)
> +		dec->send_cmd = send_cmd_jpeg;
> +	else
> +		dec->send_cmd = send_cmd_dec;
>   
>   	return &dec->base;
>   
> diff --git a/src/gallium/drivers/radeon/radeon_vcn_dec.h b/src/gallium/drivers/radeon/radeon_vcn_dec.h
> index 05e4847..782eb65 100644
> --- a/src/gallium/drivers/radeon/radeon_vcn_dec.h
> +++ b/src/gallium/drivers/radeon/radeon_vcn_dec.h
> @@ -627,6 +627,10 @@ void send_cmd_dec(struct radeon_decoder *dec,
>   		  struct pipe_video_buffer *target,
>   		  struct pipe_picture_desc *picture);
>   
> +void send_cmd_jpeg(struct radeon_decoder *dec,
> +		  struct pipe_video_buffer *target,
> +		  struct pipe_picture_desc *picture);
> +
>   struct pipe_video_codec *radeon_create_decoder(struct pipe_context *context,
>   		const struct pipe_video_codec *templat);
>   
> diff --git a/src/gallium/drivers/radeon/radeon_vcn_dec_jpeg.c b/src/gallium/drivers/radeon/radeon_vcn_dec_jpeg.c
> new file mode 100644
> index 0000000..c52ed36
> --- /dev/null
> +++ b/src/gallium/drivers/radeon/radeon_vcn_dec_jpeg.c
> @@ -0,0 +1,99 @@
> +/**************************************************************************
> + *
> + * Copyright 2018 Advanced Micro Devices, Inc.
> + * All Rights Reserved.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the
> + * "Software"), to deal in the Software without restriction, including
> + * without limitation the rights to use, copy, modify, merge, publish,
> + * distribute, sub license, and/or sell copies of the Software, and to
> + * permit persons to whom the Software is furnished to do so, subject to
> + * the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the
> + * next paragraph) shall be included in all copies or substantial portions
> + * of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
> + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
> + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> + *
> + **************************************************************************/
> +
> +#include <assert.h>
> +#include <stdio.h>
> +
> +#include "pipe/p_video_codec.h"
> +
> +#include "util/u_memory.h"
> +#include "util/u_video.h"
> +
> +#include "radeonsi/si_pipe.h"
> +#include "radeon_video.h"
> +#include "radeon_vcn_dec.h"
> +
> +static struct pb_buffer *radeon_jpeg_get_decode_param(struct radeon_decoder *dec,
> +					struct pipe_video_buffer *target,
> +					struct pipe_picture_desc *picture)
> +{
> +	struct r600_texture *luma = (struct r600_texture *)
> +				((struct vl_video_buffer *)target)->resources[0];
> +	struct r600_texture *chroma = (struct r600_texture *)
> +				((struct vl_video_buffer *)target)->resources[1];
> +
> +	dec->jpg.bsd_size = align(dec->bs_size, 128);
> +	dec->jpg.dt_luma_top_offset = luma->surface.u.gfx9.surf_offset;
> +	if (target->buffer_format == PIPE_FORMAT_NV12) {
> +		dec->jpg.dt_chroma_top_offset = chroma->surface.u.gfx9.surf_offset;
> +		dec->jpg.dt_pitch = luma->surface.u.gfx9.surf_pitch * luma->surface.blk_w;
> +	}
> +	else if (target->buffer_format == PIPE_FORMAT_YUYV)
> +		dec->jpg.dt_pitch = luma->surface.u.gfx9.surf_pitch;
> +	dec->jpg.dt_uv_pitch = dec->jpg.dt_pitch / 2;
> +
> +	return luma->resource.buf;
> +}
> +
> +/* send a bitstream buffer command */
> +static void send_cmd_bitstream(struct radeon_decoder *dec,
> +		     struct pb_buffer* buf, uint32_t off,
> +		     enum radeon_bo_usage usage, enum radeon_bo_domain domain)
> +{
> +	/* TODO */
> +}
> +
> +/* send a target buffer command */
> +static void send_cmd_target(struct radeon_decoder *dec,
> +		     struct pb_buffer* buf, uint32_t off,
> +		     enum radeon_bo_usage usage, enum radeon_bo_domain domain)
> +{
> +	/* TODO */
> +}
> +
> +/**
> + * send cmd for vcn jpeg
> + */
> +void send_cmd_jpeg(struct radeon_decoder *dec,
> +			   struct pipe_video_buffer *target,
> +			   struct pipe_picture_desc *picture)
> +{
> +	struct pb_buffer *dt;
> +	struct rvid_buffer *bs_buf;
> +
> +	bs_buf = &dec->bs_buffers[dec->cur_buffer];
> +
> +	memset(dec->bs_ptr, 0, align(dec->bs_size, 128) - dec->bs_size);
> +	dec->ws->buffer_unmap(bs_buf->res->buf);
> +
> +	dt = radeon_jpeg_get_decode_param(dec, target, picture);
> +
> +	send_cmd_bitstream(dec, bs_buf->res->buf,
> +		 0, RADEON_USAGE_READ, RADEON_DOMAIN_GTT);
> +	send_cmd_target(dec, dt, 0,
> +		 RADEON_USAGE_WRITE, RADEON_DOMAIN_VRAM);
> +}



More information about the mesa-dev mailing list