• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2022 Advanced Micro Devices, Inc.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a
4  * copy of this software and associated documentation files (the "Software"),
5  * to deal in the Software without restriction, including without limitation
6  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7  * and/or sell copies of the Software, and to permit persons to whom the
8  * Software is furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
16  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
17  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19  * OTHER DEALINGS IN THE SOFTWARE.
20  *
21  * Authors: AMD
22  *
23  */
24 
25 #pragma once
26 
27 #include "vpe_types.h"
28 #include "resource.h"
29 #include "transform.h"
30 #include "color.h"
31 #include "color_gamma.h"
32 #include "vpe_desc_writer.h"
33 #include "plane_desc_writer.h"
34 #include "config_writer.h"
35 #include "color_cs.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #define vpe_zalloc(size) vpe_priv->init.funcs.zalloc(vpe_priv->init.funcs.mem_ctx, size)
42 #define vpe_free(ptr)    vpe_priv->init.funcs.free(vpe_priv->init.funcs.mem_ctx, (ptr))
43 #define vpe_log(...)                                                                               \
44     do {                                                                                           \
45         vpe_priv->init.funcs.log(vpe_priv->init.funcs.log_ctx, "vpe: ");                           \
46         vpe_priv->init.funcs.log(vpe_priv->init.funcs.log_ctx, __VA_ARGS__);                       \
47     } while (0)
48 
49 #define vpe_event(event_id, ...)                                                                   \
50     do {                                                                                           \
51         vpe_priv->init.funcs.sys_event(event_id, __VA_ARGS__);                                     \
52     } while (0)
53 
54 #define container_of(ptr, type, member) (type *)(void *)((char *)ptr - offsetof(type, member))
55 
56 #define VPE_MIN_VIEWPORT_SIZE                                                                      \
57     2                      // chroma viewport size is half of it, thus need to be 2 for YUV420
58                            // for simplication we just use 2 for all types
59 
60 #define MAX_LINE_SIZE 1024 // without 16 pixels for the seams
61 #define MAX_LINE_CNT  4
62 
63 enum vpe_cmd_ops {
64     VPE_CMD_OPS_BLENDING,
65     VPE_CMD_OPS_BG,
66     VPE_CMD_OPS_COMPOSITING,
67     VPE_CMD_OPS_BG_VSCF_INPUT,  // For visual confirm input
68     VPE_CMD_OPS_BG_VSCF_OUTPUT, // For visual confirm output
69 };
70 
71 enum vpe_cmd_type {
72     VPE_CMD_TYPE_COMPOSITING,
73     VPE_CMD_TYPE_BG,
74     VPE_CMD_TYPE_BG_VSCF_INPUT,  // For visual confirm input
75     VPE_CMD_TYPE_BG_VSCF_OUTPUT, // For visual confirm output
76     VPE_CMD_TYPE_COUNT
77 };
78 
79 enum vpe_stream_type {
80     VPE_STREAM_TYPE_INPUT,
81     VPE_STREAM_TYPE_BG_GEN,
82 };
83 
84 /** this represents a segement context.
85  * each segment has its own version of data */
86 struct segment_ctx {
87     uint16_t           segment_idx;
88     struct stream_ctx *stream_ctx;
89     struct scaler_data scaler_data;
90 };
91 
92 struct vpe_cmd_input {
93     uint16_t           stream_idx;
94     struct scaler_data scaler_data;
95 };
96 
97 struct vpe_cmd_output {
98     struct vpe_rect dst_viewport;
99     struct vpe_rect dst_viewport_c;
100 };
101 
102 struct vpe_cmd_info {
103     enum vpe_cmd_ops ops;
104     uint8_t          cd; // count down value
105 
106     // input
107     uint16_t             num_inputs;
108     struct vpe_cmd_input inputs[MAX_INPUT_PIPE];
109 
110     // output
111     uint16_t              num_outputs;
112     struct vpe_cmd_output outputs[MAX_OUTPUT_PIPE];
113 
114     bool tm_enabled;
115     bool insert_start_csync;
116     bool insert_end_csync;
117 };
118 
119 struct config_record {
120     uint64_t config_base_addr;
121     uint64_t config_size;
122 };
123 
124 /** represents a stream input, i.e. common to all segments */
125 struct stream_ctx {
126     struct vpe_priv *vpe_priv;
127 
128     enum vpe_stream_type stream_type;
129     int32_t              stream_idx;
130     struct vpe_stream    stream; /**< stores all the input data */
131 
132     uint16_t            num_segments;
133     struct segment_ctx *segment_ctx;
134 
135     // share configs that can be re-used once generated
136     struct vpe_vector *configs[MAX_INPUT_PIPE];
137     struct vpe_vector *stream_op_configs[MAX_INPUT_PIPE][VPE_CMD_TYPE_COUNT];
138 
139     // cached color properties
140     bool                     per_pixel_alpha;
141     enum color_transfer_func tf;
142     enum color_space         cs;
143     bool                     enable_3dlut;
144     uint64_t                 uid_3dlut;                 // UID for current 3D LUT params
145     bool                     geometric_scaling;
146     bool                     is_yuv_input;
147 
148     union {
149         struct {
150             unsigned int color_space       : 1;
151             unsigned int transfer_function : 1;
152             unsigned int pixel_format      : 1;
153             unsigned int reserved          : 1;
154         };
155         unsigned int u32All;
156     } dirty_bits;
157 
158     struct bias_and_scale       *bias_scale;
159     struct transfer_func        *input_tf;
160     struct vpe_csc_matrix       *input_cs;
161     struct colorspace_transform *gamut_remap;
162     struct transfer_func        *in_shaper_func; // for shaper lut
163     struct vpe_3dlut            *lut3d_func;     // for 3dlut
164     struct transfer_func        *blend_tf;       // for 1dlut
165     white_point_gain             white_point_gain;
166     bool                         flip_horizonal_output;
167     struct vpe_color_adjust      color_adjustments; // stores the current color adjustments params
168     struct fixed31_32            tf_scaling_factor; // a gain applied on a transfer function
169 };
170 
171 struct output_ctx {
172     // stores the paramters built for generating vpep configs
173     struct vpe_surface_info    surface;
174     struct vpe_color           mpc_bg_color;
175     struct vpe_color           opp_bg_color;
176     struct vpe_rect            target_rect;
177     enum vpe_alpha_mode        alpha_mode;
178     struct vpe_clamping_params clamping_params;
179 
180     // cached color properties
181     enum color_transfer_func tf;
182     enum color_space         cs;
183 
184     // store generated per-pipe configs that can be reused
185     struct vpe_vector *configs[MAX_OUTPUT_PIPE];
186 
187     union {
188         struct {
189             unsigned int color_space       : 1;
190             unsigned int transfer_function : 1;
191             unsigned int lut3d             : 1;
192             unsigned int reserved          : 1;
193         };
194         unsigned int u32All;
195     } dirty_bits;
196 
197     struct transfer_func        *output_tf;
198     const struct transfer_func  *in_shaper_func; // for shaper lut
199     const struct vpe_3dlut      *lut3d_func;     // for 3dlut
200     const struct transfer_func  *blend_tf;       // for 1dlut
201     struct colorspace_transform *gamut_remap;    // post blend gamut remap
202 
203     struct {
204         uint32_t hdr_metadata : 1;
205         uint32_t reserved     : 31;
206     } flags;
207     struct vpe_hdr_metadata hdr_metadata;
208 };
209 
210 #define PIPE_CTX_NO_OWNER ((uint32_t)(-1))
211 
212 struct pipe_ctx {
213     uint32_t pipe_idx;
214     uint32_t owner; // stream_idx
215     bool     is_top_pipe;
216     int32_t  top_pipe_idx;
217 };
218 
219 struct config_frontend_cb_ctx {
220     struct vpe_priv  *vpe_priv;
221     uint32_t          stream_idx;
222     bool              stream_sharing;
223     bool              stream_op_sharing;
224     enum vpe_cmd_type cmd_type; // command type, i.e. bg or compositing
225 };
226 
227 struct config_backend_cb_ctx {
228     struct vpe_priv *vpe_priv;
229     bool             share; // add to output_ctx if true
230 };
231 
232 /** internal vpe instance */
233 struct vpe_priv {
234     /** public */
235     struct vpe pub; /**< public member */
236 
237     /** internal */
238     struct vpe_init_data    init;
239     struct resource         resource;
240     struct calculate_buffer cal_buffer;
241     struct vpe_bufs_req     bufs_required; /**< cached required buffer size for the checked ops */
242 
243     struct vpe_vector  *vpe_cmd_vector;
244     bool                ops_support;
245 
246     // writers
247     struct vpe_desc_writer        vpe_desc_writer;
248     struct plane_desc_writer      plane_desc_writer;
249     struct config_writer          config_writer;
250     struct config_frontend_cb_ctx fe_cb_ctx;
251     struct config_backend_cb_ctx  be_cb_ctx;
252 
253     // input ctx
254     uint32_t           num_virtual_streams; // streams created by VPE
255     uint32_t           num_input_streams;   // streams inputed from build params
256     uint32_t           num_streams;         // input streams + virtual streams
257     struct stream_ctx *stream_ctx;          // input streams allocated first, then virtual streams
258 
259     // output ctx
260     struct output_ctx output_ctx;
261 
262     uint16_t        num_pipe;
263     struct pipe_ctx pipe_ctx[MAX_INPUT_PIPE];
264 
265     // internal temp structure for creating pure BG filling
266     struct vpe_build_param *dummy_input_param;
267     struct vpe_stream      *dummy_stream;
268     bool scale_yuv_matrix; // this is a flag that forces scaling the yuv->rgb matrix
269                            //  when embedding the color adjustments
270 
271     // collaborate sync data counter
272     int32_t  collaborate_sync_index;
273     uint16_t vpe_num_instance;
274     bool     collaboration_mode;
275     enum vpe_expansion_mode expansion_mode;
276 };
277 
278 #ifdef __cplusplus
279 }
280 #endif
281