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

François Beaufort
François Beaufort

कॉपीExternalImageToTexture() में 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.

Dawn के अपडेट

webgpu.h C API ने एकता से जुड़े इन फ़ील्ड के नाम बदल दिए हैं: requiredFeaturesCount से requiredFeatureCount, pipelineStatisticsCount से pipelineStatisticCount, और colorFormatsCount से colorFormatCount. जारी करने का समय:146040 देखें.

vulkaninfo से मिलते-जुलते एक नए DawnInfo प्रोग्राम की मदद से, टॉगल, अडैप्टर, अडैप्टर की सुविधाओं, और अडैप्टर की सीमाओं की सूची बनाई जा सकती है. यह सुविधा, samples सुबह तैयार होने पर उपलब्ध होती है. यह रहा वह आउटपुट, जिसमें कम शब्दों में सटीक जानकारी के लिए काफ़ी काट-छांट की गई है. बदलाव सुबह: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