{"record":{"id":"dcdd0b4c845192e7","repo":"gfx-rs/wgpu","slug":"cannot-create-swapchain-with-auto-presentationmode","errorCode":null,"errorMessage":"Cannot create swapchain with Auto PresentationMode","messagePattern":"Cannot create swapchain with Auto PresentationMode","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu-hal/src/vulkan/conv.rs","lineNumber":532,"sourceCode":"    };\n    let store_op = if op.contains(crate::AttachmentOps::STORE) {\n        vk::AttachmentStoreOp::STORE\n    } else if op.contains(crate::AttachmentOps::STORE_DISCARD) {\n        vk::AttachmentStoreOp::DONT_CARE\n    } else {\n        unreachable!()\n    };\n    (load_op, store_op)\n}\n\npub fn map_present_mode(mode: wgt::PresentMode) -> vk::PresentModeKHR {\n    match mode {\n        wgt::PresentMode::Immediate => vk::PresentModeKHR::IMMEDIATE,\n        wgt::PresentMode::Mailbox => vk::PresentModeKHR::MAILBOX,\n        wgt::PresentMode::Fifo => vk::PresentModeKHR::FIFO,\n        wgt::PresentMode::FifoRelaxed => vk::PresentModeKHR::FIFO_RELAXED,\n        wgt::PresentMode::AutoNoVsync | wgt::PresentMode::AutoVsync => {\n            unreachable!(\"Cannot create swapchain with Auto PresentationMode\")\n        }\n    }\n}\n\npub fn map_vk_present_mode(mode: vk::PresentModeKHR) -> Option<wgt::PresentMode> {\n    // Not exposed in Ash yet.\n    const FIFO_LATEST_READY: vk::PresentModeKHR = vk::PresentModeKHR::from_raw(1_000_361_000);\n\n    // See https://registry.khronos.org/vulkan/specs/latest/man/html/VkPresentModeKHR.html\n    match mode {\n        vk::PresentModeKHR::IMMEDIATE => Some(wgt::PresentMode::Immediate),\n        vk::PresentModeKHR::MAILBOX => Some(wgt::PresentMode::Mailbox),\n        vk::PresentModeKHR::FIFO => Some(wgt::PresentMode::Fifo),\n        vk::PresentModeKHR::FIFO_RELAXED => Some(wgt::PresentMode::FifoRelaxed),\n\n        // Modes that aren't exposed yet.\n        vk::PresentModeKHR::SHARED_DEMAND_REFRESH => None,\n        vk::PresentModeKHR::SHARED_CONTINUOUS_REFRESH => None,","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu-hal/src/vulkan/conv.rs#L514-L550","documentation":"`map_present_mode` in the Vulkan backend converts a wgpu `PresentMode` to `vk::PresentModeKHR`. The `AutoVsync`/`AutoNoVsync` variants are wgpu-level placeholders that must be resolved to a concrete present mode (based on the surface's supported modes) before swapchain creation, so passing them to the Vulkan mapper is an invariant violation and panics.","triggerScenarios":"Creating a swapchain/surface configuration with `present_mode: PresentMode::AutoVsync` or `AutoNoVsync` in a code path that bypasses wgpu-core's Auto-resolution (e.g. calling internal hal APIs directly, or a wgpu bug where Auto leaks into configure).","commonSituations":"Hand-rolling SurfaceConfiguration for internal/core APIs; forks or bindings that skip the resolution step; using Auto modes with an API (like an older wgpu version or direct hal usage) that expects them pre-resolved.","solutions":["Use the public `Surface::configure` API, which resolves Auto modes against supported present modes automatically","Set an explicit present mode (`Fifo`, `Mailbox`, `Immediate`, `FifoRelaxed`) that the surface supports (check via `surface.get_capabilities(&adapter)`)","If Auto resolution should have happened through the normal path, update wgpu and file a bug with a reproducer"],"exampleFix":"// before\nconfig.present_mode = wgpu::PresentMode::AutoVsync; // leaked unresolved to hal\nsurface.configure(&device, &config);\n// after\nlet caps = surface.get_capabilities(&adapter);\nconfig.present_mode = caps.present_modes.iter().copied()\n    .find(|m| !matches!(m, wgpu::PresentMode::AutoVsync | wgpu::PresentMode::AutoNoVsync))\n    .unwrap_or(wgpu::PresentMode::Fifo);\nsurface.configure(&device, &config);","handlingStrategy":"validation","validationCode":"let caps = surface.get_capabilities(&adapter);\nlet resolved = match config.present_mode {\n    m @ (wgpu::PresentMode::AutoVsync | wgpu::PresentMode::AutoNoVsync) => {\n        caps.present_modes.iter().copied().find(|p| !matches!(p, wgpu::PresentMode::AutoVsync | wgpu::PresentMode::AutoNoVsync)).unwrap_or(wgpu::PresentMode::Fifo)\n    }\n    m => m,\n};\nconfig.present_mode = resolved;","typeGuard":"fn is_concrete_present_mode(m: wgpu::PresentMode) -> bool {\n    !matches!(m, wgpu::PresentMode::AutoVsync | wgpu::PresentMode::AutoNoVsync)\n}","tryCatchPattern":null,"preventionTips":["Let Surface::configure resolve Auto modes; don't pass configs into internal hal APIs","Verify chosen modes against surface.get_capabilities","Default to Fifo, which is universally supported"],"tags":["vulkan","present-mode","swapchain","unreachable","internal-invariant"],"backgroundTag":"unresolved-enum-variant","analyzedSha":"3e11ff59bf3f9795d285ecc045014089640d7248","analyzedAt":"2026-09-03T01:43:21.459Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}