SaschaWillems/Vulkan-glTF-PBR

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

syoyo opened this issue · 5 comments

syoyo commented

glm::mat4 getMatrix() {

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)

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.

syoyo commented

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);
    }
  }

thankyou you are good

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.

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 2ac4de5 should work well, so closing the issue.