Skip to content

metal: no-op texture_generate_mipmaps for non-mipmapped textures#637

Open
benface wants to merge 1 commit into
not-fl3:masterfrom
benface:metal-generate-mipmaps-noop
Open

metal: no-op texture_generate_mipmaps for non-mipmapped textures#637
benface wants to merge 1 commit into
not-fl3:masterfrom
benface:metal-generate-mipmaps-noop

Conversation

@benface

@benface benface commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Problem

RenderingBackend::texture_generate_mipmaps's doc comment already promises:

Metal-specific note: if texture was created without params.generate_mipmaps, generate_mipmaps will do nothing.

But the Metal implementation in graphics/metal.rs unconditionally calls generateMipmapsForTexture: without checking the texture's allocate_mipmaps flag. With Metal validation on, the call fails on any texture that has mipmapLevelCount == 1:

-[MTLDebugBlitCommandEncoder generateMipmapsForTexture:]:1105: failed assertion `Generate Mipmaps For Texture Validation
[tex mipmapLevelCount](1) must be > 1.

Fix

Early-return when texture.params.allocate_mipmaps is false. Honours the documented contract and matches the OpenGL backend's behaviour.

Tested on

iPhone 17 simulator on iOS 27 beta — assert gone for macroquad apps that call set_filter (which routes through texture_generate_mipmaps for the mipmap filter mode) on non-mipmapped textures.

The trait method's doc comment already promises:

    Metal-specific note: if texture was created without
    `params.generate_mipmaps`, `generate_mipmaps` will do nothing.

But the Metal implementation unconditionally calls
`generateMipmapsForTexture:`, which Metal validation rejects when the
texture has `mipmapLevelCount == 1`:

    -[MTLDebugBlitCommandEncoder generateMipmapsForTexture:]:1105:
    failed assertion `Generate Mipmaps For Texture Validation
    [tex mipmapLevelCount](1) must be > 1.`

Honour the documented contract — early-return when
`params.allocate_mipmaps` is false. Matches the OpenGL backend's
behaviour and the docstring.
@benface benface force-pushed the metal-generate-mipmaps-noop branch from c0678b5 to 14e7f18 Compare June 13, 2026 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant