Skip to content
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

Relax strict pixel match tests in test_src_alpha_sdl2_blitter by allowing a small delta #3494

Merged
merged 4 commits into from Oct 16, 2022

Conversation

Temmie3754
Copy link
Contributor

Resolves the small issue in a test raised by #3097
Allows for a delta of up to 2 which resolves all errors presented in the original problem.

Copy link
Contributor

@ankith26 ankith26 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! 🎉 🎈

Left a minor review

test/surface_test.py Outdated Show resolved Hide resolved
@ankith26 ankith26 added Surface pygame.Surface SDL2 tests tests (module) labels Oct 11, 2022
@ankith26 ankith26 changed the title Fixes #3097 Relax strict pixel match tests in test_src_alpha_sdl2_blitter by allowing a small delta Oct 11, 2022
test/surface_test.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ankith26 ankith26 left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉 😎

(There is a minor CI fail in here, could you please run black on the python file you changed in this PR to fix the formatting?)

@Temmie3754
Copy link
Contributor Author

Formatting should hopefully be correct finally

@Starbuck5
Copy link
Contributor

The source of this problem is very mysterious. I think it's SIMD related, but why? SIMD doesn't do approximation, it just does acceleration.

I don't think the solution is to just add a delta to the test. I would prefer it to test that the result is EXACTLY X or Y, rather than testing whether it's within 4 of X.

@ankith26
Copy link
Contributor

I am of the view that as long as something blitting related does not change much visually, it shouldn't be considered a break.
The underlying formula is an implementation detail, especially while using the SDL blitter, we should not treat things as a break when they make minor changes on their side. So to me having a delta makes sense, but I don't mind changing the exact number specified in the delta

@Starbuck5
Copy link
Contributor

Blitting should be 100% deterministic. Input A goes to output B, every time, 100% accurate. The fact that it isn't (on the SDL2 blitter) is extremely unsettling.

I believe our current situation is that Input A goes to output B or output C, based on SDL version / architecture. Therefore I'd like to test the output against B and C, and only fail if it is neither.

I don't want it to drift again without our noticing, and that's what a delta does.

@Temmie3754
Copy link
Contributor Author

Alright I'll look into changing the implementation to use fixed outputs as specified by the original error but I will need someone else who has those architectures to test that it resolves the issue.

@ankith26
Copy link
Contributor

Blitting should be 100% deterministic. Input A goes to output B, every time, 100% accurate. The fact that it isn't (on the SDL2 blitter) is extremely unsettling.

Blitting should be deterministic for a given SDL version? yes. The exact same on all platforms across all SDL versions of the past and future? Probably too much to ask, even if desirable. SDL can make algorithmic changes, and since the exact algorithm is not a documented API detail, I don't see why they shouldn't be making tiny changes to it if it helps with performance, even though the exact pixel colours change a tiny bit. I can understand if there's a big change that has visual affect, it could be considered a breaking change.

If I had to guess, I'd say this PR changed things libsdl-org/SDL#5430 (I tested on windows 2.24.1) but I'm not very sure. Atleast I didn't find anything else blit related that changed.

I don't want it to drift again without our noticing, and that's what a delta does.

I'm saying we shouldn't care of minor drifts. I can't tell the difference between (255, 10, 100) and (253, 12, 98) when they are in the same image side by side. Visually I can't see the line of separation and it looks all pink to me, even though I'm sure the lines technically there. Am I colour blind? Probably not 😄

I also don't want to add the maintenance burden of having to keep updating our tests everytime SDL does a minor change like now. pygame users who resort to using the SDL blitter are the same target group of people who care about performance and not exact match with the pygame blitter.

@Temmie3754
Copy link
Contributor Author

Created an implementation that checks if its either the normal outputs or the ones provided in the original issue, just need to come to a decision on which version would be a better choice now. Can view the differences here in the meantime https://github.com/Temmie3754/pygame/tree/surface-test-fixes.

Copy link
Contributor

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

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

I mentioned this on the discord too but I am generally in favour of this change for the SDL2 alpha blitter tests. This isn't the first time, or even the second time that the SDL formula has changed slightly - in fact these changes are the whole reason we ended up creating the default pygame alpha blitter. Ultimately these tests failing is outside of our control as we can't stop SDL slightly tweaking their alpha blitting formula.

For most users, they will never use the SDL2 alpha blitter as you have to go and seek it out and specifically flag to use it, and for those that do so a tiny colour discrepancy (likely less than 0.5%) between SDL versions on some platforms when alpha blitting - that is not normally visually noticeable will be unlikely to cause issues.

I do think we should create a second issue to update the docs for the BLEND_ALPHA_SDL2 in 2.1.4 after all the performance changes around the alpha blitters that are floating around have made it in. I suspect the original description of being 'sometimes faster' will be increasingly inaccurate by that point - especially if we have full AVX2 acceleration on the pygame alpha blitters. Then at that point we can also add a note in the docs that the SDL2 blitting formula differs between different versions of SDL.

@ankith26
Copy link
Contributor

I'll merge it in now, it's a non-risky change and as said before should better future-proof this test. If the need arises in the future, we can consider a stricter but more-maintenance-ey test then.
Definitely the docs around BLEND_ALPHA_SDL2 needs updating to reflect the latest pygame blitter improvements, and the inter-SDL-version minor differences, but as MyreMylar says that can happen in a future PR, lets get this one in 🥳

@ankith26 ankith26 merged commit 31f9004 into pygame:main Oct 16, 2022
@ankith26 ankith26 added this to the 2.1.3 milestone Oct 16, 2022
@illume illume added the bug label Oct 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug SDL2 Surface pygame.Surface tests tests (module)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test_src_alpha_sdl2_blitter should not test for exact pixel perfect match (and instead allow a small delta)
5 participants