-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread-safety for rendering related states #1393
base: master
Are you sure you want to change the base?
Conversation
f3ec96f
to
cb9f536
Compare
The renderer id itself is valid across threads, as it may be shared by shared EGLContexts. This doesn't make the renderer `Send` or `Sync`, but allows multiple renderers on different threads to share textures.
cb9f536
to
1fe3c70
Compare
Where Though really, in a lot of cases it won't make much of a performance difference; nor will using a For Though again, it might not make much difference. If the lock isn't held for very long, and we don't have a whole bunch of threads competing for it. In general using |
Ngl all these locks throughout make me very uneasy. I feel like it can lead to a lot of issues like: rendering thread gets some value (lock/unlock), then main thread gets a surface commit and updates values, then rendering thread later in the function gets another value (lock/unlock) and expects it to "match" the first value it got earlier in the function, but it no longer does. |
I agree with @ids1024 that using I also have similar concerns regarding atomicity of wayland operations as @YaLTeR. This could easily lead to unexpected behavior. So instead of going into more details regarding this PR changes I want to talk about the actual requirements and if there I haven't thought that completely through, but from a quick look it should be possible to make the render elements (especially the So some requirements to support this that come to my mind are:
|
The idea was that this is the primary rendering-related state, which might be processed multiple times for rendering, but is more rarely updated. Surely a Mutex wouldn't make a huge difference though.
I thought about this as well and concluded the same thing and thus went with the easier solution.
Yeah this definitely needs to be tested and probably bug fixed a lot, once any compositor actually makes use of it. It might lead to a few imperfect frames in it's current state. I can try to update and carry these patches until I have a proper implementation to show off (hopefully soon) to properly asses if this really is an issue.
Yes that is the general idea, however I feel like doing this after accumulating all the elements is the wrong approach. The idea of parallel rendering comes from the fact that you simply can't drive two 240hz displays on one main loop realistically, because the timings to commit in time are so tight. We actually profile and measure the "elements"-step separately from "drawing" in cosmic-comp and the former takes a good amount of time even after the last round of allocation optimizations. I really want to move this step into a render-thread as well, so while I like the theoretical idea of snapshotting the surface state, I don't feel like this would actually work as intended. For what is worth, cosmic-comp now puts it's whole
And that problems runs deeper. The renderers do mostly cache things using I don't think we should handle the import on the main thread btw. Importing with implicit sync might stall for quite a long time, with the MultiRenderer it might even involve a CPU copy. So locking EGLContexts to use them across multiple threads (except for creating shared contexts) is out of question luckily, which is another reason to move element-creation into the render threads.
So the idea would be to decouple import from element-creation? That might be a good idea and would easily allow to move this to another thread. (in just continue using old buffers, while the import thread is still busy?)
In general I think this is a good idea, no matter on which thread this takes place. This ensures a consistent rendered state and might already solve 99% of the problems @YaLTeR has with this PR? |
SHM uploads are especially painful on the profiles. Which happen every time you mouse over a different window (cursor surfaces are usually SHM), and also for clients like
That will be very welcome regardless. I had to make my own poor man's implementation of this for animations (window resize, window close): https://github.com/YaLTeR/niri/blob/47f6c85f64a20a9e32bf402941ecb78065aff80a/src/render_helpers/surface.rs No opaque regions or damage there though. |
Best reviewed commit-by-commit.
The biggest is easily 5b2e919, which makes the
CacheMap
thread-safe. A lot of the double buffered state is used to inform rendering, so I am not sure if this can be avoided.The rest of the changes are most likely less controversial.