[Mesa-dev] [PATCH 03/10] radeon/vcn: add jpeg decoder creation
Leo Liu
leo.liu at amd.com
Tue Aug 7 15:34:05 UTC 2018
On 08/02/2018 03:44 PM, boyuan.zhang at amd.com wrote:
> From: Boyuan Zhang <boyuan.zhang at amd.com>
>
> 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_jpeg.c | 212 +++++++++++++++++++++++++++
Most of the changes seems to be duplicated from VCN DEC, can we just
re-use them from VCN DEC, and keep something specific for JPEG to this file?
Regards,
Leo
> 3 files changed, 214 insertions(+)
> create mode 100644 src/gallium/drivers/radeon/radeon_vcn_jpeg.c
>
> diff --git a/src/gallium/drivers/radeon/Makefile.sources b/src/gallium/drivers/radeon/Makefile.sources
> index a11bffe..3424e2d 100644
> --- a/src/gallium/drivers/radeon/Makefile.sources
> +++ b/src/gallium/drivers/radeon/Makefile.sources
> @@ -16,6 +16,7 @@ C_SOURCES := \
> radeon_vcn_enc.c \
> radeon_vcn_enc.h \
> radeon_vcn_jpeg.h \
> + radeon_vcn_jpeg.c \
> radeon_uvd_enc_1_1.c \
> radeon_uvd_enc.c \
> radeon_uvd_enc.h \
> diff --git a/src/gallium/drivers/radeon/meson.build b/src/gallium/drivers/radeon/meson.build
> index eb68b57..a12cd4e 100644
> --- a/src/gallium/drivers/radeon/meson.build
> +++ b/src/gallium/drivers/radeon/meson.build
> @@ -36,6 +36,7 @@ files_libradeon = files(
> 'radeon_vcn_dec.c',
> 'radeon_vcn_dec.h',
> 'radeon_vcn_jpeg.h',
> + 'radeon_vcn_jpeg.c',
> 'radeon_uvd_enc_1_1.c',
> 'radeon_uvd_enc.c',
> 'radeon_uvd_enc.h',
> diff --git a/src/gallium/drivers/radeon/radeon_vcn_jpeg.c b/src/gallium/drivers/radeon/radeon_vcn_jpeg.c
> new file mode 100644
> index 0000000..c078131
> --- /dev/null
> +++ b/src/gallium/drivers/radeon/radeon_vcn_jpeg.c
> @@ -0,0 +1,212 @@
> +/**************************************************************************
> + *
> + * 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_jpeg.h"
> +
> +#define NUM_BUFFERS 4
> +
> +struct radeon_jpeg_decoder {
> + struct pipe_video_codec base;
> +
> + unsigned stream_handle;
> + unsigned stream_type;
> + unsigned frame_number;
> +
> + struct pipe_screen *screen;
> + struct radeon_winsys *ws;
> + struct radeon_winsys_cs *cs;
> +
> + void *bs_ptr;
> +
> + struct rvid_buffer bs_buffers[NUM_BUFFERS];
> +
> + unsigned bs_size;
> + unsigned cur_buffer;
> + unsigned bsd_size;
> + unsigned dt_pitch;
> + unsigned dt_uv_pitch;
> + unsigned dt_luma_top_offset;
> + unsigned dt_chroma_top_offset;
> +};
> +
> +/* flush IB to the hardware */
> +static int flush(struct radeon_jpeg_decoder *dec, unsigned flags)
> +{
> + return dec->ws->cs_flush(dec->cs, flags, NULL);
> +}
> +
> +/* cycle to the next set of buffers */
> +static void next_buffer(struct radeon_jpeg_decoder *dec)
> +{
> + ++dec->cur_buffer;
> + dec->cur_buffer %= NUM_BUFFERS;
> +}
> +
> +/**
> + * destroy this video decoder
> + */
> +static void radeon_jpeg_destroy(struct pipe_video_codec *decoder)
> +{
> + /* TODO */
> +}
> +
> +/**
> + * start decoding of a new frame
> + */
> +static void radeon_jpeg_begin_frame(struct pipe_video_codec *decoder,
> + struct pipe_video_buffer *target,
> + struct pipe_picture_desc *picture)
> +{
> + /* TODO */
> +}
> +
> +/**
> + * decode a macroblock
> + */
> +static void radeon_jpeg_decode_macroblock(struct pipe_video_codec *decoder,
> + struct pipe_video_buffer *target,
> + struct pipe_picture_desc *picture,
> + const struct pipe_macroblock *macroblocks,
> + unsigned num_macroblocks)
> +{
> + /* TODO */
> +}
> +
> +/**
> + * decode a bitstream
> + */
> +static void radeon_jpeg_decode_bitstream(struct pipe_video_codec *decoder,
> + struct pipe_video_buffer *target,
> + struct pipe_picture_desc *picture,
> + unsigned num_buffers,
> + const void * const *buffers,
> + const unsigned *sizes)
> +{
> + /* TODO */
> +}
> +
> +/**
> + * end decoding of the current frame
> + */
> +static void radeon_jpeg_end_frame(struct pipe_video_codec *decoder,
> + struct pipe_video_buffer *target,
> + struct pipe_picture_desc *picture)
> +{
> + /* TODO */
> +}
> +
> +/**
> + * flush any outstanding command buffers to the hardware
> + */
> +static void radeon_jpeg_flush(struct pipe_video_codec *decoder)
> +{
> +}
> +
> +/**
> + * create and HW decoder
> + */
> +struct pipe_video_codec *radeon_create_decoder_jpeg(struct pipe_context *context,
> + const struct pipe_video_codec *templ)
> +{
> + struct radeon_winsys* ws = ((struct r600_common_context *)context)->ws;
> + struct r600_common_context *rctx = (struct r600_common_context*)context;
> + unsigned width = templ->width, height = templ->height;
> + unsigned bs_buf_size, stream_type = 0;
> + struct radeon_jpeg_decoder *dec;
> + int r, i;
> +
> + if ((u_reduce_video_profile(templ->profile)) == PIPE_VIDEO_FORMAT_JPEG)
> + stream_type = RDECODE_CODEC_JPEG;
> + else
> + assert(0);
> +
> + dec = CALLOC_STRUCT(radeon_jpeg_decoder);
> +
> + if (!dec)
> + return NULL;
> +
> + dec->base = *templ;
> + dec->base.context = context;
> + dec->base.width = width;
> + dec->base.height = height;
> +
> + dec->base.destroy = radeon_jpeg_destroy;
> + dec->base.begin_frame = radeon_jpeg_begin_frame;
> + dec->base.decode_macroblock = radeon_jpeg_decode_macroblock;
> + dec->base.decode_bitstream = radeon_jpeg_decode_bitstream;
> + dec->base.end_frame = radeon_jpeg_end_frame;
> + dec->base.flush = radeon_jpeg_flush;
> +
> + dec->stream_type = stream_type;
> + dec->stream_handle = si_vid_alloc_stream_handle();
> + dec->screen = context->screen;
> + dec->ws = ws;
> + dec->cs = ws->cs_create(rctx->ctx, RING_VCN_JPEG, NULL, NULL);
> + if (!dec->cs) {
> + RVID_ERR("Can't get command submission context.\n");
> + goto error;
> + }
> +
> + bs_buf_size = width * height * (512 / (16 * 16));
> + for (i = 0; i < NUM_BUFFERS; ++i) {
> + if (!si_vid_create_buffer(dec->screen, &dec->bs_buffers[i],
> + bs_buf_size, PIPE_USAGE_STAGING)) {
> + RVID_ERR("Can't allocated bitstream buffers.\n");
> + goto error;
> + }
> + si_vid_clear_buffer(context, &dec->bs_buffers[i]);
> + }
> +
> + r = flush(dec, 0);
> + if (r)
> + goto error;
> +
> + next_buffer(dec);
> +
> + return &dec->base;
> +
> +error:
> + if (dec->cs) dec->ws->cs_destroy(dec->cs);
> +
> + for (i = 0; i < NUM_BUFFERS; ++i) {
> + si_vid_destroy_buffer(&dec->bs_buffers[i]);
> + }
> +
> + FREE(dec);
> +
> + return NULL;
> +}
More information about the mesa-dev
mailing list