Skip to content

Commit

Permalink
WebGPURenderer: avoid render pass/pipeline attachment mismatches (#26376
Browse files Browse the repository at this point in the history
)

* add support for meshPhongNodeMaterial

* add renderTarget to key for renderContexts

* use renderContext as key to locate correct renderobjects in cache

* rework to use attachment state and fix deletion path

* remove surplus :

---------

Co-authored-by: aardgoose <[email protected]>
  • Loading branch information
aardgoose and aardgoose authored Jul 8, 2023
1 parent 95fbc39 commit 366d701
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
17 changes: 13 additions & 4 deletions examples/jsm/renderers/common/RenderContexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,37 @@ class RenderContexts {

constructor() {

this.renderStates = new ChainMap();
this.chainMaps = {};

}

get( scene, camera ) {
get( scene, camera, renderTarget = null ) {

const chainKey = [ scene, camera ];
const attachmentState = renderTarget === null ? 'default' : `${renderTarget.texture.format}:${renderTarget.samples}:${renderTarget.depthBuffer}:${renderTarget.stencilBuffer}`;

const chainMap = this.getChainMap( attachmentState );

let renderState = this.renderStates.get( chainKey );
let renderState = chainMap.get( chainKey );

if ( renderState === undefined ) {

renderState = new RenderContext();

this.renderStates.set( chainKey, renderState );
chainMap.set( chainKey, renderState );

}

return renderState;

}

getChainMap( attachmentState ) {

return this.chainMaps[ attachmentState ] || ( this.chainMaps[ attachmentState ] = new ChainMap() );

}

dispose() {

this.renderStates = new ChainMap();
Expand Down
6 changes: 3 additions & 3 deletions examples/jsm/renderers/common/RenderObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ let id = 0;

export default class RenderObject {

constructor( nodes, geometries, renderer, object, material, scene, camera, lightsNode ) {
constructor( nodes, geometries, renderer, object, material, scene, camera, lightsNode, renderContext ) {

this._nodes = nodes;
this._geometries = geometries;
Expand All @@ -19,7 +19,7 @@ export default class RenderObject {
this.geometry = object.geometry;

this.attributes = null;
this.context = null;
this.context = renderContext;
this.pipeline = null;
this.vertexBuffers = null;

Expand Down Expand Up @@ -58,7 +58,7 @@ export default class RenderObject {

getChainArray() {

return [ this.object, this.material, this.scene, this.camera, this.lightsNode ];
return [ this.object, this.material, this.context, this.lightsNode ];

}

Expand Down
12 changes: 6 additions & 6 deletions examples/jsm/renderers/common/RenderObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class RenderObjects {

}

get( object, material, scene, camera, lightsNode, passId ) {
get( object, material, scene, camera, lightsNode, renderContext, passId ) {

const chainMap = this.getChainMap( passId );
const chainArray = [ object, material, scene, camera, lightsNode ];
const chainArray = [ object, material, renderContext, lightsNode ];

let renderObject = chainMap.get( chainArray );

if ( renderObject === undefined ) {

renderObject = this.createRenderObject( this.nodes, this.geometries, this.renderer, object, material, scene, camera, lightsNode, passId );
renderObject = this.createRenderObject( this.nodes, this.geometries, this.renderer, object, material, scene, camera, lightsNode, renderContext, passId );

chainMap.set( chainArray, renderObject );

Expand All @@ -39,7 +39,7 @@ class RenderObjects {

renderObject.dispose();

renderObject = this.get( object, material, scene, camera, lightsNode );
renderObject = this.get( object, material, scene, camera, lightsNode, renderContext );

}

Expand All @@ -62,11 +62,11 @@ class RenderObjects {

}

createRenderObject( nodes, geometries, renderer, object, material, scene, camera, lightsNode, passId ) {
createRenderObject( nodes, geometries, renderer, object, material, scene, camera, lightsNode, renderContext, passId ) {

const chainMap = this.getChainMap( passId );
const dataMap = this.dataMap;
const renderObject = new RenderObject( nodes, geometries, renderer, object, material, scene, camera, lightsNode );
const renderObject = new RenderObject( nodes, geometries, renderer, object, material, scene, camera, lightsNode, renderContext );

const data = dataMap.get( renderObject );
data.cacheKey = renderObject.getCacheKey();
Expand Down
5 changes: 2 additions & 3 deletions examples/jsm/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ class Renderer {

//

const renderContext = this._renderContexts.get( scene, camera );
const renderTarget = this._renderTarget;
const renderContext = this._renderContexts.get( scene, camera, renderTarget );
const activeCubeFace = this._activeCubeFace;

this._currentRenderContext = renderContext;
Expand Down Expand Up @@ -840,8 +840,7 @@ class Renderer {

//

const renderObject = this._objects.get( object, material, scene, camera, lightsNode, passId );
renderObject.context = this._currentRenderContext;
const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, passId );

//

Expand Down

0 comments on commit 366d701

Please sign in to comment.