radeon/vcn: add jpeg decode implementation
authorBoyuan Zhang <boyuan.zhang@amd.com>
Wed, 17 Oct 2018 19:03:23 +0000 (15:03 -0400)
committerLeo Liu <leo.liu@amd.com>
Tue, 23 Oct 2018 12:50:02 +0000 (08:50 -0400)
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@amd.com>
Reviewed-by: Leo Liu <leo.liu@amd.com>
src/gallium/drivers/radeon/radeon_vcn_dec.c
src/gallium/drivers/radeon/radeon_vcn_dec.h
src/gallium/drivers/radeon/radeon_vcn_dec_jpeg.c [new file with mode: 0644]
src/gallium/drivers/radeonsi/Makefile.sources
src/gallium/drivers/radeonsi/meson.build

index 30a98c278672c2893438173e6a583bea726605a6..75ef4a5d401d52f9f676a4092cd53a2d8f9985a5 100644 (file)
@@ -1247,6 +1247,10 @@ static unsigned calc_dpb_size(struct radeon_decoder *dec)
                        dpb_size *= (3 / 2);
                break;
 
+       case PIPE_VIDEO_FORMAT_JPEG:
+               dpb_size = 0;
+               break;
+
        default:
                // something is missing here
                assert(0);
@@ -1547,14 +1551,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)) {
@@ -1581,7 +1585,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;
 
index 37c050337710557fd206d8b2e3a1dc460a242365..a6a726f46d68fd9a479c956d0230a5106629dd59 100644 (file)
@@ -768,6 +768,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 (file)
index 0000000..7c078a0
--- /dev/null
@@ -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 si_texture *luma = (struct si_texture *)
+                               ((struct vl_video_buffer *)target)->resources[0];
+       struct si_texture *chroma = (struct si_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->buffer.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);
+}
index aeb9b7982c481b43231c460a77e05f1f62ea7589..dcaf446effea8e04ec214b4658184623627796c1 100644 (file)
@@ -52,6 +52,7 @@ C_SOURCES := \
        ../radeon/r600_perfcounter.c \
        ../radeon/radeon_uvd.c \
        ../radeon/radeon_uvd.h \
+       ../radeon/radeon_vcn_dec_jpeg.c \
        ../radeon/radeon_vcn_dec.c \
        ../radeon/radeon_vcn_dec.h \
        ../radeon/radeon_vcn_enc_1_2.c \
index 2542f136d110aeb942b8372bb24c19d0ca120d80..ac8ed949ea0eea1a755c183b00696bcdca39fdae 100644 (file)
@@ -71,6 +71,7 @@ files_libradeonsi = files(
   '../radeon/radeon_vcn_enc_1_2.c',
   '../radeon/radeon_vcn_enc.c',
   '../radeon/radeon_vcn_enc.h',
+  '../radeon/radeon_vcn_dec_jpeg.c',
   '../radeon/radeon_vcn_dec.c',
   '../radeon/radeon_vcn_dec.h',
   '../radeon/radeon_uvd_enc_1_1.c',