smithay icon indicating copy to clipboard operation
smithay copied to clipboard

Possible performance issue when using SHM buffers

Open elinorbgr opened this issue 5 years ago • 19 comments

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, ...)

elinorbgr avatar Oct 09 '20 10:10 elinorbgr

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

Ella-0 avatar Oct 09 '20 12:10 Ella-0

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.

Ella-0 avatar Oct 09 '20 14:10 Ella-0

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.

Ella-0 avatar Oct 09 '20 14:10 Ella-0

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.

Ella-0 avatar Oct 10 '20 09:10 Ella-0

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.

elinorbgr avatar Oct 10 '20 17:10 elinorbgr

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).

Ella-0 avatar Oct 10 '20 17:10 Ella-0

Yes, indeed, I found the core issue, will quickly make a PR.

elinorbgr avatar Oct 10 '20 18:10 elinorbgr

Oh, amazing!

Ella-0 avatar Oct 10 '20 18:10 Ella-0

Okay, could you tell how much of the problem is fixed by #236 ?

elinorbgr avatar Oct 10 '20 18:10 elinorbgr

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.

Ella-0 avatar Oct 10 '20 18:10 Ella-0

I added an other change, how is it now?

elinorbgr avatar Oct 10 '20 18:10 elinorbgr

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.

Ella-0 avatar Oct 10 '20 18:10 Ella-0

So, for mpv, is it just like before, or is there some improvement?

elinorbgr avatar Oct 10 '20 19:10 elinorbgr

Yes, its like before.

Ella-0 avatar Oct 10 '20 19:10 Ella-0

OK, so the problem with weston-simple-SHM was actually unrelated with the mpv issue. Back to figuring out the problem then.

elinorbgr avatar Oct 10 '20 20:10 elinorbgr

Yeah, bit of a shame. Still dropping 125 frames in a 5 second 1080p video.

Ella-0 avatar Oct 10 '20 20:10 Ella-0

I'll do a bit more investigation into the issue tomorrow.

Ella-0 avatar Oct 10 '20 20:10 Ella-0

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 ?

elinorbgr avatar Jul 07 '21 15:07 elinorbgr

With a 4k clip running for 46 seconds I get 1 frame drop in sway and 36 in anvil. Sounds much better.

Ella-0 avatar Jul 16 '21 15:07 Ella-0