sdl-gpu
sdl-gpu copied to clipboard
UpdateImage is very slow at updating a small region from an incompatible SDL_Surface
If UpdateImage needs to convert the format of the source pixels, it converts the entire source surface in copySurfaceIfNeeded.
My usecase involves copying thousands of individual 32x32 regions from a very large (512x6000 or larger) source surface to build an atlas image at startup. With the current code, that ends up converting the whole 512x6000 surface thousands of times and is intolerably slow.
What platform and GPU are you using? Do you have any thoughts on how to improve this?
One possibility is to add a function that does the conversion explicitly and returns the result. That way, you can continually upload the converted surface instead of the original. This would be very similar to how SDL_DisplayFormat() was used in SDL 1.2.
It was a 3rd party report on macOS, I don't know the GPU used.
Here's the workaround I ended up using: https://github.com/mutability/Cataclysm-DDA/commit/85dc4399d4b0ce727978928c117d8a297acd1f3a
(tl;dr: create a new SDL_Surface that shares storage but has a different pixel start / width / height)
Original report is here: https://github.com/CleverRaven/Cataclysm-DDA/pull/19412#issuecomment-263537985
Does it sound like my suggestion would be helpful here?
Traveling so sorry for the brevity
Something to get the desired format for an image would be potentially useful elsewhere. For my particular case doing it piece by piece is OK. I can do a PR that integrates workaround if you like?
It could be potentially good for improved atlas support, but I'm not sure yet whether it fits the goals of SDL_gpu. I'll have to think more about other cases.