-
-
Notifications
You must be signed in to change notification settings - Fork 888
Expose Buffer2D and ParallelHelper internals #1035
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1993fac
expose limited Buffer2D internals, smplify API surface
antonfirsov 88de2d9
publish ParallelHelper and RowInterval API-s
antonfirsov 7c45f46
expose ParallelExecutionSettings and ParallelHelper, fix MaxDegreeOfP…
antonfirsov e342d4f
fix Configuration.MaxDegreeOfParallelism error cases
antonfirsov 58d694f
Merge remote-tracking branch 'origin/master' into af/expose-buffer-in…
antonfirsov 6d56668
StyleCop
antonfirsov f993eb6
Remove extra chars
JimBobSquarePants fe09e10
Merge branch 'master' into af/expose-buffer-internals
JimBobSquarePants File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,44 +10,45 @@ | |
| using SixLabors.Memory; | ||
| using SixLabors.Primitives; | ||
|
|
||
| namespace SixLabors.ImageSharp.ParallelUtils | ||
| namespace SixLabors.ImageSharp.Advanced.ParallelUtils | ||
| { | ||
| /// <summary> | ||
| /// Utility methods for batched processing of pixel row intervals. | ||
| /// Parallel execution is optimized for image processing. | ||
| /// Use this instead of direct <see cref="Parallel"/> calls! | ||
| /// Parallel execution is optimized for image processing based on values defined | ||
| /// <see cref="ParallelExecutionSettings"/> or <see cref="Configuration"/>. | ||
| /// Using this class is preferred over direct usage of <see cref="Parallel"/> utility methods. | ||
| /// </summary> | ||
| internal static class ParallelHelper | ||
| public static class ParallelHelper | ||
| { | ||
| /// <summary> | ||
| /// Get the default <see cref="ParallelExecutionSettings"/> for a <see cref="Configuration"/> | ||
| /// </summary> | ||
| public static ParallelExecutionSettings GetParallelSettings(this Configuration configuration) | ||
| { | ||
| return new ParallelExecutionSettings(configuration.MaxDegreeOfParallelism, configuration.MemoryAllocator); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Iterate through the rows of a rectangle in optimized batches defined by <see cref="RowInterval"/>-s. | ||
| /// </summary> | ||
| /// <param name="rectangle">The <see cref="Rectangle"/>.</param> | ||
| /// <param name="configuration">The <see cref="Configuration"/> to get the parallel settings from.</param> | ||
| /// <param name="body">The method body defining the iteration logic on a single <see cref="RowInterval"/>.</param> | ||
| public static void IterateRows(Rectangle rectangle, Configuration configuration, Action<RowInterval> body) | ||
| { | ||
| ParallelExecutionSettings parallelSettings = configuration.GetParallelSettings(); | ||
| ParallelExecutionSettings parallelSettings = ParallelExecutionSettings.FromConfiguration(configuration); | ||
|
|
||
| IterateRows(rectangle, parallelSettings, body); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Iterate through the rows of a rectangle in optimized batches defined by <see cref="RowInterval"/>-s. | ||
| /// </summary> | ||
| /// <param name="rectangle">The <see cref="Rectangle"/>.</param> | ||
| /// <param name="parallelSettings">The <see cref="ParallelExecutionSettings"/>.</param> | ||
| /// <param name="body">The method body defining the iteration logic on a single <see cref="RowInterval"/>.</param> | ||
| public static void IterateRows( | ||
| Rectangle rectangle, | ||
| in ParallelExecutionSettings parallelSettings, | ||
| Action<RowInterval> body) | ||
| { | ||
| ValidateRectangle(rectangle); | ||
|
|
||
| int maxSteps = DivideCeil(rectangle.Width * rectangle.Height, parallelSettings.MinimumPixelsProcessedPerTask); | ||
| int maxSteps = DivideCeil( | ||
| rectangle.Width * rectangle.Height, | ||
| parallelSettings.MinimumPixelsProcessedPerTask); | ||
|
|
||
| int numOfSteps = Math.Min(parallelSettings.MaxDegreeOfParallelism, maxSteps); | ||
|
|
||
|
|
@@ -81,7 +82,7 @@ public static void IterateRows( | |
| /// Iterate through the rows of a rectangle in optimized batches defined by <see cref="RowInterval"/>-s | ||
| /// instantiating a temporary buffer for each <paramref name="body"/> invocation. | ||
| /// </summary> | ||
| public static void IterateRowsWithTempBuffer<T>( | ||
| internal static void IterateRowsWithTempBuffer<T>( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming this is internal because Drawing does not use it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I'm not fully happy with this API yet, so I'd keep it internal for now. |
||
| Rectangle rectangle, | ||
| in ParallelExecutionSettings parallelSettings, | ||
| Action<RowInterval, Memory<T>> body) | ||
|
|
@@ -133,13 +134,13 @@ public static void IterateRowsWithTempBuffer<T>( | |
| /// Iterate through the rows of a rectangle in optimized batches defined by <see cref="RowInterval"/>-s | ||
| /// instantiating a temporary buffer for each <paramref name="body"/> invocation. | ||
| /// </summary> | ||
| public static void IterateRowsWithTempBuffer<T>( | ||
| internal static void IterateRowsWithTempBuffer<T>( | ||
| Rectangle rectangle, | ||
| Configuration configuration, | ||
| Action<RowInterval, Memory<T>> body) | ||
| where T : unmanaged | ||
| { | ||
| IterateRowsWithTempBuffer(rectangle, configuration.GetParallelSettings(), body); | ||
| IterateRowsWithTempBuffer(rectangle, ParallelExecutionSettings.FromConfiguration(configuration), body); | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍