From 39b08da80a6a147cd37fe75d3e1e7446ee2f6737 Mon Sep 17 00:00:00 2001 From: chiachih Date: Sat, 27 Apr 2024 09:38:07 +0800 Subject: [PATCH] amd/vpelib: Resolve mismatch with shader Shader in SDR mode with NV12 input bypasses both primary and gamma conversions. Since in this case for RGB output p601 primary can be set for the output primary, vpe should be able to set that primary for output as well. Reviewed-by: Roy Chan Acked-by: Jack Chih Signed-off-by: Navid Assadian --- Part-of: --- .../vpelib/src/chip/vpe10/vpe10_cm_common.c | 3 +- src/amd/vpelib/src/chip/vpe10/vpe10_dpp.c | 1 + .../vpelib/src/chip/vpe10/vpe10_resource.c | 4 +-- src/amd/vpelib/src/core/color.c | 33 +++++++++++++------ .../vpelib/src/core/inc/vpe_visual_confirm.h | 2 +- src/amd/vpelib/src/core/vpe_visual_confirm.c | 4 +-- 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/amd/vpelib/src/chip/vpe10/vpe10_cm_common.c b/src/amd/vpelib/src/chip/vpe10/vpe10_cm_common.c index 720b4572e3a..d3b34044041 100644 --- a/src/amd/vpelib/src/chip/vpe10/vpe10_cm_common.c +++ b/src/amd/vpelib/src/chip/vpe10/vpe10_cm_common.c @@ -251,7 +251,8 @@ bool vpe10_cm_helper_translate_curve_to_hw_format( seg_distr[i] = 1; region_start = -MAX_LOW_POINT; region_end = 1; - } else if (output_tf->tf == TRANSFER_FUNC_LINEAR_0_125) { + } else if (output_tf->tf == TRANSFER_FUNC_LINEAR_0_125 || + output_tf->tf == TRANSFER_FUNC_LINEAR_0_1) { int num_regions_linear = MAX_LOW_POINT + 3; diff --git a/src/amd/vpelib/src/chip/vpe10/vpe10_dpp.c b/src/amd/vpelib/src/chip/vpe10/vpe10_dpp.c index 043754972d6..0f32dd1d904 100644 --- a/src/amd/vpelib/src/chip/vpe10/vpe10_dpp.c +++ b/src/amd/vpelib/src/chip/vpe10/vpe10_dpp.c @@ -333,6 +333,7 @@ void vpe10_dpp_cnv_program_pre_dgam(struct dpp *dpp, enum color_transfer_func tr switch (tr) { case TRANSFER_FUNC_LINEAR_0_125: + case TRANSFER_FUNC_LINEAR_0_1: pre_degam_en = 0; // bypass break; case TRANSFER_FUNC_SRGB: diff --git a/src/amd/vpelib/src/chip/vpe10/vpe10_resource.c b/src/amd/vpelib/src/chip/vpe10/vpe10_resource.c index f7efa71eff6..eb60b777a60 100644 --- a/src/amd/vpelib/src/chip/vpe10/vpe10_resource.c +++ b/src/amd/vpelib/src/chip/vpe10/vpe10_resource.c @@ -959,12 +959,12 @@ void vpe10_create_stream_ops_config(struct vpe_priv *vpe_priv, uint32_t pipe_idx if (ops == VPE_CMD_OPS_BG_VSCF_INPUT) { blndcfg.bg_color = vpe_get_visual_confirm_color(stream_ctx->stream.surface_info.format, stream_ctx->stream.surface_info.cs, vpe_priv->output_ctx.cs, - vpe_priv->output_ctx.output_tf, + vpe_priv->output_ctx.output_tf, vpe_priv->output_ctx.surface.format, (stream_ctx->stream.tm_params.UID != 0 || stream_ctx->stream.tm_params.enable_3dlut)); } else if (ops == VPE_CMD_OPS_BG_VSCF_OUTPUT) { blndcfg.bg_color = vpe_get_visual_confirm_color(vpe_priv->output_ctx.surface.format, vpe_priv->output_ctx.surface.cs, vpe_priv->output_ctx.cs, - vpe_priv->output_ctx.output_tf, + vpe_priv->output_ctx.output_tf, vpe_priv->output_ctx.surface.format, false); // 3DLUT should only affect input visual confirm } else { blndcfg.bg_color = vpe_priv->output_ctx.bg_color; diff --git a/src/amd/vpelib/src/core/color.c b/src/amd/vpelib/src/core/color.c index 4ed7969ca57..30651d665cf 100644 --- a/src/amd/vpelib/src/core/color.c +++ b/src/amd/vpelib/src/core/color.c @@ -451,6 +451,9 @@ static enum vpe_status vpe_update_blnd_gamma( tf = output_ctx->tf; } + if (vpe_is_fp16(param->dst_surface.format)) { + y_scale = vpe_fixpt_mul_int(y_scale, CCCS_NORM); + } color_update_regamma_tf(vpe_priv, tf, x_scale, @@ -511,19 +514,19 @@ static enum vpe_status vpe_update_output_gamma( struct output_ctx *output_ctx = &vpe_priv->output_ctx; bool is_studio = (param->dst_surface.cs.range == VPE_COLOR_RANGE_STUDIO); enum vpe_status status = VPE_STATUS_OK; + struct fixed31_32 y_scale = vpe_fixpt_one; + + if (vpe_is_fp16(param->dst_surface.format)) { + y_scale = vpe_fixpt_mul_int(y_scale, CCCS_NORM); + } if (vpe_is_HDR(output_ctx->tf) && !is_studio) can_bypass = false; //Blending is done in linear light so ogam needs to handle the regam else can_bypass = true; - color_update_regamma_tf(vpe_priv, - output_ctx->tf, - vpe_fixpt_one, - vpe_fixpt_one, - vpe_fixpt_zero, - can_bypass, - output_tf); + color_update_regamma_tf( + vpe_priv, output_ctx->tf, vpe_fixpt_one, y_scale, vpe_fixpt_zero, can_bypass, output_tf); return status; } @@ -673,6 +676,7 @@ enum vpe_status vpe_color_update_color_space_and_tf( struct fixed31_32 new_matrix_scaling_factor; struct output_ctx *output_ctx = &vpe_priv->output_ctx; enum vpe_status status = VPE_STATUS_OK; + struct fixed31_32 y_scale = vpe_fixpt_one; status = vpe_allocate_cm_memory(vpe_priv, param); if (status == VPE_STATUS_OK) { @@ -710,9 +714,13 @@ enum vpe_status vpe_color_update_color_space_and_tf( } if (stream_ctx->dirty_bits.transfer_function) { + if (vpe_is_fp16(stream_ctx->stream.surface_info.format)) { + y_scale = vpe_fixpt_div_int(y_scale, CCCS_NORM); + } + color_update_degamma_tf(vpe_priv, stream_ctx->tf, vpe_priv->stream_ctx->tf_scaling_factor, - vpe_fixpt_one, + y_scale, vpe_fixpt_zero, stream_ctx->stream.tm_params.UID != 0 || stream_ctx->stream.tm_params.enable_3dlut, // By Pass degamma if 3DLUT is enabled stream_ctx->input_tf); @@ -887,7 +895,7 @@ void vpe_color_get_color_space_and_tf( *tf = TRANSFER_FUNC_NORMALIZED_PQ; break; case VPE_TF_G10: - *tf = TRANSFER_FUNC_LINEAR_0_125; + *tf = TRANSFER_FUNC_LINEAR_0_1; break; case VPE_TF_SRGB: *tf = TRANSFER_FUNC_SRGB; @@ -932,6 +940,10 @@ void vpe_color_get_color_space_and_tf( } } else { switch (vcs->primaries) { + case VPE_PRIMARIES_BT601: + *cs = colorRange == VPE_COLOR_RANGE_FULL ? COLOR_SPACE_YCBCR601 + : COLOR_SPACE_YCBCR601_LIMITED; + break; case VPE_PRIMARIES_BT709: if (vcs->tf == VPE_TF_G10) { *cs = COLOR_SPACE_MSREF_SCRGB; @@ -991,7 +1003,8 @@ void vpe_convert_full_range_color_enum(enum color_space *cs) bool vpe_is_HDR(enum color_transfer_func tf) { - return (tf == TRANSFER_FUNC_PQ2084 || tf == TRANSFER_FUNC_LINEAR_0_125 || tf == TRANSFER_FUNC_HLG); + return (tf == TRANSFER_FUNC_PQ2084 || tf == TRANSFER_FUNC_LINEAR_0_125 || + tf == TRANSFER_FUNC_HLG || tf == TRANSFER_FUNC_LINEAR_0_1); } /* diff --git a/src/amd/vpelib/src/core/inc/vpe_visual_confirm.h b/src/amd/vpelib/src/core/inc/vpe_visual_confirm.h index 9206d6d6f9c..0a7b03aa54a 100644 --- a/src/amd/vpelib/src/core/inc/vpe_visual_confirm.h +++ b/src/amd/vpelib/src/core/inc/vpe_visual_confirm.h @@ -33,7 +33,7 @@ extern "C" { struct vpe_color vpe_get_visual_confirm_color(enum vpe_surface_pixel_format format, struct vpe_color_space cs, enum color_space output_cs, struct transfer_func *output_tf, - bool enable_3dLut); + enum vpe_surface_pixel_format output_format, bool enable_3dLut); enum vpe_status vpe_create_visual_confirm_segs( struct vpe_priv *vpe_priv, const struct vpe_build_param *params, uint32_t max_seg_width); diff --git a/src/amd/vpelib/src/core/vpe_visual_confirm.c b/src/amd/vpelib/src/core/vpe_visual_confirm.c index a29919cec4d..f5fd34147c4 100644 --- a/src/amd/vpelib/src/core/vpe_visual_confirm.c +++ b/src/amd/vpelib/src/core/vpe_visual_confirm.c @@ -65,7 +65,7 @@ static uint16_t vpe_get_visual_confirm_total_seg_count( struct vpe_color vpe_get_visual_confirm_color(enum vpe_surface_pixel_format format, struct vpe_color_space cs, enum color_space output_cs, struct transfer_func *output_tf, - bool enable_3dlut) + enum vpe_surface_pixel_format output_format, bool enable_3dlut) { struct vpe_color visual_confirm_color; visual_confirm_color.is_ycbcr = false; @@ -148,7 +148,7 @@ struct vpe_color vpe_get_visual_confirm_color(enum vpe_surface_pixel_format form vpe_bg_color_convert(output_cs, output_tf, &visual_confirm_color, enable_3dlut); // Experimental: To make FP16 Linear color looks more visually ok - if (output_tf->tf == TRANSFER_FUNC_LINEAR_0_125) { + if (vpe_is_fp16(output_format)) { visual_confirm_color.rgba.r /= 125; visual_confirm_color.rgba.g /= 125; visual_confirm_color.rgba.b /= 125;