|
|
@@ -79,21 +79,15 @@ class Bindings extends DataMap {
|
|
|
|
|
|
const bindings = renderObject.getBindings();
|
|
|
|
|
|
- for ( const bindGroup of bindings ) {
|
|
|
-
|
|
|
- const groupData = this.get( bindGroup );
|
|
|
+ const renderObjectData = this.get( renderObject );
|
|
|
|
|
|
- if ( groupData.bindGroup === undefined ) {
|
|
|
+ if ( renderObjectData.initialized !== true ) {
|
|
|
|
|
|
- // each object defines an array of bindings (ubos, textures, samplers etc.)
|
|
|
+ // bind groups are created once per object
|
|
|
|
|
|
- this._init( bindGroup );
|
|
|
+ this._createBindings( bindings );
|
|
|
|
|
|
- this.backend.createBindings( bindGroup, bindings, 0 );
|
|
|
-
|
|
|
- groupData.bindGroup = bindGroup;
|
|
|
-
|
|
|
- }
|
|
|
+ renderObjectData.initialized = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -110,20 +104,15 @@ class Bindings extends DataMap {
|
|
|
getForCompute( computeNode ) {
|
|
|
|
|
|
const bindings = this.nodes.getForCompute( computeNode ).bindings;
|
|
|
+ const computeNodeData = this.get( computeNode );
|
|
|
|
|
|
- for ( const bindGroup of bindings ) {
|
|
|
-
|
|
|
- const groupData = this.get( bindGroup );
|
|
|
-
|
|
|
- if ( groupData.bindGroup === undefined ) {
|
|
|
+ if ( computeNodeData.initialized !== true ) {
|
|
|
|
|
|
- this._init( bindGroup );
|
|
|
+ // bind groups are created once per object
|
|
|
|
|
|
- this.backend.createBindings( bindGroup, bindings, 0 );
|
|
|
+ this._createBindings( bindings );
|
|
|
|
|
|
- groupData.bindGroup = bindGroup;
|
|
|
-
|
|
|
- }
|
|
|
+ computeNodeData.initialized = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -162,12 +151,9 @@ class Bindings extends DataMap {
|
|
|
|
|
|
const bindings = this.nodes.getForCompute( computeNode ).bindings;
|
|
|
|
|
|
- for ( const bindGroup of bindings ) {
|
|
|
+ this._destroyBindings( bindings );
|
|
|
|
|
|
- this.backend.deleteBindGroupData( bindGroup );
|
|
|
- this.delete( bindGroup );
|
|
|
-
|
|
|
- }
|
|
|
+ this.delete( computeNode );
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -180,53 +166,103 @@ class Bindings extends DataMap {
|
|
|
|
|
|
const bindings = renderObject.getBindings();
|
|
|
|
|
|
- for ( const bindGroup of bindings ) {
|
|
|
-
|
|
|
- this.backend.deleteBindGroupData( bindGroup );
|
|
|
- this.delete( bindGroup );
|
|
|
+ this._destroyBindings( bindings );
|
|
|
|
|
|
- }
|
|
|
+ this.delete( renderObject );
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Updates the given array of bindings.
|
|
|
+ * Creates the bindings for the given array of bindings.
|
|
|
*
|
|
|
* @param {Array<BindGroup>} bindings - The bind groups.
|
|
|
*/
|
|
|
- _updateBindings( bindings ) {
|
|
|
+ _createBindings( bindings ) {
|
|
|
|
|
|
for ( const bindGroup of bindings ) {
|
|
|
|
|
|
- this._update( bindGroup, bindings );
|
|
|
+ // binding group
|
|
|
+
|
|
|
+ const groupData = this.get( bindGroup );
|
|
|
+
|
|
|
+ if ( groupData.bindGroup === undefined ) {
|
|
|
+
|
|
|
+ // initialize
|
|
|
+
|
|
|
+ for ( const binding of bindGroup.bindings ) {
|
|
|
+
|
|
|
+ if ( binding.isUniformBuffer ) {
|
|
|
+
|
|
|
+ this.backend.createUniformBuffer( binding );
|
|
|
+ this.info.createUniformBuffer( binding );
|
|
|
+
|
|
|
+ } else if ( binding.isSampledTexture ) {
|
|
|
+
|
|
|
+ this.textures.updateTexture( binding.texture );
|
|
|
+
|
|
|
+ } else if ( binding.isSampler ) {
|
|
|
+
|
|
|
+ this.textures.updateSampler( binding.texture );
|
|
|
+
|
|
|
+ } else if ( binding.isStorageBuffer ) {
|
|
|
+
|
|
|
+ const attribute = binding.attribute;
|
|
|
+ const attributeType = attribute.isIndirectStorageBufferAttribute ? AttributeType.INDIRECT : AttributeType.STORAGE;
|
|
|
+
|
|
|
+ this.attributes.update( attribute, attributeType );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // each object defines an array of bindings (ubos, textures, samplers etc.)
|
|
|
+
|
|
|
+ this.backend.createBindings( bindGroup, bindings, 0 );
|
|
|
+
|
|
|
+ groupData.bindGroup = bindGroup;
|
|
|
+ groupData.usedTimes = 1;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ groupData.usedTimes ++;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Initializes the given bind group.
|
|
|
+ * Deletes the given array of bindings.
|
|
|
*
|
|
|
- * @param {BindGroup} bindGroup - The bind group to initialize.
|
|
|
+ * @param {Array<BindGroup>} bindings - The bind groups.
|
|
|
*/
|
|
|
- _init( bindGroup ) {
|
|
|
+ _destroyBindings( bindings ) {
|
|
|
|
|
|
- for ( const binding of bindGroup.bindings ) {
|
|
|
+ for ( const bindGroup of bindings ) {
|
|
|
|
|
|
- if ( binding.isSampledTexture ) {
|
|
|
+ const groupData = this.get( bindGroup );
|
|
|
+ groupData.usedTimes --;
|
|
|
|
|
|
- this.textures.updateTexture( binding.texture );
|
|
|
+ if ( groupData.usedTimes === 0 ) {
|
|
|
|
|
|
- } else if ( binding.isSampler ) {
|
|
|
+ for ( const binding of bindGroup.bindings ) {
|
|
|
|
|
|
- this.textures.updateSampler( binding.texture );
|
|
|
+ if ( binding.isUniformBuffer ) {
|
|
|
|
|
|
- } else if ( binding.isStorageBuffer ) {
|
|
|
+ this.backend.destroyUniformBuffer( binding );
|
|
|
+ this.info.destroyUniformBuffer( binding );
|
|
|
|
|
|
- const attribute = binding.attribute;
|
|
|
- const attributeType = attribute.isIndirectStorageBufferAttribute ? AttributeType.INDIRECT : AttributeType.STORAGE;
|
|
|
+ // release arrays
|
|
|
|
|
|
- this.attributes.update( attribute, attributeType );
|
|
|
+ binding.release();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ this.backend.deleteBindGroupData( bindGroup );
|
|
|
+ this.delete( bindGroup );
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -234,6 +270,21 @@ class Bindings extends DataMap {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Updates the given array of bindings.
|
|
|
+ *
|
|
|
+ * @param {Array<BindGroup>} bindings - The bind groups.
|
|
|
+ */
|
|
|
+ _updateBindings( bindings ) {
|
|
|
+
|
|
|
+ for ( const bindGroup of bindings ) {
|
|
|
+
|
|
|
+ this._update( bindGroup, bindings );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Updates the given bind group.
|
|
|
*
|