Skip to content

Commit

Permalink
WebGPURenderer: Reduce bindingGroup creation for data texture content…
Browse files Browse the repository at this point in the history
… updates. (#29183)

Cleanup code

Co-authored-by: aardgoose <angus.sawyer@email.com>
  • Loading branch information
aardgoose and aardgoose authored Aug 22, 2024
1 parent 09430e8 commit 00f9175
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/renderers/common/Backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class Backend {

// bindings

createBindings( /*renderObject*/ ) { }
createBindings( /*bingGroup, bindings*/ ) { }

updateBindings( /*renderObject*/ ) { }
updateBindings( /*bingGroup, bindings*/ ) { }

// pipeline

Expand Down
28 changes: 13 additions & 15 deletions src/renderers/common/Bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ class Bindings extends DataMap {

updateForCompute( computeNode ) {

this._updateBindings( computeNode, this.getForCompute( computeNode ) );
this._updateBindings( this.getForCompute( computeNode ) );

}

updateForRender( renderObject ) {

this._updateBindings( renderObject, this.getForRender( renderObject ) );
this._updateBindings( this.getForRender( renderObject ) );

}

_updateBindings( object, bindings ) {
_updateBindings( bindings ) {

for ( const bindGroup of bindings ) {

this._update( object, bindGroup, bindings );
this._update( bindGroup, bindings );

}

Expand All @@ -110,7 +110,7 @@ class Bindings extends DataMap {

}

_update( object, bindGroup, bindings ) {
_update( bindGroup, bindings ) {

const { backend } = this;

Expand Down Expand Up @@ -144,26 +144,26 @@ class Bindings extends DataMap {

} else if ( binding.isSampledTexture ) {

const texture = binding.texture;

if ( binding.needsBindingsUpdate ) needsBindingsUpdate = true;
if ( binding.needsBindingsUpdate( this.textures.get( binding.texture ).generation ) ) needsBindingsUpdate = true;

const updated = binding.update();

const texture = binding.texture;

if ( updated ) {

this.textures.updateTexture( binding.texture );
this.textures.updateTexture( texture );

}

const textureData = backend.get( binding.texture );
const textureData = backend.get( texture );

if ( backend.isWebGPUBackend === true && textureData.texture === undefined && textureData.externalTexture === undefined ) {

// TODO: Remove this once we found why updated === false isn't bound to a texture in the WebGPU backend
console.error( 'Bindings._update: binding should be available:', binding, updated, binding.texture, binding.textureNode.value );
console.error( 'Bindings._update: binding should be available:', binding, updated, texture, binding.textureNode.value, needsBindingsUpdate );

this.textures.updateTexture( binding.texture );
this.textures.updateTexture( texture );
needsBindingsUpdate = true;

}
Expand Down Expand Up @@ -192,9 +192,7 @@ class Bindings extends DataMap {

if ( needsBindingsUpdate === true ) {

const pipeline = this.pipelines.getForRender( object );

this.backend.updateBindings( bindGroup, bindings, pipeline );
this.backend.updateBindings( bindGroup, bindings );

}

Expand Down
15 changes: 12 additions & 3 deletions src/renderers/common/SampledTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ class SampledTexture extends Binding {
this.texture = texture;
this.version = texture ? texture.version : 0;
this.store = false;
this.generation = null;

this.isSampledTexture = true;

}

get needsBindingsUpdate() {
needsBindingsUpdate( generation ) {

const { texture, version } = this;
const { texture } = this;

if ( generation !== this.generation ) {

this.generation = generation;

return true;

}

return texture.isVideoTexture ? true : version !== texture.version; // @TODO: version === 0 && texture.version > 0 ( add it just to External Textures like PNG,JPG )
return texture.isVideoTexture;

}

Expand Down
5 changes: 5 additions & 0 deletions src/renderers/common/Textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ class Textures extends DataMap {
backend.createSampler( texture );
backend.createTexture( texture, options );

textureData.generation = texture.version;

} else {

const needsCreate = textureData.initialized !== true;
Expand Down Expand Up @@ -216,6 +218,7 @@ class Textures extends DataMap {
backend.createTexture( texture, options );

textureData.isDefaultTexture = false;
textureData.generation = texture.version;

}

Expand All @@ -232,6 +235,7 @@ class Textures extends DataMap {
backend.createDefaultTexture( texture );

textureData.isDefaultTexture = true;
textureData.generation = texture.version;

}

Expand All @@ -242,6 +246,7 @@ class Textures extends DataMap {
if ( textureData.initialized !== true ) {

textureData.initialized = true;
textureData.generation = texture.version;

//

Expand Down
4 changes: 2 additions & 2 deletions src/renderers/common/nodes/NodeSampledTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class NodeSampledTexture extends SampledTexture {

}

get needsBindingsUpdate() {
needsBindingsUpdate( generation ) {

return this.textureNode.value !== this.texture || super.needsBindingsUpdate;
return this.textureNode.value !== this.texture || super.needsBindingsUpdate( generation );

}

Expand Down

0 comments on commit 00f9175

Please sign in to comment.