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

SpriteBatch poor performance in 2D compared to MonoGame #428

Open
ryancheung opened this issue Apr 1, 2019 · 11 comments
Open

SpriteBatch poor performance in 2D compared to MonoGame #428

ryancheung opened this issue Apr 1, 2019 · 11 comments
Labels

Comments

@ryancheung
Copy link

@ryancheung ryancheung commented Apr 1, 2019

SpriteBatch poor performance in 2D compared to MonoGame.

I've got very poor 2d performance on SpriteBatch. Compared to MonoGame, my game only got ~500FPS, but in MonoGame, it can be ~700-800FPS.

And I found another performance issue:

If I do:
Sprite = new SpriteBatch(Device, 5000, 1000);

The FPS Drop nearly 40% percent. The default buffer element count is 1024, and batch capaticy is 64 when initializing SpriteBatch.

There should be some poor performance code in SpriteBatch internal array resizing.

@ryancheung

This comment has been minimized.

Copy link
Author

@ryancheung ryancheung commented Apr 1, 2019

My 2d game have lots of textures to draw(around 8000 triangles and 1000 draw-calls).
And I believe https://github.com/xenko3d/xenko/blob/master/sources/engine/Xenko.Graphics/BatchBase.cs#L408

is where the performance issue lied down. In the method, there are too many memory copy. And it's per-texture method-call.

@ryancheung ryancheung mentioned this issue Apr 1, 2019
0 of 7 tasks complete
@ryancheung

This comment has been minimized.

Copy link
Author

@ryancheung ryancheung commented Apr 1, 2019

cpu-profiler-xenko

According the cpu profile result:
Xenko.Graphics.CommandList.MapSubresource(GraphicsResource, Int32, MapMode, Boolean, Int32, Int32) is the most time-cost method, which calls
SharpDX.Direct3D11.DeviceContext.MapSubresource(Resource, Int32, MapMode, MapFlags, out DataBox)

https://github.com/xenko3d/xenko/blob/master/sources/engine/Xenko.Graphics/Direct3D/CommandList.Direct3D.cs#L712

@ryancheung

This comment has been minimized.

Copy link
Author

@ryancheung ryancheung commented Apr 1, 2019

cpu-profiler-xenko-2

@Kryptos-FR

This comment has been minimized.

Copy link
Collaborator

@Kryptos-FR Kryptos-FR commented Apr 2, 2019

Compared to MonoGame, my game only got ~500FPS, but in MonoGame, it can be ~700-800FPS.

That's not relevant. Anything higher than 120 FPS cannot be called "poor performance". There is no point of rendering the scene at a higher rate than the screen refresh rate. If you want a fair comparison, try a game where the framerate is close to that refresh rate.

Xenko and monogame makes different architecture and performance tradeoff decisions. Sure, the commandlist has some overhead but the point is to actually have better performance when it maters (i.e. when the FPS would normally drop much lower). I can write a fixed-pipeline that only clears the screen and has 1000+ FPS, but it doesn't make that "engine" any better.

To be clear, I'm not saying there is nothing wrong or that could be improved in Xenko just that your test case and comparison is not a good one.

@Eideren

This comment has been minimized.

Copy link
Collaborator

@Eideren Eideren commented Apr 2, 2019

@ryancheung included more context on discord, here's an excerpt that seems more relevant:
"I tested a FPS drop heavely case. In game, I cast a lot of firewall(4x4 cell) effects in ground, which means generating a lot of animated sprites, and FPS drops speedly from ~450 to ~20 [...] In MonoGame, FPS can drop from 800 to ~100"[sic]

It would be nice if you could create a repro' or include more info regarding the 20 fps case.

@ryancheung

This comment has been minimized.

Copy link
Author

@ryancheung ryancheung commented Apr 3, 2019

In local single player test, FPS can drops from 520 to 40. Until it goes below 30~, the FPS are acceptable.

I'll update the report if the game FPS drops to ~20 in a heavy-load case. Let's just keep this open for now.

And after some time in future. I'll test the game in Mobile and see the performance.

@ryancheung

This comment has been minimized.

Copy link
Author

@ryancheung ryancheung commented Apr 8, 2019

Just had another performance test and it shows how FPS drops in Xenko to below 30:

  1. Blank case and FPS ~300 in Xenko.
    xenko-2

  2. FPS drops to 27 in Xeko.
    Xenko

  3. FPS drops to 52 in MonoGame
    MonoGame

So, I believe Xenko has some more performance refinement in Sprite Batching.

@xen2

xen2 added a commit that referenced this issue Apr 9, 2019
@ryancheung

This comment has been minimized.

Copy link
Author

@ryancheung ryancheung commented Apr 9, 2019

@xen2 Thanks for the memory leak fix and I’ll test it if the fix also improving performance. Thank you for your work!

@xen2

This comment has been minimized.

Copy link
Member

@xen2 xen2 commented Apr 9, 2019

@ryancheung thanks, keep me posted!

@ryancheung

This comment has been minimized.

Copy link
Author

@ryancheung ryancheung commented Apr 9, 2019

@xen2 The memory leak bug is actually fixed. But it seems not improving the performance.

@Kryptos-FR

This comment has been minimized.

Copy link
Collaborator

@Kryptos-FR Kryptos-FR commented Apr 9, 2019

Depends on how you use sprites and how many of them. Without a repro project, posting image rendering is not going to help solve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.