| Summary: | SDL_RENDERER_ACCELERATED makes application run extremely slow compared to 2.0.9 | ||
|---|---|---|---|
| Product: | SDL | Reporter: | mrsamsh |
| Component: | render | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | major | ||
| Priority: | P2 | CC: | amaranth72 |
| Version: | 2.0.10 | ||
| Hardware: | x86_64 | ||
| OS: | macOS 10.14 | ||
| Attachments: | the GameOfLife simulator code | ||
|
Description
mrsamsh
2019-08-15 10:42:23 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. I tried setting render hint to force OpenGL driver, I got the same result. And my program uses SDL_RenderFillRect intensively, but nothing more. 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);
}
}
}
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. (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! 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. Created attachment 3926 [details]
the GameOfLife simulator code
(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 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. (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 :) Yes, the latest branch fixes the flashing, and yes it is still slower than OpenGL backend. |