UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

46 lines (43 loc) 1.71 kB
import { DebugHelper, Debug } from '../../../core/debug.js'; import { TRACEID_COMPUTEPIPELINE_ALLOC } from '../../../core/constants.js'; import { WebgpuDebug } from './webgpu-debug.js'; import { WebgpuPipeline } from './webgpu-pipeline.js'; /** * @import { WebgpuShader } from './webgpu-shader.js' */ var _pipelineId = 0; class WebgpuComputePipeline extends WebgpuPipeline { get(shader, bindGroupFormat) { // pipeline layout var pipelineLayout = this.getPipelineLayout([ bindGroupFormat.impl ]); // TODO: this could be cached var pipeline = this.create(shader, pipelineLayout); return pipeline; } create(shader, pipelineLayout) { var wgpu = this.device.wgpu; /** @type {WebgpuShader} */ var webgpuShader = shader.impl; /** @type {GPUComputePipelineDescriptor} */ var desc = { compute: { module: webgpuShader.getComputeShaderModule(), entryPoint: webgpuShader.computeEntryPoint }, // uniform / texture binding layout layout: pipelineLayout }; WebgpuDebug.validate(this.device); _pipelineId++; DebugHelper.setLabel(desc, "ComputePipelineDescr-" + _pipelineId); var pipeline = wgpu.createComputePipeline(desc); DebugHelper.setLabel(pipeline, "ComputePipeline-" + _pipelineId); Debug.trace(TRACEID_COMPUTEPIPELINE_ALLOC, "Alloc: Id " + _pipelineId, desc); WebgpuDebug.end(this.device, 'ComputePipeline creation', { computePipeline: this, desc: desc, shader }); return pipeline; } } export { WebgpuComputePipeline };