Vulkan-glTF-PBR icon indicating copy to clipboard operation
Vulkan-glTF-PBR copied to clipboard

`getMatrix` become too slow when the scene contains deeper node hierarchies.

Open syoyo opened this issue 4 years ago • 3 comments

https://github.com/SaschaWillems/Vulkan-glTF-PBR/blob/08cf10dcd7609fa6f7d43b4e79ecca7431d09937/base/VulkanglTFModel.hpp#L511

getMatrix always loop over parent matrices until it reaches the root.

This become quite slow when the scene contains deeper node hierarchies(e.g. 100. such a deeper hierarchies would happen in character skeletons). For example, I get 120 fps(without getMatrix) -> 7 fps(with getMatrix) slowdown on Threadripper 1950X for a glTF model containing roughly 300 nodes.

The solution is obvious. Cache the node's matrix once after updating the matrix of each nodes. Probably we are better to add updateNodeMatrices() API before calling node->update()(If this change is OK, I can send a PR)

syoyo avatar Feb 28 '20 12:02 syoyo

That's true. It's especially evident in debug mode, where some scenes run extremely slow even on my 3rd Gen Ryzen CPU. I'll take a look at matrix caching, and maybe try to add some parallelism to improve performance.

SaschaWillems avatar Feb 29 '20 09:02 SaschaWillems

I'll take a look at matrix caching

Thanks! For example, adding global_transform_matrix to Node, then compute it from the root node should work well.

  void updateGlobalTransformMatrix(glm::mat4 parentMatrix) {
    global_transform_matrix = parentMatrix * localMatrix();
    for (auto &child : children) {
      child->updateGlobalTransformMatrix(global_transform_matrix);
    }
  }

syoyo avatar Feb 29 '20 11:02 syoyo

thankyou you are good

questgugou avatar Dec 29 '22 09:12 questgugou

I added a very basic "caching" algorithm to limit the number of matrix calculations per animation step. While very simple, this greatly improved performance on my side, esp. when running debug with MSVC.

SaschaWillems avatar May 04 '24 19:05 SaschaWillems

Thanks!

a glTF model containing roughly 300 nodes.

I don't have this glTF model to reproduce the issue anymore, but I think the "caching" fix https://github.com/SaschaWillems/Vulkan-glTF-PBR/commit/2ac4de59e1f9957595270733422fa4f79ee2972c should work well, so closing the issue.

syoyo avatar May 05 '24 01:05 syoyo