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

Conversation

@jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Feb 21, 2023

A not-particularly-fast implementation of texture coordinates. This is missing a fairly reasonable fast path which is 1. texture coordinates + image shader + no per vertex colors should not require any subpasses. Fast path added.

This implementation is a bit complicated by the fact that both the geometetry and the contents need to know the "size" of the color source that the texture coordinates are applied to. From experimentation with Skia, the extent of the gradient is used where possible, as is the size of the image - as the texture coordinates are always given in the local coordinate space.

For solid colors we should probably elide the subpass and bail, but that doesn't seem particularly important. For sweep gradients and runtime effect, its not clear what size we should use so I'm falling back to using the overall geometry coverage.

Fixes flutter/flutter#109956

@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 Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on 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.

@jonahwilliams
Copy link
Contributor Author

still needs effect transform

@jonahwilliams
Copy link
Contributor Author

I should double check, but I suppose a reasonable way to interpret the texture coordinates for color sources without sizes is to take the maximum coverage from the texture coordinates. I'll do some experiments with Skia.

@chinmaygarde chinmaygarde added the Work in progress (WIP) Not ready (yet) for review! label Feb 23, 2023
@jonahwilliams
Copy link
Contributor Author

Added fast path for ImageShaders and use texture coordinate extent for other shader types. Not going to spend much more time on that, I don't think its important.

Need to do effect transform still.

(texture_coord.y() - origin.y) / size.height);
// From experimentation we need to clamp these values to < 1.0 or else
// there can be flickering.
vertex_data[i] = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Observed flickering while scrolling when using vertices + texture coordinates and a gradient in a subpass. Geometry and stencil were correct

@jonahwilliams
Copy link
Contributor Author

Okay, i have hacked in support for the effect transform for textures!

@jonahwilliams jonahwilliams removed the Work in progress (WIP) Not ready (yet) for review! label Feb 24, 2023
@jonahwilliams
Copy link
Contributor Author

I removed the position_uv vertex shader because it doesn't do anything that the texture_fill.vert shader doesn't do

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM with nits

Comment on lines 391 to 394
if (!vertices->HasVertexColors() &&
(!vertices->HasTextureCoordinates() ||
(vertices->HasTextureCoordinates() &&
paint.color_source_type == Paint::ColorSourceType::kImage))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think this and the if below would read a little clearer if there was a method on Vertices to help sort these things out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's not really a good place to put this. it depends on the color source type which can't be used outside of aiks, and the vertices are a geometry object defined in entity. It can't go on the contents because it isn't created yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this to a static helper function

Comment on lines 288 to 289
.texture_coords = Point(std::clamp(uv.x, 0.0f, 0.995f),
std::clamp(uv.y, 0.0f, 0.995f)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the second constant be 1.0 - kEhCloseEnough?

Copy link
Contributor

Choose a reason for hiding this comment

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

(that would avoid introducing a new epsillon, which this feels like)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah good idea. I was actually surprised a bit by this behavior, maybe I'm actually doing the math wrong?

jonahwilliams added 2 commits February 25, 2023 14:15
# Write the new results to the file given by --before, then exit.
with open(args.before, 'w') as file:
json.dump(after_json, file, sort_keys=True)
json.dump(after_json, file, sort_keys=True, indent=2)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Splitting each line out makes the diff view a lot easier to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reverted this for now to avoid conflicts

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 27, 2023
@auto-submit auto-submit bot merged commit ab03447 into flutter:main Feb 27, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 27, 2023
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 e: impeller

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

[impeller] support for ImageShader / texture coordinates on drawVertices

3 participants