WebGPU (Chrome 118) में नया क्या है

François Beaufort
François Beaufort

copyExternalImageToTexture() में HTMLImageElement और ImageData के लिए सहायता

GPUQueue पर copyExternalImageToTexture() तरीके का इस्तेमाल करके, किसी सोर्स इमेज, वीडियो या कैनवस से लिए गए स्नैपशॉट को किसी GPUTexture में कॉपी किया जा सकता है. अब HTMLImageElement और ImageData ऑब्जेक्ट को सोर्स के तौर पर पास किया जा सकता है. यहां दिया गया उदाहरण देखें और issue 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);

रीड-राइट और रीड-ओनली स्टोरेज टेक्सचर के लिए एक्सपेरिमेंटल सपोर्ट

स्टोरेज टेक्सचर बाइंडिंग टाइप की मदद से, बिना सैंपलिंग के टेक्सचर रीड किए जा सकते हैं. साथ ही, उन्हें शेडर में किसी भी जगह पर सेव किया जा सकता है. अगर किसी GPUAdapter में "chromium-experimental-read-write-storage-texture" सुविधा उपलब्ध है, तो अब इस सुविधा के साथ GPUDevice का अनुरोध किया जा सकता है. साथ ही, बाइंड ग्रुप लेआउट बनाते समय, GPUStorageTexture ऐक्सेस को "read-write" या "read-only" पर सेट किया जा सकता है. पहले, यह सुविधा सिर्फ़ "write-only" के लिए उपलब्ध थी.

इस सुविधा का फ़ायदा पाने के लिए, आपको enable chromium_experimental_read_write_storage_texture का इस्तेमाल करके, अपने WGSL कोड में इस एक्सटेंशन को साफ़ तौर पर चालू करना होगा. इस सुविधा के चालू होने पर, स्टोरेज टेक्सचर के लिए read_write और read ऐक्सेस क्वालिफ़ायर का इस्तेमाल किया जा सकता है. साथ ही, textureLoad() और textureStore() बिल्ट-इन फ़ंक्शन इसी के मुताबिक काम करते हैं. इसके अलावा, वर्कग्रुप में टेक्सचर मेमोरी ऐक्सेस को सिंक करने के लिए, नया textureBarrier() बिल्ट-इन फ़ंक्शन उपलब्ध होता है. यहां दिया गया उदाहरण देखें और issue 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.

सुबह के अपडेट

webgpu.h C API में, एक जैसे नाम रखने के लिए इन फ़ील्ड के नाम बदल दिए गए हैं: requiredFeaturesCount से requiredFeatureCount, pipelineStatisticsCount से pipelineStatisticCount, और colorFormatsCount से colorFormatCount. issue dawn: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 140

Chrome 139

Chrome 138

Chrome 137

Chrome 136

Chrome 135

Chrome 134

Chrome 133

Chrome 132

Chrome 131

Chrome 130

Chrome 129

Chrome 128

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