มีอะไรใหม่ใน WebGPU (Chrome 118)

François Beaufort
François Beaufort

การรองรับ HTMLImageElement และ ImageData ใน copyExternalImageToTexture()

เมธอด copyExternalImageToTexture() ใน GPUQueue ช่วยให้คุณคัดลอกสแนปชอตที่ถ่ายจากรูปภาพต้นฉบับ วิดีโอ หรือแคนวาสไปยัง GPUTexture ที่ต้องการได้ ตอนนี้คุณสามารถส่งผ่านออบเจ็กต์ HTMLImageElement และ ImageData เป็นแหล่งที่มาได้แล้ว ดูตัวอย่างและปัญหา chromium:1471372 ต่อไปนี้

// Fetch and decode image.
const source = document.createElement("img");
source.src = "my-image.png";
await source.decode();

// Create destination texture.
const size = [source.width, source.height];
const texture = myDevice.createTexture({
 size,
 format: "rgba8unorm",
 usage:
   GPUTextureUsage.COPY_DST |
   GPUTextureUsage.RENDER_ATTACHMENT |
   GPUTextureUsage.TEXTURE_BINDING,
});

// Copies a snapshot taken from the source image into a texture.
myDevice.queue.copyExternalImageToTexture({ source }, { texture }, size);

การทดสอบการรองรับพื้นผิวพื้นที่เก็บข้อมูลแบบอ่านอย่างเดียวและอ่านอย่างเดียว

ประเภทการเชื่อมโยงพื้นผิวพื้นที่เก็บข้อมูลช่วยให้คุณอ่านพื้นผิวได้โดยไม่ต้องสุ่มตัวอย่างและจัดเก็บตามตำแหน่งที่กำหนดเองในเครื่องมือเฉดสี เมื่อฟีเจอร์ "chromium-experimental-read-write-storage-texture" พร้อมใช้งานใน GPUAdapter ตอนนี้คุณสามารถขอ GPUDevice ด้วยฟีเจอร์นี้และตั้งค่าสิทธิ์เข้าถึง GPUStorageTexture เป็น "read-write" หรือ "read-only" เมื่อสร้างเลย์เอาต์การเชื่อมโยงกลุ่มได้แล้ว ก่อนหน้านี้มีการจำกัดไว้เพียง "write-only"

ในการใช้ประโยชน์จากสิ่งนี้ คุณต้องเปิดใช้ส่วนขยายนี้อย่างชัดเจนในโค้ด WGSL ด้วย enable chromium_experimental_read_write_storage_texture เมื่อเปิดใช้ คุณจะใช้ตัวระบุการเข้าถึง read_write และ read สำหรับพื้นผิวพื้นที่เก็บข้อมูลได้ ฟังก์ชัน textureLoad() และ textureStore() จะทํางานตามนั้น รวมถึงมีฟังก์ชัน textureBarrier() ในตัวใหม่ที่พร้อมสำหรับซิงค์การเข้าถึงหน่วยความจำพื้นผิวในกลุ่มงาน ดูตัวอย่างและปัญหา dawn:1972

ฟีเจอร์นี้ยังอยู่ระหว่างการทดสอบและอาจมีการเปลี่ยนแปลง ขณะที่กำลังทำให้ได้มาตรฐาน ให้เรียกใช้ Chrome ด้วยธง --enable-dawn-features=allow_unsafe_apis เพื่อให้พร้อมใช้งาน

const feature = "chromium-experimental-read-write-storage-texture";
const adapter = await navigator.gpu.requestAdapter();
if (!adapter.features.has(feature)) {
  throw new Error("Read-write storage texture support is not available");
}
// Explicitly request read-write storage texture support.
const device = await adapter.requestDevice({
  requiredFeatures: [feature],
});

const bindGroupLayout = device.createBindGroupLayout({
  entries: [{
    binding: 0,
    visibility: GPUShaderStage.COMPUTE,
    storageTexture: {
      access: "read-write", // <-- New!
      format: "r32uint",
    },
  }],
});

const shaderModule = device.createShaderModule({ code: `
  enable chromium_experimental_read_write_storage_texture;
  @group(0) @binding(0) var tex : texture_storage_2d<r32uint, read_write>;

  @compute @workgroup_size(1, 1)
  fn main(@builtin(local_invocation_id) local_id: vec3u) {
    var data = textureLoad(tex, vec2i(local_id.xy));
    data.x *= 2;
    textureStore(tex, vec2i(local_id.xy), data);
  }`,
});

// You can now create a compute pipeline with this shader module and
// send the appropriate commands to the GPU.

ข้อมูลอัปเดตรุ่งเช้า

C API webgpu.h ได้เปลี่ยนชื่อช่องต่อไปนี้ requiredFeaturesCount เป็น requiredFeatureCount, pipelineStatisticsCount เป็น pipelineStatisticCount และ colorFormatsCount เป็น colorFormatCount ดูปัญหา dawn:146040

โปรแกรม DawnInfo ใหม่ (คล้ายกับ vulkaninfo) ช่วยให้คุณแสดงรายการปุ่มเปิด/ปิด อะแดปเตอร์ ฟีเจอร์อะแดปเตอร์ และขีดจำกัดของอะแดปเตอร์ได้ มีให้บริการเมื่อสร้างรุ่งเช้าเวลา samples นี่คือผลลัพธ์ด้านล่างที่มีการตัดให้สั้นลงเพื่อความกระชับ โปรดดูเปลี่ยน dawn:149020

./out/Debug/DawnInfo
Toggles
=======
  Name: allow_unsafe_apis
    Suppresses validation errors on API entry points or parameter combinations
    that aren't considered secure yet.
    http://crbug.com/1138528
[…]

Adapter
=======
VendorID: 0x106B
Vendor: apple
Architecture: common-3
DeviceID: 0x0000
Name: Apple M1 Pro
Driver description: Metal driver on macOS Version 13.5.1 (Build 22G90)
Adapter Type: discrete GPU
Backend Type: Metal
Power: <undefined>

  Features
  ========
   * depth_clip_control
      Disable depth clipping of primitives to the clip volume
      https://bugs.chromium.org/p/dawn/issues/detail?id=1178
[…]

  Adapter Limits
  ==============
    maxTextureDimension1D: 16,384
    maxTextureDimension2D: 16,384
[…]

ซึ่งกล่าวถึงไฮไลต์สำคัญเพียงบางส่วนเท่านั้น ดูรายการคอมมิตทั้งหมด

มีอะไรใหม่ใน WebGPU

รายการทั้งหมดที่กล่าวถึงในซีรีส์ What's New in WebGPU

Chrome 127

Chrome 126

Chrome 125

Chrome 124

Chrome 123

Chrome 122

Chrome 121

Chrome 120

Chrome 119

Chrome 118

Chrome 117

Chrome 116

Chrome 115

Chrome 114

Chrome 113