Direct2D: laggy mouse interaction under heavy paint load on low-end GPUs (8.0.13 / develop)

Hi all,

We’re seeing laggy mouse interaction in the Direct2D renderer on low-end GPUs when there’s a decent amount of painting going on, with large UI and animated components. Dragging a knob or clicking feels delayed, the UI visibly trails the cursor. It was first reported by one of our beta testers, we then reproduced it on our end, and we managed to put together a reproducible example (a slight modification of a previous Windows graphics bug repro we had):

GitHub - DamRsn/juce-opengl-crash at laggy_interaction · GitHub (laggy_interaction branch)

It happens on latest develop, and on 8.0.13 which we’re currently on. Also, it only happens on D2D (things behave correctly with OpenGL and the software renderer).

Here is a video showing the interaction lag:

(filmed with a phone, sorry — screen recording kills the graphics performance of my low-end Windows machine it reproduces on)

What seems to happen is that when the GPU can’t keep up, instead of dropping frames, the renderer blocks the message thread inside Present1 — so processing of user interactions like mouse clicks and drags gets delayed. We think the right behaviour here is to drop frames and keep the message thread responsive: the UI degrades in frame rate, not in input latency.

We analyzed the issue with Claude, which found the cause and came up with a fix — apologies for the AI-assisted report, but we’ve tested the fix under different conditions (slow iGPU, standalone, in DAW, many plugin instances at once) and it seems solid. The PR on our JUCE fork is here:

We’ll likely merge it on our fork soon, but we think this should really be addressed in JUCE directly.

Short summary of what’s going on: since d3a1f0f1 (which reinstated a maximum frame latency of 1, discussed in this thread), Present1 blocks the message thread whenever the previous frame hasn’t been displayed yet. That commit fixed a real multi-instance regression, so simply reverting it isn’t an option. But older versions of the renderer didn’t have this problem: before 22ae5baa removed the SwapChainThread, painting was gated on the swap chain’s frame latency waitable object, so frames were deferred when no present slot was free instead of blocking. That gate was never reinstated along with the latency cap — the PR above basically restores it, with a non-blocking check in checkPaintReady() instead of a dedicated thread.

There might be context we’re missing on why it was done this way, so happy to be corrected, and happy to provide what we can to help track this down. This thread also looks related: Sluggish and Glitchy UI on Windows with JUCE 8.0.13.

Thanks!

2 Likes

Thanks for the detailed report and example code. So far I haven’t been able to reproduce the issue, but I can understand where the problem might arise.

Please could you test out this patch and check whether it improves things for you? Thanks!

direct2d.patch (3.5 KB)

Thanks for the patch, I just tested it both on our plugins and on my repro example, and it fixes the issue. I’ll let you know if anything else comes up.

We’ll probably merge your patch in our fork then (seems like the two are very similar). Let me know when it gets in develop, or if you improve it further. Thanks!

1 Like

Hi Guys,

First of all, thank you for your work, especially to @damienr for debugging the issue.

This patch works for me too.

@reuk do you know if this patch has already been merged into the develop branch or if it is still pending?

Thanks again!

Best,

Samuele

It’s still pending at the moment. There are a few fairly urgent (or low-risk) bugfixes on the develop branch currently, so the plan is to wait another week or so for those to stabilise and then to do a point release. Slightly higher-risk changes like this one will go out after that point release.

1 Like

Hello,

When can we expect this fix to be integrated in a new release of JUCE 8? And is it already in JUCE 9?

We applied the patch on our fork (JUCE 8) and everything’s been smooth with it so far, but we think this should really be fixed in JUCE directly.

Thanks!

2 Likes

I also had an issue with two-monitor set ups, where I was getting flickering and artifacts on one monitor - this patch has fixed the problem thankfully.

It looks like the flickering was caused by an interaction between JUCE’s Windows Direct2D presentation path and mixed-refresh multi-monitor configurations. In my case, the problem was most pronounced when the Windows primary display had the lower refresh rate and the plugin editor was opened on the faster secondary display.

Windows traditional DXGI/DWM presentation model uses the primary monitor’s cadence for the compositor/swap-chain timing, which can create a mismatch when content is displayed on a secondary monitor with a different, higher refresh rate. JUCE’s Direct2D renderer could then block the message thread waiting for a DXGI presentation slot during Present1(), resulting in visible flickering/artifacts during UI interaction. Applying this fix, which checks the swap-chain’s frame-latency waitable object non-blockingly and defers/drops a frame instead of blocking the message thread, resolved the problem completely in my application.

This seems to be a common issue, I hope the fix can be released soon.

I’ve been performing some additional testing on the patch. Although it does resolve my screen issue, I found the patch stops working after a screensaver, lockscreen or hibernation (where editor window is left open). Previous behaviour returns.

After a diagnosis, this reveals Present1() returning DXGI_STATUS_OCCLUDED. Microsoft’s docs say “You will not receive DXGI_STATUS_OCCLUDED if you’re using a flip model swap chain”, however in practice DXGI_STATUS_OCCLUDED still shows up during UAC prompts, Ctrl+Alt+Del, user-switching, screensaver - despite docs saying flip model is exempt.

The patch calls didPresent() when hr == S_OK. Anything else, including DXGI_STATUS_OCCLUDED, leaves didWait stuck at true forever, because nothing ever flips it back. I believe this was intentionally an additional safe fallback - worst case reverts to the original un-throttled behaviour rather than risking a wait that never wakes up. But DXGI_STATUS_OCCLUDED just means the window’s covered.

As there is already a check in the patch “if (FAILED (hr)) { …; return; }”, it may be safe to call swap.didPresent() unconditionally, for S_OK and other success codes (occluded included).

I created a 2nd patch to test this:

-        if (hr == S_OK)
-            swap.didPresent();
+        // Reset on any successful present, not only S_OK. FAILED already returned
+        // , so hr here is always some success code; DXGI_STATUS_OCCLUDED
+        // (screensaver/lock screen/hibernate) just means the window is covered,
+        // not that the swap chain or waitable object is broken.
+        swap.didPresent();

I’ve tested this fix and found it addresses the issue, and screensaver/lockscreen etc no longer stops the original patch working. No other issues witnessed. However I’m sure it will need further evaluation before implementing.

One other point raised while analysing these patches; claude reported it may cause issues with RDP sessions or software that hooks the swap chain. I’ve not tested or confirmed this claim.

I hope this is helpful in getting the final fix released.

Thanks for reporting. We’ve now pushed a fix for the original issue described in this thread:

We’ve also pushed a fix for the DXGI_STATUS_OCCLUDED issue mentioned in the post above:

Thanks everyone! Please try this out and let us know if you encounter further issues.

1 Like