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 /** this represents a segement context. 76 * each segment has its own version of data */ 77 struct segment_ctx { 78 uint16_t segment_idx; 79 struct stream_ctx *stream_ctx; 80 struct scaler_data scaler_data; 81 }; 82 83 struct vpe_cmd_input { 84 uint16_t stream_idx; 85 struct scaler_data scaler_data; 86 }; 87 88 struct vpe_cmd_info { 89 enum vpe_cmd_ops ops; 90 uint8_t cd; // count down value 91 92 // input 93 uint16_t num_inputs; 94 struct vpe_cmd_input inputs[MAX_PIPE]; 95 96 // output 97 struct vpe_rect dst_viewport; 98 struct vpe_rect dst_viewport_c; 99 100 bool tm_enabled; 101 bool is_begin; 102 bool is_end; 103 }; 104 105 struct config_record { 106 uint64_t config_base_addr; 107 uint64_t config_size; 108 }; 109 110 /** represents a stream input, i.e. common to all segments */ 111 struct stream_ctx { 112 struct vpe_priv *vpe_priv; 113 114 int32_t stream_idx; 115 struct vpe_stream stream; /**< stores all the input data */ 116 117 uint16_t num_segments; 118 struct segment_ctx *segment_ctx; 119 120 uint16_t num_configs; // shared among same stream 121 uint16_t num_stream_op_configs[VPE_CMD_TYPE_COUNT]; // shared among same cmd type within the 122 // same stream 123 struct config_record configs[16]; 124 struct config_record stream_op_configs[VPE_CMD_TYPE_COUNT][16]; 125 126 // cached color properties 127 bool per_pixel_alpha; 128 enum color_transfer_func tf; 129 enum color_space cs; 130 bool enable_3dlut; 131 bool update_3dlut; 132 uint64_t UID_3DLUT; // UID for current 3D LUT params 133 134 union { 135 struct { 136 unsigned int color_space : 1; 137 unsigned int transfer_function : 1; 138 unsigned int pixel_format : 1; 139 unsigned int reserved : 1; 140 }; 141 unsigned int u32All; 142 } dirty_bits; 143 144 struct bias_and_scale *bias_scale; 145 struct transfer_func *input_tf; 146 struct vpe_csc_matrix *input_cs; 147 struct colorspace_transform *gamut_remap; 148 struct transfer_func *in_shaper_func; // for shaper lut 149 struct vpe_3dlut *lut3d_func; // for 3dlut 150 struct transfer_func *blend_tf; // for 1dlut 151 white_point_gain white_point_gain; 152 153 bool flip_horizonal_output; 154 struct vpe_color_adjust color_adjustments; // stores the current color adjustments params 155 struct fixed31_32 156 tf_scaling_factor; // a scaling factor that acts as a gain on the transfer function 157 }; 158 159 struct output_ctx { 160 // stores the paramters built for generating vpep configs 161 struct vpe_surface_info surface; 162 struct vpe_color bg_color; 163 struct vpe_rect target_rect; 164 enum vpe_alpha_mode alpha_mode; 165 struct vpe_clamping_params clamping_params; 166 167 // cached color properties 168 enum color_transfer_func tf; 169 enum color_space cs; 170 171 uint32_t num_configs; 172 struct config_record configs[8]; 173 174 union { 175 struct { 176 unsigned int color_space : 1; 177 unsigned int transfer_function : 1; 178 unsigned int lut3d : 1; 179 unsigned int reserved : 1; 180 }; 181 unsigned int u32All; 182 } dirty_bits; 183 184 struct transfer_func *output_tf; 185 const struct transfer_func *in_shaper_func; // for shaper lut 186 const struct vpe_3dlut *lut3d_func; // for 3dlut 187 const struct transfer_func *blend_tf; // for 1dlut 188 struct colorspace_transform *gamut_remap; // post blend gamut remap 189 190 struct { 191 uint32_t hdr_metadata : 1; 192 uint32_t reserved : 31; 193 } flags; 194 struct vpe_hdr_metadata hdr_metadata; 195 }; 196 197 #define PIPE_CTX_NO_OWNER ((uint32_t)(-1)) 198 199 struct pipe_ctx { 200 uint32_t pipe_idx; 201 uint32_t owner; // stream_idx 202 bool is_top_pipe; 203 int32_t top_pipe_idx; 204 }; 205 206 struct config_frontend_cb_ctx { 207 struct vpe_priv *vpe_priv; 208 uint32_t stream_idx; 209 bool stream_sharing; 210 bool stream_op_sharing; 211 enum vpe_cmd_type cmd_type; // command type, i.e. bg or compositing 212 }; 213 214 struct config_backend_cb_ctx { 215 struct vpe_priv *vpe_priv; 216 bool share; // add to output_ctx if true 217 }; 218 219 /** internal vpe instance */ 220 struct vpe_priv { 221 /** public */ 222 struct vpe pub; /**< public member */ 223 224 /** internal */ 225 struct vpe_init_data init; 226 struct resource resource; 227 struct calculate_buffer cal_buffer; 228 struct vpe_bufs_req bufs_required; /**< cached required buffer size for the checked ops */ 229 230 // number of total vpe cmds 231 uint16_t num_vpe_cmds; 232 struct vpe_cmd_info vpe_cmd_info[MAX_VPE_CMD]; 233 bool ops_support; 234 235 // writers 236 struct vpe_desc_writer vpe_desc_writer; 237 struct plane_desc_writer plane_desc_writer; 238 struct config_writer config_writer; 239 struct config_frontend_cb_ctx fe_cb_ctx; 240 struct config_backend_cb_ctx be_cb_ctx; 241 242 // input ctx 243 uint32_t num_streams; 244 struct stream_ctx *stream_ctx; 245 246 // output ctx 247 struct output_ctx output_ctx; 248 249 uint16_t num_pipe; 250 struct pipe_ctx pipe_ctx[MAX_PIPE]; 251 252 // internal temp structure for creating pure BG filling 253 struct vpe_build_param *dummy_input_param; 254 struct vpe_stream *dummy_stream; 255 bool scale_yuv_matrix; // this is a flag that forces scaling the yuv->rgb matrix 256 // when embedding the color adjustments 257 258 enum vpe_expansion_mode expansion_mode; 259 }; 260 261 #ifdef __cplusplus 262 } 263 #endif 264