Skip to content

Commit

Permalink
WebGPURenderer: Introduce Node.updateAfter (#28552)
Browse files Browse the repository at this point in the history
  • Loading branch information
RenaudRohlinger authored Jun 4, 2024
1 parent 3556fc5 commit f805325
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 1 deletion.
13 changes: 13 additions & 0 deletions examples/jsm/nodes/core/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Node extends EventDispatcher {

this.updateType = NodeUpdateType.NONE;
this.updateBeforeType = NodeUpdateType.NONE;
this.updateAfterType = NodeUpdateType.NONE;

this.uuid = MathUtils.generateUUID();

Expand Down Expand Up @@ -165,6 +166,12 @@ class Node extends EventDispatcher {

}

getUpdateAfterType() {

return this.updateAfterType;

}

getElementType( builder ) {

const type = this.getNodeType( builder );
Expand Down Expand Up @@ -273,6 +280,12 @@ class Node extends EventDispatcher {

}

updateAfter( /*frame*/ ) {

console.warn( 'Abstract function.' );

}

update( /*frame*/ ) {

console.warn( 'Abstract function.' );
Expand Down
8 changes: 8 additions & 0 deletions examples/jsm/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class NodeBuilder {
this.nodes = [];
this.updateNodes = [];
this.updateBeforeNodes = [];
this.updateAfterNodes = [];
this.hashNodes = {};

this.lightsNode = null;
Expand Down Expand Up @@ -215,6 +216,7 @@ class NodeBuilder {

const updateType = node.getUpdateType();
const updateBeforeType = node.getUpdateBeforeType();
const updateAfterType = node.getUpdateAfterType();

if ( updateType !== NodeUpdateType.NONE ) {

Expand All @@ -228,6 +230,12 @@ class NodeBuilder {

}

if ( updateAfterType !== NodeUpdateType.NONE ) {

this.updateAfterNodes.push( node );

}

}

}
Expand Down
42 changes: 42 additions & 0 deletions examples/jsm/nodes/core/NodeFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class NodeFrame {

this.updateMap = new WeakMap();
this.updateBeforeMap = new WeakMap();
this.updateAfterMap = new WeakMap();

this.renderer = null;
this.material = null;
Expand Down Expand Up @@ -83,6 +84,47 @@ class NodeFrame {

}

updateAfterNode( node ) {

const updateType = node.getUpdateAfterType();
const reference = node.updateReference( this );

if ( updateType === NodeUpdateType.FRAME ) {

const { frameMap } = this._getMaps( this.updateAfterMap, reference );

if ( frameMap.get( reference ) !== this.frameId ) {

if ( node.updateAfter( this ) !== false ) {

frameMap.set( reference, this.frameId );

}

}

} else if ( updateType === NodeUpdateType.RENDER ) {

const { renderMap } = this._getMaps( this.updateAfterMap, reference );

if ( renderMap.get( reference ) !== this.renderId ) {

if ( node.updateAfter( this ) !== false ) {

renderMap.set( reference, this.renderId );

}

}

} else if ( updateType === NodeUpdateType.OBJECT ) {

node.updateAfter( this );

}

}

updateNode( node ) {

const updateType = node.getUpdateType();
Expand Down
6 changes: 6 additions & 0 deletions examples/jsm/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ class Renderer {

this.backend.draw( renderObject, this.info );

this._nodes.updateAfter( renderObject );

}

}
Expand Down Expand Up @@ -1527,6 +1529,8 @@ class Renderer {

}

this._nodes.updateAfter( renderObject );

}

_createObjectPipeline( object, material, scene, camera, lightsNode, passId ) {
Expand All @@ -1545,6 +1549,8 @@ class Renderer {

this._pipelines.getForRender( renderObject, this._compilationPromises );

this._nodes.updateAfter( renderObject );

}

get compute() {
Expand Down
3 changes: 2 additions & 1 deletion examples/jsm/renderers/common/nodes/NodeBuilderState.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class NodeBuilderState {

constructor( vertexShader, fragmentShader, computeShader, nodeAttributes, bindings, updateNodes, updateBeforeNodes, transforms = [] ) {
constructor( vertexShader, fragmentShader, computeShader, nodeAttributes, bindings, updateNodes, updateBeforeNodes, updateAfterNodes, transforms = [] ) {

this.vertexShader = vertexShader;
this.fragmentShader = fragmentShader;
Expand All @@ -12,6 +12,7 @@ class NodeBuilderState {

this.updateNodes = updateNodes;
this.updateBeforeNodes = updateBeforeNodes;
this.updateAfterNodes = updateAfterNodes;

this.usedTimes = 0;

Expand Down
14 changes: 14 additions & 0 deletions examples/jsm/renderers/common/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class Nodes extends DataMap {
nodeBuilder.getBindings(),
nodeBuilder.updateNodes,
nodeBuilder.updateBeforeNodes,
nodeBuilder.updateAfterNodes,
nodeBuilder.transforms
);

Expand Down Expand Up @@ -427,6 +428,19 @@ class Nodes extends DataMap {

}

updateAfter( renderObject ) {

const nodeFrame = this.getNodeFrameForRender( renderObject );
const nodeBuilder = renderObject.getNodeBuilderState();

for ( const node of nodeBuilder.updateAfterNodes ) {

nodeFrame.updateAfterNode( node );

}

}

updateForCompute( computeNode ) {

const nodeFrame = this.getNodeFrame();
Expand Down

0 comments on commit f805325

Please sign in to comment.