xref: /aosp_15_r20/external/mesa3d/src/amd/vpelib/src/core/inc/vpe_priv.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 container_of(ptr, type, member) (type *)(void *)((char *)ptr - offsetof(type, member))
50 
51 #define VPE_MIN_VIEWPORT_SIZE                                                                      \
52     2                      // chroma viewport size is half of it, thus need to be 2 for YUV420
53                            // for simplication we just use 2 for all types
54 #define MAX_VPE_CMD 256    // TODO Dynamic allocation
55 
56 #define MAX_LINE_SIZE 1024 // without 16 pixels for the seams
57 #define MAX_LINE_CNT  4
58 
59 enum vpe_cmd_ops {
60     VPE_CMD_OPS_BLENDING,
61     VPE_CMD_OPS_BG,
62     VPE_CMD_OPS_COMPOSITING,
63     VPE_CMD_OPS_BG_VSCF_INPUT,  // For visual confirm input
64     VPE_CMD_OPS_BG_VSCF_OUTPUT, // For visual confirm output
65 };
66 
67 enum vpe_cmd_type {
68     VPE_CMD_TYPE_COMPOSITING,
69     VPE_CMD_TYPE_BG,
70     VPE_CMD_TYPE_BG_VSCF_INPUT,  // For visual confirm input
71     VPE_CMD_TYPE_BG_VSCF_OUTPUT, // For visual confirm output
72     VPE_CMD_TYPE_COUNT
73 };
74 
75 enum vpe_stream_type {
76     VPE_STREAM_TYPE_INPUT,
77     VPE_STREAM_TYPE_BG_GEN,
78 };
79 
80 /** this represents a segement context.
81  * each segment has its own version of data */
82 struct segment_ctx {
83     uint16_t           segment_idx;
84     struct stream_ctx *stream_ctx;
85     struct scaler_data scaler_data;
86 };
87 
88 struct vpe_cmd_input {
89     uint16_t           stream_idx;
90     struct scaler_data scaler_data;
91 };
92 
93 struct vpe_cmd_output {
94     struct vpe_rect dst_viewport;
95     struct vpe_rect dst_viewport_c;
96 };
97 
98 struct vpe_cmd_info {
99     enum vpe_cmd_ops ops;
100     uint8_t          cd; // count down value
101 
102     // input
103     uint16_t             num_inputs;
104     struct vpe_cmd_input inputs[MAX_PIPE];
105 
106     // output
107     uint16_t              num_outputs;
108     struct vpe_cmd_output outputs[MAX_OUTPUT_PIPE];
109 
110     bool tm_enabled;
111     bool insert_start_csync;
112     bool insert_end_csync;
113 };
114 
115 struct config_record {
116     uint64_t config_base_addr;
117     uint64_t config_size;
118 };
119 
120 #define VPE_3DLUT_CACHE_SIZE 81920
121 
122 struct vpe_3dlut_cache {
123     uint64_t uid;
124     uint8_t  cache_buf[VPE_3DLUT_CACHE_SIZE];
125     uint64_t buffer_size;
126 };
127 
128 /** represents a stream input, i.e. common to all segments */
129 struct stream_ctx {
130     struct vpe_priv *vpe_priv;
131 
132     enum vpe_stream_type stream_type;
133     int32_t              stream_idx;
134     struct vpe_stream    stream; /**< stores all the input data */
135 
136     uint16_t            num_segments;
137     struct segment_ctx *segment_ctx;
138 
139     uint16_t num_configs;                               // shared among same stream
140     uint16_t num_stream_op_configs[VPE_CMD_TYPE_COUNT]; // shared among same cmd type within the
141                                                         // same stream
142     struct config_record configs[16];
143     struct config_record stream_op_configs[VPE_CMD_TYPE_COUNT][16];
144 
145     // cached color properties
146     bool                     per_pixel_alpha;
147     enum color_transfer_func tf;
148     enum color_space         cs;
149     bool                     enable_3dlut;
150     uint64_t                 uid_3dlut;                 // UID for current 3D LUT params
151     bool                     geometric_scaling;
152     bool                     is_yuv_input;
153 
154     union {
155         struct {
156             unsigned int color_space       : 1;
157             unsigned int transfer_function : 1;
158             unsigned int pixel_format      : 1;
159             unsigned int reserved          : 1;
160         };
161         unsigned int u32All;
162     } dirty_bits;
163 
164     struct bias_and_scale       *bias_scale;
165     struct transfer_func        *input_tf;
166     struct vpe_csc_matrix       *input_cs;
167     struct colorspace_transform *gamut_remap;
168     struct transfer_func        *in_shaper_func; // for shaper lut
169     struct vpe_3dlut            *lut3d_func;     // for 3dlut
170     struct vpe_3dlut_cache      *lut3d_cache;    // for 3dlut cache
171     struct transfer_func        *blend_tf;       // for 1dlut
172     white_point_gain             white_point_gain;
173 
174     bool                    flip_horizonal_output;
175     struct vpe_color_adjust color_adjustments; // stores the current color adjustments params
176     struct fixed31_32
177         tf_scaling_factor; // a scaling factor that acts as a gain on the transfer function
178 };
179 
180 struct output_ctx {
181     // stores the paramters built for generating vpep configs
182     struct vpe_surface_info    surface;
183     struct vpe_color           bg_color;
184     struct vpe_rect            target_rect;
185     enum vpe_alpha_mode        alpha_mode;
186     struct vpe_clamping_params clamping_params;
187 
188     // cached color properties
189     enum color_transfer_func tf;
190     enum color_space         cs;
191 
192     uint32_t             num_configs;
193     struct config_record configs[8];
194 
195     union {
196         struct {
197             unsigned int color_space       : 1;
198             unsigned int transfer_function : 1;
199             unsigned int lut3d             : 1;
200             unsigned int reserved          : 1;
201         };
202         unsigned int u32All;
203     } dirty_bits;
204 
205     struct transfer_func        *output_tf;
206     const struct transfer_func  *in_shaper_func; // for shaper lut
207     const struct vpe_3dlut      *lut3d_func;     // for 3dlut
208     const struct transfer_func  *blend_tf;       // for 1dlut
209     struct colorspace_transform *gamut_remap;    // post blend gamut remap
210 
211     struct {
212         uint32_t hdr_metadata : 1;
213         uint32_t reserved     : 31;
214     } flags;
215     struct vpe_hdr_metadata hdr_metadata;
216 };
217 
218 #define PIPE_CTX_NO_OWNER ((uint32_t)(-1))
219 
220 struct pipe_ctx {
221     uint32_t pipe_idx;
222     uint32_t owner; // stream_idx
223     bool     is_top_pipe;
224     int32_t  top_pipe_idx;
225 };
226 
227 struct config_frontend_cb_ctx {
228     struct vpe_priv  *vpe_priv;
229     uint32_t          stream_idx;
230     bool              stream_sharing;
231     bool              stream_op_sharing;
232     enum vpe_cmd_type cmd_type; // command type, i.e. bg or compositing
233 };
234 
235 struct config_backend_cb_ctx {
236     struct vpe_priv *vpe_priv;
237     bool             share; // add to output_ctx if true
238 };
239 
240 /** internal vpe instance */
241 struct vpe_priv {
242     /** public */
243     struct vpe pub; /**< public member */
244 
245     /** internal */
246     struct vpe_init_data    init;
247     struct resource         resource;
248     struct calculate_buffer cal_buffer;
249     struct vpe_bufs_req     bufs_required; /**< cached required buffer size for the checked ops */
250 
251     // number of total vpe cmds
252     uint16_t            num_vpe_cmds;
253     struct vpe_cmd_info vpe_cmd_info[MAX_VPE_CMD];
254     bool                ops_support;
255 
256     // writers
257     struct vpe_desc_writer        vpe_desc_writer;
258     struct plane_desc_writer      plane_desc_writer;
259     struct config_writer          config_writer;
260     struct config_frontend_cb_ctx fe_cb_ctx;
261     struct config_backend_cb_ctx  be_cb_ctx;
262 
263     // input ctx
264     uint32_t           num_virtual_streams; // streams created by VPE
265     uint32_t           num_input_streams;   // streams inputed from build params
266     uint32_t           num_streams;         // input streams + virtual streams
267     struct stream_ctx *stream_ctx;          // input streams allocated first, then virtual streams
268 
269     // output ctx
270     struct output_ctx output_ctx;
271 
272     uint16_t        num_pipe;
273     struct pipe_ctx pipe_ctx[MAX_PIPE];
274 
275     // internal temp structure for creating pure BG filling
276     struct vpe_build_param *dummy_input_param;
277     struct vpe_stream      *dummy_stream;
278     bool scale_yuv_matrix; // this is a flag that forces scaling the yuv->rgb matrix
279                            //  when embedding the color adjustments
280 
281 #ifdef VPE_BUILD_1_1
282     // collaborate sync data counter
283     int32_t  collaborate_sync_index;
284     uint16_t vpe_num_instance;
285     bool     collaboration_mode;
286 #endif
287     enum vpe_expansion_mode expansion_mode;
288 };
289 
290 #ifdef __cplusplus
291 }
292 #endif
293