Skip to content
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

Resizing on macOS is cursed again #1168

Closed
LoganDark opened this issue Jan 24, 2021 · 10 comments · Fixed by #6107
Closed

Resizing on macOS is cursed again #1168

LoganDark opened this issue Jan 24, 2021 · 10 comments · Fixed by #6107
Labels
area: wsi Issues with swapchain management or windowing help required We need community help to make this happen. type: enhancement New feature or request

Comments

@LoganDark
Copy link

LoganDark commented Jan 24, 2021

Description
When resizing the window, the previous frame is stretched before any new frames are displayed. Or... maybe a new frame is drawn using an outdated uniform buffer and I can't update it in time. Who knows...

Repro steps
https://github.com/LoganDark/wgpu-stretch

Expected vs observed behavior
The square in the top left should not stretch

Extra materials
wgpu stretch 2

The previous incarnation of this bug can be found at #249

Platform
macOS 10.14.6 Mojave
Tech stack is as described in the wgpu-stretch repository

@LoganDark LoganDark changed the title Resizing is cursed on macOS again Resizing on macOS is cursed again Jan 24, 2021
@scoopr
Copy link
Contributor

scoopr commented Jan 24, 2021

Some idle thoughts,

I'm fairly sure that this happens because of combination of

  1. winit is deferring the resize event to slightly later moment, outside of the event handler
  2. the view/layer is set to fill the window, so the system helpfully rescales it to match (or winit scales it in-situ, but emits event deferred)

Avenues to look at,

  1. Check who is setting the view to be the size of the window (winit? gfx?), and check if it could be not automatically adjusted, but would only be updated to current size when presenting. This would introduce the "cropped" view artifacts, which would be less annoying, but feel perhaps unprofessional still.
  2. Investigate if winit could be coerced (optionally?) to handle resize events "synchronously". There might be good reasons why they aren't, but I'm not sure. This should produce "perfect" resizing behaviour, though with heavy rendering it might end up queueing a lots of slow redraws.
  3. Investigate if winit could handle windowWillResize to record what size it should be, but return the original resolution, and then at present resize the window to the suggested size anyway. This would produce "perfect windows", but possibly with ever so slight lag for when the resize occurs.

I wonder if that happens also with other winit using projects?

@LoganDark
Copy link
Author

LoganDark commented Jan 24, 2021

I wonder if that happens also with other winit using projects?

It does. Glutin has the same issue, and they also use winit: rust-windowing/glutin#1340

I'll open an issue in winit's repository to see if they can implement number 2 (handling resize events synchronously).

@kvark kvark added area: ecosystem Help the connected projects grow and prosper type: bug Something isn't working labels Jan 26, 2021
@LoganDark
Copy link
Author

LoganDark commented Apr 12, 2021

This issue is not solved yet. Redrawing immediately inside of the Resized event still results in this stretching, even on the latest winit... so this may be a wgpu issue, assuming winit is doing its job correctly now.

@LoganDark
Copy link
Author

Actually it seems now to be the reverse of what it was before. In my newest commit LoganDark/wgpu-stretch@517a37b I updated to the latest (git) version of winit and tried to make resizing smooth by redrawing synchronously inside the handler for WindowEvent::Resized.

Now it seems that the frame is being presented before the window's new size is applied, which I initially thought could be solved by using the Fifo/Mailbox PresentMode, but alas, nothing helped.

@kvark
Copy link
Member

kvark commented Apr 13, 2021

I prototyped a potential fix for this in gfx-rs/gfx#3627, but it didn't work at all 😓

@kvark
Copy link
Member

kvark commented Apr 13, 2021

You could check out gfx-rs/gfx#3627, enable the override to use it, and see if it helps.

@LoganDark
Copy link
Author

Looks like this is still an issue with https://github.com/lapce/lapce/ on Windows

@cwfitzgerald cwfitzgerald added type: enhancement New feature or request help required We need community help to make this happen. area: wsi Issues with swapchain management or windowing and removed type: bug Something isn't working area: ecosystem Help the connected projects grow and prosper labels Jun 5, 2022
@LoganDark
Copy link
Author

softbuffer does not have this issue which means it is not (anymore) a winit problem. It probably has to do with latency getting results from the GPU after a resize operation, or uniforms not being uploaded in time, or something like that.

@cwfitzgerald
Copy link
Member

Yeah this seems like a latency based race - we currently have no way of canceling presentation yet, which is potentially what you'd need to do with pending presents which hit the surface after the resize happened.

@LoganDark
Copy link
Author

LoganDark commented Jul 1, 2022

So

  • This is solvable on Windows by using PresentMode::Mailbox (but not Immediate or Fifo), but the window becomes extremely laggy, like 10fps.

    firefox_M7lfeEH4m0.mp4

    Other details are:

    • I am using WGSL instead of SPIR-V
    • I am using Push Constants instead of uniforms (fun fact, the upcoming switch to DX12 as a default will ruin this, as DX12 does not support push constants)
    • I am using Device::poll to wait for the GPU to finish before exiting winit::event::Event::RedrawRequested
  • wgpu 0.13 is the first version to point out the fact that Mailbox is actually not supported on my macOS machine which is probably why it didn't work as a troubleshooting step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: wsi Issues with swapchain management or windowing help required We need community help to make this happen. type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants