Fix Vp8Residual costs calculation#2432
Conversation
| /// Initializes a new instance of the <see cref="Vp8BandProbas"/> class. | ||
| /// Only used for unit tests. | ||
| /// </summary> | ||
| [JsonConstructor] |
There was a problem hiding this comment.
We should probably use a custom JSON converter in the tests rather than adding attributes to the source.
There was a problem hiding this comment.
Sorry @brianpopow I've given you the runaround here. I didn't realize you'd introduced the constructors.
Let's go with your original plan but wrap the namespace imports and constructor code in the following conditional.
#if SIXLABORS_TESTING || SIXLABORS_TESTING_PREVIEWThere was a problem hiding this comment.
Let's go with your original plan but wrap the namespace imports and constructor code in the following conditional.
#if SIXLABORS_TESTING || SIXLABORS_TESTING_PREVIEW
I dont think that's a good idea. If someone does a fresh clone of the repo and tries to run the tests, those webp tests will fail without any obvious reason. I dont think test should behave different when a environment is set. Unfortunately I dont have a better idea so far.
There was a problem hiding this comment.
Can we avoid the json and populate the test instance with equivalent data generated in a class using string builder or similar?
There was a problem hiding this comment.
Can we avoid the json and populate the test instance with equivalent data generated in a class using string builder or similar?
Usually I would create a test instance in the unittest and populate it with data, but for Vp8Residual that does not seem feasible. There are so many nested arrays, that I dont know how this can be populated manually. Thats why I have chosen to go for json serialization.
Also I dont understand your suggestion with the string builder.
I now tried to use the binary serialization and this was looking promising. We would not need the additional constructors.
But now I noticed its marked as obsolete 😢
See: https://learn.microsoft.com/de-de/dotnet/standard/serialization/binaryformatter-security-guide
There was a problem hiding this comment.
Changed serialization now to use BinaryWriter/BinaryReader, according to https://learn.microsoft.com/de-de/dotnet/standard/serialization/binaryformatter-security-guide this should be fine.
No additional constructors required now.
There was a problem hiding this comment.
Ah that’s fantastic! We’ll done finding a solution!
Prerequisites
Description
This PR fixes an issue with the AVX2 version of the residual costs calculation. In some rare cases it does not match the scalar version. I have switch back to the SSE2 variant, which matches the original libwebp implementation.
AVX version was
SSE version:
The problem was that
Avx2.PackSignedSaturate(e0, e0);is not the same asSse2.PackSignedSaturate(e0, e1);Related to #2414