Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@Moncader
Copy link
Contributor

@Moncader Moncader commented Jun 6, 2024

This fixes an issue where in CanvasKit builds, uniforms set in setFloat function in the Paint class don't get updated after the initial render.
For example, like in the issue linked below, having a shader that animates a value over time and you want to reuse the Paint object that the shader is set to.

I'm no expert with CanvasKit nor with the Flutter Engine, but from what I could tell it seemed that the uniforms were only being sent to Skia on creation of the shader via _makeEffect.

However, any uniforms set afterwords were just stored in a local dart-side List and forgotten about.

This PR changes the List to use a WASM backed SkFloat32List to keep the references to the uniforms linked to dart-side.

fixes flutter/flutter#149800

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides].
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the [CLA].
  • All existing and new tests are passing.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Jun 6, 2024
@Moncader
Copy link
Contributor Author

Moncader commented Jun 6, 2024

I'll get to writing tests (if possible for gl related issues on the web?) and add it here soon.
Do golden tests even work with shaders?

@eyebrowsoffire
Copy link
Contributor

test/canvaskit/canvaskit_api_test.dart is broken with this change and needs to be updated.

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

Changes reported for pull request #53246 at sha bce9de7

@Moncader
Copy link
Contributor Author

The golden is incorrect and so far I'm not sure why.
I'll slowly work it out over the next few days. (the golden seems to be affected by the previous test and is showing the 25px version on the 10px test even though it's a new paint object.

I assume it's a bug on my side but I'd also like to know if as a rule in this flutter engine golden test system you can't re-use a golden test file in a single test like I am for this one?

@Moncader
Copy link
Contributor Author

I've confirmed on my local machine that this is not a bug on my side. But the golden tests are producing different results in CI than Chrome is showing per-frame on my local machine.

Does the golden system have some kind of restriction where you aren't allowed to use multiple of the same golden file?

@IntensiCode
Copy link

@Moncader just stumbled across your PR after running into this issue. currently using the new Paint() for every frame as a work-around. anyway, is there anything I can do to help out with this PR?

@Moncader
Copy link
Contributor Author

@IntensiCode The support and fix is complete. I'm waiting on someone to give some insight on how the golden test system works due to the test saying there's a diff when there isn't actually a diff when confirmed locally.

I'm asking over on discord as well.

@Moncader Moncader force-pushed the fix/web-shader-uniforms branch from e65456a to 7a0dfcc Compare June 19, 2024 01:00
@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #53246 at sha 7a0dfcc

@eyebrowsoffire
Copy link
Contributor

The goldens seem to indicate that this issue exists in the skwasm renderer as well and needs to be fixed. I can look into that in a followup though.

@Moncader
Copy link
Contributor Author

I'll check it out first actually. I don't mind getting my feet wet there. (assuming the issue ends up being a simple fix like this one was)

@eyebrowsoffire
Copy link
Contributor

I think the fix for the skwasm side should just be here: https://github.com/flutter/engine/blob/main/lib/web_ui/skwasm/shaders.cpp#L134

Instead of doing SkData::MakeWithCopy(uniforms->data(), uniforms->size()), we should just use the existing SkData object by doing sk_ref_sp(uniforms)

class CkFragmentShader implements ui.FragmentShader, CkShader {
CkFragmentShader(this.name, this.effect, int floatCount, int textureCount)
: floats = List<double>.filled(floatCount + textureCount * 2, 0),
: floats = mallocFloat32List(floatCount + textureCount * 2),
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we malloc'd this list, we also need to free it in dispose

@Moncader
Copy link
Contributor Author

I think the fix for the skwasm side should just be here: https://github.com/flutter/engine/blob/main/lib/web_ui/skwasm/shaders.cpp#L134

Instead of doing SkData::MakeWithCopy(uniforms->data(), uniforms->size()), we should just use the existing SkData object by doing sk_ref_sp(uniforms)

This is what I was thinking as well, but wasn't sure if it's safe to use the reference like that.
Is there a guarantee that those uniforms won't be free'd or swapped to a different object somewhere else?

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #53246 at sha 2c8681f

@eyebrowsoffire
Copy link
Contributor

I think the fix for the skwasm side should just be here: https://github.com/flutter/engine/blob/main/lib/web_ui/skwasm/shaders.cpp#L134
Instead of doing SkData::MakeWithCopy(uniforms->data(), uniforms->size()), we should just use the existing SkData object by doing sk_ref_sp(uniforms)

This is what I was thinking as well, but wasn't sure if it's safe to use the reference like that. Is there a guarantee that those uniforms won't be free'd or swapped to a different object somewhere else?

It's managed by a smart pointer sk_sp so it should keep it alive as long as it is needed.

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #53246 at sha 943832e

@Moncader
Copy link
Contributor Author

The test looks good now. Seems I don't have permission to say OK to the golden though?

Copy link
Contributor

@eyebrowsoffire eyebrowsoffire left a comment

Choose a reason for hiding this comment

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

I went ahead and approved the goldens. Thanks for the fix!

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

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

lgtm

@eyebrowsoffire eyebrowsoffire added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 25, 2024
@auto-submit auto-submit bot merged commit ee1884c into flutter:main Jun 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 25, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jun 25, 2024
…150797)

flutter/engine@62e0b5f...94023d7

2024-06-25 [email protected] [skwasm] Fixes for getting pixels from an image. (flutter/engine#53561)
2024-06-25 [email protected] fix: web canvaskit fragment shaders were not using updated uniform values (flutter/engine#53246)
2024-06-25 [email protected] Roll Dart SDK from b5fc85cfcf1b to 65ab2f2cf0d3 (1 revision) (flutter/engine#53565)
2024-06-25 [email protected] Roll Skia from e4e4feb97a54 to da1ea4eb0270 (4 revisions) (flutter/engine#53563)
2024-06-25 [email protected] [DisplayList] Switch to recording DrawVertices objects by reference (flutter/engine#53548)
2024-06-25 [email protected] Roll Skia from 5f21260470cf to e4e4feb97a54 (1 revision) (flutter/engine#53559)
2024-06-25 [email protected] [impeller] Cleanup blur (flutter/engine#53543)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@Moncader Moncader deleted the fix/web-shader-uniforms branch June 26, 2024 02:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine will affect goldens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CanvasKit FragmentShaders do not update uniforms when reusing a Paint object.

4 participants