After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 793339 - kmssink: Renders at half my display refresh rate
kmssink: Renders at half my display refresh rate
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other Linux
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2018-02-09 16:18 UTC by Nicolas Dufresne (ndufresne)
Modified: 2018-11-03 14:17 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Skip VSYNC wait for synchronous SetPlane call (2.05 KB, patch)
2018-03-09 20:17 UTC, Devarsh Thakkar
none Details | Review
The drm patch in rockchip 4.4 (854 bytes, patch)
2018-04-15 10:40 UTC, Randy Li (ayaka)
rejected Details | Review
WIP: kmssink: Skip sync when atomic driver is detected (2.12 KB, patch)
2018-04-24 19:32 UTC, Nicolas Dufresne (ndufresne)
rejected Details | Review

Description Nicolas Dufresne (ndufresne) 2018-02-09 16:18:39 UTC
While doing some latency test, I notice that kmssink renders at half the speed of my display. My test pipeline was:

gst-launch-1.0 -v videotestsrc ! video/x-raw,framerate=60/1 ! fpsdisplaysink text-overlay=0 video-sink=kmssink

Commenting out the code that (according to comment) tries to wait for previous frame to finish fixes it.

https://cgit.freedesktop.org/gstreamer/gst-plugins-bad/tree/sys/kms/gstkmssink.c#n1499

My impression is that we endup waiting for an extra vblank all the time as the previous blank is behind.
Comment 1 Devarsh Thakkar 2018-03-09 20:17:21 UTC
Created attachment 369527 [details] [review]
Skip VSYNC wait for synchronous SetPlane call

The new atomic DRM driver implements synchronous
DRM_IOCTL_MODE_SETPLANE ioctl which unlike
legacy DRM driver blocks until a VSYNC is done.

As a workaround we skip the explicit wait for VSYNC done
using drmWaitVBlank and drmModePageFlip whenever
drmModeSetPlane is used by an atomic DRM driver, until
kmssink starts supporting fully atomic DRM drivers.
Comment 2 Devarsh Thakkar 2018-03-09 20:18:53 UTC
Hi,

Attached a proposed fix, tested on xilinx platform which uses atomic DRM API.
Appreciate review for the same.

Thanks,
Devarsh
Comment 3 Víctor Manuel Jáquez Leal 2018-03-28 15:45:36 UTC
Hi Devarsh,

Sorry for the delay.

If I understand correctly, although related, your patch doesn't fix the case reported by Nicolas.

I recommend you is to open a new bug report with your patch.
Comment 4 Nicolas Dufresne (ndufresne) 2018-03-28 18:02:01 UTC
Hey Victor,

I think this patche partially fixes the issue I have describe here. It fixes it for Atomic drivers, as the legacy implementation completely ignores async page flip calls, and make a synchronous commit internally. So doing pageflip or waiting for vlank with any atomic drivers means that you will likely wait for an extra blank, hence reducing the render rate by two. It's partial, because some driver ended up with that behaviour before their transition to atomic, to get rid of the tearing.

There is the other issue I've showed you on IRC yesterday, and that one need another bug, I'll file one today.
Comment 5 Randy Li (ayaka) 2018-04-15 10:40:07 UTC
Created attachment 370952 [details] [review]
The  drm patch in rockchip 4.4

I talked to ndufresne in the IRC, in the rockchip kernel, we adapt a new method to solve the performance problem with 4k video. This patch won't solve the performance unless modified the kernel.

Here is the log without the kernel patch I uploaded, it looks

root@firefly-rk3288:~# gst-launch-1.0 --gst-debug=kmssink:5 filesrc location=videos/tokyo_2013_4k.mp4 ! qtdemux ! h264parse ! mppv
ideodec ! queue ! kmssink                                                                                                                                       
Setting pipeline to PAUSED ...                                                                                                    
0:00:00.562194390   393   0x137460 INFO                 kmssink gstkmssink.c:358:log_drm_version:<kmssink0> DRM v1.0.0 [rockchip —
 RockChip Soc DRM — 20140818]                                                                                                     
0:00:00.562868432   393   0x137460 INFO                 kmssink gstkmssink.c:405:get_drm_caps:<kmssink0> prime import (✓) / prime 
export (✓) / async page flip (✗)                                                                                            
0:00:00.563487057   393   0x137460 DEBUG                kmssink gstkmssink.c:616:gst_kms_sink_start:<kmssink0> Atomic modesetting 
support enabled                                                                                                                   
0:00:00.573946517   393   0x137460 INFO                 kmssink gstkmssink.c:539:ensure_allowed_caps:<kmssink0> ignoring format RG
24                                  
....
0:00:00.641102898   393   0x119400 DEBUG                kmssink gstkmssink.c:1034:gst_kms_sink_set_caps:<kmssink0> negotiated cap$
 = video/x-raw, format=(string)NV12, width=(int)3840, height=(int)2160, interlace-mode=(string)progressive, multiview-mode=(strin$
)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flop$
ed/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt2020, framerate=(fr$
ction)24/1                                                                                                                        
0:00:00.641244648   393   0x119400 DEBUG                kmssink gstkmssink.c:1557:gst_kms_sink_drain:<kmssink0> draining          
Pipeline is PREROLLED ...                                                                                                         
Setting pipeline to PLAYING ...                                                                                                   
New clock: GstSystemClock                                                                                                         
WARNING: from element /GstPipeline:pipeline0/GstKMSSink:kmssink0: A lot of buffers are being dropped.                             
Additional debug info:                                                                                                            
../../../../git/libs/gst/base/gstbasesink.c(2902): gst_base_sink_is_too_late (): /GstPipeline:pipeline0/GstKMSSink:kmssink0:      
There may be a timestamping problem, or this computer is too slow.
WARNING: from element /GstPipeline:pipeline0/GstKMSSink:kmssink0: A lot of buffers are being dropped.
Additional debug info:
../../../../git/libs/gst/base/gstbasesink.c(2902): gst_base_sink_is_too_late (): /GstPipeline:pipeline0/GstKMSSink:kmssink0:
There may be a timestamping problem, or this computer is too slow.
WARNING: from element /GstPipeline:pipeline0/GstKMSSink:kmssink0: A lot of buffers are being dropped.
Additional debug info:
../../../../git/libs/gst/base/gstbasesink.c(2902): gst_base_sink_is_too_late (): /GstPipeline:pipeline0/GstKMSSink:kmssink0:
There may be a timestamping problem, or this computer is too slow.
WARNING: from element /GstPipeline:pipeline0/GstKMSSink:kmssink0: A lot of buffers are being dropped.
Comment 6 Nicolas Dufresne (ndufresne) 2018-04-15 13:42:33 UTC
Kernel patches have no place here. Though thanks for sharing. What was the pipeline you are testing ? Did you add a queue right before kmssink ? Turning kmssink render into something async should be filed on seperate bug imho.
Comment 7 Nicolas Dufresne (ndufresne) 2018-04-15 16:15:01 UTC
Review of attachment 370952 [details] [review]:

.
Comment 8 Randy Li (ayaka) 2018-04-16 03:47:54 UTC
Yes, that patch is just used as a reference, It is not a good patch either, I just want to tell you what the rockchip does. It the pipeline can be found the previous post.
Comment 9 Nicolas Dufresne (ndufresne) 2018-04-20 12:40:24 UTC
After rethinking this, if this patches is needed, it means that KMS Atomic drivers are simply not backward compatible peformance whise. At the same time, I'm pretty sure Devarsh is getting full frame rate with this patch, and I also see full framerate on i915. I'm wondering what would triggers this on Rockchip ...
Comment 10 Nicolas Dufresne (ndufresne) 2018-04-24 19:32:15 UTC
Created attachment 371344 [details] [review]
WIP: kmssink: Skip sync when atomic driver is detected

DON'T MERGE, this causes regressions on Intel

Atomic driver emulates the mode setting in a way that it blocks until
the frame buffer is rendered. As a side effect, waiting for a vblank, or
page flips halves the frame rate.
Comment 11 Nicolas Dufresne (ndufresne) 2018-04-24 19:34:46 UTC
Patch didn't apply anymore, and just ended up rewriting it as it was not really following the code. This patch is not acceptable, because turning on that capability apparently breaks scaling on Intel, something Devarsh cannot test on his driver, has he got no scaling support. This patch is not going upstream.
Comment 12 Nicolas Dufresne (ndufresne) 2018-04-24 19:35:01 UTC
Review of attachment 371344 [details] [review]:

.
Comment 13 Daniel Stone 2018-04-24 19:47:55 UTC
(In reply to Nicolas Dufresne (ndufresne) from comment #9)
> After rethinking this, if this patches is needed, it means that KMS Atomic
> drivers are simply not backward compatible peformance whise. At the same
> time, I'm pretty sure Devarsh is getting full frame rate with this patch,
> and I also see full framerate on i915. I'm wondering what would triggers
> this on Rockchip ...

It's not a matter of atomic vs. non-atomic drivers, it's that there is absolutely no specification of what SetPlane does. Some drivers block until the next vblank to apply, and some do no blocking at all - even to the point of generating pagefaults and display glitches if you destroy a buffer which is still active on a plane.

Most atomic drivers wait until vblank, but not all (e.g. amdgpu still does it async, although I believe only on older hardware, and newer hardware has the blocking behaviour). Most non-atomic drivers are non-blocking, but some are blocking. Many drivers (e.g. exynos and I believe also rockchip) changed their behaviour with different kernel versions.

The only way to get predictable and reliable behaviour from KMS planes is to use the atomic API. This has always been the case, and is the reason why Weston never used planes unless the user explicitly enabled them with a magic key combination. On the other hand, using atomic allows us to enable use of overlay planes by default.

As an aside, the scaling behaviour is also completely unspecified when using SetPlane. If the hardware cannot apply the requested scaling factor, drivers may clip or enlarge either source or destination bounds completely arbitrarily in order to get _some_ kind of image on screen. This becomes an error in atomic, so it's possible that flipping the client cap on just exposes this rather than silent clipping or rounding.
Comment 14 Nicolas Dufresne (ndufresne) 2018-08-27 17:57:14 UTC
Just an update, it seems there is a move along making the emulation asynchronous (though likely racy) in order to better support this legacy usage of the API. I still think we could improve this legacy a little, by syncing before releasing a buffer, rather then after updating (late sync). This would also be less in the way when we add atomic support.
Comment 15 GStreamer system administrator 2018-11-03 14:17:58 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/issues/654.