Skip to content

Add support for fetching array uniforms by name#180647

Merged
auto-submit[bot] merged 9 commits into
flutter:masterfrom
walley892:matrix-vector
Jan 17, 2026
Merged

Add support for fetching array uniforms by name#180647
auto-submit[bot] merged 9 commits into
flutter:masterfrom
walley892:matrix-vector

Conversation

@walley892

Copy link
Copy Markdown
Contributor

Adds support for fetching objects representing array Uniforms of type float, vec2, vec3, and vec4. Happy new year!

Before this change, setting an array of uniforms was verbose.

uniform vec3[2] uColors;
shader.setFloat(0, 1.0);
shader.setFloat(1, 0.0);
shader.setFloat(2, 1.0);
shader.setFloat(3, 0.0);
shader.setFloat(4, 1.0);
shader.setFloat(5, 0.0);

After this change, we have:

uniform vec3[2] uColors;
final colors = shader.getUniformVec3Array("uColors");
colors[0].set(1.0, 0.0, 1.0);
colors[1].set(0.0, 1.0, 0.0);
  • Adds a class UniformArray to represent uniform arrays in Dart.
  • Adds a bunch of methods that construct these arrays for various datatypes
  • Adds tests
  • Also removes some of the awkwardness in the _getUniformFloatIndex function by replacing that function entirely

Pre-launch Checklist

  • [x ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • [ 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 documentation (doc comments with ///).
  • [ 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.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-web Web applications specifically labels Jan 7, 2026

@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 support for fetching array uniforms by name, which simplifies setting uniform arrays significantly. The changes are well-structured, introducing a UniformArray class and refactoring uniform index retrieval for better clarity. My review includes a few suggestions:

  • A correction for a copy-paste error in the documentation.
  • A proposal to add a length property to the UniformArray interface on the web for API consistency.
  • A recommendation to expand test coverage for the CanvasKit implementation to match the thoroughness of the native tests.

Comment thread engine/src/flutter/lib/ui/painting.dart
Comment thread engine/src/flutter/lib/web_ui/lib/painting.dart
Comment thread engine/src/flutter/lib/web_ui/test/canvaskit/fragment_program_test.dart Outdated
@mdebbar mdebbar requested a review from harryterkelsen January 7, 2026 18:18
Comment thread engine/src/flutter/lib/ui/painting.dart Outdated
Comment thread engine/src/flutter/lib/ui/painting.dart Outdated
Comment thread engine/src/flutter/lib/ui/painting.dart Outdated
Comment thread engine/src/flutter/lib/web_ui/lib/painting.dart Outdated
Comment thread engine/src/flutter/testing/dart/fragment_shader_test.dart Outdated
Comment thread engine/src/flutter/testing/dart/fragment_shader_test.dart
Comment thread engine/src/flutter/lib/web_ui/test/canvaskit/fragment_program_test.dart Outdated
@walley892 walley892 requested a review from gaaclarke January 8, 2026 23:00

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm once @harryterkelsen is happy!

Comment thread engine/src/flutter/lib/ui/painting.dart Outdated

@harryterkelsen harryterkelsen 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.

Thanks for your patience and for contributing code to the Flutter engine. I have some comments

Comment thread engine/src/flutter/lib/web_ui/lib/src/engine/skwasm/skwasm_impl/shaders.dart Outdated
Comment thread engine/src/flutter/lib/web_ui/test/canvaskit/fragment_program_test.dart Outdated
final program = CkFragmentProgram.fromBytes('test', data);
shader = program.fragmentShader() as CkFragmentShader;
});
test('getUniformVec2', () {

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.

These tests all check that setting values on the by-name float arrays doesn't crash. I think we should also check that after setting the values, if we get the float arrays again, the values are set to what we just set them to. Otherwise, these tests will pass even if set() is a no-op.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't have a mechanism to do this (read uniform values) in the current fragmentshader API.

It wouldn't be too hard to write a getFloat(int index) API and expand the UniformXSlot API based on that, but. I'd want to check with the rest of the engine team before moving forward with that kind of change.

@gaaclarke for thoughts.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Checking the result isn't all that helpful because what really matters is that that value is propagated to the GPU. That would require golden tests. These classes were designed to be things you create in the widget tree declaratively, not storage classes so I think adding getters to them is contrary to how we want them used.

It would be nice to have a golden tests that runs through this. I'm not sure if there is one off the top of my mind. Eventually as the framework adopts this we'll get some. You can file an issue to follow up since this meets the standard set by the alternative API.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, actually we do have tests like golden tests, check out FragmentShader simple shader renders correctly. You can do something like that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if goldens are the best solution for testing initial implementation here, but they should serve as kind of a regression test?

Comment thread engine/src/flutter/lib/web_ui/test/ui/fragment_shader_test.dart Outdated
@walley892

Copy link
Copy Markdown
Contributor Author

@gaaclarke @harryterkelsen

I created a PR to move the existing tests to web_ui and committed the existing test shaders to github to make things less bad here. Will rebase on top of that #180910

@harryterkelsen harryterkelsen 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.

LGTM. Thanks!

@walley892 walley892 added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 14, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 14, 2026
@auto-submit

auto-submit Bot commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

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

@walley892 walley892 added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 14, 2026
@auto-submit

auto-submit Bot commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

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

@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 14, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 17, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 19, 2026
calltekk pushed a commit to calltekk/flutter that referenced this pull request Jan 19, 2026
Adds support for fetching objects representing array Uniforms of type
float, vec2, vec3, and vec4. Happy new year!

Before this change, setting an array of uniforms was verbose.
```glsl
uniform vec3[2] uColors;
```

```dart
shader.setFloat(0, 1.0);
shader.setFloat(1, 0.0);
shader.setFloat(2, 1.0);
shader.setFloat(3, 0.0);
shader.setFloat(4, 1.0);
shader.setFloat(5, 0.0);
```

After this change, we have:

```glsl
uniform vec3[2] uColors;
```

```dart
final colors = shader.getUniformVec3Array("uColors");
colors[0].set(1.0, 0.0, 1.0);
colors[1].set(0.0, 1.0, 0.0);
```

- Adds a class UniformArray to represent uniform arrays in Dart.
- Adds a bunch of methods that construct these arrays for various
datatypes
- Adds tests
- Also removes some of the awkwardness in the _getUniformFloatIndex
function by replacing that function entirely

## Pre-launch Checklist

- [x ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ 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 documentation (doc comments with `///`).
- [ 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.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 19, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 21, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 22, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jan 23, 2026
flutter-zl pushed a commit to flutter-zl/flutter that referenced this pull request Feb 10, 2026
Adds support for fetching objects representing array Uniforms of type
float, vec2, vec3, and vec4. Happy new year!

Before this change, setting an array of uniforms was verbose.
```glsl
uniform vec3[2] uColors;
```

```dart
shader.setFloat(0, 1.0);
shader.setFloat(1, 0.0);
shader.setFloat(2, 1.0);
shader.setFloat(3, 0.0);
shader.setFloat(4, 1.0);
shader.setFloat(5, 0.0);
```

After this change, we have:

```glsl
uniform vec3[2] uColors;
```

```dart
final colors = shader.getUniformVec3Array("uColors");
colors[0].set(1.0, 0.0, 1.0);
colors[1].set(0.0, 1.0, 0.0);
```

- Adds a class UniformArray to represent uniform arrays in Dart.
- Adds a bunch of methods that construct these arrays for various
datatypes
- Adds tests
- Also removes some of the awkwardness in the _getUniformFloatIndex
function by replacing that function entirely

## Pre-launch Checklist

- [x ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ 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 documentation (doc comments with `///`).
- [ 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine flutter/engine related. See also e: labels. platform-web Web applications specifically will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants