|
|
@@ -8,7 +8,7 @@ import ParameterNode from './ParameterNode.js';
|
|
|
import StructType from './StructType.js';
|
|
|
import FunctionNode from '../code/FunctionNode.js';
|
|
|
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
|
|
|
-import { getDataFromObject, getTypeFromLength } from './NodeUtils.js';
|
|
|
+import { getDataFromObject, getTypeFromLength, hashString } from './NodeUtils.js';
|
|
|
import { NodeUpdateType, defaultBuildStages, shaderStages } from './constants.js';
|
|
|
|
|
|
import {
|
|
|
@@ -20,7 +20,6 @@ import { stack } from './StackNode.js';
|
|
|
import { getCurrentStack, setCurrentStack } from '../tsl/TSLBase.js';
|
|
|
|
|
|
import CubeRenderTarget from '../../renderers/common/CubeRenderTarget.js';
|
|
|
-import ChainMap from '../../renderers/common/ChainMap.js';
|
|
|
|
|
|
import BindGroup from '../../renderers/common/BindGroup.js';
|
|
|
|
|
|
@@ -35,9 +34,9 @@ import { warn, error } from '../../utils.js';
|
|
|
|
|
|
let _id = 0;
|
|
|
|
|
|
-const sharedNodeData = new WeakMap();
|
|
|
+const _bindingGroupsCache = new WeakMap();
|
|
|
|
|
|
-const rendererCache = new WeakMap();
|
|
|
+const sharedNodeData = new WeakMap();
|
|
|
|
|
|
const typeFromArray = new Map( [
|
|
|
[ Int8Array, 'int' ],
|
|
|
@@ -491,27 +490,6 @@ class NodeBuilder {
|
|
|
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Returns the bind groups of the current renderer.
|
|
|
- *
|
|
|
- * @return {ChainMap} The cache.
|
|
|
- */
|
|
|
- getBindGroupsCache() {
|
|
|
-
|
|
|
- let bindGroupsCache = rendererCache.get( this.renderer );
|
|
|
-
|
|
|
- if ( bindGroupsCache === undefined ) {
|
|
|
-
|
|
|
- bindGroupsCache = new ChainMap();
|
|
|
-
|
|
|
- rendererCache.set( this.renderer, bindGroupsCache );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return bindGroupsCache;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Factory method for creating an instance of {@link RenderTarget} with the given
|
|
|
* dimensions and options.
|
|
|
@@ -572,19 +550,21 @@ class NodeBuilder {
|
|
|
*/
|
|
|
_getBindGroup( groupName, bindings ) {
|
|
|
|
|
|
- const bindGroupsCache = this.getBindGroupsCache();
|
|
|
+ const groupNode = bindings[ 0 ].groupNode;
|
|
|
|
|
|
- //
|
|
|
+ let sharedGroup = groupNode.shared;
|
|
|
|
|
|
- const bindingsArray = [];
|
|
|
+ if ( sharedGroup ) {
|
|
|
|
|
|
- let sharedGroup = true;
|
|
|
+ for ( let i = 1; i < bindings.length; i ++ ) {
|
|
|
|
|
|
- for ( const binding of bindings ) {
|
|
|
+ if ( groupNode !== bindings[ i ].groupNode ) {
|
|
|
|
|
|
- bindingsArray.push( binding );
|
|
|
+ sharedGroup = false;
|
|
|
|
|
|
- sharedGroup = sharedGroup && binding.groupNode.shared;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -594,19 +574,67 @@ class NodeBuilder {
|
|
|
|
|
|
if ( sharedGroup ) {
|
|
|
|
|
|
- bindGroup = bindGroupsCache.get( bindingsArray );
|
|
|
+ let cacheKeyString = '';
|
|
|
+
|
|
|
+ for ( const binding of bindings ) {
|
|
|
+
|
|
|
+ if ( binding.isNodeUniformsGroup ) {
|
|
|
+
|
|
|
+ binding.uniforms.sort( ( a, b ) => a.nodeUniform.node.id - b.nodeUniform.node.id );
|
|
|
+
|
|
|
+ for ( const uniform of binding.uniforms ) {
|
|
|
+
|
|
|
+ cacheKeyString += uniform.nodeUniform.node.id;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ cacheKeyString += binding.nodeUniform.id;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: Remove this hack ._currentRenderContext
|
|
|
+
|
|
|
+ const currentContext = this.renderer._currentRenderContext || this.renderer; // use renderer as fallback until we have a compute context
|
|
|
+
|
|
|
+ let bindingGroupsCache = _bindingGroupsCache.get( currentContext );
|
|
|
+
|
|
|
+ if ( bindingGroupsCache === undefined ) {
|
|
|
+
|
|
|
+ bindingGroupsCache = new Map();
|
|
|
+
|
|
|
+ _bindingGroupsCache.set( currentContext, bindingGroupsCache );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+
|
|
|
+ const cacheKey = hashString( cacheKeyString );
|
|
|
+
|
|
|
+ bindGroup = bindingGroupsCache.get( cacheKey );
|
|
|
|
|
|
if ( bindGroup === undefined ) {
|
|
|
|
|
|
- bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group );
|
|
|
+ bindGroup = new BindGroup( groupName, bindings, this.bindingsIndexes[ groupName ].group );
|
|
|
|
|
|
- bindGroupsCache.set( bindingsArray, bindGroup );
|
|
|
+ bindingGroupsCache.set( cacheKey, bindGroup );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ for ( let i = 0; i < bindings.length; i ++ ) {
|
|
|
+
|
|
|
+ bindGroup.bindings[ i ].visibility |= bindings[ i ].visibility;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group );
|
|
|
+ bindGroup = new BindGroup( groupName, bindings, this.bindingsIndexes[ groupName ].group );
|
|
|
|
|
|
}
|
|
|
|