Skip to content

Commit 3d97098

Browse files
UniformsGroup: Pool per-uniform update-range objects. (#33427)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3fbe9ea commit 3d97098

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

src/renderers/common/UniformsGroup.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ class UniformsGroup extends UniformBuffer {
5555
*/
5656
this._updateRangeCache = new Map();
5757

58+
/**
59+
* Uniform indices whose range has already been pushed into `updateRanges`
60+
* during the current update cycle. Reset on `clearUpdateRanges()`.
61+
*
62+
* @private
63+
* @type {Set<number>}
64+
*/
65+
this._addedIndices = new Set();
66+
5867
}
5968

6069
/**
@@ -66,29 +75,31 @@ class UniformsGroup extends UniformBuffer {
6675

6776
const index = uniform.index;
6877

69-
if ( this._updateRangeCache.has( index ) !== true ) {
78+
if ( this._addedIndices.has( index ) ) return;
7079

71-
const updateRanges = this.updateRanges;
80+
let range = this._updateRangeCache.get( index );
7281

73-
const start = uniform.offset;
74-
const count = uniform.itemSize;
75-
76-
const range = { start, count };
77-
78-
updateRanges.push( range );
82+
if ( range === undefined ) {
7983

84+
range = { start: 0, count: 0 };
8085
this._updateRangeCache.set( index, range );
8186

8287
}
8388

89+
range.start = uniform.offset;
90+
range.count = uniform.itemSize;
91+
92+
this._addedIndices.add( index );
93+
this.updateRanges.push( range );
94+
8495
}
8596

8697
/**
8798
* Clears all update ranges of this buffer.
8899
*/
89100
clearUpdateRanges() {
90101

91-
this._updateRangeCache.clear();
102+
this._addedIndices.clear();
92103

93104
super.clearUpdateRanges();
94105

0 commit comments

Comments
 (0)