r/vulkan • • 12d ago

Issue in Vulkan Rendering for 1M objects in C++

I have been following the Introduction - Vulkan Tutorial couples of times and this time i was doing something a bit different. I have create this Lonewolf30/CityFoundingSimulator but currently with 1M objects i seem to have an issue in only getting 4 FPS, as far as i can narrow it down i seem to have an issue in the vulkan rendering sequence but i cant seem to profile using VTune as to where the slowdown is, can somebody please point me in the right direction of what i am doing wrong.

If there are any other code suggestions play let me know so i can implement them.

I have been working on this project for a while on and off, no AI was used in the creation of the rendering system, the only part i used AI in was for help with the TerrainChunkRenderer::OptimiseMeshData() algorithm.

8 Upvotes

10 comments sorted by

19

u/blogoman 12d ago

I only glanced at your code, but I assume each "object" is being drawn by its own "render_component".

Doing a million calls into the various vkCmd* commands is going to be slow.

Also, as a note, I'm not sure what your strategy with all of the locks on weak_ptrs is, but it is probably not what you want. When you have a weak_ptr, the thing it points to can go away. You use lock(), but never check its results. It can be a null shared_ptr! That is what happens if the thing the weak_ptr points to goes away. If you know it isn't going away, why are you using a weak_ptr? Every lock has an overhead. If it is what you want, you should be locking it once at the beginning of scope, making sure it is still alive, and then holding onto it until you are done with it.

-4

u/LDS_Lonewolf 12d ago

The million render components exist but only the master is actually used, the million are instances rendered and confirmed with RenderDoc only ever one draw call is called.

Used weak_ptr instead of parsing raw ptr's around, will probably need to do validity checks at some point.

6

u/blogoman 12d ago

There is also the basic issue of 1million components. How many triangles are you trying to push, and on what hardware?

7

u/Afiery1 12d ago

VTune is a CPU profiler, if you suspect your bottleneck is on the GPU you’ll need a GPU profiler like Nsight.

1

u/roguethreat 9d ago

The GPU is being given far too much geometry (~3.8 billion triangles per frame). There's no frustum culling and no LOD, so you're rendering stuff behind the camera and full objects even if there are only a few pixels on your screen. VTune will only show you GPU data if you have an Intel GPU. Try Nsight or Radeon GPU Profiler or RenderDoc to see what's going on.

1

u/LDS_Lonewolf 9d ago

Have tried RenderDoc, to see draw calls and all i can see is the one draw call, but as you have stated it could be the shear amount of work the gpu is doing to will look into compute based frustum culling for my draw calls.

1

u/roguethreat 9d ago

Frustum culling likely isn't your biggest win. Let's say that cuts your geometry to 1/4, that's still ~1 billion triangles per frame. LOD is likely the bigger bang for your buck, but you should still do both.

As for RenderDoc, yes, you'll only have 1 draw call since all of the objects are drawn as instances of a single mesh. The main thing you'd see in RenderDoc is the time spent on that draw call to confirm the time is spent on all of those instances.

1

u/LDS_Lonewolf 9d ago

Thanks for the heads up, will try combine the 2 into a single compute shader, will check what RenderDoc says is the time is.

1

u/LDS_Lonewolf 8d ago

Check RenderDoc time was 740ms for draw call.

3

u/BRZDR1FT 12d ago

You really have no idea what you are doing with shared/weak_ptr. Just stick to unique_ptr and pass non owning references and raw pointers when needed.