{"record":{"id":"d79ff4260203a0b1","repo":"gfx-rs/wgpu","slug":"wgpu-core-resolves-auto-before-configuring-the-s","errorCode":null,"errorMessage":"wgpu-core resolves `Auto` before configuring the surface","messagePattern":"wgpu-core resolves `Auto` before configuring the surface","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"wgpu-hal/src/vulkan/conv.rs","lineNumber":199,"sourceCode":"}\n\npub fn map_vk_color_space(color_space: vk::ColorSpaceKHR) -> Option<wgt::SurfaceColorSpace> {\n    use wgt::SurfaceColorSpace as Scs;\n    Some(match color_space {\n        vk::ColorSpaceKHR::SRGB_NONLINEAR => Scs::Srgb,\n        vk::ColorSpaceKHR::EXTENDED_SRGB_LINEAR_EXT => Scs::ExtendedSrgbLinear,\n        vk::ColorSpaceKHR::EXTENDED_SRGB_NONLINEAR_EXT => Scs::ExtendedSrgb,\n        vk::ColorSpaceKHR::DISPLAY_P3_NONLINEAR_EXT => Scs::DisplayP3,\n        vk::ColorSpaceKHR::HDR10_ST2084_EXT => Scs::Bt2100Pq,\n        vk::ColorSpaceKHR::HDR10_HLG_EXT => Scs::Bt2100Hlg,\n        _ => return None,\n    })\n}\n\npub fn map_surface_color_space(color_space: wgt::SurfaceColorSpace) -> vk::ColorSpaceKHR {\n    use wgt::SurfaceColorSpace as Scs;\n    match color_space {\n        Scs::Auto => unreachable!(\"wgpu-core resolves `Auto` before configuring the surface\"),\n        Scs::Srgb => vk::ColorSpaceKHR::SRGB_NONLINEAR,\n        Scs::ExtendedSrgbLinear => vk::ColorSpaceKHR::EXTENDED_SRGB_LINEAR_EXT,\n        Scs::ExtendedSrgb => vk::ColorSpaceKHR::EXTENDED_SRGB_NONLINEAR_EXT,\n        Scs::DisplayP3 => vk::ColorSpaceKHR::DISPLAY_P3_NONLINEAR_EXT,\n        Scs::Bt2100Pq => vk::ColorSpaceKHR::HDR10_ST2084_EXT,\n        Scs::Bt2100Hlg => vk::ColorSpaceKHR::HDR10_HLG_EXT,\n        Scs::ExtendedDisplayP3 => {\n            unreachable!(\"`ExtendedDisplayP3` is never reported in the Vulkan surface capabilities\")\n        }\n    }\n}\n\nimpl crate::Attachment<'_, super::TextureView> {\n    pub(super) fn make_attachment_key(&self, ops: crate::AttachmentOps) -> super::AttachmentKey {\n        super::AttachmentKey {\n            format: self.view.raw_format,\n            layout: derive_image_layout(self.usage, self.view.format),\n            ops,","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/gfx-rs/wgpu/blob/3e11ff59bf3f9795d285ecc045014089640d7248/wgpu-hal/src/vulkan/conv.rs#L181-L217","documentation":"`map_surface_color_space` in the Vulkan backend converts a wgpu `SurfaceColorSpace` to a `vk::ColorSpaceKHR`. The `Auto` variant is a wgpu-level placeholder that must be resolved to a concrete color space by wgpu-core (based on surface capabilities) before any backend configuration happens, so reaching the Vulkan mapper with `Auto` is an internal invariant violation and panics via unreachable!.","triggerScenarios":"Calling surface configuration paths with `SurfaceConfiguration { color_space: SurfaceColorSpace::Auto, .. }` in a way that bypasses wgpu-core's Auto-resolution step, or an internal wgpu bug where configure_surface reaches hal with Auto still set.","commonSituations":"Almost exclusively a wgpu-internal bug or a user constructing a SurfaceConfiguration manually and forwarding it through an internal/core API without going through the public `Surface::configure` resolution path; could also appear in forks or bindings that skip wgpu-core validation.","solutions":["Use the public `Surface::configure(&device, &SurfaceConfiguration)` API and let wgpu-core resolve Auto for you","If you need a deterministic color space, set `color_space` explicitly to `Srgb` or `ExtendedSrgbLinear` instead of `Auto`","Update wgpu — if this fires through the normal public API, it is a bug; check the changelog and file an issue with a reproducer"],"exampleFix":"// before\nlet mut config = surface.get_default_config(&adapter, size.into()).unwrap();\nconfig.color_space = wgpu::SurfaceColorSpace::Auto; // must be resolved by core\nsurface.configure(&device, &config);\n// after\nlet mut config = surface.get_default_config(&adapter, size.into()).unwrap();\nconfig.color_space = wgpu::SurfaceColorSpace::ExtendedSrgbLinear;\nsurface.configure(&device, &config);","handlingStrategy":"validation","validationCode":"if config.color_space == wgpu::SurfaceColorSpace::Auto {\n    // resolve via surface capabilities before configuring\n    config.color_space = wgpu::SurfaceColorSpace::Srgb;\n}","typeGuard":"fn is_resolved_color_space(cs: wgpu::SurfaceColorSpace) -> bool {\n    !matches!(cs, wgpu::SurfaceColorSpace::Auto)\n}","tryCatchPattern":"catch (e) { if (String(e).includes('resolves `Auto`')) { config.color_space = wgpu::SurfaceColorSpace::Srgb; surface.configure(device, config); } }","preventionTips":["Only set SurfaceConfiguration through the public Surface::configure path","Prefer explicit color spaces over Auto when targeting specific backends","Keep wgpu up to date so Auto resolution bugs are patched"],"tags":["vulkan","surface","color-space","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"}