Color Pipeline API w/ VKMS
Subsystems (6)
Harry Wentland
maintainerv4 cover Color Pipeline API w/ VKMS
This is an RFC set for a color pipeline API, along with a sample implementation in VKMS. All the key API bits are here. VKMS now supports two named transfer function colorops and two matrix colorops. We have IGT tests that check all four of these colorops with a pixel-by-pixel comparison that checks that these colorops do what we expect them to do with a +/- 1 8 bpc code point margin.
The big new change with v4 is the addition of an amdgpu color pipeline, for all AMD GPUs with DCN 3 and newer. Amdgpu now support the following:
1. 1D Curve EOTF
2. 3x4 CTM
3. Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 1D Curve EOTF
7. 1D LUT
The supported curves for the 1D Curve type are:
- sRGB EOTF and its inverse
- PQ EOTF, scaled to [0.0, 125.0] and its inverse
- BT.2020/BT.709 OETF and its inverse
Note that the 1st and 5th colorops take the EOTF or Inverse OETF while the 3rd colorop takes the Inverse EOTF or OETF.
We are working on two more ops for amdgpu, the HDR multiplier and the 3DLUT, which will give us this:
1. 1D Curve EOTF
2. 3x4 CTM
3. HDR Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 3D LUT
7. 1D Curve EOTF
8. 1D LUT
This, essentially mirrors the color pipeline used by gamescope
and presented by Melissa Wen, with the exception of the DEGAM
LUT, which is not currently used. See
[1] https://indico.freedesktop.org/event/4/contributions/186/attachments/138/218/xdc2023-TheRainbowTreasureMap-MelissaWen.pdf
After this we'd like to also add the following ops:
- Scaler (Informational only)
- Color Encoding, to replace drm_plane's COLOR_ENCODING
- Color Range, to replace drm_plane's COLOR_RANGE
This patchset is grouped as follows:
- Patches 1-3: couple general patches/fixes
- Patches 4-7: introduce kunit to VKMS
- Patch 7: description of motivation and details behind the Color Pipeline API. If you're reading nothing else but are interested in the topic I highly recommend you take a look at this.
- Patches 7-27: DRM core and VKMS changes for color pipeline API
- Patches 28-40: DRM core and amdgpu changes for color pipeline API
VKMS patches could still be improved in a few ways, though the payoff might be limited and I would rather focus on other work at the moment. The most obvious thing to improve would be to eliminate the hard-coded LUTs for identity, and sRGB, and replace them with fixed-point math instead.
There are plenty of things that I would like to see here but haven't had a chance to look at. These will (hopefully) be addressed in future iterations, either in VKMS or amdgpu:
- Clear documentation for each drm_colorop_type
- Add custom LUT colorops to VKMS
- Add pre-blending 3DLUT
- How to support HW which can't bypass entire pipeline?
- Add ability to create colorops that don't have BYPASS
- Can we do a LOAD / COMMIT model for LUTs (and other properties)?
- read-only scaling colorop which defines scaling taps and position
- read-only color format colorop to define supported color formats for a pipeline
- named matrices, for things like converting YUV to RGB
IGT tests can be found at
https://gitlab.freedesktop.org/hwentland/igt-gpu-tools/-/merge_requests/1
IGT patches are also being sent to the igt-dev mailing list.
If you prefer a gitlab MR for review you can find it at
https://gitlab.freedesktop.org/hwentland/linux/-/merge_requests/5
v4:
- Add amdgpu color pipeline (WIP)
- Don't block setting of deprecated properties, instead pass client cap to atomic check so drivers can ignore these props
- Drop IOCTL definitions (Pekka)
- Use enum property for colorop TYPE (Pekka)
- A few cleanups to the docs (Pekka)
- Rework the TYPE enum to name relation to avoid code duplication (Pekka)
- Add missing function declarations (Chaitanya Kumar Borah)
- Allow setting of NEXT property to NULL in _set_ function (Chaitanya Kumar Borah)
- Add helper for creation of pipeline drm_plane property (Pekka)
- Always create Bypass pipeline (Pekka)
- A bunch of changes to VKMS kunit tests (Pekka)
- Fix index in CTM doc (Pekka)
v3:
- Abandon IOCTLs and discover colorops as clients iterate the pipeline
- Remove need for libdrm
- Add color_pipeline client cap and make mutually exclusive with COLOR_RANGE and COLOR_ENCODING properties
- add CTM colorop to VKMS
- Use include way for kunit testing static functions (Arthur)
- Make TYPE a range property
- Move enum drm_colorop_type to uapi header
- and a bunch of smaller bits that are highlighted in the relevant commit description
v2:
- Rebased on drm-misc-next
- Introduce a VKMS Kunit so we can test LUT functionality in vkms_composer
- Incorporate feedback in color_pipeline.rst doc
- Add support for sRGB inverse EOTF
- Add 2nd enumerated TF colorop to VKMS
- Fix LUTs and some issues with applying LUTs in VKMS
Alex Hung (10):
drm/colorop: define a new macro for_each_new_colorop_in_state drm/amd/display: Skip color pipeline initialization for cursor plane drm/amd/display: Add support for sRGB EOTF in DEGAM block drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block drm/amd/display: Add support for sRGB EOTF in BLND block drm/colorop: Add 1D Curve Custom LUT type
drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT drm/amd/display: add 3x4 matrix colorop
drm/colorop: Add mutliplier type
drm/amd/display: add multiplier colorop
Harry Wentland (32):
drm: Don't treat 0 as -1 in drm_fixp2int_ceil
drm: Add helper for conversion from signed-magnitude
drm: Correctly round for fixp2int_round
drm/vkms: Round fixp2int conversion in lerp_u16
drm/vkms: Create separate Kconfig file for VKMS
drm/vkms: Add kunit tests for VKMS LUT handling
drm/vkms: Avoid reading beyond LUT array
drm/doc/rfc: Describe why prescriptive color pipeline is needed drm/colorop: Introduce new drm_colorop mode object drm/colorop: Add TYPE property
drm/colorop: Add 1D Curve subtype
drm/colorop: Add BYPASS property
drm/colorop: Add NEXT property
drm/colorop: Add atomic state print for drm_colorop drm/plane: Add COLOR PIPELINE property
drm/colorop: Add NEXT to colorop state print
drm/vkms: Add enumerated 1D curve colorop
drm/vkms: Add kunit tests for linear and sRGB LUTs drm/colorop: Introduce DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE drm/colorop: Add 3x4 CTM type
drm/vkms: Pull apply_colorop out of pre_blend_color_transform drm/vkms: Use s32 for internal color pipeline precision drm/vkms: add 3x4 matrix in color pipeline
drm/tests: Add a few tests around drm_fixed.h
drm/vkms: Add tests for CTM handling
drm/colorop: pass plane_color_pipeline client cap to atomic check drm/amd/display: Ignore deprecated props when plane_color_pipeline set drm/amd/display: Add bypass COLOR PIPELINE
drm/colorop: Add PQ 125 EOTF and its inverse drm/amd/display: Enable support for PQ 125 EOTF and Inverse drm/colorop: add BT2020/BT709 OETF and Inverse OETF drm/amd/display: Add support for BT.709 and BT.2020 TFs
Documentation/gpu/rfc/color_pipeline.rst | 360 ++++++++ drivers/gpu/drm/Kconfig | 14 +- drivers/gpu/drm/Makefile | 1 + .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 352 ++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 160 ++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 36 + .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 32 + drivers/gpu/drm/drm_atomic.c | 161 +++- drivers/gpu/drm/drm_atomic_helper.c | 12 + drivers/gpu/drm/drm_atomic_state_helper.c | 5 + drivers/gpu/drm/drm_atomic_uapi.c | 158 ++++ drivers/gpu/drm/drm_colorop.c | 411 +++++++++ drivers/gpu/drm/drm_ioctl.c | 7 + drivers/gpu/drm/drm_mode_config.c | 7 + drivers/gpu/drm/drm_plane.c | 52 ++ drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_fixp_test.c | 69 ++ drivers/gpu/drm/vkms/Kconfig | 20 + drivers/gpu/drm/vkms/Makefile | 4 +- drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 449 ++++++++++ drivers/gpu/drm/vkms/vkms_colorop.c | 100 +++ drivers/gpu/drm/vkms/vkms_composer.c | 135 ++- drivers/gpu/drm/vkms/vkms_drv.h | 8 + drivers/gpu/drm/vkms/vkms_luts.c | 802 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 2 + include/drm/drm_atomic.h | 122 +++ include/drm/drm_atomic_uapi.h | 3 + include/drm/drm_colorop.h | 301 +++++++ include/drm/drm_file.h | 7 + include/drm/drm_fixed.h | 35 +- include/drm/drm_mode_config.h | 18 + include/drm/drm_plane.h | 13 + include/uapi/drm/drm.h | 16 + include/uapi/drm/drm_mode.h | 14 + 38 files changed, 3882 insertions(+), 30 deletions(-) create mode 100644 Documentation/gpu/rfc/color_pipeline.rst create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h create mode 100644 drivers/gpu/drm/drm_colorop.c create mode 100644 drivers/gpu/drm/tests/drm_fixp_test.c create mode 100644 drivers/gpu/drm/vkms/Kconfig create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/vkms_color_tests.c create mode 100644 drivers/gpu/drm/vkms/vkms_colorop.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.h create mode 100644 include/drm/drm_colorop.h
--
2.44.0
Harry Wentland
maintainerRFC PATCH v4 1/42 drm: Don't treat 0 as -1 in drm_fixp2int_ceil
Unit testing this in VKMS shows that passing 0 into this function returns -1, which is highly counter- intuitive. Fix it by checking whether the input is
Quoted 1 line
= 0 instead of > 0.
--- include/drm/drm_fixed.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/drm/drm_fixed.h +1 -1
@@ -95,7 +95,7 @@ static inline int drm_fixp2int_round(s64 a)static inline int drm_fixp2int_ceil (s64 a) { -if (a >0 ) +if (a >=0 )return drm_fixp2int (a +DRM_FIXED_ALMOST_ONE );else return drm_fixp2int (a -DRM_FIXED_ALMOST_ONE );
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 01/42] drm: Don't treat 0 as -1 in drm_fixp2int_ceil
Quoted 9 lines · Harry Wentland
Unit testing this in VKMS shows that passing 0 into this function returns -1, which is highly counter- intuitive. Fix it by checking whether the input is
Quoted 1 line
= 0 instead of > 0.
Fixes 64566b5e767f9 ("drm: Add drm_fixp_from_fraction and drm_fixp2int_ceil")Signed-off-by Harry Wentland <[email protected]>Reviewed-by Simon Ser <[email protected]>Reviewed-by Melissa Wen <[email protected]>
It was already applied upstream:
https://cgit.freedesktop.org/drm/drm-misc/commit/include?id=cf8837d7204481026335461629b84ac7f4538fa5
Thanks
Melissa
Quoted 20 lines
--- include/drm/drm_fixed.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/drm/drm_fixed.h +1
-1@@ -95,7 +95,7 @@ static inline int drm_fixp2int_round(s64 a)static inline int drm_fixp2int_ceil (s64 a) { -if (a >0 ) +if (a >=0 )return drm_fixp2int (a +DRM_FIXED_ALMOST_ONE );else return drm_fixp2int (a -DRM_FIXED_ALMOST_ONE );Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 2/42 drm: Add helper for conversion from signed-magnitude
In reply to Harry WentlandCTM values are defined as signed-magnitude values. Add a helper that converts from CTM signed-magnitude fixed point value to the twos-complement value used by drm_fixed.
--- include/drm/drm_fixed.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
include/drm/drm_fixed.h +18 -0
@@ -78,6 +78,24 @@ static inline u32 dfixed_div(fixed20_12 A, fixed20_12 B)#define DRM_FIXED_EPSILON 1LL#define DRM_FIXED_ALMOST_ONE (DRM_FIXED_ONE - DRM_FIXED_EPSILON) +/** +* @drm_sm2fixp +* +* Convert a 1.31.32 signed-magnitude fixed point to 32.32 +* 2s-complement fixed point +* +* @return s64 2s-complement fixed point +*/ +static inline s64 drm_sm2fixp (__u64 a) +{ +if ((a & (1LL <<63 ))) { +return -(a &0x7fffffffffffffffll ); + }else { +return a; + } + +} +static inline s64 drm_int2fixp (int a) {return ((s64 )a) <<DRM_FIXED_POINT ;
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 02/42] drm: Add helper for conversion from signed-magnitude
Quoted 20 lines · Harry Wentland
CTM values are defined as signed-magnitude values. Add a helper that converts from CTM signed-magnitude fixed point value to the twos-complement value used by
drm_fixed.Signed-off-by Harry Wentland <[email protected]>--- include/drm/drm_fixed.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)include/drm/drm_fixed.h +2
-0@@ -78,6 +78,24 @@ static inline u32 dfixed_div(fixed20_12 A, fixed20_12 B)#define DRM_FIXED_EPSILON 1LL#define DRM_FIXED_ALMOST_ONE (DRM_FIXED_ONE - DRM_FIXED_EPSILON) +/** +* @drm_sm2fixp
include/drm/drm_fixed.h static inline u32 dfixed_div(fixed20_12 A, fixed20_12 B) · line 92
Quoted 10 lines
include/drm/drm_fixed.h +10
-0+* +* Convert a 1.31.32 signed-magnitude fixed point to 32.32 +* 2s-complement fixed point +* +* @return s64 2s-complement fixed point +*/ +static inline s64 drm_sm2fixp (__u64 a) +{ +if ((a & (1LL <<63 ))) { +return -(a &0x7fffffffffffffffll );
Hi Harry,
Can we have a #define macro for this constant? ^ Other than that, LGTM. You can add my r-b to the next version.
Thanks,
Melissa
Quoted 12 lines
include/drm/drm_fixed.h +6
-0+ }else { +return a; + } + +} +static inline s64 drm_int2fixp (int a) {return ((s64 )a) <<DRM_FIXED_POINT ;Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 3/42 drm: Correctly round for fixp2int_round
In reply to Harry WentlandA value of 0x80000000 and higher should round up, and below should round down. VKMS Kunit tests for lerp_u16 showed that this is not the case. Fix it.
1 << (DRM_FIXED_POINT_HALF - 1) =
1 << 15 = 0x8000
This is not 0.5, but 0.00000762939453125.
Instead of some smart math use a simple if/else to round up or down. This helps people like me to understand what the function does.
--- include/drm/drm_fixed.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
include/drm/drm_fixed.h +10 -5
@@ -77,6 +77,8 @@ static inline u32 dfixed_div(fixed20_12 A, fixed20_12 B)#define DRM_FIXED_DIGITS_MASK (~DRM_FIXED_DECIMAL_MASK)#define DRM_FIXED_EPSILON 1LL#define DRM_FIXED_ALMOST_ONE (DRM_FIXED_ONE - DRM_FIXED_EPSILON) +#define DRM_FIXED_FRACTIONAL 0xffffffffll +#define DRM_FIXED_HALF 0x80000000ll/** * @drm_sm2fixp
@@ -106,11 +108,6 @@ static inline int drm_fixp2int(s64 a)return ((s64 )a) >>DRM_FIXED_POINT ; } -static inline int drm_fixp2int_round (s64 a) -{ -return drm_fixp2int (a + (1 << (DRM_FIXED_POINT_HALF -1 ))); -} -static inline int drm_fixp2int_ceil (s64 a) {if (a >=0 )
@@ -119,6 +116,14 @@ static inline int drm_fixp2int_ceil(s64 a)return drm_fixp2int (a -DRM_FIXED_ALMOST_ONE ); } +static inline int drm_fixp2int_round (s64 a) +{ +if ((a &DRM_FIXED_FRACTIONAL ) <DRM_FIXED_HALF ) +return drm_fixp2int (a); +else +return drm_fixp2int_ceil (a); +} +static inline unsigned drm_fixp_msbset (s64 a) {unsigned shift, sign = (a >>63 ) &1 ;
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 03/42] drm: Correctly round for fixp2int_round
Quoted 44 lines · On Mon, 26 Feb 2024 16:10:17 -0500 Harry Wentland <[email protected]>…
A value of
0x80000000and higher should round up, and below should round down. VKMS Kunit tests forlerp_u16showed that this is not the case. Fix it.1 << (
DRM_FIXED_POINT_HALF- 1) =
1 << 15 =0x8000This is not 0.5, but 0.00000762939453125.
Instead of some smart math use a simple if/else to round up or down. This helps people like me to understand what the function does.
Signed-off-by Harry Wentland <[email protected]>--- include/drm/drm_fixed.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)include/drm/drm_fixed.h +2
-5@@ -77,6 +77,8 @@ static inline u32 dfixed_div(fixed20_12 A, fixed20_12 B)#define DRM_FIXED_DIGITS_MASK (~DRM_FIXED_DECIMAL_MASK)#define DRM_FIXED_EPSILON 1LL#define DRM_FIXED_ALMOST_ONE (DRM_FIXED_ONE - DRM_FIXED_EPSILON) +#define DRM_FIXED_FRACTIONAL 0xffffffffll +#define DRM_FIXED_HALF 0x80000000ll/** * @drm_sm2fixp @@ -106,11 +108,6 @@ static inline int drm_fixp2int(s64 a)return ((s64 )a) >>DRM_FIXED_POINT ; } -static inline int drm_fixp2int_round (s64 a) -{ -return drm_fixp2int (a + (1 << (DRM_FIXED_POINT_HALF -1 ))); -} -static inline int drm_fixp2int_ceil (s64 a) {if (a >=0 )
include/drm/drm_fixed.h static inline int drm_fixp2int_ceil(s64 a) · line 122
Quoted 7 lines
include/drm/drm_fixed.h +4
-0@@ -119,6 +116,14 @@ static inline int drm_fixp2int_ceil(s64 a)return drm_fixp2int (a -DRM_FIXED_ALMOST_ONE ); } +static inline int drm_fixp2int_round (s64 a) +{ +if ((a &DRM_FIXED_FRACTIONAL ) <DRM_FIXED_HALF ) +return drm_fixp2int (a);
So, if we take -epsilon (which is -1 in raw s64 value, the largest possible value less than zero), this would return -1.0? That does not sound right.
However, the "add 0.5 and truncate" trick always works, so I'd recommend sticking that.
Thanks,
pq
Quoted 7 lines
include/drm/drm_fixed.h +4
-0+else +return drm_fixp2int_ceil (a); +} +static inline unsigned drm_fixp_msbset (s64 a) {unsigned shift, sign = (a >>63 ) &1 ;
Harry Wentland
maintainerRFC PATCH v4 4/42 drm/vkms: Round fixp2int conversion in lerp_u16
In reply to Harry Wentlandfixp2int always rounds down, fixp2int_ceil rounds up. We need the new fixp2int_round.
--- drivers/gpu/drm/vkms/vkms_composer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/vkms/vkms_composer.c +1 -1
@@ -98,7 +98,7 @@ static u16 lerp_u16(u16 a, u16 b, s64 t)s64 delta =drm_fixp_mul (b_fp - a_fp, t); -return drm_fixp2int (a_fp + delta); +return drm_fixp2int_round (a_fp + delta); }static s64 get_lut_index (const struct vkms_color_lut *lut,u16 channel_value)
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 5/42 drm/vkms: Create separate Kconfig file for VKMS
In reply to Harry WentlandThis aligns with most other DRM drivers and will allow us to add new VKMS config options without polluting the DRM Kconfig.
v3:
- Change SPDX to GPL-2.0-only to match DRM KConfig SPDX (Simon)
--- drivers/gpu/drm/Kconfig | 14 +------------- drivers/gpu/drm/vkms/Kconfig | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 drivers/gpu/drm/vkms/Kconfig
drivers/gpu/drm/Kconfig +1 -13
@@ -289,19 +289,7 @@ config DRM_VGEM as used by Mesa's software renderer for enhanced performance. If M is selected the module will be called vgem. -config DRM_VKMS - tristate "Virtual KMS (EXPERIMENTAL)" - depends on DRM && MMU - select DRM_KMS_HELPER - select DRM_GEM_SHMEM_HELPER - select CRC32 - default n - help - Virtual Kernel Mode-Setting (VKMS) is used for testing or for - running GPU in a headless machines. Choose this option to get - a VKMS. - - If M is selected the module will be called vkms. +source "drivers/gpu/drm/vkms/Kconfig" source "drivers/gpu/drm/exynos/Kconfig"
drivers/gpu/drm/vkms/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config DRM_VKMS + tristate "Virtual KMS (EXPERIMENTAL)" + depends on DRM && MMU + select DRM_KMS_HELPER + select DRM_GEM_SHMEM_HELPER + select CRC32 + default n + help + Virtual Kernel Mode-Setting (VKMS) is used for testing or for + running GPU in a headless machines. Choose this option to get + a VKMS. + + If M is selected the module will be called vkms.
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 05/42] drm/vkms: Create separate Kconfig file for VKMS
Quoted 10 lines · Harry Wentland
This aligns with most other DRM drivers and will allow us to add new VKMS config options without polluting the DRM
Kconfig.v3:
- Change SPDX to GPL-2.0-only to match DRM KConfig SPDX (Simon)Signed-off-by Harry Wentland <[email protected]>Reviewed-by Simon Ser <[email protected]>
Just to let you know this patch is already upstream. I cherry-picked it from the last patchset version and applied to drm-misc-next:
https://cgit.freedesktop.org/drm/drm-misc/commit/drivers/gpu/drm?id=ffcc67cd79ff2e93fd0bdb837c99cbab6c59d38c
Thanks again,
Melissa
Quoted 55 lines
--- drivers/gpu/drm/Kconfig | 14 +------------- drivers/gpu/drm/vkms/Kconfig | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 drivers/gpu/drm/vkms/Kconfigdrivers/gpu/drm/Kconfig +1
-13@@ -289,19 +289,7 @@ config DRM_VGEM as used by Mesa's software renderer for enhanced performance. If M is selected the module will be called vgem. -config DRM_VKMS - tristate "Virtual KMS (EXPERIMENTAL)" - depends on DRM && MMU - select DRM_KMS_HELPER - select DRM_GEM_SHMEM_HELPER - select CRC32 - default n - help - Virtual Kernel Mode-Setting (VKMS) is used for testing or for - running GPU in a headless machines. Choose this option to get - a VKMS. - - If M is selected the module will be called vkms. +source "drivers/gpu/drm/vkms/Kconfig" source "drivers/gpu/drm/exynos/Kconfig"drivers/gpu/drm/vkms/Kconfig new file +15
-0@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config DRM_VKMS + tristate "Virtual KMS (EXPERIMENTAL)" + depends on DRM && MMU + select DRM_KMS_HELPER + select DRM_GEM_SHMEM_HELPER + select CRC32 + default n + help + Virtual Kernel Mode-Setting (VKMS) is used for testing or for + running GPU in a headless machines. Choose this option to get + a VKMS. + + If M is selected the module will be called vkms.Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 6/42 drm/vkms: Add kunit tests for VKMS LUT handling
In reply to Harry WentlandDebugging LUT math is much easier when we can unit test it. Add kunit functionality to VKMS and add tests for
- get_lut_index
- lerp_u16
v4:
- Test the critical points of the lerp function (Pekka)
v3:
- Use include way of testing static functions (Arthur)
--- drivers/gpu/drm/vkms/Kconfig | 5 + drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 163 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_composer.c | 8 +- 4 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/vkms_color_tests.c
drivers/gpu/drm/vkms/Kconfig +5 -0
@@ -13,3 +13,8 @@ config DRM_VKMS a VKMS. If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "Tests for VKMS" if !KUNIT_ALL_TESTS + depends on DRM_VKMS && KUNIT + default KUNIT_ALL_TESTS
drivers/gpu/drm/vkms/tests/.kunitconfig new file +4 -0
@@ -0,0 +1,4 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_VKMS=y +CONFIG_DRM_VKMS_KUNIT_TESTS=y
drivers/gpu/drm/vkms/tests/vkms_color_tests.c new file +163 -0
164 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_composer.c +6 -2
@@ -91,7 +91,7 @@ static void fill_background(const struct pixel_argb_u16 *background_color, }// lerp(a, b, t) = a + (b - a) * t -static u16 lerp_u16 (u16 a,u16 b,s64 t) +u16 lerp_u16 (u16 a,u16 b,s64 t) {s64 a_fp =drm_int2fixp (a);s64 b_fp =drm_int2fixp (b);
@@ -101,7 +101,7 @@ static u16 lerp_u16(u16 a, u16 b, s64 t)return drm_fixp2int_round (a_fp + delta); } -static s64 get_lut_index (const struct vkms_color_lut *lut,u16 channel_value) +s64 get_lut_index (const struct vkms_color_lut *lut,u16 channel_value) {s64 color_channel_fp =drm_int2fixp (channel_value);
@@ -429,3 +429,7 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name)return ret; } + +#ifdef CONFIG_DRM_VKMS_KUNIT_TESTS +#include "tests/vkms_color_tests.c" +#endif
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 06/42] drm/vkms: Add kunit tests for VKMS LUT handling
Quoted 220 lines · Harry Wentland
Debugging LUT math is much easier when we can unit test it. Add kunit functionality to VKMS and add tests for
-get_lut_index
-lerp_u16v4:
- Test the critical points of the lerp function (Pekka)v3:
- Use include way of testing static functions (Arthur)Signed-off-by Harry Wentland <[email protected]>Cc Arthur Grillo <[email protected]>--- drivers/gpu/drm/vkms/Kconfig | 5 + drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 163 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_composer.c | 8 +- 4 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/vkms_color_tests.cdrivers/gpu/drm/vkms/Kconfig +5
-0@@ -13,3 +13,8 @@ config DRM_VKMS a VKMS. If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "Tests for VKMS" if !KUNIT_ALL_TESTS + depends on DRM_VKMS && KUNIT + default KUNIT_ALL_TESTSdrivers/gpu/drm/vkms/tests/.kunitconfig new file +4
-0@@ -0,0 +1,4 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_VKMS=y +CONFIG_DRM_VKMS_KUNIT_TESTS=ydrivers/gpu/drm/vkms/tests/vkms_color_tests.c new file +163
-0@@ -0,0 +1,163 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#include <kunit/test.h> + +#include <drm/drm_fixed.h> + +#define TEST_LUT_SIZE 16 + +static struct drm_color_lut test_linear_array[TEST_LUT_SIZE ] = { + {0x0 ,0x0 ,0x0 ,0 }, + {0x1111 ,0x1111 ,0x1111 ,0 }, + {0x2222 ,0x2222 ,0x2222 ,0 }, + {0x3333 ,0x3333 ,0x3333 ,0 }, + {0x4444 ,0x4444 ,0x4444 ,0 }, + {0x5555 ,0x5555 ,0x5555 ,0 }, + {0x6666 ,0x6666 ,0x6666 ,0 }, + {0x7777 ,0x7777 ,0x7777 ,0 }, + {0x8888 ,0x8888 ,0x8888 ,0 }, + {0x9999 ,0x9999 ,0x9999 ,0 }, + {0xaaaa ,0xaaaa ,0xaaaa ,0 }, + {0xbbbb ,0xbbbb ,0xbbbb ,0 }, + {0xcccc ,0xcccc ,0xcccc ,0 }, + {0xdddd ,0xdddd ,0xdddd ,0 }, + {0xeeee ,0xeeee ,0xeeee ,0 }, + {0xffff ,0xffff ,0xffff ,0 }, +}; + +const struct vkms_color_lut test_linear_lut = { + .base = test_linear_array, + .lut_length =TEST_LUT_SIZE , + .channel_value2index_ratio =0xf000fll +}; + + +static void vkms_color_test_get_lut_index (struct kunit *test) +{ +int i; + +KUNIT_EXPECT_EQ (test,drm_fixp2int (get_lut_index (&test_linear_lut, test_linear_array[0 ].red)),0 ); + +for (i =0 ; i <TEST_LUT_SIZE ; i++) +KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&test_linear_lut, test_linear_array[i].red)), i); +} + +static void vkms_color_test_lerp (struct kunit *test) +{ +/*** half-way round down ***/ +s64 t =0x80000000 -1 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x8 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x8 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x8 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x10 ); + + +/*** half-way round up ***/ + t =0x80000000 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x8 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x9 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x8 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x11 ); + +/*** t = 0.0 ***/ + t =0x0 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x0 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x1 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x1 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x10 ); + +/*** t = 1.0 ***/ + t =0x100000000 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x10 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x10 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0xf ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x11 ); + + +/*** t = 0.0 + 1 ***/ + t =0x0 +1 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x0 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x1 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x1 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x10 ); + +/*** t = 1.0 - 1 ***/ + t =0x100000000 -1 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x10 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x10 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0xf ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x11 ); + + +/*** t chosen to verify the flipping point of result a (or b) to a+1 (or b-1) ***/ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x1 ,0x80000000 -1 ),0x0 ); +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x1 ,0x80000000 ),0x1 ); +} + +static struct kunit_case vkms_color_test_cases[] = { +KUNIT_CASE (vkms_color_test_get_lut_index), +KUNIT_CASE (vkms_color_test_lerp), + {} +}; + +static struct kunit_suite vkms_color_test_suite = { + .name ="vkms-color" , + .test_cases = vkms_color_test_cases, +}; +kunit_test_suite (vkms_color_test_suite); + +MODULE_LICENSE ("GPL" );drivers/gpu/drm/vkms/vkms_composer.c +0
-0
drivers/gpu/drm/vkms/vkms_composer.c static void fill_background(const struct pixel_argb_u16 *background_color, · line 94
Quoted 5 lines
drivers/gpu/drm/vkms/vkms_composer.c +1
-1@@ -91,7 +91,7 @@ static void fill_background(const struct pixel_argb_u16 *background_color, }// lerp(a, b, t) = a + (b - a) * t -static u16 lerp_u16 (u16 a,u16 b,s64 t) +u16 lerp_u16 (u16 a,u16 b,s64 t)
You don't need to do that, as already said on [1].
drivers/gpu/drm/vkms/vkms_composer.c static u16 lerp_u16(u16 a, u16 b, s64 t) · line 104
Quoted 9 lines
drivers/gpu/drm/vkms/vkms_composer.c +1
-1{s64 a_fp =drm_int2fixp (a);s64 b_fp =drm_int2fixp (b);@@ -101,7 +101,7 @@ static u16 lerp_u16(u16 a, u16 b, s64 t)return drm_fixp2int_round (a_fp + delta); } -static s64 get_lut_index (const struct vkms_color_lut *lut,u16 channel_value) +s64 get_lut_index (const struct vkms_color_lut *lut,u16 channel_value)
Same here.
[1]: https://lore.kernel.org/dri-devel/[email protected]/
Best Regards,
~Arthur Grillo
Quoted 11 lines
drivers/gpu/drm/vkms/vkms_composer.c +4
-0{s64 color_channel_fp =drm_int2fixp (channel_value);@@ -429,3 +429,7 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name)return ret; } + +#ifdef CONFIG_DRM_VKMS_KUNIT_TESTS +#include "tests/vkms_color_tests.c" +#endif
Harry Wentland
maintainerRe: [RFC PATCH v4 06/42] drm/vkms: Add kunit tests for VKMS LUT handling
Quoted 238 lines · Arthur Grillo
Quoted 220 lines · Harry Wentland
Debugging LUT math is much easier when we can unit test it. Add kunit functionality to VKMS and add tests for
-get_lut_index
-lerp_u16v4:
- Test the critical points of the lerp function (Pekka)v3:
- Use include way of testing static functions (Arthur)Signed-off-by Harry Wentland <[email protected]>Cc Arthur Grillo <[email protected]>--- drivers/gpu/drm/vkms/Kconfig | 5 + drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 163 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_composer.c | 8 +- 4 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/vkms_color_tests.cdrivers/gpu/drm/vkms/Kconfig +5
-0@@ -13,3 +13,8 @@ config DRM_VKMS a VKMS. If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "Tests for VKMS" if !KUNIT_ALL_TESTS + depends on DRM_VKMS && KUNIT + default KUNIT_ALL_TESTSdrivers/gpu/drm/vkms/tests/.kunitconfig new file +4
-0@@ -0,0 +1,4 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_VKMS=y +CONFIG_DRM_VKMS_KUNIT_TESTS=ydrivers/gpu/drm/vkms/tests/vkms_color_tests.c new file +163
-0@@ -0,0 +1,163 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#include <kunit/test.h> + +#include <drm/drm_fixed.h> + +#define TEST_LUT_SIZE 16 + +static struct drm_color_lut test_linear_array[TEST_LUT_SIZE ] = { + {0x0 ,0x0 ,0x0 ,0 }, + {0x1111 ,0x1111 ,0x1111 ,0 }, + {0x2222 ,0x2222 ,0x2222 ,0 }, + {0x3333 ,0x3333 ,0x3333 ,0 }, + {0x4444 ,0x4444 ,0x4444 ,0 }, + {0x5555 ,0x5555 ,0x5555 ,0 }, + {0x6666 ,0x6666 ,0x6666 ,0 }, + {0x7777 ,0x7777 ,0x7777 ,0 }, + {0x8888 ,0x8888 ,0x8888 ,0 }, + {0x9999 ,0x9999 ,0x9999 ,0 }, + {0xaaaa ,0xaaaa ,0xaaaa ,0 }, + {0xbbbb ,0xbbbb ,0xbbbb ,0 }, + {0xcccc ,0xcccc ,0xcccc ,0 }, + {0xdddd ,0xdddd ,0xdddd ,0 }, + {0xeeee ,0xeeee ,0xeeee ,0 }, + {0xffff ,0xffff ,0xffff ,0 }, +}; + +const struct vkms_color_lut test_linear_lut = { + .base = test_linear_array, + .lut_length =TEST_LUT_SIZE , + .channel_value2index_ratio =0xf000fll +}; + + +static void vkms_color_test_get_lut_index (struct kunit *test) +{ +int i; + +KUNIT_EXPECT_EQ (test,drm_fixp2int (get_lut_index (&test_linear_lut, test_linear_array[0 ].red)),0 ); + +for (i =0 ; i <TEST_LUT_SIZE ; i++) +KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&test_linear_lut, test_linear_array[i].red)), i); +} + +static void vkms_color_test_lerp (struct kunit *test) +{ +/*** half-way round down ***/ +s64 t =0x80000000 -1 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x8 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x8 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x8 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x10 ); + + +/*** half-way round up ***/ + t =0x80000000 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x8 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x9 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x8 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x11 ); + +/*** t = 0.0 ***/ + t =0x0 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x0 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x1 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x1 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x10 ); + +/*** t = 1.0 ***/ + t =0x100000000 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x10 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x10 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0xf ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x11 ); + + +/*** t = 0.0 + 1 ***/ + t =0x0 +1 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x0 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x1 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x1 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x10 ); + +/*** t = 1.0 - 1 ***/ + t =0x100000000 -1 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x10 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x10 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0xf ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x11 ); + + +/*** t chosen to verify the flipping point of result a (or b) to a+1 (or b-1) ***/ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x1 ,0x80000000 -1 ),0x0 ); +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x1 ,0x80000000 ),0x1 ); +} + +static struct kunit_case vkms_color_test_cases[] = { +KUNIT_CASE (vkms_color_test_get_lut_index), +KUNIT_CASE (vkms_color_test_lerp), + {} +}; + +static struct kunit_suite vkms_color_test_suite = { + .name ="vkms-color" , + .test_cases = vkms_color_test_cases, +}; +kunit_test_suite (vkms_color_test_suite); + +MODULE_LICENSE ("GPL" );drivers/gpu/drm/vkms/vkms_composer.c +0
-0drivers/gpu/drm/vkms/vkms_composer.c static void fill_background(const struct pixel_argb_u16 *background_color, · line 94
Quoted 5 lines
drivers/gpu/drm/vkms/vkms_composer.c +1
-1@@ -91,7 +91,7 @@ static void fill_background(const struct pixel_argb_u16 *background_color, }// lerp(a, b, t) = a + (b - a) * t -static u16 lerp_u16 (u16 a,u16 b,s64 t) +u16 lerp_u16 (u16 a,u16 b,s64 t)You don't need to do that, as already said on [1].
Quoted 7 lines
drivers/gpu/drm/vkms/vkms_composer.c +0
-0{s64 a_fp =drm_int2fixp (a);s64 b_fp =drm_int2fixp (b);@@ -101,7 +101,7 @@ static u16 lerp_u16(u16 a, u16 b, s64 t)return drm_fixp2int_round (a_fp + delta); }
Quoted 7 lines
drivers/gpu/drm/vkms/vkms_composer.c static u16 lerp_u16(u16 a, u16 b, s64 t) · line 104
Quoted 2 lines
drivers/gpu/drm/vkms/vkms_composer.c +1
-1-static s64 get_lut_index (const struct vkms_color_lut *lut,u16 channel_value) +s64 get_lut_index (const struct vkms_color_lut *lut,u16 channel_value)Same here.
Oops, apologies. Somehow missed this when spinning the set. static will be back in the next version.
Harry
Quoted 14 lines
Best Regards,
~Arthur GrilloQuoted 11 lines
drivers/gpu/drm/vkms/vkms_composer.c +4
-0{s64 color_channel_fp =drm_int2fixp (channel_value);@@ -429,3 +429,7 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name)return ret; } + +#ifdef CONFIG_DRM_VKMS_KUNIT_TESTS +#include "tests/vkms_color_tests.c" +#endif
Re: [RFC PATCH v4 06/42] drm/vkms: Add kunit tests for VKMS LUT handling
In reply to Harry WentlandQuoted 13 lines · On Mon, 26 Feb 2024 16:10:20 -0500 Harry Wentland <[email protected]>…
Debugging LUT math is much easier when we can unit test it. Add kunit functionality to VKMS and add tests for
-get_lut_index
-lerp_u16v4:
- Test the critical points of the lerp function (Pekka)v3:
- Use include way of testing static functions (Arthur)Signed-off-by Harry Wentland <[email protected]>Cc Arthur Grillo <[email protected]>
Quoted 9 lines
--- drivers/gpu/drm/vkms/Kconfig | 5 + drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 163 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_composer.c | 8 +- 4 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/vkms_color_tests.c
Hi Harry,
since fixed point math is hard, please allow me to nitpick so maybe these patches could be landed ahead of time.
Quoted 50 lines
drivers/gpu/drm/vkms/Kconfig +5
-0@@ -13,3 +13,8 @@ config DRM_VKMS a VKMS. If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "Tests for VKMS" if !KUNIT_ALL_TESTS + depends on DRM_VKMS && KUNIT + default KUNIT_ALL_TESTSdrivers/gpu/drm/vkms/tests/.kunitconfig new file +4
-0@@ -0,0 +1,4 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_VKMS=y +CONFIG_DRM_VKMS_KUNIT_TESTS=ydrivers/gpu/drm/vkms/tests/vkms_color_tests.c new file +21
-0@@ -0,0 +1,163 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#include <kunit/test.h> + +#include <drm/drm_fixed.h> + +#define TEST_LUT_SIZE 16 + +static struct drm_color_lut test_linear_array[TEST_LUT_SIZE ] = { + {0x0 ,0x0 ,0x0 ,0 }, + {0x1111 ,0x1111 ,0x1111 ,0 }, + {0x2222 ,0x2222 ,0x2222 ,0 }, + {0x3333 ,0x3333 ,0x3333 ,0 }, + {0x4444 ,0x4444 ,0x4444 ,0 }, + {0x5555 ,0x5555 ,0x5555 ,0 }, + {0x6666 ,0x6666 ,0x6666 ,0 }, + {0x7777 ,0x7777 ,0x7777 ,0 }, + {0x8888 ,0x8888 ,0x8888 ,0 }, + {0x9999 ,0x9999 ,0x9999 ,0 }, + {0xaaaa ,0xaaaa ,0xaaaa ,0 }, + {0xbbbb ,0xbbbb ,0xbbbb ,0 },
drivers/gpu/drm/vkms/tests/vkms_color_tests.c line 31
Quoted 10 lines
drivers/gpu/drm/vkms/tests/vkms_color_tests.c new file +10
-0+ { 0xcccc, 0xcccc, 0xcccc, 0 }, + { 0xdddd, 0xdddd, 0xdddd, 0 }, + { 0xeeee, 0xeeee, 0xeeee, 0 }, + { 0xffff, 0xffff, 0xffff, 0 }, +}; + +const struct vkms_color_lut test_linear_lut = { + .base = test_linear_array, + .lut_length =TEST_LUT_SIZE , + .channel_value2index_ratio = 0xf000fll
Where does 0xf000f come from? Could it be computed from DRM_FIXED_ONE and ARRAY_LENGTH()?
drivers/gpu/drm/vkms/tests/vkms_color_tests.c line 42
Quoted 11 lines
drivers/gpu/drm/vkms/tests/vkms_color_tests.c new file +11
-0+}; + + +static void vkms_color_test_get_lut_index (struct kunit *test) +{ +int i; + +KUNIT_EXPECT_EQ (test,drm_fixp2int (get_lut_index (&test_linear_lut, test_linear_array[0 ].red)),0 ); + +for (i =0 ; i <TEST_LUT_SIZE ; i++) +KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&test_linear_lut, test_linear_array[i].red)), i);
Why this instead of
+ for (i = 0; i < TEST_LUT_SIZE; i++)
+ KUNIT_EXPECT_EQ(test, get_lut_index(&test_linear_lut, test_linear_array[i].red), drm_int2fixp(i));
and
+ for (i = 0; i < 0xffff; i++)
+ KUNIT_EXPECT_EQ(test, drm_fixp2int(get_lut_index(&test_linear_lut, i)), i / 0x1111);
?
I think your original form is leaving quite much room for error in precision.
Quoted 96 lines
drivers/gpu/drm/vkms/tests/vkms_color_tests.c new file +96
-0+} + +static void vkms_color_test_lerp (struct kunit *test) +{ +/*** half-way round down ***/ +s64 t =0x80000000 -1 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x8 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x8 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x8 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x10 ); + + +/*** half-way round up ***/ + t =0x80000000 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x8 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x9 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x8 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x11 ); + +/*** t = 0.0 ***/ + t =0x0 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x0 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x1 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x1 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x10 ); + +/*** t = 1.0 ***/ + t =0x100000000 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x10 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x10 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0xf ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x11 ); + + +/*** t = 0.0 + 1 ***/ + t =0x0 +1 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x0 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x1 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0x1 ); + +/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x10 ); + +/*** t = 1.0 - 1 ***/ + t =0x100000000 -1 ; +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x10 , t),0x10 ); + +/* odd a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0x10 , t),0x10 ); + +/* odd b */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x1 ,0xf , t),0xf ); +
drivers/gpu/drm/vkms/tests/vkms_color_tests.c line 148
Quoted 10 lines
drivers/gpu/drm/vkms/tests/vkms_color_tests.c new file +10
-0+/* b = a */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x10 , t),0x10 ); + +/* b = a + 1 */ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x10 ,0x11 , t),0x11 ); + + +/*** t chosen to verify the flipping point of result a (or b) to a+1 (or b-1) ***/ +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x1 ,0x80000000 -1 ),0x0 ); +KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x1 ,0x80000000 ),0x1 );
What about b = 0xfffd also? The smaller number in b, and especially in b - a, the more precision error the rounding will forgive.
Quoted 30 lines
drivers/gpu/drm/vkms/tests/vkms_color_tests.c new file +15
-0+} + +static struct kunit_case vkms_color_test_cases[] = { +KUNIT_CASE (vkms_color_test_get_lut_index), +KUNIT_CASE (vkms_color_test_lerp), + {} +}; + +static struct kunit_suite vkms_color_test_suite = { + .name ="vkms-color" , + .test_cases = vkms_color_test_cases, +}; +kunit_test_suite (vkms_color_test_suite); + +MODULE_LICENSE ("GPL" );drivers/gpu/drm/vkms/vkms_composer.c +1
-1@@ -91,7 +91,7 @@ static void fill_background(const struct pixel_argb_u16 *background_color, }// lerp(a, b, t) = a + (b - a) * t -static u16 lerp_u16 (u16 a,u16 b,s64 t) +u16 lerp_u16 (u16 a,u16 b,s64 t) {s64 a_fp =drm_int2fixp (a);s64 b_fp =drm_int2fixp (b);
drivers/gpu/drm/vkms/vkms_composer.c static u16 lerp_u16(u16 a, u16 b, s64 t) · line 101
Quoted 1 line
drivers/gpu/drm/vkms/vkms_composer.c +0
-0@@ -101,7 +101,7 @@ static u16 lerp_u16(u16 a, u16 b, s64 t)return drm_fixp2int_round (a_fp + delta);
Given the past, I guess it wouldn't hurt if all drm fixp functions had a few tests of their own.
Thanks,
pq
Quoted 15 lines
drivers/gpu/drm/vkms/vkms_composer.c +5
-1} -static s64 get_lut_index (const struct vkms_color_lut *lut,u16 channel_value) +s64 get_lut_index (const struct vkms_color_lut *lut,u16 channel_value) {s64 color_channel_fp =drm_int2fixp (channel_value);@@ -429,3 +429,7 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name)return ret; } + +#ifdef CONFIG_DRM_VKMS_KUNIT_TESTS +#include "tests/vkms_color_tests.c" +#endif
Harry Wentland
maintainerRFC PATCH v4 7/42 drm/vkms: Avoid reading beyond LUT array
In reply to Harry WentlandWhen the floor LUT index (drm_fixp2int(lut_index) is the last index of the array the ceil LUT index will point to an entry beyond the array. Make sure we guard against it and use the value of the floor LUT index.
v3:
- Drop bits from commit description that didn't contribute anything of value
--- drivers/gpu/drm/vkms/vkms_composer.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +10 -4
@@ -123,6 +123,8 @@ static u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 chan enum lut_channel channel) {s64 lut_index =get_lut_index (lut, channel_value); +u16 *floor_lut_value, *ceil_lut_value; +u16 floor_channel_value, ceil_channel_value;/* * This checks if `struct drm_color_lut` has any gap added by the compiler
@@ -130,11 +132,15 @@ static u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 chan*/ static_assert (sizeof (struct drm_color_lut ) ==sizeof (__u16) *4 ); -u16 *floor_lut_value = (__u16 *)&lut->base[drm_fixp2int (lut_index)]; -u16 *ceil_lut_value = (__u16 *)&lut->base[drm_fixp2int_ceil (lut_index)]; + floor_lut_value = (__u16 *)&lut->base[drm_fixp2int (lut_index)]; +if (drm_fixp2int (lut_index) == (lut->lut_length -1 )) +/* We're at the end of the LUT array, use same value for ceil and floor */ + ceil_lut_value = floor_lut_value; +else + ceil_lut_value = (__u16 *)&lut->base[drm_fixp2int_ceil (lut_index)]; -u16 floor_channel_value = floor_lut_value[channel]; -u16 ceil_channel_value = ceil_lut_value[channel]; + floor_channel_value = floor_lut_value[channel]; + ceil_channel_value = ceil_lut_value[channel];return lerp_u16 (floor_channel_value, ceil_channel_value, lut_index &DRM_FIXED_DECIMAL_MASK );
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 07/42] drm/vkms: Avoid reading beyond LUT array
Quoted 5 lines · Harry Wentland
When the floor LUT index (
drm_fixp2int(lut_index)is the last index of the array the ceil LUT index will point to an entry beyond the array. Make sure we guard against it and use the value of the floor LUT index.
Quoted 8 lines
v3:
- Drop bits from commit description that didn't contribute anything of valueFixes db1f254f2cfaf ("drm/vkms: Add support to 1D gamma LUT")Signed-off-by Harry Wentland <[email protected]>Cc Arthur Grillo <[email protected]>Reviewed-by Melissa Wen <[email protected]>
Same. Already applied upstream:
https://cgit.freedesktop.org/drm/drm-misc/commit/drivers/gpu/drm?id=2fee84030d12d9fddfa874e4562d71761a129277
I guess you are working on top of asdn branch and it's okay to me. I'm just mentioning to avoid confusion.
Melissa
Quoted 40 lines
--- drivers/gpu/drm/vkms/vkms_composer.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)drivers/gpu/drm/vkms/vkms_composer.c +10
-4@@ -123,6 +123,8 @@ static u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 chan enum lut_channel channel) {s64 lut_index =get_lut_index (lut, channel_value); +u16 *floor_lut_value, *ceil_lut_value; +u16 floor_channel_value, ceil_channel_value;/* * This checks if `struct drm_color_lut` has any gap added by the compiler @@ -130,11 +132,15 @@ static u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 chan*/ static_assert (sizeof (struct drm_color_lut ) ==sizeof (__u16) *4 ); -u16 *floor_lut_value = (__u16 *)&lut->base[drm_fixp2int (lut_index)]; -u16 *ceil_lut_value = (__u16 *)&lut->base[drm_fixp2int_ceil (lut_index)]; + floor_lut_value = (__u16 *)&lut->base[drm_fixp2int (lut_index)]; +if (drm_fixp2int (lut_index) == (lut->lut_length -1 )) +/* We're at the end of the LUT array, use same value for ceil and floor */ + ceil_lut_value = floor_lut_value; +else + ceil_lut_value = (__u16 *)&lut->base[drm_fixp2int_ceil (lut_index)]; -u16 floor_channel_value = floor_lut_value[channel]; -u16 ceil_channel_value = ceil_lut_value[channel]; + floor_channel_value = floor_lut_value[channel]; + ceil_channel_value = ceil_lut_value[channel];return lerp_u16 (floor_channel_value, ceil_channel_value, lut_index &DRM_FIXED_DECIMAL_MASK );Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 8/42 drm/doc/rfc: Describe why prescriptive color pipeline is needed
In reply to Harry Wentlandv4:
- Drop IOCTL docs since we dropped the IOCTLs (Pekka)
- Clarify reading and setting of COLOR_PIPELINE prop (Pekka)
- Add blurb about not requiring to reject a pipeline due to incompatible ops, as long as op can be bypassed (Pekka)
- Dropped informational strings (such as input CSC) as they're not actually intended to be advertised (Pekka)
v3:
- Describe DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE (Sebastian)
- Ask for clear documentation of colorop behavior (Sebastian)
v2:
- Update colorop visualizations to match reality (Sebastian, Alex Hung)
- Updated wording (Pekka)
- Change BYPASS wording to make it non-mandatory (Sebastian)
- Drop cover-letter-like paragraph from COLOR_PIPELINE Plane Property section (Pekka)
- Use PQ EOTF instead of its inverse in Pipeline Programming example (Melissa)
- Add "Driver Implementer's Guide" section (Pekka)
- Add "Driver Forward/Backward Compatibility" section (Sebastian, Pekka)
--- Documentation/gpu/rfc/color_pipeline.rst | 360 +++++++++++++++++++++++ 1 file changed, 360 insertions(+) create mode 100644 Documentation/gpu/rfc/color_pipeline.rst
Documentation/gpu/rfc/color_pipeline.rst new file +360 -0
@@ -0,0 +1,360 @@ +======================== +Linux Color Pipeline API +======================== + +What problem are we solving? +============================ + +We would like to support pre-, and post-blending complex color +transformations in display controller hardware in order to allow for +HW-supported HDR use-cases, as well as to provide support to +color-managed applications, such as video or image editors. + +It is possible to support an HDR output on HW supporting the Colorspace +and HDR Metadata drm_connector properties, but that requires the +compositor or application to render and compose the content into one +final buffer intended for display. Doing so is costly. + +Most modern display HW offers various 1D LUTs, 3D LUTs, matrices, and other +operations to support color transformations. These operations are often +implemented in fixed-function HW and therefore much more power efficient than +performing similar operations via shaders or CPU. + +We would like to make use of this HW functionality to support complex color +transformations with no, or minimal CPU or shader load. + + +How are other OSes solving this problem? +======================================== + +The most widely supported use-cases regard HDR content, whether video or +gaming. + +Most OSes will specify the source content format (color gamut, encoding transfer +function, and other metadata, such as max and average light levels) to a driver. +Drivers will then program their fixed-function HW accordingly to map from a +source content buffer's space to a display's space. + +When fixed-function HW is not available the compositor will assemble a shader to +ask the GPU to perform the transformation from the source content format to the +display's format. + +A compositor's mapping function and a driver's mapping function are usually +entirely separate concepts. On OSes where a HW vendor has no insight into +closed-source compositor code such a vendor will tune their color management +code to visually match the compositor's. On other OSes, where both mapping +functions are open to an implementer they will ensure both mappings match. + +This results in mapping algorithm lock-in, meaning that no-one alone can +experiment with or introduce new mapping algorithms and achieve +consistent results regardless of which implementation path is taken. + +Why is Linux different? +======================= + +Unlike other OSes, where there is one compositor for one or more drivers, on +Linux we have a many-to-many relationship. Many compositors; many drivers. +In addition each compositor vendor or community has their own view of how +color management should be done. This is what makes Linux so beautiful. + +This means that a HW vendor can now no longer tune their driver to one +compositor, as tuning it to one could make it look fairly different from +another compositor's color mapping. + +We need a better solution. + + +Descriptive API +=============== + +An API that describes the source and destination colorspaces is a descriptive +API. It describes the input and output color spaces but does not describe +how precisely they should be mapped. Such a mapping includes many minute +design decision that can greatly affect the look of the final result. + +It is not feasible to describe such mapping with enough detail to ensure the +same result from each implementation. In fact, these mappings are a very active +research area. + + +Prescriptive API +================ + +A prescriptive API describes not the source and destination colorspaces. It +instead prescribes a recipe for how to manipulate pixel values to arrive at the +desired outcome. + +This recipe is generally an ordered list of straight-forward operations, +with clear mathematical definitions, such as 1D LUTs, 3D LUTs, matrices, +or other operations that can be described in a precise manner. + + +The Color Pipeline API +====================== + +HW color management pipelines can significantly differ between HW +vendors in terms of availability, ordering, and capabilities of HW +blocks. This makes a common definition of color management blocks and +their ordering nigh impossible. Instead we are defining an API that +allows user space to discover the HW capabilities in a generic manner, +agnostic of specific drivers and hardware. + + +drm_colorop Object +================== + +To support the definition of color pipelines we define the DRM core +object type drm_colorop. Individual drm_colorop objects will be chained +via the NEXT property of a drm_colorop to constitute a color pipeline. +Each drm_colorop object is unique, i.e., even if multiple color +pipelines have the same operation they won't share the same drm_colorop +object to describe that operation. + +Note that drivers are not expected to map drm_colorop objects statically +to specific HW blocks. The mapping of drm_colorop objects is entirely a +driver-internal detail and can be as dynamic or static as a driver needs +it to be. See more in the Driver Implementation Guide section below. + +Each drm_colorop has three core properties: + +TYPE: An enumeration property, definint the type of transformation, such as +* enumerated curve +* custom (uniform) 1D LUT +* 3x3 matrix +* 3x4 matrix +* 3D LUT +* etc. + +Depending on the type of transformation other properties will describe +more details. + +BYPASS: A boolean property that can be used to easily put a block into +bypass mode. While setting other properties might fail atomic check, +setting the BYPASS property to true should never fail. The BYPASS +property is not mandatory for a colorop, as long as the entire pipeline +can get bypassed by setting the COLOR_PIPELINE on a plane to '0'. + +NEXT: The ID of the next drm_colorop in a color pipeline, or 0 if this +drm_colorop is the last in the chain. + +An example of a drm_colorop object might look like one of these:: + + /* 1D enumerated curve */ + Color operation 42 + ├─ "TYPE": immutable enum {1D enumerated curve, 1D LUT, 3x3 matrix, 3x4 matrix, 3D LUT, etc.} = 1D enumerated curve + ├─ "BYPASS": bool {true, false} + ├─ "CURVE_1D_TYPE": enum {sRGB EOTF, sRGB inverse EOTF, PQ EOTF, PQ inverse EOTF, …} + └─ "NEXT": immutable color operation ID = 43 + + /* custom 4k entry 1D LUT */ + Color operation 52 + ├─ "TYPE": immutable enum {1D enumerated curve, 1D LUT, 3x3 matrix, 3x4 matrix, 3D LUT, etc.} = 1D LUT + ├─ "BYPASS": bool {true, false} + ├─ "LUT_1D_SIZE": immutable range = 4096 + ├─ "LUT_1D": blob + └─ "NEXT": immutable color operation ID = 0 + + /* 17^3 3D LUT */ + Color operation 72 + ├─ "TYPE": immutable enum {1D enumerated curve, 1D LUT, 3x3 matrix, 3x4 matrix, 3D LUT, etc.} = 3D LUT + ├─ "BYPASS": bool {true, false} + ├─ "LUT_3D_SIZE": immutable range = 17 + ├─ "LUT_3D": blob + └─ "NEXT": immutable color operation ID = 73 + + +COLOR_PIPELINE Plane Property +============================= + +Color Pipelines are created by a driver and advertised via a new +COLOR_PIPELINE enum property on each plane. Values of the property +always include object id 0, which is the default and means all color +processing is disabled. Additional values will be the object IDs of the +first drm_colorop in a pipeline. A driver can create and advertise none, +one, or more possible color pipelines. A DRM client will select a color +pipeline by setting the COLOR PIPELINE to the respective value. + +NOTE: Many DRM clients will set enumeration properties via the string +value, often hard-coding it. Since this enumeration is generated based +on the colorop object IDs it is important to perform the Color Pipeline +Discovery, described below, instead of hard-coding color pipeline +assignment. Drivers might generate the enum strings dynamically. +Hard-coded strings might only work for specific drivers on a specific +pieces of HW. Color Pipeline Discovery can work universally, as long as +drivers implement the required color operations. + +The COLOR_PIPELINE property is only exposed when the +DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE is set. Drivers shall ignore any +existing pre-blend color operations when this cap is set, such as +COLOR_RANGE and COLOR_ENCODING. If drivers want to support COLOR_RANGE +or COLOR_ENCODING functionality when the color pipeline client cap is +set, they are expected to expose colorops in the pipeline to allow for +the appropriate color transformation. + +Setting of the COLOR_PIPELINE plane property or drm_colorop properties +is only allowed for userspace that sets this client cap. + +An example of a COLOR_PIPELINE property on a plane might look like this:: + + Plane 10 + ├─ "TYPE": immutable enum {Overlay, Primary, Cursor} = Primary + ├─ … + └─ "COLOR_PIPELINE": enum {0, 42, 52} = 0 + + +Color Pipeline Discovery +======================== + +A DRM client wanting color management on a drm_plane will: + +1. Get the COLOR_PIPELINE property of the plane +2. iterate all COLOR_PIPELINE enum values +3. for each enum value walk the color pipeline (via the NEXT pointers) + and see if the available color operations are suitable for the + desired color management operations + +If userspace encounters an unknown or unsuitable color operation during +discovery it does not need to reject the entire color pipeline outright, +as long as the unknown or unsuitable colorop has a "BYPASS" property. +Drivers will ensure that a bypassed block does not have any effect. + +An example of chained properties to define an AMD pre-blending color +pipeline might look like this:: + + Plane 10 + ├─ "TYPE" (immutable) = Primary + └─ "COLOR_PIPELINE": enum {0, 44} = 0 + + Color operation 44 + ├─ "TYPE" (immutable) = 1D enumerated curve + ├─ "BYPASS": bool + ├─ "CURVE_1D_TYPE": enum {sRGB EOTF, PQ EOTF} = sRGB EOTF + └─ "NEXT" (immutable) = 45 + + Color operation 45 + ├─ "TYPE" (immutable) = 3x4 Matrix + ├─ "BYPASS": bool + ├─ "MATRIX_3_4": blob + └─ "NEXT" (immutable) = 46 + + Color operation 46 + ├─ "TYPE" (immutable) = 1D enumerated curve + ├─ "BYPASS": bool + ├─ "CURVE_1D_TYPE": enum {sRGB Inverse EOTF, PQ Inverse EOTF} = sRGB EOTF + └─ "NEXT" (immutable) = 47 + + Color operation 47 + ├─ "TYPE" (immutable) = 1D LUT + ├─ "LUT_1D_SIZE": immutable range = 4096 + ├─ "LUT_1D_DATA": blob + └─ "NEXT" (immutable) = 48 + + Color operation 48 + ├─ "TYPE" (immutable) = 3D LUT + ├─ "LUT_3D_SIZE" (immutable) = 17 + ├─ "LUT_3D_DATA": blob + └─ "NEXT" (immutable) = 49 + + Color operation 49 + ├─ "TYPE" (immutable) = 1D enumerated curve + ├─ "BYPASS": bool + ├─ "CURVE_1D_TYPE": enum {sRGB EOTF, PQ EOTF} = sRGB EOTF + └─ "NEXT" (immutable) = 0 + + +Color Pipeline Programming +========================== + +Once a DRM client has found a suitable pipeline it will: + +1. Set the COLOR_PIPELINE enum value to the one pointing at the first + drm_colorop object of the desired pipeline +2. Set the properties for all drm_colorop objects in the pipeline to the + desired values, setting BYPASS to true for unused drm_colorop blocks, + and false for enabled drm_colorop blocks +3. Perform (TEST_ONLY or not) atomic commit with all the other KMS + states it wishes to change + +To configure the pipeline for an HDR10 PQ plane and blending in linear +space, a compositor might perform an atomic commit with the following +property values:: + + Plane 10 + └─ "COLOR_PIPELINE" = 42 + + Color operation 42 + └─ "BYPASS" = true + + Color operation 44 + └─ "BYPASS" = true + + Color operation 45 + └─ "BYPASS" = true + + Color operation 46 + └─ "BYPASS" = true + + Color operation 47 + ├─ "LUT_3D_DATA" = Gamut mapping + tone mapping + night mode + └─ "BYPASS" = false + + Color operation 48 + ├─ "CURVE_1D_TYPE" = PQ EOTF + └─ "BYPASS" = false + + +Driver Implementer's Guide +========================== + +What does this all mean for driver implementations? As noted above the +colorops can map to HW directly but don't need to do so. Here are some +suggestions on how to think about creating your color pipelines: + +- Try to expose pipelines that use already defined colorops, even if + your hardware pipeline is split differently. This allows existing + userspace to immediately take advantage of the hardware. + +- Additionally, try to expose your actual hardware blocks as colorops. + Define new colorop types where you believe it can offer significant + benefits if userspace learns to program them. + +- Avoid defining new colorops for compound operations with very narrow + scope. If you have a hardware block for a special operation that + cannot be split further, you can expose that as a new colorop type. + However, try to not define colorops for "use cases", especially if + they require you to combine multiple hardware blocks. + +- Design new colorops as prescriptive, not descriptive; by the + mathematical formula, not by the assumed input and output. + +A defined colorop type must be deterministic. The exact behavior of the +colorop must be documented entirely, whether via a mathematical formula +or some other description. Its operation can depend only on its +properties and input and nothing else, allowed error tolerance +notwithstanding. + + +Driver Forward/Backward Compatibility +===================================== + +As this is uAPI drivers can't regress color pipelines that have been +introduced for a given HW generation. New HW generations are free to +abandon color pipelines advertised for previous generations. +Nevertheless, it can be beneficial to carry support for existing color +pipelines forward as those will likely already have support in DRM +clients. + +Introducing new colorops to a pipeline is fine, as long as they can be +bypassed or are purely informational. DRM clients implementing support +for the pipeline can always skip unknown properties as long as they can +be confident that doing so will not cause unexpected results. + +If a new colorop doesn't fall into one of the above categories +(bypassable or informational) the modified pipeline would be unusable +for user space. In this case a new pipeline should be defined. + + +References +========== + +1. https://lore.kernel.org/dri-devel/QMers3awXvNCQlyhWdTtsPwkp5ie9bze_hD5nAccFW7a_RXlWjYB7MoUW_8CKLT2bSQwIXVi5H6VULYIxCdgvryZoAoJnC5lZgyK1QWn488=@emersion.fr/
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 08/42] drm/doc/rfc: Describe why prescriptive color pipeline is needed
Quoted 144 lines · On Mon, 26 Feb 2024 16:10:22 -0500 Harry Wentland <[email protected]>…
v4:
- Drop IOCTL docs since we dropped the IOCTLs (Pekka)
- Clarify reading and setting ofCOLOR_PIPELINEprop (Pekka)
- Add blurb about not requiring to reject a pipeline due to incompatible ops, as long as op can be bypassed (Pekka)
- Dropped informational strings (such as input CSC) as they're not actually intended to be advertised (Pekka)v3:
- DescribeDRM_CLIENT_CAP_PLANE_COLOR_PIPELINE(Sebastian)
- Ask for clear documentation of colorop behavior (Sebastian)v2:
- Update colorop visualizations to match reality (Sebastian, Alex Hung)
- Updated wording (Pekka)
- Change BYPASS wording to make it non-mandatory (Sebastian)
- Drop cover-letter-like paragraph fromCOLOR_PIPELINEPlane Property section (Pekka)
- Use PQ EOTF instead of its inverse in Pipeline Programming example (Melissa)
- Add "Driver Implementer's Guide" section (Pekka)
- Add "Driver Forward/Backward Compatibility" section (Sebastian, Pekka)Signed-off-by Harry Wentland <[email protected]>--- Documentation/gpu/rfc/color_pipeline.rst | 360 +++++++++++++++++++++++ 1 file changed, 360 insertions(+) create mode 100644 Documentation/gpu/rfc/color_pipeline.rstDocumentation/gpu/rfc/color_pipeline.rst new file +110
-0@@ -0,0 +1,360 @@ +======================== +Linux Color Pipeline API +======================== + +What problem are we solving? +============================ + +We would like to support pre-, and post-blending complex color +transformations in display controller hardware in order to allow for +HW-supported HDR use-cases, as well as to provide support to +color-managed applications, such as video or image editors. + +It is possible to support an HDR output on HW supporting the Colorspace +and HDR Metadata drm_connector properties, but that requires the +compositor or application to render and compose the content into one +final buffer intended for display. Doing so is costly. + +Most modern display HW offers various 1D LUTs, 3D LUTs, matrices, and other +operations to support color transformations. These operations are often +implemented in fixed-function HW and therefore much more power efficient than +performing similar operations via shaders or CPU. + +We would like to make use of this HW functionality to support complex color +transformations with no, or minimal CPU or shader load. + + +How are other OSes solving this problem? +======================================== + +The most widely supported use-cases regard HDR content, whether video or +gaming. + +Most OSes will specify the source content format (color gamut, encoding transfer +function, and other metadata, such as max and average light levels) to a driver. +Drivers will then program their fixed-function HW accordingly to map from a +source content buffer's space to a display's space. + +When fixed-function HW is not available the compositor will assemble a shader to +ask the GPU to perform the transformation from the source content format to the +display's format. + +A compositor's mapping function and a driver's mapping function are usually +entirely separate concepts. On OSes where a HW vendor has no insight into +closed-source compositor code such a vendor will tune their color management +code to visually match the compositor's. On other OSes, where both mapping +functions are open to an implementer they will ensure both mappings match. + +This results in mapping algorithm lock-in, meaning that no-one alone can +experiment with or introduce new mapping algorithms and achieve +consistent results regardless of which implementation path is taken. + +Why is Linux different? +======================= + +Unlike other OSes, where there is one compositor for one or more drivers, on +Linux we have a many-to-many relationship. Many compositors; many drivers. +In addition each compositor vendor or community has their own view of how +color management should be done. This is what makes Linux so beautiful. + +This means that a HW vendor can now no longer tune their driver to one +compositor, as tuning it to one could make it look fairly different from +another compositor's color mapping. + +We need a better solution. + + +Descriptive API +=============== + +An API that describes the source and destination colorspaces is a descriptive +API. It describes the input and output color spaces but does not describe +how precisely they should be mapped. Such a mapping includes many minute +design decision that can greatly affect the look of the final result. + +It is not feasible to describe such mapping with enough detail to ensure the +same result from each implementation. In fact, these mappings are a very active +research area. + + +Prescriptive API +================ + +A prescriptive API describes not the source and destination colorspaces. It +instead prescribes a recipe for how to manipulate pixel values to arrive at the +desired outcome. + +This recipe is generally an ordered list of straight-forward operations, +with clear mathematical definitions, such as 1D LUTs, 3D LUTs, matrices, +or other operations that can be described in a precise manner. + + +The Color Pipeline API +====================== + +HW color management pipelines can significantly differ between HW +vendors in terms of availability, ordering, and capabilities of HW +blocks. This makes a common definition of color management blocks and +their ordering nigh impossible. Instead we are defining an API that +allows user space to discover the HW capabilities in a generic manner, +agnostic of specific drivers and hardware. + + +drm_colorop Object +================== + +To support the definition of color pipelines we define the DRM core +object type drm_colorop. Individual drm_colorop objects will be chained +via the NEXT property of a drm_colorop to constitute a color pipeline. +Each drm_colorop object is unique, i.e., even if multiple color +pipelines have the same operation they won't share the same drm_colorop
Documentation/gpu/rfc/color_pipeline.rst line 120
Quoted 10 lines
Documentation/gpu/rfc/color_pipeline.rst new file +10
-0+object to describe that operation. + +Note that drivers are not expected to map drm_colorop objects statically +to specific HW blocks. The mapping of drm_colorop objects is entirely a +driver-internal detail and can be as dynamic or static as a driver needs +it to be. See more in the Driver Implementation Guide section below. + +Each drm_colorop has three core properties: + +TYPE: An enumeration property, definint the type of transformation, such as
typo: definint
Quoted 14 lines
Documentation/gpu/rfc/color_pipeline.rst new file +14
-0+* enumerated curve +* custom (uniform) 1D LUT +* 3x3 matrix +* 3x4 matrix +* 3D LUT +* etc. + +Depending on the type of transformation other properties will describe +more details. + +BYPASS: A boolean property that can be used to easily put a block into +bypass mode. While setting other properties might fail atomic check, +setting the BYPASS property to true should never fail. The BYPASS +property is not mandatory for a colorop, as long as the entire pipeline
Documentation/gpu/rfc/color_pipeline.rst line 144
Quoted 10 lines
Documentation/gpu/rfc/color_pipeline.rst new file +10
-0+can get bypassed by setting the COLOR_PIPELINE on a plane to '0'. + +NEXT: The ID of the next drm_colorop in a color pipeline, or 0 if this +drm_colorop is the last in the chain. + +An example of a drm_colorop object might look like one of these:: + + /* 1D enumerated curve */ + Color operation 42 + ├─ "TYPE": immutable enum {1D enumerated curve, 1D LUT, 3x3 matrix, 3x4 matrix, 3D LUT, etc.} = 1D enumerated curve
Since this is an immutable enum, does it really need to list all the possible values it will never have?
Internally DRM would have the complete list, but KMS tends to not expose enum values that cannot be picked.
Documentation/gpu/rfc/color_pipeline.rst line 146
Quoted 2 lines
Documentation/gpu/rfc/color_pipeline.rst new file +2
-0+ ├─ "BYPASS": bool {true, false} + ├─ "CURVE_1D_TYPE": enum {sRGB EOTF, sRGB inverse EOTF, PQ EOTF, PQ inverse EOTF, …}
A better name for "sRGB EOTF" would be "power 2.2", referring to a power function with exponent 2.2. I know these are just examples, but maybe giving an example of something that looks obvious but won't actually exist should be avoided.
Quoted 16 lines
Documentation/gpu/rfc/color_pipeline.rst new file +16
-0+ └─ "NEXT": immutable color operation ID = 43 + + /* custom 4k entry 1D LUT */ + Color operation 52 + ├─ "TYPE": immutable enum {1D enumerated curve, 1D LUT, 3x3 matrix, 3x4 matrix, 3D LUT, etc.} = 1D LUT + ├─ "BYPASS": bool {true, false} + ├─ "LUT_1D_SIZE": immutable range = 4096 + ├─ "LUT_1D": blob + └─ "NEXT": immutable color operation ID = 0 + + /* 17^3 3D LUT */ + Color operation 72 + ├─ "TYPE": immutable enum {1D enumerated curve, 1D LUT, 3x3 matrix, 3x4 matrix, 3D LUT, etc.} = 3D LUT + ├─ "BYPASS": bool {true, false} + ├─ "LUT_3D_SIZE": immutable range = 17 + ├─ "LUT_3D": blob
Documentation/gpu/rfc/color_pipeline.rst line 172
Quoted 10 lines
Documentation/gpu/rfc/color_pipeline.rst new file +10
-0+ └─ "NEXT": immutable color operation ID = 73 + + +COLOR_PIPELINE Plane Property +============================= + +Color Pipelines are created by a driver and advertised via a new +COLOR_PIPELINE enum property on each plane. Values of the property +always include object id 0, which is the default and means all color +processing is disabled. Additional values will be the object IDs of the
maybe "all color processing is pass-through"?
"Disabled" could read as "nothing comes through".
Documentation/gpu/rfc/color_pipeline.rst line 184
Quoted 12 lines
Documentation/gpu/rfc/color_pipeline.rst new file +12
-0+first drm_colorop in a pipeline. A driver can create and advertise none, +one, or more possible color pipelines. A DRM client will select a color +pipeline by setting the COLOR PIPELINE to the respective value. + +NOTE: Many DRM clients will set enumeration properties via the string +value, often hard-coding it. Since this enumeration is generated based +on the colorop object IDs it is important to perform the Color Pipeline +Discovery, described below, instead of hard-coding color pipeline +assignment. Drivers might generate the enum strings dynamically. +Hard-coded strings might only work for specific drivers on a specific +pieces of HW. Color Pipeline Discovery can work universally, as long as +drivers implement the required color operations.
Yes!
Should there be rules about the string names for drivers? Can any driver pick anything, even if it conflicts with a different kind of pipeline?
Documentation/gpu/rfc/color_pipeline.rst line 192
Quoted 8 lines
Documentation/gpu/rfc/color_pipeline.rst new file +8
-0+ +The COLOR_PIPELINE property is only exposed when the +DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE is set. Drivers shall ignore any +existing pre-blend color operations when this cap is set, such as +COLOR_RANGE and COLOR_ENCODING. If drivers want to support COLOR_RANGE +or COLOR_ENCODING functionality when the color pipeline client cap is +set, they are expected to expose colorops in the pipeline to allow for +the appropriate color transformation.
I see it's called plane color pipeline, so I presume there will be another cap for post-blending pipelines. Ok.
Quoted 41 lines
Documentation/gpu/rfc/color_pipeline.rst new file +41
-0+ +Setting of the COLOR_PIPELINE plane property or drm_colorop properties +is only allowed for userspace that sets this client cap. + +An example of a COLOR_PIPELINE property on a plane might look like this:: + + Plane 10 + ├─ "TYPE": immutable enum {Overlay, Primary, Cursor} = Primary + ├─ … + └─ "COLOR_PIPELINE": enum {0, 42, 52} = 0 + + +Color Pipeline Discovery +======================== + +A DRM client wanting color management on a drm_plane will: + +1. Get the COLOR_PIPELINE property of the plane +2. iterate all COLOR_PIPELINE enum values +3. for each enum value walk the color pipeline (via the NEXT pointers) + and see if the available color operations are suitable for the + desired color management operations + +If userspace encounters an unknown or unsuitable color operation during +discovery it does not need to reject the entire color pipeline outright, +as long as the unknown or unsuitable colorop has a "BYPASS" property. +Drivers will ensure that a bypassed block does not have any effect. + +An example of chained properties to define an AMD pre-blending color +pipeline might look like this:: + + Plane 10 + ├─ "TYPE" (immutable) = Primary + └─ "COLOR_PIPELINE": enum {0, 44} = 0 + + Color operation 44 + ├─ "TYPE" (immutable) = 1D enumerated curve + ├─ "BYPASS": bool + ├─ "CURVE_1D_TYPE": enum {sRGB EOTF, PQ EOTF} = sRGB EOTF + └─ "NEXT" (immutable) = 45 +
Documentation/gpu/rfc/color_pipeline.rst line 243
Quoted 10 lines
Documentation/gpu/rfc/color_pipeline.rst new file +10
-0+ Color operation 45 + ├─ "TYPE" (immutable) = 3x4 Matrix + ├─ "BYPASS": bool + ├─ "MATRIX_3_4": blob + └─ "NEXT" (immutable) = 46 + + Color operation 46 + ├─ "TYPE" (immutable) = 1D enumerated curve + ├─ "BYPASS": bool + ├─ "CURVE_1D_TYPE": enum {sRGB Inverse EOTF, PQ Inverse EOTF} = sRGB EOTF
Current value is illegal. ;-)
Documentation/gpu/rfc/color_pipeline.rst line 253
Quoted 10 lines
Documentation/gpu/rfc/color_pipeline.rst new file +10
-0+ └─ "NEXT" (immutable) = 47 + + Color operation 47 + ├─ "TYPE" (immutable) = 1D LUT + ├─ "LUT_1D_SIZE": immutable range = 4096 + ├─ "LUT_1D_DATA": blob + └─ "NEXT" (immutable) = 48 + + Color operation 48 + ├─ "TYPE" (immutable) = 3D LUT
I see these LUT things do not have BYPASS. They probably should, even if it is equivalent to setting the data blob to 0.
Quoted 54 lines
Documentation/gpu/rfc/color_pipeline.rst new file +54
-0+ ├─ "LUT_3D_SIZE" (immutable) = 17 + ├─ "LUT_3D_DATA": blob + └─ "NEXT" (immutable) = 49 + + Color operation 49 + ├─ "TYPE" (immutable) = 1D enumerated curve + ├─ "BYPASS": bool + ├─ "CURVE_1D_TYPE": enum {sRGB EOTF, PQ EOTF} = sRGB EOTF + └─ "NEXT" (immutable) = 0 + + +Color Pipeline Programming +========================== + +Once a DRM client has found a suitable pipeline it will: + +1. Set the COLOR_PIPELINE enum value to the one pointing at the first + drm_colorop object of the desired pipeline +2. Set the properties for all drm_colorop objects in the pipeline to the + desired values, setting BYPASS to true for unused drm_colorop blocks, + and false for enabled drm_colorop blocks +3. Perform (TEST_ONLY or not) atomic commit with all the other KMS + states it wishes to change + +To configure the pipeline for an HDR10 PQ plane and blending in linear +space, a compositor might perform an atomic commit with the following +property values:: + + Plane 10 + └─ "COLOR_PIPELINE" = 42 + + Color operation 42 + └─ "BYPASS" = true + + Color operation 44 + └─ "BYPASS" = true + + Color operation 45 + └─ "BYPASS" = true + + Color operation 46 + └─ "BYPASS" = true + + Color operation 47 + ├─ "LUT_3D_DATA" = Gamut mapping + tone mapping + night mode + └─ "BYPASS" = false + + Color operation 48 + ├─ "CURVE_1D_TYPE" = PQ EOTF + └─ "BYPASS" = false + + +Driver Implementer's Guide +==========================
Documentation/gpu/rfc/color_pipeline.rst line 317
Quoted 10 lines
Documentation/gpu/rfc/color_pipeline.rst new file +10
-0+ +What does this all mean for driver implementations? As noted above the +colorops can map to HW directly but don't need to do so. Here are some +suggestions on how to think about creating your color pipelines: + +- Try to expose pipelines that use already defined colorops, even if + your hardware pipeline is split differently. This allows existing + userspace to immediately take advantage of the hardware. + +- Additionally, try to expose your actual hardware blocks as colorops.
...colorops in additional pipelines.
Especially if exposing hw-specific blocks together with generic blocks in the same pipeline would result in the possibility of unsupported combinations.
Maybe there should be a general rule, that it must be possible to enable all colorops in the same pipeline simultaneously?
Quoted 34 lines
Documentation/gpu/rfc/color_pipeline.rst new file +34
-0+ Define new colorop types where you believe it can offer significant + benefits if userspace learns to program them. + +- Avoid defining new colorops for compound operations with very narrow + scope. If you have a hardware block for a special operation that + cannot be split further, you can expose that as a new colorop type. + However, try to not define colorops for "use cases", especially if + they require you to combine multiple hardware blocks. + +- Design new colorops as prescriptive, not descriptive; by the + mathematical formula, not by the assumed input and output. + +A defined colorop type must be deterministic. The exact behavior of the +colorop must be documented entirely, whether via a mathematical formula +or some other description. Its operation can depend only on its +properties and input and nothing else, allowed error tolerance +notwithstanding. + + +Driver Forward/Backward Compatibility +===================================== + +As this is uAPI drivers can't regress color pipelines that have been +introduced for a given HW generation. New HW generations are free to +abandon color pipelines advertised for previous generations. +Nevertheless, it can be beneficial to carry support for existing color +pipelines forward as those will likely already have support in DRM +clients. + +Introducing new colorops to a pipeline is fine, as long as they can be +bypassed or are purely informational. DRM clients implementing support +for the pipeline can always skip unknown properties as long as they can +be confident that doing so will not cause unexpected results. +
Documentation/gpu/rfc/color_pipeline.rst line 360
Quoted 10 lines
Documentation/gpu/rfc/color_pipeline.rst new file +9
-0+If a new colorop doesn't fall into one of the above categories +(bypassable or informational) the modified pipeline would be unusable +for user space. In this case a new pipeline should be defined. + + +References +========== + +1. https://lore.kernel.org/dri-devel/QMers3awXvNCQlyhWdTtsPwkp5ie9bze_hD5nAccFW7a_RXlWjYB7MoUW_8CKLT2bSQwIXVi5H6VULYIxCdgvryZoAoJnC5lZgyK1QWn488=@emersion.fr/
All in all, I think this is good enough to have my
in spite of the comments I had. They are just fine tuning.
Thanks,
pq
Harry Wentland
maintainerRFC PATCH v4 9/42 drm/colorop: Introduce new drm_colorop mode object
In reply to Harry WentlandThis patches introduces a new drm_colorop mode object. This object represents color transformations and can be used to define color pipelines.
We also introduce the drm_colorop_state here, as well as various helpers and state tracking bits.
v4:
- Drop IOCTL definitions (Pekka)
- add missing declaration (Chaitanya Kumar Borah)
v3:
- Drop TODO for lock (it's handled in drm_modeset_drop_locks) (Melissa)
- Don't get plane state when getting colorop state
- Make some functions static (kernel test robot)
--- drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_atomic.c | 70 ++++++++++++ drivers/gpu/drm/drm_atomic_helper.c | 12 +++ drivers/gpu/drm/drm_atomic_uapi.c | 48 +++++++++ drivers/gpu/drm/drm_colorop.c | 152 ++++++++++++++++++++++++++ drivers/gpu/drm/drm_mode_config.c | 7 ++ include/drm/drm_atomic.h | 82 +++++++++++++++ include/drm/drm_atomic_uapi.h | 1 + include/drm/drm_colorop.h | 158 ++++++++++++++++++++++++++++ include/drm/drm_mode_config.h | 18 ++++ include/drm/drm_plane.h | 2 + include/uapi/drm/drm_mode.h | 1 + 12 files changed, 552 insertions(+) create mode 100644 drivers/gpu/drm/drm_colorop.c create mode 100644 include/drm/drm_colorop.h
drivers/gpu/drm/Makefile +1 -0
@@ -16,6 +16,7 @@ drm-y := \ drm_client.o \ drm_client_modeset.o \ drm_color_mgmt.o \ + drm_colorop.o \ drm_connector.o \ drm_crtc.o \ drm_displayid.o \
drivers/gpu/drm/drm_atomic.c +70 -0
100 lines not on this page · raw message
drivers/gpu/drm/drm_atomic_helper.c +12 -0
@@ -3022,6 +3022,8 @@ int drm_atomic_helper_swap_state(struct drm_atomic_state *state,struct drm_crtc_state *old_crtc_state, *new_crtc_state;struct drm_plane *plane;struct drm_plane_state *old_plane_state, *new_plane_state; +struct drm_colorop *colorop; +struct drm_colorop_state *old_colorop_state, *new_colorop_state;struct drm_crtc_commit *commit;struct drm_private_obj *obj;struct drm_private_state *old_obj_state, *new_obj_state;
@@ -3099,6 +3101,16 @@ int drm_atomic_helper_swap_state(struct drm_atomic_state *state, } } +for_each_oldnew_colorop_in_state (state, colorop, old_colorop_state, new_colorop_state, i) { +WARN_ON (colorop->state != old_colorop_state); + + old_colorop_state->state = state; + new_colorop_state->state =NULL ; + + state->colorops[i].state = old_colorop_state; + colorop->state = new_colorop_state; + } +for_each_oldnew_plane_in_state (state, plane, old_plane_state, new_plane_state, i) {WARN_ON (plane->state != old_plane_state);
drivers/gpu/drm/drm_atomic_uapi.c +48 -0
72 lines not on this page · raw message
drivers/gpu/drm/drm_colorop.c new file +152 -0
152 lines not on this page · raw message
drivers/gpu/drm/drm_mode_config.c +7 -0
@@ -29,6 +29,7 @@#include <drm/drm_managed.h> #include <drm/drm_mode_config.h> #include <drm/drm_print.h> +#include <drm/drm_colorop.h> #include <linux/dma-resv.h> #include "drm_crtc_internal.h"
@@ -182,11 +183,15 @@ int drm_mode_getresources(struct drm_device *dev, void *data,void drm_mode_config_reset (struct drm_device *dev) {struct drm_crtc *crtc; +struct drm_colorop *colorop;struct drm_plane *plane;struct drm_encoder *encoder;struct drm_connector *connector;struct drm_connector_list_iter conn_iter; +drm_for_each_colorop (colorop, dev) +drm_colorop_reset (colorop); +drm_for_each_plane (plane, dev)if (plane->funcs->reset) plane->funcs->reset (plane);
@@ -413,6 +418,7 @@ int drmm_mode_config_init(struct drm_device *dev)INIT_LIST_HEAD (&dev->mode_config.property_list);INIT_LIST_HEAD (&dev->mode_config.property_blob_list);INIT_LIST_HEAD (&dev->mode_config.plane_list); +INIT_LIST_HEAD (&dev->mode_config.colorop_list);INIT_LIST_HEAD (&dev->mode_config.privobj_list);idr_init_base (&dev->mode_config.object_idr,1 );idr_init_base (&dev->mode_config.tile_idr,1 );
@@ -434,6 +440,7 @@ int drmm_mode_config_init(struct drm_device *dev) dev->mode_config.num_crtc =0 ; dev->mode_config.num_encoder =0 ; dev->mode_config.num_total_plane =0 ; + dev->mode_config.num_colorop =0 ;if (IS_ENABLED (CONFIG_LOCKDEP )) {struct drm_modeset_acquire_ctx modeset_ctx;
include/drm/drm_atomic.h +82 -0
118 lines not on this page · raw message
include/drm/drm_atomic_uapi.h +1 -0
@@ -37,6 +37,7 @@ struct drm_crtc;struct drm_connector_state ;struct dma_fence ;struct drm_framebuffer ; +struct drm_colorop ; int __must_check drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
include/drm/drm_colorop.h new file +158 -0
158 lines not on this page · raw message
include/drm/drm_mode_config.h +18 -0
@@ -505,6 +505,24 @@ struct drm_mode_config {*/ struct list_head plane_list; +/** +* @num_colorop: +* +* Number of colorop objects on this device. +* This is invariant over the lifetime of a device and hence doesn't +* need any locks. +*/ +int num_colorop; + +/** +* @colorops_list: +* +* List of colorop objects linked with &drm_colorop.head. This is +* invariant over the lifetime of a device and hence doesn't need any +* locks. +*/ +struct list_head colorop_list; +/** * @num_crtc: *
include/drm/drm_plane.h +2 -0
@@ -241,6 +241,8 @@ struct drm_plane_state {*/ enum drm_scaling_filter scaling_filter; +struct drm_colorop *color_pipeline; +/** * @commit: Tracks the pending commit to prevent use-after-free conditions, * and for async plane updates.
include/uapi/drm/drm_mode.h +1 -0
@@ -629,6 +629,7 @@ struct drm_mode_connector_set_property {#define DRM_MODE_OBJECT_FB 0xfbfbfbfb#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee +#define DRM_MODE_OBJECT_COLOROP 0xfafafafa#define DRM_MODE_OBJECT_ANY 0struct drm_mode_obj_get_properties {
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 09/42] drm/colorop: Introduce new drm_colorop mode object
Quoted 806 lines · Harry Wentland
This patches introduces a new
drm_coloropmode object. This object represents color transformations and can be used to define color pipelines.We also introduce the
drm_colorop_statehere, as well as various helpers and state tracking bits.v4:
- Drop IOCTL definitions (Pekka)
- add missing declaration (Chaitanya Kumar Borah)v3:
- Drop TODO for lock (it's handled indrm_modeset_drop_locks) (Melissa)
- Don't get plane state when getting colorop state
- Make some functions static (kernel test robot)Signed-off-by Harry Wentland <[email protected]>--- drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_atomic.c | 70 ++++++++++++ drivers/gpu/drm/drm_atomic_helper.c | 12 +++ drivers/gpu/drm/drm_atomic_uapi.c | 48 +++++++++ drivers/gpu/drm/drm_colorop.c | 152 ++++++++++++++++++++++++++ drivers/gpu/drm/drm_mode_config.c | 7 ++ include/drm/drm_atomic.h | 82 +++++++++++++++ include/drm/drm_atomic_uapi.h | 1 + include/drm/drm_colorop.h | 158 ++++++++++++++++++++++++++++ include/drm/drm_mode_config.h | 18 ++++ include/drm/drm_plane.h | 2 + include/uapi/drm/drm_mode.h | 1 + 12 files changed, 552 insertions(+) create mode 100644 drivers/gpu/drm/drm_colorop.c create mode 100644 include/drm/drm_colorop.hdrivers/gpu/drm/Makefile +1
-0@@ -16,6 +16,7 @@ drm-y := \ drm_client.o \ drm_client_modeset.o \ drm_color_mgmt.o \ + drm_colorop.o \ drm_connector.o \ drm_crtc.o \ drm_displayid.o \drivers/gpu/drm/drm_atomic.c +70
-0@@ -42,6 +42,7 @@#include <drm/drm_mode.h> #include <drm/drm_print.h> #include <drm/drm_writeback.h> +#include <drm/drm_colorop.h> #include "drm_crtc_internal.h" #include "drm_internal.h" @@ -108,6 +109,7 @@ void drm_atomic_state_default_release(struct drm_atomic_state *state)kfree (state->connectors);kfree (state->crtcs);kfree (state->planes); +kfree (state->colorops);kfree (state->private_objs); }EXPORT_SYMBOL (drm_atomic_state_default_release);@@ -139,6 +141,10 @@ drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state) sizeof(*state->planes), GFP_KERNEL);if (!state->planes) goto fail; + state->colorops =kcalloc (dev->mode_config.num_colorop, +sizeof (*state->colorops),GFP_KERNEL ); +if (!state->colorops) + goto fail;/* * Because drm_atomic_state can be committed asynchronously we need our @@ -250,6 +256,20 @@ void drm_atomic_state_default_clear(struct drm_atomic_state *state) state->planes[i].new_state =NULL ; } +for (i =0 ; i < config->num_colorop; i++) { +struct drm_colorop *colorop = state->colorops[i].ptr; + +if (!colorop) +continue ; + +drm_colorop_atomic_destroy_state (colorop, + state->colorops[i].state); + state->colorops[i].ptr =NULL ; + state->colorops[i].state =NULL ; + state->colorops[i].old_state =NULL ; + state->colorops[i].new_state =NULL ; + } +for (i =0 ; i < state->num_private_objs; i++) {struct drm_private_obj *obj = state->private_objs[i].ptr;@@ -571,6 +591,56 @@ drm_atomic_get_plane_state(struct drm_atomic_state *state, }EXPORT_SYMBOL (drm_atomic_get_plane_state); + +/** +* drm_atomic_get_colorop_state - get colorop state +* @state: global atomic state object +* @colorop: colorop to get state object for +* +* This function returns the colorop state for the given colorop, allocating it +* if needed. It will also grab the relevant plane lock to make sure that the +* state is consistent. +* +* Returns: +* +* Either the allocated state or the error code encoded into the pointer. When +* the error is EDEADLK then the w/w mutex code has detected a deadlock and the +* entire atomic sequence must be restarted. All other errors are fatal. +*/ +struct drm_colorop_state * +drm_atomic_get_colorop_state (struct drm_atomic_state *state, +struct drm_colorop *colorop) +{ +int ret, index =drm_colorop_index (colorop); +struct drm_colorop_state *colorop_state; + +WARN_ON (!state->acquire_ctx); + + colorop_state =drm_atomic_get_existing_colorop_state (state, colorop); +if (colorop_state) +return colorop_state; + + ret =drm_modeset_lock (&colorop->plane->mutex, state->acquire_ctx); +if (ret) +return ERR_PTR (ret); + + colorop_state =drm_atomic_helper_colorop_duplicate_state (colorop); +if (!colorop_state) +return ERR_PTR (-ENOMEM ); + + state->colorops[index].state = colorop_state; + state->colorops[index].ptr = colorop; + state->colorops[index].old_state = colorop->state; + state->colorops[index].new_state = colorop_state; + colorop_state->state = state; + +drm_dbg_atomic (colorop->dev,"Added [COLOROP:%d] %p state to %p\n" , + colorop->base.id, colorop_state, state); + +return colorop_state; +} +EXPORT_SYMBOL (drm_atomic_get_colorop_state); +static bool plane_switching_crtc (const struct drm_plane_state *old_plane_state,const struct drm_plane_state *new_plane_state)drivers/gpu/drm/drm_atomic_helper.c +12
-0@@ -3022,6 +3022,8 @@ int drm_atomic_helper_swap_state(struct drm_atomic_state *state,struct drm_crtc_state *old_crtc_state, *new_crtc_state;struct drm_plane *plane;struct drm_plane_state *old_plane_state, *new_plane_state; +struct drm_colorop *colorop; +struct drm_colorop_state *old_colorop_state, *new_colorop_state;struct drm_crtc_commit *commit;struct drm_private_obj *obj;struct drm_private_state *old_obj_state, *new_obj_state;@@ -3099,6 +3101,16 @@ int drm_atomic_helper_swap_state(struct drm_atomic_state *state, } } +for_each_oldnew_colorop_in_state (state, colorop, old_colorop_state, new_colorop_state, i) { +WARN_ON (colorop->state != old_colorop_state); + + old_colorop_state->state = state; + new_colorop_state->state =NULL ; + + state->colorops[i].state = old_colorop_state; + colorop->state = new_colorop_state; + } +for_each_oldnew_plane_in_state (state, plane, old_plane_state, new_plane_state, i) {WARN_ON (plane->state != old_plane_state);drivers/gpu/drm/drm_atomic_uapi.c +48
-0@@ -34,6 +34,7 @@#include <drm/drm_drv.h> #include <drm/drm_writeback.h> #include <drm/drm_vblank.h> +#include <drm/drm_colorop.h> #include <linux/dma-fence.h> #include <linux/uaccess.h> @@ -642,6 +643,26 @@ drm_atomic_plane_get_property(struct drm_plane *plane,return 0 ; } + +static int drm_atomic_colorop_set_property (struct drm_colorop *colorop, +struct drm_colorop_state *state,struct drm_file *file_priv, +struct drm_property *property,uint64_t val) +{ +drm_dbg_atomic (colorop->dev, +"[COLOROP:%d] unknown property [PROP:%d:%s]]\n" , + colorop->base.id, + property->base.id, property->name); +return -EINVAL ; +} + +static int +drm_atomic_colorop_get_property (struct drm_colorop *colorop, +const struct drm_colorop_state *state, +struct drm_property *property,uint64_t *val) +{ +return -EINVAL ; +} +static int drm_atomic_set_writeback_fb_for_connector (struct drm_connector_state *conn_state,struct drm_framebuffer *fb)@@ -904,6 +925,16 @@ int drm_atomic_get_property(struct drm_mode_object *obj, plane->state, property, val);break ; } +case DRM_MODE_OBJECT_COLOROP : { +struct drm_colorop *colorop =obj_to_colorop (obj); + +if (colorop->plane) +WARN_ON (!drm_modeset_is_locked (&colorop->plane->mutex)); + + ret =drm_atomic_colorop_get_property (colorop, + colorop->state, property, val); +break ; + }default :drm_dbg_atomic (dev,"[OBJECT:%d] has no properties\n" , obj->id); ret = -EINVAL ;@@ -1084,6 +1115,23 @@ int drm_atomic_set_property(struct drm_atomic_state *state, ret =drm_atomic_plane_set_property (plane, plane_state, file_priv, prop, prop_value); + +break ; + } +case DRM_MODE_OBJECT_COLOROP : { +struct drm_colorop *colorop =obj_to_colorop (obj); +struct drm_colorop_state *colorop_state; + + colorop_state =drm_atomic_get_colorop_state (state, colorop); +if (IS_ERR (colorop_state)) { + ret =PTR_ERR (colorop_state); +break ; + } + + ret =drm_atomic_colorop_set_property (colorop, + colorop_state, file_priv, + prop, prop_value); +break ; }default :drivers/gpu/drm/drm_colorop.c new file +152
-0@@ -0,0 +1,152 @@ +/* +* Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Authors: AMD +* +*/ + +#include <drm/drm_colorop.h> +#include <drm/drm_print.h> +#include <drm/drm_drv.h> +#include <drm/drm_plane.h> + +#include "drm_crtc_internal.h" + +/* TODO big colorop doc, including properties, etc. */ + +/* Init Helpers */ + +int drm_colorop_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane) +{ +struct drm_mode_config *config = &dev->mode_config; +int ret =0 ; + + ret =drm_mode_object_add (dev, &colorop->base,DRM_MODE_OBJECT_COLOROP ); +if (ret) +return ret; + + colorop->base.properties = &colorop->properties; + colorop->dev = dev; + colorop->plane = plane; + +list_add_tail (&colorop->head, &config->colorop_list); + colorop->index = config->num_colorop++; + +/* add properties */ +return ret; +} +EXPORT_SYMBOL (drm_colorop_init); + +static void __drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop, +struct drm_colorop_state *state) +{ +memcpy (state, colorop->state,sizeof (*state)); +} + +struct drm_colorop_state * +drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop) +{ +struct drm_colorop_state *state; + +if (WARN_ON (!colorop->state)) +return NULL ; + + state =kmalloc (sizeof (*state),GFP_KERNEL ); +if (state) +__drm_atomic_helper_colorop_duplicate_state (colorop, state); + +return state; +} + + +void drm_colorop_atomic_destroy_state (struct drm_colorop *colorop, +struct drm_colorop_state *state) +{ +kfree (state); +} + +/** +* drm_colorop_destroy_state - default state destroy hook +* @colorop: drm colorop +* @state: colorop state object to release +* +* Default colorop state destroy hook for drivers which don't have their own +* subclassed colorop state structure. +*/ +void drm_colorop_destroy_state (struct drm_colorop *colorop, +struct drm_colorop_state *state) +{ +kfree (state); +} +EXPORT_SYMBOL (drm_colorop_destroy_state); + +/** +* __drm_colorop_state_reset - resets colorop state to default values +* @colorop_state: atomic colorop state, must not be NULL +* @colorop: colorop object, must not be NULL +* +* Initializes the newly allocated @colorop_state with default +* values. This is useful for drivers that subclass the CRTC state. +*/ +static void __drm_colorop_state_reset (struct drm_colorop_state *colorop_state, +struct drm_colorop *colorop) +{ + colorop_state->colorop = colorop; +} + +/** +* __drm_colorop_reset - reset state on colorop +* @colorop: drm colorop +* @colorop_state: colorop state to assign +* +* Initializes the newly allocated @colorop_state and assigns it to +* the &drm_crtc->state pointer of @colorop, usually required when +* initializing the drivers or when called from the &drm_colorop_funcs.reset +* hook. +* +* This is useful for drivers that subclass the colorop state. +*/ +static void __drm_colorop_reset (struct drm_colorop *colorop, +struct drm_colorop_state *colorop_state) +{ +if (colorop_state) +__drm_colorop_state_reset (colorop_state, colorop); + + colorop->state = colorop_state; +} + +/** +* drm_colorop_reset - reset colorop atomic state +* @colorop: drm colorop +* +* Resets the atomic state for @colorop by freeing the state pointer (which might +* be NULL, e.g. at driver load time) and allocating a new empty state object. +*/ +void drm_colorop_reset (struct drm_colorop *colorop) +{ +kfree (colorop->state); + colorop->state =kzalloc (sizeof (*colorop->state),GFP_KERNEL ); + +if (colorop->state) +__drm_colorop_reset (colorop, colorop->state); +} +EXPORT_SYMBOL (drm_colorop_reset);drivers/gpu/drm/drm_mode_config.c +7
-0@@ -29,6 +29,7 @@#include <drm/drm_managed.h> #include <drm/drm_mode_config.h> #include <drm/drm_print.h> +#include <drm/drm_colorop.h> #include <linux/dma-resv.h> #include "drm_crtc_internal.h" @@ -182,11 +183,15 @@ int drm_mode_getresources(struct drm_device *dev, void *data,void drm_mode_config_reset (struct drm_device *dev) {struct drm_crtc *crtc; +struct drm_colorop *colorop;struct drm_plane *plane;struct drm_encoder *encoder;struct drm_connector *connector;struct drm_connector_list_iter conn_iter; +drm_for_each_colorop (colorop, dev) +drm_colorop_reset (colorop); +drm_for_each_plane (plane, dev)if (plane->funcs->reset) plane->funcs->reset (plane);@@ -413,6 +418,7 @@ int drmm_mode_config_init(struct drm_device *dev)INIT_LIST_HEAD (&dev->mode_config.property_list);INIT_LIST_HEAD (&dev->mode_config.property_blob_list);INIT_LIST_HEAD (&dev->mode_config.plane_list); +INIT_LIST_HEAD (&dev->mode_config.colorop_list);INIT_LIST_HEAD (&dev->mode_config.privobj_list);idr_init_base (&dev->mode_config.object_idr,1 );idr_init_base (&dev->mode_config.tile_idr,1 );@@ -434,6 +440,7 @@ int drmm_mode_config_init(struct drm_device *dev) dev->mode_config.num_crtc =0 ; dev->mode_config.num_encoder =0 ; dev->mode_config.num_total_plane =0 ; + dev->mode_config.num_colorop =0 ;if (IS_ENABLED (CONFIG_LOCKDEP )) {struct drm_modeset_acquire_ctx modeset_ctx;include/drm/drm_atomic.h +82
-0@@ -30,6 +30,7 @@#include <drm/drm_crtc.h> #include <drm/drm_util.h> +#include <drm/drm_colorop.h> /** * struct drm_crtc_commit - track modeset commits on a CRTC @@ -157,6 +158,11 @@ struct drm_crtc_commit {bool abort_completion; }; +struct __drm_colorops_state { +struct drm_colorop *ptr; +struct drm_colorop_state *state, *old_state, *new_state; +}; +struct __drm_planes_state {struct drm_plane *ptr;struct drm_plane_state *state, *old_state, *new_state;@@ -398,6 +404,7 @@ struct drm_atomic_state {* states. */ bool duplicated : 1; +struct __drm_colorops_state *colorops;struct __drm_planes_state *planes;struct __drm_crtcs_state *crtcs;int num_connector;@@ -501,6 +508,9 @@ drm_atomic_get_crtc_state(struct drm_atomic_state *state,struct drm_plane_state *__must_check drm_atomic_get_plane_state (struct drm_atomic_state *state,struct drm_plane *plane); +struct drm_colorop_state * +drm_atomic_get_colorop_state (struct drm_atomic_state *state, +struct drm_colorop *colorop);struct drm_connector_state *__must_check drm_atomic_get_connector_state (struct drm_atomic_state *state,struct drm_connector *connector);@@ -630,6 +640,55 @@ drm_atomic_get_new_plane_state(const struct drm_atomic_state *state,return state->planes[drm_plane_index (plane)].new_state; } + +/** +* drm_atomic_get_existing_colorop_state - get colorop state, if it exists +* @state: global atomic state object +* @colorop: colorop to grab +* +* This function returns the colorop state for the given colorop, or NULL +* if the colorop is not part of the global atomic state. +* +* This function is deprecated, @drm_atomic_get_old_colorop_state or +* @drm_atomic_get_new_colorop_state should be used instead. +*/ +static inline struct drm_colorop_state * +drm_atomic_get_existing_colorop_state (struct drm_atomic_state *state, +struct drm_colorop *colorop) +{ +return state->colorops[drm_colorop_index (colorop)].state; +} + +/** +* drm_atomic_get_old_colorop_state - get colorop state, if it exists +* @state: global atomic state object +* @colorop: colorop to grab +* +* This function returns the old colorop state for the given colorop, or +* NULL if the colorop is not part of the global atomic state. +*/ +static inline struct drm_colorop_state * +drm_atomic_get_old_colorop_state (struct drm_atomic_state *state, +struct drm_colorop *colorop) +{ +return state->colorops[drm_colorop_index (colorop)].old_state; +} + +/** +* drm_atomic_get_new_colorop_state - get colorop state, if it exists +* @state: global atomic state object +* @colorop: colorop to grab +* +* This function returns the new colorop state for the given colorop, or +* NULL if the colorop is not part of the global atomic state. +*/ +static inline struct drm_colorop_state * +drm_atomic_get_new_colorop_state (struct drm_atomic_state *state, +struct drm_colorop *colorop) +{ +return state->colorops[drm_colorop_index (colorop)].new_state; +} +/** * drm_atomic_get_existing_connector_state - get connector state, if it exists * @state: global atomic state object @@ -877,6 +936,29 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p); (new_crtc_state) = (__state)->crtcs[__i].new_state, \ (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1)) +/** +* for_each_oldnew_colorop_in_state - iterate over all colorops in an atomic update +* @__state: &struct drm_atomic_state pointer +* @colorop: &struct drm_colorop iteration cursor +* @old_colorop_state: &struct drm_colorop_state iteration cursor for the old state +* @new_colorop_state: &struct drm_colorop_state iteration cursor for the new state +* @__i: int iteration cursor, for macro-internal use +* +* This iterates over all colorops in an atomic update, tracking both old and +* new state. This is useful in places where the state delta needs to be +* considered, for example in atomic check functions. +*/ +#define for_each_oldnew_colorop_in_state(__state, colorop, old_colorop_state, new_colorop_state, __i) \ + for ((__i) = 0; \ + (__i) < (__state)->dev->mode_config.num_colorop; \ + (__i)++) \ + for_each_if ((__state)->colorops[__i].ptr && \ + ((colorop) = (__state)->colorops[__i].ptr, \ + (void)(colorop) /* Only to avoid unused-but-set-variable warning */, \ + (old_colorop_state) = (__state)->colorops[__i].old_state,\ + (new_colorop_state) = (__state)->colorops[__i].new_state, 1)) + +/** * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update * @__state: &struct drm_atomic_state pointer include/drm/drm_atomic_uapi.h +1
-0@@ -37,6 +37,7 @@ struct drm_crtc;struct drm_connector_state ;struct dma_fence ;struct drm_framebuffer ; +struct drm_colorop ; int __must_check drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,include/drm/drm_colorop.h new file +158
-0@@ -0,0 +1,158 @@ +/* +* Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Authors: AMD +* +*/ + +#ifndef __DRM_COLOROP_H__ +#define __DRM_COLOROP_H__ + +#include <drm/drm_mode_object.h> +#include <drm/drm_mode.h> +#include <drm/drm_property.h> + +/** +* struct drm_colorop_state - mutable colorop state +*/ +struct drm_colorop_state { +/** @colorop: backpointer to the colorop */ +struct drm_colorop *colorop; + +/* colorop properties */ + +/** @state: backpointer to global drm_atomic_state */ +struct drm_atomic_state *state; +}; + +/** +* struct drm_colorop - DRM color operation control structure +* +* A colorop represents one color operation. They can be chained via +* the 'next' pointer to build a color pipeline. +*/ +struct drm_colorop { +/** @dev: parent DRM device */ +struct drm_device *dev; + +/** +* @head: +* +* List of all colorops on @dev, linked from &drm_mode_config.colorop_list. +* Invariant over the lifetime of @dev and therefore does not need +* locking. +*/ +struct list_head head; + +/** +* @index: Position inside the mode_config.list, can be used as an array +* index. It is invariant over the lifetime of the plane. +*/ +unsigned index; + +/* TODO do we need a separate mutex or will we tag along with the plane mutex? */ + +/** @base base mode object*/ +struct drm_mode_object base; + +/** +* @plane: +* +* The plane on which the colorop sits. A drm_colorop is always unique +* to a plane. +*/ +struct drm_plane *plane; + +/** +* @state: +* +* Current atomic state for this colorop. +* +* This is protected by @mutex. Note that nonblocking atomic commits +* access the current colorop state without taking locks. Either by +* going through the &struct drm_atomic_state pointers, see +* for_each_oldnew_plane_in_state(), for_each_old_plane_in_state() and +* for_each_new_plane_in_state(). Or through careful ordering of atomic +* commit operations as implemented in the atomic helpers, see +* &struct drm_crtc_commit. +* +* TODO keep, remove, or rewrite above plane references? +*/ +struct drm_colorop_state *state; + +/* colorop properties */ + +/** @properties: property tracking for this plane */ +struct drm_object_properties properties; + +}; + +#define obj_to_colorop (x) container_of(x, struct drm_colorop, base) + +/** +* drm_crtc_find - look up a Colorop object from its ID +* @dev: DRM device +* @file_priv: drm file to check for lease against. +* @id: &drm_mode_object ID +* +* This can be used to look up a Colorop from its userspace ID. Only used by +* drivers for legacy IOCTLs and interface, nowadays extensions to the KMS +* userspace interface should be done using &drm_property. +*/ +static inline struct drm_colorop *drm_colorop_find (struct drm_device *dev, +struct drm_file *file_priv, +uint32_t id) +{ +struct drm_mode_object *mo; + mo =drm_mode_object_find (dev, file_priv, id,DRM_MODE_OBJECT_COLOROP ); +return mo ?obj_to_colorop (mo) :NULL ; +} + +int drm_colorop_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane); + +struct drm_colorop_state * +drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop); + +void drm_colorop_atomic_destroy_state (struct drm_colorop *colorop, +struct drm_colorop_state *state); +void drm_colorop_destroy_state (struct drm_colorop *colorop, +struct drm_colorop_state *state); +void drm_colorop_reset (struct drm_colorop *colorop); + +/** +* drm_colorop_index - find the index of a registered colorop +* @colorop: colorop to find index for +* +* Given a registered colorop, return the index of that colorop within a DRM +* device's list of colorops. +*/ +static inline unsigned int drm_colorop_index (const struct drm_colorop *colorop) +{ +return colorop->index; +} + + +#define drm_for_each_colorop (colorop, dev) \ + list_for_each_entry(colorop, &(dev)->mode_config.colorop_list, head) + + +#endif /* __DRM_COLOROP_H__ */ include/drm/drm_mode_config.h +18
-0@@ -505,6 +505,24 @@ struct drm_mode_config {*/ struct list_head plane_list; +/** +* @num_colorop: +* +* Number of colorop objects on this device. +* This is invariant over the lifetime of a device and hence doesn't +* need any locks. +*/ +int num_colorop; + +/** +* @colorops_list: +* +* List of colorop objects linked with &drm_colorop.head. This is +* invariant over the lifetime of a device and hence doesn't need any +* locks. +*/ +struct list_head colorop_list; +/** * @num_crtc: * include/drm/drm_plane.h +0
-0
include/drm/drm_plane.h struct drm_plane_state { · line 243
Quoted 3 lines
include/drm/drm_plane.h +0
-0@@ -241,6 +241,8 @@ struct drm_plane_state {*/ enum drm_scaling_filter scaling_filter;
Missing kerneldocs for @color_pipeline.
Quoted 20 lines
include/drm/drm_plane.h +2
-0+struct drm_colorop *color_pipeline; +/** * @commit: Tracks the pending commit to prevent use-after-free conditions, * and for async plane updates. include/uapi/drm/drm_mode.h +1
-0@@ -629,6 +629,7 @@ struct drm_mode_connector_set_property {#define DRM_MODE_OBJECT_FB 0xfbfbfbfb#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee +#define DRM_MODE_OBJECT_COLOROP 0xfafafafa#define DRM_MODE_OBJECT_ANY 0struct drm_mode_obj_get_properties {Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 10/42 drm/colorop: Add TYPE property
In reply to Harry WentlandAdd a read-only TYPE property. The TYPE specifies the colorop type, such as enumerated curve, 1D LUT, CTM, 3D LUT, PWL LUT, etc.
v4:
- Use enum property for TYPE (Pekka)
v3:
- Make TYPE a range property
- Move enum drm_colorop_type to uapi header
- Fix drm_get_colorop_type_name description
For now we're only introducing an enumerated 1D LUT type to illustrate the concept.
--- drivers/gpu/drm/drm_atomic.c | 4 +-- drivers/gpu/drm/drm_atomic_uapi.c | 8 +++++- drivers/gpu/drm/drm_colorop.c | 44 ++++++++++++++++++++++++++++++- include/drm/drm_colorop.h | 17 +++++++++++- include/uapi/drm/drm_mode.h | 4 +++ 5 files changed, 72 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_atomic.c +2 -2
@@ -634,8 +634,8 @@ drm_atomic_get_colorop_state(struct drm_atomic_state *state, state->colorops[index].new_state = colorop_state; colorop_state->state = state; -drm_dbg_atomic (colorop->dev,"Added [COLOROP:%d] %p state to %p\n" , - colorop->base.id, colorop_state, state); +drm_dbg_atomic (colorop->dev,"Added [COLOROP:%d:%d] %p state to %p\n" , + colorop->base.id, colorop->type, colorop_state, state);return colorop_state; }
drivers/gpu/drm/drm_atomic_uapi.c +7 -1
@@ -660,7 +660,13 @@ drm_atomic_colorop_get_property(struct drm_colorop *colorop,const struct drm_colorop_state *state, struct drm_property *property, uint64_t *val) { - return -EINVAL; + if (property == colorop->type_property) { + *val = colorop->type; + } else { +return -EINVAL ; + } + +return 0 ; } static int drm_atomic_set_writeback_fb_for_connector(
drivers/gpu/drm/drm_colorop.c +43 -1
70 lines not on this page · raw message
include/drm/drm_colorop.h +16 -1
@@ -103,6 +103,21 @@ struct drm_colorop {/** @properties: property tracking for this plane */ struct drm_object_properties properties; +/** +* @type: +* +* Read-only +* Type of color operation +*/ +enum drm_colorop_type type; + +/** +* @type_property: +* +* Read-only "TYPE" property for specifying the type of +* this color operation. The type is enum drm_colorop_type. +*/ +struct drm_property *type_property; };#define obj_to_colorop (x) container_of(x, struct drm_colorop, base)
@@ -127,7 +142,7 @@ static inline struct drm_colorop *drm_colorop_find(struct drm_device *dev, }int drm_colorop_init (struct drm_device *dev,struct drm_colorop *colorop, -struct drm_plane *plane); +struct drm_plane *plane,enum drm_colorop_type type);struct drm_colorop_state *drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop);
include/uapi/drm/drm_mode.h +4 -0
@@ -866,6 +866,10 @@ struct drm_color_lut {__u16 reserved; }; +enum drm_colorop_type { +DRM_COLOROP_1D_CURVE +}; +/** * struct hdr_metadata_infoframe - HDR Metadata Infoframe Data. *
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 10/42] drm/colorop: Add TYPE property
Quoted 23 lines · On Mon, 26 Feb 2024 16:10:24 -0500 Harry Wentland <[email protected]>…
Add a read-only TYPE property. The TYPE specifies the colorop type, such as enumerated curve, 1D LUT, CTM, 3D LUT, PWL LUT, etc.
v4:
- Use enum property for TYPE (Pekka)v3:
- Make TYPE a range property
- Move enumdrm_colorop_typeto uapi header
- Fixdrm_get_colorop_type_namedescriptionFor now we're only introducing an enumerated 1D LUT type to illustrate the concept.
Signed-off-by Harry Wentland <[email protected]>--- drivers/gpu/drm/drm_atomic.c | 4 +-- drivers/gpu/drm/drm_atomic_uapi.c | 8 +++++- drivers/gpu/drm/drm_colorop.c | 44 ++++++++++++++++++++++++++++++- include/drm/drm_colorop.h | 17 +++++++++++- include/uapi/drm/drm_mode.h | 4 +++ 5 files changed, 72 insertions(+), 5 deletions(-)
...
Quoted 30 lines
drivers/gpu/drm/drm_colorop.c +7
-1@@ -32,12 +32,17 @@/* TODO big colorop doc, including properties, etc. */ +static const struct drm_prop_enum_list drm_colorop_type_enum_list[] = { + {DRM_COLOROP_1D_CURVE ,"1D Curve" }, +}; +/* Init Helpers */ int drm_colorop_init (struct drm_device *dev,struct drm_colorop *colorop, -struct drm_plane *plane) +struct drm_plane *plane,enum drm_colorop_type type) {struct drm_mode_config *config = &dev->mode_config; +struct drm_property *prop;int ret =0 ; ret =drm_mode_object_add (dev, &colorop->base,DRM_MODE_OBJECT_COLOROP );@@ -46,12 +51,29 @@ int drm_colorop_init(struct drm_device *dev, struct drm_colorop *colorop, colorop->base.properties = &colorop->properties; colorop->dev = dev; + colorop->type = type; colorop->plane = plane;
drivers/gpu/drm/drm_colorop.c int drm_colorop_init(struct drm_device *dev, struct drm_colorop *colorop, · line 66
Quoted 10 lines
drivers/gpu/drm/drm_colorop.c +6
-0list_add_tail (&colorop->head, &config->colorop_list); colorop->index = config->num_colorop++;/* add properties */ + +/* type */ + prop =drm_property_create_enum (dev, +DRM_MODE_PROP_IMMUTABLE , +"TYPE" , drm_colorop_type_enum_list, +ARRAY_SIZE (drm_colorop_type_enum_list));
This list here is the list of all values the enum could take, right? Should it not be just the one value it's going to have? It'll never change, and it can never be changed.
drivers/gpu/drm/drm_colorop.c int drm_colorop_init(struct drm_device *dev, struct drm_colorop *colorop, · line 79
Quoted 13 lines
drivers/gpu/drm/drm_colorop.c +10
-0+ +if (!prop) +return -ENOMEM ; + + colorop->type_property = prop; + +drm_object_attach_property (&colorop->base, + colorop->type_property, + colorop->type); +return ret; }EXPORT_SYMBOL (drm_colorop_init);
Thanks,
pq
Re: [RFC PATCH v4 10/42] drm/colorop: Add TYPE property
Quoted 3 lines · Pekka Paalanen
This list here is the list of all values the enum could take, right? Should it not be just the one value it's going to have? It'll never change, and it can never be changed.
Listing all possible values is how other properties behave. Example:
"type" (immutable): enum {Overlay, Primary, Cursor} = Primary
Re: [RFC PATCH v4 10/42] drm/colorop: Add TYPE property
Quoted 9 lines · On Tue, 12 Mar 2024 15:15:13 +0000 Simon Ser <[email protected]> wrote:
Quoted 3 lines · Pekka Paalanen
This list here is the list of all values the enum could take, right? Should it not be just the one value it's going to have? It'll never change, and it can never be changed.
Listing all possible values is how other properties behave. Example:
"type" (immutable): enum {Overlay, Primary, Cursor} = Primary
Yeah, that's weird, now that you pointed it out.
Userspace does nothing with the knowledge of what this specific object's property "could" be since it's immutable. Only the kernel internals and UAPI docs need the full list, and userspace needs to hardcode the full list in general so it can recognize each value. But on the property instance on a specific object, I see no use for the full list.
Thanks,
pq
Harry Wentland
maintainerRFC PATCH v4 11/42 drm/colorop: Add 1D Curve subtype
In reply to Harry Wentlandv4:
- Use drm_colorop_curve_1d_type_enum_list to get name (Pekka)
- Create separate init function for 1D curve
- Pass supported TFs into 1D curve init function
--- drivers/gpu/drm/drm_atomic_uapi.c | 18 +++++--- drivers/gpu/drm/drm_colorop.c | 71 +++++++++++++++++++++++++++++++ include/drm/drm_colorop.h | 24 +++++++++++ 3 files changed, 108 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_atomic_uapi.c +13 -5
@@ -648,11 +648,17 @@ static int drm_atomic_colorop_set_property(struct drm_colorop *colorop, struct drm_colorop_state *state, struct drm_file *file_priv, struct drm_property *property, uint64_t val) { - drm_dbg_atomic(colorop->dev, -"[COLOROP:%d] unknown property [PROP:%d:%s]]\n" , - colorop->base.id, - property->base.id, property->name); -return -EINVAL ; + if (property == colorop->curve_1d_type_property) { + state->curve_1d_type = val; + } else { +drm_dbg_atomic (colorop->dev, +"[COLOROP:%d:%d] unknown property [PROP:%d:%s]]\n" , + colorop->base.id, colorop->type, + property->base.id, property->name); +return -EINVAL ; + } + +return 0 ; } static int
@@ -662,6 +668,8 @@ drm_atomic_colorop_get_property(struct drm_colorop *colorop, {if (property == colorop->type_property) { *val = colorop->type; + }else if (property == colorop->curve_1d_type_property) { + *val = state->curve_1d_type; }else {return -EINVAL ; }
drivers/gpu/drm/drm_colorop.c +71 -0
86 lines not on this page · raw message
include/drm/drm_colorop.h +24 -0
@@ -30,6 +30,12 @@#include <drm/drm_mode.h> #include <drm/drm_property.h> +enum drm_colorop_curve_1d_type { +DRM_COLOROP_1D_CURVE_SRGB_EOTF , +DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF , +DRM_COLOROP_1D_CURVE_COUNT +}; +/** * struct drm_colorop_state - mutable colorop state */
@@ -39,6 +45,13 @@ struct drm_colorop_state {/* colorop properties */ +/** +* @curve_1d_type: +* +* Type of 1D curve. +*/ +enum drm_colorop_curve_1d_type curve_1d_type; +/** @state: backpointer to global drm_atomic_state */ struct drm_atomic_state *state; };
@@ -118,6 +131,14 @@ struct drm_colorop {* this color operation. The type is enum drm_colorop_type. */ struct drm_property *type_property; + +/** +* @curve_1d_type: +* +* Sub-type for DRM_COLOROP_1D_CURVE type. +*/ +struct drm_property *curve_1d_type_property; + };#define obj_to_colorop (x) container_of(x, struct drm_colorop, base)
@@ -144,6 +165,9 @@ static inline struct drm_colorop *drm_colorop_find(struct drm_device *dev,int drm_colorop_init (struct drm_device *dev,struct drm_colorop *colorop,struct drm_plane *plane,enum drm_colorop_type type); +int drm_colorop_curve_1d_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane,u64 supported_tfs); +struct drm_colorop_state *drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop);
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 12/42 drm/colorop: Add BYPASS property
In reply to Harry WentlandWe want to be able to bypass each colorop at all times. Introduce a new BYPASS boolean property for this.
--- drivers/gpu/drm/drm_atomic_uapi.c | 6 +++++- drivers/gpu/drm/drm_colorop.c | 16 ++++++++++++++++ include/drm/drm_colorop.h | 20 ++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic_uapi.c +5 -1
@@ -648,7 +648,9 @@ static int drm_atomic_colorop_set_property(struct drm_colorop *colorop, struct drm_colorop_state *state, struct drm_file *file_priv, struct drm_property *property, uint64_t val) { - if (property == colorop->curve_1d_type_property) { + if (property == colorop->bypass_property) { + state->bypass = val; + } else if (property == colorop->curve_1d_type_property) { state->curve_1d_type = val; }else { drm_dbg_atomic(colorop->dev,
@@ -668,6 +670,8 @@ drm_atomic_colorop_get_property(struct drm_colorop *colorop, {if (property == colorop->type_property) { *val = colorop->type; + }else if (property == colorop->bypass_property) { + *val = state->bypass; }else if (property == colorop->curve_1d_type_property) { *val = state->curve_1d_type; }else {
drivers/gpu/drm/drm_colorop.c +16 -0
@@ -80,6 +80,18 @@ int drm_colorop_init(struct drm_device *dev, struct drm_colorop *colorop, colorop->type_property, colorop->type); +/* bypass */ +/* TODO can we reuse the mode_config->active_prop? */ + prop =drm_property_create_bool (dev,DRM_MODE_PROP_ATOMIC , +"BYPASS" ); +if (!prop) +return -ENOMEM ; + + colorop->bypass_property = prop; +drm_object_attach_property (&colorop->base, + colorop->bypass_property, +1 ); +return ret; }EXPORT_SYMBOL (drm_colorop_init);
@@ -123,6 +135,7 @@ int drm_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *coloro/* initialize 1D curve only attribute */ prop =drm_property_create_enum (dev,DRM_MODE_PROP_ATOMIC ,"CURVE_1D_TYPE" , enum_list, len); +if (!prop)return -ENOMEM ;
@@ -138,6 +151,8 @@ static void __drm_atomic_helper_colorop_duplicate_state(struct drm_colorop *colo struct drm_colorop_state *state) {memcpy (state, colorop->state,sizeof (*state)); + + state->bypass = true; } struct drm_colorop_state *
@@ -189,6 +204,7 @@ static void __drm_colorop_state_reset(struct drm_colorop_state *colorop_state, struct drm_colorop *colorop) { colorop_state->colorop = colorop; + colorop_state->bypass = true; }/**
include/drm/drm_colorop.h +20 -0
@@ -45,6 +45,14 @@ struct drm_colorop_state {/* colorop properties */ +/** +* @bypass: +* +* True if colorop shall be bypassed. False if colorop is +* enabled. +*/ +bool bypass; +/** * @curve_1d_type: *
@@ -132,6 +140,18 @@ struct drm_colorop {*/ struct drm_property *type_property; +/** +* @bypass_property: +* +* Boolean property to control enablement of the color +* operation. Setting bypass to "true" shall always be supported +* in order to allow compositors to quickly fall back to +* alternate methods of color processing. This is important +* since setting color operations can fail due to unique +* HW constraints. +*/ +struct drm_property *bypass_property; +/** * @curve_1d_type: *
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 13/42 drm/colorop: Add NEXT property
In reply to Harry WentlandWe'll construct color pipelines out of drm_colorop by chaining them via the NEXT pointer. NEXT will point to the next drm_colorop in the pipeline, or by 0 if we're at the end of the pipeline.
v4:
- Allow setting of NEXT property to NULL (Chaitanya Kumar Borah)
v3:
- Add next pointer to colorop to be used by drivers and in DRM core
--- drivers/gpu/drm/drm_colorop.c | 29 +++++++++++++++++++++++++++++ include/drm/drm_colorop.h | 20 ++++++++++++++++++++ 2 files changed, 49 insertions(+)
drivers/gpu/drm/drm_colorop.c +29 -0
@@ -59,6 +59,7 @@ int drm_colorop_init(struct drm_device *dev, struct drm_colorop *colorop, colorop->dev = dev; colorop->type = type; colorop->plane = plane; + colorop->next =NULL ;list_add_tail (&colorop->head, &config->colorop_list); colorop->index = config->num_colorop++;
@@ -92,6 +93,15 @@ int drm_colorop_init(struct drm_device *dev, struct drm_colorop *colorop, colorop->bypass_property, 1); + prop =drm_property_create_object (dev,DRM_MODE_PROP_IMMUTABLE |DRM_MODE_PROP_ATOMIC , +"NEXT" ,DRM_MODE_OBJECT_COLOROP ); +if (!prop) +return -ENOMEM ; + colorop->next_property = prop; +drm_object_attach_property (&colorop->base, + colorop->next_property, +0 ); +return ret; }EXPORT_SYMBOL (drm_colorop_init);
@@ -279,3 +289,22 @@ const char *drm_get_colorop_curve_1d_type_name(enum drm_colorop_curve_1d_type tyreturn colorop_curve_1d_type_names[type]; } + +/** +* drm_colorop_set_next_property - sets the next pointer +* @colorop: drm colorop +* @next: next colorop +* +* Should be used when constructing the color pipeline +*/ +void drm_colorop_set_next_property (struct drm_colorop *colorop,struct drm_colorop *next) +{ +if (!colorop->next_property) +return ; + +drm_object_property_set_value (&colorop->base, + colorop->next_property, + next ? next->base.id :0 ); + colorop->next = next; +} +EXPORT_SYMBOL (drm_colorop_set_next_property);
include/drm/drm_colorop.h +20 -0
@@ -132,6 +132,14 @@ struct drm_colorop {*/ enum drm_colorop_type type; +/** +* @next: +* +* Read-only +* Pointer to next drm_colorop in pipeline +*/ +struct drm_colorop *next; +/** * @type_property: *
@@ -159,10 +167,20 @@ struct drm_colorop {*/ struct drm_property *curve_1d_type_property; +/** +* @next_property +* +* Read-only property to next colorop in the pipeline +*/ +struct drm_property *next_property; + };#define obj_to_colorop (x) container_of(x, struct drm_colorop, base) + + +/** * drm_crtc_find - look up a Colorop object from its ID * @dev: DRM device
@@ -213,5 +231,7 @@ static inline unsigned int drm_colorop_index(const struct drm_colorop *colorop)#define drm_for_each_colorop (colorop, dev) \ list_for_each_entry(colorop, &(dev)->mode_config.colorop_list, head) +void drm_colorop_set_next_property (struct drm_colorop *colorop,struct drm_colorop *next); +#endif /* __DRM_COLOROP_H__ */
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 14/42 drm/colorop: Add atomic state print for drm_colorop
In reply to Harry Wentland--- drivers/gpu/drm/drm_atomic.c | 25 ++++++++++++++++++++++++- include/drm/drm_colorop.h | 5 +++++ 2 files changed, 29 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic.c +24 -1
@@ -783,6 +783,19 @@ static int drm_atomic_plane_check(const struct drm_plane_state *old_plane_state,return 0 ; } + + +static void drm_atomic_colorop_print_state (struct drm_printer *p, +const struct drm_colorop_state *state) +{ +struct drm_colorop *colorop = state->colorop; + +drm_printf (p,"colorop[%u]:\n" , colorop->base.id); +drm_printf (p,"\ttype=%s\n" ,drm_get_colorop_type_name (colorop->type)); +drm_printf (p,"\tbypass=%u\n" , state->bypass); +drm_printf (p,"\tcurve_1d_type=%s\n" ,drm_get_colorop_curve_1d_type_name (state->curve_1d_type)); +} +static void drm_atomic_plane_print_state (struct drm_printer *p,const struct drm_plane_state *state) {
@@ -804,7 +817,8 @@ static void drm_atomic_plane_print_state(struct drm_printer *p,drm_printf (p,"\tcolor-range=%s\n" ,drm_get_color_range_name (state->color_range));drm_printf (p,"\tcolor_mgmt_changed=%d\n" , state->color_mgmt_changed); - +drm_printf (p,"\tcolor-pipeline=%d\n" , + state->color_pipeline ? state->color_pipeline->base.id :0 );if (plane->funcs->atomic_print_state) plane->funcs->atomic_print_state (p, state); }
@@ -1840,6 +1854,7 @@ static void __drm_state_dump(struct drm_device *dev, struct drm_printer *p, bool take_locks) {struct drm_mode_config *config = &dev->mode_config; +struct drm_colorop *colorop;struct drm_plane *plane;struct drm_crtc *crtc;struct drm_connector *connector;
@@ -1849,6 +1864,14 @@ static void __drm_state_dump(struct drm_device *dev, struct drm_printer *p,if (!drm_drv_uses_atomic_modeset (dev))return ; +list_for_each_entry (colorop, &config->colorop_list, head) { +if (take_locks) +drm_modeset_lock (&colorop->plane->mutex,NULL ); +drm_atomic_colorop_print_state (p, colorop->state); +if (take_locks) +drm_modeset_unlock (&colorop->plane->mutex); + } +list_for_each_entry (plane, &config->plane_list, head) {if (take_locks)drm_modeset_lock (&plane->mutex,NULL );
include/drm/drm_colorop.h +5 -0
@@ -231,6 +231,11 @@ static inline unsigned int drm_colorop_index(const struct drm_colorop *colorop)#define drm_for_each_colorop (colorop, dev) \ list_for_each_entry(colorop, &(dev)->mode_config.colorop_list, head) +const char *drm_get_color_pipeline_name (struct drm_colorop *colorop); + +const char *drm_get_colorop_type_name (enum drm_colorop_type type); +const char *drm_get_colorop_curve_1d_type_name (enum drm_colorop_curve_1d_type type); +void drm_colorop_set_next_property (struct drm_colorop *colorop,struct drm_colorop *next);
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 15/42 drm/plane: Add COLOR PIPELINE property
In reply to Harry WentlandWe're adding a new enum COLOR PIPELINE property. This property will have entries for each COLOR PIPELINE by referencing the DRM object ID of the first drm_colorop of the pipeline. 0 disables the entire COLOR PIPELINE.
Userspace can use this to discover the available color pipelines, as well as set the desired one. The color pipelines are programmed via properties on the actual drm_colorop objects.
v4:
- Add pipeline property creation helper (Pekka)
- Fix function comment for drm_atomic_set_colorop_for_plane (Pekka)
- Always create Bypass pipeline (Pekka)
- Add missing function declaration (Chaitanya Kumar Borah)
--- drivers/gpu/drm/drm_atomic.c | 46 ++++++++++++++++++++ drivers/gpu/drm/drm_atomic_state_helper.c | 5 +++ drivers/gpu/drm/drm_atomic_uapi.c | 42 ++++++++++++++++++ drivers/gpu/drm/drm_plane.c | 52 +++++++++++++++++++++++ include/drm/drm_atomic.h | 3 ++ include/drm/drm_atomic_uapi.h | 2 + include/drm/drm_plane.h | 11 +++++ 7 files changed, 161 insertions(+)
drivers/gpu/drm/drm_atomic.c +46 -0
@@ -1458,6 +1458,52 @@ drm_atomic_add_affected_planes(struct drm_atomic_state *state, }EXPORT_SYMBOL (drm_atomic_add_affected_planes); +/** +* drm_atomic_add_affected_colorops - add colorops for plane +* @state: atomic state +* @plane: DRM plane +* +* This function walks the current configuration and adds all colorops +* currently used by @plane to the atomic configuration @state. This is useful +* when an atomic commit also needs to check all currently enabled colorop on +* @plane, e.g. when changing the mode. It's also useful when re-enabling a plane +* to avoid special code to force-enable all colorops. +* +* Since acquiring a colorop state will always also acquire the w/w mutex of the +* current plane for that colorop (if there is any) adding all the colorop states for +* a plane will not reduce parallelism of atomic updates. +* +* Returns: +* 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK +* then the w/w mutex code has detected a deadlock and the entire atomic +* sequence must be restarted. All other errors are fatal. +*/ +int +drm_atomic_add_affected_colorops (struct drm_atomic_state *state, +struct drm_plane *plane) +{ +struct drm_colorop *colorop; +struct drm_colorop_state *colorop_state; + +WARN_ON (!drm_atomic_get_new_plane_state (state, plane)); + +drm_dbg_atomic (plane->dev, +"Adding all current colorops for [plane:%d:%s] to %p\n" , + plane->base.id, plane->name, state); + +drm_for_each_colorop (colorop, plane->dev) { +if (colorop->plane != plane) +continue ; + + colorop_state =drm_atomic_get_colorop_state (state, colorop); +if (IS_ERR (colorop_state)) +return PTR_ERR (colorop_state); + } + +return 0 ; +} +EXPORT_SYMBOL (drm_atomic_add_affected_colorops); +/** * drm_atomic_check_only - check whether a given config would work * @state: atomic configuration to check
drivers/gpu/drm/drm_atomic_state_helper.c +5 -0
@@ -267,6 +267,11 @@ void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state, plane_state->color_range = val; } +if (plane->color_pipeline_property) { +/* default is always NULL, i.e., bypass */ + plane_state->color_pipeline =NULL ; + } + if (plane->zpos_property) { if (!drm_object_property_get_default_value(&plane->base, plane->zpos_property,
drivers/gpu/drm/drm_atomic_uapi.c +42 -0
60 lines not on this page · raw message
drivers/gpu/drm/drm_plane.c +52 -0
56 lines not on this page · raw message
include/drm/drm_atomic.h +3 -0
@@ -797,6 +797,9 @@ drm_atomic_add_affected_connectors(struct drm_atomic_state *state,int __must_check drm_atomic_add_affected_planes (struct drm_atomic_state *state,struct drm_crtc *crtc); +int __must_check +drm_atomic_add_affected_colorops (struct drm_atomic_state *state, +struct drm_plane *plane);int __must_check drm_atomic_check_only (struct drm_atomic_state *state);int __must_check drm_atomic_commit (struct drm_atomic_state *state);
include/drm/drm_atomic_uapi.h +2 -0
@@ -50,6 +50,8 @@ drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state, struct drm_crtc *crtc);void drm_atomic_set_fb_for_plane (struct drm_plane_state *plane_state,struct drm_framebuffer *fb); +void drm_atomic_set_colorop_for_plane (struct drm_plane_state *plane_state, +struct drm_colorop *colorop);int __must_check drm_atomic_set_crtc_for_connector (struct drm_connector_state *conn_state,struct drm_crtc *crtc);
include/drm/drm_plane.h +11 -0
@@ -766,6 +766,14 @@ struct drm_plane {*/ struct drm_property *color_range_property; +/** +* @color_pipeline_property: +* +* Optional "COLOR_PIPELINE" enum property for specifying +* a color pipeline to use on the plane. +*/ +struct drm_property *color_pipeline_property; +/** * @scaling_filter_property: property to apply a particular filter while * scaling.
@@ -979,4 +987,7 @@ drm_plane_get_damage_clips(const struct drm_plane_state *state);int drm_plane_create_scaling_filter_property (struct drm_plane *plane,unsigned int supported_filters); +int drm_plane_create_color_pipeline_property (struct drm_plane *plane, +struct drm_prop_enum_list *pipelines, +int num_pipelines);#endif
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 16/42 drm/colorop: Add NEXT to colorop state print
In reply to Harry Wentlandv3:
- Read NEXT ID from drm_colorop's next pointer
--- drivers/gpu/drm/drm_atomic.c | 1 + include/drm/drm_colorop.h | 2 ++ 2 files changed, 3 insertions(+)
drivers/gpu/drm/drm_atomic.c +1 -0
@@ -794,6 +794,7 @@ static void drm_atomic_colorop_print_state(struct drm_printer *p,drm_printf (p,"\ttype=%s\n" ,drm_get_colorop_type_name (colorop->type));drm_printf (p,"\tbypass=%u\n" , state->bypass);drm_printf (p,"\tcurve_1d_type=%s\n" ,drm_get_colorop_curve_1d_type_name (state->curve_1d_type)); +drm_printf (p,"\tnext=%d\n" , colorop->next ? colorop->next->base.id :0 ); } static void drm_atomic_plane_print_state(struct drm_printer *p,
include/drm/drm_colorop.h +2 -0
@@ -237,6 +237,8 @@ const char *drm_get_colorop_type_name(enum drm_colorop_type type);const char *drm_get_colorop_curve_1d_type_name (enum drm_colorop_curve_1d_type type);void drm_colorop_set_next_property (struct drm_colorop *colorop,struct drm_colorop *next); +uint32_t drm_colorop_get_next_property (struct drm_colorop *colorop); +struct drm_colorop *drm_colorop_get_next (struct drm_colorop *colorop);#endif /* __DRM_COLOROP_H__ */
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 17/42 drm/vkms: Add enumerated 1D curve colorop
In reply to Harry WentlandThis patch introduces a VKMS color pipeline that includes two drm_colorops for named transfer functions. For now the only ones supported are sRGB EOTF, sRGB Inverse EOTF, and a Linear TF. We will expand this in the future but I don't want to do so without accompanying IGT tests.
We introduce a new vkms_luts.c file that hard-codes sRGB EOTF, sRGB Inverse EOTF, and a linear EOTF LUT. These have been generated with 256 entries each as IGT is currently testing only 8 bpc surfaces. We will likely need higher precision but I'm reluctant to make that change without clear indication that we need it. We'll revisit and, if necessary, regenerate the LUTs when we have IGT tests for higher precision buffers.
v4:
- Drop _tf_ from color_pipeline init function
- Pass supported TFs into colorop init
- Create bypass pipeline in DRM helper (Pekka)
v2:
- Add commit description
- Fix sRGB EOTF LUT definition
- Add linear and sRGB inverse EOTF LUTs
--- drivers/gpu/drm/vkms/Makefile | 4 +- drivers/gpu/drm/vkms/vkms_colorop.c | 70 +++ drivers/gpu/drm/vkms/vkms_composer.c | 45 ++ drivers/gpu/drm/vkms/vkms_drv.h | 4 + drivers/gpu/drm/vkms/vkms_luts.c | 802 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 2 + 7 files changed, 938 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/vkms/vkms_colorop.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.h
drivers/gpu/drm/vkms/Makefile +3 -1
@@ -6,6 +6,8 @@ vkms-y := \ vkms_formats.o \ vkms_crtc.o \ vkms_composer.o \ - vkms_writeback.o + vkms_writeback.o \ + vkms_colorop.o \ + vkms_luts.o obj-$(CONFIG_DRM_VKMS) += vkms.o
drivers/gpu/drm/vkms/vkms_colorop.c new file +70 -0
70 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_composer.c +45 -0
63 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_drv.h +4 -0
@@ -170,4 +170,8 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_buffer/* Writeback */ int vkms_enable_writeback_connector (struct vkms_device *vkmsdev); +/* Colorops */ +int vkms_initialize_colorops (struct drm_plane *plane); + +#endif /* _VKMS_DRV_H_ */
drivers/gpu/drm/vkms/vkms_luts.c new file +802 -0
802 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_luts.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _VKMS_LUTS_H_ +#define _VKMS_LUTS_H_ + +#define LUT_SIZE 256 + +extern const struct vkms_color_lut linear_eotf; +extern const struct vkms_color_lut srgb_eotf; +extern const struct vkms_color_lut srgb_inv_eotf; + +#endif /* _VKMS_LUTS_H_ */
drivers/gpu/drm/vkms/vkms_plane.c +2 -0
@@ -215,5 +215,7 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,drm_plane_create_rotation_property (&plane->base,DRM_MODE_ROTATE_0 ,DRM_MODE_ROTATE_MASK |DRM_MODE_REFLECT_MASK ); +vkms_initialize_colorops (&plane->base); +return plane; }
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 17/42] drm/vkms: Add enumerated 1D curve colorop
Quoted 38 lines · On Mon, 26 Feb 2024 16:10:31 -0500 Harry Wentland <[email protected]>…
This patch introduces a VKMS color pipeline that includes two
drm_coloropsfor named transfer functions. For now the only ones supported are sRGB EOTF, sRGB Inverse EOTF, and a Linear TF. We will expand this in the future but I don't want to do so without accompanying IGT tests.We introduce a new
vkms_luts.cfile that hard-codes sRGB EOTF, sRGB Inverse EOTF, and a linear EOTF LUT. These have been generated with 256 entries each as IGT is currently testing only 8 bpc surfaces. We will likely need higher precision but I'm reluctant to make that change without clear indication that we need it. We'll revisit and, if necessary, regenerate the LUTs when we have IGT tests for higher precision buffers.v4:
- Drop _tf_ fromcolor_pipelineinit function
- Pass supported TFs into colorop init
- Create bypass pipeline in DRM helper (Pekka)v2:
- Add commit description
- Fix sRGB EOTF LUT definition
- Add linear and sRGB inverse EOTF LUTsSigned-off-by Harry Wentland <[email protected]>Signed-off-by Alex Hung <[email protected]>--- drivers/gpu/drm/vkms/Makefile | 4 +- drivers/gpu/drm/vkms/vkms_colorop.c | 70 +++ drivers/gpu/drm/vkms/vkms_composer.c | 45 ++ drivers/gpu/drm/vkms/vkms_drv.h | 4 + drivers/gpu/drm/vkms/vkms_luts.c | 802 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 2 + 7 files changed, 938 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/vkms/vkms_colorop.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.h
...
Quoted 13 lines
drivers/gpu/drm/vkms/vkms_composer.c +1
-0@@ -12,6 +12,7 @@#include <linux/minmax.h> #include "vkms_drv.h" +#include "vkms_luts.h" static u16 pre_mul_blend_channel (u16 src,u16 dst,u16 alpha) {
drivers/gpu/drm/vkms/vkms_composer.c static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff · line 171
Quoted 8 lines
drivers/gpu/drm/vkms/vkms_composer.c +5
-0@@ -163,6 +164,47 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff } } +static void pre_blend_color_transform (const struct vkms_plane_state *plane_state,struct line_buffer *output_buffer) +{ +struct drm_colorop *colorop = plane_state->base.base.color_pipeline; + +while (colorop) {
I think this would be easier to read if you used
for (; colorop; colorop = colorop->next) {and
drivers/gpu/drm/vkms/vkms_composer.c static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff · line 181
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_composer.c +10
-0+struct drm_colorop_state *colorop_state; + +if (!colorop) +return ; + +/* TODO this is probably wrong */ + colorop_state = colorop->state; + +if (!colorop_state) +return ;
if (colorop_state->bypass) continue;
Something about 'switch (colorop->type)' to pick a function pointer to call, but hard to see at this point of the series how that would work.
However, you can pick between srgb_inv_eotf and srgb_eotf already here. Then inside the loop you can just call one set of apply_lut_to_channel_value() and not need conditionals and avoid indentation levels.
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_composer.c +10
-0+ +for (size_t x =0 ; x < output_buffer->n_pixels; x++) { +struct pixel_argb_u16 *pixel = &output_buffer->pixels[x]; + +if (colorop->type ==DRM_COLOROP_1D_CURVE && + colorop_state->bypass == false) { +switch (colorop_state->curve_1d_type) { +case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF : + pixel->r =apply_lut_to_channel_value (&srgb_inv_eotf, pixel->r,LUT_RED ); + pixel->g =apply_lut_to_channel_value (&srgb_inv_eotf, pixel->g,LUT_GREEN );
drivers/gpu/drm/vkms/vkms_composer.c static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff · line 201
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_composer.c +10
-0+ pixel->b =apply_lut_to_channel_value (&srgb_inv_eotf, pixel->b,LUT_BLUE ); +break ; +case DRM_COLOROP_1D_CURVE_SRGB_EOTF : +default : + pixel->r =apply_lut_to_channel_value (&srgb_eotf, pixel->r,LUT_RED ); + pixel->g =apply_lut_to_channel_value (&srgb_eotf, pixel->g,LUT_GREEN ); + pixel->b =apply_lut_to_channel_value (&srgb_eotf, pixel->b,LUT_BLUE ); +break ; + } + }
else { aaargh_unknown_colorop(); }
Quoted 5 lines
drivers/gpu/drm/vkms/vkms_composer.c +5
-0+ } + + colorop = colorop->next; + } +}
...
drivers/gpu/drm/vkms/vkms_luts.c line 7
Quoted 13 lines
drivers/gpu/drm/vkms/vkms_luts.c new file +7
-0@@ -0,0 +1,802 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#include <drm/drm_mode.h> + +#include "vkms_drv.h" +#include "vkms_luts.h" +
Here it would be really nice to explain how the tables were generated.
Quoted 2 lines
drivers/gpu/drm/vkms/vkms_luts.c new file +2
-0+static struct drm_color_lut linear_array[LUT_SIZE ] = { + {0x0 ,0x0 ,0x0 ,0 },
...
drivers/gpu/drm/vkms/vkms_luts.c line 269
Quoted 6 lines
drivers/gpu/drm/vkms/vkms_luts.c new file +6
-0+ { 0xffff, 0xffff, 0xffff, 0 }, +}; + +const struct vkms_color_lut linear_eotf = { + .base = linear_array, + .lut_length = LUT_SIZE,
Why not use just 2 table entries for the linear array?
I didn't see linear_eotf used at all? It could also just skip in the code, not need an array.
drivers/gpu/drm/vkms/vkms_luts.c
Quoted 2 lines
drivers/gpu/drm/vkms/vkms_luts.c new file +2
-0+ .channel_value2index_ratio = 0xff00ffll +};
Thanks,
pq
Harry Wentland
maintainerRFC PATCH v4 18/42 drm/vkms: Add kunit tests for linear and sRGB LUTs
In reply to Harry Wentland--- drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-)
drivers/gpu/drm/vkms/tests/vkms_color_tests.c +36 -1
@@ -31,7 +31,6 @@ const struct vkms_color_lut test_linear_lut = { .channel_value2index_ratio = 0xf000fll }; -static void vkms_color_test_get_lut_index (struct kunit *test) {int i;
@@ -40,6 +39,19 @@ static void vkms_color_test_get_lut_index(struct kunit *test)for (i =0 ; i <TEST_LUT_SIZE ; i++)KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&test_linear_lut, test_linear_array[i].red)), i); + +KUNIT_EXPECT_EQ (test,drm_fixp2int (get_lut_index (&srgb_eotf,0x0 )),0x0 ); +KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&srgb_eotf,0x0 )),0x0 ); +KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&srgb_eotf,0x101 )),0x1 ); +KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&srgb_eotf,0x202 )),0x2 ); + +KUNIT_EXPECT_EQ (test,drm_fixp2int (get_lut_index (&srgb_inv_eotf,0x0 )),0x0 ); +KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&srgb_inv_eotf,0x0 )),0x0 ); +KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&srgb_inv_eotf,0x101 )),0x1 ); +KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&srgb_inv_eotf,0x202 )),0x2 ); + +KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&srgb_eotf,0xfefe )),0xfe ); +KUNIT_EXPECT_EQ (test,drm_fixp2int_ceil (get_lut_index (&srgb_eotf,0xffff )),0xff ); }static void vkms_color_test_lerp (struct kunit *test)
@@ -148,9 +160,32 @@ static void vkms_color_test_lerp(struct kunit *test)KUNIT_EXPECT_EQ (test,lerp_u16 (0x0 ,0x1 ,0x80000000 ),0x1 ); } +static void vkms_color_test_linear (struct kunit *test) +{ +for (int i =0 ; i <LUT_SIZE ; i++) { +int linear =apply_lut_to_channel_value (&linear_eotf, i *0x101 ,LUT_RED ); +KUNIT_EXPECT_EQ (test,DIV_ROUND_CLOSEST (linear,0x101 ), i); + } +} + +static void vkms_color_srgb_inv_srgb (struct kunit *test) +{ +u16 srgb, final; + +for (int i =0 ; i <LUT_SIZE ; i++) { + srgb =apply_lut_to_channel_value (&srgb_eotf, i *0x101 ,LUT_RED ); + final =apply_lut_to_channel_value (&srgb_inv_eotf, srgb,LUT_RED ); + +KUNIT_EXPECT_GE (test, final /0x101 , i-1 ); +KUNIT_EXPECT_LE (test, final /0x101 , i+1 ); + } +} +static struct kunit_case vkms_color_test_cases[] = {KUNIT_CASE (vkms_color_test_get_lut_index),KUNIT_CASE (vkms_color_test_lerp), +KUNIT_CASE (vkms_color_test_linear), +KUNIT_CASE (vkms_color_srgb_inv_srgb), {} };
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 19/42 drm/colorop: Introduce DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE
In reply to Harry WentlandWith the introduction of the pre-blending color pipeline we can no longer have color operations that don't have a clear position in the color pipeline. We deprecate all existing plane properties. For upstream drivers those are:
- COLOR_ENCODING
- COLOR_RANGE
Drivers are expected to ignore these properties when programming the HW.
Setting of the COLOR_PIPELINE plane property or drm_colorop properties is only allowed for userspace that sets this client cap.
v4:
- Don't block setting of COLOR_RANGE and COLOR_ENCODING when client cap is set
--- drivers/gpu/drm/drm_atomic_uapi.c | 13 ++++++++++++- drivers/gpu/drm/drm_ioctl.c | 7 +++++++ include/drm/drm_file.h | 7 +++++++ include/uapi/drm/drm.h | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_atomic_uapi.c +12 -1
@@ -570,6 +570,12 @@ static int drm_atomic_plane_set_property(struct drm_plane *plane, }else if (property == plane->color_range_property) { state->color_range = val; }else if (property == plane->color_pipeline_property) { +if (!file_priv->plane_color_pipeline) { +drm_dbg_atomic (dev, +"Setting COLOR_PIPELINE plane property not permitted unless DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE is set\n" ); +return -EINVAL ; + } +/* find DRM colorop object */ struct drm_colorop *colorop =NULL ; colorop =drm_colorop_find (dev, file_priv, val);
@@ -1179,6 +1185,12 @@ int drm_atomic_set_property(struct drm_atomic_state *state,break ; }case DRM_MODE_OBJECT_COLOROP : { +if (!file_priv->plane_color_pipeline) { +drm_dbg_atomic (prop->dev, +"[OBJECT:%d] is a colorop but DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE not set\n" , + obj->id); + ret = -EINVAL ; + }struct drm_colorop *colorop =obj_to_colorop (obj);struct drm_colorop_state *colorop_state;
@@ -1191,7 +1203,6 @@ int drm_atomic_set_property(struct drm_atomic_state *state, ret =drm_atomic_colorop_set_property (colorop, colorop_state, file_priv, prop, prop_value); -break ; }default :
drivers/gpu/drm/drm_ioctl.c +7 -0
@@ -373,6 +373,13 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)return -EINVAL ; file_priv->supports_virtualized_cursor_plane = req->value;break ; +case DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE : +if (!file_priv->atomic) +return -EINVAL ; +if (req->value >1 ) +return -EINVAL ; + file_priv->plane_color_pipeline = req->value; +break ;default :return -EINVAL ; }
include/drm/drm_file.h +7 -0
@@ -204,6 +204,13 @@ struct drm_file {*/ bool writeback_connectors; +/** +* @plane_color_pipeline: +* +* True if client understands plane color pipelines +*/ +bool plane_color_pipeline; +/** * @was_master: *
include/uapi/drm/drm.h +16 -0
@@ -875,6 +875,22 @@ struct drm_get_cap {*/ #define DRM_CLIENT_CAP_CURSOR_PLANE_HOTSPOT 6 +/** +* DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE +* +* If set to 1 +* - the DRM core will allow setting of plane the COLOR_PIPELINE +* property, as well as drm_colorop properties. +* - Drivers will ignore these properties +* - COLOR_ENCODING +* - COLOR_RANGE +* +* The client must enable &DRM_CLIENT_CAP_ATOMIC first. +* +* This capability is currently in development. +*/ +#define DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE 7 +/* DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */ struct drm_set_client_cap {__u64 capability;
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 20/42 drm/colorop: Add 3x4 CTM type
In reply to Harry WentlandThis 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.
v4:
- Create helper function for creating 3x4 CTM colorop
- Fix CTM indexes in comment (Pekka)
--- drivers/gpu/drm/drm_atomic.c | 14 ++++++++++- drivers/gpu/drm/drm_atomic_uapi.c | 29 ++++++++++++++++++++++ drivers/gpu/drm/drm_colorop.c | 40 +++++++++++++++++++++++++++++++ include/drm/drm_colorop.h | 19 +++++++++++++++ include/uapi/drm/drm_mode.h | 9 ++++++- 5 files changed, 109 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic.c +13 -1
@@ -793,7 +793,19 @@ static void drm_atomic_colorop_print_state(struct drm_printer *p,drm_printf (p,"colorop[%u]:\n" , colorop->base.id);drm_printf (p,"\ttype=%s\n" ,drm_get_colorop_type_name (colorop->type));drm_printf (p,"\tbypass=%u\n" , state->bypass); -drm_printf (p,"\tcurve_1d_type=%s\n" ,drm_get_colorop_curve_1d_type_name (state->curve_1d_type)); + +switch (colorop->type) { +case DRM_COLOROP_1D_CURVE : +drm_printf (p,"\tcurve_1d_type=%s\n" , +drm_get_colorop_curve_1d_type_name (state->curve_1d_type)); +break ; +case DRM_COLOROP_CTM_3X4 : +drm_printf (p,"\tdata blob id=%d\n" , state->data ? state->data->base.id :0 ); +break ; +default : +break ; + } +drm_printf (p,"\tnext=%d\n" , colorop->next ? colorop->next->base.id :0 ); }
drivers/gpu/drm/drm_atomic_uapi.c +29 -0
@@ -691,6 +691,30 @@ drm_atomic_plane_get_property(struct drm_plane *plane,return 0 ; } +static int drm_atomic_color_set_data_property (struct drm_colorop *colorop, +struct drm_colorop_state *state, +struct drm_property *property,uint64_t val) +{ +ssize_t elem_size =-1 ; +ssize_t size =-1 ; +bool replaced = false; + +switch (colorop->type) { +case DRM_COLOROP_CTM_3X4 : + size =sizeof (struct drm_color_ctm_3x4 ); +break ; +default : +/* should never get here */ +return -EINVAL ; + } + +return drm_property_replace_blob_from_id (colorop->dev, + &state->data, + val, + size, + elem_size, + &replaced); +} static int drm_atomic_colorop_set_property(struct drm_colorop *colorop, struct drm_colorop_state *state, struct drm_file *file_priv,
@@ -700,6 +724,9 @@ static int drm_atomic_colorop_set_property(struct drm_colorop *colorop, state->bypass = val; }else if (property == colorop->curve_1d_type_property) { state->curve_1d_type = val; + }else if (property == colorop->data_property) { +return drm_atomic_color_set_data_property (colorop, + state, property, val); }else { drm_dbg_atomic(colorop->dev, "[COLOROP:%d:%d] unknown property [PROP:%d:%s]]\n",
@@ -722,6 +749,8 @@ drm_atomic_colorop_get_property(struct drm_colorop *colorop, *val = state->bypass; }else if (property == colorop->curve_1d_type_property) { *val = state->curve_1d_type; + }else if (property == colorop->data_property) { + *val = (state->data) ? state->data->base.id :0 ; }else {return -EINVAL ; }
drivers/gpu/drm/drm_colorop.c +40 -0
@@ -34,6 +34,7 @@static const struct drm_prop_enum_list drm_colorop_type_enum_list[] = { {DRM_COLOROP_1D_CURVE ,"1D Curve" }, + {DRM_COLOROP_CTM_3X4 ,"3x4 Matrix" } };static const char *const colorop_curve_1d_type_names[] = {
@@ -93,6 +94,7 @@ int drm_colorop_init(struct drm_device *dev, struct drm_colorop *colorop, colorop->bypass_property, 1); +/* next */ prop =drm_property_create_object (dev,DRM_MODE_PROP_IMMUTABLE |DRM_MODE_PROP_ATOMIC ,"NEXT" ,DRM_MODE_OBJECT_COLOROP );if (!prop)
@@ -157,6 +159,43 @@ int drm_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *coloro }EXPORT_SYMBOL (drm_colorop_curve_1d_init); +static int drm_colorop_create_data_prop (struct drm_device *dev,struct drm_colorop *colorop) +{ +struct drm_property *prop; + +/* data */ + prop =drm_property_create (dev,DRM_MODE_PROP_ATOMIC |DRM_MODE_PROP_BLOB , +"DATA" ,0 ); +if (!prop) +return -ENOMEM ; + + colorop->data_property = prop; +drm_object_attach_property (&colorop->base, + colorop->data_property, +0 ); + +return 0 ; +} + +int drm_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane) +{ +int ret; + + ret =drm_colorop_init (dev, colorop, plane,DRM_COLOROP_CTM_3X4 ); +if (ret) +return ret; + + ret =drm_colorop_create_data_prop (dev, colorop); +if (ret) +return ret; + +drm_colorop_reset (colorop); + +return 0 ; +} +EXPORT_SYMBOL (drm_colorop_ctm_3x4_init); +static void __drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop,struct drm_colorop_state *state) {
@@ -258,6 +297,7 @@ EXPORT_SYMBOL(drm_colorop_reset);static const char *const colorop_type_name[] = { [DRM_COLOROP_1D_CURVE ] ="1D Curve" , + [DRM_COLOROP_CTM_3X4 ] ="3x4 Matrix" };/**
include/drm/drm_colorop.h +19 -0
@@ -60,6 +60,14 @@ struct drm_colorop_state {*/ enum drm_colorop_curve_1d_type curve_1d_type; +/** +* @data: +* +* Data blob for any TYPE that requires such a blob. The +* interpretation of the blob is TYPE-specific. +*/ +struct drm_property_blob *data; +/** @state: backpointer to global drm_atomic_state */ struct drm_atomic_state *state; };
@@ -167,6 +175,17 @@ struct drm_colorop {*/ struct drm_property *curve_1d_type_property; +/** +* @data: +* +* blob property for any TYPE that requires a blob of data, +* such as 1DLUT, CTM, 3DLUT, etc. +* +* The way this blob is interpreted depends on the TYPE of +* this +*/ +struct drm_property *data_property; +/** * @next_property *
include/uapi/drm/drm_mode.h +8 -1
@@ -851,6 +851,12 @@ struct drm_color_ctm_3x4 {/* * Conversion matrix with 3x4 dimensions in S31.32 sign-magnitude * (not two's complement!) format. +* +* out matrix in +* |R| |0 1 2 3 | | R | +* |G| = |4 5 6 7 | x | G | +* |B| |8 9 10 11| | B | +* |1.0| */ __u64 matrix[12 ]; };
@@ -867,7 +873,8 @@ struct drm_color_lut { };enum drm_colorop_type { -DRM_COLOROP_1D_CURVE +DRM_COLOROP_1D_CURVE , +DRM_COLOROP_CTM_3X4 , };/**
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 21/42 drm/vkms: Pull apply_colorop out of pre_blend_color_transform
In reply to Harry WentlandThe if/switch statement is bound to grow with more types and subtypes. Pull this out into its own funcion to make things more manageable and readable.
--- drivers/gpu/drm/vkms/vkms_composer.c | 48 ++++++++++++++++------------ 1 file changed, 28 insertions(+), 20 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +28 -20
@@ -164,6 +164,31 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff } } +static void apply_colorop (struct pixel_argb_u16 *pixel,struct drm_colorop *colorop) +{ +/* TODO is this right? */ +struct drm_colorop_state *colorop_state = colorop->state; + +if (colorop->type ==DRM_COLOROP_1D_CURVE ) { +switch (colorop_state->curve_1d_type) { +case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF : + pixel->r =apply_lut_to_channel_value (&srgb_inv_eotf, pixel->r,LUT_RED ); + pixel->g =apply_lut_to_channel_value (&srgb_inv_eotf, pixel->g,LUT_GREEN ); + pixel->b =apply_lut_to_channel_value (&srgb_inv_eotf, pixel->b,LUT_BLUE ); +break ; +case DRM_COLOROP_1D_CURVE_SRGB_EOTF : + pixel->r =apply_lut_to_channel_value (&srgb_eotf, pixel->r,LUT_RED ); + pixel->g =apply_lut_to_channel_value (&srgb_eotf, pixel->g,LUT_GREEN ); + pixel->b =apply_lut_to_channel_value (&srgb_eotf, pixel->b,LUT_BLUE ); +break ; +default : +DRM_DEBUG_DRIVER ("unkown colorop 1D curve type %d\n" , colorop_state->curve_1d_type); +break ; + } + } + +} +static void pre_blend_color_transform (const struct vkms_plane_state *plane_state,struct line_buffer *output_buffer) {struct drm_colorop *colorop = plane_state->base.base.color_pipeline;
@@ -180,26 +205,9 @@ static void pre_blend_color_transform(const struct vkms_plane_state *plane_stateif (!colorop_state)return ; -for (size_t x =0 ; x < output_buffer->n_pixels; x++) { -struct pixel_argb_u16 *pixel = &output_buffer->pixels[x]; - -if (colorop->type ==DRM_COLOROP_1D_CURVE && - colorop_state->bypass == false) { -switch (colorop_state->curve_1d_type) { -case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF : - pixel->r =apply_lut_to_channel_value (&srgb_inv_eotf, pixel->r,LUT_RED ); - pixel->g =apply_lut_to_channel_value (&srgb_inv_eotf, pixel->g,LUT_GREEN ); - pixel->b =apply_lut_to_channel_value (&srgb_inv_eotf, pixel->b,LUT_BLUE ); -break ; -case DRM_COLOROP_1D_CURVE_SRGB_EOTF : -default : - pixel->r =apply_lut_to_channel_value (&srgb_eotf, pixel->r,LUT_RED ); - pixel->g =apply_lut_to_channel_value (&srgb_eotf, pixel->g,LUT_GREEN ); - pixel->b =apply_lut_to_channel_value (&srgb_eotf, pixel->b,LUT_BLUE ); -break ; - } - } - } +for (size_t x =0 ; x < output_buffer->n_pixels; x++) +if (!colorop_state->bypass) +apply_colorop (&output_buffer->pixels[x], colorop); colorop = colorop->next; }
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 22/42 drm/vkms: Use s32 for internal color pipeline precision
In reply to Harry WentlandCertain operations require us to preserve values below 0.0 and above 1.0 (0x0 and 0xffff respectively in 16 bpc unorm). One such operation is a BT709 encoding operation followed by its decoding operation, or the reverse.
We'll use s32 values as intermediate in and outputs of our color operations, for the operations where it matters.
For now this won't apply to LUT operations. We might want to update those to work on s32 as well, but it's unclear how that should work for unorm LUT definitions. We'll revisit that once we add LUT + CTM tests.
In order to allow for this we'll also invert the nesting of our colorop processing loops. We now use the pixel iteration loop on the outside and the colorop iteration on the inside.
v4:
- Clarify that we're packing 16-bit UNORM into s32, not converting values to a different representation (Pekka)
v3:
- Use new colorop->next pointer
--- drivers/gpu/drm/vkms/vkms_composer.c | 57 +++++++++++++++++++++------- drivers/gpu/drm/vkms/vkms_drv.h | 4 ++ 2 files changed, 48 insertions(+), 13 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +44 -13
@@ -164,7 +164,7 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff } } -static void apply_colorop (struct pixel_argb_u16 *pixel,struct drm_colorop *colorop) +static void apply_colorop (struct pixel_argb_s32 *pixel,struct drm_colorop *colorop) {/* TODO is this right? */ struct drm_colorop_state *colorop_state = colorop->state;
@@ -191,25 +191,56 @@ static void apply_colorop(struct pixel_argb_u16 *pixel, struct drm_colorop *colostatic void pre_blend_color_transform (const struct vkms_plane_state *plane_state,struct line_buffer *output_buffer) { -struct drm_colorop *colorop = plane_state->base.base.color_pipeline; +struct drm_colorop *colorop; +struct pixel_argb_s32 pixel; -while (colorop) { -struct drm_colorop_state *colorop_state; +for (size_t x =0 ; x < output_buffer->n_pixels; x++) { -if (!colorop) -return ; +/* +* Some operations, such as applying a BT709 encoding matrix, +* followed by a decoding matrix, require that we preserve +* values above 1.0 and below 0.0 until the end of the pipeline. +* +* Pack the 16-bit UNORM values into s32 to give us head-room to +* avoid clipping until we're at the end of the pipeline. Clip +* intentionally at the end of the pipeline before packing +* UNORM values back into u16. +*/ + pixel.a = output_buffer->pixels[x].a; + pixel.r = output_buffer->pixels[x].r; + pixel.g = output_buffer->pixels[x].g; + pixel.b = output_buffer->pixels[x].b; -/* TODO this is probably wrong */ - colorop_state = colorop->state; + colorop = plane_state->base.base.color_pipeline; +while (colorop) { +struct drm_colorop_state *colorop_state; -if (!colorop_state) -return ; +if (!colorop) +return ; + +/* TODO this is probably wrong */ + colorop_state = colorop->state; + +if (!colorop_state) +return ; -for (size_t x =0 ; x < output_buffer->n_pixels; x++)if (!colorop_state->bypass) -apply_colorop (&output_buffer->pixels[x], colorop); +apply_colorop (&pixel, colorop); - colorop = colorop->next; + colorop = colorop->next; + } + +/* clamp pixel */ + pixel.a =max (min (pixel.a,0xffff ),0x0 ); + pixel.r =max (min (pixel.r,0xffff ),0x0 ); + pixel.g =max (min (pixel.g,0xffff ),0x0 ); + pixel.b =max (min (pixel.b,0xffff ),0x0 ); + +/* put back to output_buffer */ + output_buffer->pixels[x].a = pixel.a; + output_buffer->pixels[x].r = pixel.r; + output_buffer->pixels[x].g = pixel.g; + output_buffer->pixels[x].b = pixel.b; } }
drivers/gpu/drm/vkms/vkms_drv.h +4 -0
@@ -36,6 +36,10 @@ struct vkms_frame_info {unsigned int cpp; }; +struct pixel_argb_s32 { +s32 a, r, g, b; +}; +struct pixel_argb_u16 {u16 a, r, g, b; };
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 22/42] drm/vkms: Use s32 for internal color pipeline precision
Quoted 8 lines · On Mon, 26 Feb 2024 16:10:36 -0500 Harry Wentland <[email protected]>…
Certain operations require us to preserve values below 0.0 and above 1.0 (
0x0and0xffffrespectively in 16 bpc unorm). One such operation is a BT709 encoding operation followed by its decoding operation, or the reverse.We'll use s32 values as intermediate in and outputs of our color operations, for the operations where it matters.
Quoted 8 lines
For now this won't apply to LUT operations. We might want to update those to work on s32 as well, but it's unclear how that should work for unorm LUT definitions. We'll revisit that once we add LUT + CTM tests.
In order to allow for this we'll also invert the nesting of our colorop processing loops. We now use the pixel iteration loop on the outside and the colorop iteration on the inside.
I always go through the same thought process:
- putting the pixel iteration loop outermost is going to be horrible for performance
- maybe should turn the temporary line buffer to argb_s32 for all of VKMS
- that's going to be a lot of memory traffic... maybe your way is not horrible for performance
- maybe processing pixel by pixel is good, if you can prepare the operation in advance, so you don't need to analyze colorops again and again on each pixel
- eh, maybe it's not a gain after all, needs benchmarking
My comment on patch 17 was like the step 0 of this train of thought. I just always get the same comments in my mind when seeing the same code again.
Thanks,
pq
Quoted 111 lines
v4:
- Clarify that we're packing 16-bit UNORM into s32, not converting values to a different representation (Pekka)v3:
- Use newcolorop->nextpointerSigned-off-by Harry Wentland <[email protected]>--- drivers/gpu/drm/vkms/vkms_composer.c | 57 +++++++++++++++++++++------- drivers/gpu/drm/vkms/vkms_drv.h | 4 ++ 2 files changed, 48 insertions(+), 13 deletions(-)drivers/gpu/drm/vkms/vkms_composer.c +44
-13@@ -164,7 +164,7 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff } } -static void apply_colorop (struct pixel_argb_u16 *pixel,struct drm_colorop *colorop) +static void apply_colorop (struct pixel_argb_s32 *pixel,struct drm_colorop *colorop) {/* TODO is this right? */ struct drm_colorop_state *colorop_state = colorop->state;@@ -191,25 +191,56 @@ static void apply_colorop(struct pixel_argb_u16 *pixel, struct drm_colorop *colostatic void pre_blend_color_transform (const struct vkms_plane_state *plane_state,struct line_buffer *output_buffer) { -struct drm_colorop *colorop = plane_state->base.base.color_pipeline; +struct drm_colorop *colorop; +struct pixel_argb_s32 pixel; -while (colorop) { -struct drm_colorop_state *colorop_state; +for (size_t x =0 ; x < output_buffer->n_pixels; x++) { -if (!colorop) -return ; +/* +* Some operations, such as applying a BT709 encoding matrix, +* followed by a decoding matrix, require that we preserve +* values above 1.0 and below 0.0 until the end of the pipeline. +* +* Pack the 16-bit UNORM values into s32 to give us head-room to +* avoid clipping until we're at the end of the pipeline. Clip +* intentionally at the end of the pipeline before packing +* UNORM values back into u16. +*/ + pixel.a = output_buffer->pixels[x].a; + pixel.r = output_buffer->pixels[x].r; + pixel.g = output_buffer->pixels[x].g; + pixel.b = output_buffer->pixels[x].b; -/* TODO this is probably wrong */ - colorop_state = colorop->state; + colorop = plane_state->base.base.color_pipeline; +while (colorop) { +struct drm_colorop_state *colorop_state; -if (!colorop_state) -return ; +if (!colorop) +return ; + +/* TODO this is probably wrong */ + colorop_state = colorop->state; + +if (!colorop_state) +return ; -for (size_t x =0 ; x < output_buffer->n_pixels; x++)if (!colorop_state->bypass) -apply_colorop (&output_buffer->pixels[x], colorop); +apply_colorop (&pixel, colorop); - colorop = colorop->next; + colorop = colorop->next; + } + +/* clamp pixel */ + pixel.a =max (min (pixel.a,0xffff ),0x0 ); + pixel.r =max (min (pixel.r,0xffff ),0x0 ); + pixel.g =max (min (pixel.g,0xffff ),0x0 ); + pixel.b =max (min (pixel.b,0xffff ),0x0 ); + +/* put back to output_buffer */ + output_buffer->pixels[x].a = pixel.a; + output_buffer->pixels[x].r = pixel.r; + output_buffer->pixels[x].g = pixel.g; + output_buffer->pixels[x].b = pixel.b; } }drivers/gpu/drm/vkms/vkms_drv.h +4
-0@@ -36,6 +36,10 @@ struct vkms_frame_info {unsigned int cpp; }; +struct pixel_argb_s32 { +s32 a, r, g, b; +}; +struct pixel_argb_u16 {u16 a, r, g, b; };
Harry Wentland
maintainerRFC PATCH v4 23/42 drm/vkms: add 3x4 matrix in color pipeline
In reply to Harry WentlandWe add two 3x4 matrices into the VKMS color pipeline. The reason we're adding matrices is so that we can test that application of a matrix and its inverse yields an output equal to the input image.
One complication with the matrix implementation has to do with the fact that the matrix entries are in signed-magnitude fixed point, whereas the drm_fixed.h implementation uses 2s-complement. The latter one is the one that we want for easy addition and subtraction, so we convert all entries to 2s-complement.
--- drivers/gpu/drm/vkms/vkms_colorop.c | 32 +++++++++++++++++++++++++++- drivers/gpu/drm/vkms/vkms_composer.c | 27 +++++++++++++++++++++++ include/drm/drm_colorop.h | 2 ++ 3 files changed, 60 insertions(+), 1 deletion(-)
drivers/gpu/drm/vkms/vkms_colorop.c +31 -1
@@ -35,7 +35,37 @@ const int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_pro prev_op = op; -/* 2nd op: 1d curve */ +/* 2nd op: 3x4 matrix */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_ctm_3x4_init (dev, op, plane); +if (ret) +return ret; + +drm_colorop_set_next_property (prev_op, op); + + prev_op = op; + +/* 3rd op: 3x4 matrix */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_ctm_3x4_init (dev, op, plane); +if (ret) +return ret; + +drm_colorop_set_next_property (prev_op, op); + + prev_op = op; + +/* 4th op: 1d curve */ op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL );if (!op) {DRM_ERROR ("KMS: Failed to allocate colorop\n" );
drivers/gpu/drm/vkms/vkms_composer.c +27 -0
@@ -164,6 +164,30 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff } } +static void apply_3x4_matrix (struct pixel_argb_s32 *pixel,const struct drm_color_ctm_3x4 *matrix) +{ +s64 rf, gf, bf; + + rf =drm_fixp_mul (drm_sm2fixp (matrix->matrix[0 ]),drm_int2fixp (pixel->r)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[1 ]),drm_int2fixp (pixel->g)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[2 ]),drm_int2fixp (pixel->b)) + +drm_sm2fixp (matrix->matrix[3 ]); + + gf =drm_fixp_mul (drm_sm2fixp (matrix->matrix[4 ]),drm_int2fixp (pixel->r)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[5 ]),drm_int2fixp (pixel->g)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[6 ]),drm_int2fixp (pixel->b)) + +drm_sm2fixp (matrix->matrix[7 ]); + + bf =drm_fixp_mul (drm_sm2fixp (matrix->matrix[8 ]),drm_int2fixp (pixel->r)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[9 ]),drm_int2fixp (pixel->g)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[10 ]),drm_int2fixp (pixel->b)) + +drm_sm2fixp (matrix->matrix[11 ]); + + pixel->r =drm_fixp2int (rf); + pixel->g =drm_fixp2int (gf); + pixel->b =drm_fixp2int (bf); +} +static void apply_colorop (struct pixel_argb_s32 *pixel,struct drm_colorop *colorop) {/* TODO is this right? */
@@ -185,6 +209,9 @@ static void apply_colorop(struct pixel_argb_s32 *pixel, struct drm_colorop *coloDRM_DEBUG_DRIVER ("unkown colorop 1D curve type %d\n" , colorop_state->curve_1d_type);break ; } + }else if (colorop->type ==DRM_COLOROP_CTM_3X4 ) { +if (colorop_state->data) +apply_3x4_matrix (pixel, (struct drm_color_ctm_3x4 *) colorop_state->data->data); } }
include/drm/drm_colorop.h +2 -0
@@ -224,6 +224,8 @@ int drm_colorop_init(struct drm_device *dev, struct drm_colorop *colorop,int drm_colorop_curve_1d_init (struct drm_device *dev,struct drm_colorop *colorop,struct drm_plane *plane,u64 supported_tfs); +int drm_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane);struct drm_colorop_state *drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop);
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 23/42] drm/vkms: add 3x4 matrix in color pipeline
Quoted 4 lines · On Mon, 26 Feb 2024 16:10:37 -0500 Harry Wentland <[email protected]>…
We add two 3x4 matrices into the VKMS color pipeline. The reason we're adding matrices is so that we can test that application of a matrix and its inverse yields an output equal to the input image.
You will test also cases where the matrix configuration will not produce output equal to input, right?
Otherwise one can accidentally pass the matrix test by ignoring all matrices.
Quoted 62 lines
One complication with the matrix implementation has to do with the fact that the matrix entries are in signed-magnitude fixed point, whereas the
drm_fixed.himplementation uses 2s-complement. The latter one is the one that we want for easy addition and subtraction, so we convert all entries to 2s-complement.Signed-off-by Harry Wentland <[email protected]>--- drivers/gpu/drm/vkms/vkms_colorop.c | 32 +++++++++++++++++++++++++++- drivers/gpu/drm/vkms/vkms_composer.c | 27 +++++++++++++++++++++++ include/drm/drm_colorop.h | 2 ++ 3 files changed, 60 insertions(+), 1 deletion(-)drivers/gpu/drm/vkms/vkms_colorop.c +31
-1@@ -35,7 +35,37 @@ const int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_pro prev_op = op; -/* 2nd op: 1d curve */ +/* 2nd op: 3x4 matrix */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_ctm_3x4_init (dev, op, plane); +if (ret) +return ret; + +drm_colorop_set_next_property (prev_op, op); + + prev_op = op; + +/* 3rd op: 3x4 matrix */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_ctm_3x4_init (dev, op, plane); +if (ret) +return ret; + +drm_colorop_set_next_property (prev_op, op); + + prev_op = op; + +/* 4th op: 1d curve */ op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL );if (!op) {DRM_ERROR ("KMS: Failed to allocate colorop\n" );drivers/gpu/drm/vkms/vkms_composer.c +0
-0@@ -164,6 +164,30 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff }
drivers/gpu/drm/vkms/vkms_composer.c static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff · line 174
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_composer.c +8
-0} +static void apply_3x4_matrix (struct pixel_argb_s32 *pixel,const struct drm_color_ctm_3x4 *matrix) +{ +s64 rf, gf, bf; + + rf =drm_fixp_mul (drm_sm2fixp (matrix->matrix[0 ]),drm_int2fixp (pixel->r)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[1 ]),drm_int2fixp (pixel->g)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[2 ]),drm_int2fixp (pixel->b)) + +drm_sm2fixp (matrix->matrix[3 ]);
It would be nice if the driver had its private data for the matrix colorop state, so it could convert the matrix only once when userspace sets it.
Thanks,
pq
Quoted 42 lines
drivers/gpu/drm/vkms/vkms_composer.c +19
-0+ + gf =drm_fixp_mul (drm_sm2fixp (matrix->matrix[4 ]),drm_int2fixp (pixel->r)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[5 ]),drm_int2fixp (pixel->g)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[6 ]),drm_int2fixp (pixel->b)) + +drm_sm2fixp (matrix->matrix[7 ]); + + bf =drm_fixp_mul (drm_sm2fixp (matrix->matrix[8 ]),drm_int2fixp (pixel->r)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[9 ]),drm_int2fixp (pixel->g)) + +drm_fixp_mul (drm_sm2fixp (matrix->matrix[10 ]),drm_int2fixp (pixel->b)) + +drm_sm2fixp (matrix->matrix[11 ]); + + pixel->r =drm_fixp2int (rf); + pixel->g =drm_fixp2int (gf); + pixel->b =drm_fixp2int (bf); +} +static void apply_colorop (struct pixel_argb_s32 *pixel,struct drm_colorop *colorop) {/* TODO is this right? */ @@ -185,6 +209,9 @@ static void apply_colorop(struct pixel_argb_s32 *pixel, struct drm_colorop *coloDRM_DEBUG_DRIVER ("unkown colorop 1D curve type %d\n" , colorop_state->curve_1d_type);break ; } + }else if (colorop->type ==DRM_COLOROP_CTM_3X4 ) { +if (colorop_state->data) +apply_3x4_matrix (pixel, (struct drm_color_ctm_3x4 *) colorop_state->data->data); } }include/drm/drm_colorop.h +2
-0@@ -224,6 +224,8 @@ int drm_colorop_init(struct drm_device *dev, struct drm_colorop *colorop,int drm_colorop_curve_1d_init (struct drm_device *dev,struct drm_colorop *colorop,struct drm_plane *plane,u64 supported_tfs); +int drm_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane);struct drm_colorop_state *drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop);
Harry Wentland
maintainerRFC PATCH v4 24/42 drm/tests: Add a few tests around drm_fixed.h
In reply to Harry WentlandWhile working on the CTM implementation of VKMS I had to ascertain myself of a few assumptions. One of those is whether drm_fixed.h treats its numbers using signed-magnitude or twos-complement. It is twos-complement.
In order to make someone else's day easier I am adding the drm_test_int2fixp test that validates the above assumption.
I am also adding a test for the new sm2fixp function that converts from a signed-magnitude fixed point to the twos-complement fixed point.
--- drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_fixp_test.c | 69 +++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/tests/drm_fixp_test.c
drivers/gpu/drm/tests/Makefile +2 -1
@@ -19,6 +19,7 @@ obj-$(CONFIG_DRM_KUNIT_TEST) += \ drm_modes_test.o \ drm_plane_helper_test.o \ drm_probe_helper_test.o \ - drm_rect_test.o + drm_rect_test.o \ + drm_fixp_test.o CFLAGS_drm_mm_test.o := $(DISABLE_STRUCTLEAK_PLUGIN)
drivers/gpu/drm/tests/drm_fixp_test.c new file +69 -0
70 lines not on this page · raw message
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 24/42] drm/tests: Add a few tests around drm_fixed.h
Quoted 42 lines · On Mon, 26 Feb 2024 16:10:38 -0500 Harry Wentland <[email protected]>…
While working on the CTM implementation of VKMS I had to ascertain myself of a few assumptions. One of those is whether
drm_fixed.htreats its numbers using signed-magnitude or twos-complement. It is twos-complement.In order to make someone else's day easier I am adding the
drm_test_int2fixptest that validates the above assumption.I am also adding a test for the new sm2fixp function that converts from a signed-magnitude fixed point to the twos-complement fixed point.
Signed-off-by Harry Wentland <[email protected]>--- drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_fixp_test.c | 69 +++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/tests/drm_fixp_test.cdrivers/gpu/drm/tests/Makefile +2
-1@@ -19,6 +19,7 @@ obj-$(CONFIG_DRM_KUNIT_TEST) += \ drm_modes_test.o \ drm_plane_helper_test.o \ drm_probe_helper_test.o \ - drm_rect_test.o + drm_rect_test.o \ + drm_fixp_test.o CFLAGS_drm_mm_test.o := $(DISABLE_STRUCTLEAK_PLUGIN)drivers/gpu/drm/tests/drm_fixp_test.c new file +4
-0@@ -0,0 +1,69 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright 2022 Advanced Micro Devices, Inc. +*/
drivers/gpu/drm/tests/drm_fixp_test.c line 14
Quoted 10 lines
drivers/gpu/drm/tests/drm_fixp_test.c new file +10
-0+ +#include <kunit/test.h> +#include <drm/drm_fixed.h> + +static void drm_test_sm2fixp (struct kunit *test) +{ +KUNIT_EXPECT_EQ (test,0x7fffffffffffffffll , ((1LL <<63 ) -1 )); + +/* 1 */ +KUNIT_EXPECT_EQ (test,drm_int2fixp (1 ),drm_sm2fixp (1ull <<DRM_FIXED_POINT ));
This sounds like confusing two different APIs.
DRM_FIXED_POINT is for the two's complement representation, and sm is not.
It does not look like there is a #define for the signed-magnitude UAPI construct, otherwise drm_color_ctm_s31_32_to_qm_n() would be using it.
It's just an accident that DRM_FIXED_POINT has the right value for sm.
Hm, drm_color_ctm_s31_32_to_qm_n() produces two's complement. Why not use that for implementing drm_sm2fixp()?
Thanks,
pq
Quoted 56 lines
drivers/gpu/drm/tests/drm_fixp_test.c new file +55
-0+ +/* -1 */ +KUNIT_EXPECT_EQ (test,drm_int2fixp (-1 ),drm_sm2fixp ((1ull <<63 ) | (1ull <<DRM_FIXED_POINT ))); + +/* 0.5 */ +KUNIT_EXPECT_EQ (test,drm_fixp_from_fraction (1 ,2 ),drm_sm2fixp (1ull << (DRM_FIXED_POINT -1 ))); + +/* -0.5 */ +KUNIT_EXPECT_EQ (test,drm_fixp_from_fraction (-1 ,2 ),drm_sm2fixp ((1ull <<63 ) | (1ull << (DRM_FIXED_POINT -1 )))); + +} + +static void drm_test_int2fixp (struct kunit *test) +{ +/* 1 */ +KUNIT_EXPECT_EQ (test,1ll <<32 ,drm_int2fixp (1 )); + +/* -1 */ +KUNIT_EXPECT_EQ (test, -(1ll <<32 ),drm_int2fixp (-1 )); + +/* 1 + (-1) = 0 */ +KUNIT_EXPECT_EQ (test,0 ,drm_int2fixp (1 ) +drm_int2fixp (-1 )); + +/* 1 / 2 */ +KUNIT_EXPECT_EQ (test,1ll <<31 ,drm_fixp_from_fraction (1 ,2 )); + +/* -0.5 */ +KUNIT_EXPECT_EQ (test, -(1ll <<31 ),drm_fixp_from_fraction (-1 ,2 )); + +/* (1 / 2) + (-1) = 0.5 */ +KUNIT_EXPECT_EQ (test,1ll <<31 ,drm_fixp_from_fraction (-1 ,2 ) +drm_int2fixp (1 )); + +/* (1 / 2) - 1) = 0.5 */ +KUNIT_EXPECT_EQ (test, -(1ll <<31 ),drm_fixp_from_fraction (1 ,2 ) +drm_int2fixp (-1 )); + +/* (1 / 2) - 1) = 0.5 */ +KUNIT_EXPECT_EQ (test, -(1ll <<31 ),drm_fixp_from_fraction (1 ,2 ) -drm_int2fixp (1 )); + +} + +static struct kunit_case drm_fixp_tests[] = { +KUNIT_CASE (drm_test_int2fixp), +KUNIT_CASE (drm_test_sm2fixp), + { } +}; + +static struct kunit_suite drm_rect_test_suite = { + .name ="drm_fixp" , + .test_cases = drm_fixp_tests, +}; + +kunit_test_suite (drm_rect_test_suite); + +MODULE_AUTHOR ("AMD" ); +MODULE_LICENSE ("GPL and additional rights" );
Harry Wentland
maintainerRFC PATCH v4 25/42 drm/vkms: Add tests for CTM handling
In reply to Harry WentlandA whole slew of tests for CTM handling that greatly helped in debugging the CTM code. The extent of tests might seem a bit silly but they're fast and might someday help save someone else's day when debugging this.
v4:
- Comment on origin of bt709_enc matrix (Pekka)
- Use full opaque alpha (Pekka)
- Add additional check for Y < 0xffff (Pekka)
- Remove unused code (Pekka)
- Rename red, green, blue to Y, U, V where applicable
--- drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 251 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_composer.c | 2 +- 2 files changed, 252 insertions(+), 1 deletion(-)
drivers/gpu/drm/vkms/tests/vkms_color_tests.c +251 -0
@@ -3,6 +3,7 @@#include <kunit/test.h> #include <drm/drm_fixed.h> +#include <drm/drm_mode.h> #define TEST_LUT_SIZE 16
@@ -181,11 +182,261 @@ static void vkms_color_srgb_inv_srgb(struct kunit *test) } } +#define FIXPT_HALF (DRM_FIXED_ONE >> 1) +#define FIXPT_QUARTER (DRM_FIXED_ONE >> 2) + +const struct drm_color_ctm_3x4 test_matrix_3x4_50_desat = { { +FIXPT_HALF ,FIXPT_QUARTER ,FIXPT_QUARTER ,0 , +FIXPT_QUARTER ,FIXPT_HALF ,FIXPT_QUARTER ,0 , +FIXPT_QUARTER ,FIXPT_QUARTER ,FIXPT_HALF ,0 +} }; + +static void vkms_color_ctm_3x4_50_desat (struct kunit *test) +{ +struct pixel_argb_s32 ref, out; + +/* full white */ + ref.a =0xffff ; + ref.r =0xffff ; + ref.g =0xffff ; + ref.b =0xffff ; + +memcpy (&out, &ref,sizeof (out)); +apply_3x4_matrix (&out, &test_matrix_3x4_50_desat); + +KUNIT_EXPECT_MEMEQ (test, &ref, &out,sizeof (out)); + +/* full black */ + ref.a =0xffff ; + ref.r =0x0 ; + ref.g =0x0 ; + ref.b =0x0 ; + +memcpy (&out, &ref,sizeof (out)); +apply_3x4_matrix (&out, &test_matrix_3x4_50_desat); + +KUNIT_EXPECT_MEMEQ (test, &ref, &out,sizeof (out)); + +/* 50% grey */ + ref.a =0xffff ; + ref.r =0x8000 ; + ref.g =0x8000 ; + ref.b =0x8000 ; + +memcpy (&out, &ref,sizeof (out)); +apply_3x4_matrix (&out, &test_matrix_3x4_50_desat); + +KUNIT_EXPECT_MEMEQ (test, &ref, &out,sizeof (out)); + +/* full red to 50% desat */ + ref.a =0xffff ; + ref.r =0x7fff ; + ref.g =0x3fff ; + ref.b =0x3fff ; + + out.a =0xffff ; + out.r =0xffff ; + out.g =0x0 ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_50_desat); + +KUNIT_EXPECT_MEMEQ (test, &ref, &out,sizeof (out)); +} + +/* +* BT.709 encoding matrix +* +* Values printed from within IGT when converting +* igt_matrix_3x4_bt709_enc to the fixed-point format expected +* by DRM/KMS. +*/ +const struct drm_color_ctm_3x4 test_matrix_3x4_bt709_enc = { { +0x00000000366cf400ull ,0x00000000b7175900ull ,0x0000000127bb300ull ,0 , +0x800000001993b3a0ull ,0x800000005609fe80ull ,0x000000006f9db200ull ,0 , +0x000000009d70a400ull ,0x800000008f011100ull ,0x800000000e6f9330ull ,0 +} }; + +static void vkms_color_ctm_3x4_bt709 (struct kunit *test) +{ +struct pixel_argb_s32 out; + +/* full white to bt709 */ + out.a =0xffff ; + out.r =0xffff ; + out.g =0xffff ; + out.b =0xffff ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 255 */ +KUNIT_EXPECT_GT (test, out.r,0xfe00 ); +KUNIT_EXPECT_LT (test, out.r,0x10000 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x0100 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x0100 ); + +/* full black to bt709 */ + out.a =0xffff ; + out.r =0x0 ; + out.g =0x0 ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 0 */ +KUNIT_EXPECT_LT (test, out.r,0x100 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x0100 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x0100 ); + +/* gray to bt709 */ + out.a =0xffff ; + out.r =0x7fff ; + out.g =0x7fff ; + out.b =0x7fff ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 127 */ +KUNIT_EXPECT_GT (test, out.r,0x7e00 ); +KUNIT_EXPECT_LT (test, out.r,0x8000 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x0100 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x0100 ); + +/* == red 255 - bt709 enc == */ + out.a =0xffff ; + out.r =0xffff ; + out.g =0x0 ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 54 */ +KUNIT_EXPECT_GT (test, out.r,0x3500 ); +KUNIT_EXPECT_LT (test, out.r,0x3700 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x0100 ); + +/* V 157 */ +KUNIT_EXPECT_GT (test, out.b,0x9C00 ); +KUNIT_EXPECT_LT (test, out.b,0x9E00 ); + + +/* == green 255 - bt709 enc == */ + out.a =0xffff ; + out.r =0x0 ; + out.g =0xffff ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 182 */ +KUNIT_EXPECT_GT (test, out.r,0xB500 ); +KUNIT_EXPECT_LT (test, out.r,0xB780 );/* laxed by half*/ + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x0100 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x0100 ); + +/* == blue 255 - bt709 enc == */ + out.a =0xffff ; + out.r =0x0 ; + out.g =0x0 ; + out.b =0xffff ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 18 */ +KUNIT_EXPECT_GT (test, out.r,0x1100 ); +KUNIT_EXPECT_LT (test, out.r,0x1300 ); + +/* U 111 */ +KUNIT_EXPECT_GT (test, out.g,0x6E00 ); +KUNIT_EXPECT_LT (test, out.g,0x7000 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x0100 ); + +/* == red 140 - bt709 enc == */ + out.a =0xffff ; + out.r =0x8c8c ; + out.g =0x0 ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 30 */ +KUNIT_EXPECT_GT (test, out.r,0x1D00 ); +KUNIT_EXPECT_LT (test, out.r,0x1F00 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x100 ); + +/* V 87 */ +KUNIT_EXPECT_GT (test, out.b,0x5600 ); +KUNIT_EXPECT_LT (test, out.b,0x5800 ); + +/* == green 140 - bt709 enc == */ + out.a =0xffff ; + out.r =0x0 ; + out.g =0x8c8c ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 30 */ +KUNIT_EXPECT_GT (test, out.r,0x6400 ); +KUNIT_EXPECT_LT (test, out.r,0x6600 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x100 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x100 ); + + +/* == blue 140 - bt709 enc == */ + out.a =0xffff ; + out.r =0x0 ; + out.g =0x0 ; + out.b =0x8c8c ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 30 */ +KUNIT_EXPECT_GT (test, out.r,0x900 ); +KUNIT_EXPECT_LT (test, out.r,0xB00 ); + +/* U 61 */ +KUNIT_EXPECT_GT (test, out.g,0x3C00 ); +KUNIT_EXPECT_LT (test, out.g,0x3E00 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x100 ); + +} +static struct kunit_case vkms_color_test_cases[] = {KUNIT_CASE (vkms_color_test_get_lut_index),KUNIT_CASE (vkms_color_test_lerp),KUNIT_CASE (vkms_color_test_linear),KUNIT_CASE (vkms_color_srgb_inv_srgb), +KUNIT_CASE (vkms_color_ctm_3x4_50_desat), +KUNIT_CASE (vkms_color_ctm_3x4_bt709), {} };
drivers/gpu/drm/vkms/vkms_composer.c +1 -1
@@ -164,7 +164,7 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff } } -static void apply_3x4_matrix (struct pixel_argb_s32 *pixel,const struct drm_color_ctm_3x4 *matrix) +void apply_3x4_matrix (struct pixel_argb_s32 *pixel,const struct drm_color_ctm_3x4 *matrix) {s64 rf, gf, bf;
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 25/42] drm/vkms: Add tests for CTM handling
Quoted 31 lines · On Mon, 26 Feb 2024 16:10:39 -0500 Harry Wentland <[email protected]>…
A whole slew of tests for CTM handling that greatly helped in debugging the CTM code. The extent of tests might seem a bit silly but they're fast and might someday help save someone else's day when debugging this.
v4:
- Comment on origin ofbt709_encmatrix (Pekka)
- Use full opaque alpha (Pekka)
- Add additional check for Y <0xffff(Pekka)
- Remove unused code (Pekka)
- Rename red, green, blue to Y, U, V where applicableSigned-off-by Harry Wentland <[email protected]>--- drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 251 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_composer.c | 2 +- 2 files changed, 252 insertions(+), 1 deletion(-)drivers/gpu/drm/vkms/tests/vkms_color_tests.c +1
-0@@ -3,6 +3,7 @@#include <kunit/test.h> #include <drm/drm_fixed.h> +#include <drm/drm_mode.h> #define TEST_LUT_SIZE 16
drivers/gpu/drm/vkms/tests/vkms_color_tests.c static void vkms_color_srgb_inv_srgb(struct kunit *test) · line 191
Quoted 10 lines
drivers/gpu/drm/vkms/tests/vkms_color_tests.c +7
-0@@ -181,11 +182,261 @@ static void vkms_color_srgb_inv_srgb(struct kunit *test) } } +#define FIXPT_HALF (DRM_FIXED_ONE >> 1) +#define FIXPT_QUARTER (DRM_FIXED_ONE >> 2) + +const struct drm_color_ctm_3x4 test_matrix_3x4_50_desat = { { +FIXPT_HALF ,FIXPT_QUARTER ,FIXPT_QUARTER ,0 , +FIXPT_QUARTER ,FIXPT_HALF ,FIXPT_QUARTER ,0 , +FIXPT_QUARTER ,FIXPT_QUARTER ,FIXPT_HALF ,0
These are supposed to be sign-magnitude, not fixed-point, to my understanding. It just happens that these specific values have the same bit pattern in both representations.
Quoted 51 lines
drivers/gpu/drm/vkms/tests/vkms_color_tests.c +51
-0+} }; + +static void vkms_color_ctm_3x4_50_desat (struct kunit *test) +{ +struct pixel_argb_s32 ref, out; + +/* full white */ + ref.a =0xffff ; + ref.r =0xffff ; + ref.g =0xffff ; + ref.b =0xffff ; + +memcpy (&out, &ref,sizeof (out)); +apply_3x4_matrix (&out, &test_matrix_3x4_50_desat); + +KUNIT_EXPECT_MEMEQ (test, &ref, &out,sizeof (out)); + +/* full black */ + ref.a =0xffff ; + ref.r =0x0 ; + ref.g =0x0 ; + ref.b =0x0 ; + +memcpy (&out, &ref,sizeof (out)); +apply_3x4_matrix (&out, &test_matrix_3x4_50_desat); + +KUNIT_EXPECT_MEMEQ (test, &ref, &out,sizeof (out)); + +/* 50% grey */ + ref.a =0xffff ; + ref.r =0x8000 ; + ref.g =0x8000 ; + ref.b =0x8000 ; + +memcpy (&out, &ref,sizeof (out)); +apply_3x4_matrix (&out, &test_matrix_3x4_50_desat); + +KUNIT_EXPECT_MEMEQ (test, &ref, &out,sizeof (out)); + +/* full red to 50% desat */ + ref.a =0xffff ; + ref.r =0x7fff ; + ref.g =0x3fff ; + ref.b =0x3fff ; + + out.a =0xffff ; + out.r =0xffff ; + out.g =0x0 ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_50_desat);
drivers/gpu/drm/vkms/tests/vkms_color_tests.c static void vkms_color_srgb_inv_srgb(struct kunit *test) · line 252
Quoted 10 lines
drivers/gpu/drm/vkms/tests/vkms_color_tests.c +10
-0+ +KUNIT_EXPECT_MEMEQ (test, &ref, &out,sizeof (out)); +} + +/* +* BT.709 encoding matrix +* +* Values printed from within IGT when converting +* igt_matrix_3x4_bt709_enc to the fixed-point format expected +* by DRM/KMS.
Shouldn't that be sign-magnitude, not fixed point?
I was hoping to get a reference to a spec like BT.709 and a formula for getting the blow out of it. IGT can change over time, and I don't know where IGT for that matrix from.
But ok, this is a test with an arbitrary matrix, not necessarily the BT.709 matrix specifically.
Btw. which BT.709 matrix is this? YUV->RGB, RGB->XYZ, or the inverse of one of those? Limited or full quantization range?
Judging by the tests, I guess RGB->YUV full range.
Quoted 15 lines
drivers/gpu/drm/vkms/tests/vkms_color_tests.c +15
-0+*/ +const struct drm_color_ctm_3x4 test_matrix_3x4_bt709_enc = { { +0x00000000366cf400ull ,0x00000000b7175900ull ,0x0000000127bb300ull ,0 , +0x800000001993b3a0ull ,0x800000005609fe80ull ,0x000000006f9db200ull ,0 , +0x000000009d70a400ull ,0x800000008f011100ull ,0x800000000e6f9330ull ,0 +} }; + +static void vkms_color_ctm_3x4_bt709 (struct kunit *test) +{ +struct pixel_argb_s32 out; + +/* full white to bt709 */ + out.a =0xffff ; + out.r =0xffff ; + out.g =0xffff ;
drivers/gpu/drm/vkms/tests/vkms_color_tests.c static void vkms_color_srgb_inv_srgb(struct kunit *test) · line 277
Quoted 10 lines
drivers/gpu/drm/vkms/tests/vkms_color_tests.c +10
-0+ out.b =0xffff ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 255 */ +KUNIT_EXPECT_GT (test, out.r,0xfe00 ); +KUNIT_EXPECT_LT (test, out.r,0x10000 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x0100 );
For all of these U/V too, you may want to enforce a range. The value must be approximately 0x100. Something like 0x17 would very wrong.
Hmm, wait...
Neutral color should have U and V neutral, that is, zero, right? So what is zero in this integer representation?
You don't seem to be testing negative U or V...
Thanks,
pq
Quoted 178 lines
drivers/gpu/drm/vkms/tests/vkms_color_tests.c +157
-0+ +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x0100 ); + +/* full black to bt709 */ + out.a =0xffff ; + out.r =0x0 ; + out.g =0x0 ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 0 */ +KUNIT_EXPECT_LT (test, out.r,0x100 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x0100 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x0100 ); + +/* gray to bt709 */ + out.a =0xffff ; + out.r =0x7fff ; + out.g =0x7fff ; + out.b =0x7fff ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 127 */ +KUNIT_EXPECT_GT (test, out.r,0x7e00 ); +KUNIT_EXPECT_LT (test, out.r,0x8000 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x0100 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x0100 ); + +/* == red 255 - bt709 enc == */ + out.a =0xffff ; + out.r =0xffff ; + out.g =0x0 ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 54 */ +KUNIT_EXPECT_GT (test, out.r,0x3500 ); +KUNIT_EXPECT_LT (test, out.r,0x3700 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x0100 ); + +/* V 157 */ +KUNIT_EXPECT_GT (test, out.b,0x9C00 ); +KUNIT_EXPECT_LT (test, out.b,0x9E00 ); + + +/* == green 255 - bt709 enc == */ + out.a =0xffff ; + out.r =0x0 ; + out.g =0xffff ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 182 */ +KUNIT_EXPECT_GT (test, out.r,0xB500 ); +KUNIT_EXPECT_LT (test, out.r,0xB780 );/* laxed by half*/ + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x0100 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x0100 ); + +/* == blue 255 - bt709 enc == */ + out.a =0xffff ; + out.r =0x0 ; + out.g =0x0 ; + out.b =0xffff ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 18 */ +KUNIT_EXPECT_GT (test, out.r,0x1100 ); +KUNIT_EXPECT_LT (test, out.r,0x1300 ); + +/* U 111 */ +KUNIT_EXPECT_GT (test, out.g,0x6E00 ); +KUNIT_EXPECT_LT (test, out.g,0x7000 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x0100 ); + +/* == red 140 - bt709 enc == */ + out.a =0xffff ; + out.r =0x8c8c ; + out.g =0x0 ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 30 */ +KUNIT_EXPECT_GT (test, out.r,0x1D00 ); +KUNIT_EXPECT_LT (test, out.r,0x1F00 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x100 ); + +/* V 87 */ +KUNIT_EXPECT_GT (test, out.b,0x5600 ); +KUNIT_EXPECT_LT (test, out.b,0x5800 ); + +/* == green 140 - bt709 enc == */ + out.a =0xffff ; + out.r =0x0 ; + out.g =0x8c8c ; + out.b =0x0 ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 30 */ +KUNIT_EXPECT_GT (test, out.r,0x6400 ); +KUNIT_EXPECT_LT (test, out.r,0x6600 ); + +/* U 0 */ +KUNIT_EXPECT_LT (test, out.g,0x100 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x100 ); + + +/* == blue 140 - bt709 enc == */ + out.a =0xffff ; + out.r =0x0 ; + out.g =0x0 ; + out.b =0x8c8c ; + +apply_3x4_matrix (&out, &test_matrix_3x4_bt709_enc); + +/* Y 30 */ +KUNIT_EXPECT_GT (test, out.r,0x900 ); +KUNIT_EXPECT_LT (test, out.r,0xB00 ); + +/* U 61 */ +KUNIT_EXPECT_GT (test, out.g,0x3C00 ); +KUNIT_EXPECT_LT (test, out.g,0x3E00 ); + +/* V 0 */ +KUNIT_EXPECT_LT (test, out.b,0x100 ); + +} +static struct kunit_case vkms_color_test_cases[] = {KUNIT_CASE (vkms_color_test_get_lut_index),KUNIT_CASE (vkms_color_test_lerp),KUNIT_CASE (vkms_color_test_linear),KUNIT_CASE (vkms_color_srgb_inv_srgb), +KUNIT_CASE (vkms_color_ctm_3x4_50_desat), +KUNIT_CASE (vkms_color_ctm_3x4_bt709), {} };drivers/gpu/drm/vkms/vkms_composer.c +1
-1@@ -164,7 +164,7 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff } } -static void apply_3x4_matrix (struct pixel_argb_s32 *pixel,const struct drm_color_ctm_3x4 *matrix) +void apply_3x4_matrix (struct pixel_argb_s32 *pixel,const struct drm_color_ctm_3x4 *matrix) {s64 rf, gf, bf;
Harry Wentland
maintainerRFC PATCH v4 26/42 drm/colorop: pass plane_color_pipeline client cap to atomic check
In reply to Harry WentlandDrivers will need to know whether an atomic check/commit originated from a client with DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE so they can ignore deprecated properties, like COLOR_ENCODING and COLOR_RANGE.
Pass the plane_color_pipeline bit to drm_atomic_state.
--- drivers/gpu/drm/drm_atomic_uapi.c | 1 + include/drm/drm_atomic.h | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
drivers/gpu/drm/drm_atomic_uapi.c +1 -0
@@ -1571,6 +1571,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,drm_modeset_acquire_init (&ctx,DRM_MODESET_ACQUIRE_INTERRUPTIBLE ); state->acquire_ctx = &ctx; state->allow_modeset = !!(arg->flags &DRM_MODE_ATOMIC_ALLOW_MODESET ); + state->plane_color_pipeline = file_priv->plane_color_pipeline; retry: copied_objs =0 ;
include/drm/drm_atomic.h +17 -0
@@ -404,6 +404,23 @@ struct drm_atomic_state {* states. */ bool duplicated : 1; + +/** +* @plane_color_pipeline : 1 +* +* Indicates whether this atomic state originated with a client that +* set the DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE. +* +* Drivers and helper functions should use this to ignore legacy +* properties that are incompatible with the drm_plane COLOR_PIPELINE +* behavior, such as +* - COLOR_RANGE +* - COLOR_ENCODING +* or any other driver-specific properties that might affect pixel +* values. +*/ + bool plane_color_pipeline : 1; +struct __drm_colorops_state *colorops;struct __drm_planes_state *planes;struct __drm_crtcs_state *crtcs;
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 27/42 drm/colorop: define a new macro for_each_new_colorop_in_state
In reply to Harry WentlandFrom: Alex Hung <[email protected]>
Create a new macro for_each_new_colorop_in_state to access new drm_colorop_state updated from uapi.
--- include/drm/drm_atomic.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
include/drm/drm_atomic.h +20 -0
@@ -979,6 +979,26 @@ void drm_state_dump(struct drm_device *dev, struct drm_printer *p); (new_colorop_state) = (__state)->colorops[__i].new_state, 1)) +/** +* for_each_new_colorop_in_state - iterate over all colorops in an atomic update +* @__state: &struct drm_atomic_state pointer +* @colorop: &struct drm_colorop iteration cursor +* @new_colorop_state: &struct drm_colorop_state iteration cursor for the new state +* @__i: int iteration cursor, for macro-internal use +* +* This iterates over all colorops in an atomic update, tracking new state. This is +* useful is useful in places where the state delta needs to be considered, for +* example in atomic check functions. +*/ +#define for_each_new_colorop_in_state(__state, colorop, new_colorop_state, __i) \ + for ((__i) = 0; \ + (__i) < (__state)->dev->mode_config.num_colorop; \ + (__i)++) \ + for_each_if ((__state)->colorops[__i].ptr && \ + ((colorop) = (__state)->colorops[__i].ptr, \ + (void)(colorop) /* Only to avoid unused-but-set-variable warning */, \ + (new_colorop_state) = (__state)->colorops[__i].new_state, 1)) +/** * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update * @__state: &struct drm_atomic_state pointer
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 28/42 drm/amd/display: Ignore deprecated props when plane_color_pipeline set
In reply to Harry WentlandWhen the plane_color_pipeline bit is set we should ignore deprecated properties, such as COLOR_RANGE and COLOR_ENCODING.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4 -0
@@ -4948,6 +4948,10 @@ fill_plane_color_attributes(const struct drm_plane_state *plane_state, *color_space =COLOR_SPACE_SRGB ; +/* Ignore properties when DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE is set */ +if (plane_state->state && plane_state->state->plane_color_pipeline) +return 0 ; +/* DRM color properties only affect non-RGB formats. */ if (format <SURFACE_PIXEL_FORMAT_VIDEO_BEGIN )return 0 ;
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 29/42 drm/amd/display: Add bypass COLOR PIPELINE
In reply to Harry WentlandAdd the default Bypass pipeline and ensure it passes the kms_colorop test plane-XR30-XR30-bypass.
--- .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +19 -0
@@ -1651,6 +1651,20 @@ dm_atomic_plane_get_property(struct drm_plane *plane, }#endif +#define MAX_COLOR_PIPELINES 5 + +static int +dm_plane_init_colorops (struct drm_plane *plane) +{ +struct drm_prop_enum_list pipelines[MAX_COLOR_PIPELINES ]; +int len =0 ; + +/* Create COLOR_PIPELINE property and attach */ +drm_plane_create_color_pipeline_property (plane, pipelines, len); + +return 0 ; +} +static const struct drm_plane_funcs dm_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane,
@@ -1744,7 +1758,12 @@ int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,#ifdef AMD_PRIVATE_COLOR dm_atomic_plane_attach_color_mgmt_properties (dm, plane); +#else + res =dm_plane_init_colorops (plane); +if (res) +return res;#endif +/* Create (reset) the plane state */ if (plane->funcs->reset) plane->funcs->reset (plane);
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 30/42 drm/amd/display: Skip color pipeline initialization for cursor plane
In reply to Harry WentlandFrom: Alex Hung <[email protected]>
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +3 -0
@@ -1659,6 +1659,9 @@ dm_plane_init_colorops(struct drm_plane *plane)struct drm_prop_enum_list pipelines[MAX_COLOR_PIPELINES ];int len =0 ; +if (plane->type ==DRM_PLANE_TYPE_CURSOR ) +return 0 ; +/* Create COLOR_PIPELINE property and attach */ drm_plane_create_color_pipeline_property (plane, pipelines, len);
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 31/42 drm/amd/display: Add support for sRGB EOTF in DEGAM block
In reply to Harry WentlandFrom: Alex Hung <[email protected]>
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
--- .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 88 +++++++++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 58 ++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 34 +++++++ .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 10 +++ 5 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h
drivers/gpu/drm/amd/display/amdgpu_dm/Makefile +2 -1
@@ -38,7 +38,8 @@ AMDGPUDM = \ amdgpu_dm_pp_smu.o \ amdgpu_dm_psr.o \ amdgpu_dm_replay.o \ - amdgpu_dm_wb.o + amdgpu_dm_wb.o \ + amdgpu_dm_colorop.o ifdef CONFIG_DRM_AMD_DC_FP AMDGPUDM += dc_fpu.o
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +88 -0
111 lines not on this page · raw message
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c new file +58 -0
59 lines not on this page · raw message
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright 2023 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Authors: AMD +* +*/ + +#ifndef __AMDGPU_DM_COLOROP_H__ +#define __AMDGPU_DM_COLOROP_H__ + +extern const u64 amdgpu_dm_supported_degam_tfs; + +int amdgpu_dm_initialize_default_pipeline (struct drm_plane *plane,struct drm_prop_enum_list *list); + +#endif /* __AMDGPU_DM_COLOROP_H__*/
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +10 -0
@@ -35,6 +35,7 @@#include "amdgpu_display.h" #include "amdgpu_dm_trace.h" #include "amdgpu_dm_plane.h" +#include "amdgpu_dm_colorop.h" #include "gc/gc_11_0_0_offset.h" #include "gc/gc_11_0_0_sh_mask.h"
@@ -1658,10 +1659,19 @@ dm_plane_init_colorops(struct drm_plane *plane) {struct drm_prop_enum_list pipelines[MAX_COLOR_PIPELINES ];int len =0 ; +int ret;if (plane->type ==DRM_PLANE_TYPE_CURSOR )return 0 ; +/* initialize default pipeline */ + ret =amdgpu_dm_initialize_default_pipeline (plane, &(pipelines[len])); +if (ret) { +DRM_ERROR ("Failed to create color pipeline for plane %d: %d\n" , plane->base.id, ret); +return ret; + } + len++; +/* Create COLOR_PIPELINE property and attach */ drm_plane_create_color_pipeline_property (plane, pipelines, len);
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 31/42] drm/amd/display: Add support for sRGB EOTF in DEGAM block
Quoted 64 lines · Harry Wentland
From: Alex Hung <[email protected]>
Expose one 1D curve colorop with support for
DRM_COLOROP_1D_CURVE_SRGB_EOTFand 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_eotfThe color pipeline now consists of a single colorop:
1. 1D curve colorop w/ sRGB EOTFSigned-off-by Alex Hung <[email protected]>Signed-off-by Harry Wentland <[email protected]>Co-developed-by Harry Wentland <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 88 +++++++++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 58 ++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 34 +++++++ .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 10 +++ 5 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.hdrivers/gpu/drm/amd/display/amdgpu_dm/Makefile +2
-1@@ -38,7 +38,8 @@ AMDGPUDM = \ amdgpu_dm_pp_smu.o \ amdgpu_dm_psr.o \ amdgpu_dm_replay.o \ - amdgpu_dm_wb.o + amdgpu_dm_wb.o \ + amdgpu_dm_colorop.o ifdef CONFIG_DRM_AMD_DC_FP AMDGPUDM += dc_fpu.odrivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +13
-0@@ -668,6 +668,19 @@ amdgpu_tf_to_dc_tf(enum amdgpu_transfer_function tf) } } +static enum dc_transfer_func_predefined +amdgpu_colorop_tf_to_dc_tf (enum drm_colorop_curve_1d_type tf) +{ +switch (tf) + { +case DRM_COLOROP_1D_CURVE_SRGB_EOTF : +case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF : +return TRANSFER_FUNCTION_SRGB ; +default : +return TRANSFER_FUNCTION_LINEAR ;; + } +} +static void __to_dc_lut3d_color (struct dc_rgb *rgb,const struct drm_color_lut lut,int bit_precision)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c __set_dm_plane_degamma(struct drm_plane_state *plane_state, · line 1157
Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +5
-0@@ -1137,6 +1150,59 @@ __set_dm_plane_degamma(struct drm_plane_state *plane_state,return 0 ; } +static int +__set_colorop_in_tf_1d_curve (struct dc_plane_state *dc_plane_state, +struct drm_colorop_state *colorop_state) +{ +struct dc_transfer_func *tf = dc_plane_state->in_transfer_func;
For this patch and the next two, it ^ should be:&dc_plane_state->in_transfer_func (same for shape and blend), right?
Quoted 227 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +70
-0+struct drm_colorop *colorop = colorop_state->colorop; +struct drm_device *drm = colorop->dev; + +if (colorop->type !=DRM_COLOROP_1D_CURVE && + colorop_state->curve_1d_type !=DRM_COLOROP_1D_CURVE_SRGB_EOTF ) +return -EINVAL ; + +if (colorop_state->bypass) { + tf->type =TF_TYPE_BYPASS ; + tf->tf =TRANSFER_FUNCTION_LINEAR ; +return 0 ; + } + +drm_dbg (drm,"Degamma colorop with ID: %d\n" , colorop->base.id); + + tf->type =TF_TYPE_PREDEFINED ; + tf->tf =amdgpu_colorop_tf_to_dc_tf (colorop_state->curve_1d_type); + +return 0 ; +} + +static int +__set_dm_plane_colorop_degamma (struct drm_plane_state *plane_state, +struct dc_plane_state *dc_plane_state, +struct drm_colorop *colorop) +{ +struct drm_colorop *old_colorop; +struct drm_colorop_state *colorop_state =NULL , *new_colorop_state; +struct drm_atomic_state *state = plane_state->state; +int i =0 ; + + old_colorop = colorop; + +/* 1st op: 1d curve - degamma */ +for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) { +if (new_colorop_state->colorop == old_colorop && + new_colorop_state->curve_1d_type ==DRM_COLOROP_1D_CURVE_SRGB_EOTF ) { + colorop_state = new_colorop_state; +break ; + } + } + +if (!colorop_state) +return -EINVAL ; + +return __set_colorop_in_tf_1d_curve (dc_plane_state, colorop_state); +} +static int amdgpu_dm_plane_set_color_properties (struct drm_plane_state *plane_state,struct dc_plane_state *dc_plane_state)@@ -1187,6 +1253,25 @@ amdgpu_dm_plane_set_color_properties(struct drm_plane_state *plane_state,return 0 ; } +static int +amdgpu_dm_plane_set_colorop_properties (struct drm_plane_state *plane_state, +struct dc_plane_state *dc_plane_state) +{ +struct drm_colorop *colorop = plane_state->color_pipeline; +int ret; + +/* 1D Curve - DEGAM TF */ +if (!colorop) { +return -EINVAL ; + } + + ret =__set_dm_plane_colorop_degamma (plane_state, dc_plane_state, colorop); +if (ret) +return ret; + +return 0 ; +} +/** * amdgpu_dm_update_plane_color_mgmt: Maps DRM color management to DC plane. * @crtc: amdgpu_dm crtc state @@ -1283,5 +1368,8 @@ int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc, dc_plane_state->input_csc_color_matrix.enable_adjustment = false; } +if (!amdgpu_dm_plane_set_colorop_properties (plane_state, dc_plane_state)) +return 0 ; +return amdgpu_dm_plane_set_color_properties (plane_state, dc_plane_state); }drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c new file +58
-0@@ -0,0 +1,58 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright 2023 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Authors: AMD +* +*/ + +#include <drm/drm_print.h> +#include <drm/drm_plane.h> +#include <drm/drm_property.h> +#include <drm/drm_colorop.h> + +#include "amdgpu_dm_colorop.h" + +const u64 amdgpu_dm_supported_degam_tfs = +BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ); + +int amdgpu_dm_initialize_default_pipeline (struct drm_plane *plane,struct drm_prop_enum_list *list) +{ +struct drm_colorop *op; +struct drm_device *dev = plane->dev; +int ret; + +/* 1D curve - DEGAM TF */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_curve_1d_init (dev, op, plane, amdgpu_dm_supported_degam_tfs); +if (ret) +return ret; + + list->type = op->base.id; + list->name =kasprintf (GFP_KERNEL ,"Color Pipeline %d" , op->base.id); + +return 0 ; +}drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h new file +34
-0@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright 2023 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Authors: AMD +* +*/ + +#ifndef __AMDGPU_DM_COLOROP_H__ +#define __AMDGPU_DM_COLOROP_H__ + +extern const u64 amdgpu_dm_supported_degam_tfs; + +int amdgpu_dm_initialize_default_pipeline (struct drm_plane *plane,struct drm_prop_enum_list *list); + +#endif /* __AMDGPU_DM_COLOROP_H__*/ drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +10
-0@@ -35,6 +35,7 @@#include "amdgpu_display.h" #include "amdgpu_dm_trace.h" #include "amdgpu_dm_plane.h" +#include "amdgpu_dm_colorop.h" #include "gc/gc_11_0_0_offset.h" #include "gc/gc_11_0_0_sh_mask.h" @@ -1658,10 +1659,19 @@ dm_plane_init_colorops(struct drm_plane *plane) {struct drm_prop_enum_list pipelines[MAX_COLOR_PIPELINES ];int len =0 ; +int ret;if (plane->type ==DRM_PLANE_TYPE_CURSOR )return 0 ; +/* initialize default pipeline */ + ret =amdgpu_dm_initialize_default_pipeline (plane, &(pipelines[len])); +if (ret) { +DRM_ERROR ("Failed to create color pipeline for plane %d: %d\n" , plane->base.id, ret); +return ret; + } + len++; +/* Create COLOR_PIPELINE property and attach */ drm_plane_create_color_pipeline_property (plane, pipelines, len);Signature · 1 line
2.44.0
Re: [RFC PATCH v4 31/42] drm/amd/display: Add support for sRGB EOTF in DEGAM block
Quoted 48 lines · Melissa Wen
Quoted 47 lines · Harry Wentland
From: Alex Hung <[email protected]>
Expose one 1D curve colorop with support for
DRM_COLOROP_1D_CURVE_SRGB_EOTFand 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_eotfThe color pipeline now consists of a single colorop:
1. 1D curve colorop w/ sRGB EOTFSigned-off-by Alex Hung <[email protected]>Signed-off-by Harry Wentland <[email protected]>Co-developed-by Harry Wentland <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 88 +++++++++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 58 ++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 34 +++++++ .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 10 +++ 5 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.hdrivers/gpu/drm/amd/display/amdgpu_dm/Makefile +2
-1@@ -38,7 +38,8 @@ AMDGPUDM = \ amdgpu_dm_pp_smu.o \ amdgpu_dm_psr.o \ amdgpu_dm_replay.o \ - amdgpu_dm_wb.o + amdgpu_dm_wb.o \ + amdgpu_dm_colorop.o ifdef CONFIG_DRM_AMD_DC_FP AMDGPUDM += dc_fpu.odrivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +0
-0@@ -668,6 +668,19 @@ amdgpu_tf_to_dc_tf(enum amdgpu_transfer_function tf) } }
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c amdgpu_tf_to_dc_tf(enum amdgpu_transfer_function tf) · line 680
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +10
-0+static enum dc_transfer_func_predefined +amdgpu_colorop_tf_to_dc_tf (enum drm_colorop_curve_1d_type tf) +{ +switch (tf) + { +case DRM_COLOROP_1D_CURVE_SRGB_EOTF : +case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF : +return TRANSFER_FUNCTION_SRGB ; +default : +return TRANSFER_FUNCTION_LINEAR ;;
Nitpick: double ;
Quoted 246 lines
Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +3
-0+ } +} +static void __to_dc_lut3d_color (struct dc_rgb *rgb,const struct drm_color_lut lut,int bit_precision)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c __set_dm_plane_degamma(struct drm_plane_state *plane_state, · line 1157
Quoted 8 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +5
-0@@ -1137,6 +1150,59 @@ __set_dm_plane_degamma(struct drm_plane_state *plane_state,return 0 ; } +static int +__set_colorop_in_tf_1d_curve (struct dc_plane_state *dc_plane_state, +struct drm_colorop_state *colorop_state) +{ +struct dc_transfer_func *tf = dc_plane_state->in_transfer_func;For this patch and the next two, it ^ should be:
&dc_plane_state->in_transfer_func(same for shape and blend), right?Quoted 227 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +70
-0+struct drm_colorop *colorop = colorop_state->colorop; +struct drm_device *drm = colorop->dev; + +if (colorop->type !=DRM_COLOROP_1D_CURVE && + colorop_state->curve_1d_type !=DRM_COLOROP_1D_CURVE_SRGB_EOTF ) +return -EINVAL ; + +if (colorop_state->bypass) { + tf->type =TF_TYPE_BYPASS ; + tf->tf =TRANSFER_FUNCTION_LINEAR ; +return 0 ; + } + +drm_dbg (drm,"Degamma colorop with ID: %d\n" , colorop->base.id); + + tf->type =TF_TYPE_PREDEFINED ; + tf->tf =amdgpu_colorop_tf_to_dc_tf (colorop_state->curve_1d_type); + +return 0 ; +} + +static int +__set_dm_plane_colorop_degamma (struct drm_plane_state *plane_state, +struct dc_plane_state *dc_plane_state, +struct drm_colorop *colorop) +{ +struct drm_colorop *old_colorop; +struct drm_colorop_state *colorop_state =NULL , *new_colorop_state; +struct drm_atomic_state *state = plane_state->state; +int i =0 ; + + old_colorop = colorop; + +/* 1st op: 1d curve - degamma */ +for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) { +if (new_colorop_state->colorop == old_colorop && + new_colorop_state->curve_1d_type ==DRM_COLOROP_1D_CURVE_SRGB_EOTF ) { + colorop_state = new_colorop_state; +break ; + } + } + +if (!colorop_state) +return -EINVAL ; + +return __set_colorop_in_tf_1d_curve (dc_plane_state, colorop_state); +} +static int amdgpu_dm_plane_set_color_properties (struct drm_plane_state *plane_state,struct dc_plane_state *dc_plane_state)@@ -1187,6 +1253,25 @@ amdgpu_dm_plane_set_color_properties(struct drm_plane_state *plane_state,return 0 ; } +static int +amdgpu_dm_plane_set_colorop_properties (struct drm_plane_state *plane_state, +struct dc_plane_state *dc_plane_state) +{ +struct drm_colorop *colorop = plane_state->color_pipeline; +int ret; + +/* 1D Curve - DEGAM TF */ +if (!colorop) { +return -EINVAL ; + } + + ret =__set_dm_plane_colorop_degamma (plane_state, dc_plane_state, colorop); +if (ret) +return ret; + +return 0 ; +} +/** * amdgpu_dm_update_plane_color_mgmt: Maps DRM color management to DC plane. * @crtc: amdgpu_dm crtc state @@ -1283,5 +1368,8 @@ int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc, dc_plane_state->input_csc_color_matrix.enable_adjustment = false; } +if (!amdgpu_dm_plane_set_colorop_properties (plane_state, dc_plane_state)) +return 0 ; +return amdgpu_dm_plane_set_color_properties (plane_state, dc_plane_state); }drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c new file +58
-0@@ -0,0 +1,58 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright 2023 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Authors: AMD +* +*/ + +#include <drm/drm_print.h> +#include <drm/drm_plane.h> +#include <drm/drm_property.h> +#include <drm/drm_colorop.h> + +#include "amdgpu_dm_colorop.h" + +const u64 amdgpu_dm_supported_degam_tfs = +BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ); + +int amdgpu_dm_initialize_default_pipeline (struct drm_plane *plane,struct drm_prop_enum_list *list) +{ +struct drm_colorop *op; +struct drm_device *dev = plane->dev; +int ret; + +/* 1D curve - DEGAM TF */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_curve_1d_init (dev, op, plane, amdgpu_dm_supported_degam_tfs); +if (ret) +return ret; + + list->type = op->base.id; + list->name =kasprintf (GFP_KERNEL ,"Color Pipeline %d" , op->base.id); + +return 0 ; +}drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h new file +34
-0@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: MIT +/* +* Copyright 2023 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +* +* Authors: AMD +* +*/ + +#ifndef __AMDGPU_DM_COLOROP_H__ +#define __AMDGPU_DM_COLOROP_H__ + +extern const u64 amdgpu_dm_supported_degam_tfs; + +int amdgpu_dm_initialize_default_pipeline (struct drm_plane *plane,struct drm_prop_enum_list *list); + +#endif /* __AMDGPU_DM_COLOROP_H__*/ drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c +10
-0@@ -35,6 +35,7 @@#include "amdgpu_display.h" #include "amdgpu_dm_trace.h" #include "amdgpu_dm_plane.h" +#include "amdgpu_dm_colorop.h" #include "gc/gc_11_0_0_offset.h" #include "gc/gc_11_0_0_sh_mask.h" @@ -1658,10 +1659,19 @@ dm_plane_init_colorops(struct drm_plane *plane) {struct drm_prop_enum_list pipelines[MAX_COLOR_PIPELINES ];int len =0 ; +int ret;if (plane->type ==DRM_PLANE_TYPE_CURSOR )return 0 ; +/* initialize default pipeline */ + ret =amdgpu_dm_initialize_default_pipeline (plane, &(pipelines[len])); +if (ret) { +DRM_ERROR ("Failed to create color pipeline for plane %d: %d\n" , plane->base.id, ret); +return ret; + } + len++; +/* Create COLOR_PIPELINE property and attach */ drm_plane_create_color_pipeline_property (plane, pipelines, len);Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 32/42 drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block
In reply to Harry WentlandFrom: Alex Hung <[email protected]>
Expose a 2nd curve colorop with support for DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF and program HW to perform the sRGB Inverse EOTF on the shaper block when the colorop is not in bypass.
With this change the follow IGT tests pass:kms_colorop --run plane-XR30-XR30-srgb_inv_eotf kms_colorop --run plane-XR30-XR30-srgb_eotf-srgb_inv_eotf
The color pipeline now consists of the following colorops:
1. 1D curve colorop w/ sRGB EOTF support
2. 1D curve colorop w/ sRGB Inverse EOTF support
--- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 76 +++++++++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 20 ++++- .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 1 + 3 files changed, 96 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +76 -0
@@ -1203,6 +1203,70 @@ __set_dm_plane_colorop_degamma(struct drm_plane_state *plane_state,return __set_colorop_in_tf_1d_curve (dc_plane_state, colorop_state); } +static int +__set_colorop_in_shaper_1d_curve (struct dc_plane_state *dc_plane_state, +struct drm_colorop_state *colorop_state) +{ +struct dc_transfer_func *tf = dc_plane_state->in_shaper_func; +struct drm_colorop *colorop = colorop_state->colorop; +struct drm_device *drm = colorop->dev; +const struct drm_color_lut *shaper_lut; +uint32_t shaper_size; + +if (colorop->type !=DRM_COLOROP_1D_CURVE && + colorop_state->curve_1d_type !=DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ) +return -EINVAL ; + +if (colorop_state->bypass) { + tf->type =TF_TYPE_BYPASS ; + tf->tf =TRANSFER_FUNCTION_LINEAR ; +return 0 ; + } + +drm_dbg (drm,"Shaper colorop with ID: %d\n" , colorop->base.id); + +if (colorop->type ==DRM_COLOROP_1D_CURVE ) { + tf->type =TF_TYPE_DISTRIBUTED_POINTS ; + tf->tf =amdgpu_colorop_tf_to_dc_tf (colorop_state->curve_1d_type); + tf->sdr_ref_white_level =SDR_WHITE_LEVEL_INIT_VALUE ; +return __set_output_tf (tf, shaper_lut, shaper_size, false); + } + +return -EINVAL ; +} + +static int +__set_dm_plane_colorop_shaper (struct drm_plane_state *plane_state, +struct dc_plane_state *dc_plane_state, +struct drm_colorop *colorop) +{ +struct drm_colorop *old_colorop; +struct drm_colorop_state *colorop_state =NULL , *new_colorop_state; +struct drm_atomic_state *state = plane_state->state; +int i =0 ; + + old_colorop = colorop; + +/* 2nd op: 1d curve - shaper */ +for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) { +if (new_colorop_state->colorop == old_colorop && + new_colorop_state->curve_1d_type ==DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ) { + colorop_state = new_colorop_state; +break ; + } + +if (new_colorop_state->colorop == old_colorop) { + colorop_state = new_colorop_state; +break ; + } + } + +if (!colorop_state) +return -EINVAL ; + +return __set_colorop_in_shaper_1d_curve (dc_plane_state, colorop_state); +} +static int amdgpu_dm_plane_set_color_properties (struct drm_plane_state *plane_state,struct dc_plane_state *dc_plane_state)
@@ -1258,6 +1322,7 @@ amdgpu_dm_plane_set_colorop_properties(struct drm_plane_state *plane_state, struct dc_plane_state *dc_plane_state) {struct drm_colorop *colorop = plane_state->color_pipeline; +struct drm_device *dev = plane_state->plane->dev;int ret;/* 1D Curve - DEGAM TF */
@@ -1269,6 +1334,17 @@ amdgpu_dm_plane_set_colorop_properties(struct drm_plane_state *plane_state,if (ret)return ret; +/* 1D Curve - SHAPER TF */ + colorop = colorop->next; +if (!colorop) { +drm_dbg (dev,"no Shaper TF colorop found\n" ); +return -EINVAL ; + } + + ret =__set_dm_plane_colorop_shaper (plane_state, dc_plane_state, colorop); +if (ret) +return ret; +return 0 ; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +19 -1
@@ -34,9 +34,12 @@const u64 amdgpu_dm_supported_degam_tfs =BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ); +const u64 amdgpu_dm_supported_shaper_tfs = +BIT (DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ); +int amdgpu_dm_initialize_default_pipeline (struct drm_plane *plane,struct drm_prop_enum_list *list) { -struct drm_colorop *op; +struct drm_colorop *op, *prev_op;struct drm_device *dev = plane->dev;int ret;
@@ -54,5 +57,20 @@ int amdgpu_dm_initialize_default_pipeline(struct drm_plane *plane, struct drm_pr list->type = op->base.id; list->name =kasprintf (GFP_KERNEL ,"Color Pipeline %d" , op->base.id); + prev_op = op; + +/* 1D curve - SHAPER TF */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_curve_1d_init (dev, op, plane, amdgpu_dm_supported_shaper_tfs); +if (ret) +return ret; + +drm_colorop_set_next_property (prev_op, op); +return 0 ; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h +1 -0
@@ -28,6 +28,7 @@#define __AMDGPU_DM_COLOROP_H__extern const u64 amdgpu_dm_supported_degam_tfs; +extern const u64 amdgpu_dm_supported_shaper_tfs;int amdgpu_dm_initialize_default_pipeline (struct drm_plane *plane,struct drm_prop_enum_list *list);
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 33/42 drm/amd/display: Add support for sRGB EOTF in BLND block
In reply to Harry WentlandFrom: Alex Hung <[email protected]>
Expose a 3rd 1D curve colorop, with support for DRM_COLOROP_1D_CURVE_SRGB_EOTF and program the BLND block 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-srgb_inv_eotf-srgb_eotf
The color pipeline now consists of the following colorops:
1. 1D curve colorop w/ sRGB EOTF support
2. 1D curve colorop w/ sRGB Inverse EOTF support
3. 1D curve colorop w/ sRGB EOTF support
--- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 77 +++++++++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 18 +++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 1 + 3 files changed, 96 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +77 -0
@@ -1267,6 +1267,72 @@ __set_dm_plane_colorop_shaper(struct drm_plane_state *plane_state,return __set_colorop_in_shaper_1d_curve (dc_plane_state, colorop_state); } + +static int +__set_colorop_1d_curve_blend_tf_lut (struct dc_plane_state *dc_plane_state, +struct drm_colorop_state *colorop_state) +{ + +struct dc_transfer_func *tf = dc_plane_state->blend_tf; +struct drm_colorop *colorop = colorop_state->colorop; +struct drm_device *drm = colorop->dev; +const struct drm_color_lut *blend_lut; +uint32_t blend_size; + +if (colorop->type !=DRM_COLOROP_1D_CURVE && + colorop_state->curve_1d_type !=DRM_COLOROP_1D_CURVE_SRGB_EOTF ) +return -EINVAL ; + +if (colorop_state->bypass) { + tf->type =TF_TYPE_BYPASS ; + tf->tf =TRANSFER_FUNCTION_LINEAR ; +return 0 ; + } + +drm_dbg (drm,"Blend colorop with ID: %d\n" , colorop->base.id); + +if (colorop->type ==DRM_COLOROP_1D_CURVE ) { + tf->type =TF_TYPE_DISTRIBUTED_POINTS ; + tf->tf =amdgpu_colorop_tf_to_dc_tf (colorop_state->curve_1d_type); + tf->sdr_ref_white_level =SDR_WHITE_LEVEL_INIT_VALUE ; +return __set_input_tf (NULL , tf, blend_lut, blend_size); + } + +return -EINVAL ; +} + +static int +__set_dm_plane_colorop_blend (struct drm_plane_state *plane_state, +struct dc_plane_state *dc_plane_state, +struct drm_colorop *colorop) +{ +struct drm_colorop *old_colorop; +struct drm_colorop_state *colorop_state =NULL , *new_colorop_state; +struct drm_atomic_state *state = plane_state->state; +int i =0 ; + + old_colorop = colorop; + +/* 3nd op: 1d curve - blend */ +for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) { +if (new_colorop_state->colorop == old_colorop && + new_colorop_state->curve_1d_type ==DRM_COLOROP_1D_CURVE_SRGB_EOTF ) { + colorop_state = new_colorop_state; +break ; + } + +if (new_colorop_state->colorop == old_colorop) { + colorop_state = new_colorop_state; +break ; + } + } + +if (!colorop_state) +return -EINVAL ; + +return __set_colorop_1d_curve_blend_tf_lut (dc_plane_state, colorop_state); +} +static int amdgpu_dm_plane_set_color_properties (struct drm_plane_state *plane_state,struct dc_plane_state *dc_plane_state)
@@ -1345,6 +1411,17 @@ amdgpu_dm_plane_set_colorop_properties(struct drm_plane_state *plane_state,if (ret)return ret; +/* 1D Curve - BLND TF */ + colorop = colorop->next; +if (!colorop) { +drm_dbg (dev,"no Blend TF colorop found\n" ); +return -EINVAL ; + } + + ret =__set_dm_plane_colorop_blend (plane_state, dc_plane_state, colorop); +if (ret) +return ret; +return 0 ; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +18 -0
@@ -37,6 +37,9 @@ const u64 amdgpu_dm_supported_degam_tfs =const u64 amdgpu_dm_supported_shaper_tfs =BIT (DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ); +const u64 amdgpu_dm_supported_blnd_tfs = +BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ); +int amdgpu_dm_initialize_default_pipeline (struct drm_plane *plane,struct drm_prop_enum_list *list) {struct drm_colorop *op, *prev_op;
@@ -72,5 +75,20 @@ int amdgpu_dm_initialize_default_pipeline(struct drm_plane *plane, struct drm_prdrm_colorop_set_next_property (prev_op, op); + prev_op = op; + +/* 1D curve - BLND TF */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_curve_1d_init (dev, op, plane, amdgpu_dm_supported_blnd_tfs); +if (ret) +return ret; + +drm_colorop_set_next_property (prev_op, op); +return 0 ; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h +1 -0
@@ -29,6 +29,7 @@extern const u64 amdgpu_dm_supported_degam_tfs;extern const u64 amdgpu_dm_supported_shaper_tfs; +extern const u64 amdgpu_dm_supported_blnd_tfs;int amdgpu_dm_initialize_default_pipeline (struct drm_plane *plane,struct drm_prop_enum_list *list);
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 34/42 drm/colorop: Add PQ 125 EOTF and its inverse
In reply to Harry WentlandThe PQ function defines a mapping of code values to nits (cd/m^2). The max code value maps to 10,000 nits.
Windows DWM's canonical composition color space (CCCS) defaults to composing SDR contents to 80 nits and uses a float value of 1.0 to represent this. For this reason AMD HW hard-codes a PQ function that is scaled by 125, yielding 80 nit PQ values for 1.0 and 10,000 nits at 125.0.
This patch introduces this scaled PQ EOTF and its inverse as 1D curve types.
--- drivers/gpu/drm/drm_colorop.c | 2 ++ include/drm/drm_colorop.h | 2 ++ 2 files changed, 4 insertions(+)
drivers/gpu/drm/drm_colorop.c +2 -0
@@ -40,6 +40,8 @@ static const struct drm_prop_enum_list drm_colorop_type_enum_list[] = {static const char *const colorop_curve_1d_type_names[] = { [DRM_COLOROP_1D_CURVE_SRGB_EOTF ] ="sRGB EOTF" , [DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ] ="sRGB Inverse EOTF" , + [DRM_COLOROP_1D_CURVE_PQ_125_EOTF ] ="PQ 125 EOTF" , + [DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF ] ="PQ 125 Inverse EOTF" , };
include/drm/drm_colorop.h +2 -0
@@ -33,6 +33,8 @@enum drm_colorop_curve_1d_type {DRM_COLOROP_1D_CURVE_SRGB_EOTF ,DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF , +DRM_COLOROP_1D_CURVE_PQ_125_EOTF , +DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF ,DRM_COLOROP_1D_CURVE_COUNT };
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 35/42 drm/amd/display: Enable support for PQ 125 EOTF and Inverse
In reply to Harry WentlandThis patchset enables support for the PQ_125 EOTF and its inverse on all existing plane 1D curve colorops, i.e., on DEGAM, SHAPER, and BLND blocks.
With this patchset the following IGT subtests are passing:kms_colorop --run plane-XR30-XR30-pq_125_eotfkms_colorop --run plane-XR30-XR30-pq_125_inv_eotfkms_colorop --run plane-XR30-XR30-pq_125_eotf-pq_125_inv_eotf kms_colorop --run plane-XR30-XR30-pq_125_eotf-pq_125_inv_eotf-pq_125_eotf
--- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 20 +++++++++++++------ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 8 +++++--- 2 files changed, 19 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +14 -6
@@ -25,6 +25,7 @@#include "amdgpu.h" #include "amdgpu_mode.h" #include "amdgpu_dm.h" +#include "amdgpu_dm_colorop.h" #include "dc.h" #include "modules/color/color_gamma.h" #include "basics/conversion.h"
@@ -676,6 +677,9 @@ amdgpu_colorop_tf_to_dc_tf(enum drm_colorop_curve_1d_type tf)case DRM_COLOROP_1D_CURVE_SRGB_EOTF :case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF :return TRANSFER_FUNCTION_SRGB ; +case DRM_COLOROP_1D_CURVE_PQ_125_EOTF : +case DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF : +return TRANSFER_FUNCTION_PQ ;default :return TRANSFER_FUNCTION_LINEAR ;; }
@@ -1158,8 +1162,10 @@ __set_colorop_in_tf_1d_curve(struct dc_plane_state *dc_plane_state,struct drm_colorop *colorop = colorop_state->colorop;struct drm_device *drm = colorop->dev; -if (colorop->type !=DRM_COLOROP_1D_CURVE && - colorop_state->curve_1d_type !=DRM_COLOROP_1D_CURVE_SRGB_EOTF ) +if (colorop->type !=DRM_COLOROP_1D_CURVE ) +return -EINVAL ; + +if (!(BIT (colorop_state->curve_1d_type) & amdgpu_dm_supported_degam_tfs))return -EINVAL ;if (colorop_state->bypass) {
@@ -1191,7 +1197,7 @@ __set_dm_plane_colorop_degamma(struct drm_plane_state *plane_state,/* 1st op: 1d curve - degamma */ for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) {if (new_colorop_state->colorop == old_colorop && - new_colorop_state->curve_1d_type ==DRM_COLOROP_1D_CURVE_SRGB_EOTF ) { + (BIT (new_colorop_state->curve_1d_type) & amdgpu_dm_supported_degam_tfs)) { colorop_state = new_colorop_state;break ; }
@@ -1213,8 +1219,10 @@ __set_colorop_in_shaper_1d_curve(struct dc_plane_state *dc_plane_state,const struct drm_color_lut *shaper_lut;uint32_t shaper_size; -if (colorop->type !=DRM_COLOROP_1D_CURVE && - colorop_state->curve_1d_type !=DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ) +if (colorop->type !=DRM_COLOROP_1D_CURVE ) +return -EINVAL ; + +if (!(BIT (colorop_state->curve_1d_type) & amdgpu_dm_supported_shaper_tfs))return -EINVAL ;if (colorop_state->bypass) {
@@ -1250,7 +1258,7 @@ __set_dm_plane_colorop_shaper(struct drm_plane_state *plane_state,/* 2nd op: 1d curve - shaper */ for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) {if (new_colorop_state->colorop == old_colorop && - new_colorop_state->curve_1d_type ==DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ) { + (BIT (new_colorop_state->curve_1d_type) & amdgpu_dm_supported_shaper_tfs)) { colorop_state = new_colorop_state;break ; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +5 -3
@@ -32,10 +32,12 @@#include "amdgpu_dm_colorop.h" const u64 amdgpu_dm_supported_degam_tfs = -BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ); +BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ) | +BIT (DRM_COLOROP_1D_CURVE_PQ_125_EOTF ); -const u64 amdgpu_dm_supported_shaper_tfs = -BIT (DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ); +const u64 amdgpu_dm_supported_shaper_tfs = +BIT (DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ) | +BIT (DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF );const u64 amdgpu_dm_supported_blnd_tfs =BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF );
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 36/42 drm/colorop: add BT2020/BT709 OETF and Inverse OETF
In reply to Harry WentlandThe BT.709 and BT.2020 OETFs are the same, the only difference being that the BT.2020 variant is defined with more precision for 10 and 12-bit per color encodings.
Both are used as encoding functions for video content, and are therefore defined as OETF (opto-electronic transfer function) instead of as EOTF (electro-optical transfer function).
--- drivers/gpu/drm/drm_colorop.c | 2 ++ include/drm/drm_colorop.h | 2 ++ 2 files changed, 4 insertions(+)
drivers/gpu/drm/drm_colorop.c +2 -0
@@ -40,6 +40,8 @@ static const struct drm_prop_enum_list drm_colorop_type_enum_list[] = {static const char *const colorop_curve_1d_type_names[] = { [DRM_COLOROP_1D_CURVE_SRGB_EOTF ] ="sRGB EOTF" , [DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ] ="sRGB Inverse EOTF" , + [DRM_COLOROP_1D_CURVE_BT2020_INV_OETF ] ="BT.2020 Inverse OETF" , + [DRM_COLOROP_1D_CURVE_BT2020_OETF ] ="BT.2020 OETF" , [DRM_COLOROP_1D_CURVE_PQ_125_EOTF ] ="PQ 125 EOTF" , [DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF ] ="PQ 125 Inverse EOTF" , };
include/drm/drm_colorop.h +2 -0
@@ -33,6 +33,8 @@enum drm_colorop_curve_1d_type {DRM_COLOROP_1D_CURVE_SRGB_EOTF ,DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF , +DRM_COLOROP_1D_CURVE_BT2020_INV_OETF , +DRM_COLOROP_1D_CURVE_BT2020_OETF ,DRM_COLOROP_1D_CURVE_PQ_125_EOTF ,DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF ,DRM_COLOROP_1D_CURVE_COUNT
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 37/42 drm/amd/display: Add support for BT.709 and BT.2020 TFs
In reply to Harry WentlandThis adds support for the BT.709/BT.2020 transfer functions on all current 1D curve plane colorops, i.e., on DEGAM, SHAPER, and BLND blocks.
With this change the following IGT subtests pass:kms_colorop --run plane-XR30-XR30-bt2020_inv_oetfkms_colorop --run plane-XR30-XR30-bt2020_oetf
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c | 11 ++++++++--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 10 +++++++--- 2 files changed, 15 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +8 -3
@@ -677,6 +677,9 @@ amdgpu_colorop_tf_to_dc_tf(enum drm_colorop_curve_1d_type tf)case DRM_COLOROP_1D_CURVE_SRGB_EOTF :case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF :return TRANSFER_FUNCTION_SRGB ; +case DRM_COLOROP_1D_CURVE_BT2020_INV_OETF : +case DRM_COLOROP_1D_CURVE_BT2020_OETF : +return TRANSFER_FUNCTION_BT709 ;case DRM_COLOROP_1D_CURVE_PQ_125_EOTF :case DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF :return TRANSFER_FUNCTION_PQ ;
@@ -1287,8 +1290,10 @@ __set_colorop_1d_curve_blend_tf_lut(struct dc_plane_state *dc_plane_state,const struct drm_color_lut *blend_lut;uint32_t blend_size; -if (colorop->type !=DRM_COLOROP_1D_CURVE && - colorop_state->curve_1d_type !=DRM_COLOROP_1D_CURVE_SRGB_EOTF ) +if (colorop->type !=DRM_COLOROP_1D_CURVE ) +return -EINVAL ; + +if (!(BIT (colorop_state->curve_1d_type) & amdgpu_dm_supported_blnd_tfs))return -EINVAL ;if (colorop_state->bypass) {
@@ -1324,7 +1329,7 @@ __set_dm_plane_colorop_blend(struct drm_plane_state *plane_state,/* 3nd op: 1d curve - blend */ for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) {if (new_colorop_state->colorop == old_colorop && - new_colorop_state->curve_1d_type ==DRM_COLOROP_1D_CURVE_SRGB_EOTF ) { + (BIT (new_colorop_state->curve_1d_type) & amdgpu_dm_supported_blnd_tfs)) { colorop_state = new_colorop_state;break ; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +7 -3
@@ -33,14 +33,18 @@const u64 amdgpu_dm_supported_degam_tfs =BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ) | -BIT (DRM_COLOROP_1D_CURVE_PQ_125_EOTF ); +BIT (DRM_COLOROP_1D_CURVE_PQ_125_EOTF ) | +BIT (DRM_COLOROP_1D_CURVE_BT2020_INV_OETF );const u64 amdgpu_dm_supported_shaper_tfs =BIT (DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF ) | -BIT (DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF ); +BIT (DRM_COLOROP_1D_CURVE_PQ_125_INV_EOTF ) | +BIT (DRM_COLOROP_1D_CURVE_BT2020_OETF );const u64 amdgpu_dm_supported_blnd_tfs = -BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ); +BIT (DRM_COLOROP_1D_CURVE_SRGB_EOTF ) | +BIT (DRM_COLOROP_1D_CURVE_PQ_125_EOTF ) | +BIT (DRM_COLOROP_1D_CURVE_BT2020_INV_OETF );int amdgpu_dm_initialize_default_pipeline (struct drm_plane *plane,struct drm_prop_enum_list *list) {
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 38/42 drm/colorop: Add 1D Curve Custom LUT type
In reply to Harry WentlandFrom: Alex Hung <[email protected]>
We've previously introduced DRM_COLOROP_1D_CURVE for pre-defined 1D curves. But we also have HW that supports custom curves and userspace needs the ability to pass custom curves, aka LUTs.
This patch introduces a new colorop type, called DRM_COLOROP_1D_LUT that provides a SIZE property which is used by a driver to advertise the supported SIZE of the LUT, as well as a DATA property which userspace uses to set the LUT.
DATA and size function in the same way as current drm_crtc GAMMA and DEGAMMA LUTs.
--- drivers/gpu/drm/drm_atomic.c | 4 ++++ drivers/gpu/drm/drm_atomic_uapi.c | 5 +++++ drivers/gpu/drm/drm_colorop.c | 36 +++++++++++++++++++++++++++++-- include/drm/drm_colorop.h | 16 ++++++++++++++ include/uapi/drm/drm_mode.h | 1 + 5 files changed, 60 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic.c +4 -0
@@ -799,6 +799,10 @@ static void drm_atomic_colorop_print_state(struct drm_printer *p,drm_printf (p,"\tcurve_1d_type=%s\n" ,drm_get_colorop_curve_1d_type_name (state->curve_1d_type));break ; +case DRM_COLOROP_1D_LUT : +drm_printf (p,"\tsize=%d\n" , state->size); +drm_printf (p,"\tdata blob id=%d\n" , state->data ? state->data->base.id :0 ); +break ;case DRM_COLOROP_CTM_3X4 :drm_printf (p,"\tdata blob id=%d\n" , state->data ? state->data->base.id :0 );break ;
drivers/gpu/drm/drm_atomic_uapi.c +5 -0
@@ -700,6 +700,9 @@ static int drm_atomic_color_set_data_property(struct drm_colorop *colorop,bool replaced = false;switch (colorop->type) { +case DRM_COLOROP_1D_LUT : + size = state->size *sizeof (struct drm_color_lut ); +break ;case DRM_COLOROP_CTM_3X4 : size =sizeof (struct drm_color_ctm_3x4 );break ;
@@ -749,6 +752,8 @@ drm_atomic_colorop_get_property(struct drm_colorop *colorop, *val = state->bypass; }else if (property == colorop->curve_1d_type_property) { *val = state->curve_1d_type; + }else if (property == colorop->size_property) { + *val = state->size; }else if (property == colorop->data_property) { *val = (state->data) ? state->data->base.id :0 ; }else {
drivers/gpu/drm/drm_colorop.c +34 -2
@@ -34,6 +34,7 @@static const struct drm_prop_enum_list drm_colorop_type_enum_list[] = { {DRM_COLOROP_1D_CURVE ,"1D Curve" }, + {DRM_COLOROP_1D_LUT ,"1D Curve Custom LUT" }, {DRM_COLOROP_CTM_3X4 ,"3x4 Matrix" } };
@@ -175,11 +176,41 @@ static int drm_colorop_create_data_prop(struct drm_device *dev, struct drm_color colorop->data_property = prop;drm_object_attach_property (&colorop->base, - colorop->data_property, -0 ); + colorop->data_property, +0 );return 0 ; } +int drm_colorop_curve_1d_lut_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane,uint32_t lut_size) +{ +struct drm_property *prop; +int ret; + + ret =drm_colorop_init (dev, colorop, plane,DRM_COLOROP_1D_LUT ); +if (ret) +return ret; + +/* initialize 1D LUT only attribute */ +/* LUT size */ + prop =drm_property_create_range (dev,DRM_MODE_PROP_ATOMIC ,"SIZE" , lut_size, lut_size); +if (!prop) +return -ENOMEM ; + + colorop->size_property = prop; +drm_object_attach_property (&colorop->base, colorop->size_property,0 ); + +/* data */ + ret =drm_colorop_create_data_prop (dev, colorop); +if (ret) +return ret; + +drm_colorop_reset (colorop); + colorop->state->size = lut_size; + +return 0 ; +} +EXPORT_SYMBOL (drm_colorop_curve_1d_lut_init);int drm_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop,struct drm_plane *plane)
@@ -301,6 +332,7 @@ EXPORT_SYMBOL(drm_colorop_reset);static const char *const colorop_type_name[] = { [DRM_COLOROP_1D_CURVE ] ="1D Curve" , + [DRM_COLOROP_1D_LUT ] ="1D Curve Custom LUT" , [DRM_COLOROP_CTM_3X4 ] ="3x4 Matrix" };
include/drm/drm_colorop.h +16 -0
@@ -64,6 +64,13 @@ struct drm_colorop_state {*/ enum drm_colorop_curve_1d_type curve_1d_type; +/** +* @size: +* +* Number of entries of the custom LUT. This should be read-only. +*/ +uint32_t size; +/** * @data: *
@@ -179,6 +186,13 @@ struct drm_colorop {*/ struct drm_property *curve_1d_type_property; +/** +* @size_property: +* +* Size property for custom LUT from userspace. +*/ +struct drm_property *size_property; +/** * @data: *
@@ -228,6 +242,8 @@ int drm_colorop_init(struct drm_device *dev, struct drm_colorop *colorop,int drm_colorop_curve_1d_init (struct drm_device *dev,struct drm_colorop *colorop,struct drm_plane *plane,u64 supported_tfs); +int drm_colorop_curve_1d_lut_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane,uint32_t lut_size);int drm_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop,struct drm_plane *plane);
include/uapi/drm/drm_mode.h +1 -0
@@ -874,6 +874,7 @@ struct drm_color_lut {enum drm_colorop_type {DRM_COLOROP_1D_CURVE , +DRM_COLOROP_1D_LUT ,DRM_COLOROP_CTM_3X4 , };
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 39/42 drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT
In reply to Harry WentlandFrom: Alex Hung <[email protected]>
This patch adds colorops for custom 1D LUTs in the SHAPER and BLND HW blocks.
With this change the following IGT tests pass:kms_colorop --run plane-XR30-XR30-srgb_inv_eotf_lut kms_colorop --run plane-XR30-XR30-srgb_inv_eotf_lut-srgb_eotf_lut
The color pipeline now consists of the following colorops:
1. 1D curve colorop
2. 1D curve colorop
3. 1D LUT
4. 1D curve colorop
5. 1D LUT
The 1D curve colorops support sRGB, BT2020, and PQ scaled to 125.0.
--- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 170 +++++++++--------- .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 30 ++++ 2 files changed, 119 insertions(+), 81 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +89 -81
@@ -1212,40 +1212,6 @@ __set_dm_plane_colorop_degamma(struct drm_plane_state *plane_state,return __set_colorop_in_tf_1d_curve (dc_plane_state, colorop_state); } -static int -__set_colorop_in_shaper_1d_curve (struct dc_plane_state *dc_plane_state, -struct drm_colorop_state *colorop_state) -{ -struct dc_transfer_func *tf = dc_plane_state->in_shaper_func; -struct drm_colorop *colorop = colorop_state->colorop; -struct drm_device *drm = colorop->dev; -const struct drm_color_lut *shaper_lut; -uint32_t shaper_size; - -if (colorop->type !=DRM_COLOROP_1D_CURVE ) -return -EINVAL ; - -if (!(BIT (colorop_state->curve_1d_type) & amdgpu_dm_supported_shaper_tfs)) -return -EINVAL ; - -if (colorop_state->bypass) { - tf->type =TF_TYPE_BYPASS ; - tf->tf =TRANSFER_FUNCTION_LINEAR ; -return 0 ; - } - -drm_dbg (drm,"Shaper colorop with ID: %d\n" , colorop->base.id); - -if (colorop->type ==DRM_COLOROP_1D_CURVE ) { - tf->type =TF_TYPE_DISTRIBUTED_POINTS ; - tf->tf =amdgpu_colorop_tf_to_dc_tf (colorop_state->curve_1d_type); - tf->sdr_ref_white_level =SDR_WHITE_LEVEL_INIT_VALUE ; -return __set_output_tf (tf, shaper_lut, shaper_size, false); - } - -return -EINVAL ; -} - static int __set_dm_plane_colorop_shaper(struct drm_plane_state *plane_state, struct dc_plane_state *dc_plane_state,
@@ -1254,64 +1220,61 @@ __set_dm_plane_colorop_shaper(struct drm_plane_state *plane_state,struct drm_colorop *old_colorop;struct drm_colorop_state *colorop_state =NULL , *new_colorop_state;struct drm_atomic_state *state = plane_state->state; +enum dc_transfer_func_predefined default_tf =TRANSFER_FUNCTION_LINEAR ; +struct dc_transfer_func *tf = dc_plane_state->in_shaper_func; +const struct drm_color_lut *shaper_lut; +struct drm_device *dev = colorop->dev; +uint32_t shaper_size;int i =0 ; +/* 1D Curve - SHAPER TF */ old_colorop = colorop; - -/* 2nd op: 1d curve - shaper */ for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) {if (new_colorop_state->colorop == old_colorop && (BIT (new_colorop_state->curve_1d_type) & amdgpu_dm_supported_shaper_tfs)) { colorop_state = new_colorop_state;break ; } + } -if (new_colorop_state->colorop == old_colorop) { +if (colorop_state && !colorop_state->bypass && colorop->type ==DRM_COLOROP_1D_CURVE ) { +drm_dbg (dev,"Shaper TF colorop with ID: %d\n" , colorop->base.id); + tf->type =TF_TYPE_DISTRIBUTED_POINTS ; + tf->tf = default_tf =amdgpu_colorop_tf_to_dc_tf (colorop_state->curve_1d_type); + tf->sdr_ref_white_level =SDR_WHITE_LEVEL_INIT_VALUE ; +__set_output_tf (tf, shaper_lut, shaper_size, false); + } + +/* 1D LUT - SHAPER LUT */ + colorop = old_colorop->next; +if (!colorop) { +drm_dbg (dev,"no Shaper LUT colorop found\n" ); +return -EINVAL ; + } + + old_colorop = colorop; +for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) { +if (new_colorop_state->colorop == old_colorop && + new_colorop_state->colorop->type ==DRM_COLOROP_1D_LUT ) { colorop_state = new_colorop_state;break ; } } -if (!colorop_state) -return -EINVAL ; - -return __set_colorop_in_shaper_1d_curve (dc_plane_state, colorop_state); -} - - -static int -__set_colorop_1d_curve_blend_tf_lut (struct dc_plane_state *dc_plane_state, -struct drm_colorop_state *colorop_state) -{ - -struct dc_transfer_func *tf = dc_plane_state->blend_tf; -struct drm_colorop *colorop = colorop_state->colorop; -struct drm_device *drm = colorop->dev; -const struct drm_color_lut *blend_lut; -uint32_t blend_size; - -if (colorop->type !=DRM_COLOROP_1D_CURVE ) -return -EINVAL ; - -if (!(BIT (colorop_state->curve_1d_type) & amdgpu_dm_supported_blnd_tfs)) -return -EINVAL ; - -if (colorop_state->bypass) { - tf->type =TF_TYPE_BYPASS ; - tf->tf =TRANSFER_FUNCTION_LINEAR ; -return 0 ; - } - -drm_dbg (drm,"Blend colorop with ID: %d\n" , colorop->base.id); - -if (colorop->type ==DRM_COLOROP_1D_CURVE ) { +if (colorop_state && !colorop_state->bypass && colorop->type ==DRM_COLOROP_1D_LUT ) { +drm_dbg (dev,"Shaper LUT colorop with ID: %d\n" , colorop->base.id); tf->type =TF_TYPE_DISTRIBUTED_POINTS ; - tf->tf =amdgpu_colorop_tf_to_dc_tf (colorop_state->curve_1d_type); + tf->tf = default_tf; tf->sdr_ref_white_level =SDR_WHITE_LEVEL_INIT_VALUE ; -return __set_input_tf (NULL , tf, blend_lut, blend_size); + shaper_lut =__extract_blob_lut (colorop_state->data, &shaper_size); + shaper_size = shaper_lut !=NULL ? shaper_size :0 ; + +/* Custom LUT size must be the same as supported size */ +if (shaper_size == colorop_state->size) +__set_output_tf (tf, shaper_lut, shaper_size, false); } -return -EINVAL ; +return 0 ; } static int
@@ -1322,28 +1285,63 @@ __set_dm_plane_colorop_blend(struct drm_plane_state *plane_state,struct drm_colorop *old_colorop;struct drm_colorop_state *colorop_state =NULL , *new_colorop_state;struct drm_atomic_state *state = plane_state->state; +enum dc_transfer_func_predefined default_tf =TRANSFER_FUNCTION_LINEAR ; +struct dc_transfer_func *tf = dc_plane_state->blend_tf; +const struct drm_color_lut *blend_lut; +struct drm_device *dev = colorop->dev; +uint32_t blend_size;int i =0 ; +/* 1D Curve - BLND TF */ old_colorop = colorop; - -/* 3nd op: 1d curve - blend */ for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) {if (new_colorop_state->colorop == old_colorop && (BIT (new_colorop_state->curve_1d_type) & amdgpu_dm_supported_blnd_tfs)) { colorop_state = new_colorop_state;break ; } + } -if (new_colorop_state->colorop == old_colorop) { +if (colorop_state && !colorop_state->bypass && colorop->type ==DRM_COLOROP_1D_CURVE && + (BIT (colorop_state->curve_1d_type) & amdgpu_dm_supported_blnd_tfs)) { +drm_dbg (dev,"Blend TF colorop with ID: %d\n" , colorop->base.id); + tf->type =TF_TYPE_DISTRIBUTED_POINTS ; + tf->tf = default_tf =amdgpu_colorop_tf_to_dc_tf (colorop_state->curve_1d_type); + tf->sdr_ref_white_level =SDR_WHITE_LEVEL_INIT_VALUE ; +__set_input_tf (NULL , tf, blend_lut, blend_size); + } + +/* 1D Curve - BLND LUT */ + colorop = old_colorop->next; +if (!colorop) { +drm_dbg (dev,"no Blend LUT colorop found\n" ); +return -EINVAL ; + } + + old_colorop = colorop; +for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) { +if (new_colorop_state->colorop == old_colorop && + new_colorop_state->colorop->type ==DRM_COLOROP_1D_LUT ) { colorop_state = new_colorop_state;break ; } } -if (!colorop_state) -return -EINVAL ; +if (colorop_state && !colorop_state->bypass && colorop->type ==DRM_COLOROP_1D_LUT && + (BIT (colorop_state->curve_1d_type) & amdgpu_dm_supported_blnd_tfs)) { +drm_dbg (dev,"Blend LUT colorop with ID: %d\n" , colorop->base.id); + tf->type =TF_TYPE_DISTRIBUTED_POINTS ; + tf->tf = default_tf; + tf->sdr_ref_white_level =SDR_WHITE_LEVEL_INIT_VALUE ; + blend_lut =__extract_blob_lut (colorop_state->data, &blend_size); + blend_size = blend_lut !=NULL ? blend_size :0 ; -return __set_colorop_1d_curve_blend_tf_lut (dc_plane_state, colorop_state); +/* Custom LUT size must be the same as supported size */ +if (blend_size == colorop_state->size) +__set_input_tf (NULL , tf, blend_lut, blend_size); + } + +return 0 ; } static int
@@ -1413,7 +1411,7 @@ amdgpu_dm_plane_set_colorop_properties(struct drm_plane_state *plane_state,if (ret)return ret; -/* 1D Curve - SHAPER TF */ +/* 1D Curve & LUT - SHAPER TF & LUT */ colorop = colorop->next;if (!colorop) {drm_dbg (dev,"no Shaper TF colorop found\n" );
@@ -1424,7 +1422,12 @@ amdgpu_dm_plane_set_colorop_properties(struct drm_plane_state *plane_state,if (ret)return ret; -/* 1D Curve - BLND TF */ +/* Shaper LUT colorop is already handled, just skip here */ + colorop = colorop->next; +if (!colorop) +return -EINVAL ; + +/* 1D Curve & LUT - BLND TF & LUT */ colorop = colorop->next;if (!colorop) {drm_dbg (dev,"no Blend TF colorop found\n" );
@@ -1435,6 +1438,11 @@ amdgpu_dm_plane_set_colorop_properties(struct drm_plane_state *plane_state,if (ret)return ret; +/* BLND LUT colorop is already handled, just skip here */ + colorop = colorop->next; +if (!colorop) +return -EINVAL ; +return 0 ; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +30 -0
@@ -29,6 +29,7 @@#include <drm/drm_property.h> #include <drm/drm_colorop.h> +#include "amdgpu.h" #include "amdgpu_dm_colorop.h" const u64 amdgpu_dm_supported_degam_tfs =
@@ -83,6 +84,21 @@ int amdgpu_dm_initialize_default_pipeline(struct drm_plane *plane, struct drm_pr prev_op = op; +/* 1D LUT - SHAPER LUT */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_curve_1d_lut_init (dev, op, plane,MAX_COLOR_LUT_ENTRIES ); +if (ret) +return ret; + +drm_colorop_set_next_property (prev_op, op); + + prev_op = op; +/* 1D curve - BLND TF */ op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL );if (!op) {
@@ -96,5 +112,19 @@ int amdgpu_dm_initialize_default_pipeline(struct drm_plane *plane, struct drm_prdrm_colorop_set_next_property (prev_op, op); + prev_op = op; + +/* 1D LUT - BLND LUT */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_curve_1d_lut_init (dev, op, plane,MAX_COLOR_LUT_ENTRIES ); +if (ret) +return ret; + +drm_colorop_set_next_property (prev_op, op);return 0 ; }
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 40/42 drm/amd/display: add 3x4 matrix colorop
In reply to Harry WentlandFrom: Alex Hung <[email protected]>
This adds support for a 3x4 color transformation matrix.
With this change the following IGT tests pass:kms_colorop --run plane-XR30-XR30-ctm_3x4_50_desat kms_colorop --run plane-XR30-XR30-ctm_3x4_overdrive kms_colorop --run plane-XR30-XR30-ctm_3x4_oversaturate kms_colorop --run plane-XR30-XR30-ctm_3x4_bt709_enc kms_colorop --run plane-XR30-XR30-ctm_3x4_bt709_dec
The color pipeline now consists of the following colorops:
1. 1D curve colorop
2. 3x4 CTM
3. 1D curve colorop
4. 1D LUT
5. 1D curve colorop
6. 1D LUT
--- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 50 +++++++++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 15 ++++++ 2 files changed, 65 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +50 -0
@@ -1212,6 +1212,45 @@ __set_dm_plane_colorop_degamma(struct drm_plane_state *plane_state,return __set_colorop_in_tf_1d_curve (dc_plane_state, colorop_state); } +static int +__set_dm_plane_colorop_3x4_matrix (struct drm_plane_state *plane_state, +struct dc_plane_state *dc_plane_state, +struct drm_colorop *colorop) +{ +struct drm_colorop *old_colorop; +struct drm_colorop_state *colorop_state =NULL , *new_colorop_state; +struct drm_atomic_state *state = plane_state->state; +const struct drm_device *dev = colorop->dev; +const struct drm_property_blob *blob; +struct drm_color_ctm_3x4 *ctm =NULL ; +int i =0 ; + +/* 3x4 matrix */ + old_colorop = colorop; +for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) { +if (new_colorop_state->colorop == old_colorop && + new_colorop_state->colorop->type ==DRM_COLOROP_CTM_3X4 ) { + colorop_state = new_colorop_state; +break ; + } + } + +if (colorop_state && !colorop_state->bypass && colorop->type ==DRM_COLOROP_CTM_3X4 ) { +drm_dbg (dev,"3x4 matrix colorop with ID: %d\n" , colorop->base.id); + blob = colorop_state->data; +if (blob->length ==sizeof (struct drm_color_ctm_3x4 )) { + ctm = blob ? (struct drm_color_ctm_3x4 *) blob->data :NULL ; +__drm_ctm_3x4_to_dc_matrix (ctm, dc_plane_state->gamut_remap_matrix.matrix); + dc_plane_state->gamut_remap_matrix.enable_remap = true; + dc_plane_state->input_csc_color_matrix.enable_adjustment = false; + }else +drm_warn (dev,"blob->length (%ld) isn't equal to drm_color_ctm_3x4 (%ld)\n" , + blob->length,sizeof (struct drm_color_ctm_3x4 )); + } + +return 0 ; +} + static int __set_dm_plane_colorop_shaper(struct drm_plane_state *plane_state, struct dc_plane_state *dc_plane_state,
@@ -1411,6 +1450,17 @@ amdgpu_dm_plane_set_colorop_properties(struct drm_plane_state *plane_state,if (ret)return ret; +/* 3x4 matrix */ + colorop = colorop->next; +if (!colorop) { +drm_dbg (dev,"no 3x4 matrix colorop found\n" ); +return -EINVAL ; + } + + ret =__set_dm_plane_colorop_3x4_matrix (plane_state, dc_plane_state, colorop); +if (ret) +return ret; +/* 1D Curve & LUT - SHAPER TF & LUT */ colorop = colorop->next;if (!colorop) {
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +15 -0
@@ -69,6 +69,21 @@ int amdgpu_dm_initialize_default_pipeline(struct drm_plane *plane, struct drm_pr prev_op = op; +/* 3x4 matrix */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_ctm_3x4_init (dev, op, plane); +if (ret) +return ret; + +drm_colorop_set_next_property (prev_op, op); + + prev_op = op; +/* 1D curve - SHAPER TF */ op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL );if (!op) {
Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 41/42 drm/colorop: Add mutliplier type
In reply to Harry WentlandFrom: Alex Hung <[email protected]>
This introduces a new drm_colorop_type: DRM_COLOROP_MULTIPLIER.
It's a simple multiplier to all pixel values. The value is specified via a S31.32 fixed point provided via the "MULTIPLIER" property.
--- drivers/gpu/drm/drm_atomic.c | 3 +++ drivers/gpu/drm/drm_atomic_uapi.c | 4 ++++ drivers/gpu/drm/drm_colorop.c | 29 +++++++++++++++++++++++++++-- include/drm/drm_colorop.h | 16 ++++++++++++++++ include/uapi/drm/drm_mode.h | 1 + 5 files changed, 51 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic.c +3 -0
@@ -806,6 +806,9 @@ static void drm_atomic_colorop_print_state(struct drm_printer *p,case DRM_COLOROP_CTM_3X4 :drm_printf (p,"\tdata blob id=%d\n" , state->data ? state->data->base.id :0 );break ; +case DRM_COLOROP_MULTIPLIER : +drm_printf (p,"\tmultiplier=%u\n" , state->multiplier); +break ;default :break ; }
drivers/gpu/drm/drm_atomic_uapi.c +4 -0
@@ -727,6 +727,8 @@ static int drm_atomic_colorop_set_property(struct drm_colorop *colorop, state->bypass = val; }else if (property == colorop->curve_1d_type_property) { state->curve_1d_type = val; + }else if (property == colorop->multiplier_property) { + state->multiplier = val; }else if (property == colorop->data_property) {return drm_atomic_color_set_data_property (colorop, state, property, val);
@@ -752,6 +754,8 @@ drm_atomic_colorop_get_property(struct drm_colorop *colorop, *val = state->bypass; }else if (property == colorop->curve_1d_type_property) { *val = state->curve_1d_type; + }else if (property == colorop->multiplier_property) { + *val = state->multiplier; }else if (property == colorop->size_property) { *val = state->size; }else if (property == colorop->data_property) {
drivers/gpu/drm/drm_colorop.c +27 -2
@@ -35,7 +35,8 @@static const struct drm_prop_enum_list drm_colorop_type_enum_list[] = { {DRM_COLOROP_1D_CURVE ,"1D Curve" }, {DRM_COLOROP_1D_LUT ,"1D Curve Custom LUT" }, - {DRM_COLOROP_CTM_3X4 ,"3x4 Matrix" } + {DRM_COLOROP_CTM_3X4 ,"3x4 Matrix" }, + {DRM_COLOROP_MULTIPLIER ,"Multiplier" }, };static const char *const colorop_curve_1d_type_names[] = {
@@ -231,6 +232,29 @@ int drm_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop }EXPORT_SYMBOL (drm_colorop_ctm_3x4_init); +int drm_colorop_mult_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane) +{ +struct drm_property *prop; +int ret; + + ret =drm_colorop_init (dev, colorop, plane,DRM_COLOROP_MULTIPLIER ); +if (ret) +return ret; + + prop =drm_property_create_range (dev,DRM_MODE_PROP_ATOMIC ,"MULTIPLIER" ,0 ,U64_MAX ); +if (!prop) +return -ENOMEM ; + + colorop->multiplier_property = prop; +drm_object_attach_property (&colorop->base, colorop->multiplier_property,0 ); + +drm_colorop_reset (colorop); + +return 0 ; +} +EXPORT_SYMBOL (drm_colorop_mult_init); +static void __drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop,struct drm_colorop_state *state) {
@@ -333,7 +357,8 @@ EXPORT_SYMBOL(drm_colorop_reset);static const char *const colorop_type_name[] = { [DRM_COLOROP_1D_CURVE ] ="1D Curve" , [DRM_COLOROP_1D_LUT ] ="1D Curve Custom LUT" , - [DRM_COLOROP_CTM_3X4 ] ="3x4 Matrix" + [DRM_COLOROP_CTM_3X4 ] ="3x4 Matrix" , + [DRM_COLOROP_MULTIPLIER ] ="Multiplier" , };/**
include/drm/drm_colorop.h +16 -0
@@ -64,6 +64,13 @@ struct drm_colorop_state {*/ enum drm_colorop_curve_1d_type curve_1d_type; +/** +* @multiplier: +* +* Multiplier to 'gain' the plane. Format is S31.32 sign-magnitude. +*/ +uint64_t multiplier; +/** * @size: *
@@ -186,6 +193,13 @@ struct drm_colorop {*/ struct drm_property *curve_1d_type_property; +/** +* @multiplier_property: +* +* Multiplier property for plane gain +*/ +struct drm_property *multiplier_property; +/** * @size_property: *
@@ -246,6 +260,8 @@ int drm_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorop *co struct drm_plane *plane, uint32_t lut_size);int drm_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop,struct drm_plane *plane); +int drm_colorop_mult_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane);struct drm_colorop_state *drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop);
include/uapi/drm/drm_mode.h +1 -0
@@ -876,6 +876,7 @@ enum drm_colorop_type {DRM_COLOROP_1D_CURVE ,DRM_COLOROP_1D_LUT ,DRM_COLOROP_CTM_3X4 , + DRM_COLOROP_MULTIPLIER, };/**
Signature · 1 line
2.44.0
Re: [RFC PATCH v4 41/42] drm/colorop: Add mutliplier type
Quoted 22 lines · Harry Wentland
From: Alex Hung <[email protected]>
This introduces a new
drm_colorop_type:DRM_COLOROP_MULTIPLIER.It's a simple multiplier to all pixel values. The value is specified via a S31.32 fixed point provided via the "MULTIPLIER" property.
Signed-off-by Alex Hung <[email protected]>--- drivers/gpu/drm/drm_atomic.c | 3 +++ drivers/gpu/drm/drm_atomic_uapi.c | 4 ++++ drivers/gpu/drm/drm_colorop.c | 29 +++++++++++++++++++++++++++-- include/drm/drm_colorop.h | 16 ++++++++++++++++ include/uapi/drm/drm_mode.h | 1 + 5 files changed, 51 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_atomic.c +0
-0
drivers/gpu/drm/drm_atomic.c static void drm_atomic_colorop_print_state(struct drm_printer *p, · line 810
Quoted 5 lines
drivers/gpu/drm/drm_atomic.c +2
-0@@ -806,6 +806,9 @@ static void drm_atomic_colorop_print_state(struct drm_printer *p,case DRM_COLOROP_CTM_3X4 :drm_printf (p,"\tdata blob id=%d\n" , state->data ? state->data->base.id :0 );break ; +case DRM_COLOROP_MULTIPLIER : +drm_printf (p,"\tmultiplier=%u\n" , state->multiplier);
Compiler complains of unsigned int instead of llu.
Quoted 136 lines
drivers/gpu/drm/drm_atomic.c +1
-0+break ;default :break ; }drivers/gpu/drm/drm_atomic_uapi.c +4
-0@@ -727,6 +727,8 @@ static int drm_atomic_colorop_set_property(struct drm_colorop *colorop, state->bypass = val; }else if (property == colorop->curve_1d_type_property) { state->curve_1d_type = val; + }else if (property == colorop->multiplier_property) { + state->multiplier = val; }else if (property == colorop->data_property) {return drm_atomic_color_set_data_property (colorop, state, property, val);@@ -752,6 +754,8 @@ drm_atomic_colorop_get_property(struct drm_colorop *colorop, *val = state->bypass; }else if (property == colorop->curve_1d_type_property) { *val = state->curve_1d_type; + }else if (property == colorop->multiplier_property) { + *val = state->multiplier; }else if (property == colorop->size_property) { *val = state->size; }else if (property == colorop->data_property) {drivers/gpu/drm/drm_colorop.c +27
-2@@ -35,7 +35,8 @@static const struct drm_prop_enum_list drm_colorop_type_enum_list[] = { {DRM_COLOROP_1D_CURVE ,"1D Curve" }, {DRM_COLOROP_1D_LUT ,"1D Curve Custom LUT" }, - {DRM_COLOROP_CTM_3X4 ,"3x4 Matrix" } + {DRM_COLOROP_CTM_3X4 ,"3x4 Matrix" }, + {DRM_COLOROP_MULTIPLIER ,"Multiplier" }, };static const char *const colorop_curve_1d_type_names[] = {@@ -231,6 +232,29 @@ int drm_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop }EXPORT_SYMBOL (drm_colorop_ctm_3x4_init); +int drm_colorop_mult_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane) +{ +struct drm_property *prop; +int ret; + + ret =drm_colorop_init (dev, colorop, plane,DRM_COLOROP_MULTIPLIER ); +if (ret) +return ret; + + prop =drm_property_create_range (dev,DRM_MODE_PROP_ATOMIC ,"MULTIPLIER" ,0 ,U64_MAX ); +if (!prop) +return -ENOMEM ; + + colorop->multiplier_property = prop; +drm_object_attach_property (&colorop->base, colorop->multiplier_property,0 ); + +drm_colorop_reset (colorop); + +return 0 ; +} +EXPORT_SYMBOL (drm_colorop_mult_init); +static void __drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop,struct drm_colorop_state *state) {@@ -333,7 +357,8 @@ EXPORT_SYMBOL(drm_colorop_reset);static const char *const colorop_type_name[] = { [DRM_COLOROP_1D_CURVE ] ="1D Curve" , [DRM_COLOROP_1D_LUT ] ="1D Curve Custom LUT" , - [DRM_COLOROP_CTM_3X4 ] ="3x4 Matrix" + [DRM_COLOROP_CTM_3X4 ] ="3x4 Matrix" , + [DRM_COLOROP_MULTIPLIER ] ="Multiplier" , };/** include/drm/drm_colorop.h +16
-0@@ -64,6 +64,13 @@ struct drm_colorop_state {*/ enum drm_colorop_curve_1d_type curve_1d_type; +/** +* @multiplier: +* +* Multiplier to 'gain' the plane. Format is S31.32 sign-magnitude. +*/ +uint64_t multiplier; +/** * @size: * @@ -186,6 +193,13 @@ struct drm_colorop {*/ struct drm_property *curve_1d_type_property; +/** +* @multiplier_property: +* +* Multiplier property for plane gain +*/ +struct drm_property *multiplier_property; +/** * @size_property: * @@ -246,6 +260,8 @@ int drm_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorop *co struct drm_plane *plane, uint32_t lut_size);int drm_colorop_ctm_3x4_init (struct drm_device *dev,struct drm_colorop *colorop,struct drm_plane *plane); +int drm_colorop_mult_init (struct drm_device *dev,struct drm_colorop *colorop, +struct drm_plane *plane);struct drm_colorop_state *drm_atomic_helper_colorop_duplicate_state (struct drm_colorop *colorop);include/uapi/drm/drm_mode.h +1
-0@@ -876,6 +876,7 @@ enum drm_colorop_type {DRM_COLOROP_1D_CURVE ,DRM_COLOROP_1D_LUT ,DRM_COLOROP_CTM_3X4 , + DRM_COLOROP_MULTIPLIER, };/** Signature · 1 line
2.44.0
Harry Wentland
maintainerRFC PATCH v4 42/42 drm/amd/display: add multiplier colorop
In reply to Harry WentlandFrom: Alex Hung <[email protected]>
This adds support for a multiplier. This multiplier is programmed via the HDR Multiplier in DCN.
With this change the following IGT tests pass:kms_colorop --run plane-XR30-XR30-multiply_125 kms_colorop --run plane-XR30-XR30-multiply_inv_125
The color pipeline now consists of the following colorops:
1. 1D curve colorop
2. 3x4 CTM
3. Multiplier
4. 1D curve colorop
5. 1D LUT
6. 1D curve colorop
7. 1D LUT
--- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 40 +++++++++++++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 15 +++++++ 2 files changed, 55 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +40 -0
@@ -1251,6 +1251,35 @@ __set_dm_plane_colorop_3x4_matrix(struct drm_plane_state *plane_state,return 0 ; } +static int +__set_dm_plane_colorop_multiplier (struct drm_plane_state *plane_state, +struct dc_plane_state *dc_plane_state, +struct drm_colorop *colorop) +{ +struct drm_colorop *old_colorop; +struct drm_colorop_state *colorop_state =NULL , *new_colorop_state; +struct drm_atomic_state *state = plane_state->state; +const struct drm_device *dev = colorop->dev; +int i =0 ; + +/* Multiplier */ + old_colorop = colorop; +for_each_new_colorop_in_state (state, colorop, new_colorop_state, i) { +if (new_colorop_state->colorop == old_colorop && + new_colorop_state->colorop->type ==DRM_COLOROP_MULTIPLIER ) { + colorop_state = new_colorop_state; +break ; + } + } + +if (colorop_state && !colorop_state->bypass && colorop->type ==DRM_COLOROP_MULTIPLIER ) { +drm_dbg (dev,"Multiplier colorop with ID: %d\n" , colorop->base.id); + dc_plane_state->hdr_mult =amdgpu_dm_fixpt_from_s3132 (colorop_state->multiplier); + } + +return 0 ; +} + static int __set_dm_plane_colorop_shaper(struct drm_plane_state *plane_state, struct dc_plane_state *dc_plane_state,
@@ -1461,6 +1490,17 @@ amdgpu_dm_plane_set_colorop_properties(struct drm_plane_state *plane_state,if (ret)return ret; +/* Multiplier */ + colorop = colorop->next; +if (!colorop) { +drm_dbg (dev,"no multiplier colorop found\n" ); +return -EINVAL ; + } + + ret =__set_dm_plane_colorop_multiplier (plane_state, dc_plane_state, colorop); +if (ret) +return ret; +/* 1D Curve & LUT - SHAPER TF & LUT */ colorop = colorop->next;if (!colorop) {
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c +15 -0
@@ -84,6 +84,21 @@ int amdgpu_dm_initialize_default_pipeline(struct drm_plane *plane, struct drm_pr prev_op = op; +/* Multiplier */ + op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL ); +if (!op) { +DRM_ERROR ("KMS: Failed to allocate colorop\n" ); +return -ENOMEM ; + } + + ret =drm_colorop_mult_init (dev, op, plane); +if (ret) +return ret; + +drm_colorop_set_next_property (prev_op, op); + + prev_op = op; +/* 1D curve - SHAPER TF */ op =kzalloc (sizeof (struct drm_colorop ),GFP_KERNEL );if (!op) {
Signature · 1 line
2.44.0
Quoted 39 lines · Harry Wentland
This is an RFC set for a color pipeline API, along with a sample implementation in VKMS. All the key API bits are here. VKMS now supports two named transfer function colorops and two matrix colorops. We have IGT tests that check all four of these colorops with a pixel-by-pixel comparison that checks that these colorops do what we expect them to do with a +/- 1 8 bpc code point margin.
The big new change with v4 is the addition of an amdgpu color pipeline, for all AMD GPUs with DCN 3 and newer. Amdgpu now support the following:
1. 1D Curve EOTF
2. 3x4 CTM
3. Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 1D Curve EOTF
7. 1D LUTThe supported curves for the 1D Curve type are:
- sRGB EOTF and its inverse
- PQ EOTF, scaled to [0.0, 125.0] and its inverse
- BT.2020/BT.709 OETF and its inverseNote that the 1st and 5th colorops take the EOTF or Inverse OETF while the 3rd colorop takes the Inverse EOTF or OETF.
We are working on two more ops for amdgpu, the HDR multiplier and the 3DLUT, which will give us this:
1. 1D Curve EOTF
2. 3x4 CTM
3. HDR Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 3D LUT
7. 1D Curve EOTF
8. 1D LUT
Quoted 7 lines
This, essentially mirrors the color pipeline used by gamescope
and presented by Melissa Wen, with the exception of the DEGAM
LUT, which is not currently used. See
[1] https://indico.freedesktop.org/event/4/contributions/186/attachments/138/218/xdc2023-TheRainbowTreasureMap-MelissaWen.pdfAfter this we'd like to also add the following ops:
- Scaler (Informational only)
Why informational only? Having NEAREST and in general custom taps should be possible on AMDGPU right?
We don't have to solve this now, but I just want to make sure that we aren't locking this to info only.
Thanks
- Joshie 🐸✨
Quoted 202 lines
- Color Encoding, to replace drm_plane's
COLOR_ENCODING
- Color Range, to replace drm_plane'sCOLOR_RANGEThis patchset is grouped as follows:
- Patches 1-3: couple general patches/fixes
- Patches 4-7: introduce kunit to VKMS
- Patch 7: description of motivation and details behind the Color Pipeline API. If you're reading nothing else but are interested in the topic I highly recommend you take a look at this.
- Patches 7-27: DRM core and VKMS changes for color pipeline API
- Patches 28-40: DRM core and amdgpu changes for color pipeline APIVKMS patches could still be improved in a few ways, though the payoff might be limited and I would rather focus on other work at the moment. The most obvious thing to improve would be to eliminate the hard-coded LUTs for identity, and sRGB, and replace them with fixed-point math instead.
There are plenty of things that I would like to see here but haven't had a chance to look at. These will (hopefully) be addressed in future iterations, either in VKMS or amdgpu:
- Clear documentation for eachdrm_colorop_type
- Add custom LUT colorops to VKMS
- Add pre-blending 3DLUT
- How to support HW which can't bypass entire pipeline?
- Add ability to create colorops that don't have BYPASS
- Can we do a LOAD / COMMIT model for LUTs (and other properties)?
- read-only scaling colorop which defines scaling taps and position
- read-only color format colorop to define supported color formats for a pipeline
- named matrices, for things like converting YUV to RGBIGT tests can be found at
https://gitlab.freedesktop.org/hwentland/igt-gpu-tools/-/merge_requests/1IGT patches are also being sent to the igt-dev mailing list.
If you prefer a gitlab MR for review you can find it at
https://gitlab.freedesktop.org/hwentland/linux/-/merge_requests/5v4:
- Add amdgpu color pipeline (WIP)
- Don't block setting of deprecated properties, instead pass client cap to atomic check so drivers can ignore these props
- Drop IOCTL definitions (Pekka)
- Use enum property for colorop TYPE (Pekka)
- A few cleanups to the docs (Pekka)
- Rework the TYPE enum to name relation to avoid code duplication (Pekka)
- Add missing function declarations (Chaitanya Kumar Borah)
- Allow setting of NEXT property to NULL in _set_ function (Chaitanya Kumar Borah)
- Add helper for creation of pipelinedrm_planeproperty (Pekka)
- Always create Bypass pipeline (Pekka)
- A bunch of changes to VKMS kunit tests (Pekka)
- Fix index in CTM doc (Pekka)v3:
- Abandon IOCTLs and discover colorops as clients iterate the pipeline
- Remove need for libdrm
- Addcolor_pipelineclient cap and make mutually exclusive withCOLOR_RANGEandCOLOR_ENCODINGproperties
- add CTM colorop to VKMS
- Use include way for kunit testing static functions (Arthur)
- Make TYPE a range property
- Move enumdrm_colorop_typeto uapi header
- and a bunch of smaller bits that are highlighted in the relevant commit descriptionv2:
- Rebased on drm-misc-next
- Introduce a VKMS Kunit so we can test LUT functionality invkms_composer
- Incorporate feedback incolor_pipeline.rstdoc
- Add support for sRGB inverse EOTF
- Add 2nd enumerated TF colorop to VKMS
- Fix LUTs and some issues with applying LUTs in VKMSCc Ville Syrjala <[email protected]>Cc Pekka Paalanen <[email protected]>Cc Simon Ser <[email protected]>Cc Harry Wentland <[email protected]>Cc Melissa Wen <[email protected]>Cc Jonas Ådahl <[email protected]>Cc Sebastian Wick <[email protected]>Cc Shashank Sharma <[email protected]>Cc Alexander Goins <[email protected]>Cc Joshua Ashton <[email protected]>Cc Michel Dänzer <[email protected]>Cc Aleix Pol <[email protected]>Cc Xaver Hugl <[email protected]>Cc Victoria Brekenfeld <[email protected]>Cc Sima <[email protected]>Cc Uma Shankar <[email protected]>Cc Naseer Ahmed <[email protected]>Cc Christopher Braga <[email protected]>Cc Abhinav Kumar <[email protected]>Cc Arthur Grillo <[email protected]>Cc Hector Martin <[email protected]>Cc Liviu Dudau <[email protected]>Cc Sasha McIntosh <[email protected]>Cc Chaitanya Kumar Borah <[email protected]>Alex Hung (10):
drm/colorop: define a new macrofor_each_new_colorop_in_statedrm/amd/display: Skip color pipeline initialization for cursor plane drm/amd/display: Add support for sRGB EOTF in DEGAM block drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block drm/amd/display: Add support for sRGB EOTF in BLND block drm/colorop: Add 1D Curve Custom LUT type
drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT drm/amd/display: add 3x4 matrix colorop
drm/colorop: Add mutliplier type
drm/amd/display: add multiplier coloropHarry Wentland (32):
drm: Don't treat 0 as -1 indrm_fixp2int_ceil
drm: Add helper for conversion from signed-magnitude
drm: Correctly round forfixp2int_round
drm/vkms: Round fixp2int conversion inlerp_u16
drm/vkms: Create separateKconfigfile for VKMS
drm/vkms: Add kunit tests for VKMS LUT handling
drm/vkms: Avoid reading beyond LUT array
drm/doc/rfc: Describe why prescriptive color pipeline is needed drm/colorop: Introduce newdrm_coloropmode object drm/colorop: Add TYPE property
drm/colorop: Add 1D Curve subtype
drm/colorop: Add BYPASS property
drm/colorop: Add NEXT property
drm/colorop: Add atomic state print fordrm_coloropdrm/plane: Add COLOR PIPELINE property
drm/colorop: Add NEXT to colorop state print
drm/vkms: Add enumerated 1D curve colorop
drm/vkms: Add kunit tests for linear and sRGB LUTs drm/colorop: IntroduceDRM_CLIENT_CAP_PLANE_COLOR_PIPELINEdrm/colorop: Add 3x4 CTM type
drm/vkms: Pullapply_coloropout ofpre_blend_color_transformdrm/vkms: Use s32 for internal color pipeline precision drm/vkms: add 3x4 matrix in color pipeline
drm/tests: Add a few tests arounddrm_fixed.h
drm/vkms: Add tests for CTM handling
drm/colorop: passplane_color_pipelineclient cap to atomic check drm/amd/display: Ignore deprecated props whenplane_color_pipelineset drm/amd/display: Add bypass COLOR PIPELINE
drm/colorop: Add PQ 125 EOTF and its inverse drm/amd/display: Enable support for PQ 125 EOTF and Inverse drm/colorop: add BT2020/BT709 OETF and Inverse OETF drm/amd/display: Add support for BT.709 and BT.2020 TFsDocumentation/gpu/rfc/color_pipeline.rst | 360 ++++++++ drivers/gpu/drm/Kconfig | 14 +- drivers/gpu/drm/Makefile | 1 + .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 352 ++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 160 ++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 36 + .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 32 + drivers/gpu/drm/drm_atomic.c | 161 +++- drivers/gpu/drm/drm_atomic_helper.c | 12 + drivers/gpu/drm/drm_atomic_state_helper.c | 5 + drivers/gpu/drm/drm_atomic_uapi.c | 158 ++++ drivers/gpu/drm/drm_colorop.c | 411 +++++++++ drivers/gpu/drm/drm_ioctl.c | 7 + drivers/gpu/drm/drm_mode_config.c | 7 + drivers/gpu/drm/drm_plane.c | 52 ++ drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_fixp_test.c | 69 ++ drivers/gpu/drm/vkms/Kconfig | 20 + drivers/gpu/drm/vkms/Makefile | 4 +- drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 449 ++++++++++ drivers/gpu/drm/vkms/vkms_colorop.c | 100 +++ drivers/gpu/drm/vkms/vkms_composer.c | 135 ++- drivers/gpu/drm/vkms/vkms_drv.h | 8 + drivers/gpu/drm/vkms/vkms_luts.c | 802 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 2 + include/drm/drm_atomic.h | 122 +++ include/drm/drm_atomic_uapi.h | 3 + include/drm/drm_colorop.h | 301 +++++++ include/drm/drm_file.h | 7 + include/drm/drm_fixed.h | 35 +- include/drm/drm_mode_config.h | 18 + include/drm/drm_plane.h | 13 + include/uapi/drm/drm.h | 16 + include/uapi/drm/drm_mode.h | 14 + 38 files changed, 3882 insertions(+), 30 deletions(-)create mode 100644
Documentation/gpu/rfc/color_pipeline.rstcreate mode 100644drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.ccreate mode 100644drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.hcreate mode 100644drivers/gpu/drm/drm_colorop.c
create mode 100644drivers/gpu/drm/tests/drm_fixp_test.c
create mode 100644drivers/gpu/drm/vkms/Kconfig
create mode 100644drivers/gpu/drm/vkms/tests/.kunitconfigcreate mode 100644drivers/gpu/drm/vkms/tests/vkms_color_tests.ccreate mode 100644drivers/gpu/drm/vkms/vkms_colorop.c
create mode 100644drivers/gpu/drm/vkms/vkms_luts.c
create mode 100644drivers/gpu/drm/vkms/vkms_luts.h
create mode 100644include/drm/drm_colorop.h--
2.44.0
Harry Wentland
maintainerQuoted 47 lines · Joshua Ashton
Quoted 44 lines · Harry Wentland
This is an RFC set for a color pipeline API, along with a sample implementation in VKMS. All the key API bits are here. VKMS now supports two named transfer function colorops and two matrix colorops. We have IGT tests that check all four of these colorops with a pixel-by-pixel comparison that checks that these colorops do what we expect them to do with a +/- 1 8 bpc code point margin.
The big new change with v4 is the addition of an amdgpu color pipeline, for all AMD GPUs with DCN 3 and newer. Amdgpu now support the following:
1. 1D Curve EOTF
2. 3x4 CTM
3. Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 1D Curve EOTF
7. 1D LUTThe supported curves for the 1D Curve type are:
- sRGB EOTF and its inverse
- PQ EOTF, scaled to [0.0, 125.0] and its inverse
- BT.2020/BT.709 OETF and its inverseNote that the 1st and 5th colorops take the EOTF or Inverse OETF while the 3rd colorop takes the Inverse EOTF or OETF.
We are working on two more ops for amdgpu, the HDR multiplier and the 3DLUT, which will give us this:
1. 1D Curve EOTF
2. 3x4 CTM
3. HDR Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 3D LUT
7. 1D Curve EOTF
8. 1D LUTThis, essentially mirrors the color pipeline used by gamescope
and presented by Melissa Wen, with the exception of the DEGAM
LUT, which is not currently used. See
[1] https://indico.freedesktop.org/event/4/contributions/186/attachments/138/218/xdc2023-TheRainbowTreasureMap-MelissaWen.pdf
Quoted 7 lines
Quoted 2 lines
After this we'd like to also add the following ops:
- Scaler (Informational only)Why informational only? Having NEAREST and in general custom taps should be possible on AMDGPU right?
We don't have to solve this now, but I just want to make sure that we aren't locking this to info only.
No, this isn't locking it to information only. We could allow for NEAREST or even custom taps in the future. Just don't want to open that debate now if we don't have a good reason to.
Harry
Quoted 207 lines
Thanks
- Joshie 🐸✨
Quoted 202 lines
- Color Encoding, to replace drm_plane's
COLOR_ENCODING
- Color Range, to replace drm_plane'sCOLOR_RANGEThis patchset is grouped as follows:
- Patches 1-3: couple general patches/fixes
- Patches 4-7: introduce kunit to VKMS
- Patch 7: description of motivation and details behind the Color Pipeline API. If you're reading nothing else but are interested in the topic I highly recommend you take a look at this.
- Patches 7-27: DRM core and VKMS changes for color pipeline API
- Patches 28-40: DRM core and amdgpu changes for color pipeline APIVKMS patches could still be improved in a few ways, though the payoff might be limited and I would rather focus on other work at the moment. The most obvious thing to improve would be to eliminate the hard-coded LUTs for identity, and sRGB, and replace them with fixed-point math instead.
There are plenty of things that I would like to see here but haven't had a chance to look at. These will (hopefully) be addressed in future iterations, either in VKMS or amdgpu:
- Clear documentation for eachdrm_colorop_type
- Add custom LUT colorops to VKMS
- Add pre-blending 3DLUT
- How to support HW which can't bypass entire pipeline?
- Add ability to create colorops that don't have BYPASS
- Can we do a LOAD / COMMIT model for LUTs (and other properties)?
- read-only scaling colorop which defines scaling taps and position
- read-only color format colorop to define supported color formats for a pipeline
- named matrices, for things like converting YUV to RGBIGT tests can be found at
https://gitlab.freedesktop.org/hwentland/igt-gpu-tools/-/merge_requests/1IGT patches are also being sent to the igt-dev mailing list.
If you prefer a gitlab MR for review you can find it at
https://gitlab.freedesktop.org/hwentland/linux/-/merge_requests/5v4:
- Add amdgpu color pipeline (WIP)
- Don't block setting of deprecated properties, instead pass client cap to atomic check so drivers can ignore these props
- Drop IOCTL definitions (Pekka)
- Use enum property for colorop TYPE (Pekka)
- A few cleanups to the docs (Pekka)
- Rework the TYPE enum to name relation to avoid code duplication (Pekka)
- Add missing function declarations (Chaitanya Kumar Borah)
- Allow setting of NEXT property to NULL in _set_ function (Chaitanya Kumar Borah)
- Add helper for creation of pipelinedrm_planeproperty (Pekka)
- Always create Bypass pipeline (Pekka)
- A bunch of changes to VKMS kunit tests (Pekka)
- Fix index in CTM doc (Pekka)v3:
- Abandon IOCTLs and discover colorops as clients iterate the pipeline
- Remove need for libdrm
- Addcolor_pipelineclient cap and make mutually exclusive withCOLOR_RANGEandCOLOR_ENCODINGproperties
- add CTM colorop to VKMS
- Use include way for kunit testing static functions (Arthur)
- Make TYPE a range property
- Move enumdrm_colorop_typeto uapi header
- and a bunch of smaller bits that are highlighted in the relevant commit descriptionv2:
- Rebased on drm-misc-next
- Introduce a VKMS Kunit so we can test LUT functionality invkms_composer
- Incorporate feedback incolor_pipeline.rstdoc
- Add support for sRGB inverse EOTF
- Add 2nd enumerated TF colorop to VKMS
- Fix LUTs and some issues with applying LUTs in VKMSCc Ville Syrjala <[email protected]>Cc Pekka Paalanen <[email protected]>Cc Simon Ser <[email protected]>Cc Harry Wentland <[email protected]>Cc Melissa Wen <[email protected]>Cc Jonas Ådahl <[email protected]>Cc Sebastian Wick <[email protected]>Cc Shashank Sharma <[email protected]>Cc Alexander Goins <[email protected]>Cc Joshua Ashton <[email protected]>Cc Michel Dänzer <[email protected]>Cc Aleix Pol <[email protected]>Cc Xaver Hugl <[email protected]>Cc Victoria Brekenfeld <[email protected]>Cc Sima <[email protected]>Cc Uma Shankar <[email protected]>Cc Naseer Ahmed <[email protected]>Cc Christopher Braga <[email protected]>Cc Abhinav Kumar <[email protected]>Cc Arthur Grillo <[email protected]>Cc Hector Martin <[email protected]>Cc Liviu Dudau <[email protected]>Cc Sasha McIntosh <[email protected]>Cc Chaitanya Kumar Borah <[email protected]>Alex Hung (10):
drm/colorop: define a new macrofor_each_new_colorop_in_statedrm/amd/display: Skip color pipeline initialization for cursor plane drm/amd/display: Add support for sRGB EOTF in DEGAM block drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block drm/amd/display: Add support for sRGB EOTF in BLND block drm/colorop: Add 1D Curve Custom LUT type
drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT drm/amd/display: add 3x4 matrix colorop
drm/colorop: Add mutliplier type
drm/amd/display: add multiplier coloropHarry Wentland (32):
drm: Don't treat 0 as -1 indrm_fixp2int_ceil
drm: Add helper for conversion from signed-magnitude
drm: Correctly round forfixp2int_round
drm/vkms: Round fixp2int conversion inlerp_u16
drm/vkms: Create separateKconfigfile for VKMS
drm/vkms: Add kunit tests for VKMS LUT handling
drm/vkms: Avoid reading beyond LUT array
drm/doc/rfc: Describe why prescriptive color pipeline is needed drm/colorop: Introduce newdrm_coloropmode object drm/colorop: Add TYPE property
drm/colorop: Add 1D Curve subtype
drm/colorop: Add BYPASS property
drm/colorop: Add NEXT property
drm/colorop: Add atomic state print fordrm_coloropdrm/plane: Add COLOR PIPELINE property
drm/colorop: Add NEXT to colorop state print
drm/vkms: Add enumerated 1D curve colorop
drm/vkms: Add kunit tests for linear and sRGB LUTs drm/colorop: IntroduceDRM_CLIENT_CAP_PLANE_COLOR_PIPELINEdrm/colorop: Add 3x4 CTM type
drm/vkms: Pullapply_coloropout ofpre_blend_color_transformdrm/vkms: Use s32 for internal color pipeline precision drm/vkms: add 3x4 matrix in color pipeline
drm/tests: Add a few tests arounddrm_fixed.h
drm/vkms: Add tests for CTM handling
drm/colorop: passplane_color_pipelineclient cap to atomic check drm/amd/display: Ignore deprecated props whenplane_color_pipelineset drm/amd/display: Add bypass COLOR PIPELINE
drm/colorop: Add PQ 125 EOTF and its inverse drm/amd/display: Enable support for PQ 125 EOTF and Inverse drm/colorop: add BT2020/BT709 OETF and Inverse OETF drm/amd/display: Add support for BT.709 and BT.2020 TFsDocumentation/gpu/rfc/color_pipeline.rst | 360 ++++++++ drivers/gpu/drm/Kconfig | 14 +- drivers/gpu/drm/Makefile | 1 + .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +-
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c| 4 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 352 ++++++++.../amd/display/amdgpu_dm/amdgpu_dm_colorop.c| 160 ++++.../amd/display/amdgpu_dm/amdgpu_dm_colorop.h| 36 + .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 32 + drivers/gpu/drm/drm_atomic.c | 161 +++- drivers/gpu/drm/drm_atomic_helper.c | 12 + drivers/gpu/drm/drm_atomic_state_helper.c | 5 + drivers/gpu/drm/drm_atomic_uapi.c | 158 ++++ drivers/gpu/drm/drm_colorop.c | 411 +++++++++ drivers/gpu/drm/drm_ioctl.c | 7 + drivers/gpu/drm/drm_mode_config.c | 7 + drivers/gpu/drm/drm_plane.c | 52 ++ drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_fixp_test.c | 69 ++ drivers/gpu/drm/vkms/Kconfig | 20 + drivers/gpu/drm/vkms/Makefile | 4 +- drivers/gpu/drm/vkms/tests/.kunitconfig | 4 +drivers/gpu/drm/vkms/tests/vkms_color_tests.c| 449 ++++++++++ drivers/gpu/drm/vkms/vkms_colorop.c | 100 +++ drivers/gpu/drm/vkms/vkms_composer.c | 135 ++- drivers/gpu/drm/vkms/vkms_drv.h | 8 + drivers/gpu/drm/vkms/vkms_luts.c | 802 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 2 + include/drm/drm_atomic.h | 122 +++ include/drm/drm_atomic_uapi.h | 3 + include/drm/drm_colorop.h | 301 +++++++ include/drm/drm_file.h | 7 + include/drm/drm_fixed.h | 35 +- include/drm/drm_mode_config.h | 18 + include/drm/drm_plane.h | 13 + include/uapi/drm/drm.h | 16 + include/uapi/drm/drm_mode.h | 14 +38 files changed, 3882 insertions(+), 30 deletions(-)create mode 100644
Documentation/gpu/rfc/color_pipeline.rstcreate mode 100644drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.ccreate mode 100644drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.hcreate mode 100644drivers/gpu/drm/drm_colorop.c
create mode 100644drivers/gpu/drm/tests/drm_fixp_test.c
create mode 100644drivers/gpu/drm/vkms/Kconfig
create mode 100644drivers/gpu/drm/vkms/tests/.kunitconfigcreate mode 100644drivers/gpu/drm/vkms/tests/vkms_color_tests.ccreate mode 100644drivers/gpu/drm/vkms/vkms_colorop.c
create mode 100644drivers/gpu/drm/vkms/vkms_luts.c
create mode 100644drivers/gpu/drm/vkms/vkms_luts.h
create mode 100644include/drm/drm_colorop.hSignature · 1 line
2.44.0
Quoted 6 lines · Harry Wentland
This is an RFC set for a color pipeline API, along with a sample implementation in VKMS. All the key API bits are here. VKMS now supports two named transfer function colorops and two matrix colorops. We have IGT tests that check all four of these colorops with a pixel-by-pixel comparison that checks that these colorops do what we expect them to do with a +/- 1 8 bpc code point margin.
So vkms is definitely great to make sure the igts are generic enough and somewhat useful, but ... does steam run on vkms too? I think that would be a really good test to show that the api we have here is actually useful for compositors in a cross-driver way, and not just a neat idea that doesn't survive harsh reality.
And yes I realize that's probably going to be a bunch of work, but I feel like the color pipeline discussion has dragged around enough in hypotheticals and concerns that I think it would really help a lot.
Thoughts?
-Sima
Quoted 242 lines
The big new change with v4 is the addition of an amdgpu color pipeline, for all AMD GPUs with DCN 3 and newer. Amdgpu now support the following:
1. 1D Curve EOTF
2. 3x4 CTM
3. Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 1D Curve EOTF
7. 1D LUTThe supported curves for the 1D Curve type are:
- sRGB EOTF and its inverse
- PQ EOTF, scaled to [0.0, 125.0] and its inverse
- BT.2020/BT.709 OETF and its inverseNote that the 1st and 5th colorops take the EOTF or Inverse OETF while the 3rd colorop takes the Inverse EOTF or OETF.
We are working on two more ops for amdgpu, the HDR multiplier and the 3DLUT, which will give us this:
1. 1D Curve EOTF
2. 3x4 CTM
3. HDR Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 3D LUT
7. 1D Curve EOTF
8. 1D LUTThis, essentially mirrors the color pipeline used by gamescope
and presented by Melissa Wen, with the exception of the DEGAM
LUT, which is not currently used. See
[1] https://indico.freedesktop.org/event/4/contributions/186/attachments/138/218/xdc2023-TheRainbowTreasureMap-MelissaWen.pdfAfter this we'd like to also add the following ops:
- Scaler (Informational only)
- Color Encoding, to replace drm_plane'sCOLOR_ENCODING
- Color Range, to replace drm_plane'sCOLOR_RANGEThis patchset is grouped as follows:
- Patches 1-3: couple general patches/fixes
- Patches 4-7: introduce kunit to VKMS
- Patch 7: description of motivation and details behind the Color Pipeline API. If you're reading nothing else but are interested in the topic I highly recommend you take a look at this.
- Patches 7-27: DRM core and VKMS changes for color pipeline API
- Patches 28-40: DRM core and amdgpu changes for color pipeline APIVKMS patches could still be improved in a few ways, though the payoff might be limited and I would rather focus on other work at the moment. The most obvious thing to improve would be to eliminate the hard-coded LUTs for identity, and sRGB, and replace them with fixed-point math instead.
There are plenty of things that I would like to see here but haven't had a chance to look at. These will (hopefully) be addressed in future iterations, either in VKMS or amdgpu:
- Clear documentation for eachdrm_colorop_type
- Add custom LUT colorops to VKMS
- Add pre-blending 3DLUT
- How to support HW which can't bypass entire pipeline?
- Add ability to create colorops that don't have BYPASS
- Can we do a LOAD / COMMIT model for LUTs (and other properties)?
- read-only scaling colorop which defines scaling taps and position
- read-only color format colorop to define supported color formats for a pipeline
- named matrices, for things like converting YUV to RGBIGT tests can be found at
https://gitlab.freedesktop.org/hwentland/igt-gpu-tools/-/merge_requests/1IGT patches are also being sent to the igt-dev mailing list.
If you prefer a gitlab MR for review you can find it at
https://gitlab.freedesktop.org/hwentland/linux/-/merge_requests/5v4:
- Add amdgpu color pipeline (WIP)
- Don't block setting of deprecated properties, instead pass client cap to atomic check so drivers can ignore these props
- Drop IOCTL definitions (Pekka)
- Use enum property for colorop TYPE (Pekka)
- A few cleanups to the docs (Pekka)
- Rework the TYPE enum to name relation to avoid code duplication (Pekka)
- Add missing function declarations (Chaitanya Kumar Borah)
- Allow setting of NEXT property to NULL in _set_ function (Chaitanya Kumar Borah)
- Add helper for creation of pipelinedrm_planeproperty (Pekka)
- Always create Bypass pipeline (Pekka)
- A bunch of changes to VKMS kunit tests (Pekka)
- Fix index in CTM doc (Pekka)v3:
- Abandon IOCTLs and discover colorops as clients iterate the pipeline
- Remove need for libdrm
- Addcolor_pipelineclient cap and make mutually exclusive withCOLOR_RANGEandCOLOR_ENCODINGproperties
- add CTM colorop to VKMS
- Use include way for kunit testing static functions (Arthur)
- Make TYPE a range property
- Move enumdrm_colorop_typeto uapi header
- and a bunch of smaller bits that are highlighted in the relevant commit descriptionv2:
- Rebased on drm-misc-next
- Introduce a VKMS Kunit so we can test LUT functionality invkms_composer
- Incorporate feedback incolor_pipeline.rstdoc
- Add support for sRGB inverse EOTF
- Add 2nd enumerated TF colorop to VKMS
- Fix LUTs and some issues with applying LUTs in VKMSCc Ville Syrjala <[email protected]>Cc Pekka Paalanen <[email protected]>Cc Simon Ser <[email protected]>Cc Harry Wentland <[email protected]>Cc Melissa Wen <[email protected]>Cc Jonas Ådahl <[email protected]>Cc Sebastian Wick <[email protected]>Cc Shashank Sharma <[email protected]>Cc Alexander Goins <[email protected]>Cc Joshua Ashton <[email protected]>Cc Michel Dänzer <[email protected]>Cc Aleix Pol <[email protected]>Cc Xaver Hugl <[email protected]>Cc Victoria Brekenfeld <[email protected]>Cc Sima <[email protected]>Cc Uma Shankar <[email protected]>Cc Naseer Ahmed <[email protected]>Cc Christopher Braga <[email protected]>Cc Abhinav Kumar <[email protected]>Cc Arthur Grillo <[email protected]>Cc Hector Martin <[email protected]>Cc Liviu Dudau <[email protected]>Cc Sasha McIntosh <[email protected]>Cc Chaitanya Kumar Borah <[email protected]>Alex Hung (10):
drm/colorop: define a new macrofor_each_new_colorop_in_statedrm/amd/display: Skip color pipeline initialization for cursor plane drm/amd/display: Add support for sRGB EOTF in DEGAM block drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block drm/amd/display: Add support for sRGB EOTF in BLND block drm/colorop: Add 1D Curve Custom LUT type
drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT drm/amd/display: add 3x4 matrix colorop
drm/colorop: Add mutliplier type
drm/amd/display: add multiplier coloropHarry Wentland (32):
drm: Don't treat 0 as -1 indrm_fixp2int_ceil
drm: Add helper for conversion from signed-magnitude
drm: Correctly round forfixp2int_round
drm/vkms: Round fixp2int conversion inlerp_u16
drm/vkms: Create separateKconfigfile for VKMS
drm/vkms: Add kunit tests for VKMS LUT handling
drm/vkms: Avoid reading beyond LUT array
drm/doc/rfc: Describe why prescriptive color pipeline is needed drm/colorop: Introduce newdrm_coloropmode object drm/colorop: Add TYPE property
drm/colorop: Add 1D Curve subtype
drm/colorop: Add BYPASS property
drm/colorop: Add NEXT property
drm/colorop: Add atomic state print fordrm_coloropdrm/plane: Add COLOR PIPELINE property
drm/colorop: Add NEXT to colorop state print
drm/vkms: Add enumerated 1D curve colorop
drm/vkms: Add kunit tests for linear and sRGB LUTs drm/colorop: IntroduceDRM_CLIENT_CAP_PLANE_COLOR_PIPELINEdrm/colorop: Add 3x4 CTM type
drm/vkms: Pullapply_coloropout ofpre_blend_color_transformdrm/vkms: Use s32 for internal color pipeline precision drm/vkms: add 3x4 matrix in color pipeline
drm/tests: Add a few tests arounddrm_fixed.h
drm/vkms: Add tests for CTM handling
drm/colorop: passplane_color_pipelineclient cap to atomic check drm/amd/display: Ignore deprecated props whenplane_color_pipelineset drm/amd/display: Add bypass COLOR PIPELINE
drm/colorop: Add PQ 125 EOTF and its inverse drm/amd/display: Enable support for PQ 125 EOTF and Inverse drm/colorop: add BT2020/BT709 OETF and Inverse OETF drm/amd/display: Add support for BT.709 and BT.2020 TFsDocumentation/gpu/rfc/color_pipeline.rst | 360 ++++++++ drivers/gpu/drm/Kconfig | 14 +- drivers/gpu/drm/Makefile | 1 + .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 352 ++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 160 ++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 36 + .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 32 + drivers/gpu/drm/drm_atomic.c | 161 +++- drivers/gpu/drm/drm_atomic_helper.c | 12 + drivers/gpu/drm/drm_atomic_state_helper.c | 5 + drivers/gpu/drm/drm_atomic_uapi.c | 158 ++++ drivers/gpu/drm/drm_colorop.c | 411 +++++++++ drivers/gpu/drm/drm_ioctl.c | 7 + drivers/gpu/drm/drm_mode_config.c | 7 + drivers/gpu/drm/drm_plane.c | 52 ++ drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_fixp_test.c | 69 ++ drivers/gpu/drm/vkms/Kconfig | 20 + drivers/gpu/drm/vkms/Makefile | 4 +- drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 449 ++++++++++ drivers/gpu/drm/vkms/vkms_colorop.c | 100 +++ drivers/gpu/drm/vkms/vkms_composer.c | 135 ++- drivers/gpu/drm/vkms/vkms_drv.h | 8 + drivers/gpu/drm/vkms/vkms_luts.c | 802 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 2 + include/drm/drm_atomic.h | 122 +++ include/drm/drm_atomic_uapi.h | 3 + include/drm/drm_colorop.h | 301 +++++++ include/drm/drm_file.h | 7 + include/drm/drm_fixed.h | 35 +- include/drm/drm_mode_config.h | 18 + include/drm/drm_plane.h | 13 + include/uapi/drm/drm.h | 16 + include/uapi/drm/drm_mode.h | 14 + 38 files changed, 3882 insertions(+), 30 deletions(-) create mode 100644 Documentation/gpu/rfc/color_pipeline.rst create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h create mode 100644 drivers/gpu/drm/drm_colorop.c create mode 100644 drivers/gpu/drm/tests/drm_fixp_test.c create mode 100644 drivers/gpu/drm/vkms/Kconfig create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/vkms_color_tests.c create mode 100644 drivers/gpu/drm/vkms/vkms_colorop.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.h create mode 100644 include/drm/drm_colorop.h--
2.44.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 14 lines · Daniel Vetter
Quoted 6 lines · Harry Wentland
This is an RFC set for a color pipeline API, along with a sample implementation in VKMS. All the key API bits are here. VKMS now supports two named transfer function colorops and two matrix colorops. We have IGT tests that check all four of these colorops with a pixel-by-pixel comparison that checks that these colorops do what we expect them to do with a +/- 1 8 bpc code point margin.
So vkms is definitely great to make sure the igts are generic enough and somewhat useful, but ... does steam run on vkms too? I think that would be a really good test to show that the api we have here is actually useful for compositors in a cross-driver way, and not just a neat idea that doesn't survive harsh reality.
Quoted 3 lines
And yes I realize that's probably going to be a bunch of work, but I feel like the color pipeline discussion has dragged around enough in hypotheticals and concerns that I think it would really help a lot.
I don't think we have ever tested Steam/Gamescope on vkms.
The last time I tried stuff there, there was all the problems with the ttm page table tail thing for virtio stuff that made using Steam games + Gamescope unfeasable because Vulkan + bindless, but I have heard those are solved now?
I will have to try it again at the weekend and see where it's at.
I am willing to place my bets that some part of the stack will fall over relating to modifiers somehow... =P
But yes, testing there would be good too, as we have the full Steam Deck OLED HDR color pipeline implemented in shader-based composition validated as being 1:1 on a suite of HDR and SDR test images. (That *will* definitely rely on 3D LUTs being tetrahedrally interpolated though)
I'll have a look at this at the weekend and also see about getting a Gamescope branch that uses the new wip colorop stuff.
- Joshie 🐸✨
Quoted 247 lines
Thoughts?
-SimaQuoted 242 lines
The big new change with v4 is the addition of an amdgpu color pipeline, for all AMD GPUs with DCN 3 and newer. Amdgpu now support the following:
1. 1D Curve EOTF
2. 3x4 CTM
3. Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 1D Curve EOTF
7. 1D LUTThe supported curves for the 1D Curve type are:
- sRGB EOTF and its inverse
- PQ EOTF, scaled to [0.0, 125.0] and its inverse
- BT.2020/BT.709 OETF and its inverseNote that the 1st and 5th colorops take the EOTF or Inverse OETF while the 3rd colorop takes the Inverse EOTF or OETF.
We are working on two more ops for amdgpu, the HDR multiplier and the 3DLUT, which will give us this:
1. 1D Curve EOTF
2. 3x4 CTM
3. HDR Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 3D LUT
7. 1D Curve EOTF
8. 1D LUTThis, essentially mirrors the color pipeline used by gamescope
and presented by Melissa Wen, with the exception of the DEGAM
LUT, which is not currently used. See
[1] https://indico.freedesktop.org/event/4/contributions/186/attachments/138/218/xdc2023-TheRainbowTreasureMap-MelissaWen.pdfAfter this we'd like to also add the following ops:
- Scaler (Informational only)
- Color Encoding, to replace drm_plane'sCOLOR_ENCODING
- Color Range, to replace drm_plane'sCOLOR_RANGEThis patchset is grouped as follows:
- Patches 1-3: couple general patches/fixes
- Patches 4-7: introduce kunit to VKMS
- Patch 7: description of motivation and details behind the Color Pipeline API. If you're reading nothing else but are interested in the topic I highly recommend you take a look at this.
- Patches 7-27: DRM core and VKMS changes for color pipeline API
- Patches 28-40: DRM core and amdgpu changes for color pipeline APIVKMS patches could still be improved in a few ways, though the payoff might be limited and I would rather focus on other work at the moment. The most obvious thing to improve would be to eliminate the hard-coded LUTs for identity, and sRGB, and replace them with fixed-point math instead.
There are plenty of things that I would like to see here but haven't had a chance to look at. These will (hopefully) be addressed in future iterations, either in VKMS or amdgpu:
- Clear documentation for eachdrm_colorop_type
- Add custom LUT colorops to VKMS
- Add pre-blending 3DLUT
- How to support HW which can't bypass entire pipeline?
- Add ability to create colorops that don't have BYPASS
- Can we do a LOAD / COMMIT model for LUTs (and other properties)?
- read-only scaling colorop which defines scaling taps and position
- read-only color format colorop to define supported color formats for a pipeline
- named matrices, for things like converting YUV to RGBIGT tests can be found at
https://gitlab.freedesktop.org/hwentland/igt-gpu-tools/-/merge_requests/1IGT patches are also being sent to the igt-dev mailing list.
If you prefer a gitlab MR for review you can find it at
https://gitlab.freedesktop.org/hwentland/linux/-/merge_requests/5v4:
- Add amdgpu color pipeline (WIP)
- Don't block setting of deprecated properties, instead pass client cap to atomic check so drivers can ignore these props
- Drop IOCTL definitions (Pekka)
- Use enum property for colorop TYPE (Pekka)
- A few cleanups to the docs (Pekka)
- Rework the TYPE enum to name relation to avoid code duplication (Pekka)
- Add missing function declarations (Chaitanya Kumar Borah)
- Allow setting of NEXT property to NULL in _set_ function (Chaitanya Kumar Borah)
- Add helper for creation of pipelinedrm_planeproperty (Pekka)
- Always create Bypass pipeline (Pekka)
- A bunch of changes to VKMS kunit tests (Pekka)
- Fix index in CTM doc (Pekka)v3:
- Abandon IOCTLs and discover colorops as clients iterate the pipeline
- Remove need for libdrm
- Addcolor_pipelineclient cap and make mutually exclusive withCOLOR_RANGEandCOLOR_ENCODINGproperties
- add CTM colorop to VKMS
- Use include way for kunit testing static functions (Arthur)
- Make TYPE a range property
- Move enumdrm_colorop_typeto uapi header
- and a bunch of smaller bits that are highlighted in the relevant commit descriptionv2:
- Rebased on drm-misc-next
- Introduce a VKMS Kunit so we can test LUT functionality invkms_composer
- Incorporate feedback incolor_pipeline.rstdoc
- Add support for sRGB inverse EOTF
- Add 2nd enumerated TF colorop to VKMS
- Fix LUTs and some issues with applying LUTs in VKMSCc Ville Syrjala <[email protected]>Cc Pekka Paalanen <[email protected]>Cc Simon Ser <[email protected]>Cc Harry Wentland <[email protected]>Cc Melissa Wen <[email protected]>Cc Jonas Ådahl <[email protected]>Cc Sebastian Wick <[email protected]>Cc Shashank Sharma <[email protected]>Cc Alexander Goins <[email protected]>Cc Joshua Ashton <[email protected]>Cc Michel Dänzer <[email protected]>Cc Aleix Pol <[email protected]>Cc Xaver Hugl <[email protected]>Cc Victoria Brekenfeld <[email protected]>Cc Sima <[email protected]>Cc Uma Shankar <[email protected]>Cc Naseer Ahmed <[email protected]>Cc Christopher Braga <[email protected]>Cc Abhinav Kumar <[email protected]>Cc Arthur Grillo <[email protected]>Cc Hector Martin <[email protected]>Cc Liviu Dudau <[email protected]>Cc Sasha McIntosh <[email protected]>Cc Chaitanya Kumar Borah <[email protected]>Alex Hung (10):
drm/colorop: define a new macrofor_each_new_colorop_in_statedrm/amd/display: Skip color pipeline initialization for cursor plane drm/amd/display: Add support for sRGB EOTF in DEGAM block drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block drm/amd/display: Add support for sRGB EOTF in BLND block drm/colorop: Add 1D Curve Custom LUT type
drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT drm/amd/display: add 3x4 matrix colorop
drm/colorop: Add mutliplier type
drm/amd/display: add multiplier coloropHarry Wentland (32):
drm: Don't treat 0 as -1 indrm_fixp2int_ceil
drm: Add helper for conversion from signed-magnitude
drm: Correctly round forfixp2int_round
drm/vkms: Round fixp2int conversion inlerp_u16
drm/vkms: Create separateKconfigfile for VKMS
drm/vkms: Add kunit tests for VKMS LUT handling
drm/vkms: Avoid reading beyond LUT array
drm/doc/rfc: Describe why prescriptive color pipeline is needed drm/colorop: Introduce newdrm_coloropmode object drm/colorop: Add TYPE property
drm/colorop: Add 1D Curve subtype
drm/colorop: Add BYPASS property
drm/colorop: Add NEXT property
drm/colorop: Add atomic state print fordrm_coloropdrm/plane: Add COLOR PIPELINE property
drm/colorop: Add NEXT to colorop state print
drm/vkms: Add enumerated 1D curve colorop
drm/vkms: Add kunit tests for linear and sRGB LUTs drm/colorop: IntroduceDRM_CLIENT_CAP_PLANE_COLOR_PIPELINEdrm/colorop: Add 3x4 CTM type
drm/vkms: Pullapply_coloropout ofpre_blend_color_transformdrm/vkms: Use s32 for internal color pipeline precision drm/vkms: add 3x4 matrix in color pipeline
drm/tests: Add a few tests arounddrm_fixed.h
drm/vkms: Add tests for CTM handling
drm/colorop: passplane_color_pipelineclient cap to atomic check drm/amd/display: Ignore deprecated props whenplane_color_pipelineset drm/amd/display: Add bypass COLOR PIPELINE
drm/colorop: Add PQ 125 EOTF and its inverse drm/amd/display: Enable support for PQ 125 EOTF and Inverse drm/colorop: add BT2020/BT709 OETF and Inverse OETF drm/amd/display: Add support for BT.709 and BT.2020 TFsDocumentation/gpu/rfc/color_pipeline.rst | 360 ++++++++ drivers/gpu/drm/Kconfig | 14 +- drivers/gpu/drm/Makefile | 1 + .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 352 ++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 160 ++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 36 + .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 32 + drivers/gpu/drm/drm_atomic.c | 161 +++- drivers/gpu/drm/drm_atomic_helper.c | 12 + drivers/gpu/drm/drm_atomic_state_helper.c | 5 + drivers/gpu/drm/drm_atomic_uapi.c | 158 ++++ drivers/gpu/drm/drm_colorop.c | 411 +++++++++ drivers/gpu/drm/drm_ioctl.c | 7 + drivers/gpu/drm/drm_mode_config.c | 7 + drivers/gpu/drm/drm_plane.c | 52 ++ drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_fixp_test.c | 69 ++ drivers/gpu/drm/vkms/Kconfig | 20 + drivers/gpu/drm/vkms/Makefile | 4 +- drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 449 ++++++++++ drivers/gpu/drm/vkms/vkms_colorop.c | 100 +++ drivers/gpu/drm/vkms/vkms_composer.c | 135 ++- drivers/gpu/drm/vkms/vkms_drv.h | 8 + drivers/gpu/drm/vkms/vkms_luts.c | 802 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 2 + include/drm/drm_atomic.h | 122 +++ include/drm/drm_atomic_uapi.h | 3 + include/drm/drm_colorop.h | 301 +++++++ include/drm/drm_file.h | 7 + include/drm/drm_fixed.h | 35 +- include/drm/drm_mode_config.h | 18 + include/drm/drm_plane.h | 13 + include/uapi/drm/drm.h | 16 + include/uapi/drm/drm_mode.h | 14 + 38 files changed, 3882 insertions(+), 30 deletions(-)create mode 100644
Documentation/gpu/rfc/color_pipeline.rstcreate mode 100644drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.ccreate mode 100644drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.hcreate mode 100644drivers/gpu/drm/drm_colorop.c
create mode 100644drivers/gpu/drm/tests/drm_fixp_test.c
create mode 100644drivers/gpu/drm/vkms/Kconfig
create mode 100644drivers/gpu/drm/vkms/tests/.kunitconfigcreate mode 100644drivers/gpu/drm/vkms/tests/vkms_color_tests.ccreate mode 100644drivers/gpu/drm/vkms/vkms_colorop.c
create mode 100644drivers/gpu/drm/vkms/vkms_luts.c
create mode 100644drivers/gpu/drm/vkms/vkms_luts.h
create mode 100644include/drm/drm_colorop.h--
2.44.0
Quoted 82 lines · Harry Wentland
This is an RFC set for a color pipeline API, along with a sample implementation in VKMS. All the key API bits are here. VKMS now supports two named transfer function colorops and two matrix colorops. We have IGT tests that check all four of these colorops with a pixel-by-pixel comparison that checks that these colorops do what we expect them to do with a +/- 1 8 bpc code point margin.
The big new change with v4 is the addition of an amdgpu color pipeline, for all AMD GPUs with DCN 3 and newer. Amdgpu now support the following:
1. 1D Curve EOTF
2. 3x4 CTM
3. Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 1D Curve EOTF
7. 1D LUTThe supported curves for the 1D Curve type are:
- sRGB EOTF and its inverse
- PQ EOTF, scaled to [0.0, 125.0] and its inverse
- BT.2020/BT.709 OETF and its inverseNote that the 1st and 5th colorops take the EOTF or Inverse OETF while the 3rd colorop takes the Inverse EOTF or OETF.
We are working on two more ops for amdgpu, the HDR multiplier and the 3DLUT, which will give us this:
1. 1D Curve EOTF
2. 3x4 CTM
3. HDR Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 3D LUT
7. 1D Curve EOTF
8. 1D LUTThis, essentially mirrors the color pipeline used by gamescope
and presented by Melissa Wen, with the exception of the DEGAM
LUT, which is not currently used. See
[1] https://indico.freedesktop.org/event/4/contributions/186/attachments/138/218/xdc2023-TheRainbowTreasureMap-MelissaWen.pdfAfter this we'd like to also add the following ops:
- Scaler (Informational only)
- Color Encoding, to replace drm_plane'sCOLOR_ENCODING
- Color Range, to replace drm_plane'sCOLOR_RANGEThis patchset is grouped as follows:
- Patches 1-3: couple general patches/fixes
- Patches 4-7: introduce kunit to VKMS
- Patch 7: description of motivation and details behind the Color Pipeline API. If you're reading nothing else but are interested in the topic I highly recommend you take a look at this.
- Patches 7-27: DRM core and VKMS changes for color pipeline API
- Patches 28-40: DRM core and amdgpu changes for color pipeline APIVKMS patches could still be improved in a few ways, though the payoff might be limited and I would rather focus on other work at the moment. The most obvious thing to improve would be to eliminate the hard-coded LUTs for identity, and sRGB, and replace them with fixed-point math instead.
There are plenty of things that I would like to see here but haven't had a chance to look at. These will (hopefully) be addressed in future iterations, either in VKMS or amdgpu:
- Clear documentation for eachdrm_colorop_type
- Add custom LUT colorops to VKMS
- Add pre-blending 3DLUT
- How to support HW which can't bypass entire pipeline?
- Add ability to create colorops that don't have BYPASS
- Can we do a LOAD / COMMIT model for LUTs (and other properties)?
- read-only scaling colorop which defines scaling taps and position
- read-only color format colorop to define supported color formats for a pipeline
- named matrices, for things like converting YUV to RGBIGT tests can be found at
https://gitlab.freedesktop.org/hwentland/igt-gpu-tools/-/merge_requests/1
Quoted 6 lines
IGT patches are also being sent to the igt-dev mailing list.
If you prefer a gitlab MR for review you can find it at
https://gitlab.freedesktop.org/hwentland/linux/-/merge_requests/5v4:
Hey,
I'm not sure if this is the latest version, but this is the one I'm using now. I just pointed out some minor issues that I found when applying this series for testing, so I won't forget to report. But I'm still performing tests and validations on my side.
Melissa
Quoted 160 lines
- Add amdgpu color pipeline (WIP)
- Don't block setting of deprecated properties, instead pass client cap to atomic check so drivers can ignore these props
- Drop IOCTL definitions (Pekka)
- Use enum property for colorop TYPE (Pekka)
- A few cleanups to the docs (Pekka)
- Rework the TYPE enum to name relation to avoid code duplication (Pekka)
- Add missing function declarations (Chaitanya Kumar Borah)
- Allow setting of NEXT property to NULL in _set_ function (Chaitanya Kumar Borah)
- Add helper for creation of pipelinedrm_planeproperty (Pekka)
- Always create Bypass pipeline (Pekka)
- A bunch of changes to VKMS kunit tests (Pekka)
- Fix index in CTM doc (Pekka)v3:
- Abandon IOCTLs and discover colorops as clients iterate the pipeline
- Remove need for libdrm
- Addcolor_pipelineclient cap and make mutually exclusive withCOLOR_RANGEandCOLOR_ENCODINGproperties
- add CTM colorop to VKMS
- Use include way for kunit testing static functions (Arthur)
- Make TYPE a range property
- Move enumdrm_colorop_typeto uapi header
- and a bunch of smaller bits that are highlighted in the relevant commit descriptionv2:
- Rebased on drm-misc-next
- Introduce a VKMS Kunit so we can test LUT functionality invkms_composer
- Incorporate feedback incolor_pipeline.rstdoc
- Add support for sRGB inverse EOTF
- Add 2nd enumerated TF colorop to VKMS
- Fix LUTs and some issues with applying LUTs in VKMSCc Ville Syrjala <[email protected]>Cc Pekka Paalanen <[email protected]>Cc Simon Ser <[email protected]>Cc Harry Wentland <[email protected]>Cc Melissa Wen <[email protected]>Cc Jonas Ådahl <[email protected]>Cc Sebastian Wick <[email protected]>Cc Shashank Sharma <[email protected]>Cc Alexander Goins <[email protected]>Cc Joshua Ashton <[email protected]>Cc Michel Dänzer <[email protected]>Cc Aleix Pol <[email protected]>Cc Xaver Hugl <[email protected]>Cc Victoria Brekenfeld <[email protected]>Cc Sima <[email protected]>Cc Uma Shankar <[email protected]>Cc Naseer Ahmed <[email protected]>Cc Christopher Braga <[email protected]>Cc Abhinav Kumar <[email protected]>Cc Arthur Grillo <[email protected]>Cc Hector Martin <[email protected]>Cc Liviu Dudau <[email protected]>Cc Sasha McIntosh <[email protected]>Cc Chaitanya Kumar Borah <[email protected]>Alex Hung (10):
drm/colorop: define a new macrofor_each_new_colorop_in_statedrm/amd/display: Skip color pipeline initialization for cursor plane drm/amd/display: Add support for sRGB EOTF in DEGAM block drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block drm/amd/display: Add support for sRGB EOTF in BLND block drm/colorop: Add 1D Curve Custom LUT type
drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT drm/amd/display: add 3x4 matrix colorop
drm/colorop: Add mutliplier type
drm/amd/display: add multiplier coloropHarry Wentland (32):
drm: Don't treat 0 as -1 indrm_fixp2int_ceil
drm: Add helper for conversion from signed-magnitude
drm: Correctly round forfixp2int_round
drm/vkms: Round fixp2int conversion inlerp_u16
drm/vkms: Create separateKconfigfile for VKMS
drm/vkms: Add kunit tests for VKMS LUT handling
drm/vkms: Avoid reading beyond LUT array
drm/doc/rfc: Describe why prescriptive color pipeline is needed drm/colorop: Introduce newdrm_coloropmode object drm/colorop: Add TYPE property
drm/colorop: Add 1D Curve subtype
drm/colorop: Add BYPASS property
drm/colorop: Add NEXT property
drm/colorop: Add atomic state print fordrm_coloropdrm/plane: Add COLOR PIPELINE property
drm/colorop: Add NEXT to colorop state print
drm/vkms: Add enumerated 1D curve colorop
drm/vkms: Add kunit tests for linear and sRGB LUTs drm/colorop: IntroduceDRM_CLIENT_CAP_PLANE_COLOR_PIPELINEdrm/colorop: Add 3x4 CTM type
drm/vkms: Pullapply_coloropout ofpre_blend_color_transformdrm/vkms: Use s32 for internal color pipeline precision drm/vkms: add 3x4 matrix in color pipeline
drm/tests: Add a few tests arounddrm_fixed.h
drm/vkms: Add tests for CTM handling
drm/colorop: passplane_color_pipelineclient cap to atomic check drm/amd/display: Ignore deprecated props whenplane_color_pipelineset drm/amd/display: Add bypass COLOR PIPELINE
drm/colorop: Add PQ 125 EOTF and its inverse drm/amd/display: Enable support for PQ 125 EOTF and Inverse drm/colorop: add BT2020/BT709 OETF and Inverse OETF drm/amd/display: Add support for BT.709 and BT.2020 TFsDocumentation/gpu/rfc/color_pipeline.rst | 360 ++++++++ drivers/gpu/drm/Kconfig | 14 +- drivers/gpu/drm/Makefile | 1 + .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 352 ++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 160 ++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 36 + .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 32 + drivers/gpu/drm/drm_atomic.c | 161 +++- drivers/gpu/drm/drm_atomic_helper.c | 12 + drivers/gpu/drm/drm_atomic_state_helper.c | 5 + drivers/gpu/drm/drm_atomic_uapi.c | 158 ++++ drivers/gpu/drm/drm_colorop.c | 411 +++++++++ drivers/gpu/drm/drm_ioctl.c | 7 + drivers/gpu/drm/drm_mode_config.c | 7 + drivers/gpu/drm/drm_plane.c | 52 ++ drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_fixp_test.c | 69 ++ drivers/gpu/drm/vkms/Kconfig | 20 + drivers/gpu/drm/vkms/Makefile | 4 +- drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 449 ++++++++++ drivers/gpu/drm/vkms/vkms_colorop.c | 100 +++ drivers/gpu/drm/vkms/vkms_composer.c | 135 ++- drivers/gpu/drm/vkms/vkms_drv.h | 8 + drivers/gpu/drm/vkms/vkms_luts.c | 802 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 2 + include/drm/drm_atomic.h | 122 +++ include/drm/drm_atomic_uapi.h | 3 + include/drm/drm_colorop.h | 301 +++++++ include/drm/drm_file.h | 7 + include/drm/drm_fixed.h | 35 +- include/drm/drm_mode_config.h | 18 + include/drm/drm_plane.h | 13 + include/uapi/drm/drm.h | 16 + include/uapi/drm/drm_mode.h | 14 + 38 files changed, 3882 insertions(+), 30 deletions(-) create mode 100644 Documentation/gpu/rfc/color_pipeline.rst create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h create mode 100644 drivers/gpu/drm/drm_colorop.c create mode 100644 drivers/gpu/drm/tests/drm_fixp_test.c create mode 100644 drivers/gpu/drm/vkms/Kconfig create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/vkms_color_tests.c create mode 100644 drivers/gpu/drm/vkms/vkms_colorop.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.h create mode 100644 include/drm/drm_colorop.h--
2.44.0
Quoted 19 lines · Harry Wentland
This is an RFC set for a color pipeline API, along with a sample implementation in VKMS. All the key API bits are here. VKMS now supports two named transfer function colorops and two matrix colorops. We have IGT tests that check all four of these colorops with a pixel-by-pixel comparison that checks that these colorops do what we expect them to do with a +/- 1 8 bpc code point margin.
The big new change with v4 is the addition of an amdgpu color pipeline, for all AMD GPUs with DCN 3 and newer. Amdgpu now support the following:
1. 1D Curve EOTF
2. 3x4 CTM
3. Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 1D Curve EOTF
7. 1D LUT
Quoted 4 lines
The supported curves for the 1D Curve type are:
- sRGB EOTF and its inverse
- PQ EOTF, scaled to [0.0, 125.0] and its inverse
- BT.2020/BT.709 OETF and its inverse
So, as we talked in the 2024 Linux Display Next Hackfest, I hacked drm_info to show the KMS color pipeline properties. You can find the experimental-and-ugly code here:
- https://gitlab.freedesktop.org/mwen/drm_info/-/merge_requests/1
It depends on updating libdrm [1] and you will only see something if you use a custom kernel with this series applied.
After checking the output, I missed a kind of Default or "Identity" curve for the CURVE_1D_TYPE enum. I understand that if the color operation is set bypass, we can ignore all property values, but I didn't find a similar approach on plane properties, so it looks weird to me:
└───"CURVE_1D_TYPE" (atomic): enum {sRGB Inverse EOTF, BT.2020 OETF, PQ 125 Inverse EOTF} = invalid (0)
Another thing that caught my attention was the size property for 1D Curve Custom LUT, that I expected a similar setup to CRTC 1D LUTs:
└───"GAMMA_LUT_SIZE" (immutable): range [0, UINT32_MAX] = 4096
But I got:
├───"SIZE" (atomic): range [4096, 4096] = 4096
Any thoughts?
Anyway, see below an example of drm_info output on AMD DCN301 for a given Overlay/Primary plane without userspace usage of the properties:
│ └───"COLOR_PIPELINE" (atomic): enum {Bypass, Color Pipeline 265} = Bypass
│ ├───Bypass
│ └───Color Pipeline 265
│ ├───Color Operation 265
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 1D Curve
│ │ ├───"BYPASS" (atomic): range [0, 1] = 1
│ │ └───"CURVE_1D_TYPE" (atomic): enum {sRGB EOTF, BT.2020 Inverse OETF, PQ 125 EOTF} = sRGB EOTF
│ ├───Color Operation 270
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 3x4 Matrix
│ │ ├───"BYPASS" (atomic): range [0, 1] = 1
│ │ └───"DATA" (atomic): blob = 0
│ ├───Color Operation 275
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = Multiplier
│ │ ├───"BYPASS" (atomic): range [0, 1] = 1
│ │ └───"MULTIPLIER" (atomic): range [0, UINT64_MAX] = 0
│ ├───Color Operation 280
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 1D Curve
│ │ ├───"BYPASS" (atomic): range [0, 1] = 1
│ │ └───"CURVE_1D_TYPE" (atomic): enum {sRGB Inverse EOTF, BT.2020 OETF, PQ 125 Inverse EOTF} = invalid (0)
│ ├───Color Operation 285
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 1D Curve Custom LUT
│ │ ├───"BYPASS" (atomic): range [0, 1] = 1
│ │ ├───"SIZE" (atomic): range [4096, 4096] = 4096
│ │ └───"DATA" (atomic): blob = 0
│ ├───Color Operation 291
│ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 1D Curve
│ │ ├───"BYPASS" (atomic): range [0, 1] = 1
│ │ └───"CURVE_1D_TYPE" (atomic): enum {sRGB EOTF, BT.2020 Inverse OETF, PQ 125 EOTF} = sRGB EOTF
│ └───Color Operation 296
│ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 1D Curve Custom LUT
│ ├───"BYPASS" (atomic): range [0, 1] = 1
│ ├───"SIZE" (atomic): range [4096, 4096] = 4096
│ └───"DATA" (atomic): blob = 0It's a WIP and the output still needs to be reviewed. So feel free to point out any mistake.
BR,
Melissa
Quoted 225 lines
Note that the 1st and 5th colorops take the EOTF or Inverse OETF while the 3rd colorop takes the Inverse EOTF or OETF.
We are working on two more ops for amdgpu, the HDR multiplier and the 3DLUT, which will give us this:
1. 1D Curve EOTF
2. 3x4 CTM
3. HDR Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 3D LUT
7. 1D Curve EOTF
8. 1D LUTThis, essentially mirrors the color pipeline used by gamescope
and presented by Melissa Wen, with the exception of the DEGAM
LUT, which is not currently used. See
[1] https://indico.freedesktop.org/event/4/contributions/186/attachments/138/218/xdc2023-TheRainbowTreasureMap-MelissaWen.pdfAfter this we'd like to also add the following ops:
- Scaler (Informational only)
- Color Encoding, to replace drm_plane'sCOLOR_ENCODING
- Color Range, to replace drm_plane'sCOLOR_RANGEThis patchset is grouped as follows:
- Patches 1-3: couple general patches/fixes
- Patches 4-7: introduce kunit to VKMS
- Patch 7: description of motivation and details behind the Color Pipeline API. If you're reading nothing else but are interested in the topic I highly recommend you take a look at this.
- Patches 7-27: DRM core and VKMS changes for color pipeline API
- Patches 28-40: DRM core and amdgpu changes for color pipeline APIVKMS patches could still be improved in a few ways, though the payoff might be limited and I would rather focus on other work at the moment. The most obvious thing to improve would be to eliminate the hard-coded LUTs for identity, and sRGB, and replace them with fixed-point math instead.
There are plenty of things that I would like to see here but haven't had a chance to look at. These will (hopefully) be addressed in future iterations, either in VKMS or amdgpu:
- Clear documentation for eachdrm_colorop_type
- Add custom LUT colorops to VKMS
- Add pre-blending 3DLUT
- How to support HW which can't bypass entire pipeline?
- Add ability to create colorops that don't have BYPASS
- Can we do a LOAD / COMMIT model for LUTs (and other properties)?
- read-only scaling colorop which defines scaling taps and position
- read-only color format colorop to define supported color formats for a pipeline
- named matrices, for things like converting YUV to RGBIGT tests can be found at
https://gitlab.freedesktop.org/hwentland/igt-gpu-tools/-/merge_requests/1IGT patches are also being sent to the igt-dev mailing list.
If you prefer a gitlab MR for review you can find it at
https://gitlab.freedesktop.org/hwentland/linux/-/merge_requests/5v4:
- Add amdgpu color pipeline (WIP)
- Don't block setting of deprecated properties, instead pass client cap to atomic check so drivers can ignore these props
- Drop IOCTL definitions (Pekka)
- Use enum property for colorop TYPE (Pekka)
- A few cleanups to the docs (Pekka)
- Rework the TYPE enum to name relation to avoid code duplication (Pekka)
- Add missing function declarations (Chaitanya Kumar Borah)
- Allow setting of NEXT property to NULL in _set_ function (Chaitanya Kumar Borah)
- Add helper for creation of pipelinedrm_planeproperty (Pekka)
- Always create Bypass pipeline (Pekka)
- A bunch of changes to VKMS kunit tests (Pekka)
- Fix index in CTM doc (Pekka)v3:
- Abandon IOCTLs and discover colorops as clients iterate the pipeline
- Remove need for libdrm
- Addcolor_pipelineclient cap and make mutually exclusive withCOLOR_RANGEandCOLOR_ENCODINGproperties
- add CTM colorop to VKMS
- Use include way for kunit testing static functions (Arthur)
- Make TYPE a range property
- Move enumdrm_colorop_typeto uapi header
- and a bunch of smaller bits that are highlighted in the relevant commit descriptionv2:
- Rebased on drm-misc-next
- Introduce a VKMS Kunit so we can test LUT functionality invkms_composer
- Incorporate feedback incolor_pipeline.rstdoc
- Add support for sRGB inverse EOTF
- Add 2nd enumerated TF colorop to VKMS
- Fix LUTs and some issues with applying LUTs in VKMSCc Ville Syrjala <[email protected]>Cc Pekka Paalanen <[email protected]>Cc Simon Ser <[email protected]>Cc Harry Wentland <[email protected]>Cc Melissa Wen <[email protected]>Cc Jonas Ådahl <[email protected]>Cc Sebastian Wick <[email protected]>Cc Shashank Sharma <[email protected]>Cc Alexander Goins <[email protected]>Cc Joshua Ashton <[email protected]>Cc Michel Dänzer <[email protected]>Cc Aleix Pol <[email protected]>Cc Xaver Hugl <[email protected]>Cc Victoria Brekenfeld <[email protected]>Cc Sima <[email protected]>Cc Uma Shankar <[email protected]>Cc Naseer Ahmed <[email protected]>Cc Christopher Braga <[email protected]>Cc Abhinav Kumar <[email protected]>Cc Arthur Grillo <[email protected]>Cc Hector Martin <[email protected]>Cc Liviu Dudau <[email protected]>Cc Sasha McIntosh <[email protected]>Cc Chaitanya Kumar Borah <[email protected]>Alex Hung (10):
drm/colorop: define a new macrofor_each_new_colorop_in_statedrm/amd/display: Skip color pipeline initialization for cursor plane drm/amd/display: Add support for sRGB EOTF in DEGAM block drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block drm/amd/display: Add support for sRGB EOTF in BLND block drm/colorop: Add 1D Curve Custom LUT type
drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT drm/amd/display: add 3x4 matrix colorop
drm/colorop: Add mutliplier type
drm/amd/display: add multiplier coloropHarry Wentland (32):
drm: Don't treat 0 as -1 indrm_fixp2int_ceil
drm: Add helper for conversion from signed-magnitude
drm: Correctly round forfixp2int_round
drm/vkms: Round fixp2int conversion inlerp_u16
drm/vkms: Create separateKconfigfile for VKMS
drm/vkms: Add kunit tests for VKMS LUT handling
drm/vkms: Avoid reading beyond LUT array
drm/doc/rfc: Describe why prescriptive color pipeline is needed drm/colorop: Introduce newdrm_coloropmode object drm/colorop: Add TYPE property
drm/colorop: Add 1D Curve subtype
drm/colorop: Add BYPASS property
drm/colorop: Add NEXT property
drm/colorop: Add atomic state print fordrm_coloropdrm/plane: Add COLOR PIPELINE property
drm/colorop: Add NEXT to colorop state print
drm/vkms: Add enumerated 1D curve colorop
drm/vkms: Add kunit tests for linear and sRGB LUTs drm/colorop: IntroduceDRM_CLIENT_CAP_PLANE_COLOR_PIPELINEdrm/colorop: Add 3x4 CTM type
drm/vkms: Pullapply_coloropout ofpre_blend_color_transformdrm/vkms: Use s32 for internal color pipeline precision drm/vkms: add 3x4 matrix in color pipeline
drm/tests: Add a few tests arounddrm_fixed.h
drm/vkms: Add tests for CTM handling
drm/colorop: passplane_color_pipelineclient cap to atomic check drm/amd/display: Ignore deprecated props whenplane_color_pipelineset drm/amd/display: Add bypass COLOR PIPELINE
drm/colorop: Add PQ 125 EOTF and its inverse drm/amd/display: Enable support for PQ 125 EOTF and Inverse drm/colorop: add BT2020/BT709 OETF and Inverse OETF drm/amd/display: Add support for BT.709 and BT.2020 TFsDocumentation/gpu/rfc/color_pipeline.rst | 360 ++++++++ drivers/gpu/drm/Kconfig | 14 +- drivers/gpu/drm/Makefile | 1 + .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 352 ++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 160 ++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 36 + .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 32 + drivers/gpu/drm/drm_atomic.c | 161 +++- drivers/gpu/drm/drm_atomic_helper.c | 12 + drivers/gpu/drm/drm_atomic_state_helper.c | 5 + drivers/gpu/drm/drm_atomic_uapi.c | 158 ++++ drivers/gpu/drm/drm_colorop.c | 411 +++++++++ drivers/gpu/drm/drm_ioctl.c | 7 + drivers/gpu/drm/drm_mode_config.c | 7 + drivers/gpu/drm/drm_plane.c | 52 ++ drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_fixp_test.c | 69 ++ drivers/gpu/drm/vkms/Kconfig | 20 + drivers/gpu/drm/vkms/Makefile | 4 +- drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 449 ++++++++++ drivers/gpu/drm/vkms/vkms_colorop.c | 100 +++ drivers/gpu/drm/vkms/vkms_composer.c | 135 ++- drivers/gpu/drm/vkms/vkms_drv.h | 8 + drivers/gpu/drm/vkms/vkms_luts.c | 802 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 2 + include/drm/drm_atomic.h | 122 +++ include/drm/drm_atomic_uapi.h | 3 + include/drm/drm_colorop.h | 301 +++++++ include/drm/drm_file.h | 7 + include/drm/drm_fixed.h | 35 +- include/drm/drm_mode_config.h | 18 + include/drm/drm_plane.h | 13 + include/uapi/drm/drm.h | 16 + include/uapi/drm/drm_mode.h | 14 + 38 files changed, 3882 insertions(+), 30 deletions(-) create mode 100644 Documentation/gpu/rfc/color_pipeline.rst create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h create mode 100644 drivers/gpu/drm/drm_colorop.c create mode 100644 drivers/gpu/drm/tests/drm_fixp_test.c create mode 100644 drivers/gpu/drm/vkms/Kconfig create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/vkms_color_tests.c create mode 100644 drivers/gpu/drm/vkms/vkms_colorop.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.h create mode 100644 include/drm/drm_colorop.h--
2.44.0
Harry Wentland
maintainerQuoted 25 lines · Melissa Wen
Quoted 19 lines · Harry Wentland
This is an RFC set for a color pipeline API, along with a sample implementation in VKMS. All the key API bits are here. VKMS now supports two named transfer function colorops and two matrix colorops. We have IGT tests that check all four of these colorops with a pixel-by-pixel comparison that checks that these colorops do what we expect them to do with a +/- 1 8 bpc code point margin.
The big new change with v4 is the addition of an amdgpu color pipeline, for all AMD GPUs with DCN 3 and newer. Amdgpu now support the following:
1. 1D Curve EOTF
2. 3x4 CTM
3. Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 1D Curve EOTF
7. 1D LUTQuoted 4 lines
The supported curves for the 1D Curve type are:
- sRGB EOTF and its inverse
- PQ EOTF, scaled to [0.0, 125.0] and its inverse
- BT.2020/BT.709 OETF and its inverse
Quoted 7 lines
So, as we talked in the 2024 Linux Display Next Hackfest, I hacked
drm_infoto show the KMS color pipeline properties. You can find the experimental-and-ugly code here:
- https://gitlab.freedesktop.org/mwen/drm_info/-/merge_requests/1
It depends on updating libdrm [1] and you will only see something if you use a custom kernel with this series applied.
Thanks. That's very useful.
Quoted 7 lines
After checking the output, I missed a kind of Default or "Identity" curve for the
CURVE_1D_TYPEenum. I understand that if the color operation is set bypass, we can ignore all property values, but I didn't find a similar approach on plane properties, so it looks weird to me:└───"CURVE_1D_TYPE" (atomic): enum {sRGB Inverse EOTF, BT.2020 OETF, PQ 125 Inverse EOTF} = invalid (0)
Good catch. That's where drm_info is useful. We shouldn't be reporting "invalid (0)" but default to any other value. I'll fix that.
While your suggestion would work for AMD I'm a bit reluctant to add an Identity element. It doesn't add value over "BYPASS". But more importantly we discussed that there might be some HW that doesn't support HW on colorops. It would be better if we avoid assumptions about the availability of identity or bypass.
Quoted 10 lines
Another thing that caught my attention was the size property for 1D Curve Custom LUT, that I expected a similar setup to CRTC 1D LUTs:
└───"GAMMA_LUT_SIZE" (immutable): range [0,
UINT32_MAX] = 4096But I got:
├───"SIZE" (atomic): range [4096, 4096] = 4096
Any thoughts?
We should stick with same behavior as GAMMA_LUT_SIZE. I'll change that.
Quoted 38 lines
Anyway, see below an example of
drm_infooutput on AMD DCN301 for a given Overlay/Primary plane without userspace usage of the properties:│ └───"COLOR_PIPELINE" (atomic): enum {Bypass, Color Pipeline 265} = Bypass │ ├───Bypass │ └───Color Pipeline 265 │ ├───Color Operation 265 │ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 1D Curve │ │ ├───"BYPASS" (atomic): range [0, 1] = 1 │ │ └───"CURVE_1D_TYPE" (atomic): enum {sRGB EOTF, BT.2020 Inverse OETF, PQ 125 EOTF} = sRGB EOTF │ ├───Color Operation 270 │ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 3x4 Matrix │ │ ├───"BYPASS" (atomic): range [0, 1] = 1 │ │ └───"DATA" (atomic): blob = 0 │ ├───Color Operation 275 │ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = Multiplier │ │ ├───"BYPASS" (atomic): range [0, 1] = 1 │ │ └───"MULTIPLIER" (atomic): range [0, UINT64_MAX] = 0 │ ├───Color Operation 280 │ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 1D Curve │ │ ├───"BYPASS" (atomic): range [0, 1] = 1 │ │ └───"CURVE_1D_TYPE" (atomic): enum {sRGB Inverse EOTF, BT.2020 OETF, PQ 125 Inverse EOTF} = invalid (0) │ ├───Color Operation 285 │ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 1D Curve Custom LUT │ │ ├───"BYPASS" (atomic): range [0, 1] = 1 │ │ ├───"SIZE" (atomic): range [4096, 4096] = 4096 │ │ └───"DATA" (atomic): blob = 0 │ ├───Color Operation 291 │ │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 1D Curve │ │ ├───"BYPASS" (atomic): range [0, 1] = 1 │ │ └───"CURVE_1D_TYPE" (atomic): enum {sRGB EOTF, BT.2020 Inverse OETF, PQ 125 EOTF} = sRGB EOTF │ └───Color Operation 296 │ ├───"TYPE" (immutable): enum {1D Curve, 1D Curve Custom LUT, 3x4 Matrix, Multiplier} = 1D Curve Custom LUT │ ├───"BYPASS" (atomic): range [0, 1] = 1 │ ├───"SIZE" (atomic): range [4096, 4096] = 4096 │ └───"DATA" (atomic): blob = 0
Quoted 3 lines
It's a WIP and the output still needs to be reviewed. So feel free to point out any mistake.
Thanks for doing this work.
Btw, I can't seem to access your MR but found the kms_color branch on your fork of drm_info.
Harry
Quoted 229 lines
BR,
Melissa
Quoted 225 lines
Note that the 1st and 5th colorops take the EOTF or Inverse OETF while the 3rd colorop takes the Inverse EOTF or OETF.
We are working on two more ops for amdgpu, the HDR multiplier and the 3DLUT, which will give us this:
1. 1D Curve EOTF
2. 3x4 CTM
3. HDR Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 3D LUT
7. 1D Curve EOTF
8. 1D LUTThis, essentially mirrors the color pipeline used by gamescope
and presented by Melissa Wen, with the exception of the DEGAM
LUT, which is not currently used. See
[1] https://indico.freedesktop.org/event/4/contributions/186/attachments/138/218/xdc2023-TheRainbowTreasureMap-MelissaWen.pdfAfter this we'd like to also add the following ops:
- Scaler (Informational only)
- Color Encoding, to replace drm_plane'sCOLOR_ENCODING
- Color Range, to replace drm_plane'sCOLOR_RANGEThis patchset is grouped as follows:
- Patches 1-3: couple general patches/fixes
- Patches 4-7: introduce kunit to VKMS
- Patch 7: description of motivation and details behind the Color Pipeline API. If you're reading nothing else but are interested in the topic I highly recommend you take a look at this.
- Patches 7-27: DRM core and VKMS changes for color pipeline API
- Patches 28-40: DRM core and amdgpu changes for color pipeline APIVKMS patches could still be improved in a few ways, though the payoff might be limited and I would rather focus on other work at the moment. The most obvious thing to improve would be to eliminate the hard-coded LUTs for identity, and sRGB, and replace them with fixed-point math instead.
There are plenty of things that I would like to see here but haven't had a chance to look at. These will (hopefully) be addressed in future iterations, either in VKMS or amdgpu:
- Clear documentation for eachdrm_colorop_type
- Add custom LUT colorops to VKMS
- Add pre-blending 3DLUT
- How to support HW which can't bypass entire pipeline?
- Add ability to create colorops that don't have BYPASS
- Can we do a LOAD / COMMIT model for LUTs (and other properties)?
- read-only scaling colorop which defines scaling taps and position
- read-only color format colorop to define supported color formats for a pipeline
- named matrices, for things like converting YUV to RGBIGT tests can be found at
https://gitlab.freedesktop.org/hwentland/igt-gpu-tools/-/merge_requests/1IGT patches are also being sent to the igt-dev mailing list.
If you prefer a gitlab MR for review you can find it at
https://gitlab.freedesktop.org/hwentland/linux/-/merge_requests/5v4:
- Add amdgpu color pipeline (WIP)
- Don't block setting of deprecated properties, instead pass client cap to atomic check so drivers can ignore these props
- Drop IOCTL definitions (Pekka)
- Use enum property for colorop TYPE (Pekka)
- A few cleanups to the docs (Pekka)
- Rework the TYPE enum to name relation to avoid code duplication (Pekka)
- Add missing function declarations (Chaitanya Kumar Borah)
- Allow setting of NEXT property to NULL in _set_ function (Chaitanya Kumar Borah)
- Add helper for creation of pipelinedrm_planeproperty (Pekka)
- Always create Bypass pipeline (Pekka)
- A bunch of changes to VKMS kunit tests (Pekka)
- Fix index in CTM doc (Pekka)v3:
- Abandon IOCTLs and discover colorops as clients iterate the pipeline
- Remove need for libdrm
- Addcolor_pipelineclient cap and make mutually exclusive withCOLOR_RANGEandCOLOR_ENCODINGproperties
- add CTM colorop to VKMS
- Use include way for kunit testing static functions (Arthur)
- Make TYPE a range property
- Move enumdrm_colorop_typeto uapi header
- and a bunch of smaller bits that are highlighted in the relevant commit descriptionv2:
- Rebased on drm-misc-next
- Introduce a VKMS Kunit so we can test LUT functionality invkms_composer
- Incorporate feedback incolor_pipeline.rstdoc
- Add support for sRGB inverse EOTF
- Add 2nd enumerated TF colorop to VKMS
- Fix LUTs and some issues with applying LUTs in VKMSCc Ville Syrjala <[email protected]>Cc Pekka Paalanen <[email protected]>Cc Simon Ser <[email protected]>Cc Harry Wentland <[email protected]>Cc Melissa Wen <[email protected]>Cc Jonas Ådahl <[email protected]>Cc Sebastian Wick <[email protected]>Cc Shashank Sharma <[email protected]>Cc Alexander Goins <[email protected]>Cc Joshua Ashton <[email protected]>Cc Michel Dänzer <[email protected]>Cc Aleix Pol <[email protected]>Cc Xaver Hugl <[email protected]>Cc Victoria Brekenfeld <[email protected]>Cc Sima <[email protected]>Cc Uma Shankar <[email protected]>Cc Naseer Ahmed <[email protected]>Cc Christopher Braga <[email protected]>Cc Abhinav Kumar <[email protected]>Cc Arthur Grillo <[email protected]>Cc Hector Martin <[email protected]>Cc Liviu Dudau <[email protected]>Cc Sasha McIntosh <[email protected]>Cc Chaitanya Kumar Borah <[email protected]>Alex Hung (10):
drm/colorop: define a new macrofor_each_new_colorop_in_statedrm/amd/display: Skip color pipeline initialization for cursor plane drm/amd/display: Add support for sRGB EOTF in DEGAM block drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block drm/amd/display: Add support for sRGB EOTF in BLND block drm/colorop: Add 1D Curve Custom LUT type
drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT drm/amd/display: add 3x4 matrix colorop
drm/colorop: Add mutliplier type
drm/amd/display: add multiplier coloropHarry Wentland (32):
drm: Don't treat 0 as -1 indrm_fixp2int_ceil
drm: Add helper for conversion from signed-magnitude
drm: Correctly round forfixp2int_round
drm/vkms: Round fixp2int conversion inlerp_u16
drm/vkms: Create separateKconfigfile for VKMS
drm/vkms: Add kunit tests for VKMS LUT handling
drm/vkms: Avoid reading beyond LUT array
drm/doc/rfc: Describe why prescriptive color pipeline is needed drm/colorop: Introduce newdrm_coloropmode object drm/colorop: Add TYPE property
drm/colorop: Add 1D Curve subtype
drm/colorop: Add BYPASS property
drm/colorop: Add NEXT property
drm/colorop: Add atomic state print fordrm_coloropdrm/plane: Add COLOR PIPELINE property
drm/colorop: Add NEXT to colorop state print
drm/vkms: Add enumerated 1D curve colorop
drm/vkms: Add kunit tests for linear and sRGB LUTs drm/colorop: IntroduceDRM_CLIENT_CAP_PLANE_COLOR_PIPELINEdrm/colorop: Add 3x4 CTM type
drm/vkms: Pullapply_coloropout ofpre_blend_color_transformdrm/vkms: Use s32 for internal color pipeline precision drm/vkms: add 3x4 matrix in color pipeline
drm/tests: Add a few tests arounddrm_fixed.h
drm/vkms: Add tests for CTM handling
drm/colorop: passplane_color_pipelineclient cap to atomic check drm/amd/display: Ignore deprecated props whenplane_color_pipelineset drm/amd/display: Add bypass COLOR PIPELINE
drm/colorop: Add PQ 125 EOTF and its inverse drm/amd/display: Enable support for PQ 125 EOTF and Inverse drm/colorop: add BT2020/BT709 OETF and Inverse OETF drm/amd/display: Add support for BT.709 and BT.2020 TFsDocumentation/gpu/rfc/color_pipeline.rst | 360 ++++++++ drivers/gpu/drm/Kconfig | 14 +- drivers/gpu/drm/Makefile | 1 + .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 352 ++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 160 ++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 36 + .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 32 + drivers/gpu/drm/drm_atomic.c | 161 +++- drivers/gpu/drm/drm_atomic_helper.c | 12 + drivers/gpu/drm/drm_atomic_state_helper.c | 5 + drivers/gpu/drm/drm_atomic_uapi.c | 158 ++++ drivers/gpu/drm/drm_colorop.c | 411 +++++++++ drivers/gpu/drm/drm_ioctl.c | 7 + drivers/gpu/drm/drm_mode_config.c | 7 + drivers/gpu/drm/drm_plane.c | 52 ++ drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_fixp_test.c | 69 ++ drivers/gpu/drm/vkms/Kconfig | 20 + drivers/gpu/drm/vkms/Makefile | 4 +- drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 449 ++++++++++ drivers/gpu/drm/vkms/vkms_colorop.c | 100 +++ drivers/gpu/drm/vkms/vkms_composer.c | 135 ++- drivers/gpu/drm/vkms/vkms_drv.h | 8 + drivers/gpu/drm/vkms/vkms_luts.c | 802 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 2 + include/drm/drm_atomic.h | 122 +++ include/drm/drm_atomic_uapi.h | 3 + include/drm/drm_colorop.h | 301 +++++++ include/drm/drm_file.h | 7 + include/drm/drm_fixed.h | 35 +- include/drm/drm_mode_config.h | 18 + include/drm/drm_plane.h | 13 + include/uapi/drm/drm.h | 16 + include/uapi/drm/drm_mode.h | 14 + 38 files changed, 3882 insertions(+), 30 deletions(-) create mode 100644 Documentation/gpu/rfc/color_pipeline.rst create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h create mode 100644 drivers/gpu/drm/drm_colorop.c create mode 100644 drivers/gpu/drm/tests/drm_fixp_test.c create mode 100644 drivers/gpu/drm/vkms/Kconfig create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/vkms_color_tests.c create mode 100644 drivers/gpu/drm/vkms/vkms_colorop.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.h create mode 100644 include/drm/drm_colorop.h--
2.44.0
Quoted 28 lines · Harry Wentland
Quoted 25 lines · Melissa Wen
Quoted 23 lines · Harry Wentland
This is an RFC set for a color pipeline API, along with a sample implementation in VKMS. All the key API bits are here. VKMS now supports two named transfer function colorops and two matrix colorops. We have IGT tests that check all four of these colorops with a pixel-by-pixel comparison that checks that these colorops do what we expect them to do with a +/- 1 8 bpc code point margin.
The big new change with v4 is the addition of an amdgpu color pipeline, for all AMD GPUs with DCN 3 and newer. Amdgpu now support the following:
1. 1D Curve EOTF
2. 3x4 CTM
3. Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 1D Curve EOTF
7. 1D LUTThe supported curves for the 1D Curve type are:
- sRGB EOTF and its inverse
- PQ EOTF, scaled to [0.0, 125.0] and its inverse
- BT.2020/BT.709 OETF and its inverse
Quoted 6 lines
Quoted 6 lines
So, as we talked in the 2024 Linux Display Next Hackfest, I hacked
drm_infoto show the KMS color pipeline properties. You can find the experimental-and-ugly code here:
- https://gitlab.freedesktop.org/mwen/drm_info/-/merge_requests/1
It depends on updating libdrm [1] and you will only see something if you use a custom kernel with this series applied.
Hi all,
In the hackfest, we discussed that compositors should exercise this proposal and validate the API defined in this version, and only after that would we resume the effort in the kernel.
So, where is the best place to track this progress on compositors side?
[...]
Quoted 3 lines
Btw, I can't seem to access your MR but found the
kms_colorbranch on your fork ofdrm_info.
Oops, I've changed permissions and the MR is visible now. Thanks for pointing this issue.
Melissa
Quoted 233 lines
Harry
Quoted 229 lines
BR,
Melissa
Quoted 225 lines
Note that the 1st and 5th colorops take the EOTF or Inverse OETF while the 3rd colorop takes the Inverse EOTF or OETF.
We are working on two more ops for amdgpu, the HDR multiplier and the 3DLUT, which will give us this:
1. 1D Curve EOTF
2. 3x4 CTM
3. HDR Multiplier
4. 1D Curve Inverse EOTF
5. 1D LUT
6. 3D LUT
7. 1D Curve EOTF
8. 1D LUTThis, essentially mirrors the color pipeline used by gamescope
and presented by Melissa Wen, with the exception of the DEGAM
LUT, which is not currently used. See
[1] https://indico.freedesktop.org/event/4/contributions/186/attachments/138/218/xdc2023-TheRainbowTreasureMap-MelissaWen.pdfAfter this we'd like to also add the following ops:
- Scaler (Informational only)
- Color Encoding, to replace drm_plane'sCOLOR_ENCODING
- Color Range, to replace drm_plane'sCOLOR_RANGEThis patchset is grouped as follows:
- Patches 1-3: couple general patches/fixes
- Patches 4-7: introduce kunit to VKMS
- Patch 7: description of motivation and details behind the Color Pipeline API. If you're reading nothing else but are interested in the topic I highly recommend you take a look at this.
- Patches 7-27: DRM core and VKMS changes for color pipeline API
- Patches 28-40: DRM core and amdgpu changes for color pipeline APIVKMS patches could still be improved in a few ways, though the payoff might be limited and I would rather focus on other work at the moment. The most obvious thing to improve would be to eliminate the hard-coded LUTs for identity, and sRGB, and replace them with fixed-point math instead.
There are plenty of things that I would like to see here but haven't had a chance to look at. These will (hopefully) be addressed in future iterations, either in VKMS or amdgpu:
- Clear documentation for eachdrm_colorop_type
- Add custom LUT colorops to VKMS
- Add pre-blending 3DLUT
- How to support HW which can't bypass entire pipeline?
- Add ability to create colorops that don't have BYPASS
- Can we do a LOAD / COMMIT model for LUTs (and other properties)?
- read-only scaling colorop which defines scaling taps and position
- read-only color format colorop to define supported color formats for a pipeline
- named matrices, for things like converting YUV to RGBIGT tests can be found at
https://gitlab.freedesktop.org/hwentland/igt-gpu-tools/-/merge_requests/1IGT patches are also being sent to the igt-dev mailing list.
If you prefer a gitlab MR for review you can find it at
https://gitlab.freedesktop.org/hwentland/linux/-/merge_requests/5v4:
- Add amdgpu color pipeline (WIP)
- Don't block setting of deprecated properties, instead pass client cap to atomic check so drivers can ignore these props
- Drop IOCTL definitions (Pekka)
- Use enum property for colorop TYPE (Pekka)
- A few cleanups to the docs (Pekka)
- Rework the TYPE enum to name relation to avoid code duplication (Pekka)
- Add missing function declarations (Chaitanya Kumar Borah)
- Allow setting of NEXT property to NULL in _set_ function (Chaitanya Kumar Borah)
- Add helper for creation of pipelinedrm_planeproperty (Pekka)
- Always create Bypass pipeline (Pekka)
- A bunch of changes to VKMS kunit tests (Pekka)
- Fix index in CTM doc (Pekka)v3:
- Abandon IOCTLs and discover colorops as clients iterate the pipeline
- Remove need for libdrm
- Addcolor_pipelineclient cap and make mutually exclusive withCOLOR_RANGEandCOLOR_ENCODINGproperties
- add CTM colorop to VKMS
- Use include way for kunit testing static functions (Arthur)
- Make TYPE a range property
- Move enumdrm_colorop_typeto uapi header
- and a bunch of smaller bits that are highlighted in the relevant commit descriptionv2:
- Rebased on drm-misc-next
- Introduce a VKMS Kunit so we can test LUT functionality invkms_composer
- Incorporate feedback incolor_pipeline.rstdoc
- Add support for sRGB inverse EOTF
- Add 2nd enumerated TF colorop to VKMS
- Fix LUTs and some issues with applying LUTs in VKMSCc Ville Syrjala <[email protected]>Cc Pekka Paalanen <[email protected]>Cc Simon Ser <[email protected]>Cc Harry Wentland <[email protected]>Cc Melissa Wen <[email protected]>Cc Jonas Ådahl <[email protected]>Cc Sebastian Wick <[email protected]>Cc Shashank Sharma <[email protected]>Cc Alexander Goins <[email protected]>Cc Joshua Ashton <[email protected]>Cc Michel Dänzer <[email protected]>Cc Aleix Pol <[email protected]>Cc Xaver Hugl <[email protected]>Cc Victoria Brekenfeld <[email protected]>Cc Sima <[email protected]>Cc Uma Shankar <[email protected]>Cc Naseer Ahmed <[email protected]>Cc Christopher Braga <[email protected]>Cc Abhinav Kumar <[email protected]>Cc Arthur Grillo <[email protected]>Cc Hector Martin <[email protected]>Cc Liviu Dudau <[email protected]>Cc Sasha McIntosh <[email protected]>Cc Chaitanya Kumar Borah <[email protected]>Alex Hung (10):
drm/colorop: define a new macrofor_each_new_colorop_in_statedrm/amd/display: Skip color pipeline initialization for cursor plane drm/amd/display: Add support for sRGB EOTF in DEGAM block drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block drm/amd/display: Add support for sRGB EOTF in BLND block drm/colorop: Add 1D Curve Custom LUT type
drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT drm/amd/display: add 3x4 matrix colorop
drm/colorop: Add mutliplier type
drm/amd/display: add multiplier coloropHarry Wentland (32):
drm: Don't treat 0 as -1 indrm_fixp2int_ceil
drm: Add helper for conversion from signed-magnitude
drm: Correctly round forfixp2int_round
drm/vkms: Round fixp2int conversion inlerp_u16
drm/vkms: Create separateKconfigfile for VKMS
drm/vkms: Add kunit tests for VKMS LUT handling
drm/vkms: Avoid reading beyond LUT array
drm/doc/rfc: Describe why prescriptive color pipeline is needed drm/colorop: Introduce newdrm_coloropmode object drm/colorop: Add TYPE property
drm/colorop: Add 1D Curve subtype
drm/colorop: Add BYPASS property
drm/colorop: Add NEXT property
drm/colorop: Add atomic state print fordrm_coloropdrm/plane: Add COLOR PIPELINE property
drm/colorop: Add NEXT to colorop state print
drm/vkms: Add enumerated 1D curve colorop
drm/vkms: Add kunit tests for linear and sRGB LUTs drm/colorop: IntroduceDRM_CLIENT_CAP_PLANE_COLOR_PIPELINEdrm/colorop: Add 3x4 CTM type
drm/vkms: Pullapply_coloropout ofpre_blend_color_transformdrm/vkms: Use s32 for internal color pipeline precision drm/vkms: add 3x4 matrix in color pipeline
drm/tests: Add a few tests arounddrm_fixed.h
drm/vkms: Add tests for CTM handling
drm/colorop: passplane_color_pipelineclient cap to atomic check drm/amd/display: Ignore deprecated props whenplane_color_pipelineset drm/amd/display: Add bypass COLOR PIPELINE
drm/colorop: Add PQ 125 EOTF and its inverse drm/amd/display: Enable support for PQ 125 EOTF and Inverse drm/colorop: add BT2020/BT709 OETF and Inverse OETF drm/amd/display: Add support for BT.709 and BT.2020 TFsDocumentation/gpu/rfc/color_pipeline.rst | 360 ++++++++ drivers/gpu/drm/Kconfig | 14 +- drivers/gpu/drm/Makefile | 1 + .../gpu/drm/amd/display/amdgpu_dm/Makefile | 3 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 4 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 352 ++++++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.c | 160 ++++ .../amd/display/amdgpu_dm/amdgpu_dm_colorop.h | 36 + .../amd/display/amdgpu_dm/amdgpu_dm_plane.c | 32 + drivers/gpu/drm/drm_atomic.c | 161 +++- drivers/gpu/drm/drm_atomic_helper.c | 12 + drivers/gpu/drm/drm_atomic_state_helper.c | 5 + drivers/gpu/drm/drm_atomic_uapi.c | 158 ++++ drivers/gpu/drm/drm_colorop.c | 411 +++++++++ drivers/gpu/drm/drm_ioctl.c | 7 + drivers/gpu/drm/drm_mode_config.c | 7 + drivers/gpu/drm/drm_plane.c | 52 ++ drivers/gpu/drm/tests/Makefile | 3 +- drivers/gpu/drm/tests/drm_fixp_test.c | 69 ++ drivers/gpu/drm/vkms/Kconfig | 20 + drivers/gpu/drm/vkms/Makefile | 4 +- drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/vkms_color_tests.c | 449 ++++++++++ drivers/gpu/drm/vkms/vkms_colorop.c | 100 +++ drivers/gpu/drm/vkms/vkms_composer.c | 135 ++- drivers/gpu/drm/vkms/vkms_drv.h | 8 + drivers/gpu/drm/vkms/vkms_luts.c | 802 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_luts.h | 12 + drivers/gpu/drm/vkms/vkms_plane.c | 2 + include/drm/drm_atomic.h | 122 +++ include/drm/drm_atomic_uapi.h | 3 + include/drm/drm_colorop.h | 301 +++++++ include/drm/drm_file.h | 7 + include/drm/drm_fixed.h | 35 +- include/drm/drm_mode_config.h | 18 + include/drm/drm_plane.h | 13 + include/uapi/drm/drm.h | 16 + include/uapi/drm/drm_mode.h | 14 + 38 files changed, 3882 insertions(+), 30 deletions(-) create mode 100644 Documentation/gpu/rfc/color_pipeline.rst create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.c create mode 100644 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_colorop.h create mode 100644 drivers/gpu/drm/drm_colorop.c create mode 100644 drivers/gpu/drm/tests/drm_fixp_test.c create mode 100644 drivers/gpu/drm/vkms/Kconfig create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/vkms_color_tests.c create mode 100644 drivers/gpu/drm/vkms/vkms_colorop.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.c create mode 100644 drivers/gpu/drm/vkms/vkms_luts.h create mode 100644 include/drm/drm_colorop.h--
2.44.0