-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
WebGPURenderer: Don't set redundant state #26186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
c9ce570
95cf8c4
a0c4bf7
f57f1af
08a64ee
809d821
c384b57
7b004f7
442d2e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| /*// debugger tools | ||
| import 'https://greggman.github.io/webgpu-avoid-redundant-state-setting/webgpu-check-redundant-state-setting.js'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @greggman I've added its lib here, so it can inspire other developers to build good tools for it :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can add some debug toggle (for example, global variable like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah... And maybe place There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think |
||
| //*/ | ||
|
|
||
| import { GPUFeatureName, GPUTextureFormat, GPULoadOp, GPUStoreOp, GPUIndexFormat, GPUTextureViewDimension } from './utils/WebGPUConstants.js'; | ||
|
|
||
| import WebGPUNodeBuilder from './nodes/WGSLNodeBuilder.js'; | ||
|
|
@@ -243,6 +247,7 @@ class WebGPUBackend extends Backend { | |
| renderContextData.descriptor = descriptor; | ||
| renderContextData.encoder = encoder; | ||
| renderContextData.currentPass = currentPass; | ||
| renderContextData.currentAttributesSet = {}; | ||
|
|
||
| // | ||
|
|
||
|
|
@@ -395,6 +400,7 @@ class WebGPUBackend extends Backend { | |
| const bindingsData = this.get( renderObject.getBindings() ); | ||
| const contextData = this.get( context ); | ||
| const pipelineGPU = this.get( pipeline ).pipeline; | ||
| const attributesSet = contextData.currentAttributesSet; | ||
|
|
||
| // pipeline | ||
|
|
||
|
|
@@ -406,18 +412,28 @@ class WebGPUBackend extends Backend { | |
| const bindGroupGPU = bindingsData.group; | ||
| passEncoderGPU.setBindGroup( 0, bindGroupGPU ); | ||
|
|
||
| // index | ||
| // attributes | ||
|
|
||
| const index = renderObject.getIndex(); | ||
|
|
||
| const hasIndex = ( index !== null ); | ||
|
|
||
| // index | ||
|
|
||
| if ( hasIndex === true ) { | ||
|
|
||
| const buffer = this.get( index ).buffer; | ||
| const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32; | ||
| const indexHash = renderObject.getIndexHash(); | ||
|
|
||
| passEncoderGPU.setIndexBuffer( buffer, indexFormat ); | ||
| if ( attributesSet.index !== indexHash ) { | ||
|
|
||
| const buffer = this.get( index ).buffer; | ||
| const indexFormat = ( index.array instanceof Uint16Array ) ? GPUIndexFormat.Uint16 : GPUIndexFormat.Uint32; | ||
|
|
||
| passEncoderGPU.setIndexBuffer( buffer, indexFormat ); | ||
|
|
||
| attributesSet.index = indexHash; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
@@ -427,8 +443,17 @@ class WebGPUBackend extends Backend { | |
|
|
||
| for ( let i = 0, l = attributes.length; i < l; i ++ ) { | ||
|
|
||
| const buffer = this.get( attributes[ i ] ).buffer; | ||
| passEncoderGPU.setVertexBuffer( i, buffer ); | ||
| const attribute = attributes[ i ]; | ||
| const attributeHash = renderObject.getAttributeHash( i ); | ||
|
|
||
| if ( attributesSet[ i ] !== attributeHash ) { | ||
|
|
||
| const buffer = this.get( attribute ).buffer; | ||
| passEncoderGPU.setVertexBuffer( i, buffer ); | ||
|
|
||
| attributesSet[ i ] = attributeHash; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
@@ -703,6 +728,7 @@ class WebGPUBackend extends Backend { | |
| if ( renderContext.stencil ) descriptor.depthStencilAttachment.stencilLoadOp = GPULoadOp.Load; | ||
|
|
||
| renderContextData.currentPass = encoder.beginRenderPass( descriptor ); | ||
| renderContextData.currentAttributesSet = {}; | ||
|
|
||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.