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

François Beaufort
François Beaufort

CopyExternalImageToTexture() में HTMLImageElement और ImageData काम करता है

GPUQueue में बताए गए copyExternalImageToTexture() तरीके से, किसी सोर्स इमेज, वीडियो या कैनवस से लिए गए स्नैपशॉट को किसी 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);

पढ़ने-लिखने और केवल पढ़ने के लिए मेमोरी टेक्स्चर के लिए प्रयोगात्मक समर्थन

स्टोरेज टेक्सचर बाइंडिंग टाइप, आपको बिना सैंपलिंग के टेक्सचर रीड करने और शेडर में आर्बिट्रेरी पोज़िशन में स्टोर करने की अनुमति देता है. जब 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() बिल्ट-इन फ़ंक्शन उपलब्ध है. नीचे दिया गया उदाहरण और समस्या सुबह: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. समस्या dawn:146040 देखें.

vulkaninfo की तरह एक नए DawnInfo प्रोग्राम में, टॉगल, अडैप्टर, अडैप्टर की सुविधाएं, और अडैप्टर की सीमाएं सेट की जा सकती हैं. यह तब उपलब्ध होता है, जब सुबह 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 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