Re: [PATCH] drm/atomic: add quirks for blind save/restore

2022-11-17 Thread Pekka Paalanen
On Thu, 17 Nov 2022 07:54:40 +
Simon Ser  wrote:

> Two quirks to make blind atomic save/restore [1] work correctly:
> 
> - Mark the DPMS property as immutable for atomic clients, since
>   atomic clients cannot change it.
> - Allow user-space to set content protection to "enabled", interpret
>   it as "desired".
> 
> [1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3794
> 
> Signed-off-by: Simon Ser 

That seems to be the sensible thing to do to these properties.

Acked-by: Pekka Paalanen 

I'm really to happy see wlroots doing this. This has been in my mind to
do in Weston for years, but never had the chance to implement it yet. I
have just one little detail different: I would snapshot the "original"
KMS state at Weston start-up only once, and then use that snapshot as
the base every time Weston needs to sanitize the KMS state, like when
re-gaining DRM master. It's a bit more complicated, but it goes better
with the idea of resetting KMS state or starting from clean state, in
case KMS ever gains UAPI for that.


Thanks,
pq

> ---
> 
> I don't have the motivation to write IGT tests for this.
> 
>  drivers/gpu/drm/drm_atomic_uapi.c | 5 +++--
>  drivers/gpu/drm/drm_property.c| 7 +++
>  2 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_atomic_uapi.c 
> b/drivers/gpu/drm/drm_atomic_uapi.c
> index c06d0639d552..95363aac7f69 100644
> --- a/drivers/gpu/drm/drm_atomic_uapi.c
> +++ b/drivers/gpu/drm/drm_atomic_uapi.c
> @@ -741,8 +741,9 @@ static int drm_atomic_connector_set_property(struct 
> drm_connector *connector,
>   state->scaling_mode = val;
>   } else if (property == config->content_protection_property) {
>   if (val == DRM_MODE_CONTENT_PROTECTION_ENABLED) {
> - drm_dbg_kms(dev, "only drivers can set CP Enabled\n");
> - return -EINVAL;
> + /* Degrade ENABLED to DESIRED so that blind atomic
> +  * save/restore works as intended. */
> + val = DRM_MODE_CONTENT_PROTECTION_DESIRED;
>   }
>   state->content_protection = val;
>   } else if (property == config->hdcp_content_type_property) {
> diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
> index dfec479830e4..dde42986f8cb 100644
> --- a/drivers/gpu/drm/drm_property.c
> +++ b/drivers/gpu/drm/drm_property.c
> @@ -474,7 +474,14 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
>   return -ENOENT;
>  
>   strscpy_pad(out_resp->name, property->name, DRM_PROP_NAME_LEN);
> +
>   out_resp->flags = property->flags;
> + if (file_priv->atomic && property == dev->mode_config.dpms_property) {
> + /* Quirk: indicate that the legacy DPMS property is not
> +  * writable from atomic user-space, so that blind atomic
> +  * save/restore works as intended. */
> + out_resp->flags |= DRM_MODE_PROP_IMMUTABLE;
> + }
>  
>   value_count = property->num_values;
>   values_ptr = u64_to_user_ptr(out_resp->values_ptr);



pgpYVnmf_1frG.pgp
Description: OpenPGP digital signature


Re: [PATCH v3 0/6] Add support for atomic async page-flips

2022-11-17 Thread Simon Ser
Ville, any news on this?


Re: [PATCH] drm/atomic: add quirks for blind save/restore

2022-11-17 Thread Daniel Vetter
On Thu, Nov 17, 2022 at 07:54:40AM +, Simon Ser wrote:
> Two quirks to make blind atomic save/restore [1] work correctly:
> 
> - Mark the DPMS property as immutable for atomic clients, since
>   atomic clients cannot change it.
> - Allow user-space to set content protection to "enabled", interpret
>   it as "desired".
> 
> [1]: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/3794
> 
> Signed-off-by: Simon Ser 

Reviewed-by: Daniel Vetter 

I think a doc patch which documents the guarantees we're trying to make
here and that they're uapi would be really nice. Maybe somewhere in the
KMS properties section in the docs.
-Daniel

> ---
> 
> I don't have the motivation to write IGT tests for this.
> 
>  drivers/gpu/drm/drm_atomic_uapi.c | 5 +++--
>  drivers/gpu/drm/drm_property.c| 7 +++
>  2 files changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_atomic_uapi.c 
> b/drivers/gpu/drm/drm_atomic_uapi.c
> index c06d0639d552..95363aac7f69 100644
> --- a/drivers/gpu/drm/drm_atomic_uapi.c
> +++ b/drivers/gpu/drm/drm_atomic_uapi.c
> @@ -741,8 +741,9 @@ static int drm_atomic_connector_set_property(struct 
> drm_connector *connector,
>   state->scaling_mode = val;
>   } else if (property == config->content_protection_property) {
>   if (val == DRM_MODE_CONTENT_PROTECTION_ENABLED) {
> - drm_dbg_kms(dev, "only drivers can set CP Enabled\n");
> - return -EINVAL;
> + /* Degrade ENABLED to DESIRED so that blind atomic
> +  * save/restore works as intended. */
> + val = DRM_MODE_CONTENT_PROTECTION_DESIRED;
>   }
>   state->content_protection = val;
>   } else if (property == config->hdcp_content_type_property) {
> diff --git a/drivers/gpu/drm/drm_property.c b/drivers/gpu/drm/drm_property.c
> index dfec479830e4..dde42986f8cb 100644
> --- a/drivers/gpu/drm/drm_property.c
> +++ b/drivers/gpu/drm/drm_property.c
> @@ -474,7 +474,14 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
>   return -ENOENT;
>  
>   strscpy_pad(out_resp->name, property->name, DRM_PROP_NAME_LEN);
> +
>   out_resp->flags = property->flags;
> + if (file_priv->atomic && property == dev->mode_config.dpms_property) {
> + /* Quirk: indicate that the legacy DPMS property is not
> +  * writable from atomic user-space, so that blind atomic
> +  * save/restore works as intended. */
> + out_resp->flags |= DRM_MODE_PROP_IMMUTABLE;
> + }
>  
>   value_count = property->num_values;
>   values_ptr = u64_to_user_ptr(out_resp->values_ptr);
> -- 
> 2.38.1
> 
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


Re: The state of Quantization Range handling

2022-11-17 Thread Sebastian Wick
Hi Dave,

I noticed that I didn't get the Broadcast RGB property thanks to you
(more below)

On Tue, Nov 15, 2022 at 2:16 PM Dave Stevenson
 wrote:
>
> Hi Sebastian
>
> Thanks for starting the conversation - it's stalled a number of times
> previously.
>
> On Mon, 14 Nov 2022 at 23:12, Sebastian Wick  
> wrote:
> >
> > There are still regular bug reports about monitors (sinks) and sources
> > disagreeing about the quantization range of the pixel data. In
> > particular sources sending full range data when the sink expects
> > limited range. From a user space perspective, this is all hidden in
> > the kernel. We send full range data to the kernel and then hope it
> > does the right thing but as the bug reports show: some combinations of
> > displays and drivers result in problems.
>
> I'll agree that we as Raspberry Pi also get a number of bug reports
> where sinks don't always look at the infoframes and misinterpret the
> data.
>
> > In general the whole handling of the quantization range on linux is
> > not defined or documented at all. User space sends full range data
> > because that's what seems to work most of the time but technically
> > this is all undefined and user space can not fix those issues. Some
> > compositors have resorted to giving users the option to choose the
> > quantization range but this really should only be necessary for
> > straight up broken hardware.
>
> Wowsers! Making userspace worry about limited range data would be a
> very weird decision in my view, so compositors should always deal in
> full range data.

Making this a user space problem is IMO the ideal way to deal with it
but that's a bit harder to do (I'll answer that in the reply to
Pekka). So let's just assume we all agree that user space only deals
with full range data.

> How would composition of multiple DRM planes work if some are limited
> range and some are full but you want limited range output? Your
> hardware needs to have CSC matrices to convert full range down to
> limited range, and know that you want to use them to effectively
> compose to limited range.
> In fact you can't currently tell DRM that an RGB plane is limited
> range - the values in enum drm_color_range are
> DRM_COLOR_YCBCR_LIMITED_RANGE and DRM_COLOR_YCBCR_FULL_RANGE [1].
>
> > Quantization Range can be explicitly controlled by AVI InfoFrame or
> > HDMI General Control Packets. This is the ideal case and when the
> > source uses them there is not a lot that can go wrong. Not all
> > displays support those explicit controls in which case the chosen
> > video format (IT, CE, SD; details in CTA-861-H 5.1) influences which
> > quantization range the sink expects.
> >
> > This means that we have to expect that sometimes we have to send
> > limited and sometimes full range content. The big question however
> > that is not answered in the docs: who is responsible for making sure
> > the data is in the correct range? Is it the kernel or user space?
> >
> > If it's the kernel: does user space supply full range or limited range
> > content? Each of those has a disadvantage. If we send full range
> > content and the driver scales it down to limited range, we can't use
> > the out-of-range bits to transfer information. If we send limited
> > range content and the driver scales it up we lose information.
>
> How often have you encountered the out-of-range bits being used?
> Personally I've never come across it. Is it really that common?
> If trying to pass non-video data from the client then you need to pray
> there is no scaling or filtering during composition as it could
> legitimately be corrupted.

All true, and personally I've also never encountered this which is why
I'd like to ignore all of that for now.

>
> > Either way, this must be documented. My suggestion is to say that the
> > kernel always expects full range data as input and is responsible for
> > scaling it to limited range data if the sink expects limited range
> > data.
>
> AIUI That is the current situation. It certainly fits the way that all
> our hardware works.
>
> > Another problem is that some displays do not behave correctly. It must
> > be possible to override the kernel when the user detects such a
> > situation. This override then controls if the driver converts the full
> > range data coming from the client or not (Default, Force Limited,
> > Force Full). It does not try to control what range the sink expects.
>
> Sorry, I'm not clear from the description. Is this a plane, crtc, or
> connector property?
>
> "Data coming from the client" would imply a plane property only -
> effectively extending enum drm_color_range for RGB formats.
>
> If it is a connector property then what do you mean by not controlling
> the range? It doesn't change the AVI Infoframe or GCP and leaves the
> sink thinking it is the default? If so, doesn't that mean this control
> can now make a compliant sink incorrectly render the data? Assuming
> the driver is using drm_hdmi_avi_infoframe_quant_range [2

Re: The state of Quantization Range handling

2022-11-17 Thread Sebastian Wick
Hi Yussuf,

On Tue, Nov 15, 2022 at 5:26 PM Yussuf Khalil  wrote:
>
> Hello Sebastian,
>
> I've previously done some work on this topic [1]. My efforts were mostly about
> fixing the situation regarding overrides and providing proper means for
> userspace. I am affected by the issue myself as I own several DELL U2414H
> screens that declare a CE mode as their preferred one, but should receive full
> range data nonetheless. They do not have the respective bit set in their EDID
> to indicate full range support either.
>
> My implementation primarily moved the "Broadcast RGB" to DRM core and re-wired
> it in i915 and gma500. I further added a flag to indicate CE modes to 
> userspace
> so that apps such as gnome-control-center can clearly communicate whether full
> or limited range would be used by default. A v2 branch that I never submitted
> is available at [2]. I also have some code lying around locally that adds the
> required functionality to mutter and gnome-control-center.

Yeah, I now agree that moving the "Broadcast RGB" to DRM core would be
a good decision. The slight behavior change I want to see can be done
afterwards as well. Not so sure about indicating CE modes because
there are other factors (YCC vs RGB, the connector type and version)
which influence the default quantization range.

>
> I had to pause work on the issue back then and never really came around to
> picking it up again, however, I would be interested in working on it again if
> there is consensus on the direction that my patches laid out. I did not
> consider use cases for the out-of-range bits though.

I think we can safely ignore out-of-range bits for now and good to
know you're on board.

>
> Regards
> Yussuf
>
> [1] 
> https://patchwork.kernel.org/project/dri-devel/cover/20200413214024.46500-1-...@pp3345.net/
> [2] https://github.com/pp3345/linux/commits/rgb-quant-range-v2
>
> On 15.11.22 00:11, Sebastian Wick wrote:
> > There are still regular bug reports about monitors (sinks) and sources
> > disagreeing about the quantization range of the pixel data. In
> > particular sources sending full range data when the sink expects
> > limited range. From a user space perspective, this is all hidden in
> > the kernel. We send full range data to the kernel and then hope it
> > does the right thing but as the bug reports show: some combinations of
> > displays and drivers result in problems.
> >
> > In general the whole handling of the quantization range on linux is
> > not defined or documented at all. User space sends full range data
> > because that's what seems to work most of the time but technically
> > this is all undefined and user space can not fix those issues. Some
> > compositors have resorted to giving users the option to choose the
> > quantization range but this really should only be necessary for
> > straight up broken hardware.
> >
> > Quantization Range can be explicitly controlled by AVI InfoFrame or
> > HDMI General Control Packets. This is the ideal case and when the
> > source uses them there is not a lot that can go wrong. Not all
> > displays support those explicit controls in which case the chosen
> > video format (IT, CE, SD; details in CTA-861-H 5.1) influences which
> > quantization range the sink expects.
> >
> > This means that we have to expect that sometimes we have to send
> > limited and sometimes full range content. The big question however
> > that is not answered in the docs: who is responsible for making sure
> > the data is in the correct range? Is it the kernel or user space?
> >
> > If it's the kernel: does user space supply full range or limited range
> > content? Each of those has a disadvantage. If we send full range
> > content and the driver scales it down to limited range, we can't use
> > the out-of-range bits to transfer information. If we send limited
> > range content and the driver scales it up we lose information.
> >
> > Either way, this must be documented. My suggestion is to say that the
> > kernel always expects full range data as input and is responsible for
> > scaling it to limited range data if the sink expects limited range
> > data.
> >
> > Another problem is that some displays do not behave correctly. It must
> > be possible to override the kernel when the user detects such a
> > situation. This override then controls if the driver converts the full
> > range data coming from the client or not (Default, Force Limited,
> > Force Full). It does not try to control what range the sink expects.
> > Let's call this the Quantization Range Override property which should
> > be implemented by all drivers.
> >
> > All drivers should make sure their behavior is correct:
> >
> > * check that drivers choose the correct default quantization range for
> > the selected mode
> > * whenever explicit control is available, use it and set the
> > quantization range to full
> > * make sure that the hardware converts from full range to limited
> > range whenever the sink expects limited range
> 

Re: The state of Quantization Range handling

2022-11-17 Thread Sebastian Wick
On Wed, Nov 16, 2022 at 1:34 PM Pekka Paalanen  wrote:
>
> On Tue, 15 Nov 2022 00:11:56 +0100
> Sebastian Wick  wrote:
>
> > There are still regular bug reports about monitors (sinks) and sources
> > disagreeing about the quantization range of the pixel data. In
> > particular sources sending full range data when the sink expects
> > limited range. From a user space perspective, this is all hidden in
> > the kernel. We send full range data to the kernel and then hope it
> > does the right thing but as the bug reports show: some combinations of
> > displays and drivers result in problems.
> >
> > In general the whole handling of the quantization range on linux is
> > not defined or documented at all. User space sends full range data
> > because that's what seems to work most of the time but technically
> > this is all undefined and user space can not fix those issues. Some
> > compositors have resorted to giving users the option to choose the
> > quantization range but this really should only be necessary for
> > straight up broken hardware.
> >
> > Quantization Range can be explicitly controlled by AVI InfoFrame or
> > HDMI General Control Packets. This is the ideal case and when the
> > source uses them there is not a lot that can go wrong. Not all
> > displays support those explicit controls in which case the chosen
> > video format (IT, CE, SD; details in CTA-861-H 5.1) influences which
> > quantization range the sink expects.
> >
> > This means that we have to expect that sometimes we have to send
> > limited and sometimes full range content. The big question however
> > that is not answered in the docs: who is responsible for making sure
> > the data is in the correct range? Is it the kernel or user space?
> >
> > If it's the kernel: does user space supply full range or limited range
> > content? Each of those has a disadvantage. If we send full range
> > content and the driver scales it down to limited range, we can't use
> > the out-of-range bits to transfer information. If we send limited
> > range content and the driver scales it up we lose information.
> >
> > Either way, this must be documented. My suggestion is to say that the
> > kernel always expects full range data as input and is responsible for
> > scaling it to limited range data if the sink expects limited range
> > data.
>
> Hi Sebastian,
>
> you are proposing the that driver/hardware will do either no range
> conversion, or full-to-limited range conversion. Limited-to-full range
> conversion would never be supported.
>
> I still wonder if limited-to-full range conversion could be useful with
> video content.
>
> > Another problem is that some displays do not behave correctly. It must
> > be possible to override the kernel when the user detects such a
> > situation. This override then controls if the driver converts the full
> > range data coming from the client or not (Default, Force Limited,
> > Force Full). It does not try to control what range the sink expects.
> > Let's call this the Quantization Range Override property which should
> > be implemented by all drivers.
>
> In other words, a CRTC "quantization range conversion" property with
> values:
> - auto, with the assumption that color pipeline always produces full-range
> - identity
> - full-to-limited
> (- limited-to-full)
>
> If this property was truly independent of the metadata being sent to
> the sink, and of the framebuffer format, it would allow us to do four
> ways: both full/limited framebuffer on both full/limited sink. It would
> allow us to send sub-blacks and super-whites as well.
>
> More precisely, framebuffers would always have *undefined* quantization
> range. The configuration of the color pipeline then determines how that
> data is manipulated into a video signal.
>
> So I am advocating the same design as with color spaces: do not tell
> KMS what your colorspaces are. Instead tell KMS what operations it
> needs to do with the pixel data, and what metadata to send to the sink.
>
> > All drivers should make sure their behavior is correct:
> >
> > * check that drivers choose the correct default quantization range for
> > the selected mode
>
> Mode implying a quantization range is awkward, but maybe the kernel
> established modes should just have a flag for it. Then userspace would
> know. Unless the video mode system is extended to communicate
> IT/CE/SD/VIC and whatnot to userspace, making the modes better defined.
> Then userspace would know too.
>
> > * whenever explicit control is available, use it and set the
> > quantization range to full
> > * make sure that the hardware converts from full range to limited
> > range whenever the sink expects limited range
> > * implement the Quantization Range Override property
> >
> > I'm volunteering for the documentation, UAPI and maybe even the drm
> > core parts if there is willingness to tackle the issue.
>
> Is it a good idea to put even more automation/magic into configuring
> the color pipeline and metadata for a