From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4CC02FE0F for ; Sun, 2 Aug 2026 14:35:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785681334; cv=none; b=Q98Th1TLwSbwrOXPdfccu3ivf7PjbBTY9me13NXSpeVD4yycpZiK6i6Yptnr2P9UpYobfpiQPm+w3cQQcewa/MPopEQkWAqpd5aYSwJeNGaityrCKMJAIM3KOZ9XGhSVIjOMxYrPtGhr5S6isDco4vp8Vv7J6t02AmrJ2hVuFTM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785681334; c=relaxed/simple; bh=oqH75FqE8IN3bZrGBHwKUh3SutduxEVwzQjYhiN471I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cd/8CliW04qrh3E+3t02zN1SBYEMy5ce8Yam4u//d0Uj/KvGbcChvDdTT3rHcVyQBgxGOPjfMuBDkPoPaYIQtroEk0xWA42Ru514n2oJ3LKLRgg/xJ7lEt5p3c8qNCe3lsX/Nldc7rOzNrV3yseq7cU4KF9YrDf4tUQcN27y/x4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=g3LllBNO; arc=none smtp.client-ip=209.85.210.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g3LllBNO" Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-7e9d7464b71so1180498a34.0 for ; Sun, 02 Aug 2026 07:35:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785681331; x=1786286131; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Io4qfNiJxrvTXDG74iRNZw9/a8wNffmXNJvx5MlsNa4=; b=g3LllBNOX24yhW8sxCi0nDkuukyoW8JfKQaxSrEXOdhmOzpvWThRr5/SFj+ykWMbO5 FheRuEpKys2CF40YjdeWNbUzR2gvDbzKDX0ed8SaFuJR92O37JzTv9em8T24t1EnBTZ3 zKE7YVs9m1ZcYaVFZ5ueBxQIQm90SNELZ3lae+05CZYz2fC3HB5mQic3hP7ktn9IH2uw LPPJCDLoQhDExIQrSU0fzHpdrIDJ3L4EuWDXiRL7L9fzDWoZLCMO3gub6u7Ureq4Vswy LJvCqgxfMhSpFADRFdhRsqqMk5MbQLtZa1aWZEBhOFCX8f0lo+ns2IV3eYvc6Jod43gU ZhFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785681331; x=1786286131; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Io4qfNiJxrvTXDG74iRNZw9/a8wNffmXNJvx5MlsNa4=; b=XUdndiRKg1Irto54JgiMEc5+IG6/CJ9Jnz8Boc4BwM0nUYyDcKYyBr/C6tT/9aaGxI 2x7FqAWFRrzJw3Ho8rgI/28+GjPGKxD2gT7WItXqcOoGNdkj2PX46xrNoqMS67s82po0 Jun6iRnwLZhMzVbSan8HiowakHg0YaFcsq9XIn5lMEElKBC+MUYj1fvkVdctpFHMYIwK 1Oz5Pz5WBtGwqRN6Lc5+2YtVfa4Xut1xJR06DtycY7Amwiw3jjePwoHx0tvbWQWVDwMb ghD7JiDLkoCRarZn24fWRVwXMbVI47NgaUd1BZnDUzm0PxdH4mF0mkYXGhc3wb8tUejF is/Q== X-Forwarded-Encrypted: i=1; AHgh+RqCUM4/OUT9W9JQUFzS+B/kDEwvWxWtXdy/C39+wJGPHnka+nNLiay/IkttCTYIdaw2KmnFAhPNIOEwbyw=@vger.kernel.org X-Gm-Message-State: AOJu0YzxJ4mUBDbB3ZSFpd2DNty/JyLsOc2XtX5bb8a3LtBxw19LsomU 0kCQgKFGlEmOVifrKf5dmviPekw8NfD1BHmflOeY2nHipV+A4qmNuGuC X-Gm-Gg: AR+sD11bEKc/cPwannrmvnhoKDkii4WPsk5AsLjS9CITvdiisrMU34G+g29A0GDNLcw i/upWrjYp46Dc7/KZwSFLVc0nLmRLrcuP1Hv8S88OYzYLiTk7bQvF85hQDkerQiMShw1x0UuuHN eN6yf7/3XPCj3EKZNqlT2xG5DHGe6ThCxql5K6366jy1rjvxLl/DDmuXHrGyrFWmlJk7ea+jK2j f4etP+D9B27ah7cNhzJVlRpfdGG7G700ghkEPXO8pbdIjl79r2pcMMIuAAT+2IBIfKepuXBg9on HxomJx9nAwrMP+TNRwxzeHYKdtM0V4hzsndMSLpBb3sch8GF84ojFP7WO7/HVBaDERwZbQZwgfg RcwYuDGFOZQxxK8NwlNh3vPIvOi0OLmDJ/4XXLxq+UES0dxXnVPBCMukOUtmWUr2+H5aAzqGOWj NO8Gf6eFlyUUE1ffmvACUQ/o/UpZaQDqlKGUxQoqenJCLk1wN1LbW0BcKmjUt5iip/xKhUfc1li lWwZFr3iVF0jvE++kFg+bieHSPyrrLESU/sHopHzjkp X-Received: by 2002:a05:6808:17aa:b0:487:530f:5754 with SMTP id 5614622812f47-4af5e2f59b4mr12709212b6e.20.1785681331520; Sun, 02 Aug 2026 07:35:31 -0700 (PDT) Received: from natebox2.jabitha.com (46-110-104-162.wmnscoaa.metronetinc.net. [46.110.104.162]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4af58e9551dsm4778877b6e.11.2026.08.02.07.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2026 07:35:31 -0700 (PDT) From: Nathan Lucas To: amd-gfx@lists.freedesktop.org Cc: harry.wentland@amd.com, sunpeng.li@amd.com, siqueira@igalia.com, alexander.deucher@amd.com, joshua@froggi.es, mwen@igalia.com, leorize+oss@disroot.org, alex.hung@amd.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] drm/amd/display: fix BT.2020 YCbCr limited output CSC matrix Date: Sun, 2 Aug 2026 08:35:23 -0600 Message-ID: <2fcc52cc1a86d6e9e393e72f6038ae42ccf1930d.1785616749.git.nlucasgit@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit COLOR_SPACE_YCBCR2020_TYPE, which is selected for COLOR_SPACE_2020_YCBCR_LIMITED color_space, has coefficients that are incorrect for limited-range output. Its luma and chroma scaling is full-range so output is too bright and colors are incorrect. COLOR_SPACE_YCBCR2020_TYPE is closer to a full-range conversion matrix with incorrect luma offset, so correct the luma offset for full-range and rename it to COLOR_SPACE_YCBCR2020_FULL_TYPE. Add COLOR_SPACE_YCBCR2020_LIMITED_TYPE with correct scaling and range for limited-range output. Fix related functions so COLOR_SPACE_YCBCR2020_LIMITED_TYPE and COLOR_SPACE_YCBCR2020_FULL_TYPE are correctly selected based on dc_color_space. Derivation of both matrices follows ITU-T H.273: Table 4, MatrixCoefficients 9, BT.2020-NCL weights: KR = 0.2627, KB = 0.0593, KG = 1 - KR - KB = 0.6780. Equations 45-47 in matrix form: [ KR KG KB 0 ] M2020_NCL = [ -KR/(2(1-KB)) -KG/(2(1-KB)) 1/2 0 ] [ 1/2 -KG/(2(1-KR)) -KB/(2(1-KR)) 0 ] [ 0 0 0 1 ] Limited and Full transforms based on equations 30-32 and 36-38 with bit depth 10, normalized by 1023: [ 876/1023 0 0 64/1023 ] MLimited = [ 0 896/1023 0 512/1023 ] [ 0 0 896/1023 512/1023 ] [ 0 0 0 1 ] [ 1023/1023 0 0 0 ] MFull = [ 0 1023/1023 0 512/1023 ] [ 0 0 1023/1023 512/1023 ] [ 0 0 0 1 ] M2020_NCL_Limited = MLimited x M2020_NCL M2020_NCL_Full = MFull x M2020_NCL The upper three rows of M2020_NCL_* are stored in CR, Y, CB order. Each M2020_NCL_* value is stored as Round(value * 8192) in its 16-bit two's-complement representation. Fixes: 973a9c810c78 ("drm/amd/display: Fix COLOR_SPACE_YCBCR2020_TYPE matrix") Assisted-by: OpenAI-Codex:GPT-5.6-Sol Signed-off-by: Nathan Lucas --- .../drm/amd/display/dc/core/dc_hw_sequencer.c | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c b/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c index 11411fa94665..e686815f9a0e 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c @@ -59,7 +59,8 @@ enum dc_color_space_type { COLOR_SPACE_RGB_LIMITED_TYPE, COLOR_SPACE_YCBCR601_TYPE, COLOR_SPACE_YCBCR709_TYPE, - COLOR_SPACE_YCBCR2020_TYPE, + COLOR_SPACE_YCBCR2020_LIMITED_TYPE, + COLOR_SPACE_YCBCR2020_FULL_TYPE, COLOR_SPACE_YCBCR601_LIMITED_TYPE, COLOR_SPACE_YCBCR709_LIMITED_TYPE, COLOR_SPACE_YCBCR709_BLACK_TYPE, @@ -111,9 +112,15 @@ static const struct out_csc_color_matrix_type output_csc_matrix[] = { { 0xE00, 0xF349, 0xFEB7, 0x1000, 0x6CE, 0x16E3, 0x24F, 0x200, 0xFCCB, 0xF535, 0xE00, 0x1000} }, - { COLOR_SPACE_YCBCR2020_TYPE, + /* Corrected. Not included in the TODO above. */ + { COLOR_SPACE_YCBCR2020_LIMITED_TYPE, + { 0x0E04, 0xF31D, 0xFEDF, 0x1004, + 0x0733, 0x1294, 0x01A0, 0x0201, + 0xFC16, 0xF5E6, 0x0E04, 0x1004} }, + /* Corrected. Not included in the TODO above. */ + { COLOR_SPACE_YCBCR2020_FULL_TYPE, { 0x1000, 0xF149, 0xFEB7, 0x1004, - 0x0868, 0x15B2, 0x01E6, 0x201, + 0x0868, 0x15B2, 0x01E6, 0, 0xFB88, 0xF478, 0x1000, 0x1004} }, { COLOR_SPACE_YCBCR709_BLACK_TYPE, { 0x0000, 0x0000, 0x0000, 0x1000, @@ -180,14 +187,14 @@ static bool is_ycbcr709_type( return ret; } -static bool is_ycbcr2020_type( - enum dc_color_space color_space) +static bool is_ycbcr2020_limited_type(enum dc_color_space color_space) { - bool ret = false; + return color_space == COLOR_SPACE_2020_YCBCR_LIMITED; +} - if (color_space == COLOR_SPACE_2020_YCBCR_LIMITED || color_space == COLOR_SPACE_2020_YCBCR_FULL) - ret = true; - return ret; +static bool is_ycbcr2020_full_type(enum dc_color_space color_space) +{ + return color_space == COLOR_SPACE_2020_YCBCR_FULL; } static bool is_ycbcr709_limited_type( @@ -216,8 +223,10 @@ static enum dc_color_space_type get_color_space_type(enum dc_color_space color_s type = COLOR_SPACE_YCBCR601_LIMITED_TYPE; else if (is_ycbcr709_limited_type(color_space)) type = COLOR_SPACE_YCBCR709_LIMITED_TYPE; - else if (is_ycbcr2020_type(color_space)) - type = COLOR_SPACE_YCBCR2020_TYPE; + else if (is_ycbcr2020_limited_type(color_space)) + type = COLOR_SPACE_YCBCR2020_LIMITED_TYPE; + else if (is_ycbcr2020_full_type(color_space)) + type = COLOR_SPACE_YCBCR2020_FULL_TYPE; else if (color_space == COLOR_SPACE_YCBCR709) type = COLOR_SPACE_YCBCR709_BLACK_TYPE; else if (color_space == COLOR_SPACE_YCBCR709_BLACK) -- 2.55.0