Skip to content

Commit 9ba2591

Browse files
Alex Hungemersion
authored andcommitted
drm/amd/display: Add support for sRGB EOTF in DEGAM block
Expose one 1D curve colorop with support for DRM_COLOROP_1D_CURVE_SRGB_EOTF and program HW to perform the sRGB transform when the colorop is not in bypass. With this change the following IGT test passes: kms_colorop --run plane-XR30-XR30-srgb_eotf The color pipeline now consists of a single colorop: 1. 1D curve colorop w/ sRGB EOTF Signed-off-by: Alex Hung <alex.hung@amd.com> Co-developed-by: Harry Wentland <harry.wentland@amd.com> Signed-off-by: Harry Wentland <harry.wentland@amd.com> Reviewed-by: Daniel Stone <daniels@collabora.com> Signed-off-by: Simon Ser <contact@emersion.fr> Link: https://patch.msgid.link/20251115000237.3561250-29-alex.hung@amd.com
1 parent af755a7 commit 9ba2591

5 files changed

Lines changed: 211 additions & 3 deletions

File tree

drivers/gpu/drm/amd/display/amdgpu_dm/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ AMDGPUDM = \
3939
amdgpu_dm_psr.o \
4040
amdgpu_dm_replay.o \
4141
amdgpu_dm_quirks.o \
42-
amdgpu_dm_wb.o
42+
amdgpu_dm_wb.o \
43+
amdgpu_dm_colorop.o
4344

4445
ifdef CONFIG_DRM_AMD_DC_FP
4546
AMDGPUDM += dc_fpu.o

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,18 @@ amdgpu_tf_to_dc_tf(enum amdgpu_transfer_function tf)
667667
}
668668
}
669669

670+
static enum dc_transfer_func_predefined
671+
amdgpu_colorop_tf_to_dc_tf(enum drm_colorop_curve_1d_type tf)
672+
{
673+
switch (tf) {
674+
case DRM_COLOROP_1D_CURVE_SRGB_EOTF:
675+
case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF:
676+
return TRANSFER_FUNCTION_SRGB;
677+
default:
678+
return TRANSFER_FUNCTION_LINEAR;
679+
}
680+
}
681+
670682
static void __to_dc_lut3d_color(struct dc_rgb *rgb,
671683
const struct drm_color_lut lut,
672684
int bit_precision)
@@ -1177,6 +1189,59 @@ __set_dm_plane_degamma(struct drm_plane_state *plane_state,
11771189
return 0;
11781190
}
11791191

1192+
static int
1193+
__set_colorop_in_tf_1d_curve(struct dc_plane_state *dc_plane_state,
1194+
struct drm_colorop_state *colorop_state)
1195+
{
1196+
struct dc_transfer_func *tf = &dc_plane_state->in_transfer_func;
1197+
struct drm_colorop *colorop = colorop_state->colorop;
1198+
struct drm_device *drm = colorop->dev;
1199+
1200+
if (colorop->type != DRM_COLOROP_1D_CURVE ||
1201+
colorop_state->curve_1d_type != DRM_COLOROP_1D_CURVE_SRGB_EOTF)
1202+
return -EINVAL;
1203+
1204+
if (colorop_state->bypass) {
1205+
tf->type = TF_TYPE_BYPASS;
1206+
tf->tf = TRANSFER_FUNCTION_LINEAR;
1207+
return 0;
1208+
}
1209+
1210+
drm_dbg(drm, "Degamma colorop with ID: %d\n", colorop->base.id);
1211+
1212+
tf->type = TF_TYPE_PREDEFINED;
1213+
tf->tf = amdgpu_colorop_tf_to_dc_tf(colorop_state->curve_1d_type);
1214+
1215+
return 0;
1216+
}
1217+
1218+
static int
1219+
__set_dm_plane_colorop_degamma(struct drm_plane_state *plane_state,
1220+
struct dc_plane_state *dc_plane_state,
1221+
struct drm_colorop *colorop)
1222+
{
1223+
struct drm_colorop *old_colorop;
1224+
struct drm_colorop_state *colorop_state = NULL, *new_colorop_state;
1225+
struct drm_atomic_state *state = plane_state->state;
1226+
int i = 0;
1227+
1228+
old_colorop = colorop;
1229+
1230+
/* 1st op: 1d curve - degamma */
1231+
for_each_new_colorop_in_state(state, colorop, new_colorop_state, i) {
1232+
if (new_colorop_state->colorop == old_colorop &&
1233+
new_colorop_state->curve_1d_type == DRM_COLOROP_1D_CURVE_SRGB_EOTF) {
1234+
colorop_state = new_colorop_state;
1235+
break;
1236+
}
1237+
}
1238+
1239+
if (!colorop_state)
1240+
return -EINVAL;
1241+
1242+
return __set_colorop_in_tf_1d_curve(dc_plane_state, colorop_state);
1243+
}
1244+
11801245
static int
11811246
amdgpu_dm_plane_set_color_properties(struct drm_plane_state *plane_state,
11821247
struct dc_plane_state *dc_plane_state)
@@ -1227,6 +1292,24 @@ amdgpu_dm_plane_set_color_properties(struct drm_plane_state *plane_state,
12271292
return 0;
12281293
}
12291294

1295+
static int
1296+
amdgpu_dm_plane_set_colorop_properties(struct drm_plane_state *plane_state,
1297+
struct dc_plane_state *dc_plane_state)
1298+
{
1299+
struct drm_colorop *colorop = plane_state->color_pipeline;
1300+
int ret;
1301+
1302+
/* 1D Curve - DEGAM TF */
1303+
if (!colorop)
1304+
return -EINVAL;
1305+
1306+
ret = __set_dm_plane_colorop_degamma(plane_state, dc_plane_state, colorop);
1307+
if (ret)
1308+
return ret;
1309+
1310+
return 0;
1311+
}
1312+
12301313
/**
12311314
* amdgpu_dm_update_plane_color_mgmt: Maps DRM color management to DC plane.
12321315
* @crtc: amdgpu_dm crtc state
@@ -1323,5 +1406,8 @@ int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc,
13231406
dc_plane_state->input_csc_color_matrix.enable_adjustment = false;
13241407
}
13251408

1409+
if (!amdgpu_dm_plane_set_colorop_properties(plane_state, dc_plane_state))
1410+
return 0;
1411+
13261412
return amdgpu_dm_plane_set_color_properties(plane_state, dc_plane_state);
13271413
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: MIT
2+
/*
3+
* Copyright 2023 Advanced Micro Devices, Inc.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a
6+
* copy of this software and associated documentation files (the "Software"),
7+
* to deal in the Software without restriction, including without limitation
8+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
* and/or sell copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21+
* OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* Authors: AMD
24+
*
25+
*/
26+
27+
#include <drm/drm_print.h>
28+
#include <drm/drm_plane.h>
29+
#include <drm/drm_property.h>
30+
#include <drm/drm_colorop.h>
31+
32+
#include "amdgpu_dm_colorop.h"
33+
34+
const u64 amdgpu_dm_supported_degam_tfs =
35+
BIT(DRM_COLOROP_1D_CURVE_SRGB_EOTF);
36+
37+
#define MAX_COLOR_PIPELINE_OPS 10
38+
39+
int amdgpu_dm_initialize_default_pipeline(struct drm_plane *plane, struct drm_prop_enum_list *list)
40+
{
41+
struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS];
42+
struct drm_device *dev = plane->dev;
43+
int ret;
44+
int i = 0;
45+
46+
memset(ops, 0, sizeof(ops));
47+
48+
/* 1D curve - DEGAM TF */
49+
ops[i] = kzalloc(sizeof(*ops[0]), GFP_KERNEL);
50+
if (!ops[i]) {
51+
ret = -ENOMEM;
52+
goto cleanup;
53+
}
54+
55+
ret = drm_plane_colorop_curve_1d_init(dev, ops[i], plane, amdgpu_dm_supported_degam_tfs);
56+
if (ret)
57+
goto cleanup;
58+
59+
list->type = ops[i]->base.id;
60+
list->name = kasprintf(GFP_KERNEL, "Color Pipeline %d", ops[i]->base.id);
61+
62+
return 0;
63+
64+
cleanup:
65+
if (ret == -ENOMEM)
66+
drm_err(plane->dev, "KMS: Failed to allocate colorop\n");
67+
68+
drm_colorop_pipeline_destroy(dev);
69+
70+
return ret;
71+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* SPDX-License-Identifier: MIT */
2+
/*
3+
* Copyright 2023 Advanced Micro Devices, Inc.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a
6+
* copy of this software and associated documentation files (the "Software"),
7+
* to deal in the Software without restriction, including without limitation
8+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
9+
* and/or sell copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21+
* OTHER DEALINGS IN THE SOFTWARE.
22+
*
23+
* Authors: AMD
24+
*
25+
*/
26+
27+
#ifndef __AMDGPU_DM_COLOROP_H__
28+
#define __AMDGPU_DM_COLOROP_H__
29+
30+
extern const u64 amdgpu_dm_supported_degam_tfs;
31+
32+
int amdgpu_dm_initialize_default_pipeline(struct drm_plane *plane, struct drm_prop_enum_list *list);
33+
34+
#endif /* __AMDGPU_DM_COLOROP_H__*/

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "amdgpu_display.h"
3838
#include "amdgpu_dm_trace.h"
3939
#include "amdgpu_dm_plane.h"
40+
#include "amdgpu_dm_colorop.h"
4041
#include "gc/gc_11_0_0_offset.h"
4142
#include "gc/gc_11_0_0_sh_mask.h"
4243

@@ -1790,13 +1791,28 @@ static int
17901791
dm_plane_init_colorops(struct drm_plane *plane)
17911792
{
17921793
struct drm_prop_enum_list pipelines[MAX_COLOR_PIPELINES];
1794+
struct drm_device *dev = plane->dev;
1795+
struct amdgpu_device *adev = drm_to_adev(dev);
1796+
struct dc *dc = adev->dm.dc;
17931797
int len = 0;
1798+
int ret;
17941799

17951800
if (plane->type == DRM_PLANE_TYPE_CURSOR)
17961801
return 0;
17971802

1798-
/* Create COLOR_PIPELINE property and attach */
1799-
drm_plane_create_color_pipeline_property(plane, pipelines, len);
1803+
/* initialize pipeline */
1804+
if (dc->ctx->dce_version >= DCN_VERSION_3_0) {
1805+
ret = amdgpu_dm_initialize_default_pipeline(plane, &pipelines[len]);
1806+
if (ret) {
1807+
drm_err(plane->dev, "Failed to create color pipeline for plane %d: %d\n",
1808+
plane->base.id, ret);
1809+
return ret;
1810+
}
1811+
len++;
1812+
1813+
/* Create COLOR_PIPELINE property and attach */
1814+
drm_plane_create_color_pipeline_property(plane, pipelines, len);
1815+
}
18001816

18011817
return 0;
18021818
}

0 commit comments

Comments
 (0)