Skip to content

[Flutter GPU] Add explicit draw counts#186639

Open
bdero wants to merge 1 commit into
flutter:masterfrom
bdero:bdero/flutter-gpu-draw-api
Open

[Flutter GPU] Add explicit draw counts#186639
bdero wants to merge 1 commit into
flutter:masterfrom
bdero:bdero/flutter-gpu-draw-api

Conversation

@bdero
Copy link
Copy Markdown
Member

@bdero bdero commented May 17, 2026

Moves the vertex and index count off the buffer-binding calls and onto the draw call.

A simple (breaking) change that fixes a very silly design flaw that I built into the API near the very beginning. Moves Flutter GPU draws towards a design that matches virtually all modern graphics APIs, including today's Impeller!
Now is the right time to make changes like this to Flutter GPU, since the API is not yet considered stable.

Before, bindVertexBuffer and bindIndexBuffer each took a count, and a single argument-less draw() guessed vertex versus index based on whether an index buffer happened to be bound.

Sooooo many reasons this was the wrong design:

  • Wrong object. A draw count belongs on the draw, not on a buffer binding.
  • Implicit kind. Indexed vs. non-indexed was inferred from what happened to be bound, not stated.
  • Colliding counts. Vertex and index counts shared one field; the vertex count was dropped when an index buffer was bound.
  • Slot-0-only. The count came from vertex slot 0; values on other slots were silently ignored.
  • Opaque draws. draw() told you nothing; you had to trace every bind to know what it drew.
  • Sticky state. The count leaked across draws in a pass.
  • Redundant re-binds. Changing only the count forced re-binding the buffer.
  • No room to grow. Nowhere natural for per-draw params like instanceCount or baseVertex.
  • Unconventional. WebGPU, Vulkan, Metal, and D3D all put counts on the draw.
  • Late errors. Bad counts failed at draw() time, far from the mistaken line.

Now:

  • bindVertexBuffer and bindIndexBuffer only bind buffers.
  • draw(vertexCount) does a non-indexed draw.
  • drawIndexed(indexCount) does an indexed draw.

Instanced draws can be landed later via draw and drawIndexed gaining an instanceCount parameter later on, assuming the Impeller-side instancing support in #186653 lands.

Pre-launch Checklist

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 17, 2026
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests flutter-gpu team-fluttergpu Owned by Flutter GPU team labels May 17, 2026
@github-project-automation github-project-automation Bot moved this to 🤔 Needs Triage in Flutter GPU May 17, 2026
@fluttergithubbot
Copy link
Copy Markdown
Contributor

An existing Git SHA, 32015b673360111432f7f9ee8eb0edd1da7f8fbe, was detected, and no actions were taken.

To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with --force) that already was pushed before, push a blank commit (git commit --allow-empty -m "Trigger Build") or rebase to continue.

@bdero bdero force-pushed the bdero/flutter-gpu-draw-api branch from 32015b6 to ed965e1 Compare May 17, 2026 22:54
@github-actions github-actions Bot removed the CICD Run CI/CD label May 17, 2026
@bdero bdero changed the title [Flutter GPU] Add instanced draws and explicit draw counts [Flutter GPU] Add explicit draw counts May 17, 2026
@bdero bdero marked this pull request as ready for review May 18, 2026 01:16
Copy link
Copy Markdown
Contributor

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

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 refactors the Flutter GPU API by moving vertex and index count parameters from the binding methods, such as bindVertexBuffer and bindIndexBuffer, to the draw and drawIndexed methods. These changes are reflected across the Dart API, the C++ implementation, and the native bindings. Feedback suggests strengthening input validation by replacing asserts with RangeError.checkNotNegative in the Dart public API and adding explicit non-negative checks in the C++ layer to prevent potential integer overflow issues when casting signed integers to size_t.

Comment thread engine/src/flutter/lib/gpu/render_pass.cc
Comment thread engine/src/flutter/lib/gpu/render_pass.cc
Comment thread engine/src/flutter/lib/gpu/lib/src/render_pass.dart Outdated
Comment thread engine/src/flutter/lib/gpu/lib/src/render_pass.dart Outdated
@bdero bdero force-pushed the bdero/flutter-gpu-draw-api branch from ed965e1 to 2705bf3 Compare May 18, 2026 01:34
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 18, 2026
Reworks the Flutter GPU draw API so the count of vertices or indices is
passed to the draw call rather than smuggled through the buffer-binding
calls.

bindVertexBuffer and bindIndexBuffer no longer take a count. The single
argument-less draw() is replaced by draw(vertexCount) and
drawIndexed(indexCount). The count is now explicit, and whether a draw
is non-indexed or indexed is chosen by the method called rather than by
whether an index buffer happens to be bound.

Updates the flutter_gpu tests and the impeller dart_tests fixture, and
adds coverage for drawIndexed.
@bdero bdero force-pushed the bdero/flutter-gpu-draw-api branch from 2705bf3 to 6db9ef3 Compare May 18, 2026 04:23
@github-actions github-actions Bot removed the CICD Run CI/CD label May 18, 2026
@bdero bdero added the CICD Run CI/CD label May 18, 2026
@bdero bdero requested a review from gaaclarke May 18, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels. flutter-gpu team-fluttergpu Owned by Flutter GPU team

Projects

Status: 🤔 Needs Triage

Development

Successfully merging this pull request may close these issues.

3 participants