Skip to content

Commit 4d28e8d

Browse files
committed
drm: GAMMA_LUT_3D (wip)
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
1 parent 1d97609 commit 4d28e8d

File tree

Image for: File tree

9 files changed

Image for: 9 files changed
+93
-3
lines changed

9 files changed

Image for: 9 files changed
+93
-3
lines changed

‎drivers/gpu/drm/drm_atomic_helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3554,10 +3554,10 @@ int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc,
35543554
goto fail;
35553555
}
35563556

3557-
/* Reset DEGAMMA_LUT and CTM properties. */
35583557
replaced = drm_property_replace_blob(&crtc_state->degamma_lut, NULL);
35593558
replaced |= drm_property_replace_blob(&crtc_state->ctm, NULL);
35603559
replaced |= drm_property_replace_blob(&crtc_state->gamma_lut, blob);
3560+
replaced |= drm_property_replace_blob(&crtc_state->gamma_lut_3d, NULL);
35613561
crtc_state->color_mgmt_changed |= replaced;
35623562

35633563
ret = drm_atomic_commit(state);

‎drivers/gpu/drm/drm_atomic_state_helper.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
141141
drm_property_blob_get(state->ctm);
142142
if (state->gamma_lut)
143143
drm_property_blob_get(state->gamma_lut);
144+
if (state->gamma_lut_3d)
145+
drm_property_blob_get(state->gamma_lut_3d);
144146
state->mode_changed = false;
145147
state->active_changed = false;
146148
state->planes_changed = false;
@@ -213,6 +215,7 @@ void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
213215
drm_property_blob_put(state->degamma_lut);
214216
drm_property_blob_put(state->ctm);
215217
drm_property_blob_put(state->gamma_lut);
218+
drm_property_blob_put(state->gamma_lut_3d);
216219
}
217220
EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
218221

‎drivers/gpu/drm/drm_atomic_uapi.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,14 @@ static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
471471
&replaced);
472472
state->color_mgmt_changed |= replaced;
473473
return ret;
474+
} else if (property == config->gamma_lut_3d_property) {
475+
ret = drm_atomic_replace_property_blob_from_id(dev,
476+
&state->gamma_lut_3d,
477+
val,
478+
-1, sizeof(struct drm_color_lut),
479+
&replaced);
480+
state->color_mgmt_changed |= replaced;
481+
return ret;
474482
} else if (property == config->prop_out_fence_ptr) {
475483
s32 __user *fence_ptr = u64_to_user_ptr(val);
476484

@@ -516,6 +524,8 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc,
516524
*val = (state->ctm) ? state->ctm->base.id : 0;
517525
else if (property == config->gamma_lut_property)
518526
*val = (state->gamma_lut) ? state->gamma_lut->base.id : 0;
527+
else if (property == config->gamma_lut_3d_property)
528+
*val = (state->gamma_lut_3d) ? state->gamma_lut_3d->base.id : 0;
519529
else if (property == config->prop_out_fence_ptr)
520530
*val = 0;
521531
else if (property == crtc->scaling_filter_property)

‎drivers/gpu/drm/drm_color_mgmt.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,29 @@
8888
* largest size, and sub-sample smaller sized LUTs (e.g. for split-gamma
8989
* modes) appropriately.
9090
*
91+
* “GAMMA_LUT_3D”:
92+
* Blob property to set the current 3D LUT apply to pixel data after
93+
* the lookup through the gamma LUT. The data is interpreted as a struct
94+
* &drm_color_lut.
95+
*
96+
* The 3D LUT is stored in the following order:
97+
* output=lut[red*sz*sz+green*sz+blue],
98+
* where sz=GAMMA_LUT_3D_SIZE, and red,green,blue are
99+
* the input values in the range [0,sz-1].
100+
*
101+
* Setting this to NULL (blob property value set to 0) means a
102+
* unit/pass-thru matrix should be used. This is generally the driver
103+
* boot-up state too. Drivers can access the blob for the color conversion
104+
* matrix through &drm_crtc_state.lut_3d.
105+
*
106+
* “GAMMA_LUT_3D_SIZE”:
107+
* Unsigned range property to give the size of the lookup table to be set
108+
* on the GAMMA_LUT_3D property (the size depends on the underlying hardware).
109+
* This is the size of a single dimension of the LUT, so the LUT will have
110+
* GAMMA_LUT_3D_SIZE^3 total entries.
111+
* If drivers support multiple LUT sizes then they should publish the
112+
* largest size, and sub-sample smaller sized LUTs appropriately.
113+
*
91114
* There is also support for a legacy gamma table, which is set up by calling
92115
* drm_mode_crtc_set_gamma_size(). Drivers which support both should use
93116
* drm_atomic_helper_legacy_gamma_set() to alias the legacy gamma ramp with the
@@ -190,6 +213,22 @@ void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
190213
}
191214
EXPORT_SYMBOL(drm_crtc_enable_color_mgmt);
192215

216+
void drm_crtc_enable_gamma_lut_3d(struct drm_crtc *crtc,
217+
unsigned int gamma_lut_3d_size)
218+
{
219+
struct drm_device *dev = crtc->dev;
220+
struct drm_mode_config *config = &dev->mode_config;
221+
222+
if (gamma_lut_3d_size) {
223+
drm_object_attach_property(&crtc->base,
224+
config->gamma_lut_3d_property, 0);
225+
drm_object_attach_property(&crtc->base,
226+
config->gamma_lut_3d_size_property,
227+
gamma_lut_3d_size);
228+
}
229+
}
230+
EXPORT_SYMBOL(drm_crtc_enable_gamma_lut_3d);
231+
193232
/**
194233
* drm_mode_crtc_set_gamma_size - set the gamma table size
195234
* @crtc: CRTC to set the gamma table size for

‎drivers/gpu/drm/drm_fb_helper.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,8 @@ static int setcmap_atomic(struct fb_cmap *cmap, struct fb_info *info)
10591059
replaced |= drm_property_replace_blob(&crtc_state->ctm, NULL);
10601060
replaced |= drm_property_replace_blob(&crtc_state->gamma_lut,
10611061
gamma_lut);
1062+
replaced |= drm_property_replace_blob(&crtc_state->gamma_lut_3d,
1063+
NULL);
10621064
crtc_state->color_mgmt_changed |= replaced;
10631065
}
10641066

‎drivers/gpu/drm/drm_mode_config.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,20 @@ static int drm_mode_create_standard_properties(struct drm_device *dev)
364364
return -ENOMEM;
365365
dev->mode_config.gamma_lut_size_property = prop;
366366

367+
prop = drm_property_create(dev,
368+
DRM_MODE_PROP_BLOB,
369+
"GAMMA_LUT_3D", 0);
370+
if (!prop)
371+
return -ENOMEM;
372+
dev->mode_config.gamma_lut_3d_property = prop;
373+
374+
prop = drm_property_create_range(dev,
375+
DRM_MODE_PROP_IMMUTABLE,
376+
"GAMMA_LUT_3D_SIZE", 0, UINT_MAX);
377+
if (!prop)
378+
return -ENOMEM;
379+
dev->mode_config.gamma_lut_3d_size_property = prop;
380+
367381
prop = drm_property_create(dev,
368382
DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_BLOB,
369383
"IN_FORMATS", 0);

‎include/drm/drm_color_mgmt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
5959
bool has_ctm,
6060
uint gamma_lut_size);
6161

62+
void drm_crtc_enable_gamma_lut_3d(struct drm_crtc *crtc,
63+
unsigned int gamma_lut_3d_size);
64+
6265
int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
6366
int gamma_size);
6467

‎include/drm/drm_crtc.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ struct drm_crtc_state {
165165
bool zpos_changed : 1;
166166
/**
167167
* @color_mgmt_changed: Color management properties have changed
168-
* (@gamma_lut, @degamma_lut or @ctm). Used by the atomic helpers and
169-
* drivers to steer the atomic commit control flow.
168+
* (@gamma_lut, @degamma_lut, @ctm, @gamma_lut_3d). Used by the atomic
169+
* helpers and drivers to steer the atomic commit control flow.
170170
*/
171171
bool color_mgmt_changed : 1;
172172

@@ -288,6 +288,15 @@ struct drm_crtc_state {
288288
*/
289289
struct drm_property_blob *gamma_lut;
290290

291+
/**
292+
* @gamma_lut_3d:
293+
*
294+
* 3D LUT for converting pixel data adter @gamma_lut.
295+
* See drm_crtc_enable_color_mgmt(). The blob (if not NULL)
296+
* is a &struct drm_color_lut.
297+
*/
298+
struct drm_property_blob *gamma_lut_3d;
299+
291300
/**
292301
* @target_vblank:
293302
*

‎include/drm/drm_mode_config.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,16 @@ struct drm_mode_config {
799799
* gamma LUT as supported by the driver (read-only).
800800
*/
801801
struct drm_property *gamma_lut_size_property;
802+
/**
803+
* @gamma_lut_3d_property: Optional CRTC property to set the 3D LUT
804+
* used to convert the colors, after the gamma LUT.
805+
*/
806+
struct drm_property *gamma_lut_3d_property;
807+
/**
808+
* @gamma_lut_3d_size_property: Optional CRTC property for the size
809+
* of the 3D LUT as supported by the driver (read-only).
810+
*/
811+
struct drm_property *gamma_lut_3d_size_property;
802812

803813
/**
804814
* @suggested_x_property: Optional connector property with a hint for

0 commit comments

Image for: 0 commit comments
Comments
 (0)