Skip to content

Commit 52bc19c

Browse files
authored
WebGPURenderer: Don't set redundant state (#26186)
* BufferAttribute: Added .uuid * WebGPURenderer: Don't set redundant state * cleanup * BufferAttribute: Fix serialization and tests * Attributes: Rename .getUUID() to .getHash() * Attributes: Rename .getHash() to .getUUID() * BufferGeometryLoader: Fix undefined uuid * cleanup * Reverting
1 parent ed7d2ca commit 52bc19c

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

examples/jsm/renderers/webgpu/WebGPUBackend.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*// debugger tools
2+
import 'https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-check-redundant-state-setting.js';
3+
//*/
4+
15
import { GPUFeatureName, GPUTextureFormat, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension } from './utils/WebGPUConstants.js';
26

37
import WebGPUNodeBuilder from './nodes/WGSLNodeBuilder.js';
@@ -243,6 +247,7 @@ class WebGPUBackend extends Backend {
243247
renderContextData.descriptor = descriptor;
244248
renderContextData.encoder = encoder;
245249
renderContextData.currentPass = currentPass;
250+
renderContextData.currentAttributesSet = {};
246251

247252
//
248253

@@ -395,6 +400,7 @@ class WebGPUBackend extends Backend {
395400
const bindingsData = this.get( renderObject.getBindings() );
396401
const contextData = this.get( context );
397402
const pipelineGPU = this.get( pipeline ).pipeline;
403+
const attributesSet = contextData.currentAttributesSet;
398404

399405
// pipeline
400406

@@ -406,18 +412,26 @@ class WebGPUBackend extends Backend {
406412
const bindGroupGPU = bindingsData.group;
407413
passEncoderGPU.setBindGroup( 0, bindGroupGPU );
408414

409-
// index
415+
// attributes
410416

411417
const index = renderObject.getIndex();
412418

413419
const hasIndex = ( index !== null );
414420

421+
// index
422+
415423
if ( hasIndex === true ) {
416424

417-
const buffer = this.get( index ).buffer;
418-
const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
425+
if ( attributesSet.index !== index ) {
426+
427+
const buffer = this.get( index ).buffer;
428+
const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32;
429+
430+
passEncoderGPU.setIndexBuffer( buffer, indexFormat );
431+
432+
attributesSet.index = index;
419433

420-
passEncoderGPU.setIndexBuffer( buffer, indexFormat );
434+
}
421435

422436
}
423437

@@ -427,8 +441,16 @@ class WebGPUBackend extends Backend {
427441

428442
for ( let i = 0, l = attributes.length; i < l; i ++ ) {
429443

430-
const buffer = this.get( attributes[ i ] ).buffer;
431-
passEncoderGPU.setVertexBuffer( i, buffer );
444+
const attribute = attributes[ i ];
445+
446+
if ( attributesSet[ i ] !== attribute ) {
447+
448+
const buffer = this.get( attribute ).buffer;
449+
passEncoderGPU.setVertexBuffer( i, buffer );
450+
451+
attributesSet[ i ] = attribute;
452+
453+
}
432454

433455
}
434456

@@ -703,6 +725,7 @@ class WebGPUBackend extends Backend {
703725
if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load;
704726

705727
renderContextData.currentPass = encoder.beginRenderPass( descriptor );
728+
renderContextData.currentAttributesSet = {};
706729

707730
}
708731

0 commit comments

Comments
 (0)