Repository navigation
Improve instance batching. - #125808
Improve instance batching.#125808blueskythlikesclouds wants to merge 1 commit into
Conversation
|
For the depth layer to be beneficial it needs to be in the most significant position possible. Think of it this way, we want all objects that are up close to the viewer to be drawn before all objects that are far from the viewer. Otherwise we won't benefit from the depth sorting at all. |
|
Damnit, I have only just started benchmarking stuff. You beat me to it by like a day or two.
Not sure I agree. depth layer is a 16 bit quantization, so in most scene everything ends up in layer 0. It honestly doesn't do much that isn't also done by 'lod index' (which in a way also encodes depth information). I think some kind of occlusion culling will do more for performance than the current depth layer sorting. Oh wait, directional light cascades! Their old is based on the scene camera, while depth layer is based on the actual cascade. More importantly, it uses the cascades far and near distance, so it should make better use of the 16 bits.
That's honestly a lot less improvement than I expected. Maybe the TPS demo has a lot of unique meshes or materials? |
|
I tried bringing depth layer to the front in TPS Demo and the amount of Vulkan calls jumped to 28K, and in the MRP they all don't merge perfectly, though the amount of calls is still much lower than upstream. So I guess we should see which tradeoff we want, depth sorting or less draw calls. I'll do some profiling on my device. |
|
Hmmm. I am working on HiZ culling, which might change the math a fair bit. If culling already removes many of the occluded instances depth sorting becomes a lot less important. Should I push my current wip branch when I am back from lunch so that you can take a look at it Skyth? Be warned, it's fairly messy. |
|
HiZ culling would only help with the opaque pass, shadow passes don't use that, so depth sorting would still be beneficial there. |
|
Did some tests in TPS Demo. I spawned a bunch of omni lights in player view and forced them to update every frame. Here are the numbers: Upstream:
This PR:
This PR with depth layer more important in the sort key:
I feel like it'd be possible to get a balance of both by sorting surfaces by depth anyway but having identical surfaces next to each other so they still end up getting merged. I'm gonna experiment with this. |
What problem(s) does this PR solve?
The Forward+ renderer compares sort keys to determine whether surfaces are identical, and can be batched into a single draw call. This comparison also included the
depth_layerandpriorityvalues, which do not actually matter for equivalency and are only used for sorting. To improve this, we set both values to 0 before comparing, allowing identical surfaces to be batched together.I also moved
depth_layerto the least significant position in the sort key. The intention behind this value seems to be for sorting identical surfaces from front to back for early Z culling. However, since it previously had higher priority thanlod_index, draw calls could constantly alternate between different LOD levels. By making it the least significant value, all LOD levels in the MRP now merge into a single draw call for each respective LOD level.In TPS Demo, this also reduced the number of Vulkan calls from 22K to 18K.
Additional information
N/A.