Fix Metal stencil mismatch in mutable-image seed pass (#5103)#5106
Merged
Conversation
CN1MetalEnsureMutableTexture's seed pass (used when an existing UIImage's pixels need to be carried into a freshly-allocated mutable texture) built its render pass with only a colour attachment, then bound the TexturedRGBA pipeline -- which declares stencilAttachmentPixelFormat=Stencil8 since the polygon-clip work in #3921. Metal's validation layer aborts setRenderPipelineState: with "For stencil attachment, the renderPipelineState pixelFormat must be MTLPixelFormatInvalid, as no texture is set", crashing any app that lands on a screen whose first paint touches a seeded mutable image (e.g. gausianBlurImage, FontImage thumbnails). Allocate a throwaway Stencil8 texture for the pass mirroring the pattern already used in CN1MetalBeginMutableImageDraw. The seed draw never engages the stencil test, so loadAction=Clear / storeAction=DontCare is enough. The sibling clearPass above doesn't need the same treatment -- it never calls setRenderPipelineState:, so the validation rule isn't triggered. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
✅ Continuous Quality ReportTest & Coverage
Static Analysis
Generated automatically by the PR CI workflow. |
Collaborator
Author
|
Compared 122 screenshots: 122 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
Collaborator
Author
|
Compared 122 screenshots: 122 matched. Benchmark Results
Build and Run Timing
Detailed Performance Metrics
|
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.
Summary
setRenderPipelineState:withFor stencil attachment, the renderPipelineState pixelFormat must be MTLPixelFormatInvalid, as no texture is set.CN1MetalPipelineCache.mdeclaresstencilAttachmentPixelFormat = MTLPixelFormatStencil8(added with the polygon-clip stencil work in Clipping region not respected with non-90 degree rotations. #3921), so every render pass that binds one must attach a Stencil8 texture. The seed pass inCN1MetalEnsureMutableTexture(used to carry an existingUIImage's pixels —gausianBlurImage,FontImagethumbnails, etc. — into a freshly-allocated mutable target) was built with only a colour attachment but then bound the TexturedRGBA pipeline.CN1MetalBeginMutableImageDrawa few lines below. The seed draw never engages the stencil test, soloadAction=Clear/storeAction=DontCareis sufficient.The sibling
clearPassimmediately above the seed pass does not need the same fix — it never callssetRenderPipelineState:(it just clears the colour attachment and ends the encoder), so the validation rule is not triggered.Test plan
FontImage/gausianBlurImage-derived mutable image and confirm the app no longer crashes on the first form.🤖 Generated with Claude Code