You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Implement new Vector methods correctly to take advantage of performance improvements #3
The new System.Numerics.Vectors contains several new types that take advantage of SIMD processors and are specifically designed graphics programming. I have little-to-no knowledge of those types and will need assistance integration the various methods they offer in order to utilize them properly.
Copied from original issue: JimBobSquarePants/ImageProcessor#259
public static Color Lerp(Color from, Color to, float amount)
{
amount = amount.Clamp(0f, 1f);
if (Math.Abs(from.A - 1) < Epsilon && Math.Abs(to.A - 1) < Epsilon)
{
return from + (to - from) * amount;
}
// Premultiplied.
return from * (1 - amount) + to;
}
to this:
public static Color Lerp(Color from, Color to, float amount)
{
amount = amount.Clamp(0f, 1f);
if (Math.Abs(from.A - 1) < Epsilon && Math.Abs(to.A - 1) < Epsilon)
{
return Vector4.Lerp(from, to, amount);
}
// Premultiplied.
// TODO: not sure how to use Vector4.Lerp here
return from * (1 - amount) + to;
}
might improve performance by making use of the Vector4.Lerp method (need to measure performance to be certain).
You're absolutely correct. I can use the built in Vector4.Lerp in that situation. The Color minus operator utilizes the backing vector but we might as well cut out the middle man.
changed the title [-]Implement new Vector methods correctly to take advantage of performance improments[/-][+]Implement new Vector methods correctly to take advantage of performance improvements[/+]on Oct 30, 2016
I think it might be possible to vectorize bits and bobs throughout, maybe in colorspace conversions or running through lists. I know the subsampling scaling in jpeg decoder is vectorised in libjpeg turbo also.
I just don't know the Numerics API's well enough though to figure out what could benefit.
Activity
JimBobSquarePants commentedon Oct 30, 2016
From @voidstar69 on January 23, 2016 14:27
@JimBobSquarePants is this the sort of change that you are looking for?
Changing Color.Lerp from this:
to this:
might improve performance by making use of the Vector4.Lerp method (need to measure performance to be certain).
JimBobSquarePants commentedon Oct 30, 2016
You're absolutely correct. I can use the built in
Vector4.Lerpin that situation. TheColorminus operator utilizes the backing vector but we might as well cut out the middle man.The code, I believe, would be:
For premultiplied alpha we'd probably have to fall back to the non SIMD approach.
I'd imagine it would be a very tiny performance improvement but every little most certainly helps.
[-]Implement new Vector methods correctly to take advantage of performance improments[/-][+]Implement new Vector methods correctly to take advantage of performance improvements[/+]olivif commentedon Dec 19, 2016
I see usage of
Vector4in a bunch of places now, are there any remaining areas which we need to convert? 😄JimBobSquarePants commentedon Dec 19, 2016
I think it might be possible to vectorize bits and bobs throughout, maybe in colorspace conversions or running through lists. I know the subsampling scaling in jpeg decoder is vectorised in libjpeg turbo also.
I just don't know the Numerics API's well enough though to figure out what could benefit.
antonfirsov commentedon Dec 26, 2016
Subsampling is not an issue, the only test input where it goes over 1% is the cmyk watch:

JimBobSquarePants commentedon Nov 23, 2018
Closing this. @antonfirsov has done incredible work to implement vectorization throughout the library.
Merge pull request #3 from SixLabors/master