sdl-gpu icon indicating copy to clipboard operation
sdl-gpu copied to clipboard

UpdateImage is very slow at updating a small region from an incompatible SDL_Surface

Open mutability opened this issue 7 years ago • 6 comments

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.

mutability avatar Nov 29 '16 13:11 mutability

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.

grimfang4 avatar Nov 29 '16 13:11 grimfang4

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)

mutability avatar Nov 29 '16 15:11 mutability

Original report is here: https://github.com/CleverRaven/Cataclysm-DDA/pull/19412#issuecomment-263537985

mutability avatar Nov 29 '16 15:11 mutability

Does it sound like my suggestion would be helpful here?

grimfang4 avatar Dec 06 '16 03:12 grimfang4

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?

mutability avatar Dec 07 '16 11:12 mutability

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.

grimfang4 avatar Dec 07 '16 13:12 grimfang4