Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions src/renderers/common/Bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ class Bindings extends DataMap {

}

if ( binding.isBuffer && binding.updateRanges.length > 0 ) {

binding.clearUpdateRanges();

}

}

if ( needsBindingsUpdate === true ) {
Expand Down
8 changes: 8 additions & 0 deletions src/renderers/common/Uniform.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class Uniform {
*/
this.offset = 0;

/**
* This property is set by {@link UniformsGroup} and marks
* the index position in the uniform array.
*
* @type {number}
*/
this.index = - 1;

}

/**
Expand Down
60 changes: 53 additions & 7 deletions src/renderers/common/UniformsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,51 @@ class UniformsGroup extends UniformBuffer {
*/
this.uniforms = [];

/**
* A cache for the uniform update ranges.
*
* @private
* @type {Map<number, {start: number, count: number}>}
*/
this._updateRangeCache = new Map();

}

/**
* Adds a uniform's update range to this buffer.
*
* @param {Uniform} uniform - The uniform.
*/
addUniformUpdateRange( uniform ) {

const index = uniform.index;

if ( this._updateRangeCache.has( index ) !== true ) {

const updateRanges = this.updateRanges;

const start = uniform.offset;
const count = uniform.itemSize;

const range = { start, count };

updateRanges.push( range );

this._updateRangeCache.set( index, range );

}

}

/**
* Clears all update ranges of this buffer.
*/
clearUpdateRanges() {

this._updateRangeCache.clear();

super.clearUpdateRanges();

}

/**
Expand Down Expand Up @@ -156,6 +201,7 @@ class UniformsGroup extends UniformBuffer {
}

uniform.offset = offset / bytesPerElement;
uniform.index = i;

offset += itemSize;

Expand Down Expand Up @@ -235,7 +281,7 @@ class UniformsGroup extends UniformBuffer {
b[ offset ] = a[ offset ] = v;
updated = true;

this.addUpdateRange( offset, 1 );
this.addUniformUpdateRange( uniform );

}

Expand Down Expand Up @@ -267,7 +313,7 @@ class UniformsGroup extends UniformBuffer {

updated = true;

this.addUpdateRange( offset, 2 );
this.addUniformUpdateRange( uniform );

}

Expand Down Expand Up @@ -300,7 +346,7 @@ class UniformsGroup extends UniformBuffer {

updated = true;

this.addUpdateRange( offset, 3 );
this.addUniformUpdateRange( uniform );

}

Expand Down Expand Up @@ -334,7 +380,7 @@ class UniformsGroup extends UniformBuffer {

updated = true;

this.addUpdateRange( offset, 4 );
this.addUniformUpdateRange( uniform );

}

Expand Down Expand Up @@ -366,7 +412,7 @@ class UniformsGroup extends UniformBuffer {

updated = true;

this.addUpdateRange( offset, 3 );
this.addUniformUpdateRange( uniform );

}

Expand Down Expand Up @@ -406,7 +452,7 @@ class UniformsGroup extends UniformBuffer {

updated = true;

this.addUpdateRange( offset, 12 );
this.addUniformUpdateRange( uniform );

}

Expand Down Expand Up @@ -435,7 +481,7 @@ class UniformsGroup extends UniformBuffer {
setArray( a, e, offset );
updated = true;

this.addUpdateRange( offset, 16 );
this.addUniformUpdateRange( uniform );

}

Expand Down
2 changes: 0 additions & 2 deletions src/renderers/webgpu/utils/WebGPUBindingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ class WebGPUBindingUtils {

}

binding.clearUpdateRanges();

}

}
Expand Down