🐛 Keep the window's swapchain when its remake refuses before the create
The remake retired the old swapchain whether or not the new one was made, and the make can refuse before vkCreateSwapchainKHR, where the window's surface has no pixels for now. Vulkan was never handed the old one, so it stayed the window's, and each later remake, with no current swapchain to pass as oldSwapchain, made one beside it, which Windows refuses while the old one lives (VK_ERROR_NATIVE_WINDOW_IN_USE_KHR). On a Ryzen 5 5600G host with an RTX 3060 the window kept the macOS installer's last frame from the guest's reboot on, while QMP's screendumps followed the guest, and drew nothing on a minimize and restore; the log held the one refusal a refusing swapchain logs. A make refused before the create now leaves the old swapchain the current one, stale, so the next remake hands it over; one refused by the create or the wrap of its images retires it, as before. No unit test reaches the swapchain without a window system, and the fix is not yet checked on a VM boot; docs/lessons.md records the trap.
This commit is contained in:
1 parent
9db299bdba
commit
245a1ebb66
2 files changed
+53
-15
No files matched your search
@@ -597,6 +597,16 @@ pub fn report_gpu_time(
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
/// Why `Swapchain::make` made no swapchain, by whether Vulkan was asked for one with the old
|
||||
/// swapchain as its `oldSwapchain`, which retires the old one whatever the answer.
|
||||
#[derive(Debug)]
|
||||
enum Unmade {
|
||||
/// Refused before the create: the old swapchain is still the window's.
|
||||
Unasked(Refused),
|
||||
/// The create, or the wrap of its images, refused: the old swapchain is retired.
|
||||
Asked(Refused),
|
||||
}
|
||||
|
||||
/// A refusal naming `what` failed with `result`.
|
||||
fn refused(what: &str, result: vk::Result) -> Refused {
|
||||
Refused(format!("{what}: {result}"))
|
||||
@@ -1114,12 +1124,30 @@ impl Swapchain {
|
||||
size,
|
||||
old.as_ref().map_or(vk::SwapchainKHR::null(), |c| c.raw),
|
||||
);
|
||||
// Retired whether or not the new one was made.
|
||||
self.retired.extend(old);
|
||||
self.collect();
|
||||
self.chain = Some(made?);
|
||||
self.stale = false;
|
||||
Ok(())
|
||||
match made {
|
||||
Ok(chain) => {
|
||||
self.retired.extend(old);
|
||||
self.collect();
|
||||
self.chain = Some(chain);
|
||||
self.stale = false;
|
||||
Ok(())
|
||||
}
|
||||
// Vulkan was never handed the old swapchain, so it is still the window's: it stays the
|
||||
// current one, stale, and the next remake hands it over as `oldSwapchain`. Retired
|
||||
// here, the next create would pass none while it lives, which Windows refuses
|
||||
// (`VK_ERROR_NATIVE_WINDOW_IN_USE_KHR`) at every draw from then on.
|
||||
Err(Unmade::Unasked(e)) => {
|
||||
self.chain = old;
|
||||
self.stale = true;
|
||||
Err(e)
|
||||
}
|
||||
// A create that refused retired the old swapchain all the same.
|
||||
Err(Unmade::Asked(e)) => {
|
||||
self.retired.extend(old);
|
||||
self.collect();
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Takes the swapchain out once its frames have completed, waiting on nothing else; its
|
||||
@@ -1300,16 +1328,21 @@ impl Swapchain {
|
||||
|
||||
/// A swapchain for a window of `size` pixels, passing `old` as its `oldSwapchain`, its images
|
||||
/// wrapped as runtime textures (the module doc). A refusal for a lost surface marks it lost.
|
||||
fn make(&mut self, size: (u64, u64), old: vk::SwapchainKHR) -> Result<Chain, Refused> {
|
||||
fn make(&mut self, size: (u64, u64), old: vk::SwapchainKHR) -> Result<Chain, Unmade> {
|
||||
let _wsi = WSI.lock();
|
||||
// SAFETY: the surface and physical device are live, of one instance.
|
||||
let caps = unsafe {
|
||||
self.surface_api
|
||||
.get_physical_device_surface_capabilities(self.physical, self.surface)
|
||||
}
|
||||
.map_err(|e| self.refused_by("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", e))?;
|
||||
let extent = extent_for(size, &caps)
|
||||
.ok_or_else(|| Refused("the window's surface has no pixels for now".to_owned()))?;
|
||||
.map_err(|e| {
|
||||
Unmade::Unasked(self.refused_by("vkGetPhysicalDeviceSurfaceCapabilitiesKHR", e))
|
||||
})?;
|
||||
let extent = extent_for(size, &caps).ok_or_else(|| {
|
||||
Unmade::Unasked(Refused(
|
||||
"the window's surface has no pixels for now".to_owned(),
|
||||
))
|
||||
})?;
|
||||
let wanted = if self.is_mailbox() {
|
||||
MAILBOX_IMAGES
|
||||
} else {
|
||||
@@ -1348,11 +1381,14 @@ impl Swapchain {
|
||||
}
|
||||
// SAFETY: a valid create info over the live surface; `old` is this swapchain's last.
|
||||
let raw = unsafe { self.swapchain_api.create_swapchain(&info) }
|
||||
.map_err(|e| self.refused_by("vkCreateSwapchainKHR", e))?;
|
||||
let images = self.wrap(raw, extent, usage, sharing).inspect_err(|_| {
|
||||
// SAFETY: nothing was presented from the new swapchain.
|
||||
unsafe { self.swapchain_api.destroy_swapchain(raw) };
|
||||
})?;
|
||||
.map_err(|e| Unmade::Asked(self.refused_by("vkCreateSwapchainKHR", e)))?;
|
||||
let images = self
|
||||
.wrap(raw, extent, usage, sharing)
|
||||
.inspect_err(|_| {
|
||||
// SAFETY: nothing was presented from the new swapchain.
|
||||
unsafe { self.swapchain_api.destroy_swapchain(raw) };
|
||||
})
|
||||
.map_err(Unmade::Asked)?;
|
||||
Ok(Chain {
|
||||
raw,
|
||||
size,
|
||||
|
||||
@@ -65,6 +65,8 @@ one. A new trap found the same way goes here.
|
||||
|
||||
## QEMU, the window and VM boots
|
||||
|
||||
- A refusal that comes before the call it guards must leave the state as the call found it. The swapchain's remake retired the old swapchain whether or not the new one was made, and its make can refuse before `vkCreateSwapchainKHR`, where the window's surface has no pixels for now. Windows' window then still had the old swapchain, unretired as far as Vulkan knew, and each later remake, with no current swapchain left to hand over, made one with no `oldSwapchain` beside it, which Windows refuses while the old one lives (`VK_ERROR_NATIVE_WINDOW_IN_USE_KHR`). The window kept the installer's last frame through the rest of a macOS install while QMP's screendumps showed the guest going on, and minimizing and restoring it drew nothing (a Ryzen 5 5600G host with an RTX 3060, 2026-11-16); the log held one `no swapchain yet (the window's surface has no pixels for now)` at the guest's reboot and nothing after it, since a refusing swapchain logs only its first refusal. A make refused before the create now leaves the old swapchain the current one, stale, so the next remake hands it over. That the later creates failed with `VK_ERROR_NATIVE_WINDOW_IN_USE_KHR` is read from code and the Vulkan spec, not logged. How to spot the next one: a window that stops following the guest after one logged refusal, while the host's read-back of the display does follow it.
|
||||
|
||||
- An answer the newest Metal knows can be one an older Metal has no table for. The device answered the M3 Max's feature profile, 10, which 13.7.8, 14.8.9 and 26.7.2 create the device with; macOS 12's Metal keys every limit of a device on that profile, has none for 10, and left them 0, so WindowServer ended at device creation with a failed assertion that a limit be above 0 (`-[_MTLDevice initLimits]`), launchd gave up after 14 runs and the guest never reached its desktop. Unit tests and the boots of 14 and 26 passed throughout. The device now answers by what the guest's Metal has (`guest/bundle/src/RgfxFeatureProfile.hpp`). How to spot the next one: WindowServer crashing on `com.Metal.DeviceDispatch` under `MTLAddDevice` on one release and not the next; boot the oldest release of each answer's range, not only the newest.
|
||||
- A device-info answer chooses the guest's code, not only a value it reads. Answering Metal's SIMD bits of key 33 on the Vulkan platform, where they had followed the device, made hundreds more suite cases match Metal's, and a macOS 15.6.1 guest then died at boot: with the bits set, its frameworks chose a SIMD blur whose tile dispatch the runtime refuses, where before they took a fallback and booted. With that fixed, a 26.6.2 guest died at the next refusal down the same path, a sampler that path makes and the other never did. The suite's scenarios do not model the guest's choice, and guest shaders are never committed, so only a boot shows it. How to spot the next one: a change to what device info, GPU families or feature queries answer; boot the guests on it before it merges, and keep the old answer until they boot (AGENTS.md, "Checking a change").
|
||||
- A difference a boot already logs is a death on every boot once it is made one. A change that ended the process on two differences the Vulkan platform had logged passed `cargo xtask check`, and every macOS 26 boot then died early, at about 6 s on MoltenVK and 38 s on an NVIDIA driver, each at one of the two: the last good boot's log had counted 873 states with one and 20 with the other. No committed test runs the shaders a guest's boot draws. How to spot the next one: before a change ends the process on something the platform logged, look its code up in the last good boot's notice counts; any count there is a death every boot reaches.
|
||||
|
||||
Reference in new issue
Block a user