Skip to content

Commit e5719e7

Browse files
Harry Wentlandemersion
authored andcommitted
drm/colorop: Add 3x4 CTM type
This type is used to support a 3x4 matrix in colorops. A 3x4 matrix uses the last column as a "bias" column. Some HW exposes support for 3x4. The calculation looks like: out matrix in |R| |0 1 2 3 | | R | |G| = |4 5 6 7 | x | G | |B| |8 9 10 11| | B | |1.0| This is also the first colorop where we need a blob property to program the property. For that we'll introduce a new DATA property that can be used by all colorop TYPEs requiring a blob. The way a DATA blob is read depends on the TYPE of the colorop. We only create the DATA property for property types that need it. Reviewed-by: Simon Ser <contact@emersion.fr> Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com> Signed-off-by: Alex Hung <alex.hung@amd.com> Signed-off-by: Harry Wentland <harry.wentland@amd.com> Reviewed-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Melissa Wen <mwen@igalia.com> Reviewed-by: Sebastian Wick <sebastian.wick@redhat.com> Signed-off-by: Simon Ser <contact@emersion.fr> Link: https://patch.msgid.link/20251115000237.3561250-19-alex.hung@amd.com
1 parent cb500b4 commit e5719e7

6 files changed

Lines changed: 136 additions & 10 deletions

File tree

drivers/gpu/drm/drm_atomic.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,9 @@ static void drm_atomic_colorop_print_state(struct drm_printer *p,
794794
drm_printf(p, "\tcurve_1d_type=%s\n",
795795
drm_get_colorop_curve_1d_type_name(state->curve_1d_type));
796796
break;
797+
case DRM_COLOROP_CTM_3X4:
798+
drm_printf(p, "\tdata blob id=%d\n", state->data ? state->data->base.id : 0);
799+
break;
797800
default:
798801
break;
799802
}

drivers/gpu/drm/drm_atomic_uapi.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,32 @@ drm_atomic_plane_get_property(struct drm_plane *plane,
689689
return 0;
690690
}
691691

692+
static int drm_atomic_color_set_data_property(struct drm_colorop *colorop,
693+
struct drm_colorop_state *state,
694+
struct drm_property *property,
695+
uint64_t val)
696+
{
697+
ssize_t elem_size = -1;
698+
ssize_t size = -1;
699+
bool replaced = false;
700+
701+
switch (colorop->type) {
702+
case DRM_COLOROP_CTM_3X4:
703+
size = sizeof(struct drm_color_ctm_3x4);
704+
break;
705+
default:
706+
/* should never get here */
707+
return -EINVAL;
708+
}
709+
710+
return drm_property_replace_blob_from_id(colorop->dev,
711+
&state->data,
712+
val,
713+
size,
714+
elem_size,
715+
&replaced);
716+
}
717+
692718
static int drm_atomic_colorop_set_property(struct drm_colorop *colorop,
693719
struct drm_colorop_state *state,
694720
struct drm_file *file_priv,
@@ -699,6 +725,9 @@ static int drm_atomic_colorop_set_property(struct drm_colorop *colorop,
699725
state->bypass = val;
700726
} else if (property == colorop->curve_1d_type_property) {
701727
state->curve_1d_type = val;
728+
} else if (property == colorop->data_property) {
729+
return drm_atomic_color_set_data_property(colorop, state,
730+
property, val);
702731
} else {
703732
drm_dbg_atomic(colorop->dev,
704733
"[COLOROP:%d:%d] unknown property [PROP:%d:%s]\n",
@@ -721,6 +750,8 @@ drm_atomic_colorop_get_property(struct drm_colorop *colorop,
721750
*val = state->bypass;
722751
else if (property == colorop->curve_1d_type_property)
723752
*val = state->curve_1d_type;
753+
else if (property == colorop->data_property)
754+
*val = (state->data) ? state->data->base.id : 0;
724755
else
725756
return -EINVAL;
726757

drivers/gpu/drm/drm_colorop.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
static const struct drm_prop_enum_list drm_colorop_type_enum_list[] = {
6666
{ DRM_COLOROP_1D_CURVE, "1D Curve" },
67+
{ DRM_COLOROP_CTM_3X4, "3x4 Matrix"},
6768
};
6869

6970
static const char * const colorop_curve_1d_type_names[] = {
@@ -147,6 +148,11 @@ void drm_colorop_cleanup(struct drm_colorop *colorop)
147148
list_del(&colorop->head);
148149
config->num_colorop--;
149150

151+
if (colorop->state && colorop->state->data) {
152+
drm_property_blob_put(colorop->state->data);
153+
colorop->state->data = NULL;
154+
}
155+
150156
kfree(colorop->state);
151157
}
152158
EXPORT_SYMBOL(drm_colorop_cleanup);
@@ -236,11 +242,51 @@ int drm_plane_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *
236242
}
237243
EXPORT_SYMBOL(drm_plane_colorop_curve_1d_init);
238244

245+
static int drm_colorop_create_data_prop(struct drm_device *dev, struct drm_colorop *colorop)
246+
{
247+
struct drm_property *prop;
248+
249+
/* data */
250+
prop = drm_property_create(dev, DRM_MODE_PROP_ATOMIC | DRM_MODE_PROP_BLOB,
251+
"DATA", 0);
252+
if (!prop)
253+
return -ENOMEM;
254+
255+
colorop->data_property = prop;
256+
drm_object_attach_property(&colorop->base,
257+
colorop->data_property,
258+
0);
259+
260+
return 0;
261+
}
262+
263+
int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
264+
struct drm_plane *plane)
265+
{
266+
int ret;
267+
268+
ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_CTM_3X4);
269+
if (ret)
270+
return ret;
271+
272+
ret = drm_colorop_create_data_prop(dev, colorop);
273+
if (ret)
274+
return ret;
275+
276+
drm_colorop_reset(colorop);
277+
278+
return 0;
279+
}
280+
EXPORT_SYMBOL(drm_plane_colorop_ctm_3x4_init);
281+
239282
static void __drm_atomic_helper_colorop_duplicate_state(struct drm_colorop *colorop,
240283
struct drm_colorop_state *state)
241284
{
242285
memcpy(state, colorop->state, sizeof(*state));
243286

287+
if (state->data)
288+
drm_property_blob_get(state->data);
289+
244290
state->bypass = true;
245291
}
246292

@@ -321,6 +367,7 @@ void drm_colorop_reset(struct drm_colorop *colorop)
321367

322368
static const char * const colorop_type_name[] = {
323369
[DRM_COLOROP_1D_CURVE] = "1D Curve",
370+
[DRM_COLOROP_CTM_3X4] = "3x4 Matrix",
324371
};
325372

326373
const char *drm_get_colorop_type_name(enum drm_colorop_type type)

include/drm/drm_colorop.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ struct drm_colorop_state {
9797
*/
9898
enum drm_colorop_curve_1d_type curve_1d_type;
9999

100+
/**
101+
* @data:
102+
*
103+
* Data blob for any TYPE that requires such a blob. The
104+
* interpretation of the blob is TYPE-specific.
105+
*
106+
* See the &drm_colorop_type documentation for how blob is laid
107+
* out.
108+
*/
109+
struct drm_property_blob *data;
110+
100111
/** @state: backpointer to global drm_atomic_state */
101112
struct drm_atomic_state *state;
102113
};
@@ -206,6 +217,17 @@ struct drm_colorop {
206217
*/
207218
struct drm_property *curve_1d_type_property;
208219

220+
/**
221+
* @data_property:
222+
*
223+
* blob property for any TYPE that requires a blob of data,
224+
* such as 1DLUT, CTM, 3DLUT, etc.
225+
*
226+
* The way this blob is interpreted depends on the TYPE of
227+
* this
228+
*/
229+
struct drm_property *data_property;
230+
209231
/**
210232
* @next_property:
211233
*
@@ -242,6 +264,8 @@ void drm_colorop_cleanup(struct drm_colorop *colorop);
242264

243265
int drm_plane_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *colorop,
244266
struct drm_plane *plane, u64 supported_tfs);
267+
int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
268+
struct drm_plane *plane);
245269

246270
struct drm_colorop_state *
247271
drm_atomic_helper_colorop_duplicate_state(struct drm_colorop *colorop);

include/uapi/drm/amdgpu_drm.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,15 +1656,6 @@ struct drm_amdgpu_info_uq_metadata {
16561656
#define AMDGPU_FAMILY_GC_11_5_0 150 /* GC 11.5.0 */
16571657
#define AMDGPU_FAMILY_GC_12_0_0 152 /* GC 12.0.0 */
16581658

1659-
/* FIXME wrong namespace! */
1660-
struct drm_color_ctm_3x4 {
1661-
/*
1662-
* Conversion matrix with 3x4 dimensions in S31.32 sign-magnitude
1663-
* (not two's complement!) format.
1664-
*/
1665-
__u64 matrix[12];
1666-
};
1667-
16681659
#if defined(__cplusplus)
16691660
}
16701661
#endif

include/uapi/drm/drm_mode.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,20 @@ struct drm_color_ctm {
847847
__u64 matrix[9];
848848
};
849849

850+
struct drm_color_ctm_3x4 {
851+
/*
852+
* Conversion matrix with 3x4 dimensions in S31.32 sign-magnitude
853+
* (not two's complement!) format.
854+
*
855+
* out matrix in
856+
* |R| |0 1 2 3 | | R |
857+
* |G| = |4 5 6 7 | x | G |
858+
* |B| |8 9 10 11| | B |
859+
* |1.0|
860+
*/
861+
__u64 matrix[12];
862+
};
863+
850864
struct drm_color_lut {
851865
/*
852866
* Values are mapped linearly to 0.0 - 1.0 range, with 0x0 == 0.0 and
@@ -874,7 +888,23 @@ enum drm_colorop_type {
874888
* A 1D curve that is being applied to all color channels. The
875889
* curve is specified via the CURVE_1D_TYPE colorop property.
876890
*/
877-
DRM_COLOROP_1D_CURVE
891+
DRM_COLOROP_1D_CURVE,
892+
893+
/**
894+
* @DRM_COLOROP_CTM_3X4:
895+
*
896+
* enum string "3x4 Matrix"
897+
*
898+
* A 3x4 matrix. Its values are specified via the
899+
* &drm_color_ctm_3x4 struct provided via the DATA property.
900+
*
901+
* The DATA blob is a float[12]:
902+
* out matrix in
903+
* | R | | 0 1 2 3 | | R |
904+
* | G | = | 4 5 6 7 | x | G |
905+
* | B | | 8 9 10 12 | | B |
906+
*/
907+
DRM_COLOROP_CTM_3X4,
878908
};
879909

880910
/**

0 commit comments

Comments
 (0)