GPUComputePipeline:label 属性

可用性有限

此特性不是基线特性,因为它在一些最广泛使用的浏览器中不起作用。

安全上下文: 此功能仅在安全上下文(HTTPS)中可用,且支持此功能的浏览器数量有限。

注意:此功能在 Web Workers 中可用。

label 属性是 GPUComputePipeline 接口的一部分,它提供了一个可用于标识对象的标签,例如在 GPUError 消息或控制台警告中。

可以在调用 GPUDevice.createComputePipeline()GPUDevice.createComputePipelineAsync() 时,通过在传入的描述符对象中提供 label 属性来设置它,或者可以直接在 GPUComputePipeline 对象上获取和设置它。

一个字符串。如果之前未按上述方式设置,则为空字符串。

示例

通过 GPUComputePipeline.label 设置和获取标签

js
// …

const computePipeline = device.createComputePipeline({
  layout: device.createPipelineLayout({
    bindGroupLayouts: [bindGroupLayout],
  }),
  compute: {
    module: shaderModule,
    entryPoint: "main",
  },
});

computePipeline.label = "my_compute_pipeline";

console.log(computePipeline.label); // "my_compute_pipeline"

通过 GPUDevice.createComputePipeline() 调用设置标签,然后通过 GPUComputePipeline.label 获取它

js
// …

const computePipeline = device.createComputePipeline({
  layout: device.createPipelineLayout({
    bindGroupLayouts: [bindGroupLayout],
  }),
  compute: {
    module: shaderModule,
    entryPoint: "main",
  },
  label: "my_compute_pipeline",
});

console.log(computePipeline.label); // "my_compute_pipeline"

规范

规范
WebGPU
# dom-gpuobjectbase-label

浏览器兼容性

另见