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

[d3d9,d3d11] recreate swapchain on VK_SUBOPTIMAL_KHR #4252

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

llyyr
Copy link
Contributor

@llyyr llyyr commented Sep 11, 2024

The vulkan wayland wsi returns suboptimal when the window is fullscreened and not directly scanned out, and there are modifiers available that would allow the window to be directly scanned out. Recreate the swapchain if we receive suboptimal result.

This allows us recreate the swapchain to use a modifier that allows direct scan-out under winewayland on wayland compositors.

I only managed to test it on a couple of games, so this doesn't have the greatest test coverage. I could put it behind a config option if this change is likely to break stuff.

@llyyr llyyr force-pushed the direct-scanout branch 2 times, most recently from ce75e9a to 1a6d154 Compare September 11, 2024 00:59
@llyyr llyyr changed the title d3d{9,11}_swapchain: recreate swapchain on VK_SUBOPTIMAL_KHR [d3d9,d3d11] recreate swapchain on VK_SUBOPTIMAL_KHR Sep 11, 2024
@doitsujin
Copy link
Owner

doitsujin commented Sep 11, 2024

Why does this change anything? We already recreate the swap chain if present returns SUBOPTIMAL_KHR.

If we need to do this on acquire as well for whatever reason then we should at least ensure that we're not turning the whole thing into an infinite loop if WSI can't give us what we want.

@llyyr
Copy link
Contributor Author

llyyr commented Sep 11, 2024

We already recreate the swap chain if present returns SUBOPTIMAL_KHR.

Yeah I see it now. I'm not too familiar with dxvk but I'll look into why that isn't sufficient. Marking this as draft for now.

if WSI can't give us what we want.

I might be misunderstanding this comment, but from my understanding we're still picking the format but the WSI is responsible picking what modifier to use for the client. It would be a WSI bug if it picks a modifier but it's still suboptimal no?

@llyyr llyyr marked this pull request as draft September 11, 2024 12:48
@doitsujin
Copy link
Owner

doitsujin commented Sep 11, 2024

Yeah I see it now. I'm not too familiar with dxvk but I'll look into why that isn't sufficient.

Looking at the mesa code it seems like present always returns VK_SUCCESS and ignores the swap chain's suboptimal status? Not sure if this is intended by the vk spec that return values ping-pong between SUBOPTIMAL and SUCCESS, but this would at least explain the issue.

We can definitely land this change in that case. Does this currently affect XWayland and/or Gamescope environments too?

It would be a WSI bug if it picks a modifier but it's still suboptimal no?

Arguably yes, but Wayland and X11 aren't the only WSI implementations we end up running on even if those are obviously the priority, and we've had weirder issues in the past. I'd prefer to be robust here and do something like if (status == SUBOPTIMAL) break; after acquiring from the recreated swap chain to only allow one iteration in that case.

The vulkan wayland wsi returns suboptimal when the window is
fullscreened and not directly scanned out, and there are modifiers
available that would allow the window to be directly scanned out.
Recreate the swapchain if we receive suboptimal result.

This allows us recreate the swapchain to use a modifier that allows
direct scan-out under winewayland on wayland compositors.
@llyyr
Copy link
Contributor Author

llyyr commented Sep 11, 2024

Not sure if this is intended by the vk spec that return values ping-pong between SUBOPTIMAL and SUCCESS, but this would at least explain the issue.

Is this worth reporting to mesa?

Does this currently affect XWayland and/or Gamescope environments too?

Not in my testing, no.

I'd prefer to be robust here and do something like if (status == SUBOPTIMAL) break; after acquiring from the recreated swap chain to only allow one iteration in that case.

Done. Thanks for the help, and also for identifying why this was necessary.

@llyyr llyyr marked this pull request as ready for review September 11, 2024 14:28
@doitsujin
Copy link
Owner

Is this worth reporting to mesa?

Would probably be good to clarify why SUBOPTIMAL isn't propagated, yes.

Either way, LGTM.

@doitsujin doitsujin merged commit 1a1c3a4 into doitsujin:master Sep 11, 2024
4 checks passed
@llyyr
Copy link
Contributor Author

llyyr commented Sep 11, 2024

Would probably be good to clarify why SUBOPTIMAL isn't propagated, yes.

I asked and it appears that QueuePresent doesn't propagate suboptimal on X11 either for performance reasons. https://gitlab.freedesktop.org/mesa/mesa/-/commit/2b885b233f7a6300ae88732c179888c02788493d

So both x11 and wayland WSI only return suboptimal on AcquireNextImage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants