Repository navigation
Commit 6ed3be9
authored
[Impeller] Cache GLES sampler configuration in RenderPassStateCache (flutter#193922)
### Rationale
Split out from flutter#193427 per
@gaaclarke's review feedback.
OpenGL ES does not expose standalone sampler objects on the paths used
by `SamplerGLES`; instead, `SamplerGLES::ConfigureBoundTexture` emits up
to 5 `glTexParameteri` calls (`GL_TEXTURE_MIN_FILTER`,
`GL_TEXTURE_MAG_FILTER`, `GL_TEXTURE_MAX_LEVEL`, `GL_TEXTURE_WRAP_S`,
`GL_TEXTURE_WRAP_T`) plus optional `GL_TEXTURE_MAX_ANISOTROPY_EXT` on
the bound GL texture object every time a texture is bound for a draw
call. On glyph-atlas-heavy and tiled scenes (`bouncy@128`, `grid@1000`),
hundreds or thousands of consecutive draw calls sample the same texture
with an identical `SamplerDescriptor`, issuing up to `12,258` redundant
`glTexParameteri`/`glTexParameterf` calls per frame after
flutter#193427.
Within a render pass, non-wrapped `TextureGLES` instances own an
immutable `UniqueHandleGLES` (`HandleGLES`) and immutable
`TextureDescriptor` / `mip_count`. Caching the last configured
`SamplerDescriptor::ToKey` per `HandleGLES` in `SamplerStateCache`
inside `RenderPassStateCache` (alongside `BlendStateCache`,
`StencilStateCache`, and `DepthStateCache`) skips redundant
`glTexParameter*` calls across draws and pipelines within the pass
without storing mutable cached state on `TextureGLES`.
### Summary of Changes
-
[`engine/src/flutter/impeller/renderer/backend/gles/texture_gles.h`](https://github.com/kevmoo/flutter/blob/f9f4ba51255/engine/src/flutter/impeller/renderer/backend/gles/texture_gles.h):
Add a read-only `const HandleGLES& GetHandle() const` accessor matching
`PipelineGLES::GetProgramHandle()`.
-
[`engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles.h`](https://github.com/kevmoo/flutter/blob/f9f4ba51255/engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles.h)
&
[`engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles.cc`](https://github.com/kevmoo/flutter/blob/f9f4ba51255/engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles.cc):
Add `struct SamplerStateCache` (`absl::flat_hash_map<HandleGLES,
uint64_t, HandleGLES::Hash, HandleGLES::Equal> configured_samplers;` +
`ConfigureBoundTexture(...)`) and pass an optional `SamplerStateCache*`
into `BufferBindingsGLES::BindUniformData` and
`BufferBindingsGLES::BindTextures`. Wrapped external textures
(`IsWrapped()`) bypass the cache so external callers mutating raw GL
texture parameters are unaffected.
-
[`engine/src/flutter/impeller/renderer/backend/gles/render_pass_gles.cc`](https://github.com/kevmoo/flutter/blob/f9f4ba51255/engine/src/flutter/impeller/renderer/backend/gles/render_pass_gles.cc):
Add `SamplerStateCache sampler;` to `RenderPassStateCache` and pass
`&state_cache.sampler` into `vertex_desc_gles->BindUniformData(...)`.
-
[`engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles_unittests.cc`](https://github.com/kevmoo/flutter/blob/f9f4ba51255/engine/src/flutter/impeller/renderer/backend/gles/buffer_bindings_gles_unittests.cc):
Add
`BufferBindingsGLESTest.SkipsRedundantSamplerConfigurationOnSameTexture`
covering repeated binds with an identical sampler descriptor,
re-configuration when the sampler descriptor changes, cross-pipeline
deduplication/invalidation via a shared `SamplerStateCache`, and cache
bypass for wrapped external textures (`TextureGLES::WrapTexture`).
### Flow / Surface Delta
#### 1. Deterministic WebGL2 Call-Count Reductions (`0%` Variance)
Measured on top of merged flutter#193427
(`origin/master` @ `a554b8ac180` vs. `daad7727f54` across steady-state
frames):
| Workload (`1280x720`, `wimp_st`) | Metric | Pre-Change
(post-`flutter#193427`) | Post-Change | Absolute Delta | Delta (%) | Reduction
|
| :--- | :--- | :---: | :---: | :---: | :---: | :--- |
| **`bouncy` (`128` nodes, `441` draws, `247` textured)** |
`glTexParameteri` + `glTexParameterf` / frame | `1,482` (`1,235` +
`247`) | `~6` (`1` per pass) | `-1,476` | **`-99.6%`** | **Deduplicated
per pass** |
| | Total GL calls / frame | `7,827` | `6,336` | `-1,491` | **`-19.0%`**
| **`1.24x` fewer calls** (`-52.2%` / `2.09x` cumulative w/ `flutter#193427`) |
| **`grid` (`100` nodes, `660` draws, `245` textured)** |
`glTexParameteri` + `glTexParameterf` / frame | `1,470` (`1,225` +
`245`) | `~6` (`1` per pass) | `-1,464` | **`-99.6%`** | **Deduplicated
per pass** |
| | Total GL calls / frame | `10,674` | `9,213` | `-1,461` |
**`-13.7%`** | **`1.16x` fewer calls** |
| **`grid` (`1000` nodes, `5,908` draws, `2,043` textured)** |
`glTexParameteri` + `glTexParameterf` / frame | `12,258` (`10,215` +
`2,043`) | `~6` (`1` per pass) | `-12,252` | **`-99.95%`** |
**Deduplicated per pass** |
| | Total GL calls / frame | `93,669` | `81,285` | `-12,384` |
**`-13.2%`** | **`1.15x` fewer calls** (`-47.4%` / `1.90x` cumulative w/
`flutter#193427`) |
In `100us` V8/Wasm CPU profiling of the `DedicatedWorker` raster thread
on `grid@1000` (`--profile --no-strip-wasm`), redundant
`glTexParameteri` (`9.75 ms` Wasm self-time + `19.76 ms` JS binding) and
`glTexParameterf` (`12.80 ms` JS binding) accounted for **`42.31 ms`
(`2.09%` of total active worker CPU time)** across a `2.02s`
steady-state window.
#### 2. Hardware WebGL2 `rasterTimeMs` A/B (`AMD Radeon 780M`, `n=5`
Interleaved ABBA Pairs)
Measured on headed Chrome 154 (`ANGLE (AMD, AMD Radeon 780M Graphics
(radeonsi phoenix ACO), OpenGL ES 3.2)`, `--disable-gpu-vsync
--disable-frame-rate-limit`, `10` samples/run × `5` interleaved ABBA
pairs per arm):
| Workload (`1280x720`, `wimp_st`) | Pre-Change (`a554b8ac180`) |
Post-Change (`daad7727f54`) | Absolute Delta | Delta (%) | Speedup |
| :--- | :---: | :---: | :---: | :---: | :---: |
| **`bouncy` (`64` nodes)** | `1.412 ms` | `1.382 ms` | `-0.030 ms` |
`-2.15%` | `1.02x` |
| **`bouncy` (`128` nodes)** | `1.842 ms` | `1.756 ms` | `-0.086 ms` |
**`-4.66%`** | **`1.05x`** |
| **`grid` (`100` nodes)** | `1.783 ms` | `1.727 ms` | `-0.057 ms` |
**`-3.17%`** | **`1.03x`** |
| **`grid` (`1000` nodes)** | `16.385 ms` | `15.996 ms` | `-0.389 ms` |
**`-2.37%`** | **`1.02x`** |
**How much to trust these numbers:**
- **Call counts (Table 1) are exact (`0%` run-to-run variance)**: Every
frame deterministically eliminates `1,464`–`12,252` redundant
`glTexParameter*` calls across the boundary.
- **Wall-clock `rasterTimeMs` (Table 2) has a `~1.2%–2.0%` run-to-run
noise floor**:
- **`bouncy@128` (`-4.66%`)** and **`grid@100` (`-3.17%`)** clear the
noise floor consistently (`5/5` interleaved Post runs beat Pre).
- **`grid@1000` (`-2.37%`, `-0.39 ms`)** sits just above the
`~1.5%–2.0%` noise floor (`4/5` pairs faster) and aligns with the
`2.09%` worker CPU profile share of `glTexParameter*` when `5,908` draw
calls dominate frame time.
- **`bouncy@64` (`-2.15%`, `-0.03 ms`)** is inside the noise floor at
`<1.5 ms` frame times and should be treated as flat/within noise.
### Verification
- Built and ran `host_debug_unopt:impeller_unittests
--gtest_filter="*BufferBindingsGLES*:*RenderPassGLES*:*SamplerGLES*:*TextureGLES*"`
locally (`37/37` passed, including
`BufferBindingsGLESTest.SkipsRedundantSamplerConfigurationOnSameTexture`).
- Built `wasm_release:skwasm/wimp.js` and verified both deterministic
WebGL2 call counts and `n=5` interleaved hardware WebGL2 `rasterTimeMs`
medians (`AMD Radeon 780M`) in Chrome 154 via `flutter-wasm-compare`.
Related to flutter#192147
Towards flutter#174980
## 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.
<!-- Links -->
[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/Tree-hygiene.md#ai-contribution-guidelines
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[flutter/website]: https://github.com/flutter/website
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md1 parent 099a0b8 commit 6ed3be9
5 files changed
Lines changed: 156 additions & 8 deletions
File tree
- engine/src/flutter/impeller/renderer/backend/gles
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
265 | 285 | | |
266 | 286 | | |
267 | 287 | | |
268 | 288 | | |
269 | 289 | | |
270 | | - | |
| 290 | + | |
| 291 | + | |
271 | 292 | | |
272 | 293 | | |
273 | 294 | | |
274 | 295 | | |
275 | 296 | | |
276 | 297 | | |
277 | | - | |
| 298 | + | |
| 299 | + | |
278 | 300 | | |
279 | 301 | | |
280 | 302 | | |
281 | 303 | | |
282 | | - | |
| 304 | + | |
283 | 305 | | |
284 | 306 | | |
285 | 307 | | |
| |||
491 | 513 | | |
492 | 514 | | |
493 | 515 | | |
494 | | - | |
| 516 | + | |
| 517 | + | |
495 | 518 | | |
496 | 519 | | |
497 | 520 | | |
| |||
549 | 572 | | |
550 | 573 | | |
551 | 574 | | |
552 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
553 | 581 | | |
554 | 582 | | |
555 | 583 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
| 15 | + | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
| |||
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| 31 | + | |
| 32 | + | |
28 | 33 | | |
29 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
30 | 58 | | |
31 | 59 | | |
32 | 60 | | |
| |||
59 | 87 | | |
60 | 88 | | |
61 | 89 | | |
62 | | - | |
| 90 | + | |
| 91 | + | |
63 | 92 | | |
64 | 93 | | |
65 | 94 | | |
| |||
76 | 105 | | |
77 | 106 | | |
78 | 107 | | |
| 108 | + | |
| 109 | + | |
79 | 110 | | |
80 | 111 | | |
81 | 112 | | |
| |||
131 | 162 | | |
132 | 163 | | |
133 | 164 | | |
134 | | - | |
| 165 | + | |
| 166 | + | |
135 | 167 | | |
136 | 168 | | |
137 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
503 | 586 | | |
504 | 587 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
| 256 | + | |
256 | 257 | | |
257 | 258 | | |
258 | 259 | | |
| |||
681 | 682 | | |
682 | 683 | | |
683 | 684 | | |
684 | | - | |
| 685 | + | |
| 686 | + | |
685 | 687 | | |
686 | 688 | | |
687 | 689 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
174 | 177 | | |
175 | 178 | | |
176 | 179 | | |
| |||
0 commit comments