Webgpu webgpuCacheRenderPipelineTree _getRenderPipeline

why _nodeStack next nodeState from privious’s values?
but nn is from this._states[i],assign the state node corresponding to the state value with ID “i” to the next value in the “_nodeStack” array.

_nodeStack[0] is filled with the cache root node (see line 62), that’s why we shift by one.

there is an offset between _states and ‘_nodeStack’

Yes, _states and _nodeStack are not the same thing.

It works like this:

  • _nodeStack[0] is the root of the cache. We query its values _nodeStack[0].values with the first state _states[0]: node0 = _nodeStack[0].values[_states[0]]
  • we set _nodeStack[1] with the node corresponding to state 0: _nodeStack[1] = node0
  • we query the value of _nodeStack[1] with the second state states[1]: node1 = _nodeStack[1].values[_states[1]]
  • we set _nodeStack[2] with the node corresponding to state 1: _nodeStack[2] = node1
  • and so on

So, you can see that there’s an offset between indexing _nodeStack and _states because of the first node of _nodeStack being the cache root node.

1 Like