satchelfrost / revolvr

A VR-focused Game Engine
MIT License
9 stars 1 forks source link

Gfx perf bug #49

Closed satchelfrost closed 11 months ago

satchelfrost commented 11 months ago

Finally fixed the graphics performance bug issue. Before when using uniform buffers, only one global uniform buffer could be used at a time, and at the end of the render pass (SwapchainImageContext::EndRenderPass()), the command buffer had to block on the CPU to avoid race conditions. In other words, to avoid having the CPU writing to a uniform buffer while that same buffer was being read/processed by the GPU. The issue was solved by allowing multiple uniform buffers each corresponding to only one command buffer. The issue was complicated by the fact that there are two instances of SwapchainImageContext (one per eye) since we are in VR.

An instance of SwapchainImageContext has MAX_FRAMES_IN_FLIGHT command buffers (note there may be more images in each swapchain, but this is the max that can be processed asynchronously by the GPU). Since there are two instances of SwapchainContext, this effectively totals to MAX_FRAMES_IN_FLIGHT * 2: command buffers, uniform buffers, and descriptor sets (though uniform buffers, and descriptor sets are kept in VulkanContext). In the end however, the result is that there is only one uniform buffer per frame in flight.

When testing the point cloud example the FPS was 48 without the fix and 60 with, for a ~10 FPS improvement! Note: that the point cloud is slow mostly because of the massive amount of vertices, but it makes for a good performance test.