Repository navigation
Commit 9dbb687
[Impeller] Sample the render target rect in offscreen advanced blends (flutter#192988)
## Problem
In the offscreen advanced blend path, the subpass render target is
allocated with an integral size — `ISize(subpass_coverage.GetSize())`, a
truncating conversion — and the quad spans that render target. But the
texture coordinates are derived from the full, fractional coverage. The
quad therefore displays a slightly larger region than it covers, scaling
the contents by `trunc(w)/w`.
That factor changes whenever the coverage crosses a pixel boundary, so
animated content is resampled differently every frame, which reads as
shaking and crawling. The coverage does not need to be meaningfully
fractional: in the per-draw path the blend runs over the whole pass
(`FlipBackdrop`), and floating-point residue in the transform chain is
enough — instrumenting master while running the Rive artboard below, the
extent truncated on 29% of blend subpasses and the origin was fractional
on 34%.
Only configurations **without framebuffer fetch** take this path — the
iOS simulator, PowerVR, and Adreno on GLES. Devices with framebuffer
fetch blend in-pass via `ApplyFramebufferBlend`, which is exact.
## Fix
Derive the texture coordinates from the rect the render target actually
represents, so the quad and the sampled region agree exactly. The render
target size, the composite origin and the composited rect are all
unchanged from master; `PipelineBlend` draws each input at its own size
and transform and never had this mismatch, so it is not touched.
## Verification
Measured on an iPhone 17 Pro simulator against a Rive artboard
exercising Multiply, Screen, Overlay, Soft Light and Color Dodge, loaded
with `Factory.flutter` so drawing goes through Flutter's canvas and into
Impeller's blend paths. The landmark is the left edge of static artboard
content that never moves in the animation, so every pixel of movement is
the bug. 40 consecutive frames:
| landmark | master | this PR |
|---|---|---|
| row 1 — position range | 0.237 px | **0.000 px** |
| row 3 — position range | 0.655 px | **0.000 px** |
| row 3 — frames moving >0.25 px | 10 / 39 | **0 / 39** |
<details>
<summary>lib/main.dart</summary>
```dart
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await RiveNative.init();
runApp(const MaterialApp(home: Scaffold(body: BlendModeTest())));
}
class BlendModeTest extends StatefulWidget {
const BlendModeTest({super.key});
@OverRide
State<BlendModeTest> createState() => _BlendModeTestState();
}
class _BlendModeTestState extends State<BlendModeTest> {
File? _file;
RiveWidgetController? _controller;
@OverRide
void initState() {
super.initState();
_load();
}
Future<void> _load() async {
// Factory.flutter routes drawing through Flutter's Canvas, so the artboard
// goes through Impeller's blend paths. Factory.rive would use Rive's own
// renderer and would not exercise this code at all.
final file = await File.asset(
'assets/blend_mode_test.riv',
riveFactory: Factory.flutter,
);
if (file == null) {
return;
}
setState(() {
_file = file;
_controller = RiveWidgetController(file);
});
}
@OverRide
void dispose() {
_controller?.dispose();
_file?.dispose();
super.dispose();
}
@OverRide
Widget build(BuildContext context) {
final controller = _controller;
if (controller == null) {
return const Center(child: CircularProgressIndicator());
}
return Container(
color: const Color(0xFF9E9E9E),
child: RiveWidget(controller: controller, fit: Fit.contain),
);
}
}
```
</details>
| before | after |
|---|---|
|
https://github.com/user-attachments/assets/0dfa75f6-8b7f-4cb6-876d-3314baac2f44
|
https://github.com/user-attachments/assets/87f59617-12b4-40cb-9da4-35990d5df1ee
|
*(The recordings were made with an earlier revision of this change; the
measured result for the final revision is identical.)*
## Golden change
This changes exactly one engine golden (of 466 Metal goldens compared
locally): `ColorFilterAdvancedBlendNoFbFetch`. It is a correction, not a
regression. That test stacks thirty full-frame blends, so the per-frame
resampling error accumulates into a visible smear of every cell edge.
Cell 2's image begins at x=400 (400 px pitch, 320 px images); row y=220:
| x → | 396 | 398 | 400 | 402 | 404 | 406 |
|---|---|---|---|---|---|---|
| same test through framebuffer fetch (exact) | black | black |
(230,128,0) | (230,128,0) | (230,128,0) | (230,128,0) |
| current golden | (255,116,0) | (255,137,0) | (229,128,0) | (229,128,0)
| (221,125,5) | (199,121,20) |
| this PR | black | black | (229,128,0) | (229,128,0) | (229,128,0) |
(229,128,0) |
The current golden bleeds orange four pixels into the empty gap before
the cell and blurs the edge over ~7 px; this PR matches the exact
in-pass rendering to within 1/255. The golden will need triage.
## Tests
`DlGoldenTest.StackedOffscreenAdvancedBlendsDoNotResample` renders a
hard backdrop edge and blends over it thirty times with `kLighten` on a
context without framebuffer fetch, then requires the result to match a
single blend. Lighten is idempotent, so the only thing that can differ
is resampling error accumulated across the stacked subpasses. A 0.4x
canvas scale makes the full-pass coverage fractional the same way the
golden does. **Fails on master (RMSE 5.75), passes with this change
(RMSE 0).**
`impeller_unittests` `*Blend*`/`*Filter*`: 791 passing, 0 failing. The
`ColorFilterAdvancedBlendNoFbFetch` golden exercises the same path with
thirty stacked blends and visibly captures the defect.
Fixes flutter#192980
## 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.
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/AI-contributions.md
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[CLA]: https://cla.developers.google.com/
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
---------
Co-authored-by: b-luk <[email protected]>1 parent 1467f62 commit 9dbb687
3 files changed
Lines changed: 252 additions & 26 deletions
File tree
- engine/src/flutter/impeller
- display_list
- entity/contents/filters
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
650 | 653 | | |
651 | 654 | | |
652 | 655 | | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
653 | 824 | | |
654 | 825 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
116 | 118 | | |
117 | 119 | | |
118 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
119 | 156 | | |
120 | 157 | | |
121 | 158 | | |
122 | 159 | | |
123 | 160 | | |
124 | | - | |
| 161 | + | |
125 | 162 | | |
126 | 163 | | |
127 | 164 | | |
| |||
138 | 175 | | |
139 | 176 | | |
140 | 177 | | |
141 | | - | |
| 178 | + | |
142 | 179 | | |
143 | 180 | | |
144 | 181 | | |
| |||
148 | 185 | | |
149 | 186 | | |
150 | 187 | | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | 188 | | |
167 | 189 | | |
168 | 190 | | |
| |||
226 | 248 | | |
227 | 249 | | |
228 | 250 | | |
229 | | - | |
230 | | - | |
231 | | - | |
| 251 | + | |
232 | 252 | | |
233 | 253 | | |
234 | 254 | | |
| |||
242 | 262 | | |
243 | 263 | | |
244 | 264 | | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
251 | 271 | | |
252 | 272 | | |
253 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
67 | 102 | | |
68 | 103 | | |
0 commit comments