Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Impeller] Switch to uniform arrays for gradient data on non-SSBO hardware #56294

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

flar
Copy link
Contributor

@flar flar commented Nov 1, 2024

Currently the most generalized form of the Impeller gradient shaders uses an SSBO to store the gradient information, but SSBO data is not supported on older platforms. To make the capability more general we introduce variants of the gradient shaders that uses uniform arrays which are more widely supported.

float tile_mode;
vec4 decal_border_color;
float alpha;
int colors_length;
Copy link
Member

Choose a reason for hiding this comment

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

GLES 2.0 requires that we use a float for this 😨

highp vec2 start_to_end;
float alpha;
float tile_mode;
int colors_length;
Copy link
Member

Choose a reason for hiding this comment

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

Same here

float tile_mode;
vec4 decal_border_color;
float alpha;
int colors_length;
Copy link
Member

Choose a reason for hiding this comment

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

Same here

@@ -53,6 +53,10 @@ class LinearGradientContents final : public ColorSourceContents {
const Entity& entity,
Copy link
Member

Choose a reason for hiding this comment

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

Can we also remove RenderTexture in this patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Eventually, I want to leave the old stuff around while I get the new stuff working and then I can run comparisons for testing/benchmarking.

Copy link
Member

Choose a reason for hiding this comment

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

SGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per other discussions I think we decided it would stay in case we get more than 256 colors. Eventually we hope to have a vertex tiling solution that works efficiently on all platforms, but until then we'll still have the issue with zero-length stops on older platforms, but only if there are more than 256 stops total...

/**
* @brief Populate 2 arrays with the colors and stop data for a gradient
*
* The color data is simple converted to a vec4 format, but the stop data
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@flar
Copy link
Contributor Author

flar commented Nov 5, 2024

FYI - The latest push uses the Uniform versions of the shaders for all types as long as there are fewer than 256 colors. References to the old shaders are commented out for now just as a test run to test the new shaders as much as possible. If the test results are fine then I'll restore and finalize the code.

@@ -145,4 +145,30 @@ vec3 IPComputeFixedGradientValues(float t, float colors_length) {
return vec3(lower_index, upper_index, scale);
}

vec4 IPComputeColorFromTables(vec4 colors[256],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this is used any more as the call overhead swamped everything else. I'll delete when I finalize the code.

@flar flar marked this pull request as ready for review November 6, 2024 02:28
@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 #56294 at sha 3dc79ba

@flar flar force-pushed the impeller-uniforms-for-general-gradients branch from 3dc79ba to 75874d3 Compare November 6, 2024 02:53
@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, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

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. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@flar flar changed the title [Impeller] Switch to uniform arrays for gradient data [Impeller] Switch to uniform arrays for gradient data on non-SSBO hardware Nov 6, 2024
@flar
Copy link
Contributor Author

flar commented Nov 6, 2024

I just noticed the golden diffs from the previous round of testing. It looks like I have more testing/debugging to do.

@flutter-dashboard
Copy link

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

Changes reported for pull request #56294 at sha 75874d3

@flar
Copy link
Contributor Author

flar commented Nov 6, 2024

I've fixed the problem that was causing the golden failures (I believe) and restored the code that forces the new Uniform variant of the shaders to do another test run.

While testing this version I was seeing memory corruption issues in my local testing. I'll file a related bug for review by a wider audience.

@flar
Copy link
Contributor Author

flar commented Nov 6, 2024

AFAICT, the golden diffs on the last commit were due to:

  • the new shaders not supporting dithering (which uses instructions not avilable on the older hardware platforms) for all of the Vulkan/Metal diffs
  • a few "edge of the gradient is +/- 1" differences from the new shader compared to the old texture shader
  • and finally at least one diff that represents one of the issues that these new shaders are trying to fix - the texture shader doesn't handle stop lengths of 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants