-
Notifications
You must be signed in to change notification settings - Fork 205
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
Prototype For Fast Bulk Sampling Of Pixels #5102
Conversation
d543a09
to
d90fcba
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Daniel, I like it! Few rushed comments inline - trying to get it posted before our meeting which started 2 minutes ago :)
@@ -95,6 +95,13 @@ class GAFFERIMAGE_API Sampler | |||
/// 0.5, 0.5. | |||
float sample( float x, float y ); | |||
|
|||
/// Call a functor for all pixels in the region. | |||
/// The signature of the functor must be `F( float value, int x, int y )`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you have any objection to F( const V2i &p, float value )
?
14a0392
to
13f4ea0
Compare
13f4ea0
to
4dd0504
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one! I've made a few very minor comments inline, but this is looking great, and the results speak for themselves.
Note to self : you will need to update Changes.md after merging.
This is a very low quality, but fast approach ( it also offer a way of profiling the performance of Sampler::sample( float, float ), which previously wasn't used anywhere critical )
Might as well make it easy for people who want to do fast things with images?
Seems to give a 15% performance improvement in common cases
This is a 70% performance improvement when using a VectorWarp with useDerivatives on to downsample an image.
4dd0504
to
8eec8bd
Compare
Thanks Daniel! While updating Changes.md, I tested with a large-radius Blur and was very pleased to see that it was nearly 6x faster, and feels waay speedier in interactive use. Nice one! |
I was doing some experimenting with some of our more expensive image operations, and found that Sampler.sample() is a big bottleneck. In cases where we need to sample every pixel in a region, we can do much better by doing the iteration within Sampler, where we can iterate through every pixel in the region within a particular tile with a single call to cachedData.
I was a bit unsure how to demonstrate the benefit from this ... Resample with a non-separable filter should benefit because it needs to do an enormous amount of sampling ... but the only case we have currently of a non-separable filter is a filter which is incredibly slow to evaluate, so it doesn't really demonstrate the benefit.
I've ended up demonstrating this on RankFilter - this is a little silly, because RankFilter doesn't need to do all this repeated sampling of the same pixels, but for our current naive implementation, it does show a noticeable speedup, 4X for Erode/Dilate, and 2X for Median.
A more practical demonstration of benefit would be optimizing Blur, but that feels a little bit more contentious, because doing that efficiently would probably require adding a special case to Resample for when the matrix is an identity and the filter weights are identical for every pixel ... I think this makes a lot of sense, but perhaps should be a separate PR.
I think this is looking pretty good, though I wish I had slightly more thorough tests for the rank filters in order to validate this sort of work, and ideally I would double check that visitPixels is fully getting inlined and optimized away properly - the goal is that copying a scanline into a vector should be optimized to basically a memcpy per tile.