מה חדש ב-WebGPU (Chrome {8/}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.

עדכונים בשעות השחר

ה-C API של webgpu.h שינה את השמות של השדות הבאים לשמירה על עקביות: requiredFeaturesCount ל-requiredFeatureCount, pipelineStatisticsCount ל-pipelineStatisticCount ו-colorFormatsCount ל-colorFormatCount. לעיון בעלות השחר: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

רשימה של כל מה שמכוסה בסדרה מה חדש ב-WebGPU.

Chrome 125

Chrome 124

Chrome 123

גרסה 122 של Chrome

גרסה 121 של Chrome

Chrome 120

גרסה 119 של Chrome

גרסה 118 של Chrome

גרסה 117 של Chrome

גרסה 116 של Chrome

Chrome 115

Chrome 114

גרסה 113 של Chrome