@@ -5,6 +5,7 @@ import WebGPUGeometries from './WebGPUGeometries.js';
55import WebGPUInfo from './WebGPUInfo.js' ;
66import WebGPUProperties from './WebGPUProperties.js' ;
77import WebGPURenderPipelines from './WebGPURenderPipelines.js' ;
8+ import WebGPUComputePipelines from './WebGPUComputePipelines.js' ;
89import WebGPUBindings from './WebGPUBindings.js' ;
910import WebGPURenderLists from './WebGPURenderLists.js' ;
1011import WebGPUTextures from './WebGPUTextures.js' ;
@@ -99,6 +100,7 @@ class WebGPURenderer {
99100 this . _bindings = null ;
100101 this . _objects = null ;
101102 this . _renderPipelines = null ;
103+ this . _computePipelines = null ;
102104 this . _renderLists = null ;
103105 this . _textures = null ;
104106 this . _background = null ;
@@ -174,7 +176,8 @@ class WebGPURenderer {
174176 this . _textures = new WebGPUTextures ( device , this . _properties , this . _info , compiler ) ;
175177 this . _objects = new WebGPUObjects ( this . _geometries , this . _info ) ;
176178 this . _renderPipelines = new WebGPURenderPipelines ( this , this . _properties , device , compiler , parameters . sampleCount ) ;
177- this . _bindings = new WebGPUBindings ( device , this . _info , this . _properties , this . _textures , this . _renderPipelines ) ;
179+ this . _computePipelines = new WebGPUComputePipelines ( device , compiler ) ;
180+ this . _bindings = new WebGPUBindings ( device , this . _info , this . _properties , this . _textures , this . _renderPipelines , this . _computePipelines , this . _attributes ) ;
178181 this . _renderLists = new WebGPURenderLists ( ) ;
179182 this . _background = new WebGPUBackground ( this ) ;
180183
@@ -510,6 +513,7 @@ class WebGPURenderer {
510513 this . _objects . dispose ( ) ;
511514 this . _properties . dispose ( ) ;
512515 this . _renderPipelines . dispose ( ) ;
516+ this . _computePipelines . dispose ( ) ;
513517 this . _bindings . dispose ( ) ;
514518 this . _info . dispose ( ) ;
515519 this . _renderLists . dispose ( ) ;
@@ -529,6 +533,34 @@ class WebGPURenderer {
529533
530534 }
531535
536+ compute ( computeParams ) {
537+
538+ const device = this . _device ;
539+ const cmdEncoder = device . createCommandEncoder ( { } ) ;
540+ const passEncoder = cmdEncoder . beginComputePass ( ) ;
541+
542+ for ( const param of computeParams ) {
543+
544+ // pipeline
545+
546+ const pipeline = this . _computePipelines . get ( param ) ;
547+ passEncoder . setPipeline ( pipeline ) ;
548+
549+ // bind group
550+
551+ const bindGroup = this . _bindings . getForCompute ( param ) . group ;
552+ this . _bindings . update ( param ) ;
553+ passEncoder . setBindGroup ( 0 , bindGroup ) ;
554+
555+ passEncoder . dispatch ( param . num ) ;
556+
557+ }
558+
559+ passEncoder . endPass ( ) ;
560+ device . defaultQueue . submit ( [ cmdEncoder . finish ( ) ] ) ;
561+
562+ }
563+
532564 getRenderTarget ( ) {
533565
534566 return this . _renderTarget ;
0 commit comments