@@ -3275,7 +3275,7 @@ function addMethodChaining( name, nodeElement ) {
32753275
32763276 //if ( name === 'toVarIntent' ) return this;
32773277
3278- return this.isStackNode ? this.add ( nodeElement( ...params ) ) : nodeElement( this, ...params );
3278+ return this.isStackNode ? this.addToStack ( nodeElement( ...params ) ) : nodeElement( this, ...params );
32793279
32803280 };
32813281
@@ -3314,7 +3314,7 @@ Node.prototype.assign = function ( ...params ) {
33143314
33153315 const nodeElement = NodeElements.get( 'assign' );
33163316
3317- return this.add ( nodeElement( ...params ) );
3317+ return this.addToStack ( nodeElement( ...params ) );
33183318
33193319 }
33203320
@@ -4361,7 +4361,7 @@ const Switch = ( ...params ) => currentStack.Switch( ...params );
43614361 */
43624362function Stack( node ) {
43634363
4364- if ( currentStack ) currentStack.add ( node );
4364+ if ( currentStack ) currentStack.addToStack ( node );
43654365
43664366 return node;
43674367
@@ -9287,9 +9287,10 @@ class ToneMappingNode extends TempNode {
92879287 /**
92889288 * The tone mapping type.
92899289 *
9290+ * @private
92909291 * @type {number}
92919292 */
9292- this.toneMapping = toneMapping;
9293+ this._toneMapping = toneMapping;
92939294
92949295 /**
92959296 * The tone mapping exposure.
@@ -9317,14 +9318,39 @@ class ToneMappingNode extends TempNode {
93179318 */
93189319 customCacheKey() {
93199320
9320- return hash$1( this.toneMapping );
9321+ return hash$1( this._toneMapping );
9322+
9323+ }
9324+
9325+ /**
9326+ * Sets the tone mapping type.
9327+ *
9328+ * @param {number} value - The tone mapping type.
9329+ * @return {ToneMappingNode} A reference to this node.
9330+ */
9331+ setToneMapping( value ) {
9332+
9333+ this._toneMapping = value;
9334+
9335+ return this;
9336+
9337+ }
9338+
9339+ /**
9340+ * Gets the tone mapping type.
9341+ *
9342+ * @returns {number} The tone mapping type.
9343+ */
9344+ getToneMapping() {
9345+
9346+ return this._toneMapping;
93219347
93229348 }
93239349
93249350 setup( builder ) {
93259351
93269352 const colorNode = this.colorNode || builder.context.color;
9327- const toneMapping = this.toneMapping ;
9353+ const toneMapping = this._toneMapping ;
93289354
93299355 if ( toneMapping === NoToneMapping ) return colorNode;
93309356
@@ -10445,9 +10471,10 @@ class RenderOutputNode extends TempNode {
1044510471 /**
1044610472 * The tone mapping type.
1044710473 *
10474+ * @private
1044810475 * @type {?number}
1044910476 */
10450- this.toneMapping = toneMapping;
10477+ this._toneMapping = toneMapping;
1045110478
1045210479 /**
1045310480 * The output color space.
@@ -10467,13 +10494,38 @@ class RenderOutputNode extends TempNode {
1046710494
1046810495 }
1046910496
10497+ /**
10498+ * Sets the tone mapping type.
10499+ *
10500+ * @param {number} value - The tone mapping type.
10501+ * @return {ToneMappingNode} A reference to this node.
10502+ */
10503+ setToneMapping( value ) {
10504+
10505+ this._toneMapping = value;
10506+
10507+ return this;
10508+
10509+ }
10510+
10511+ /**
10512+ * Gets the tone mapping type.
10513+ *
10514+ * @returns {number} The tone mapping type.
10515+ */
10516+ getToneMapping() {
10517+
10518+ return this._toneMapping;
10519+
10520+ }
10521+
1047010522 setup( { context } ) {
1047110523
1047210524 let outputNode = this.colorNode || context.color;
1047310525
1047410526 // tone mapping
1047510527
10476- const toneMapping = ( this.toneMapping !== null ? this.toneMapping : context.toneMapping ) || NoToneMapping;
10528+ const toneMapping = ( this._toneMapping !== null ? this._toneMapping : context.toneMapping ) || NoToneMapping;
1047710529 const outputColorSpace = ( this.outputColorSpace !== null ? this.outputColorSpace : context.outputColorSpace ) || NoColorSpace;
1047810530
1047910531 if ( toneMapping !== NoToneMapping ) {
@@ -19993,7 +20045,7 @@ class NodeMaterial extends Material {
1999320045
1999420046 const outgoingLightNode = this.setupLighting( builder );
1999520047
19996- if ( clippingNode !== null ) builder.stack.add ( clippingNode );
20048+ if ( clippingNode !== null ) builder.stack.addToStack ( clippingNode );
1999720049
1999820050 // force unsigned floats - useful for RenderTargets
1999920051
@@ -20087,7 +20139,7 @@ class NodeMaterial extends Material {
2008720139
2008820140 } else {
2008920141
20090- builder.stack.add ( clipping() );
20142+ builder.stack.addToStack ( clipping() );
2009120143
2009220144 }
2009320145
@@ -20114,7 +20166,7 @@ class NodeMaterial extends Material {
2011420166
2011520167 if ( candidateCount > 0 && candidateCount <= 8 && builder.isAvailable( 'clipDistance' ) ) {
2011620168
20117- builder.stack.add ( hardwareClipping() );
20169+ builder.stack.addToStack ( hardwareClipping() );
2011820170
2011920171 this.hardwareClipping = true;
2012020172
@@ -32264,7 +32316,7 @@ class StackNode extends Node {
3226432316 * @param {Node} node - The node to add.
3226532317 * @return {StackNode} A reference to this stack node.
3226632318 */
32267- add ( node ) {
32319+ addToStack ( node ) {
3226832320
3226932321 if ( node.isNode !== true ) {
3227032322
@@ -32291,7 +32343,7 @@ class StackNode extends Node {
3229132343 const methodNode = new ShaderNode( method );
3229232344 this._currentCond = select( boolNode, methodNode );
3229332345
32294- return this.add ( this._currentCond );
32346+ return this.addToStack ( this._currentCond );
3229532347
3229632348 }
3229732349
@@ -32393,7 +32445,7 @@ class StackNode extends Node {
3239332445
3239432446 this._currentCond = condNode;
3239532447
32396- return this.add ( this._currentCond );
32448+ return this.addToStack ( this._currentCond );
3239732449
3239832450 } else {
3239932451
@@ -68813,29 +68865,27 @@ fn main( @location( 0 ) vTex : vec2<f32> ) -> @location( 0 ) vec4<f32> {
6881368865 * @param {GPUTexture} textureGPU - The GPU texture object.
6881468866 * @param {Object} textureGPUDescriptor - The texture descriptor.
6881568867 * @param {number} [baseArrayLayer=0] - The index of the first array layer accessible to the texture view.
68868+ * @param {?GPUCommandEncoder} [encoder=null] - An optional command encoder used to generate mipmaps.
6881668869 */
68817- generateMipmaps( textureGPU, textureGPUDescriptor, baseArrayLayer = 0 ) {
68870+ generateMipmaps( textureGPU, textureGPUDescriptor, baseArrayLayer = 0, encoder = null ) {
6881868871
6881968872 const textureData = this.get( textureGPU );
6882068873
68821- if ( textureData.useCount === undefined ) {
68874+ if ( textureData.layers === undefined ) {
6882268875
68823- textureData.useCount = 0;
6882468876 textureData.layers = [];
6882568877
6882668878 }
6882768879
6882868880 const passes = textureData.layers[ baseArrayLayer ] || this._mipmapCreateBundles( textureGPU, textureGPUDescriptor, baseArrayLayer );
6882968881
68830- const commandEncoder = this.device.createCommandEncoder( {} );
68882+ const commandEncoder = encoder || this.device.createCommandEncoder( { label: 'mipmapEncoder' } );
6883168883
6883268884 this._mipmapRunBundles( commandEncoder, passes );
6883368885
68834- this.device.queue.submit( [ commandEncoder.finish() ] );
68835-
68836- if ( textureData.useCount !== 0 ) textureData.layers[ baseArrayLayer ] = passes;
68886+ if ( encoder === null ) this.device.queue.submit( [ commandEncoder.finish() ] );
6883768887
68838- textureData.useCount ++ ;
68888+ textureData.layers[ baseArrayLayer ] = passes ;
6883968889
6884068890 }
6884168891
@@ -69263,16 +69313,17 @@ class WebGPUTextureUtils {
6926369313 * Generates mipmaps for the given texture.
6926469314 *
6926569315 * @param {Texture} texture - The texture.
69316+ * @param {?GPUCommandEncoder} [encoder=null] - An optional command encoder used to generate mipmaps.
6926669317 */
69267- generateMipmaps( texture ) {
69318+ generateMipmaps( texture, encoder = null ) {
6926869319
6926969320 const textureData = this.backend.get( texture );
6927069321
6927169322 if ( texture.isCubeTexture ) {
6927269323
6927369324 for ( let i = 0; i < 6; i ++ ) {
6927469325
69275- this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i );
69326+ this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i, encoder );
6927669327
6927769328 }
6927869329
@@ -69282,7 +69333,7 @@ class WebGPUTextureUtils {
6928269333
6928369334 for ( let i = 0; i < depth; i ++ ) {
6928469335
69285- this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i );
69336+ this._generateMipmaps( textureData.texture, textureData.textureDescriptorGPU, i, encoder );
6928669337
6928769338 }
6928869339
@@ -69733,10 +69784,11 @@ class WebGPUTextureUtils {
6973369784 * @param {GPUTexture} textureGPU - The GPU texture object.
6973469785 * @param {Object} textureDescriptorGPU - The texture descriptor.
6973569786 * @param {number} [baseArrayLayer=0] - The index of the first array layer accessible to the texture view.
69787+ * @param {?GPUCommandEncoder} [encoder=null] - An optional command encoder used to generate mipmaps.
6973669788 */
69737- _generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer = 0 ) {
69789+ _generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer = 0, encoder = null ) {
6973869790
69739- this._getPassUtils().generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer );
69791+ this._getPassUtils().generateMipmaps( textureGPU, textureDescriptorGPU, baseArrayLayer, encoder );
6974069792
6974169793 }
6974269794
@@ -75913,8 +75965,7 @@ class WebGPUBackend extends Backend {
7591375965
7591475966 if ( renderContext.scissor ) {
7591575967
75916- const { x, y, width, height } = renderContext.scissorValue;
75917- currentPass.setScissorRect( x, y, width, height );
75968+ this.updateScissor( renderContext );
7591875969
7591975970 }
7592075971
@@ -76274,6 +76325,20 @@ class WebGPUBackend extends Backend {
7627476325
7627576326 }
7627676327
76328+ /**
76329+ * Updates the scissor with the values from the given render context.
76330+ *
76331+ * @param {RenderContext} renderContext - The render context.
76332+ */
76333+ updateScissor( renderContext ) {
76334+
76335+ const { currentPass } = this.get( renderContext );
76336+ const { x, y, width, height } = renderContext.scissorValue;
76337+
76338+ currentPass.setScissorRect( x, y, width, height );
76339+
76340+ }
76341+
7627776342 /**
7627876343 * Returns the clear color and alpha into a single
7627976344 * color object.
@@ -77537,6 +77602,15 @@ class WebGPUBackend extends Backend {
7753777602 ]
7753877603 );
7753977604
77605+ // mipmaps must be genereated with the same encoder otherwise the copied texture data
77606+ // might be out-of-sync, see #31768
77607+
77608+ if ( texture.generateMipmaps ) {
77609+
77610+ this.textureUtils.generateMipmaps( texture, encoder );
77611+
77612+ }
77613+
7754077614 if ( renderContextData.currentPass ) {
7754177615
7754277616 const { descriptor } = renderContextData;
@@ -77561,9 +77635,7 @@ class WebGPUBackend extends Backend {
7756177635
7756277636 if ( renderContext.scissor ) {
7756377637
77564- const { x, y, width, height } = renderContext.scissorValue;
77565-
77566- renderContextData.currentPass.setScissorRect( x, y, width, height );
77638+ this.updateScissor( renderContext );
7756777639
7756877640 }
7756977641
@@ -77573,12 +77645,6 @@ class WebGPUBackend extends Backend {
7757377645
7757477646 }
7757577647
77576- if ( texture.generateMipmaps ) {
77577-
77578- this.textureUtils.generateMipmaps( texture );
77579-
77580- }
77581-
7758277648 }
7758377649
7758477650 dispose() {
0 commit comments