Skip to content

Commit

Permalink
asyncio: Added Linux io_uring support.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Dec 3, 2024
1 parent e79ce2a commit 022a6a9
Show file tree
Hide file tree
Showing 5 changed files with 540 additions and 1 deletion.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ set_option(SDL_SYSTEM_ICONV "Use iconv() from system-installed libraries"
set_option(SDL_LIBICONV "Prefer iconv() from libiconv, if available, over libc version" OFF)
set_option(SDL_GCC_ATOMICS "Use gcc builtin atomics" ${SDL_GCC_ATOMICS_DEFAULT})
dep_option(SDL_DBUS "Enable D-Bus support" ON "${UNIX_SYS}" OFF)
dep_option(SDL_LIBURING "Enable liburing support" ON "${UNIX_SYS}" OFF)
dep_option(SDL_DISKAUDIO "Support the disk writer audio driver" ON "SDL_AUDIO" OFF)
dep_option(SDL_DUMMYAUDIO "Support the dummy audio driver" ON "SDL_AUDIO" OFF)
dep_option(SDL_DUMMYVIDEO "Use dummy video driver" ON "SDL_VIDEO" OFF)
Expand Down Expand Up @@ -1657,6 +1658,16 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
set(SDL_USE_IME 1)
endif()

if(SDL_LIBURING)
pkg_search_module(LIBURING liburing-ffi)
find_path(HAVE_LIBURING_H NAMES liburing.h)
if(LIBURING_FOUND AND HAVE_LIBURING_H)
set(HAVE_LIBURING_LIBURING_H TRUE)
sdl_include_directories(PRIVATE SYSTEM ${LIBURING_INCLUDE_DIRS})
set(HAVE_LIBURING TRUE)
endif()
endif()

if((FREEBSD OR NETBSD) AND NOT HAVE_INOTIFY)
set(LibInotify_PKG_CONFIG_SPEC libinotify)
pkg_check_modules(PC_LIBINOTIFY IMPORTED_TARGET ${LibInotify_PKG_CONFIG_SPEC})
Expand Down Expand Up @@ -1720,6 +1731,10 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU)
endif()
endif()

if(HAVE_LIBURING_H)
sdl_sources("${SDL3_SOURCE_DIR}/src/file/io_uring/SDL_asyncio_liburing.c")
endif()

# Always compiled for Linux, unconditionally:
sdl_sources(
"${SDL3_SOURCE_DIR}/src/core/linux/SDL_evdev_capabilities.c"
Expand Down
4 changes: 3 additions & 1 deletion docs/README-linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Ubuntu 18.04, all available features enabled:
libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev \
libegl1-mesa-dev libdbus-1-dev libibus-1.0-dev libudev-dev fcitx-libs-dev

Ubuntu 22.04+ can also add `libpipewire-0.3-dev libwayland-dev libdecor-0-dev` to that command line.
Ubuntu 22.04+ can also add `libpipewire-0.3-dev libwayland-dev libdecor-0-dev liburing-dev` to that command line.

Fedora 35, all available features enabled:

Expand All @@ -34,6 +34,8 @@ Fedora 35, all available features enabled:
libdrm-devel mesa-libgbm-devel libusb-devel libdecor-devel \
pipewire-jack-audio-connection-kit-devel \

Fedora 39+ can also add `liburing-devel` to that command line.

NOTES:
- The sndio audio target is unavailable on Fedora (but probably not what you
should want to use anyhow).
Expand Down
1 change: 1 addition & 0 deletions include/build_config/SDL_build_config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
#cmakedefine HAVE_LINUX_INPUT_H 1
#cmakedefine HAVE_LIBUDEV_H 1
#cmakedefine HAVE_LIBDECOR_H 1
#cmakedefine HAVE_LIBURING_H 1

#cmakedefine HAVE_D3D11_H @HAVE_D3D11_H@
#cmakedefine HAVE_DDRAW_H @HAVE_DDRAW_H@
Expand Down
4 changes: 4 additions & 0 deletions src/file/SDL_sysasyncio.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
// is #defined to 0 instead and implement the SDL_SYS_* functions below in your
// backend (having them maybe call into the SDL_SYS_*_Generic versions as a
// fallback if the platform has functionality that isn't always available).
#ifdef HAVE_LIBURING_H
#define SDL_ASYNCIO_ONLY_HAVE_GENERIC 0
#else
#define SDL_ASYNCIO_ONLY_HAVE_GENERIC 1
#endif

// this entire thing is just juggling doubly-linked lists, so make some helper macros.
#define LINKED_LIST_DECLARE_FIELDS(type, prefix) \
Expand Down
Loading

0 comments on commit 022a6a9

Please sign in to comment.