Skip to content

Introduce optimized conversion methods for RGBA-like types#751

Merged
JimBobSquarePants merged 19 commits intomasterfrom
af/extend-bulk-conversion
Oct 27, 2018
Merged

Introduce optimized conversion methods for RGBA-like types#751
JimBobSquarePants merged 19 commits intomasterfrom
af/extend-bulk-conversion

Conversation

@antonfirsov
Copy link
Member

@antonfirsov antonfirsov commented Oct 26, 2018

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

@JimBobSquarePants unleashed the beast in #729 by introducing T4 generators for several pixel types. This PR introduces optimized bulk conversion methods for most of them, making them first class citizens, reducing the privileged role of Rgba32.

  • SixLabors.ImageSharp.PixelFormats.Utils.PixelConverter: Optimized conversion primitives for Rgba32 <-> Bgra32 <-> Argb32
  • _Common.ttinclude now generates code using PixelConverter for Rgba32, Bgra32, Argb32
  • Added a Configuration parameter to all conversion methods so they can allocate. (And maybe do other configuration-dependent stuff in the future)
  • Optimized ToVector4() and FromVector4() for all "RGBA-compatible" types (Argb32, Bgra32, Rgb24, Bgr24): converting to/from Rgba32 and utilize SimdUtils
  • Bunch of chore refactor: Common Vector4 conversion code moved to Vector4Converters, PixelOperationsTests have been split into separate files, etc.

Performance gain

  • Rgba32 <-> Bgra32 conversion time reduced by 30%
  • Bgra32 -> Vector4 conversion time reduced by 55% on CoreCLR 2.1, and by 15% on .NET Framework on my PC. (Anyone any idea why? I have 4.7.2 installed!)
  • Haven't benchmarked it, but the Argb32 path should be even faster.

@antonfirsov antonfirsov changed the title Introduce optimized conversion methods for "RGBA-compatible" types Introduce optimized conversion methods for RGBA-like types Oct 26, 2018
Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

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

This is an extraordinary piece of work!

The masking code is excellent and really nicely annotated also. I would never have in a million years thought of it.

@antonfirsov
Copy link
Member Author

antonfirsov commented Oct 26, 2018

I also needed to browse corefx code for hours. Everything is based on Levi Boderick's ideas in dotnet/corefx#26303.

@JimBobSquarePants JimBobSquarePants merged commit fc4da81 into master Oct 27, 2018
@antonfirsov antonfirsov deleted the af/extend-bulk-conversion branch October 30, 2018 21:08
antonfirsov pushed a commit to antonfirsov/ImageSharp that referenced this pull request Nov 11, 2019
…sion

Introduce optimized conversion methods for RGBA-like types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants