|
@@ -1,3 +1,5 @@
|
|
|
+import WebGPUProgrammableStage from './WebGPUProgrammableStage.js';
|
|
|
+
|
|
|
class WebGPUComputePipelines {
|
|
|
|
|
|
constructor( device, glslang ) {
|
|
@@ -6,7 +8,7 @@ class WebGPUComputePipelines {
|
|
|
this.glslang = glslang;
|
|
|
|
|
|
this.pipelines = new WeakMap();
|
|
|
- this.shaderModules = {
|
|
|
+ this.stages = {
|
|
|
compute: new WeakMap()
|
|
|
};
|
|
|
|
|
@@ -16,38 +18,31 @@ class WebGPUComputePipelines {
|
|
|
|
|
|
let pipeline = this.pipelines.get( param );
|
|
|
|
|
|
+ // @TODO: Reuse compute pipeline if possible
|
|
|
+
|
|
|
if ( pipeline === undefined ) {
|
|
|
|
|
|
const device = this.device;
|
|
|
+ const glslang = this.glslang;
|
|
|
+
|
|
|
const shader = {
|
|
|
computeShader: param.shader
|
|
|
};
|
|
|
|
|
|
- // shader modules
|
|
|
-
|
|
|
- const glslang = this.glslang;
|
|
|
-
|
|
|
- let moduleCompute = this.shaderModules.compute.get( shader );
|
|
|
+ // programmable stage
|
|
|
|
|
|
- if ( moduleCompute === undefined ) {
|
|
|
+ let stageCompute = this.stages.compute.get( shader );
|
|
|
|
|
|
- const byteCodeCompute = glslang.compileGLSL( shader.computeShader, 'compute' );
|
|
|
+ if ( stageCompute === undefined ) {
|
|
|
|
|
|
- moduleCompute = device.createShaderModule( { code: byteCodeCompute } );
|
|
|
+ stageCompute = new WebGPUProgrammableStage( device, glslang, shader.computeShader, 'compute' );
|
|
|
|
|
|
- this.shaderModules.compute.set( shader, moduleCompute );
|
|
|
+ this.stages.compute.set( shader, stageCompute );
|
|
|
|
|
|
}
|
|
|
|
|
|
- //
|
|
|
-
|
|
|
- const compute = {
|
|
|
- module: moduleCompute,
|
|
|
- entryPoint: 'main'
|
|
|
- };
|
|
|
-
|
|
|
pipeline = device.createComputePipeline( {
|
|
|
- compute: compute
|
|
|
+ compute: stageCompute.stage
|
|
|
} );
|
|
|
|
|
|
this.pipelines.set( param, pipeline );
|
|
@@ -61,7 +56,7 @@ class WebGPUComputePipelines {
|
|
|
dispose() {
|
|
|
|
|
|
this.pipelines = new WeakMap();
|
|
|
- this.shaderModules = {
|
|
|
+ this.stages = {
|
|
|
compute: new WeakMap()
|
|
|
};
|
|
|
|