GPUBindGroupLayout:label 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

安全上下文: 此功能僅在安全上下文(HTTPS)中可用,且支援此功能的瀏覽器數量有限。

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

GPUBindGroupLayout 介面的 label 屬性提供了一個標籤,可用於標識該物件,例如在 GPUError 訊息或控制檯警告中。

可以透過在傳遞給原始 GPUDevice.createBindGroupLayout() 呼叫的描述符物件中提供 label 屬性來設定此項,也可以直接在 GPUBindGroupLayout 物件上獲取和設定它。

一個字串。如果之前未按上述方式設定,則為空字串。

示例

透過 GPUBindGroupLayout.label 設定和獲取標籤

js
// …

const bindGroupLayout = device.createBindGroupLayout({
  entries: [
    {
      binding: 0,
      visibility: GPUShaderStage.COMPUTE,
      buffer: {
        type: "storage",
      },
    },
  ],
});

bindGroupLayout.label = "my_bind_group_layout";

console.log(bindGroupLayout.label); // "my_bind_group_layout"

透過原始 GPUDevice.createBindGroupLayout() 呼叫設定標籤,然後透過 GPUBindGroupLayout.label 獲取它

js
// …

const bindGroupLayout = device.createBindGroupLayout({
  entries: [
    {
      binding: 0,
      visibility: GPUShaderStage.COMPUTE,
      buffer: {
        type: "storage",
      },
    },
  ],
  label: "my_bind_group_layout",
});

console.log(bindGroupLayout.label); // "my_bind_group_layout"

規範

規範
WebGPU
# dom-gpuobjectbase-label

瀏覽器相容性

另見