Skip to content

[Flutter GPU] Reusable binding sets - #190400

Merged
bdero merged 3 commits into
flutter:masterfrom
bdero:bdero/flutter-gpu-binding-sets
Oct 5, 2026
Merged

bdero merged 3 commits into
flutter:masterfrom
bdero:bdero/flutter-gpu-binding-sets

Conversation

@bdero

@bdero bdero commented Aug 2, 2026

Copy link
Copy Markdown
Member

Fixes #190397.

GpuContext.createBindingSet resolves a group of uniform and texture bindings against shader reflection once, and RenderPass.bindSet puts that set in one of four slots. Binding a whole material is now one slot assignment instead of per-resource work on every draw, and the set's bindings are replayed with borrowed reflection metadata, so no per-binding allocation happens inside Draw.

Keys are UniformSlots rather than names, so a single set can span the vertex and fragment stages. The existing bindUniform and bindTexture are unchanged and are applied after any bound sets, so an individual bind still overrides a set member for that draw.

Pre-launch Checklist

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. flutter-gpu team-fluttergpu Owned by Flutter GPU team labels Aug 2, 2026
@github-project-automation github-project-automation Bot moved this to 🤔 Needs Triage in Flutter GPU Aug 2, 2026
@bdero
bdero changed the base branch from main to master August 2, 2026 04:46
@bdero bdero added the CICD Run CI/CD label Aug 2, 2026
@bdero
bdero marked this pull request as ready for review August 2, 2026 04:59

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces BindingSet to Flutter GPU, allowing developers to group uniform and texture bindings into a single reusable set to optimize draw calls. The implementation spans both C++ and Dart, with corresponding unit and integration tests added. Feedback focuses on a critical lifetime risk where storing the sampler as a raw pointer (impeller::raw_ptr) in TextureBinding can lead to dangling pointers; it is recommended to use std::shared_ptr instead and update the associated signatures and tests. Additionally, a documentation comment is requested for the public texture field in Dart to comply with the repository's style guide.

Comment thread engine/src/flutter/lib/gpu/binding_set.h
Comment thread engine/src/flutter/lib/gpu/binding_set.h
Comment thread engine/src/flutter/lib/gpu/binding_set.cc
Comment thread engine/src/flutter/lib/gpu/binding_set.cc
Comment thread engine/src/flutter/lib/gpu/binding_set_unittests.cc
Comment thread engine/src/flutter/lib/gpu/binding_set_unittests.cc
Comment thread engine/src/flutter/lib/gpu/binding_set_unittests.cc
Comment thread engine/src/flutter/lib/gpu/lib/src/binding_set.dart
@gaaclarke

Copy link
Copy Markdown
Member

is this ready for review?

bdero added 2 commits August 5, 2026 17:24
A BindingSet resolves a group of uniform and texture bindings against
shader reflection once at creation. RenderPass.bindSet puts it in one of
four slots, so binding a whole material costs one slot assignment instead
of per-resource work on every draw.
@bdero
bdero force-pushed the bdero/flutter-gpu-binding-sets branch from 96c921a to d40fe62 Compare August 6, 2026 00:25
@bdero
bdero requested a review from wolfenrain August 6, 2026 00:56
@bdero

bdero commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

Ready now!

bdero added a commit to bdero/flutter_scene that referenced this pull request Oct 4, 2026
A material's textures live as long as the material, but its uniforms are
rewritten every draw from the transient allocator, so a shader's resources are
not one uniform group. WebGPU models exactly that split as a bind group whose
textures are fixed and whose uniform buffer is reached through a dynamic offset,
and a bind group cannot be built until its layout is known.

GpuBindingLayout is that layout as pure comparable data, canonically ordered so
declaration order does not split a cache, and testable without a GPU.
GpuBindingSet carries the stable half plus the per-draw uniform entry point.

The Flutter GPU backend replays both halves as individual binds, which costs
what binding each resource directly costs today, and collapses to one call when
flutter/flutter#190400 lands behind an unchanged seam.
bdero added a commit to bdero/flutter_scene that referenced this pull request Oct 4, 2026
A material's textures live as long as the material, but its uniforms are
rewritten every draw from the transient allocator, so a shader's resources are
not one uniform group. WebGPU models exactly that split as a bind group whose
textures are fixed and whose uniform buffer is reached through a dynamic offset,
and a bind group cannot be built until its layout is known.

GpuBindingLayout is that layout as pure comparable data, canonically ordered so
declaration order does not split a cache, and testable without a GPU.
GpuBindingSet carries the stable half plus the per-draw uniform entry point.

The Flutter GPU backend replays both halves as individual binds, which costs
what binding each resource directly costs today, and collapses to one call when
flutter/flutter#190400 lands behind an unchanged seam.
@bdero
bdero added this pull request to the merge queue Oct 5, 2026
Merged via the queue into flutter:master with commit 4d5c68b Oct 5, 2026
18 checks passed
@bdero
bdero deleted the bdero/flutter-gpu-binding-sets branch October 5, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels. flutter-gpu team-fluttergpu Owned by Flutter GPU team

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

[Flutter GPU] Reusable binding sets so per-draw bind cost stops scaling with binding count

3 participants