This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How do I get stutter free playback with kwin+mpv?

Tags: None
(comma "," separated)
User avatar
Soukyuu
Registered Member
Posts
71
Karma
0
OS
I'm using a 260GTX with nvidia 340xx drivers (because nouveau is very bad for performance), and I'm so far unable to get both stutter and tear free playback with kwin.

If I leave compositing enabled, then playback stutters like crazy, no matter the settings I choose. Ticking "disable compositing for fullscreen windows" doesn't help to get rid off the stutters, but also breaks vsync.

I was using a rule that blocked compositing for mpv, which fixed the stutters, but tearing is still a problem. Sometimes I'm lucky and it stays at the edge of the screen so that I don't notice it, but most of the time it's very jarring. None of mpv internal functions to sync to vsync seem to help once compositing is blocked.

Some things I also tried is setting the vsync variables in /etc/profile
Code: Select all
export __GL_SYNC_TO_VBLANK=1
export __GL_SYNC_DISPLAY_DEVICE=DVI-I-2
export __VDPAU_NVIDIA_SYNC_DISPLAY_DEVICE=DVI-I-2
Double checking kwin is using the correct refresh rate
Code: Select all
[Compositing]
AnimationSpeed=0
Backend=OpenGL
Enabled=true
GLColorCorrection=false
GLCore=true
GLPlatformInterface=glx
GLPreferBufferSwap=a
GLTextureFilter=2
HiddenPreviews=5
OpenGLIsUnsafe=false
OpenGLIsUnsafe0=false
OpenGLIsUnsafe1=false
RefreshRate=60
UnredirectFullscreen=false
XRenderSmoothScale=false

[Desktops]
Number=2
Rows=2

[Desktops-screen-1]
Number=1

[Effect-Cube]
BorderActivate=9
BorderActivateCylinder=9
BorderActivateSphere=9

[Effect-DesktopGrid]
BorderActivate=9

[Effect-PresentWindows]
BorderActivate=9
BorderActivateAll=9
BorderActivateClass=9

[Effect-ShowFps]
TextAlpha=0.5
TextColor=0,255,255

[Effect-Zoom]
InitialZoom=1

[ElectricBorders]
Bottom=None
BottomLeft=ShowDesktop
BottomRight=None
Left=None
Right=None
Top=None
TopLeft=None
TopRight=None

[MouseBindings]
CommandActiveTitlebar1=Raise
CommandActiveTitlebar2=Start window tab drag
CommandActiveTitlebar3=Operations menu
CommandAll1=Move
CommandAll2=Toggle raise and lower
CommandAll3=Resize
CommandAllKey=Alt
CommandAllWheel=Nothing
CommandInactiveTitlebar1=Activate and raise
CommandInactiveTitlebar2=Start window tab drag
CommandInactiveTitlebar3=Operations menu
CommandTitlebarWheel=Switch to Window Tab to the Left/Right
CommandWindow1=Activate, raise and pass click
CommandWindow2=Activate and pass click
CommandWindow3=Activate and pass click
CommandWindowWheel=Scroll

[Plugins]
contrastEnabled=false
cubeslideEnabled=false
desktopchangeosdEnabled=false
kwin4_effect_fadedesktopEnabled=false
kwin4_effect_windowapertureEnabled=false
slideEnabled=true
windowgeometryEnabled=false

[Script-desktopchangeosd]
PopupHideDelay=1000
TextOnly=false

[TabBox]
BorderActivate=9
BorderAlternativeActivate=9

[Windows]
ActiveMouseScreen=false
AutoRaise=false
AutoRaiseInterval=750
AutogroupInForeground=true
AutogroupSimilarWindows=false
BorderSnapZone=10
CenterSnapZone=0
ClickRaise=true
DelayFocusInterval=300
ElectricBorderCooldown=350
ElectricBorderCornerRatio=0.25
ElectricBorderDelay=100
ElectricBorderMaximize=true
ElectricBorderTiling=true
ElectricBorders=0
FocusPolicy=ClickToFocus
FocusStealingPreventionLevel=1
GeometryTip=false
HideUtilityWindowsForInactive=true
InactiveTabsSkipTaskbar=false
MaximizeButtonLeftClickCommand=Maximize
MaximizeButtonMiddleClickCommand=Maximize (vertical only)
MaximizeButtonRightClickCommand=Maximize (horizontal only)
NextFocusPrefersMouse=false
Placement=UnderMouse
RollOverDesktops=true
SeparateScreenFocus=false
ShadeHover=false
ShadeHoverInterval=250
SnapOnlyWhenOverlapping=false
TitlebarDoubleClickCommand=Maximize
WindowSnapZone=10

[org.kde.kdecoration2]
BorderSize=Tiny
ButtonsOnLeft=MS
ButtonsOnRight=HIAX
CloseOnDoubleClickOnMenu=false
library=org.kde.breeze
theme[$d]
One might be inclined to conclude that it's mpv's fault - but here's the thing: I started an openbox/kde session with compton configured as
Code: Select all
compton --paint-on-overlay --unredir-if-possible --backend glx --glx-no-stencil --glx-no-rebind-pixmap
and it just works. No stutters. No tearing. Just smooth playback.
Now, why can't I have that with kwin?
luebking
Karma
0
If the mpv window is unredirected (fullscreen; for compton maybe more, depending on the settings) it /is/ mpv's "fault" - nothing else has impact on the visual output.

An increasing troublemaker reg. nvidia (and apparently notably on only double buffering systems) seems KWIN_EXPLICIT_SYNC
Code: Select all
export KWIN_EXPLICIT_SYNC=0


This syncing points control of OpenGL and X11 command streams, not vertical synchronisation.

also do *not* override swapcontrol for KWin ("__GL_SYNC_TO_VBLANK=1") - this will totally screw the internal timing estimations.
For mpv, it's only relevant if you render into the OpenGL sink, not vdpau or xv.
If you want v'sync on double buffer setups, "export __GL_YIELD=USLEEP" (upcase does matter), if there're issues on detecting triple buffering in kwin, do "export KWIN_TRIPLE_BUFFER=1".
User avatar
Soukyuu
Registered Member
Posts
71
Karma
0
OS
What I don't get is why it's mpv's fault when the only changing variable is compton vs kwin. kwin pretty much has to be doing something differently.

In any case, I tried first setting KWIN_EXPLICIT_SYNC=0, then added __GL_YIELD=USLEEP and then KWIN_TRIPLE_BUFFER=1, rebooting between each change. The behavior is unchanged: with unredirected window enabled there is tearing, with no unredirection there is stutter, but no tearing.

The __GL lines in /etc/profile were removed before that, though I didn't notice any impact of doing so. And yes, I'm using --vo=opengl-hq

edit: There is this message that says unredirection is not supported on every hardware. What happens in that case?
luebking
Karma
0
> kwin pretty much has to be doing something differently.

Repeat after me:
if the window is not redirected, the output goes from the client to the X11 server to the driver to the crtc to your screen. Other clients have *no* impact on it.

One option would be server grabs (ie. kwin grabs the server, it cannot perform any updates then) but while that could cause stutter, there's hardly an option for tearing.

mpv will toggle its swapcontrol depending on the presence of (known) compositors or similar.

__VDPAU_NVIDIA_SYNC_DISPLAY_DEVICE is irrelevant if you use the OpenGL sync.

don't export "KWIN_TRIPLE_BUFFER=1" unless you really configured the driver to perform triple buffering.

I'm not sure about your opinion of "stutter" in this case, but please notice that it's *completely* impossible to avoid judder when playing 23.976Hz or 25Hz material synced to a 60Hz screen. No matter whether synced directly or via a compositor (except when the player injects interpolated frames to increase the framerate - or performs smart swapcontrol management to paint some frames unsynced)

=> do you get the same "stutter" with compton without allowing unredirection?
luebking
Karma
0
PS: there might be a bug in the driver causing the stutter when the gl contexts of mpv and kwin interleave.
Try to "export KWIN_USE_BUFFER_AGE=0; kwin_x11 --replace &"
User avatar
Soukyuu
Registered Member
Posts
71
Karma
0
OS
luebking wrote:if the window is not redirected, the output goes from the client to the X11 server to the driver to the crtc to your screen. Other clients have *no* impact on it.

Hence my question on what would happen in case not redirecting doesn't work.

don't export "KWIN_TRIPLE_BUFFER=1" unless you really configured the driver to perform triple buffering.

Gotcha. Did enable triple buffering in the driver now, though that didn't help.

I'm not sure about your opinion of "stutter" in this case, but please notice that it's *completely* impossible to avoid judder when playing 23.976Hz or 25Hz material synced to a 60Hz screen. No matter whether synced directly or via a compositor (except when the player injects interpolated frames to increase the framerate - or performs smart swapcontrol management to paint some frames unsynced)

I am aware of that. I'm using mvtools to inject interpolated frames and reach 60fps, then mpv's interpolation (based on frame blending) takes care of any vsync fluctuations. I could remove the second step, but that doesn't change anything performance-wise. Of course, the whole setup is highly reliant on getting the correct vsync "signal".

The stutters I'm seeing is not the 23.97 -> 60 judder (I know exactly how that one feels), but really hard stutters every few seconds. They are only happening on camera pans.

=> do you get the same "stutter" with compton without allowing unredirection?

No, the only two options that have to be specified to get smooth playback turns out to be --backend glx (to prevent tearing) and --glx-no-rebind-pixmap (eliminate stutter). Other options don't seem to have any effect.
luebking
Karma
0
> hard stutters every few seconds
You might be running seeing https://bugs.kde.org/show_bug.cgi?id=344433 then (I had imagined worse "stutter")
User avatar
Soukyuu
Registered Member
Posts
71
Karma
0
OS
glxgears run smoothly unless I maximize them. When maximized, the stutters are similar to the ones I see with mpv.

Code: Select all
304 frames in 5.0 seconds = 60.669 FPS
297 frames in 5.0 seconds = 59.386 FPS
301 frames in 5.0 seconds = 60.012 FPS
300 frames in 5.0 seconds = 59.932 FPS
301 frames in 5.0 seconds = 60.064 FPS
300 frames in 5.0 seconds = 59.998 FPS
300 frames in 5.0 seconds = 60.000 FPS
300 frames in 5.0 seconds = 59.996 FPS
300 frames in 5.0 seconds = 59.998 FPS
300 frames in 5.0 seconds = 59.998 FPS
300 frames in 5.0 seconds = 59.996 FPS
301 frames in 5.0 seconds = 60.001 FPS
300 frames in 5.0 seconds = 59.911 FPS
298 frames in 5.0 seconds = 59.485 FPS
300 frames in 5.0 seconds = 59.984 FPS
301 frames in 5.0 seconds = 60.002 FPS
300 frames in 5.0 seconds = 59.994 FPS
301 frames in 5.0 seconds = 60.009 FPS
300 frames in 5.0 seconds = 60.000 FPS
300 frames in 5.0 seconds = 59.983 FPS
301 frames in 5.0 seconds = 59.997 FPS
301 frames in 5.0 seconds = 60.014 FPS
300 frames in 5.0 seconds = 59.992 FPS


However, I've been having this with triple buffering off as well, while the bug report states disabling it makes things smooth again.
luebking
Karma
0
Hmmm... what if you set the tearing prevention to full scene repaints?
User avatar
Soukyuu
Registered Member
Posts
71
Karma
0
OS
Doesn't seem to change anything, still same type of stutters. I've also tried other strategies on that list.
User avatar
Soukyuu
Registered Member
Posts
71
Karma
0
OS
luebking wrote:PS: there might be a bug in the driver causing the stutter when the gl contexts of mpv and kwin interleave.
Try to "export KWIN_USE_BUFFER_AGE=0; kwin_x11 --replace &"

Somehow I seem to have completely overlooked this post! It didn't change anything while having triple buffer enabled, but with it disabled + __GL_YIELD=USLEEP, the stutters are mostly gone. Mostly, because same scenes seem to be buttery smooth on one playthrough, then suddenly stutter on the next...

Also, even though I've removed "Option=TripleBuffer" from my xorg.conf, KWIN_TRIPLE_BUFFER is set to 1. Switching it to 0 introduces more stuttering ...

So, current manual config is:
export KWIN_USE_BUFFER_AGE=0
export __GL_YIELD=USLEEP

Rest is "as is". Sometimes, it now plays stuff smoothly. I guess that's some progress. Any idea what I could try going from here?
User avatar
google01103
Manager
Posts
6668
Karma
25
current stable Nvidia driver is 350.20, might want to try it (didn't see it in Arch repo but not familiar with Arch)

also in the Arch extra repo they have the 352.41 unstable version


OpenSuse Leap 42.1 x64, Plasma 5.x

User avatar
Soukyuu
Registered Member
Posts
71
Karma
0
OS
That's impossible, I fear. My GPU is considered legacy, and I'm using the last driver that supports my GPU (the 340xx).


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft