Skip to content

Conversation

@eyebrowsoffire
Copy link
Contributor

@eyebrowsoffire eyebrowsoffire commented Aug 26, 2025

This change adds support for host buffer that keeps index buffers separate from other general-purpose data. This is a requirement for WebGL: https://registry.khronos.org/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING

No current backends use the partitioned implementation, but once I add WebGL support it will use it to avoid #149603

@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Aug 26, 2025
@eyebrowsoffire eyebrowsoffire marked this pull request as ready for review August 26, 2025 22:23
@eyebrowsoffire eyebrowsoffire changed the title Support partitioned host buffer [impeller] Support partitioned host buffer Aug 26, 2025
Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

Introducing polymorphism in HostBuffer adds complication, overhead, and hurts locality. It's not necessary for what we are trying to do.

All you need to do is introduce a new datatype:

struct HostBuffers {
  HostBuffer data;
  std::optional<HostBuffer> indices;
};

@eyebrowsoffire
Copy link
Contributor Author

Introducing polymorphism in HostBuffer adds complication, overhead, and hurts locality. It's not necessary for what we are trying to do.

All you need to do is introduce a new datatype:

struct HostBuffers {

  HostBuffer data;

  std::optional<HostBuffer> indices;

};

The idea here is that most backends still should use a unified host buffer under the hood. Separation of indices into another buffer is pretty much specific to WebGL, so for other backends the specification of the buffer category is basically a no-op. But the backend-agnostic code needs to specify whether it is going to use the buffer for indexes or for other data, so that if the backend needs to separate it it can. Hence the polymorphism, we need different behavior for different backends.

However, it doesn't necessarily have to be dynamic polymorphism, I'm happy to refactor this a different way. But I'm not sure your suggestion on its own solves the problem. We can jump on a call to discuss the details and get aligned on a solution.

Copy link
Member

@gaaclarke gaaclarke left a comment

Choose a reason for hiding this comment

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

LGTM, thanks, this is a much better approach I think. It might be worth telling the gemini bot to double check it since there is a lot of small refactoring which it's good at checking. I reviewed it too and looked all good.

Comment on lines 1063 to 1072
auto data_host_buffer = HostBuffer::Create(
GetContext()->GetResourceAllocator(), GetContext()->GetIdleWaiter(),
GetContext()->GetCapabilities()->GetMinimumUniformAlignment());
auto indexes_host_buffer =
GetContext()->GetCapabilities()->NeedsPartitionedHostBuffer()
? HostBuffer::Create(
GetContext()->GetResourceAllocator(),
GetContext()->GetIdleWaiter(),
GetContext()->GetCapabilities()->GetMinimumUniformAlignment())
: data_host_buffer;
Copy link
Member

Choose a reason for hiding this comment

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

nit: We can probably pull this into a function since it happens a fair bit.

Comment on lines +293 to +294
/// @brief Retrieve the current host buffer for transient storage of indexes
/// used for indexed draws.
Copy link
Member

Choose a reason for hiding this comment

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

It's worth noting that GetTransientsIndexesBuffer may return the same value as GetTransientsDataBuffer in certain circumstances.

Comment on lines 562 to 568
indexes_host_buffer_(
context_->GetCapabilities()->NeedsPartitionedHostBuffer()
? HostBuffer::Create(
context_->GetResourceAllocator(),
context_->GetIdleWaiter(),
context_->GetCapabilities()->GetMinimumUniformAlignment())
: data_host_buffer_),
Copy link
Member

Choose a reason for hiding this comment

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

Please move this into the constructor. The order in which initializers are executed is controlled by the order in the header. I think we have a lint that forces them to be in the same order but I think it's safer just to avoid order issues in initializers.

@gaaclarke
Copy link
Member

fyi the test failure looks apropos, ResetHostBufferBasedOnFrameBoundary

Copy link
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 introduces support for partitioned host buffers, a necessary change for upcoming WebGL support. The primary modification involves splitting GetTransientsBuffer() into GetTransientsDataBuffer() and GetTransientsIndexesBuffer(), and updating numerous call sites to use the appropriate buffer for vertex, index, and uniform data. The implementation correctly handles backends that don't require partitioning by using a shared buffer. The changes are extensive but have been applied consistently across the codebase. I've identified one pre-existing issue in a test file that is now surfaced by these changes.

@eyebrowsoffire eyebrowsoffire added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 28, 2025

autosubmit label was removed for flutter/flutter/174463, because - The status or check suite Linux mac_clang_tidy has failed. Please fix the issues identified (or deflake) before re-applying this label.

  • The status or check suite Linux linux_clang_tidy has failed. Please fix the issues identified (or deflake) before re-applying this label.

@eyebrowsoffire eyebrowsoffire added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2025
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 28, 2025

autosubmit label was removed for flutter/flutter/174463, because - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@eyebrowsoffire eyebrowsoffire added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 28, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Aug 29, 2025
Merged via the queue into flutter:master with commit c98cc29 Aug 29, 2025
189 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 29, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 31, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 2, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Sep 2, 2025
Roll Flutter from da5523afc3c1 to 6b18740d5a23 (49 revisions)

flutter/flutter@da5523a...6b18740

2025-08-29 [email protected] Roll Dart SDK from 11f6cd99f6b3 to 72cda0f3dc42 (2 revisions) (flutter/flutter#174697)
2025-08-29 [email protected] Fix empty adaptive text selection toolbars building. (flutter/flutter#174656)
2025-08-29 [email protected] [flutter_test] update the _isImportantForAccessibility method in SemanticsController to include tooltip (flutter/flutter#174476)
2025-08-29 [email protected] Roll Skia from 89794f0b5384 to 43e79dc80ca8 (1 revision) (flutter/flutter#174678)
2025-08-29 [email protected] Roll Skia from f3c8b4c677f5 to 89794f0b5384 (6 revisions) (flutter/flutter#174675)
2025-08-29 [email protected] Implement Overlay.of with inherited widget (flutter/flutter#174315)
2025-08-29 [email protected] [impeller] Support partitioned host buffer (flutter/flutter#174463)
2025-08-29 [email protected] Adds semantics for disabled buttons in date picker (flutter/flutter#174064)
2025-08-29 [email protected] Roll Fuchsia Linux SDK from bHYRvLv2Dg56RWZF2... to 00VSr-5B7hq0G2eZx... (flutter/flutter#174667)
2025-08-29 [email protected] Check GTK calls are done on the same thread. (#174488) (flutter/flutter#174624)
2025-08-29 [email protected] [ Tool ] Only listen for DebugConnectionInfo if the service protocol is supported (flutter/flutter#174664)
2025-08-29 [email protected] Roll Dart SDK from 89023922f96d to 11f6cd99f6b3 (9 revisions) (flutter/flutter#174669)
2025-08-28 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[web] Refactor renderers to use the same frontend code (#174588)" (flutter/flutter#174672)
2025-08-28 [email protected] [a11y] [test] containsSemantics  can ignore SemanticsValidationResult (flutter/flutter#174608)
2025-08-28 [email protected] Fix some issues in engine-tool README. (flutter/flutter#174512)
2025-08-28 [email protected] Marks Linux_pixel_7pro new_gallery__transition_perf to be flaky (flutter/flutter#174106)
2025-08-28 [email protected] Make sure that an AlertDialog doesn't crash in 0x0 environment (flutter/flutter#174091)
2025-08-28 [email protected] Marks Linux_pixel_7pro hello_world_impeller to be flaky (flutter/flutter#173699)
2025-08-28 [email protected] Marks Linux_pixel_7pro drive_perf_debug_warning to be flaky (flutter/flutter#174112)
2025-08-28 [email protected] Marks Linux_android_emu android_display_cutout to be flaky (flutter/flutter#174501)
2025-08-28 [email protected] Marks Linux_pixel_7pro service_extensions_test to be flaky (flutter/flutter#174114)
2025-08-28 [email protected] Marks Windows plugin_test to be flaky (flutter/flutter#174117)
2025-08-28 [email protected] Marks Windows_mokey basic_material_app_win__compile to be flaky (flutter/flutter#173702)
2025-08-28 [email protected] Marks Mac_mokey microbenchmarks to be flaky (flutter/flutter#174102)
2025-08-28 [email protected] Marks Linux_mokey complex_layout__start_up to be flaky (flutter/flutter#173692)
2025-08-28 [email protected] Marks Linux build_android_host_app_with_module_aar to be flaky (flutter/flutter#172631)
2025-08-28 [email protected] Marks Linux_pixel_7pro new_gallery_opengles_impeller__transition_perf to be flaky (flutter/flutter#173338)
2025-08-28 [email protected] Marks Linux_pixel_7pro platform_views_scroll_perf_impeller__timeline_summary to be flaky (flutter/flutter#172211)
2025-08-28 [email protected] Remove the option to disable the merged platform/UI thread on Android and iOS (flutter/flutter#174408)
2025-08-28 [email protected] Don't fail when hot restarting `web-server` and there are no connected clients (flutter/flutter#174600)
2025-08-28 [email protected] Roll Skia from 7c2fe2629d4a to f3c8b4c677f5 (7 revisions) (flutter/flutter#174654)
2025-08-28 [email protected] [WebParagraph] More plumbing towards making it usable in Flutter apps (flutter/flutter#174587)
2025-08-28 [email protected] Roll Packages from 86fbeec to 141d8e3 (6 revisions) (flutter/flutter#174645)
2025-08-28 [email protected] [web] Refactor renderers to use the same frontend code (flutter/flutter#174588)
2025-08-28 [email protected] Roll Skia from eb000b138a9d to 7c2fe2629d4a (3 revisions) (flutter/flutter#174637)
2025-08-28 [email protected] [ Tool ] Roll package:dwds 25.0.4 (flutter/flutter#174601)
2025-08-28 [email protected] Roll Skia from 9b1642f2cfea to eb000b138a9d (2 revisions) (flutter/flutter#174627)
2025-08-28 [email protected] Roll Skia from 430d60054d66 to 9b1642f2cfea (7 revisions) (flutter/flutter#174625)
2025-08-28 [email protected] Refactored Canvas to disallow null inline contexts. (flutter/flutter#174530)
2025-08-28 [email protected] Revert "Check GTK calls are done on the same thread." (flutter/flutter#174604)
2025-08-27 [email protected] Roll Skia from 2a12b57fbbf0 to 430d60054d66 (3 revisions) (flutter/flutter#174590)
2025-08-27 [email protected] Retry "Implements the Android native stretch effect as a fragment shader (Impeller-only)." (flutter/flutter#173885)
2025-08-27 [email protected] Use raw `--removal-label "cp: ..."` when removing labels for unmerged PRs (flutter/flutter#174596)
2025-08-27 [email protected] Flutter driver deserialization (flutter/flutter#172927)
2025-08-27 [email protected] Check GTK calls are done on the same thread. (flutter/flutter#174488)
2025-08-27 [email protected] Fix broken reference to `PULL_REQUEST_CP_TEMPLATE.md` after refactor (flutter/flutter#174595)
...
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
This change adds support for host buffer that keeps index buffers
separate from other general-purpose data. This is a requirement for
WebGL:
https://registry.khronos.org/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING

No current backends use the partitioned implementation, but once I add
WebGL support it will use it to avoid
flutter#149603
korca0220 pushed a commit to korca0220/flutter that referenced this pull request Sep 22, 2025
This change adds support for host buffer that keeps index buffers
separate from other general-purpose data. This is a requirement for
WebGL:
https://registry.khronos.org/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING

No current backends use the partitioned implementation, but once I add
WebGL support it will use it to avoid
flutter#149603
Jaineel-Mamtora pushed a commit to Jaineel-Mamtora/flutter_forked that referenced this pull request Sep 24, 2025
This change adds support for host buffer that keeps index buffers
separate from other general-purpose data. This is a requirement for
WebGL:
https://registry.khronos.org/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING

No current backends use the partitioned implementation, but once I add
WebGL support it will use it to avoid
flutter#149603
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 12, 2025
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
This change adds support for host buffer that keeps index buffers
separate from other general-purpose data. This is a requirement for
WebGL:
https://registry.khronos.org/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING

No current backends use the partitioned implementation, but once I add
WebGL support it will use it to avoid
flutter#149603
@eyebrowsoffire eyebrowsoffire deleted the partitioned_host_buffer branch December 12, 2025 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems e: impeller Impeller rendering backend issues and features requests engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants