Repository navigation
Use uniforms in the Porter Duff blend shader instead of specialization constants - #195458
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request consolidates the multiple specialized Porter-Duff blend pipelines in Impeller into a single pipeline, passing the blend coefficients as uniforms via the fragment shader's uniform block instead of using specialization constants. The feedback identifies a potential out-of-bounds read in the new 'SetPorterDuffCoefficients' function if an invalid or negative 'BlendMode' is cast, recommending a cast to 'size_t' prior to the bounds check to ensure safety.
| if (blend_mode > Entity::kLastPipelineBlendMode) { | ||
| VALIDATION_LOG << "Invalid porter duff blend mode " | ||
| << BlendModeToString(blend_mode); | ||
| blend_mode = BlendMode::kClear; | ||
| } |
There was a problem hiding this comment.
If blend_mode is negative (which can happen if an invalid integer is cast to BlendMode or due to uninitialized memory), the direct comparison blend_mode > Entity::kLastPipelineBlendMode will evaluate to false because BlendMode is typically a signed enum. Subsequently, static_cast<size_t>(blend_mode) will wrap around to a very large value, leading to an out-of-bounds read on kPorterDuffCoefficients and a potential crash.
To prevent this, cast blend_mode to size_t before performing the comparison. This handles both negative values and values exceeding the upper bound in a single check.
| if (blend_mode > Entity::kLastPipelineBlendMode) { | |
| VALIDATION_LOG << "Invalid porter duff blend mode " | |
| << BlendModeToString(blend_mode); | |
| blend_mode = BlendMode::kClear; | |
| } | |
| if (static_cast<size_t>(blend_mode) > static_cast<size_t>(Entity::kLastPipelineBlendMode)) { | |
| VALIDATION_LOG << "Invalid porter duff blend mode " | |
| << BlendModeToString(blend_mode); | |
| blend_mode = BlendMode::kClear; | |
| } |
There was a problem hiding this comment.
BlendMode is an unsigned int8
. If an invalid integer were cast to it, it would wrap to the valid range.There was a problem hiding this comment.
Code Review
This pull request consolidates the individual Porter-Duff blend pipelines in Impeller into a single pipeline (porter_duff_blend) that selects the blend mode dynamically using uniforms. The porter_duff_blend.frag shader, ContentContext, AtlasContents, BlendFilterContents, and VerticesSimpleBlendContents have been updated to support this unified pipeline by passing blend coefficients as uniforms. Feedback points out a potential out-of-bounds memory access in SetPorterDuffCoefficients if BlendMode is a signed enum and a negative value is passed, which can bypass the bounds check. Casting blend_mode to size_t before comparison is recommended to prevent this issue.
| if (blend_mode > Entity::kLastPipelineBlendMode) { | ||
| VALIDATION_LOG << "Invalid porter duff blend mode " | ||
| << BlendModeToString(blend_mode); | ||
| blend_mode = BlendMode::kClear; | ||
| } |
There was a problem hiding this comment.
If BlendMode is a signed enum, passing a negative value to SetPorterDuffCoefficients will bypass the blend_mode > Entity::kLastPipelineBlendMode check. When it is subsequently cast to size_t to index kPorterDuffCoefficients, it will wrap around to a very large value, causing an out-of-bounds memory access.\n\nCasting both operands to size_t before comparison ensures that any negative values are correctly caught as being out of bounds.
if (static_cast<size_t>(blend_mode) >\n static_cast<size_t>(Entity::kLastPipelineBlendMode)) {\n VALIDATION_LOG << "Invalid porter duff blend mode "\n << BlendModeToString(blend_mode);\n blend_mode = BlendMode::kClear;\n }|
autosubmit label was removed for flutter/flutter/195458, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
autosubmit label was removed for flutter/flutter/195458, because - The status or check suite Presubmit has failed. Please fix the issues identified (or deflake) before re-applying this label. |
flutter/flutter@5e805bf...ee8b482 2026-10-31 [email protected] Roll Skia from 9bab765df357 to 607de4b035dc (1 revision) (flutter/flutter#195728) 2026-10-31 [email protected] Roll Skia from 284054bec98a to 9bab765df357 (2 revisions) (flutter/flutter#195726) 2026-10-31 [email protected] Roll Skia from 3a3f56f7ddd4 to 284054bec98a (1 revision) (flutter/flutter#195724) 2026-10-31 [email protected] Roll Skia from 466994d27b1e to 3a3f56f7ddd4 (1 revision) (flutter/flutter#195719) 2026-10-30 [email protected] Fix XcodeProjectInterpreter dependency cycle in flutter_tools (flutter/flutter#195694) 2026-10-30 [email protected] Document that Positioned also works inside an Overlay (flutter/flutter#190607) 2026-10-30 [email protected] Roll Skia from ce0b85b46db6 to 466994d27b1e (3 revisions) (flutter/flutter#195711) 2026-10-30 [email protected] Adds Vulkan sync validation test run (flutter/flutter#195596) 2026-10-30 [email protected] [Android] Let the raster thread use every core of a chip without little cores (flutter/flutter#195071) 2026-10-30 [email protected] Roll Skia from 121d04c01e2d to ce0b85b46db6 (6 revisions) (flutter/flutter#195699) 2026-10-30 [email protected] [web] Anchor platform view slots to top-left to fix RTL document layout (flutter/flutter#194601) 2026-10-30 [email protected] Update golden file testing docs (flutter/flutter#195449) 2026-10-30 [email protected] [tool] Migrate Cache.flutterRoot static state to instance configuration (flutter/flutter#190795) 2026-10-30 [email protected] Apply view metrics overrides below the framework (flutter/flutter#194311) 2026-10-30 [email protected] Roll Skia from c0c46ee9f938 to 121d04c01e2d (9 revisions) (flutter/flutter#195687) 2026-10-30 [email protected] Use uniforms in the Porter Duff blend shader instead of specialization constants (flutter/flutter#195458) 2026-10-30 [email protected] [flutter_tools] Inject dependencies into iOS, macOS, and Windows application packages (flutter/flutter#194047) If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…n constants (flutter#195458) Changes the Porter Duff blend shader to use uniforms instead of specialization constants for the blending coefficients. As each specialized variant triggered a full shader compile, this removes 14 shader compiles (~23%) from the engine initialization path, it also removes overhead from swapping shaders. This was how the shader was initially configured. It was modified to use specialization constants because of compilation issues on adreno chips using Vulkan ([PR](flutter#161273), [issue](flutter#161209)). However, those chips are now blacklisted from Vulkan ([PR](flutter#178833)) - so no compilation issues occur. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing.
Changes the Porter Duff blend shader to use uniforms instead of specialization constants for the blending coefficients. As each specialized variant triggered a full shader compile, this removes 14 shader compiles (~23%) from the engine initialization path, it also removes overhead from swapping shaders.
This was how the shader was initially configured. It was modified to use specialization constants because of compilation issues on adreno chips using Vulkan (PR, issue). However, those chips are now blacklisted from Vulkan (PR) - so no compilation issues occur.
Pre-launch Checklist
///).