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

Add SDL_CreateTexture from some shared texture #9823

Closed
1bsyl opened this issue May 17, 2024 · 5 comments
Closed

Add SDL_CreateTexture from some shared texture #9823

1bsyl opened this issue May 17, 2024 · 5 comments

Comments

@1bsyl
Copy link
Contributor

1bsyl commented May 17, 2024

There was this feature for the camera API, where the device can provide an handle to manipulate texture with 0-copy, which must faster that getting a software surface (#8565 ).

Same way we grab a software frame with
SDL_Surface * SDL_AcquireCameraFrame(...);,
we could introduce a new type (ok whatever), SDL_0CopyTexturem and have a similar API:
SDL_0CopyTexture * SDL_AcquireCamera0CopyFrame(...)

we would also need the correct helper functions
SDL_Create0CopyTextureFrom() .. (does this has to be from something here ?)
SDL_UpdateTextureFrom0Copy()

The use-case here the camera api, but I thing this can more generic purpose.

@slouken
Copy link
Collaborator

slouken commented May 17, 2024

0-copy textures are created using properties to specify the platform specific details. I'm not sure how this integrates into the camera system, but you can see an example of this in testffmpeg.

@1bsyl
Copy link
Contributor Author

1bsyl commented May 17, 2024

SDL_Create0CopyTexture() could hide all those platform specific details.

Looking at testffmpeg:

GetTextureForMemoryFrame is the usual way:
call SDL_CreateTexture() once and then SDL_UpdateTexture(), sending the new software buffer for each new memory frame.

but GetOESTextureForDRMFrame recreates the SDL_Texture each time and update it from the fd handle.
it could be splitted the same way: Create0CopyTexture once(), then and Update0CopyFromHande()
(this handle is dmabuf for v4l2 or clientbuffer in android, anyway something to hide)

the update part:
https://github.com/libsdl-org/SDL/blob/main/test/testffmpeg.c#L840
is similar to the camera 0copy:
https://github.com/libsdl-org/SDL/pull/8565/files#diff-a9717185365da787cba4e3193430078ff78313a64f1898ca7f66d1f18153f28eR323

It seems this could be factorized.

but maybe 0 copy texture need to much customization and not obvious to abstract it. And maybe re-creating the texture isn´t a big deal.

Since the use-case I thought was the camera API, maybe it can simply turned into adding a SDL_Texture * SDL_AcquireCameraFrame(SDL_Renderer *, ...); that would create a 0copy texture and avoid the software copies.

@1bsyl
Copy link
Contributor Author

1bsyl commented May 17, 2024

so if creating a re-creating 0copy texture each frame isn't a big deal. (vs only updating a 0copy texture, each frame), then this is ok. and I´ve clarified what I thought so closing this ticked, and re-opened a new one for the camera with the suggestion !

@1bsyl 1bsyl closed this as completed May 17, 2024
@1bsyl 1bsyl reopened this May 17, 2024
@1bsyl
Copy link
Contributor Author

1bsyl commented May 17, 2024

one more guess:
if we ever add SDL_Texture * SDL_AcquireCameraFrame(SDL_Renderer *, ...)
can the camera backend buffer enough SDL_0CopyTextures ??
or really, should it queue some 0CopyHandle instead ?

@slouken
Copy link
Collaborator

slouken commented May 22, 2024

Duplicate of #9826

@slouken slouken marked this as a duplicate of #9826 May 22, 2024
@slouken slouken closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2024
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

No branches or pull requests

2 participants