Skip to content

Commit 6872a18

Browse files
misyltoadalexdeucher
authored andcommitted
drm/amd/display: Add 3x4 CTM support for plane CTM
Create drm_color_ctm_3x4 to support 3x4-dimension plane CTM matrix and convert DRM CTM to DC CSC float matrix. v3: - rename ctm2 to ctm_3x4 (Harry) Reviewed-by: Harry Wentland <harry.wentland@amd.com> Signed-off-by: Joshua Ashton <joshua@froggi.es> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 3dad690 commit 6872a18

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,28 @@ static void __drm_ctm_to_dc_matrix(const struct drm_color_ctm *ctm,
434434
}
435435
}
436436

437+
/**
438+
* __drm_ctm_3x4_to_dc_matrix - converts a DRM CTM 3x4 to a DC CSC float matrix
439+
* @ctm: DRM color transformation matrix with 3x4 dimensions
440+
* @matrix: DC CSC float matrix
441+
*
442+
* The matrix needs to be a 3x4 (12 entry) matrix.
443+
*/
444+
static void __drm_ctm_3x4_to_dc_matrix(const struct drm_color_ctm_3x4 *ctm,
445+
struct fixed31_32 *matrix)
446+
{
447+
int i;
448+
449+
/* The format provided is S31.32, using signed-magnitude representation.
450+
* Our fixed31_32 is also S31.32, but is using 2's complement. We have
451+
* to convert from signed-magnitude to 2's complement.
452+
*/
453+
for (i = 0; i < 12; i++) {
454+
/* gamut_remap_matrix[i] = ctm[i - floor(i/4)] */
455+
matrix[i] = dc_fixpt_from_s3132(ctm->matrix[i]);
456+
}
457+
}
458+
437459
/**
438460
* __set_legacy_tf - Calculates the legacy transfer function
439461
* @func: transfer function
@@ -1173,7 +1195,7 @@ int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc,
11731195
{
11741196
struct amdgpu_device *adev = drm_to_adev(crtc->base.state->dev);
11751197
struct dm_plane_state *dm_plane_state = to_dm_plane_state(plane_state);
1176-
struct drm_color_ctm *ctm = NULL;
1198+
struct drm_color_ctm_3x4 *ctm = NULL;
11771199
struct dc_color_caps *color_caps = NULL;
11781200
bool has_crtc_cm_degamma;
11791201
int ret;
@@ -1228,7 +1250,7 @@ int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc,
12281250

12291251
/* Setup CRTC CTM. */
12301252
if (dm_plane_state->ctm) {
1231-
ctm = (struct drm_color_ctm *)dm_plane_state->ctm->data;
1253+
ctm = (struct drm_color_ctm_3x4 *)dm_plane_state->ctm->data;
12321254
/*
12331255
* DCN2 and older don't support both pre-blending and
12341256
* post-blending gamut remap. For this HW family, if we have
@@ -1240,7 +1262,7 @@ int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc,
12401262
* mapping CRTC CTM to MPC and keeping plane CTM setup at DPP,
12411263
* as it's done by dcn30_program_gamut_remap().
12421264
*/
1243-
__drm_ctm_to_dc_matrix(ctm, dc_plane_state->gamut_remap_matrix.matrix);
1265+
__drm_ctm_3x4_to_dc_matrix(ctm, dc_plane_state->gamut_remap_matrix.matrix);
12441266

12451267
dc_plane_state->gamut_remap_matrix.enable_remap = true;
12461268
dc_plane_state->input_csc_color_matrix.enable_adjustment = false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ dm_atomic_plane_set_property(struct drm_plane *plane,
15611561
ret = drm_property_replace_blob_from_id(plane->dev,
15621562
&dm_plane_state->ctm,
15631563
val,
1564-
sizeof(struct drm_color_ctm), -1,
1564+
sizeof(struct drm_color_ctm_3x4), -1,
15651565
&replaced);
15661566
dm_plane_state->base.color_mgmt_changed |= replaced;
15671567
return ret;

include/uapi/drm/drm_mode.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,14 @@ struct drm_color_ctm {
846846
__u64 matrix[9];
847847
};
848848

849+
struct drm_color_ctm_3x4 {
850+
/*
851+
* Conversion matrix with 3x4 dimensions in S31.32 sign-magnitude
852+
* (not two's complement!) format.
853+
*/
854+
__u64 matrix[12];
855+
};
856+
849857
struct drm_color_lut {
850858
/*
851859
* Values are mapped linearly to 0.0 - 1.0 range, with 0x0 == 0.0 and

0 commit comments

Comments
 (0)