GPUAdapter

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

Giao diện GPUAdapter của WebGPU API đại diện cho một bộ điều hợp GPU. Từ đây bạn có thể yêu cầu GPUDevice, thông tin bộ điều hợp, tính năng và giới hạn.

Một đối tượng GPUAdapter được yêu cầu bằng phương thức GPU.requestAdapter().

Thuộc tính phiên bản

features Read only

Một đối tượng GPUSupportedFeatures mô tả các chức năng bổ sung được bộ điều hợp hỗ trợ.

info Read only

Một đối tượng GPUAdapterInfo chứa thông tin nhận diện về bộ điều hợp.

limits Read only

Một đối tượng GPUSupportedLimits mô tả các giới hạn được bộ điều hợp hỗ trợ.

Thuộc tính đã lỗi thời

isFallbackAdapter Read only Deprecated Non-standard

Giá trị boolean. Trả về true nếu bộ điều hợp là fallback adapter, và false nếu không. Thuộc tính này đã bị xóa khỏi nền tảng web. Hãy dùng GPUAdapterInfo.isFallbackAdapter thay thế.

Phương thức phiên bản

requestAdapterInfo() Deprecated Non-standard

Trả về một Promise phân giải thành một đối tượng GPUAdapterInfo chứa thông tin nhận diện về bộ điều hợp.

requestDevice()

Trả về một Promise phân giải thành một đối tượng GPUDevice, là giao diện chính để giao tiếp với GPU.

Ví dụ

js
async function init() {
  if (!navigator.gpu) {
    throw Error("WebGPU not supported.");
  }

  const adapter = await navigator.gpu.requestAdapter();
  if (!adapter) {
    throw Error("Couldn't request WebGPU adapter.");
  }

  const device = await adapter.requestDevice();

  // …
}

Thông số kỹ thuật

Specification
WebGPU
# gpuadapter

Tương thích trình duyệt

Xem thêm