Skip to content

Implement new Vector methods correctly to take advantage of performance improvements #3

Closed

Description

@JimBobSquarePants

From @JimBobSquarePants on December 1, 2015 12:23

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

Activity

  1. JimBobSquarePants commented on Oct 30, 2016

    @JimBobSquarePants
    MemberAuthor

    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:

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

  2. JimBobSquarePants commented on Oct 30, 2016

    @JimBobSquarePants
    MemberAuthor

    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.

    The code, I believe, would be:

    return Vector4.Lerp(from.backingVector, to.backingVector, amount);
    

    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.

  3. 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
  4. olivif commented on Dec 19, 2016

    @olivif
    Contributor

    I see usage of Vector4 in a bunch of places now, are there any remaining areas which we need to convert? 😄

  5. JimBobSquarePants commented on Dec 19, 2016

    @JimBobSquarePants
    MemberAuthor

    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.

  6. antonfirsov commented on Dec 26, 2016

    @antonfirsov
    Member

    Subsampling is not an issue, the only test input where it goes over 1% is the cmyk watch:
    jpegcmykwatchprofile

  7. JimBobSquarePants commented on Nov 23, 2018

    @JimBobSquarePants
    MemberAuthor

    Closing this. @antonfirsov has done incredible work to implement vectorization throughout the library.

  8. added a commit that references this issue on Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions