7c078a09640203355ce8cc6cb51f5b6fd9b9d2ad
[mesa.git] / src / gallium / drivers / radeon / radeon_vcn_dec_jpeg.c
1 /**************************************************************************
2 *
3 * Copyright 2018 Advanced Micro Devices, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include <assert.h>
29 #include <stdio.h>
30
31 #include "pipe/p_video_codec.h"
32
33 #include "util/u_memory.h"
34 #include "util/u_video.h"
35
36 #include "radeonsi/si_pipe.h"
37 #include "radeon_video.h"
38 #include "radeon_vcn_dec.h"
39
40 static struct pb_buffer *radeon_jpeg_get_decode_param(struct radeon_decoder *dec,
41 struct pipe_video_buffer *target,
42 struct pipe_picture_desc *picture)
43 {
44 struct si_texture *luma = (struct si_texture *)
45 ((struct vl_video_buffer *)target)->resources[0];
46 struct si_texture *chroma = (struct si_texture *)
47 ((struct vl_video_buffer *)target)->resources[1];
48
49 dec->jpg.bsd_size = align(dec->bs_size, 128);
50 dec->jpg.dt_luma_top_offset = luma->surface.u.gfx9.surf_offset;
51 if (target->buffer_format == PIPE_FORMAT_NV12) {
52 dec->jpg.dt_chroma_top_offset = chroma->surface.u.gfx9.surf_offset;
53 dec->jpg.dt_pitch = luma->surface.u.gfx9.surf_pitch * luma->surface.blk_w;
54 }
55 else if (target->buffer_format == PIPE_FORMAT_YUYV)
56 dec->jpg.dt_pitch = luma->surface.u.gfx9.surf_pitch;
57 dec->jpg.dt_uv_pitch = dec->jpg.dt_pitch / 2;
58
59 return luma->buffer.buf;
60 }
61
62 /* send a bitstream buffer command */
63 static void send_cmd_bitstream(struct radeon_decoder *dec,
64 struct pb_buffer* buf, uint32_t off,
65 enum radeon_bo_usage usage, enum radeon_bo_domain domain)
66 {
67 /* TODO */
68 }
69
70 /* send a target buffer command */
71 static void send_cmd_target(struct radeon_decoder *dec,
72 struct pb_buffer* buf, uint32_t off,
73 enum radeon_bo_usage usage, enum radeon_bo_domain domain)
74 {
75 /* TODO */
76 }
77
78 /**
79 * send cmd for vcn jpeg
80 */
81 void send_cmd_jpeg(struct radeon_decoder *dec,
82 struct pipe_video_buffer *target,
83 struct pipe_picture_desc *picture)
84 {
85 struct pb_buffer *dt;
86 struct rvid_buffer *bs_buf;
87
88 bs_buf = &dec->bs_buffers[dec->cur_buffer];
89
90 memset(dec->bs_ptr, 0, align(dec->bs_size, 128) - dec->bs_size);
91 dec->ws->buffer_unmap(bs_buf->res->buf);
92
93 dt = radeon_jpeg_get_decode_param(dec, target, picture);
94
95 send_cmd_bitstream(dec, bs_buf->res->buf,
96 0, RADEON_USAGE_READ, RADEON_DOMAIN_GTT);
97 send_cmd_target(dec, dt, 0,
98 RADEON_USAGE_WRITE, RADEON_DOMAIN_VRAM);
99 }