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 "fixed31_32.h" 29 #include "hw_shared.h" 30 #include "config_cache.h" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #define SDR_VIDEO_WHITE_POINT 100 // nits 37 #define SDR_WHITE_POINT 80 // nits 38 #define HDR_PEAK_WHITE 10000 39 #define CCCS_NORM HDR_PEAK_WHITE / SDR_WHITE_POINT 40 #define STUDIO_RANGE_FOOT_ROOM_10_BIT vpe_fixpt_from_fraction(64, 1023) 41 #define STUDIO_RANGE_SCALE_10_BIT vpe_fixpt_from_fraction(940 - 64, 1023) 42 #define STUDIO_RANGE_FOOT_ROOM_8_BIT vpe_fixpt_from_fraction(16, 255) 43 #define STUDIO_RANGE_SCALE_8_BIT vpe_fixpt_from_fraction(235 - 16, 255) 44 45 struct vpe_priv; 46 struct stream_ctx; 47 48 enum color_depth { 49 COLOR_DEPTH_UNDEFINED, 50 COLOR_DEPTH_666, 51 COLOR_DEPTH_888, 52 COLOR_DEPTH_101010, 53 COLOR_DEPTH_121212, 54 COLOR_DEPTH_141414, 55 COLOR_DEPTH_161616, 56 COLOR_DEPTH_999, 57 COLOR_DEPTH_111111, 58 COLOR_DEPTH_COUNT 59 }; 60 61 enum color_range_type { 62 COLOR_RANGE_FULL, 63 COLOR_RANGE_LIMITED_8BPC, 64 COLOR_RANGE_LIMITED_10BPC, 65 COLOR_RANGE_LIMITED_16BPC 66 }; 67 68 enum color_transfer_func { 69 TRANSFER_FUNC_UNKNOWN, 70 TRANSFER_FUNC_SRGB, 71 TRANSFER_FUNC_BT709, 72 TRANSFER_FUNC_BT1886, 73 TRANSFER_FUNC_PQ2084, 74 TRANSFER_FUNC_LINEAR, 75 TRANSFER_FUNC_NORMALIZED_PQ, 76 TRANSFER_FUNC_HLG 77 }; 78 79 enum dither_option { 80 DITHER_OPTION_DEFAULT, 81 DITHER_OPTION_DISABLE, 82 DITHER_OPTION_FM6, 83 DITHER_OPTION_FM8, 84 DITHER_OPTION_FM10, 85 DITHER_OPTION_SPATIAL6_FRAME_RANDOM, 86 DITHER_OPTION_SPATIAL8_FRAME_RANDOM, 87 DITHER_OPTION_SPATIAL10_FRAME_RANDOM, 88 DITHER_OPTION_SPATIAL6, 89 DITHER_OPTION_SPATIAL8, 90 DITHER_OPTION_SPATIAL10, 91 DITHER_OPTION_TRUN6, 92 DITHER_OPTION_TRUN8, 93 DITHER_OPTION_TRUN10, 94 DITHER_OPTION_TRUN10_SPATIAL8, 95 DITHER_OPTION_TRUN10_SPATIAL6, 96 DITHER_OPTION_TRUN10_FM8, 97 DITHER_OPTION_TRUN10_FM6, 98 DITHER_OPTION_TRUN10_SPATIAL8_FM6, 99 DITHER_OPTION_SPATIAL10_FM8, 100 DITHER_OPTION_SPATIAL10_FM6, 101 DITHER_OPTION_TRUN8_SPATIAL6, 102 DITHER_OPTION_TRUN8_FM6, 103 DITHER_OPTION_SPATIAL8_FM6, 104 DITHER_OPTION_MAX = DITHER_OPTION_SPATIAL8_FM6, 105 DITHER_OPTION_INVALID 106 }; 107 108 enum color_space { 109 COLOR_SPACE_UNKNOWN, 110 COLOR_SPACE_SRGB, 111 COLOR_SPACE_SRGB_LIMITED, 112 COLOR_SPACE_MSREF_SCRGB, 113 COLOR_SPACE_YCBCR601, 114 COLOR_SPACE_RGB601, 115 COLOR_SPACE_RGB601_LIMITED, 116 COLOR_SPACE_YCBCR709, 117 COLOR_SPACE_YCBCR_JFIF, 118 COLOR_SPACE_RGB_JFIF, 119 COLOR_SPACE_YCBCR601_LIMITED, 120 COLOR_SPACE_YCBCR709_LIMITED, 121 COLOR_SPACE_2020_RGB_FULLRANGE, 122 COLOR_SPACE_2020_RGB_LIMITEDRANGE, 123 COLOR_SPACE_2020_YCBCR, 124 COLOR_SPACE_2020_YCBCR_LIMITED, 125 COLOR_SPACE_MAX, 126 }; 127 128 enum transfer_func_type { 129 TF_TYPE_PREDEFINED, 130 TF_TYPE_DISTRIBUTED_POINTS, 131 TF_TYPE_BYPASS, 132 TF_TYPE_HWPWL 133 }; 134 135 enum cm_type { 136 CM_DEGAM, 137 CM_REGAM, 138 }; 139 140 enum { 141 TRANSFER_FUNC_POINTS = 1025 142 }; 143 144 typedef struct fixed31_32 white_point_gain; 145 146 struct transfer_func_distributed_points { 147 struct fixed31_32 red[TRANSFER_FUNC_POINTS]; 148 struct fixed31_32 green[TRANSFER_FUNC_POINTS]; 149 struct fixed31_32 blue[TRANSFER_FUNC_POINTS]; 150 151 uint16_t end_exponent; 152 uint16_t x_point_at_y1_red; 153 uint16_t x_point_at_y1_green; 154 uint16_t x_point_at_y1_blue; 155 }; 156 157 struct cache_info { 158 enum color_transfer_func tf; 159 enum cm_type cm_gamma_type; 160 struct fixed31_32 x_scale; 161 struct fixed31_32 y_scale; 162 struct fixed31_32 y_bias; 163 }; 164 165 struct transfer_func { 166 enum transfer_func_type type; 167 enum color_transfer_func tf; 168 enum cm_type cm_gamma_type; 169 struct fixed31_32 start_base; // Used to clamp curve start 170 171 /* FP16 1.0 reference level in nits, default is 80 nits, only for PQ*/ 172 uint32_t sdr_ref_white_level; 173 union { 174 struct pwl_params pwl; 175 struct transfer_func_distributed_points tf_pts; 176 }; 177 178 // the followings are for optimization: skip if no change 179 bool dirty[MAX_INPUT_PIPE]; /*< indicate this object is updated or not */ 180 struct config_cache 181 config_cache[MAX_INPUT_PIPE]; /*< used by the hw hook layer to do the caching */ 182 183 struct cache_info cache_info[MAX_INPUT_PIPE]; 184 }; 185 186 enum color_white_point_type { 187 color_white_point_type_unknown, 188 color_white_point_type_5000k_horizon, 189 color_white_point_type_6500k_noon, 190 color_white_point_type_7500k_north_sky, 191 color_white_point_type_9300k, 192 color_white_point_type_custom_coordinates 193 }; 194 195 struct color_space_coordinates { 196 unsigned int redX; 197 unsigned int redY; 198 unsigned int greenX; 199 unsigned int greenY; 200 unsigned int blueX; 201 unsigned int blueY; 202 unsigned int whiteX; 203 unsigned int whiteY; 204 }; 205 206 enum predefined_gamut_type { 207 gamut_type_bt709, 208 gamut_type_bt601, 209 gamut_type_adobe_rgb, 210 gamut_type_srgb, 211 gamut_type_bt2020, 212 gamut_type_dcip3, 213 gamut_type_unknown, 214 }; 215 216 enum predefined_white_point_type { 217 white_point_type_5000k_horizon, 218 white_point_type_6500k_noon, 219 white_point_type_7500k_north_sky, 220 white_point_type_9300k, 221 white_point_type_unknown, 222 }; 223 224 struct colorspace_transform { 225 struct fixed31_32 matrix[12]; 226 bool enable_remap; 227 }; 228 229 struct color_gamut_data { 230 enum color_space color_space; 231 enum color_white_point_type white_point; 232 struct color_space_coordinates gamut; 233 }; 234 235 union vpe_3dlut_state { 236 struct { 237 uint32_t initialized : 1; /*< if 3dlut is went through color module for initialization */ 238 uint32_t reserved : 15; 239 } bits; 240 uint32_t raw; 241 }; 242 243 struct vpe_3dlut { 244 // struct kref refcount; 245 struct tetrahedral_params lut_3d; 246 struct fixed31_32 hdr_multiplier; 247 union vpe_3dlut_state state; 248 249 // the followings are for optimization: skip if no change 250 bool dirty[MAX_3DLUT]; /*< indicate this object is updated or not */ 251 struct config_cache config_cache[MAX_3DLUT]; /*< used by the hw hook layer to do the caching */ 252 253 struct { 254 uint64_t uid_3dlut; /*< UID for current 3D LUT params */ 255 } cache_info[MAX_3DLUT]; 256 }; 257 258 enum vpe_status vpe_color_update_color_space_and_tf( 259 struct vpe_priv *vpe_priv, const struct vpe_build_param *param); 260 261 enum vpe_status vpe_color_update_movable_cm( 262 struct vpe_priv *vpe_priv, const struct vpe_build_param *param); 263 264 void vpe_color_get_color_space_and_tf( 265 const struct vpe_color_space *vcs, enum color_space *cs, enum color_transfer_func *tf); 266 267 bool vpe_use_csc_adjust(const struct vpe_color_adjust *adjustments); 268 269 bool vpe_is_rgb_equal(const struct pwl_result_data *rgb, uint32_t num); 270 271 bool vpe_is_HDR(enum color_transfer_func tf); 272 273 void vpe_convert_full_range_color_enum(enum color_space *cs); 274 275 enum vpe_status vpe_color_update_whitepoint( 276 const struct vpe_priv *vpe_priv, const struct vpe_build_param *param); 277 278 enum vpe_status vpe_color_tm_update_hdr_mult(uint16_t shaper_in_exp_max, uint32_t peak_white, 279 struct fixed31_32 *hdr_multiplier, bool enable_3dlut, bool is_fp16); 280 281 enum vpe_status vpe_color_build_shaper_cs(const struct vpe_tonemap_params *tm_params, 282 struct vpe_surface_info *surface_info, struct vpe_color_space *tm_out_cs); 283 284 enum vpe_status vpe_color_update_shaper(const struct vpe_priv *vpe_priv, uint16_t shaper_in_exp_max, 285 struct stream_ctx *stream_ctx, enum color_transfer_func tf_in_3dlut, bool enable_3dlut); 286 287 enum vpe_status vpe_color_build_tm_cs(const struct vpe_tonemap_params *tm_params, 288 const struct vpe_surface_info *surface_info, struct vpe_color_space *vcs); 289 290 enum vpe_status vpe_color_update_3dlut( 291 struct vpe_priv *vpe_priv, struct stream_ctx *stream_ctx, bool enable_3dlut); 292 293 bool vpe_color_update_regamma_tf(struct vpe_priv *vpe_priv, 294 enum color_transfer_func output_transfer_function, struct fixed31_32 x_scale, 295 struct fixed31_32 y_scale, struct fixed31_32 y_bias, bool can_bypass, 296 struct transfer_func *output_tf); 297 298 bool vpe_color_update_degamma_tf(struct vpe_priv *vpe_priv, enum color_transfer_func color_input_tf, 299 struct fixed31_32 x_scale, struct fixed31_32 y_scale, struct fixed31_32 y_bias, bool can_bypass, 300 struct transfer_func *input_tf); 301 302 enum color_range_type vpe_get_range_type( 303 enum color_space color_space, enum vpe_surface_pixel_format format); 304 305 #ifdef __cplusplus 306 } 307 #endif 308