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

switch to SDL3 #2052

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft

switch to SDL3 #2052

wants to merge 19 commits into from

Conversation

rfomin
Copy link
Collaborator

@rfomin rfomin commented Nov 27, 2024

SDL3_Net doesn't have UDP broadcast mode, so we're still using SDL2_Net. It looks like we need to rewrite it.

@rfomin rfomin force-pushed the sdl3 branch 2 times, most recently from 9c32c93 to 9082d6a Compare November 27, 2024 06:52
@MrAlaux
Copy link
Collaborator

MrAlaux commented Nov 27, 2024

I was wondering if SDL3 would still run on my machine, so I tried the latest Win-64 artifact as of now, and I'm glad to say that it does run. Now, I'm aware that this is a draft at the moment, but I'd like to report that I'm getting much lower FPS on that build, and trying to increase the resolution scale made the game crash.

@fabiangreffrath
Copy link
Owner

Impessive effort, thank you! Did you use one of the semi-automated migration tools announced here or did you go through this line by line?

https://github.com/libsdl-org/SDL/blob/main/docs/README-migration.md

Regarding SDL2_Net, do we know of any other widely used network abstraction library? SMFL, or would that be too much of a change?

@rfomin
Copy link
Collaborator Author

rfomin commented Nov 27, 2024

I'd like to report that I'm getting much lower FPS on that build,

I added sdl_renderer_name config option in 8af9754. Try setting it to "direct3d" or "opengl". On my system SDL3 selects direct3d11 and I've got slitghly more FPS. Also, what is the output of "woof -verbose" on your system?

trying to increase the resolution scale made the game crash.

Should work with d409b3e

@fabiangreffrath
Copy link
Owner

Should work with d409b3e

Doesn't this introduce a memory leak?

@rfomin
Copy link
Collaborator Author

rfomin commented Nov 27, 2024

Did you use one of the semi-automated migration tools announced here or did you go through this line by line?

I used python scripts, they just rename functions/headers.

Regarding SDL2_Net, do we know of any other widely used network abstraction library? SMFL, or would that be too much of a change?

SMFL is too big, we can replace the whole SDL with it. SDL_Net is a small wrapper around BSD Sockets/WinSock, I think we should rewrite it (and for Choco/Crispy too).

Should work with d409b3e

Doesn't this introduce a memory leak?

Possibly. I guess we need to bring back memcpy.

@MrAlaux
Copy link
Collaborator

MrAlaux commented Nov 27, 2024

what is the output of "woof -verbose" on your system?

Without setting sdl_renderer_name:

WARNING: D3D12: Could not find d3d12.dll
SDL render driver: direct3d11

At least with D3D11, I can change resolution properly. I also tried changing widescreen, and noticed that it messes with the mouse in menus; the rects seem to become misaligned.

Performance comparisons, judging from some quick tests (640p, DRS and VSync off, otherwise default settings):

  • Non-exclusive fullscreen: D3D (~126 FPS) > OpenGL (~124) > D3D11 (~37)
  • Exclusive fullscreen: D3D (~162) > OpenGL (~124) > D3D11 (~37)

@rfomin
Copy link
Collaborator Author

rfomin commented Nov 27, 2024

Should work with d409b3e

Doesn't this introduce a memory leak?

Possibly. I guess we need to bring back memcpy.

Fixed in 090a8ca (I think)

D3D (~126 FPS) > OpenGL (~124) > D3D11 (~37)

Wow, D3D11 is very slow on your system for some reason. Does SDL2 work well in D3D11 mode?

@MrAlaux
Copy link
Collaborator

MrAlaux commented Nov 27, 2024

Wow, D3D11 is very slow on your system for some reason. Does SDL2 work well in D3D11 mode?

I tried D3D11 on the current Nugget master (I kept the sdl_renderdriver setting from an earlier Woof version), and it also performs badly.

Do note, however, that my laptop has both integrated and dedicated graphics, and it defaults to the former for Nugget; if I force using dedicated graphics, D3D11 starts out running at 60 FPS, but after a few seconds it suddenly lowers to ~15. Not sure what's going on there.

For comparison, D3D runs better with integrated graphics, but when using dedicated graphics there's no sudden decrease in performance like with D3D11, or at least it doesn't happen as quickly.

@rfomin
Copy link
Collaborator Author

rfomin commented Nov 27, 2024

if I force using dedicated graphics, D3D11 starts out running at 60 FPS, but after a few seconds it suddenly lowers to ~15.

Sounds like overheating, replace the cooler (I did it on my old laptop, it's easy to find).

Anyway, not much has changed in the SDL3 2D Render backend, it works the same. API improved with different VSync modes, SDL_SyncWindow(), SDL_GetFullscreenDisplayModes() etc.

@MrAlaux
Copy link
Collaborator

MrAlaux commented Nov 27, 2024

Sounds like overheating

According to Open Hardware Monitor, the CPU and GPU stay at around 60ºC and under 50ºC respectively (the TJ max for the CPU seems to be 90ºC). Toggling exclusive fullscreen in-game (which "restarts" the screen to some degree) repeats the process: smooth performance for a few seconds, then a slowdown. Knowing that said sudden slowdown certainly doesn't happen with other games, I'm pretty sure that there's something else going on.

@Pedro-Beirao
Copy link
Contributor

Is SDL3 stable yet? I havent seen anything adopt it

And what does it improve in woof?

@rfomin
Copy link
Collaborator Author

rfomin commented Nov 27, 2024

Is SDL3 stable yet? I havent seen anything adopt it

Based on my limited testing, it works pretty stable. They say that Valve is using it.

And what does it improve in woof?

Currently some code is mostly being removed, for example SDL3 introduces nanosecond timer/wait functions. There are also better video mode functions for adaptive VSync, exclusive full screen, etc.

@ceski-1
Copy link
Collaborator

ceski-1 commented Dec 7, 2024

And what does it improve in woof?

In addition to what rfomin mentioned, there are some input improvements as well. For example, mouse input is handled as floats, and input processing is supposedly much more performant, especially with mice/keyboards that have >1kHz polling rates. I also noticed some neat changes related to gyro, but it's pretty niche to be fair.

@rfomin
Copy link
Collaborator Author

rfomin commented Dec 8, 2024

mouse input is handled as floats

Should we switch to floats for mouse input?

TODO:

  • Use floats for renderer viewport size, so maybe we can make the scaling factor calculation a little better/simpler.
  • Remove the file globbing code (i_glob, win_opendir) as SDL has new functions for this. We can also switch completely to SDL file IO, which supports Unicode (remove m_io).
  • More simplification to timer/delay code.

Issues that I found:

  • SDL chooses new "gpu" renderer by default, which is incomplete and does not work well on low end AMD hardware from testing. It will be "direct3d11"/"direct3d12" by default in the next release.
  • With "direct3d11" backend the exclusive fullscreen option doesn't work (already fixed in development version).

@fabiangreffrath
Copy link
Owner

@rfomin
Copy link
Collaborator Author

rfomin commented Jan 22, 2025

FYI SDL 3.2.0 is out:

Let's wait for vcpkg to update. By the way, Ubuntu and Homebrew don't have the SDL3 package, can we switch to vcpkg only?

@Pedro-Beirao
Copy link
Contributor

Brew should get sdl3 very soon Homebrew/homebrew-core#167079

@rfomin rfomin closed this Jan 23, 2025
@rfomin rfomin reopened this Jan 23, 2025
@rfomin
Copy link
Collaborator Author

rfomin commented Jan 23, 2025

@MrAlaux Could you please check if this version works better on your system?

@MrAlaux
Copy link
Collaborator

MrAlaux commented Jan 24, 2025

@MrAlaux Could you please check if this version works better on your system?

I compared the latest artifacts from master and this branch. 600p, VSync and DRS off, music volume set to 0, tried with exclusive fullscreen on and off.

Master, direct3d:
- Doom 2 Map01
  - Not exclusive - 121 fps
  - Exclusive ----- 154 fps
- Eviternity Map26
  - Not exclusive - 32 fps
  - Exclusive ----- 34 fps

The SDL3 build still selects direct3d11 as the default render driver, instead of direct3d like in master. For the latter tests I enforced it using the SDL_RENDER_DRIVER environment variable (I forgot about sdl_renderer_name). Toggling exclusive fullscreen appears to make no difference in performance.

SDL3, direct3d11
- Doom 2 Map01 ----- flickering between 50-60 fps
- Eviternity Map26 - 19 fps

SDL3, direct3d
- Doom 2 Map01 ----- 101 fps
- Eviternity Map26 - 29 fps

In short, master still performs better than this branch on my machine.

@rfomin
Copy link
Collaborator Author

rfomin commented Jan 24, 2025

In short, master still performs better than this branch on my machine.

Thanks for testing. Direct3D11 is slightly faster on my machine, strange.

@MrAlaux
Copy link
Collaborator

MrAlaux commented Jan 24, 2025

Direct3D11 is slightly faster on my machine, strange.

I assumed my performance loss with D3D11 was due to my machine being older than it, but a little research says that it was basically released alongside Win7, so I am confused. I should try forcing usage of the dedicated GPU again.

@MrAlaux
Copy link
Collaborator

MrAlaux commented Jan 24, 2025

I should try forcing usage of the dedicated GPU again.

I just did that, and performance is at best equal to that of the integrated GPU.

I'll only give results for Eviternity Map26 since I forgot to mention that with direct3d11, at least in the SDL3 build, my FPS seem to be capped to 60 regardless of VSync and FPS limit, so I can't accurately compare Doom 2 Map01.

Master, direct3d
- Eviternity Map26 - 25 fps

SDL3, direct3d11
- Eviternity Map26 - 19 fps, then 11 fps about 3 seconds later

SDL3, direct3d
- Eviternity Map26 - 23 fps

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.

5 participants