มีอะไรใหม่ใน 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() ใหม่พร้อมใช้งานเพื่อซิงค์ข้อมูลการเข้าถึงหน่วยความจำพื้นผิวในกลุ่มงาน ดูตัวอย่างต่อไปนี้และปัญหารุ่งเช้า: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.

ข้อมูลอัปเดตเกี่ยวกับ Dawn

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

โปรแกรม DawnInfo ใหม่ (คล้ายกับ vulkaninfo) ช่วยให้คุณแสดงรายการปุ่มสลับ อะแดปเตอร์ ฟีเจอร์ของอะแดปเตอร์ และขีดจำกัดของอะแดปเตอร์ พร้อมให้ใช้งานเมื่อมีการรุ่งเช้า samples ต่อไปนี้เป็นผลลัพธ์ด้านล่างซึ่งตัดทอนอย่างมากเพื่อความสั้นกระชับ ดู change 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

รายการของทุกอย่างที่มีการพูดถึงในซีรีส์มีอะไรใหม่ใน WebGPU

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