Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30F93CE8D6B for ; Sat, 15 Nov 2025 00:21:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D9E3910EBED; Sat, 15 Nov 2025 00:21:13 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="cMCUmCv/"; dkim-atps=neutral Received: from MW6PR02CU001.outbound.protection.outlook.com (mail-westus2azon11012061.outbound.protection.outlook.com [52.101.48.61]) by gabe.freedesktop.org (Postfix) with ESMTPS id C394610EBED for ; Sat, 15 Nov 2025 00:21:12 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WJ10Wa0NgI7p1nddPNnaZDvl2t/KMSl0MOp8BoOze36fmM/0f4dP5wqp4utcyEBXfsq5Lua9QdqTftTkA0vqleM0+L0rLD55Yl+X42sgiBPaM5bAzmyUOwwJQaYA7vj87qpsYe6AeMLCbPyml+Btz2NX/rIfuk3+2fo6M8w8+JeFPMSLVi4LK41EU5OAJWhAMLiqX1P8TlW/s/TBbpiQ1xViy59FP9eJnD9c4+EBAGm4dNx4XbRc7bGNcTL5xatwTHNXKh0Lr7u9j7ejkKbeI4p719dh4TnEqSruLBHdsCyJsKIFMsX9SeVZD5L1gbZFvKUKO+S+ZVUAkIigVBbrDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aSlLZk2ZmXtzbNJrQE8+3b7mZhIsyJKvH+BHToOb4O4=; b=NTCIpJ1/acOtr/iYD/Mk7tXzvD2nCq/KLOXHiVjEYwYR4ynxnDSa4RIdFk7BUBS9/bpJ2IGIxzYK/nWOxSfLLuDGeH3WuNL9vCBgqnYBfb/qEonNG6whdXxPcPj4UGbNnay5MjacFu9vSrjzwzNf5QBWSSJReM09fTJGrGcQ+ToKZJE1zxKJXuz6Vg4Ja5uy9purY6pIIdxcojwTN+3opF011VfYhT0PC7dfaZz4ikODhoeNbKhtJgqObYEkTV7iob++O9Nv8mRIM7s/jAIbbxGG6X2Arw0z2sYg2UO9okYEaR5ZIFXi6/dLF2S1IZGGz2Tw8p3jG8F2VdwE5VcfjQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aSlLZk2ZmXtzbNJrQE8+3b7mZhIsyJKvH+BHToOb4O4=; b=cMCUmCv/qoifnnbWPcfumzSM1XeUbbqBIX8WKfcZ6LgA3U3xNPO3pVxVIbBREcDj+ytz/WIouWmtvcujRRbWCmd0eb7DqNkBqGKYioNU/1S7td+O90+r3VL9waGeT9/Y9/6IiPBYBOqPsTmy4QKeaOMKhI4OCWeErmFw1kQPIK8= Received: from BN1PR13CA0025.namprd13.prod.outlook.com (2603:10b6:408:e2::30) by DM4PR12MB7646.namprd12.prod.outlook.com (2603:10b6:8:106::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.18; Sat, 15 Nov 2025 00:21:05 +0000 Received: from BL6PEPF0001AB4A.namprd04.prod.outlook.com (2603:10b6:408:e2:cafe::b8) by BN1PR13CA0025.outlook.office365.com (2603:10b6:408:e2::30) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9343.7 via Frontend Transport; Sat, 15 Nov 2025 00:21:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BL6PEPF0001AB4A.mail.protection.outlook.com (10.167.242.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.13 via Frontend Transport; Sat, 15 Nov 2025 00:21:05 +0000 Received: from kylin.lan (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Fri, 14 Nov 2025 16:21:04 -0800 From: Alex Hung To: CC: , , , Leo Li Subject: [PATCH V12 11/32] tests/kms_colorop: Add kms_colorop tests Date: Fri, 14 Nov 2025 17:18:20 -0700 Message-ID: <20251115001841.3563993-12-alex.hung@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251115001841.3563993-1-alex.hung@amd.com> References: <20251115001841.3563993-1-alex.hung@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB4A:EE_|DM4PR12MB7646:EE_ X-MS-Office365-Filtering-Correlation-Id: badf217a-0df6-4a92-8d15-08de23dcddcc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|36860700013|1800799024|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Uh1UgYIdxs/J/jk/Tio8ciZy5DO3W6K+yS42132wtsJKmUlPpTPFDalWXiau?= =?us-ascii?Q?kVK9VnB+qEF8WC1cks2ZEW1LJ3Ns9C0SsOYH7SXlAzgCM3CpLaTAAcm/QKLG?= =?us-ascii?Q?M3kBfnQ5PRZIP6HscuLXx41EXulVXGvTezbdD2JtoSzzfSoWp5HZM2jqd7cq?= =?us-ascii?Q?2MVBwvFXCnz2tTI7e7pNlX0k0NzCILPe0HtSuRPp/yRU4zWMjVCgDrJe7H5E?= =?us-ascii?Q?vuBi+M6+pIdj7Cq0q7zdT7VxrxQyKupgpbzcbGjwYe8p7rEtNU2KMpqHfU0R?= =?us-ascii?Q?F18/XDN0YjHWSvJCA2VGEWGRSHNMVR8aqMnRXxFj1qTTNysJ68ak2UBGRwSF?= =?us-ascii?Q?nWTQIp6KyFbW2XZHOus+dVGD9TNjh12jDwKfIU+E4wzEYvy6/u/IB6cBlADz?= =?us-ascii?Q?FbrcSBN4fQPSKK2M7Dd8spsY6Xrd0TrjR2nPA2Jm4Xks/hfWXPau07iaikkl?= =?us-ascii?Q?y/jWhF5IJPPj8I/6YB8Q2lcRc+TT8MIbxylir/NrTMjaWVSEbQDIzYRppLAy?= =?us-ascii?Q?NG17GoEk4p73Tsw5sQr2sXsiY13zek0DPpjKXYFjYF/gQSKI1PMjIr3nJ24M?= =?us-ascii?Q?ZpTnawp4HtFrvOxM6K7s01F0Idhvo3dGcL18gxYlmJBOL1ksRvpFYv8ikeLx?= =?us-ascii?Q?55vIGS0dtnCHcFT8/5ETpHoRBnWQGut8OBru3HOhEUTPXjAC1FtfXSqJXNvA?= =?us-ascii?Q?plWyD9h6edhPMxdUmMPTq0fP09o+jx3sJfW6Mufb+O5l9A04ir6ljhSvR8aW?= =?us-ascii?Q?lkvVdUbzclNE9roQfeuBG0mmC1jtFEvPjKtJw10HndYticBGOl4tUZVo0ejx?= =?us-ascii?Q?HLb5+e6tzXh1eU6ZQdKcufFLWvnBX5SIgscWF9lyLrlHbhq7sS/fjy1VWL4v?= =?us-ascii?Q?cOCBO6IEHiSTpNCbtN3ceK9sXSCYko+78YHpEK6P/8y9YZXPwKslFRozN1QC?= =?us-ascii?Q?RqJNm7Jsiie0D14Tzxwflj96sIqSeKuqBGYYrvyLgDikCTDrrbPLVMHwK/aU?= =?us-ascii?Q?h4bPsggHBL9tAWaEpHlDafVJ45fNtibMK8CVhtap0kmAPSjBJh/56Edg0NXg?= =?us-ascii?Q?h6+H41mgM8CQv6obrXiy706HCJsyN7MtjFb8E7WT6nCpsSJ33WMfd9OkIb+k?= =?us-ascii?Q?4KnaaK6CP055eAnUy86exl0C9/W/dWgGI/xs+4sjkx1Urw/FfDAwBUjTXvWH?= =?us-ascii?Q?YniOMWkUBYEAcKK5oFrD2daU5CnpR2FqYLFLOXaJRYzwzsG0gsRrQdJSnzmF?= =?us-ascii?Q?amvSYw3xBcIP8y0bK/EJHh/79R9my4OO5Vi1O0TL50F9j87nb6zEyirlaIy9?= =?us-ascii?Q?zypQFh2a3/LnhtxO/Wj2WbYcMZHwg5AYcBbsTAz6cm5Q2cRnYM2x0e5sa+z1?= =?us-ascii?Q?fRQtrhpzEaEzdZ2iG7Rt2YULq6eUdw7EWBiEzRboIyvh3jWDBvHk8A5zrrdp?= =?us-ascii?Q?hZTCRfZ34qyL6cc098UZjNbNbH3dPVWTLJotT0lKYCm1G2Vq7lmKKV8Dk+ac?= =?us-ascii?Q?r9uNwX87jJuRtMxlVc+XijgFlg6FDN94Z62Z2sn+oReV41M8hqIbogSSVbRk?= =?us-ascii?Q?C+a8ocXsMS+1DgCdefw=3D?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(36860700013)(1800799024)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2025 00:21:05.3679 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: badf217a-0df6-4a92-8d15-08de23dcddcc X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB4A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7646 X-BeenThere: igt-dev@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development mailing list for IGT GPU Tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: igt-dev-bounces@lists.freedesktop.org Sender: "igt-dev" From: Harry Wentland This tests the color pipeline API, exposed via the COLOR PIPELINE plane property and drm_colorop objects. We introduce tests for: - sRGB EOTF - sRGB Inverse EOTF - sRGB EOTF + sRGB Inverse EOTF The last one is the holy grail of LUT testing. It tests that after applying an EOTF, followed by its inverse EOTF we arrive back at the original value. We can use this to test for precision loss in the pipeline. All tests are tested via writeback. All transforms are done in SW (in floating point) and at the end the SW transformed buffer is compared with the KMS writeback output buffer. The two should match within a bracket of acceptable deviations. Since these deviations might look different for different KMS drivers we'll do this check on a driver-specific basis. Signed-off-by: Alex Hung Signed-off-by: Harry Wentland Reviewed-by: Leo Li --- tests/kms_colorop.c | 472 ++++++++++++++++++++++++++++++++++++++++++++ tests/kms_colorop.h | 70 +++++++ tests/meson.build | 1 + 3 files changed, 543 insertions(+) create mode 100644 tests/kms_colorop.c create mode 100644 tests/kms_colorop.h diff --git a/tests/kms_colorop.c b/tests/kms_colorop.c new file mode 100644 index 000000000..a5e4f19e9 --- /dev/null +++ b/tests/kms_colorop.c @@ -0,0 +1,472 @@ +// SPDX-License-Identifier: MIT +/* + * Copyright 2025 Advanced Micro Devices, Inc. + */ + +#include "igt.h" +#include "igt_color.h" +#include "sw_sync.h" +#include "kms_colorop.h" + +/** + * TEST: kms colorop + * Category: Display + * Description: Test to validate the retrieving and setting of DRM colorops + * + * SUBTEST: plane-%s + * Description: Tests DRM colorop properties on a plane + * Driver requirement: amdgpu + * Functionality: kms_core + * Mega feature: General Display Features + * Test category: functionality test + * + * arg[1]: + * + * @srgb_eotf: sRGB EOTF + * @srgb_inv_eotf: sRGB Inverse EOTF + * @srgb_eotf-srgb_inv_eotf: sRGB EOTF -> sRGB Inverse EOTF + * + */ + +static bool check_writeback_config(igt_display_t *display, igt_output_t *output, + drmModeModeInfo override_mode) +{ + igt_fb_t input_fb, output_fb; + igt_plane_t *plane; + uint32_t writeback_format = DRM_FORMAT_XRGB8888; + uint64_t modifier = DRM_FORMAT_MOD_LINEAR; + int width, height, ret; + + igt_output_override_mode(output, &override_mode); + + width = override_mode.hdisplay; + height = override_mode.vdisplay; + + ret = igt_create_fb(display->drm_fd, width, height, + DRM_FORMAT_XRGB8888, modifier, &input_fb); + igt_assert(ret >= 0); + + ret = igt_create_fb(display->drm_fd, width, height, + writeback_format, modifier, &output_fb); + igt_assert(ret >= 0); + + plane = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); + igt_plane_set_fb(plane, &input_fb); + igt_output_set_writeback_fb(output, &output_fb); + + ret = igt_display_try_commit_atomic(display, DRM_MODE_ATOMIC_TEST_ONLY | + DRM_MODE_ATOMIC_ALLOW_MODESET, NULL); + igt_plane_set_fb(plane, NULL); + igt_remove_fb(display->drm_fd, &input_fb); + igt_remove_fb(display->drm_fd, &output_fb); + + return !ret; +} + +typedef struct { + bool dump_check; +} data_t; + +static data_t data; + +static igt_output_t *kms_writeback_get_output(igt_display_t *display) +{ + int i; + enum pipe pipe; + + drmModeModeInfo override_mode = { + .clock = 25175, + .hdisplay = 640, + .hsync_start = 656, + .hsync_end = 752, + .htotal = 800, + .hskew = 0, + .vdisplay = 480, + .vsync_start = 490, + .vsync_end = 492, + .vtotal = 525, + .vscan = 0, + .vrefresh = 60, + .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC, + .name = {"640x480-60"}, + }; + + for (i = 0; i < display->n_outputs; i++) { + igt_output_t *output = &display->outputs[i]; + + if (output->config.connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) + continue; + + for_each_pipe(display, pipe) { + igt_output_set_pipe(output, pipe); + + if (check_writeback_config(display, output, override_mode)) { + igt_debug("Using connector %u:%s on pipe %d\n", + output->config.connector->connector_id, + output->name, pipe); + return output; + } + } + + igt_debug("We found %u:%s, but this test will not be able to use it.\n", + output->config.connector->connector_id, output->name); + + /* Restore any connectors we don't use, so we don't trip on them later */ + kmstest_force_connector(display->drm_fd, output->config.connector, FORCE_CONNECTOR_UNSPECIFIED); + } + + return NULL; +} + +static bool can_use_colorop(igt_display_t *display, igt_colorop_t *colorop, kms_colorop_t *desired) +{ + switch (desired->type) { + case KMS_COLOROP_ENUMERATED_LUT1D: + if (igt_colorop_get_prop(display, colorop, IGT_COLOROP_TYPE) == DRM_COLOROP_1D_CURVE) + return true; + case KMS_COLOROP_CUSTOM_LUT1D: + case KMS_COLOROP_CTM: + case KMS_COLOROP_LUT3D: + default: + return false; + } +} + +/** + * Iterate color pipeline that begins with colorop and try to map + * colorops[] to it. + */ +static bool map_to_pipeline(igt_display_t *display, + igt_colorop_t *colorop, + kms_colorop_t *colorops[]) +{ + igt_colorop_t *next = colorop; + kms_colorop_t *current_op; + int i = 0; + int prop_val = 0; + + current_op = colorops[i++]; + igt_require(current_op); + + while (next) { + if (can_use_colorop(display, next, current_op)) { + current_op->colorop = next; + current_op = colorops[i++]; + if (!current_op) + break; + } + prop_val = igt_colorop_get_prop(display, next, + IGT_COLOROP_NEXT); + next = igt_find_colorop(display, prop_val); + } + + if (current_op) { + /* we failed to map the pipeline */ + + /* clean up colorops[i].colorop mappings */ + for (i = 0, current_op = colorops[0]; current_op; current_op = colorops[i++]) + current_op->colorop = NULL; + + return false; + } + + return true; +} + +static igt_colorop_t *get_color_pipeline(igt_display_t *display, + igt_plane_t *plane, + kms_colorop_t *colorops[]) +{ + igt_colorop_t *colorop = NULL; + int i; + + /* go through all color pipelines */ + for (i = 0; i < plane->num_color_pipelines; ++i) { + if (map_to_pipeline(display, plane->color_pipelines[i], colorops)) { + colorop = plane->color_pipelines[i]; + break; + } + } + + return colorop; +} + +static void set_colorop(igt_display_t *display, + kms_colorop_t *colorop) +{ + igt_assert(colorop->colorop); + igt_colorop_set_prop_value(colorop->colorop, IGT_COLOROP_BYPASS, 0); + + /* Set to desired value from kms_colorop_t */ + switch (colorop->type) { + case KMS_COLOROP_ENUMERATED_LUT1D: + switch (colorop->enumerated_lut1d_info.tf) { + case KMS_COLOROP_LUT1D_SRGB_EOTF: + igt_colorop_set_prop_enum(colorop->colorop, IGT_COLOROP_CURVE_1D_TYPE, "sRGB EOTF"); + break; + case KMS_COLOROP_LUT1D_SRGB_INV_EOTF: + igt_colorop_set_prop_enum(colorop->colorop, IGT_COLOROP_CURVE_1D_TYPE, "sRGB Inverse EOTF"); + break; + case KMS_COLOROP_LUT1D_PQ_EOTF: + case KMS_COLOROP_LUT1D_PQ_INV_EOTF: + default: + igt_fail(IGT_EXIT_FAILURE); + } + break; + case KMS_COLOROP_CUSTOM_LUT1D: + case KMS_COLOROP_CTM: + case KMS_COLOROP_LUT3D: + default: + igt_fail(IGT_EXIT_FAILURE); + } +} + +static void set_color_pipeline(igt_display_t *display, + igt_plane_t *plane, + kms_colorop_t *colorops[], + igt_colorop_t *color_pipeline) +{ + igt_colorop_t *next; + int prop_val = 0; + int i; + + igt_plane_set_color_pipeline(plane, color_pipeline); + + for (i = 0; colorops[i]; i++) + set_colorop(display, colorops[i]); + + /* set unused ops in pipeline to bypass */ + next = color_pipeline; + i = 0; + while (next) { + if (!colorops[i] || colorops[i]->colorop != next) + igt_colorop_set_prop_value(next, IGT_COLOROP_BYPASS, 1); + else + i++; + + prop_val = igt_colorop_get_prop(display, next, + IGT_COLOROP_NEXT); + next = igt_find_colorop(display, prop_val); + } +} + +static void set_color_pipeline_bypass(igt_plane_t *plane) +{ + igt_plane_set_prop_enum(plane, IGT_PLANE_COLOR_PIPELINE, "Bypass"); +} + +static bool compare_with_bracket(igt_fb_t *in, igt_fb_t *out) +{ + /* Each driver is expected to have its own bracket, i.e., by trial and error */ + if (is_vkms_device(in->fd)) + return igt_cmp_fb_pixels(in, out, 1, 1); + + /* + * By default we'll look for a [0, 0] bracket. We can then + * define it for each driver that implements support for this + * test. That way we can understand the precision of each + * driver better. + */ + return igt_cmp_fb_pixels(in, out, 0, 0); +} + +#define MAX_COLOROPS 3 +#define NUM_COLOROP_TESTS 3 +#define MAX_NAME_SIZE 256 + +static void apply_transforms(kms_colorop_t *colorops[], igt_fb_t *sw_transform_fb) +{ + int i; + igt_pixel_transform transforms[MAX_COLOROPS]; + + for (i = 0; colorops[i]; i++) + transforms[i] = colorops[i]->transform; + + igt_color_transform_pixels(sw_transform_fb, transforms, i); +} + +static void colorop_plane_test(igt_display_t *display, + kms_colorop_t *colorops[]) +{ + igt_colorop_t *color_pipeline = NULL; + igt_output_t *output; + igt_plane_t *plane; + igt_fb_t input_fb; + igt_fb_t sw_transform_fb; + igt_fb_t output_fb; + drmModeModeInfo mode; + unsigned int fb_id; + igt_crc_t input_crc, output_crc; + + output = kms_writeback_get_output(display); + igt_require(output); + + if (output->use_override_mode) + memcpy(&mode, &output->override_mode, sizeof(mode)); + else + memcpy(&mode, &output->config.default_mode, sizeof(mode)); + + /* create input fb */ + plane = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY); + igt_assert(plane); + + fb_id = igt_create_color_pattern_fb(display->drm_fd, + mode.hdisplay, mode.vdisplay, + DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_LINEAR, + 0.2, 0.2, 0.2, &input_fb); + igt_assert(fb_id >= 0); + igt_plane_set_fb(plane, &input_fb); + + if (data.dump_check) + igt_dump_fb(display, &input_fb, ".", "input"); + + /* create output fb */ + fb_id = igt_create_fb(display->drm_fd, mode.hdisplay, mode.vdisplay, + DRM_FORMAT_XRGB8888, + igt_fb_mod_to_tiling(0), + &output_fb); + igt_require(fb_id > 0); + + igt_fb_get_fnv1a_crc(&input_fb, &input_crc); + + igt_require(igt_plane_has_prop(plane, IGT_PLANE_COLOR_PIPELINE)); + + /* reset color pipeline*/ + + set_color_pipeline_bypass(plane); + + /* Commit */ + igt_plane_set_fb(plane, &input_fb); + igt_output_set_writeback_fb(output, &output_fb); + + igt_display_commit_atomic(output->display, + DRM_MODE_ATOMIC_ALLOW_MODESET, + NULL); + igt_get_and_wait_out_fence(output); + + /* Compare input and output buffers. They should be equal here. */ + igt_fb_get_fnv1a_crc(&output_fb, &output_crc); + + igt_assert_crc_equal(&input_crc, &output_crc); + + /* create sw transformed buffer */ + + igt_copy_fb(display->drm_fd, &input_fb, &sw_transform_fb); + igt_assert(igt_cmp_fb_pixels(&input_fb, &sw_transform_fb, 0, 0)); + + apply_transforms(colorops, &sw_transform_fb); + + if (data.dump_check) + igt_dump_fb(display, &sw_transform_fb, ".", "sw_transform"); + + /* discover and set COLOR PIPELINE */ + + /* get COLOR_PIPELINE enum */ + color_pipeline = get_color_pipeline(display, plane, colorops); + + /* skip test if we can't find applicable pipeline */ + igt_skip_on(!color_pipeline); + + set_color_pipeline(display, plane, colorops, color_pipeline); + + igt_output_set_writeback_fb(output, &output_fb); + + /* commit COLOR_PIPELINE */ + igt_display_commit_atomic(display, + DRM_MODE_ATOMIC_ALLOW_MODESET, + NULL); + igt_get_and_wait_out_fence(output); + + if (data.dump_check) + igt_dump_fb(display, &output_fb, ".", "output"); + + /* compare sw transformed and KMS transformed FBs */ + igt_assert(compare_with_bracket(&sw_transform_fb, &output_fb)); + + /* reset color pipeline*/ + set_color_pipeline_bypass(plane); + + /* Commit */ + igt_plane_set_fb(plane, &input_fb); + igt_output_set_writeback_fb(output, &output_fb); + + igt_display_commit_atomic(output->display, + DRM_MODE_ATOMIC_ALLOW_MODESET, + NULL); + igt_get_and_wait_out_fence(output); + + /* cleanup */ + igt_detach_crtc(display, output); + igt_remove_fb(display->drm_fd, &input_fb); + igt_remove_fb(display->drm_fd, &output_fb); +} + +static int opt_handler(int option, int option_index, void *_data) +{ + switch (option) { + case 'd': + data.dump_check = true; + break; + default: + return IGT_OPT_HANDLER_ERROR; + } + return IGT_OPT_HANDLER_SUCCESS; +} + +const char *help_str = + " --dump | -d Prints buffer to files.\n"; + +static const struct option long_options[] = { + { .name = "dump", .has_arg = false, .val = 'd', }, + {} +}; + +igt_main_args("d", long_options, help_str, opt_handler, NULL) +{ + + struct { + kms_colorop_t *colorops[MAX_COLOROPS]; + const char *name; + } tests[] = { + { { &kms_colorop_srgb_eotf, NULL }, "srgb_eotf" }, + { { &kms_colorop_srgb_inv_eotf, NULL }, "srgb_inv_eotf" }, + { { &kms_colorop_srgb_eotf, &kms_colorop_srgb_inv_eotf, NULL }, "srgb_eotf-srgb_inv_eotf" } + }; + + igt_display_t display; + int i, ret; + + igt_fixture { + display.drm_fd = drm_open_driver_master(DRIVER_ANY); + + if (drmSetClientCap(display.drm_fd, DRM_CLIENT_CAP_ATOMIC, 1) == 0) + display.is_atomic = 1; + + ret = drmSetClientCap(display.drm_fd, DRM_CLIENT_CAP_WRITEBACK_CONNECTORS, 1); + + igt_require_f(!ret, "error setting DRM_CLIENT_CAP_WRITEBACK_CONNECTORS\n"); + + igt_display_require(&display, display.drm_fd); + if (drmSetClientCap(display.drm_fd, DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE, 1) == 0) + display.has_plane_color_pipeline = 1; + + kmstest_set_vt_graphics_mode(); + + igt_display_require(&display, display.drm_fd); + if (drmSetClientCap(display.drm_fd, DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE, 1) == 0) + display.has_plane_color_pipeline = 1; + + igt_require(display.is_atomic); + + } + + for (i = 0; i < ARRAY_SIZE(tests); i++) { + igt_describe("Check color ops on a plane"); + igt_subtest_f("plane-%s", tests[i].name) + colorop_plane_test(&display, tests[i].colorops); + } + + igt_fixture { + igt_display_fini(&display); + } +} diff --git a/tests/kms_colorop.h b/tests/kms_colorop.h new file mode 100644 index 000000000..3c161f30d --- /dev/null +++ b/tests/kms_colorop.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Copyright 2025 Advanced Micro Devices, Inc. + */ + +#ifndef __KMS_COLOROP_H__ +#define __KMS_COLOROP_H__ + +#include "igt_color.h" + +typedef bool (*compare_fb_t)(igt_fb_t *in, igt_fb_t *out); + +typedef int (*transform_fb)(igt_fb_t *in); + +typedef int (*transform_pixel)(igt_pixel_t *pixel); + +/* Test version definitions */ +typedef enum kms_colorop_type { + KMS_COLOROP_ENUMERATED_LUT1D, + KMS_COLOROP_CUSTOM_LUT1D, + KMS_COLOROP_CTM, + KMS_COLOROP_LUT3D +} kms_colorop_type_t; + +typedef enum kms_colorop_lut1d_tf { + KMS_COLOROP_LUT1D_SRGB_EOTF, + KMS_COLOROP_LUT1D_SRGB_INV_EOTF, + KMS_COLOROP_LUT1D_PQ_EOTF, + KMS_COLOROP_LUT1D_PQ_INV_EOTF, +} kms_colorop_lut1d_tf_t; + +typedef struct kms_colorop_enumerated_lut1d_info { + kms_colorop_lut1d_tf_t tf; +} kms_colorop_enumerated_lut1d_info_t; + +typedef struct kms_colorop { + kms_colorop_type_t type; + + union { + kms_colorop_enumerated_lut1d_info_t enumerated_lut1d_info; + }; + + const char *name; + + igt_pixel_transform transform; + + /* Mapped colorop */ + igt_colorop_t *colorop; + +} kms_colorop_t; + +kms_colorop_t kms_colorop_srgb_eotf = { + .type = KMS_COLOROP_ENUMERATED_LUT1D, + .enumerated_lut1d_info = { + .tf = KMS_COLOROP_LUT1D_SRGB_EOTF + }, + .name = "srgb_eotf", + .transform = &igt_color_srgb_eotf +}; + +kms_colorop_t kms_colorop_srgb_inv_eotf = { + .type = KMS_COLOROP_ENUMERATED_LUT1D, + .enumerated_lut1d_info = { + .tf = KMS_COLOROP_LUT1D_SRGB_INV_EOTF + }, + .name = "srgb_inv_eotf", + .transform = &igt_color_srgb_inv_eotf +}; + +#endif /* __KMS_COLOROP_H__ */ diff --git a/tests/meson.build b/tests/meson.build index ecc0f4c7f..467481c28 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -26,6 +26,7 @@ test_progs = [ 'kms_bw', 'kms_color', 'kms_concurrent', + 'kms_colorop', 'kms_content_protection', 'kms_cursor_crc', 'kms_cursor_edge_walk', -- 2.43.0