Skip to content

Surface module compiling in SDL3 #3435

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Starbuck5
Copy link
Member

@Starbuck5 Starbuck5 commented May 24, 2025

This PR consists of 4 commits, and it gets the surface module to compile with SDL3. It still fails lots of tests when run in SDL3 mode, but there is lots of SDL-function porting to be done with int->bool stuff.

Commit 1 focuses on Surface.c

This commit does not change the SDL2 codepath at all, except for a cliprect thing similar to what I've done in other PRs.

The RLEaccel stuff is confusing, even digging through the SDL2 source it's hard to understand. Our code uses surf->flags & SDL_RLEACCEL to check, interchangeably with SDL_SurfaceHasRLE(surf), but if you check the source SDL_SurfaceHasRLE does not check the same flags. However, in testing it seems to be equivalent, somehow.

I also just declined to port a whole section that covers a blitting edge case, we'll get to it later, for now I think it will be valuable to have people able to compile at all.

Commit 2 and 3 focus on filling and blitting respectively

There are a lot of lines changed but it's just passing formats around, nothing complex

Commit 4 makes intrinsics compile properly

I took Ankith's prior work on this and moved it up to _surface.h, as well as making sure it defines SSE2 and AVX2 itself if necessary. On my (Windows) system it doesn't compile at least the SSE2 stuff without this, so in SDL2 we must be getting that define from SDL itself.

@Starbuck5 Starbuck5 requested a review from a team as a code owner May 24, 2025 05:11
@Starbuck5 Starbuck5 added Surface pygame.Surface sdl3 labels May 24, 2025
@Starbuck5 Starbuck5 marked this pull request as draft May 24, 2025 05:19
@Starbuck5 Starbuck5 force-pushed the surface-sdl3-comp branch 2 times, most recently from 2025f7e to a756521 Compare May 31, 2025 09:40
@Starbuck5 Starbuck5 force-pushed the surface-sdl3-comp branch from a756521 to c44f364 Compare May 31, 2025 22:55
@Starbuck5 Starbuck5 changed the title Get surface.c compiling in SDL3 Surface module compiling in SDL3 May 31, 2025
@Starbuck5 Starbuck5 marked this pull request as ready for review May 31, 2025 23:20
#if SDL_VERSION_ATLEAST(3, 0, 0)
if (SDL_SurfaceHasRLE(surf) && (!(flags & PGS_RLEACCEL)))
#else
if ((surf->flags & SDL_RLEACCEL) && (!(flags & PGS_RLEACCEL)))
Copy link
Member

Choose a reason for hiding this comment

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

SDL_SurfaceHasRLE basically checks if RLE was requested on a surface (and in this context should always be equivalent to (flags & PGS_RLEACCEL) because of the lines above this) which would basically make this whole block a if (false) thing that never runs.
surf->flags & SDL_RLEACCEL OTOH checks if the surface actually got RLE.

The problem here is that SDL doesn't expose the equivalent of (surf->flags & SDL_RLEACCEL) anymore. This is something that bites us with sdl2-compat as well (ref: libsdl-org/sdl2-compat#476) and as we have unit tests that fail because of this, we can tell that they don't have the same behavior.

As for this specific block, I think a more appropriate thing that reduces confusion would be to simply ifdef out the whole block in SDL3 and add a comment explaining that there's no way to do the check anymore (and its probably not even required in SDL3)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm unaware of any changes to RLE internals in SDL3, so if this block isn't necessary in SDL3 is it necessary in SDL2?

Copy link
Member

Choose a reason for hiding this comment

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

Added a print statement inside this block and ran the tests, it got into that path once. Found out that we have one test case that depends on this behaviour: test_solarwolf_rle_usage_2. So seems like this logic is necessary actually.

Copy link
Member

@ankith26 ankith26 Jun 12, 2025

Choose a reason for hiding this comment

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

I think that using SDL_MUSTLOCK (which is equivalent to (((S)->flags & SDL_RLEACCEL) != 0) on SDL2) does the same job on SDL3 as well, as an implementation detail
NVM SDL_MUSTLOCK is also now equivalent to SDL_SurfaceHasRLE apparently in SDL3

@ankith26 ankith26 added this to the 2.5.6 milestone Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sdl3 Surface pygame.Surface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants