gfx-rs/wgpu · error

invalid mip level

Error message

invalid mip level

What it means

A generic guard panic raised by expect() after mip_level_size() returned None: the mip_level passed to compute_render_extent is out of range for this texture, i.e. it is >= the texture's mip_level_count (or the texture was created with mip level count 1 while a larger level was requested). The offending input is the mip_level argument itself.

Source

Thrown at wgpu-types/src/texture.rs:725

    }

    /// Computes the render extent of this texture.
    ///
    /// This is a low-level helper exported for use by wgpu-core.
    ///
    /// <https://gpuweb.github.io/gpuweb/#abstract-opdef-compute-render-extent>
    ///
    /// # Panics
    ///
    /// If the mip level is out of range.
    #[doc(hidden)]
    #[must_use]
    pub fn compute_render_extent(&self, mip_level: u32, plane: Option<u32>) -> Extent3d {
        let Extent3d {
            width,
            height,
            depth_or_array_layers: _,
        } = self.mip_level_size(mip_level).expect("invalid mip level");

        let (w_subsampling, h_subsampling) = self.format.subsampling_factors(plane);

        let width = width / w_subsampling;
        let height = height / h_subsampling;

        Extent3d {
            width,
            height,
            depth_or_array_layers: 1,
        }
    }

    /// Returns the number of array layers.
    ///
    /// <https://gpuweb.github.io/gpuweb/#abstract-opdef-array-layer-count>
    #[must_use]
    pub fn array_layer_count(&self) -> u32 {

View on GitHub (pinned to 3e11ff59bf)

Solutions

  1. Ensure the mip_level passed to compute_render_extent is less than the texture's mip_level_count as specified at creation (TextureDescriptor.mip_level_count)
  2. If you need the extent of the smallest mip level, use texture.mip_level_count() - 1 or size.mip_level_size(...) helpers to query a valid level
  3. When computing render extents for a view, derive the mip level from the view's base_mip_level, which wgpu-core has already validated against the texture
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at wgpu-types/src/texture.rs:725 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/894760df188c32e2. Report an issue: GitHub.