Skip to content

metal: assert on 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: assert on 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.

Comment thread src/graphics/metal.rs Outdated
Calling `texture_generate_mipmaps` on a texture allocated without
mipmaps is a programmer error 99% of the time. Today 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.`

Raise the failure at the call site with a clear panic message
instead of crashing deep inside the blit encoder. The fix is on
the caller: pass `TextureParams::allocate_mipmaps = true` at
creation if you intend to generate mipmaps later.
@benface benface force-pushed the metal-generate-mipmaps-noop branch from 14e7f18 to 2d8823b Compare June 15, 2026 22:17
@benface

benface commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Switched to a panic with a clearer message — agreed that catching the bug at the call site is better than a silent no-op. Branch + PR title now reflect the new behaviour ('assert on texture_generate_mipmaps...'). 🙏

@benface benface changed the title metal: no-op texture_generate_mipmaps for non-mipmapped textures metal: assert on texture_generate_mipmaps for non-mipmapped textures Jun 15, 2026
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.

2 participants