-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Implement IPC API and Posix implementation #14521
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
Draft
TheMadman
wants to merge
3
commits into
libsdl-org:main
Choose a base branch
from
TheMadman:sdl-ipc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of these functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make more sense to get the IPC channel as a
SDL_IOStreampointer property, like the library currently does for stdio?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interface I planned was to have
SDL_Shared{Surface,Texture}types that would implementSDL_SendShared{Surface,Texture}(SDL_IPC *)functions. These getters just allow the programmer to get the IPC pointer they want to send to.This allows us to use the same interface for both
SDL_Processobjects created withSDL_CreateProcess()and for children that want to send something up to their parent, where there is no obviousSDL_Processobject.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels very much like platform specific behavior that's outside the scope of SDL. I'm not opposed to considering it, but you'd need to make a very good use case why this should be in SDL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be out-of-scope, I understand using SDL for multi-process stuff is already probably a niche use-case.
When I was considering writing this for my specific application, I had a rough idea of how to implement it for both Windows and Linux, and intended to also implement it in MacOS in the future, since all these OSes support both shared memory handles and shared GPU memory resources, but they all handle it slightly differently.
Since I was hoping to write a single API that opaquely abstracted away the differences, then attempt to pack the shared memory into
SDL_Surfaceobjects and shared GPU memory intoSDL_Textureobjects, and implement cross-process read/write locking of these resources, to me it made sense to implement this in SDL.Doing it on the application side is difficult, since instead of just e.g. creating a heap allocation with malloc, on the Posix side we would be using
shm_*andmmapto get the pointer, then doing everything that is in the staticSDL_InitializeSurface()function. Copy/pasting that function from SDL into the application seems brittle by comparison to me, and while another alternative is to copy from shared memory into a normalSDL_Surfaceobject... I mean, I already have the data in memory, I'd prefer to just wrap it.I haven't even considered how I would handle
SDL_Textures across processes on the application side. From inside the renderer implementation, calling the necessary Mesa functions to get the dma-buf file descriptor and additional data for object construction seems trivial by comparison.But, I don't want to add more maintenance overhead to the library if the feature doesn't seem that valuable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, it probably makes sense to flesh it out in your application and then either provide it as an example for others or develop it into a future PR.
I'll go ahead and leave this open and feel free to update it when you're ready.