Skip to content

Change ubersdf to highp float precision - #195703

Open
walley892 wants to merge 4 commits into
flutter:masterfrom
walley892:uber-highp
Open

walley892 wants to merge 4 commits into
flutter:masterfrom
walley892:uber-highp

Conversation

@walley892

Copy link
Copy Markdown
Contributor

UberSDF uses mediump float for all it's calculations - for large coordinates, this causes overflow when calculating things like length - leading to rendering errors as in #195208.

This change just switches the shader to highp floats, fixing the rendering issue - this should also make the antialiasing look sharper in general.

Before:

Screenshot 2026-10-30 at 11 19 17 AM Screenshot 2026-10-30 at 11 19 24 AM

After
Screenshot 2026-10-30 at 11 22 38 AM
Screenshot 2026-10-30 at 11 22 34 AM

Fixes #195208

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant in-code documentation (doc comments with ///).
  • If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

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. If both you and the PR author believe this PR qualifies for a test exemption, escalate to the tech lead for the changed area to review and apply the test-exempt label. All reviewers should feel empowered to ask for tests before escalating.

@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. e: impeller Impeller rendering backend issues and features requests labels Oct 30, 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 updates the float precision in the shared UberSDF shader code (uber_sdf_common.glsl) from mediump to highp. No review comments were provided, and there is no additional feedback.

@walley892

Copy link
Copy Markdown
Contributor Author

@gaaclarke thoughts on this? I think this should be fine because we're targeting desktop with uber_sdf.

Alternatively, we could do some scaling down in parts of the code that blow up. E.x., mediumPLength(V) = 100*length(V/4) or something. This avoids using highp, but (1) punts the problem to a larger scale, (2) loses precision, and (3) is messy to keep track of all the places where mediump blows up.

IMO we can live with highp for now, and we can explore tricky alternatives if we decide to use uber on mobile

@gaaclarke

Copy link
Copy Markdown
Member

IMO we can live with highp for now, and we can explore tricky alternatives if we decide to use uber on mobile

That sounds fine to me.

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

I'd like a test that demonstrates the requirement.

gaaclarke
gaaclarke previously approved these changes Nov 2, 2026

@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 assuming you're happy with the golden output

@walley892

Copy link
Copy Markdown
Contributor Author

@gaaclarke malioc'd

"stack_spill_bytes": 0,
"thread_occupancy": 100,
"uniform_registers_used": 62,
"uniform_registers_used": 78,

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.

Oof we've tried to draw a hard limit here for 64. Any ideas here?

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.

Yeah, I think we could do a few things to try and squeeze it down. Since we're only targeting desktop right now and this is something that's affecting a bunch of users - thoughts about landing this now and squeezing later?

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.

We can afford some time to try to address it. Maybe there is an easy win here. Sic mad dog gemini on it and see what it says.

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.

Gemini was kind of a mess here, but my feeble human mind came up with #196392.

There's an easier way to save uniforms, which is to completely remove the RSE from the uber shader - but that removes the gradient performance gains from RSEs. We can get to 64 registers with #196392 and more targeted highp directives

@b-luk

b-luk commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

This also fixes #195159. Can you add a test for large gradients as well, and you can update the description to say it fixes that issue too?

@b-luk b-luk closed this Nov 4, 2026
@b-luk b-luk reopened this Nov 4, 2026
@fluttergithubbot

Copy link
Copy Markdown
Contributor

An existing Git SHA, a1539020cfb25448248827193cc7e90f23b7e6b1, 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.

@walley892 walley892 mentioned this pull request Nov 11, 2026
11 tasks done
JadeCong pushed a commit to CloudEngineHub/flutter that referenced this pull request Nov 12, 2026
Refactors a few things in uber_sdf to save on uniform registers.

- makes aa_pixels a constant in the fragment shader rather than being
set by uniform
- reworks the superellipse corner calculation to remove atan and mod
- Folds the superellipse angle_span into unused `radii` fields
- Moves `center` and `gradient_origin` to vertex inputs

Prework for flutter#195703

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [AI contribution guidelines] and understand my
responsibilities, or I am not using AI tools.
- [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 in-code documentation (doc comments with
`///`).
- [x] If this PR introduces a new feature or capability, I created and
linked a website documentation issue or PR in [flutter/website] (or
verified none is needed).
- [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

CICD Run CI/CD 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.

Canvas.drawCircle behaves wrong on Linux with Impeller

4 participants