nanogui icon indicating copy to clipboard operation
nanogui copied to clipboard

Flickering on M1 Max macbook (metal backend only)

Open Tom94 opened this issue 3 years ago • 4 comments

Hi Wenzel, I've started experiencing sporadic flickering when using the metal backend on my new M1 Max macbook; see the following video.

I've made the following observations:

  • the behavior is independent of the screen. I can reproduce it on external LDR monitors connected to the laptop and all resolutions / refresh rates.
  • it appears to only affect example1 and tev, whereas for the case of tev it only affects the screen region covered by a canvas. example4 is not affected, even though it involves a canvas -- so nesting the canvas inside of a window appears to work around the problem somehow.

https://user-images.githubusercontent.com/4923655/148980181-24b7484c-714e-41f1-8f32-b11e05314f79.mov

Cheers, Thomas

Tom94 avatar Jan 11 '22 16:01 Tom94

Hi Thomas,

thank you for the report. Very puzzling. I will look into this, but it probably won't be until I receive my own M1 machine (ETA: February 1).

Wenzel

wjakob avatar Jan 11 '22 16:01 wjakob

As an extra data point: I've also noticed similar behavior on my M1 Max MacBook Pro using the precompiled binaries of HDRView, but haven't had any time to investigate.

wkjarosz avatar Jan 11 '22 16:01 wkjarosz

I can have a look when I get to my M1, but did run it a few hours ago and didn't notice flickering - but I wasn't looking hard enough

piotrkundu avatar Feb 04 '22 14:02 piotrkundu

Confirmed on MBP14 M1 Pro - Monterey 12.1 Metal backend. Used Display menu to test at different refresh rates, it seems replicable only at ProMotion 120Hz.

zzambia avatar Feb 05 '22 09:02 zzambia

Hi everyone (+ping @Tom94, @wkjarosz),

lots of time later, I finally had a moment to look into this (sorry!). It's been tricky to debug this because the flicker is not easy to reproduce reliably at least on my machine.

Could you let me know if the following simple nanogui patch fixes the issue on your side?

diff --git a/src/darwin.mm b/src/darwin.mm
index 7d9a886..83d448f 100644
--- a/src/darwin.mm
+++ b/src/darwin.mm
@@ -113,7 +113,7 @@ void metal_window_init(void *nswin_, bool float_buffer) {
         layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
         layer.colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
     }
-    layer.displaySyncEnabled = NO;
+    layer.displaySyncEnabled = YES;
     layer.allowsNextDrawableTimeout = NO;
     layer.framebufferOnly = NO;
 }

wjakob avatar Oct 21 '22 18:10 wjakob

It does -- although it's interesting that disabled VSync would cause flicker artifacts beyond tearing. Thanks for the fix!

Tom94 avatar Oct 22 '22 07:10 Tom94

Ok, that is great to hear. From what I can gather in the documentation, that flag changes the render pipeline quite a bit and has things go through CoreAnimation. So it's likely that other forces are at play beyond simple tearing etc. as you mention.

wjakob avatar Oct 22 '22 07:10 wjakob