Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodes: Optimize getCacheKey(). #30259

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/renderers/common/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { hashArray } from '../../../nodes/core/NodeUtils.js';

const _outputNodeMap = new WeakMap();
const _chainKeys = [];
const _cacheKeyValues = [];

/**
* This renderer module manages node-related objects and is the
Expand Down Expand Up @@ -391,28 +392,26 @@ class Nodes extends DataMap {

const callId = this.renderer.info.calls;

let cacheKeyData = this.callHashCache.get( _chainKeys );
const cacheKeyData = this.callHashCache.get( _chainKeys ) || {};

if ( cacheKeyData === undefined || cacheKeyData.callId !== callId ) {
if ( cacheKeyData.callId !== callId ) {

const environmentNode = this.getEnvironmentNode( scene );
const fogNode = this.getFogNode( scene );

const values = [];
if ( lightsNode ) _cacheKeyValues.push( lightsNode.getCacheKey( true ) );
if ( environmentNode ) _cacheKeyValues.push( environmentNode.getCacheKey() );
if ( fogNode ) _cacheKeyValues.push( fogNode.getCacheKey() );

if ( lightsNode ) values.push( lightsNode.getCacheKey( true ) );
if ( environmentNode ) values.push( environmentNode.getCacheKey() );
if ( fogNode ) values.push( fogNode.getCacheKey() );
_cacheKeyValues.push( this.renderer.shadowMap.enabled ? 1 : 0 );

values.push( this.renderer.shadowMap.enabled ? 1 : 0 );

cacheKeyData = {
callId,
cacheKey: hashArray( values )
};
cacheKeyData.callId = callId;
cacheKeyData.cacheKey = hashArray( _cacheKeyValues );

this.callHashCache.set( _chainKeys, cacheKeyData );

_cacheKeyValues.length = 0;

}

_chainKeys.length = 0;
Expand Down
Loading