We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4764 - SDL_RENDERER_ACCELERATED makes application run extremely slow compared to 2.0.9
Summary: SDL_RENDERER_ACCELERATED makes application run extremely slow compared to 2.0.9
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: 2.0.10
Hardware: x86_64 macOS 10.14
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-15 10:42 UTC by mrsamsh
Modified: 2019-08-18 15:37 UTC (History)
1 user (show)

See Also:


Attachments
the GameOfLife simulator code (14.45 KB, text/x-csrc)
2019-08-18 08:24 UTC, mrsamsh
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mrsamsh 2019-08-15 10:42:23 UTC
After upgrading too SDL2.0.10, I noticed that a program that I wrote (Game of life simulator) was running very slow, I recompiled and got the same slow result. When I chose SDL_RENDERER_SOFTWARE instead it ran ok, although I lost the HIDPI features. I tried the same program with 2.0.9 and it worked fine.
Comment 1 Alex Szpakowski 2019-08-15 18:52:24 UTC
SDL_Render defaults to a Metal backend on macOS, starting with SDL 2.0.10. If you choose the OpenGL backend instead, does it run fast again?

What sort of SDL_Render functions does your simulator call? SDL_UpdateTexture? Lock/UnlockTexture? The latter might be a lot faster than the former when Metal is used, right now.
Comment 2 mrsamsh 2019-08-15 22:51:39 UTC
I tried setting render hint to force OpenGL driver, I got the same result. And my program uses SDL_RenderFillRect intensively, but nothing more.
Comment 3 mrsamsh 2019-08-15 22:55:06 UTC
this is my draw call

void draw(SDL_Renderer* renderer)
{
	for (int i = 0; i < current.size(); ++i) {
		int x = (i % GRID_WIDTH) * SIDE + 1;
		int y = (i / GRID_WIDTH) * SIDE + 1;
		SDL_Rect r  = { x, y, SIDE - 1, SIDE - 1 };
		
		if (current[i].f != 0) {
			SDL_SetRenderDrawColor(renderer, 0x01 * current[i].f / 2, 0x01 * current[i].f / 2, 0x02 * current[i].f, 0xff);
			SDL_RenderFillRect(renderer, &r);
		} else if (current[i].v != 0) {
			SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, 0xff);
			SDL_RenderFillRect(renderer, &r);
		}
	}
}
Comment 4 Alex Szpakowski 2019-08-17 03:45:02 UTC
Thanks for the code snippet! I've improved performance in that scenario a lot with https://hg.libsdl.org/SDL/rev/ecad0a0684ad - if you're up for compiling SDL yourself you can give it a shot if you want.
Comment 5 mrsamsh 2019-08-17 11:37:17 UTC
(In reply to Alex Szpakowski from comment #4)
> Thanks for the code snippet! I've improved performance in that scenario a
> lot with https://hg.libsdl.org/SDL/rev/ecad0a0684ad - if you're up for
> compiling SDL yourself you can give it a shot if you want.

I did compile SDL and it has improved a lot, at least now the program runs. Anyway, I did a comparison with 2.0.9 and the older version (which I understood uses OpenGL in the backend) still runs faster. Out of curiosity, I ran the same code on the Linux installed on the same computer, and 2.0.10 worked perfectly fine.

Thank you!
Comment 6 Alex Szpakowski 2019-08-18 01:30:58 UTC
As of https://hg.libsdl.org/SDL/rev/5d1997d1ae30 , the test I'm using (just a loop of SDL_SetRenderDrawColor + SDL_RenderFillRect) now runs faster with the latest code than with SDL 2.0.9. Hopefully it's faster for you as well.
Comment 7 mrsamsh 2019-08-18 08:24:19 UTC
Created attachment 3926 [details]
the GameOfLife simulator code
Comment 8 mrsamsh 2019-08-18 08:26:38 UTC
(In reply to Alex Szpakowski from comment #6)
> As of https://hg.libsdl.org/SDL/rev/5d1997d1ae30 , the test I'm using (just
> a loop of SDL_SetRenderDrawColor + SDL_RenderFillRect) now runs faster with
> the latest code than with SDL 2.0.9. Hopefully it's faster for you as well.

The latest branch is faster but behave really weirdly. Alive cells should be drawn white, and dead cells be drawn blue and fade away gradually. With the current branch you mentioned everything is drawn blue and sometimes everything flashes white.

I attached the code I am using so you can test it
Comment 9 Alex Szpakowski 2019-08-18 13:44:17 UTC
Sorry about that, I put in a fix for that (which also slows down SDL_RenderFillRect a little bit again).

If you want to make your game of life sim run fast, I think the best route would be to reduce the number of FillRect calls - right now it draws over 230,000 rectangles individually every frame. I think you could use SDL_RenderFillRects to draw an array of ones which share the same color, and/or use images instead of collections of rectangles.
Comment 10 mrsamsh 2019-08-18 15:30:44 UTC
(In reply to Alex Szpakowski from comment #9)
> Sorry about that, I put in a fix for that (which also slows down
> SDL_RenderFillRect a little bit again).
> 
> If you want to make your game of life sim run fast, I think the best route
> would be to reduce the number of FillRect calls - right now it draws over
> 230,000 rectangles individually every frame. I think you could use
> SDL_RenderFillRects to draw an array of ones which share the same color,
> and/or use images instead of collections of rectangles.

I know that my code is not that optimized, thanks for your suggestions :)
Comment 11 mrsamsh 2019-08-18 15:37:57 UTC
Yes, the latest branch fixes the flashing, and yes it is still slower than OpenGL backend.