Repository navigation
macOS: present on Retina and scaled displays (#191) - #225
Merged
Merged
Conversation
On a Retina or scaled display the game closed right after Start with "failed to present native swap-chain texture". The game window was not high DPI, so SDL's Metal layer had contents scale 1 (1280x720 pixels), while Plume sized the swap chain by the window's backing scale (2560x1440). MoltenVK holds a swap chain to the layer's own size and returned VK_SUBOPTIMAL_KHR for every present; Plume treats that as a failure on Apple, and after 8 rebuilds at the same wrong size the game gave up. Reproduced on the M1 with 0.10.14 (through the launcher too) on a 1280x720 HiDPI display mode; 1x displays were never affected. - The macOS game window is high DPI, as on iOS: the layer takes the screen's scale. - Plume patch: on macOS the swap chain takes the window's Metal layer size (bounds x contents scale, truncated as MoltenVK does), and the swap chain keeps the VkResult of the last present and acquire. - game.log names the VkResult of every refused present and acquire (all platforms). A present still suboptimal after 8 rebuilds is kept (MoltenVK shows the image scaled) instead of closing the game. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the macOS close right after Start reported in #191 (M1 MacBook Pro, internal display and an external display scaled to 2560x1440).
Cause (reproduced)
The game window on macOS was not high DPI, so SDL's Metal layer had contents scale 1: a 1280x720 window gave a 1280x720 layer. Plume's
CocoaWindowsized the swap chain by the window's backing scale (2 on Retina or scaled displays), so it made 2560x1440 swap chains. MoltenVK holds a swap chain to the layer's own size (bounds x contents scale) and returnedVK_SUBOPTIMAL_KHRfor every present. Plume treats that as a failure on Apple, the game rebuilt the swap chain 8 times at the same wrong size, and then stopped withfailed to present native swap-chain texture. The reporter's log shows the same thing:contents scale 1.0, swap chain 2560x1440, 8present_refused.Reproduced on our M1 (macOS 27.0.1) with the 0.10.14 release package, run by the harness and through the launcher (Start pressed by the launcher, windowed and full screen settings), on a display in 1280x720 HiDPI mode (2560x1440 pixels). The new logging shows
result=VK_SUBOPTIMAL_KHR(1000001003)for each refused present. 1x displays were never affected, which is why our 1920x1080 Mac ran it fine.Fix
native_graphics.cpp: the macOS game window is high DPI (SDL_WINDOW_ALLOW_HIGHDPI), as on iOS (iOS: fix the first present (Issue #185) and draw the launcher's Chinese #194). The layer then takes the screen's scale.patches/plume-present-result-layer-size.patch:src/plume_apple_ios.mm. The window's backing scale is used only when there is no Metal layer. The swap chain and the layer can no longer disagree, even with a layer that is not high DPI.VulkanSwapChainkeeps theVkResultof the last present and acquire.native_presentation.cpp:present_refusedandacquire_refusedlines in game.log name the VkResult on all platforms (Android's rebuild path too).VK_SUBOPTIMAL_KHRafter 8 rebuilds is kept instead of closing the game, logged once asNATIVE_PRESENTATION suboptimal_kept. MoltenVK still shows that image, scaled into the layer. A normal present ends this. Other failures still stop the game as before.docs/vulkan.md: a section on this problem.Windows, Linux and Android behaviour is the same except for the extra log text. Plume already accepted
VK_SUBOPTIMAL_KHRthere, and its swap-chain sizing there is unchanged. iOS keeps its own Plume glue.Tests
On the M1, with the release 0.10.14 app bundle and only
sfr_cpu_diagnosticswapped for this build:These runs also cover each fix on its own:
VK_SUBOPTIMAL_KHR(1000001003)8 times, thensuboptimal_kept, and the game ran on.Other checks:
ninja -C out/build/rel-ios sfr_launcher sfr_cpu_diagnosticbuilds.native_shader_abiandnative_resolutionwere not built bybuild_tools.ps1(CI excludes both).Not tested
A separate, older problem showed up again during testing:
GUEST_ACCESS_VIOLATION guest=0x10insub_8249C100at startup. It hit 2 of about 18 harness runs on the M1, once with 0.10.14 and once with this branch, and is not related to this change.🤖 Generated with Claude Code