The createComputePipeline() method of the GPUDevice interface creates a GPUComputePipeline that can control the compute shader stage and be used in a GPUComputePassEncoder.
createComputePipeline(descriptor)
A GPUComputePipeline object instance.
The following criteria must be met when calling createComputePipeline(), otherwise a GPUValidationError is generated and an invalid GPUComputePipeline object is returned:
- The workgroup storage size used by the
module referenced inside the compute property is less than or equal to the GPUDevice's maxComputeWorkgroupStorageSize limit. - The
module uses a number of compute invocations per workgroup less than or equal to the GPUDevice's maxComputeInvocationsPerWorkgroup limit. - The
module's workgroup size is less than or equal to the GPUDevice's corresponding maxComputeWorkgroupSizeX, maxComputeWorkgroupSizeY, or maxComputeWorkgroupSizeZ limit.
Our basic compute demo shows a process of:
const bindGroupLayout = device.createBindGroupLayout({
entries: [
{
binding: 0,
visibility: GPUShaderStage.COMPUTE,
buffer: {
type: "storage",
},
},
],
});
const computePipeline = device.createComputePipeline({
layout: device.createPipelineLayout({
bindGroupLayouts: [bindGroupLayout],
}),
compute: {
module: shaderModule,
entryPoint: "main",
},
});