Visitar URL original
[avio] cherry-pick: shade linear and radial gradients inside UberSDF … · avio-os/avio-flutter@ecae8de · GitHub
Skip to content

Commit ecae8de

Browse files
RickyvdBergclaude
andcommitted
[avio] cherry-pick: shade linear and radial gradients inside UberSDF (flutter#192124, flutter#192962)
UberSDF in this fork cannot shade a color source, so every antialiased gradient rect, rrect, oval or circle (Avio's Shell and greeter run with use_sdfs) was blended through a white SDF mask: two snapshots and a blend target per draw, plus a deferred coverage pass in externalLinearBackdrop mode. Upstream fixed this in the owning layer: fdb1d09 (flutter#192124) shades linear and radial gradients inside UberSDF and 419f9dd (flutter#192962) adds the storage-buffer variant used on Vulkan, so no ramp texture is made per draw. Both upstream commits sit on intermediate UberSDF changes this fork does not carry (uniform reordering, rect-path derivatives, stroke pixel size, which would change other SDF output), and Avio's UberSDF carries patch 45's coverage fields, so this is an adapted backport in one commit, not literal cherry-picks: - uber_sdf.frag is split into uber_sdf_common.glsl (shape SDFs, getColor, main) plus uber_sdf.frag (ramp texture) and uber_sdf_ssbo.frag (gradient stops in a storage buffer, the same math as the SSBO gradient shaders). Wherever the backend supports SSBOs (Vulkan), every UberSDF draw uses the SSBO variant, as upstream does. - UberSDFParameters gains GradientParameters; UberSDFContents renders both variants from one FragInfo setup; color filters wrap on the GPU for a gradient, and a gradient is never a background color. - Canvas::AddRenderSDFEntityToCurrentPass shades a linear or radial gradient whose local matrix (with the inverse shape transform) is a similarity. Conical and sweep gradients, images and runtime effects keep the masked kSrcIn path patch 52 slims. Patch 52's no-mask rect still comes first. - A gradient shaded in UberSDF takes the coverage transfer in the shader; defer_coverage no longer includes the color source in that case. Avio deltas against upstream (decision D3, accepted on the condition that Avio's crisp look stays): - Edges keep the old response: a gradient's SDF alpha uses the light-foreground gamma correction of the white mask it was blended through before, not the gradient's luma; the SSBO variant dithers like the SSBO gradient shaders, and like the masked composite it dithers the gradient color before coverage scales it, so a pixel the shape does not cover (the AA band's outside, the quad corners around a rounded shape) stays exactly transparent and srcOver adds nothing to what lies underneath. Upstream does not dither in UberSDF. - Linear gradients also require a similarity matrix (upstream checks only affinity); mapping end points through a shear or non-uniform scale does not map the gradient's field. - flutter#191925 and flutter#191980 are not brought in: the ramp-texture variant uses the fork's current GradientData, and Avio's SDF users take the SSBO variant. - malioc.json is not updated. Nothing else on the branch depends on this commit; its tests use patch 52's Playground::EnsureContextUsesSDFs. Reverting it alone restores the masked path exactly. Tests: - UberSDFContentsTest.ApplyColorFilterWithGradient and AsBackgroundColorGradientReturnsNullopt (from upstream; red as compile failures on the base: GradientParameters did not exist). - On every playground that renders with SDFs (Playground:: EnsureContextUsesSDFs: Vulkan with SDFs enabled, which runs the storage-buffer variant Avio ships, and the OpenGL ES and Metal SDF backends, which run the ramp-texture variant; plain backends skip): AiksTest.SdfLinearGradientRectAllocatesNoOffscreen (expected red on the base: three offscreens), SdfRadialGradientCircleUnderNonUniformScale- AllocatesNoOffscreen, UnsupportedColorSourceStillBlends (a sweep gradient keeps exactly three offscreens), and SdfGradientEdgesMatchMaskedComposite: the pixel guard the user asked for. It renders rect, rounded rect, oval and circle with an opaque dark-to-light gradient and a translucent glass sheen, in platformDefault and externalLinearBackdrop, once shaded in UberSDF and once through the old masked composite (the same horizontal gradient with a y-scale local matrix, which leaves its field unchanged but routes it through the masked path). Every pixel, corners and antialiased edges included, must hold alpha within 2/255 and color within 2/255 (ramp texture, no dither) or 5/255 (storage buffer: the composite dithered in its snapshot's grid, then quantized once more); every pixel the composite leaves fully transparent must stay exactly zero. Green by construction on the base (both renders take the masked path there); after this patch it fails if edges, corners, glass coverage or uncovered pixels drift. - SdfGradientLeavesUncoveredQuadPixelsTransparent: the quad corners around a gradient circle are exactly zero in both coverage modes, opaque and glass. Red on the storage-buffer variant if the dither runs after coverage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e8af02e commit ecae8de

16 files changed

Lines changed: 1264 additions & 326 deletions

‎AVIO_PATCHES.md‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ already ancestors of the selected main target under their original commits.
8686
| 48 | Flip allocates a single-sample secondary | upstreamable memory fix | submit upstream |
8787
| 51 | RenderTargetCache ages once per raster frame | upstreamable correctness fix (offer on flutter/flutter#190613) | open: flutter/flutter#190613 |
8888
| 52 | SDF colour sources: no mask when the shape contains the clip; single-sample snapshots otherwise | upstreamable memory/performance fix | submit upstream |
89+
| 50 | cherry-pick: shade linear and radial gradients inside UberSDF (flutter#192124, #192962) | temporary backport — drop at the next rebase onto a base that contains #192124 and #192962, after re-checking the two Avio deltas below | merged upstream: flutter/flutter#192124, #192962 |
8990

9091
Patch #5 also owns the later exact empty-frame and global-request corrections:
9192
global requests may not be consumed by a display-scoped frame; sibling-render,
@@ -830,6 +831,60 @@ against the masked path, forced by a clip the rect does not contain) and
830831
`SingleSampleMaskInputsMatchMultisampledInputs` ((b): the same kSrcIn
831832
composite with multisampled, depth/stencil inputs as before, within 1/255).
832833

834+
### Patch 50: gradients inside UberSDF (backport)
835+
836+
Upstream moved linear and radial gradients into UberSDF (`fdb1d09ef8`,
837+
flutter#192124; `419f9dd65e`, flutter#192962, the storage-buffer variant).
838+
The fork base predates them and their prerequisites, and Avio's UberSDF
839+
carries patch 45's coverage fields, so this is an adapted backport in one
840+
commit rather than literal cherry-picks: `uber_sdf.frag` is split into
841+
`uber_sdf_common.glsl` plus a ramp-texture variant (`uber_sdf.frag`) and a
842+
storage-buffer variant (`uber_sdf_ssbo.frag`, used wherever the backend
843+
supports SSBOs, i.e. Avio's Vulkan Shell and greeter, for every UberSDF
844+
draw). `Canvas::AddRenderSDFEntityToCurrentPass` shades a linear or radial
845+
gradient whose local matrix (with the inverse shape transform) is a
846+
similarity directly in UberSDF: no snapshots, no blend target, no deferred
847+
coverage pass. Conical and sweep gradients, images, runtime effects and
848+
non-similarity gradient matrices keep the masked kSrcIn path that patch 52
849+
slims.
850+
851+
Avio deltas against upstream, each to re-check at the rebase that drops this
852+
patch:
853+
- Edges keep Avio's look. A gradient's coverage uses the light-foreground
854+
gamma correction of the white mask it was blended through before, not the
855+
gradient color's luma; the storage-buffer variant dithers like the
856+
storage-buffer gradient shaders, and like the masked composite it dithers
857+
the gradient color before coverage scales it, so a pixel the shape does not
858+
cover stays exactly transparent (upstream does not dither in UberSDF).
859+
`AiksTest.SdfGradientEdgesMatchMaskedComposite` compares every pixel (rect,
860+
rounded corners, oval, circle; opaque and glass; both coverage modes) with
861+
the masked composite: alpha within 2/255, color within 2/255 on the
862+
ramp-texture variant and 5/255 on the dithered storage-buffer variant (two
863+
dither grids), and no pixel the composite leaves transparent may gain any
864+
value. It runs on Vulkan with SDFs enabled, the storage-buffer variant
865+
Avio ships, and on the OpenGL ES SDF backend, the ramp-texture variant.
866+
`SdfGradientLeavesUncoveredQuadPixelsTransparent` checks the quad corners
867+
around a circle are exactly zero in both coverage modes.
868+
- Linear gradients need a similarity matrix too (upstream checks only
869+
affinity): mapping the end points through a shear or non-uniform scale does
870+
not map the gradient's field.
871+
- Patch 45's `external_linear_backdrop` / `defer_coverage_transform` stay;
872+
a gradient shaded in UberSDF takes the coverage transfer in the shader.
873+
- `#191925` and `#191980` (texture-gradient fixes and wide-gamut ramp
874+
textures) are not brought in: the ramp-texture variant uses the fork's
875+
current `GradientData`, and Avio's SDF users take the storage-buffer
876+
variant.
877+
878+
Revert this one commit to restore the masked path exactly; nothing else on
879+
the branch depends on it. Regressions:
880+
`UberSDFContentsTest.ApplyColorFilterWithGradient`,
881+
`AsBackgroundColorGradientReturnsNullopt`, and on every playground that
882+
renders with SDFs (`Playground::EnsureContextUsesSDFs`, patch 52)
883+
`AiksTest.SdfLinearGradientRectAllocatesNoOffscreen`,
884+
`SdfRadialGradientCircleUnderNonUniformScaleAllocatesNoOffscreen`,
885+
`UnsupportedColorSourceStillBlends`, `SdfGradientEdgesMatchMaskedComposite`,
886+
`SdfGradientLeavesUncoveredQuadPixelsTransparent`.
887+
833888
## Known baseline debt
834889

835890
- ~~Generic embedder compositor and platform-view tests required broad

‎avio-verify-patches.sh‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,22 @@ need "color-source SDF snapshots are single-sample without depth/stencil" \
456456
$F/impeller/display_list/canvas.cc '/\*depth_stencil_enabled=\*/false\)'
457457
need "snapshots may omit depth/stencil" \
458458
$F/impeller/entity/contents/contents.h 'bool depth_stencil_enabled = true;'
459+
need "UberSDF shades linear and radial gradients (backport)" \
460+
$F/impeller/display_list/canvas.cc 'CreateUberSDFGradientParameters\('
461+
need "UberSDF storage-buffer gradient variant" \
462+
$F/impeller/entity/BUILD.gn 'shaders/uber_sdf_ssbo.frag'
463+
need "UberSDF gradient edges keep the masked look" \
464+
$F/impeller/entity/shaders/uber_sdf_common.glsl \
465+
'frag_info.color_source_type < 0.5 \? color.rgb : vec3\(1.0\)'
466+
need "UberSDF gradient pixel guard" \
467+
$F/impeller/display_list/aiks_dl_sdf_gradient_unittests.cc \
468+
'SdfGradientEdgesMatchMaskedComposite'
469+
need "UberSDF dithers a gradient before coverage" \
470+
$F/impeller/entity/shaders/uber_sdf_common.glsl \
471+
'finishGradientColor\(IPPremultiply\(color\)\) \* alpha'
472+
need "UberSDF uncovered gradient pixels stay transparent guard" \
473+
$F/impeller/display_list/aiks_dl_sdf_gradient_unittests.cc \
474+
'SdfGradientLeavesUncoveredQuadPixelsTransparent'
459475
need "Slimpeller low-memory path trims idle Impeller caches" \
460476
$F/shell/common/rasterizer.cc 'TrimIdleResourceCaches'
461477
need "explicit transient profiles bypass environment policy" \

‎engine/src/flutter/impeller/display_list/BUILD.gn‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ template("display_list_unittests_component") {
8282
"aiks_dl_primitive_shape_unittests.cc",
8383
"aiks_dl_runtime_effect_unittests.cc",
8484
"aiks_dl_sdf_color_source_unittests.cc",
85+
"aiks_dl_sdf_gradient_unittests.cc",
8586
"aiks_dl_shadow_unittests.cc",
8687
"aiks_dl_text_unittests.cc",
8788
"aiks_dl_unittests.cc",

0 commit comments

Comments
 (0)