webgpuCacheRenderPipelineTree.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { WebGPUCacheRenderPipeline } from "./webgpuCacheRenderPipeline.js";
  2. /** @internal */
  3. class NodeState {
  4. constructor() {
  5. this.values = {};
  6. }
  7. count() {
  8. let countNode = 0, countPipeline = this.pipeline ? 1 : 0;
  9. for (const value in this.values) {
  10. const node = this.values[value];
  11. const [childCountNodes, childCoundPipeline] = node.count();
  12. countNode += childCountNodes;
  13. countPipeline += childCoundPipeline;
  14. countNode++;
  15. }
  16. return [countNode, countPipeline];
  17. }
  18. }
  19. /** @internal */
  20. export class WebGPUCacheRenderPipelineTree extends WebGPUCacheRenderPipeline {
  21. static GetNodeCounts() {
  22. const counts = WebGPUCacheRenderPipelineTree._Cache.count();
  23. return { nodeCount: counts[0], pipelineCount: counts[1] };
  24. }
  25. static _GetPipelines(node, pipelines, curPath, curPathLen) {
  26. if (node.pipeline) {
  27. const path = curPath.slice();
  28. path.length = curPathLen;
  29. pipelines.push(path);
  30. }
  31. for (const value in node.values) {
  32. const nnode = node.values[value];
  33. curPath[curPathLen] = parseInt(value);
  34. WebGPUCacheRenderPipelineTree._GetPipelines(nnode, pipelines, curPath, curPathLen + 1);
  35. }
  36. }
  37. static GetPipelines() {
  38. const pipelines = [];
  39. WebGPUCacheRenderPipelineTree._GetPipelines(WebGPUCacheRenderPipelineTree._Cache, pipelines, [], 0);
  40. return pipelines;
  41. }
  42. static ResetCache() {
  43. WebGPUCacheRenderPipelineTree._Cache = new NodeState();
  44. }
  45. reset() {
  46. this._nodeStack = [];
  47. this._nodeStack[0] = WebGPUCacheRenderPipelineTree._Cache;
  48. super.reset();
  49. }
  50. _getRenderPipeline(param) {
  51. let node = this._nodeStack[this._stateDirtyLowestIndex];
  52. for (let i = this._stateDirtyLowestIndex; i < this._statesLength; ++i) {
  53. let nn = node.values[this._states[i]];
  54. if (!nn) {
  55. nn = new NodeState();
  56. node.values[this._states[i]] = nn;
  57. }
  58. node = nn;
  59. this._nodeStack[i + 1] = node;
  60. }
  61. param.token = node;
  62. param.pipeline = node.pipeline;
  63. }
  64. _setRenderPipeline(param) {
  65. param.token.pipeline = param.pipeline;
  66. }
  67. }
  68. WebGPUCacheRenderPipelineTree._Cache = new NodeState();
  69. //# sourceMappingURL=webgpuCacheRenderPipelineTree.js.map