Before proceeding with the implementation of tiled deferred rendering on point and spot lights, I wanted to clean the code for directional light as much as possible. I also wanted to write from scratch the memory solution used to hold uniforms in a material, because of a leaking problem and bad performance.
First, I tackled the uniform problem. I was still using a map to hold the data, with a flawed solution to account for the different size of uniforms. I used a different system instead, which allocates a chunk of memory, and stores the uniforms at different addresses. This is not leaking memory, it is faster and helps cache coherence.
I also had to rewrite the compare_uniforms function used for sorting, in order to account for the changes. It became much simpler, and the speed up is incredible. I tested the sorting time of 10000 objects with the old and the new system, and from ~9 ms the time dropped at ~0.9 ms.
In the afternoon I decided to make the compute / non-compute techniques even more similar. Instead of sending uniforms to the light shader, I replaced them with an UBO. This is more efficient, makes the code much simpler, and reuses the same structure used by the compute shader (with the difference that the latter takes an array of lights).
With this optimization the code for directional lights has become short, readable and simple, despite the fact that it's supporting both deferred and tiled deferred shading. Tomorrow I'll mimic the same behavior for point and spot lights, and once that is done, I'll start to work on culling.
Nessun commento:
Posta un commento