Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Binary file modified examples/screenshots/webgpu_volume_lighting.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 15 additions & 14 deletions src/renderers/common/Bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,29 @@ class Bindings extends DataMap {

} else if ( binding.isSampledTexture ) {

const texturesTextureData = this.textures.get( binding.texture );

if ( binding.needsBindingsUpdate( texturesTextureData.generation ) ) needsBindingsUpdate = true;

const updated = binding.update();

// get the texture data after the update, to sync the texture reference from node

const texture = binding.texture;
const texturesTextureData = this.textures.get( texture );

if ( updated ) {

// version: update the texture data or create a new one

this.textures.updateTexture( texture );

// generation: update the bindings if a new texture has been created

if ( binding.generation !== texturesTextureData.generation ) {

binding.generation = texturesTextureData.generation;

needsBindingsUpdate = true;

}

}

const textureData = backend.get( texture );
Expand All @@ -273,16 +284,6 @@ class Bindings extends DataMap {

}

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, texture, binding.textureNode.value, needsBindingsUpdate );

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

}

if ( texture.isStorageTexture === true ) {

const textureData = this.get( texture );
Expand Down
30 changes: 0 additions & 30 deletions src/renderers/common/SampledTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ class SampledTexture extends Sampler {
*/
this.store = false;

/**
* The binding's generation which is an additional version
* qualifier.
*
* @type {?number}
* @default null
*/
this.generation = null;

/**
* This flag can be used for type testing.
*
Expand All @@ -55,27 +46,6 @@ class SampledTexture extends Sampler {

}

/**
* Returns `true` whether this binding requires an update for the
* given generation.
*
* @param {number} generation - The generation.
* @return {boolean} Whether an update is required or not.
*/
needsBindingsUpdate( generation ) {

if ( generation !== this.generation ) {

this.generation = generation;

return true;

}

return false;

}

}

/**
Expand Down
57 changes: 57 additions & 0 deletions src/renderers/common/Sampler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ class Sampler extends Binding {

super( name );

/**
* This function is called when the texture is disposed.
* @type {function}
* @private
*/
this._onDisposeTexture = () => {

this.texture = null;

};

/**
* The texture the sampler is referring to.
*
Expand All @@ -32,6 +43,15 @@ class Sampler extends Binding {
*/
this.version = texture ? texture.version : 0;

/**
* The binding's generation which is an additional version
* qualifier.
*
* @type {?number}
* @default null
*/
this.generation = null;

/**
* This flag can be used for type testing.
*
Expand All @@ -43,6 +63,43 @@ class Sampler extends Binding {

}

/**
* Sets the texture of this sampler.
* @param {?Texture} value - The texture to set.
*/
set texture( value ) {

if ( this._texture === value ) return;

if ( this._texture ) {

this._texture.removeEventListener( 'dispose', this._onDisposeTexture );

}

this._texture = value;

this.generation = null;
this.version = 0;

if ( this._texture ) {

this._texture.addEventListener( 'dispose', this._onDisposeTexture );

}

}

/**
* Gets the texture of this sampler.
* @return {?Texture} The texture.
*/
get texture() {

return this._texture;

}

/**
* Updates the binding.
*
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/common/Textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class Textures extends DataMap {
backend.createDefaultTexture( texture );

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

}

Expand Down
12 changes: 0 additions & 12 deletions src/renderers/common/nodes/NodeSampledTexture.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,6 @@ class NodeSampledTexture extends SampledTexture {

}

/**
* Overwrites the default to additionally check if the node value has changed.
*
* @param {number} generation - The generation.
* @return {boolean} Whether an update is required or not.
*/
needsBindingsUpdate( generation ) {

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

}

/**
* Updates the binding.
*
Expand Down