Possible performance issue when using SHM buffers
Initially reported in the chatroom by @Ella-0.
Apparently, high definition playback with mpv on its wlshm backend drops a lot of frames on anvil while not on sway.
We're talking at least 4k video, or 1080p@60fps. Should be reproduced by running mpv the-video-file --vo=wlshm. Only shows when using hardware decoding, as otherwise video decoding is the bottleneck. This is apparently specific to SHM buffers.
I could not repro on my laptop for lack of a good enough hardware video decoding.
We need to investigate to figure out if its an issue in anvil or smithay, and to what is it related exactly (shm buffer management ? frame callbacks ? something else ?).
Possible 4K video files to use for testing:
- 4k VP9: https://youtu.be/-W6JfiC-QBk
- 4k H264: https://4kmedia.org/sintel-4k-demo/
If anyone can try to repro, the following information about the cases tested would be useful:
- graphics driver in use
- was it on tty or in the winit backend
- amount of frame drops observed, and compared to an other wayland compositor (sway, weston, ...)
I've got the following data:
With Anvil or WaRVk
- ~30fps 1080p Intel winit - 0 frames dropped per second
- ~60fps 1080p Intel winit - 30 frames dropped per second
- ~30fps 4k Intel winit - 10 frames dropped per second-
- ~30fps 4k NVIDIA VK_KHR_display - 11 frames dropped per second
With swvkc or sway
- ~30fps 1080p Intel gl/drm - 0 frames dropped per second
- ~60fps 1080p Intel gl/drm - 0 frames dropped per second
- ~30fps 4k Intel gl/drm - 0 frames dropped per second
I think that's all the data I have, I could do more testing of Intel in VK_KHR_display mode with WaRVk and tty-udev with Anvil but Ik they both have Issues. Essentially We're just dropping frames like crazy.
I haven no way of testing on an AMD card at the moment so it'd be very useful if someone could verify my results with an AMD card.
Okay, what's perhaps even more concerning is that weston-simple-shm doesn't work properly. This must mean there is a serious issue with the handling of shm buffers.
Okay, after some testing, I think that this is indeed an issue with the way anvil manages its frame callbacks. We handle them in a bad way, causing weston-simple-shm to render at 30fps instead of 60fps.
weston-simple-shm is running way slower than 30fps for me. weston-simple-egl on the other hand is running at 1/2 the frame rate that it is meant to. tested at 4k@30fps (runs at 15pfs) and 1080p@60fps (runs at 30fps).
Yes, indeed, I found the core issue, will quickly make a PR.
Oh, amazing!
Okay, could you tell how much of the problem is fixed by #236 ?
that fixes weston-simple-shm, still dropping frames excessively with mpv and weston-simple-egl is now running at 40 fps instead of 30 when anvil is running at 60fps on winit. In tty-udev all issues are fixed including playing 4k video through mpv.
I added an other change, how is it now?
That fixes weston-simple-egl in winit, still hasn't fixed mpv on either. I was mistaken when I said mpv worked on tty-udev; I had a ytdl format flag.
So, for mpv, is it just like before, or is there some improvement?
Yes, its like before.
OK, so the problem with weston-simple-SHM was actually unrelated with the mpv issue. Back to figuring out the problem then.
Yeah, bit of a shame. Still dropping 125 frames in a 5 second 1080p video.
I'll do a bit more investigation into the issue tomorrow.
So, I just tried to read the Sintel demo again on a computer with hardware acceleration on the wlshm mpv backend, and it seems to run without dropping any frames now. Can you confirm with your own tests @Ella-0 ?
With a 4k clip running for 46 seconds I get 1 frame drop in sway and 36 in anvil. Sounds much better.