GPUComputePipeline: getBindGroupLayout() 方法
注意:此功能在 Web Workers 中可用。
getBindGroupLayout() 方法是 GPUComputePipeline 接口的一部分,它会返回管道的 GPUBindGroupLayout 对象,其索引与原始的 GPUDevice.createComputePipeline() 或 GPUDevice.createComputePipelineAsync() 调用中的管道布局给出的索引相对应。
如果 GPUComputePipeline 是使用 layout: "auto" 创建的,那么此方法是检索由管道生成的 GPUBindGroupLayouts 的唯一途径。
语法
js
getBindGroupLayout(index)
参数
index-
一个数字,表示要返回的
GPUBindGroupLayout的索引。
返回值
一个 GPUBindGroupLayout 对象实例。
验证
调用 getBindGroupLayout() 时必须满足以下条件,否则将生成 GPUValidationError 并返回一个无效的 GPUBindGroupLayout 对象。
index小于管道布局中使用的GPUBindGroupLayout对象的数量。
示例
注意: 在 WebGPU 示例中,您可以看到 getBindGroupLayout() 的完整工作示例。
js
// …
// Create a compute pipeline using layout: "auto" to automatically generate
// appropriate bind group layouts
const computePipeline = device.createComputePipeline({
layout: "auto",
compute: {
module: shaderModule,
entryPoint: "main",
},
});
// Create a bind group with the auto-generated layout from the compute pipeline
const computeBindGroup = device.createBindGroup({
layout: computePipeline.getBindGroupLayout(0),
entries: [
{
binding: 0,
resource: { buffer: storageBuffer },
},
],
});
// …
规范
| 规范 |
|---|
| WebGPU # dom-gpupipelinebase-getbindgrouplayout |
浏览器兼容性
加载中…