Smithay / smithay

A smithy for rusty wayland compositors
MIT License
1.83k stars 156 forks source link

Possible performance issue when using SHM buffers #235

Open elinorbgr opened 3 years ago

elinorbgr commented 3 years ago

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:

If anyone can try to repro, the following information about the cases tested would be useful:

Ella-0 commented 3 years ago

I've got the following data:

With Anvil or WaRVk

With swvkc or sway

Ella-0 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.

elinorbgr commented 3 years ago

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.

Ella-0 commented 3 years ago

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

elinorbgr commented 3 years ago

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

Ella-0 commented 3 years ago

Oh, amazing!

elinorbgr commented 3 years ago

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

Ella-0 commented 3 years ago

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.

elinorbgr commented 3 years ago

I added an other change, how is it now?

Ella-0 commented 3 years ago

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.

elinorbgr commented 3 years ago

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

Ella-0 commented 3 years ago

Yes, its like before.

elinorbgr commented 3 years ago

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

Ella-0 commented 3 years ago

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

Ella-0 commented 3 years ago

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

elinorbgr commented 3 years ago

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 ?

Ella-0 commented 3 years ago

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