Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions examples/jsm/renderers/webgpu/WebGPUComputePipelines.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import WebGPUProgrammableStage from './WebGPUProgrammableStage.js';

class WebGPUComputePipelines {

constructor( device, glslang ) {
Expand All @@ -6,7 +8,7 @@ class WebGPUComputePipelines {
this.glslang = glslang;

this.pipelines = new WeakMap();
this.shaderModules = {
this.stages = {
compute: new WeakMap()
};

Expand All @@ -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 );
Expand All @@ -61,7 +56,7 @@ class WebGPUComputePipelines {
dispose() {

this.pipelines = new WeakMap();
this.shaderModules = {
this.stages = {
compute: new WeakMap()
};

Expand Down
6 changes: 3 additions & 3 deletions examples/jsm/renderers/webgpu/WebGPURenderPipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ class WebGPURenderPipelines {

}

stageVertex.usedTimes ++;
stageFragment.usedTimes ++;

// determine render pipeline

currentPipeline = this._acquirePipeline( stageVertex, stageFragment, object, nodeBuilder );
Expand All @@ -83,7 +80,10 @@ class WebGPURenderPipelines {
if ( materialPipelines.has( currentPipeline ) === false ) {

materialPipelines.add( currentPipeline );

currentPipeline.usedTimes ++;
stageVertex.usedTimes ++;
stageFragment.usedTimes ++;

}

Expand Down