gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.13k stars 882 forks source link

Screen flickering on Nvidia Optimus #3452

Open jsonmona opened 1 year ago

jsonmona commented 1 year ago

Description Screen flickers (briefly shows white screen) when resizing.

As far as I can test, this only happens with Vulkan backend, and requesting LowPower adapter with nvidia optimus enabled.

Oddly, I get the same issue whenever I launch Kakaotalk (a Korean messenger app). In that case, the screen goes white without triggering repaint event, causing the app to become stuck on the white screen until the next repaint event occurs.

Repro steps

  1. cargo run --example cube
  2. Keep resizing the window

Expected vs observed behavior Screen flickers (briefly shows white screen).

Extra materials Here is a video recording of the issue (contains flashing lights): video

I do get a single validation error at start, but I believe it's irrelevant because I also get those even when I disabled nvidia adapter.

Platform

teoxoy commented 1 year ago

This sounds like a driver issue.

Just a few more questions for completeness:

jsonmona commented 1 year ago

@teoxoy Sure!

According to Nvidia control panel, only built-in display is connected to iGPU, and all external ports are connected to dGPU. So I tried to replicate the issue with a HDMI monitor (which Nvidia control panel reports as connected to dGPU), and the issue was still there.

It indeed sounds like a driver issue. If you can point to some other Vulkan applications, I would be happy to test them too.

Probably not important, but the issue also persists when I attach RenderDoc. For some reason, RenderDoc fails with VK_ERROR_DEVICE_LOST when I click EID 20 and 22 - the vkCmdDrawIndexed call. It might be RenderDoc's bug, but it's weird.

The screenshot of RenderDoc:

RenderDoc failing with device lost error
teoxoy commented 1 year ago

Thanks for all the details! I'm not sure about the RenderDoc issue.

So the conclusion is that just having optimus enabled and using the Intel iGPU causes the flicker on resize behavior.

Not sure what we can do about this, ideally we should use DX12 on Windows (see https://github.com/gfx-rs/wgpu/issues/2719).

n1ght-hunter commented 1 year ago

I get the same issue. BadReize Pc Specs OS: Window 10 CPU: AMD Ryzen 5 3600 GPU: AMD Rx 6700XT

That was using the primary Backend so i presume Vulkan

jsonmona commented 1 year ago

Looks like related to this SO question: https://stackoverflow.com/q/58808444

cwfitzgerald commented 4 months ago

@jsonmona There's kinda slim chance, but can you try https://github.com/gfx-rs/wgpu/pull/5681 to see if this fixes your issue?

jsonmona commented 4 months ago

@cwfitzgerald Sorry, but I do not own the laptop anymore. Maybe others could help? @n1ght-hunter