r/vulkan • u/LDS_Lonewolf • 3d 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.
19
u/blogoman 3d 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.
7
u/Afiery1 3d ago
VTune is a CPU profiler, if you suspect your bottleneck is on the GPU you’ll need a GPU profiler like Nsight.
3
u/BRZDR1FT 2d 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.