gfx-rs/wgpu · error

Surface should be a native Vulkan surface

Error message

Surface should be a native Vulkan surface

What it means

Panic in SurfaceTextureExt/compute_render_extent's mip_level_size call: the requested mip level exceeds the texture's mip level count, so no size exists for it. The faulty input is the out-of-range mip_level argument.

Source

Thrown at wgpu-hal/src/vulkan/mod.rs:359

    /// - `chain` must point to a valid `pNext` chain of structs that can extend
    ///   [`vk::SwapchainCreateInfoKHR`]. The extensions in the chain must be enabled
    ///   on the device the surface is configured with.
    /// - The chain must stay valid until the configuration that consumes it returns
    ///   or the surface is dropped. Don't read or write the chain during that time.
    ///   Fields the driver wrote during swapchain creation may be read afterwards.
    ///
    /// # Panics
    ///
    /// - If the surface isn't a native Vulkan surface, such as a DXGI surface.
    ///
    /// [VK_NV_low_latency2]: https://registry.khronos.org/vulkan/specs/latest/man/html/VK_NV_low_latency2.html
    #[track_caller]
    pub unsafe fn set_next_swapchain_create_chain(&self, chain: *mut c_void) {
        let surface = self
            .inner
            .as_any()
            .downcast_ref::<swapchain::NativeSurface>()
            .expect("Surface should be a native Vulkan surface");
        unsafe { surface.set_next_swapchain_create_chain(chain) };
    }
}

#[derive(Debug)]
pub struct SurfaceTexture {
    index: u32,
    texture: Texture,
    metadata: Box<dyn swapchain::SurfaceTextureMetadata>,
}

impl crate::DynSurfaceTexture for SurfaceTexture {}

impl Borrow<Texture> for SurfaceTexture {
    fn borrow(&self) -> &Texture {
        &self.texture
    }
}

View on GitHub (pinned to 3e11ff59bf)

Solutions

  1. Ensure mip_level < texture.mip_level_count before computing render extents
  2. Validate the subresource range against the texture descriptor
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at wgpu-hal/src/vulkan/mod.rs:359 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gfx-rs/wgpu@3e11ff59bf (2026-09-03). Data as JSON: /api/errors/5924945949a17e13. Report an issue: GitHub.