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
Kicad very sluggish when some of its windows are hidden #23512
Comments
Thanks for reporting this, I didn't know that calling Anyhow, it would be simple enough to add a check for whether a window is hidden to Lines 636 to 645 in 1093bb4
E.g. we could just replace the test for |
Yes, I can definitely test if it fixes the problem. Maybe not today as I'll have to compile everything, but this week I should be able to. |
How expensive is IsShownOnScreen? |
Hello there, |
Some searching shows that there is a slightly different recommended way of handling not drawing on a hidden window in the Wayland rendering loop: https://emersion.fr/blog/2018/wayland-rendering-loop/. I am not sure how easily that can be adapted to work on the GL canvas though, so I wonder if it is something we might have to put into downstream KiCad instead. |
Ensure that we only draw when we really should and do not block in SwapBuffers() when we shouldn't. Use eglSwapInterval() to disable blocking in eglSwapBuffers() and ensure that we only call it when we should by using m_readyToDraw not only for the first repaint, but also for all the subsequent one. Closes wxWidgets#23512.
Thanks Ian, this was a very useful link and I have a much better understanding of how this works after reading it (or, rather, now I have some understanding of how it works while I had no idea about it before). But unless my understanding is very wrong, it looks like there is a very simple fix to our problems: we just need to call I've created #23554 doing just this and it seems to work fine for me with the cube sample, but it would be great if somebody could test it with KiCad itself, of course. Also, @swt2c please let me know if I did something wrong with your code/logic. TIA! |
Well, that's because it was originally only intended to avoid the deadlock on the first draw before the surface was realized. However, your changes make sense to me. Hopefully they improve things for KiCad. |
Can you clarify what this means? I thought EGL bypassed the XWayland system and went to the Wayland compositor directly, so using |
Well, EGL itself might, but wxGLCanvasEGL checks the GdkWindow it's been given and if it determines its an X11 one, then it does all the X11 stuff. Presumably if using XWayland, the GdkWindow will be an X11 one? |
I wonder if the OP could actually be using Wayland in spite of running Xwayland. Unless you explicitly set |
I do use Xwayland because kicad doesn't work natively under wayland and has I can test PR #23554 and I'll let you know. |
Why doesn't KiCad work natively under Wayland? If it's due to some wx problems, could you please open (another) issue for this? We definitely want to support using Wayland natively, not just via XWayland. Unfortunately #23554 shouldn't change anything for you if you're using X11, it only changes Wayland-specific code paths (but testing it wouldn't hurt, of course). And I have no idea about what could we do for X11 branch. The only workaround I see is to switch to using GLX instead of EGL, which currently requires building wxWidgets with |
You can read the discussion here https://gitlab.com/kicad/code/kicad/-/issues/7207 |
Well, this ends with "things seem to work", so I'm still not sure what is the problem with running KiCad under Wayland natively any more (yes, there was an error shown at the beginning of this issue, but this was a couple of years ago). |
Well, I have not tested myself. The thing is, there seem to be no interest from kica developers https://gitlab.com/kicad/code/kicad/-/issues/7207#note_828671381 to support wayland. I use kicad under Xwayland, and the only real issue I have is this one (kicad freeze when some windows are hidden). So I thought it would be easier to fix. But in the end, native wayland support would be better. But I cannot steer kicad development. |
I can't speak for KiCad developers and I admit that I can share their frustration with some of Wayland design issues (not allowing applications to save/restore window geometry is just incomprehensible IMO, and I'm speaking as a user here -- I want the applications I use to do it), but at least some parts related to wxWidgets might be out of date. But if KiCad relies on events that we don't currently generate ( Anyhow, to return to the issue at hand, I wonder if we could need to call OTOH it looks like there shouldn't be any problem with skipping drawing on hidden windows in EGL/X11 case, so I've added a commit doing this to the PR (I've force pushed there to also remove "Closes #23512" from the existing commit, as it doesn't really fix this issue). Could you please check it? And if it still doesn't fix the issue, could you please experiment with moving the |
This is useless and might be actually harmful if it results in blocking in eglSwapBuffers() and slowing down the application. See wxWidgets#23512.
I have the same issue with KiCad, it is very annoying and reaction of KiCad developers is disappointing |
@SL-RU Please consider helping by testing the proposed changes. |
I will try to setup everything required to test patches on my machine this weekend.
…--
Nicolas Goy
https://www.kuon.ch
-------- Original Message --------
From: VZ ***@***.***>
Sent: May 25, 2023 4:15:20 PM GMT+02:00
To: wxWidgets/wxWidgets ***@***.***>
Cc: Nicolas Goy ***@***.***>, Mention ***@***.***>
Subject: Re: [wxWidgets/wxWidgets] Kicad very sluggish when some of its windows are hidden (Issue #23512)
@SL-RU Please consider helping by testing the proposed changes.
|
I thought the wxGrid rendering/behavior is still problematic on Wayland (I thought there was an issue somewhere for that as well, but I can't recall what number it is, since I thought that was one of the more well known issues). There are several uses of |
We should have create issues for things that don't work as right now I don't see anything Looking at the code, it seems like the problems might be limited to drag-moving, which is definitely still a problem, but I'm not even sure if it affects KiCad. If there is something (even) more serious, please don't hesitate to open an issue for it and I'll try to look at it. TIA! |
I have tried running KiCad with vadz@f2214ff applied and it did not help. It still freezes when switching between fullscreen |
Fixed this by calling That's probably not a viable fix to implement though, because I'm guessing this will cause the render loop to run at full speed on native X11? |
Quick an dirty fix for wxWidgets#23512
But currently we don't even set it to 0 there when using X11, my changes only affect Wayland. So, just to confirm, did you actually add this call in
I'm not so sure about it, you're only supposed to call So maybe the fix is really as simple as just disabling the swap interval for EGL when using X11 too... |
Sorry I forgot to mention, the X11 codepath is the one used on XWayland.
Yes I tried to set the swap interval in the
Setting the swap interval to 0 effectively disables vertical synchronization on X11, which will cause visible screen tearing. On top of pegging the CPU to 100% if the application doesn't throttle itself by some other means. Usually relying on the blocking behaviour of For power saving reasons, Wayland only requests frames from the application when the surface is visible. This caused I think what happens with Kicad is the following. Kicad windows are not totally independant: selecting a component in one window will highlight it in the other, and vice versa. There must be synchronization going on between window threads, but one of them is running at a leisurely 1Hz, causing the active window to slow down to a crawl while it waits for locks and so on. In theory though this should not happen: according to the X11 codepath,
Here's a list of the options that I see, by order of correctness: 1) Applications should decouple application logic from the render threadThat's the right way™ of doing a render loop if you need to keep processing stuff in the background when the user is not interacting with your application. And do not assume the render thread will be polled at any particular interval. We all know that's not happening though. 2) Applications should use the native Wayland backend and not force using XWaylandIn the Wayland codepath, 3) wxWidgets should correctly detect hidden surfaces in the X11 codepathAs mentionned above, if wxWidgets could detect when the surface is hidden "atomically", then we wouldn't risk hanging in 4) wxWidgets should use non-blocking
|
Set EGL swap interval to 0 to prevent EGL functions from blocking for 1 second when the window is entirely obscured, resulting in catastrophic slowdown of the entire program whenever this happened. See wxWidgets#23909, wxWidgets#23512. (cherry picked from commit aaabb84)
Now, before the patch, I cannot reproduce the slowdown for some reason. |
This PR seems to me completely unrelated to wxWidgets.
Nothing prevents you of sending gl-commands (and filling buffers) for a hidden (minimized or behind other window). The thing is that calling A good way to get the most out of the GPU is issuing data/commands to the GPU, but only call for drawing a few times. |
@Manolo-ES The above makes it clear that you didn't really follow this in details so, to prevent further confusion and misunderstanding, let me repeat: this is not about optimizing anything, because the part that you missed is that Wayland sets swap interval to 1 (*one) FPS, not 60 FPS, for the obscured windows, so it's not about making the app sluggish at more than 60 FPS but about making it completely unusable as soon as any windows containing |
IIUIC the bug is supposed to be fixed in wxWidgets 3.2.3, but I can still reproduce this in Debian testing/trixie, which has KiCAD 7.0.8 and wxWidgets 3.2.3. (My setup is the same as OP, so Sway and KiCAD under XWayland [default]). |
This is worrisome, but the upcoming 3.2.4 will have a few more fixes to this area, please retry with this when it's released in a couple of days. |
I'm on KiCAD 7.0.8 with wxWidgets 3.2.4 now, still running Sway. I still see lag problems, but on closer investigation the lag behaviour changed. My usual setup is having two maximized windows (PCB + schematics) on different workspaces. When switching between the windows/workspaces it hangs for some seconds. Afterwards it runs smoothly. So it might actually be a different bug. When putting both windows on the same workspace next to each other everything is working fine, though. So this is still about window occlusion. |
i can't reproduce occlusion lag [as you describe it] with KiCad 7.0.8 or 7.0.9 on NixOS with wxWidgets 3.2.4 and sway 1.8.1 |
It was not build against 3.2.4, but using 3.2.4 at runtime (can be easily checked in KiCAD's Help -> About KiCAD dialog). Anyways - I now installed KiCAD 7.0.9 built against wxWidgets 3.2.4 and nothing changed. I did some further tests and can narrow down the issue a bit more: First of all: When both windows are visible there are no lags. With two displays sway has one workspace per screen. Even then switching between the windows works fine. So it's not related to sway's workspaces. When I have one window per workspace (and only one of the workspaces visible at the same time), I get a period with some seconds of unresponsiveness when switching between the windows. But the lag only happens, if the other window gets focus. E.g. this sequence works without any lags: step 1: workspace: KiCAD Schematics (focus) + Terminal But this one does lag: step 1: workspace 1: KiCAD Schematics (focus) + Terminal I tried resetting KiCAD config and it does happen with the default config. During the lag CPU is more or less completely idle. Also the switch lag seems to be exactly 10 seconds. Considering eGL is involved, I guess mesa version and graphics hardware are also relevant. In my case I can reproduce the issue with two different AMD GPU based systems and I'm running mesa 23.2.1 (on both systems). |
I tried reproducing this on my old Intel based laptop and that works fine without lags. |
I tried running kicad in gdb and stopping it when the lag happens to generate a backtrace:
Looks like KiCAD is hanging in this glGetError() call. |
For anyone looking into this with an AMD system: The bug does not occur when I force software rendering in mesa like this: |
@vadz do you think the workaround added to wxwidgets EGL code could also be added for GLX? Apparently KiCAD/wxwdigets/glew in Debian is currently build without EGL support (I'm writing a bug report in parallel to change that). Running KiCAD with |
Speaking of the following comment, does it really block for up to a second on a real X session, or was it only tested on XWayland? Lines 769 to 777 in ed02e03
|
@sre Sorry for the delay with the reply, I hoped to actually do it, but as I clearly failed and am not sure to find time to do it in the near future too, let me at least reply to this: yes, we could do the same thing in
@dsa-t Personally I only tested this under XWayland. |
I will try to find some time, but not guarantees from my side either.
My understanding is, that native X does not run into this. It keeps the rendering loop active when a windows is not visible and wasting power. But on native X the current code is expected to also has issues when the KiCAD windows are on two different monitors running with different refresh rates (e.g. a gaming monitor at 144Hz and a normal one with 60Hz). Possibly less noticeable, since the refresh rate should be at least 60 Hz in that specific case. I don't have any gaming monitor to test that claim from the mesa people. |
We need to do it when using XWayland for the same reasons as we had to do it in the EGL version when using either XWayland or Wayland directly: without this, we can block for up to 1 second in glXSwapBuffers() if the window is hidden, see wxWidgets#23512. Closes wxWidgets#24163.
I couldn't resist trying to do it, finally, so I did, in #24165. This works under XWayland, but I still didn't test it under Xorg, it would be great if you could please do it. TIA! |
But we don't want to render faster than the display refresh rate. KiCad sets swap interval to adaptive or 1 to limit it. KiCad 7.99 generally renders from:
There's a limit of at least 3 ms between frame end and next frame start, but for most displays (60 Hz), disabling swap interval will cause increased power draw. |
Sorry, I don't understand: why wasn't it a problem for EGL but is for GLX?
Wouldn't it be better to avoid calling |
I'm sure this is a problem in EGL+(X)Wayland as well, but not freezing for 1 second probably was more important than high power usage.
How do we know when it's the best time to swap (aka at vblank)? On native Wayland, this can probably be hacked together via https://wayland.app/protocols/presentation-time#wp_presentation_feedback:event:presented On Xwayland... Not sure. |
So I guess the question is: does this freezing happen with GLX and XWayland only? If yes, then I need to indeed add a check for XWayland being in use... BTW, I can't reproduce the problem with GLX and XWayland here, not sure why.
Unfortunately I don't have any good answer to this neither, sorry. |
Hi. I’m waiting on this fix to land in the Flatpak it doesn’t seem yet because I have a similar bug: a big pause when switching between fullscreen windows under Gnome. It was very frustrating to have the program freeze whenever alt-tabbing between the schematic and the PCB windows. For those like me, I devised a small workaround: don’t put your windows entirely in full-screen, instead resize them to nearly the whole screen except a small band left in which you see the other window open, and same for your second window on the other side. That way, when you have the PCB in front you see a bit of the schematic window behind, and when you have the schematic window in front you see a bit of the PCB window behind. That way, Gnome never decides that a window is completely hidden (as it would with complete fullscreen) and the window doesn’t get in and out of the hidden state that causes the bug. And it works, no more freeze when alt-tabbing ! Hope it helps someone, and please devs ping us here when the patch should be in the Flatpak, so we can test :). |
@navaati You can set
Assuming the above does work, the following should make it permanent:
|
A solution to KiCAD with Ubuntu 24.04 Wayland mode, Build options for native Wayland. For wxWidgets library, use v3.2.4 or 3.2.5-proposed-backports branch. |
I am trying to find the reason for the following issue.
When using kicad under Xwayland under sway, if one window is hidden, the whole application will be very sluggish.
After some investigation, it seems to be due to
eglSwapBuffers
"slowing down" when window is hidden, ref.I am still unsure if this should be fixed here. I'll happily help as much as I can if you need more info.
kicad 7.0.1 with wxWidgets 3.2.2
The text was updated successfully, but these errors were encountered: