metal: render-target color textures must use the view's pixel format#639
Open
benface wants to merge 1 commit into
Open
metal: render-target color textures must use the view's pixel format#639benface wants to merge 1 commit into
benface wants to merge 1 commit into
Conversation
`new_pipeline` builds each pipeline's color attachment with the view's
`colorPixelFormat`, so Metal pipelines effectively bake in that format
at creation time. Color render textures created via
`new_render_texture` were following the requested `TextureFormat`
instead (e.g. `RGBA8` → `RGBA8Unorm`). The instant such a target was
bound to the pipeline, Metal validation tripped:
For color attachment 0, the render pipeline's pixelFormat
(MTLPixelFormatBGRA8Unorm) does not match the framebuffer's
pixelFormat (MTLPixelFormatRGBA8Unorm).
MTKView's allowed presentable formats are all `BGRA*` (or
`RGBA16Float`) — `RGBA8Unorm` isn't among them — so honoring
`TextureFormat::RGBA8` literally for color render targets silently
breaks every offscreen color attachment. Use the view's actual
`colorPixelFormat` for those textures so they round-trip through the
pipeline without a format mismatch. Sampling them in a shader is
unaffected: Metal's hardware swizzle returns RGBA semantics regardless
of memory order.
08402f2 to
fd253ce
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
new_pipelinebuilds each pipeline's color attachment with the view'scolorPixelFormat, so Metal pipelines effectively bake in that format at creation time. Color render textures created vianew_render_texturewere following the requestedTextureFormatinstead (e.g.RGBA8→RGBA8Unorm). The instant such a target was bound to that pipeline, Metal validation tripped:MTKView's allowed presentable formats are all
BGRA*(orRGBA16Float) —RGBA8Unormisn't among them — so honoringTextureFormat::RGBA8literally for color render targets silently breaks every offscreen color attachment.Use the view's actual
colorPixelFormatfor color render-target textures so they round-trip through the pipeline without a format mismatch. Sampling them in a shader is unaffected: Metal's hardware swizzle returns RGBA semantics regardless of memory order.Caught while wiring up macroquad's
render_target()on the iPhone 17 simulator running iOS 27.