What's New in WebGPU (Chrome 124)

François Beaufort
François Beaufort

Read-only and read-write storage textures

The storage texture binding type allows shaders to read from storage textures without adding the TEXTURE_BINDING usage, and perform mixed reads and writes on certain formats. When the "readonly_and_readwrite_storage_textures" WGSL language extension is present in navigator.gpu.wgslLanguageFeatures, you can now set GPUStorageTexture access to either "read-write" or "read-only" when creating a bind group layout. Previously this was restricted to "write-only".

Then, your WGSL shader code can use read_write and read access qualifier for storage textures, the textureLoad() and textureStore() built-in functions behave accordingly, and a new textureBarrier() built-in function is available to synchronize texture memory accesses in a workgroup.

It's recommended to use a requires-directive to signal the potential for non-portability with requires readonly_and_readwrite_storage_textures; at the top of your WGSL shader code. See the following example and issue dawn:1972.

if (!navigator.gpu.wgslLanguageFeatures.has("readonly_and_readwrite_storage_textures")) {
  throw new Error("Read-only and read-write storage textures are not available");
}

const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();

const bindGroupLayout = device.createBindGroupLayout({
  entries: [{
    binding: 0,
    visibility: GPUShaderStage.COMPUTE,
    storageTexture: {
      access: "read-write", // <-- New!
      format: "r32uint",
    },
  }],
});

const shaderModule = device.createShaderModule({ code: `
  requires readonly_and_readwrite_storage_textures;

  @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.

Service workers and shared workers support

WebGPU in Chrome takes web workers support to the next level, now offering support for both service workers and shared workers. You can use service workers to enhance background tasks and offline capabilities, and shared workers for efficient resource sharing across scripts. See issue chromium:41494731.

Check out the chrome extension sample and WebLLM chrome extension to see how to use WebGPU in an extension service worker.

Screenshot of the WebLLM chrome extension.
WebLLM chrome extension.

New adapter information attributes

Non-standard d3dShaderModel and vkDriverVersion adapter info attributes are now available upon calling requestAdapterInfo() if the user has enabled the "WebGPU Developer Features" flag at chrome://flags/#enable-webgpu-developer-features. When supported:

Screenshot of https://webgpureport.org featuring vkDriverVersion in adapter info.
Adapter info vkDriverVersion shown on https://webgpureport.org.

Bug fixes

Creating two pipelines with matching bindgroups using layout: "auto", then creating a bindgroup with the first pipeline, and using it on the second pipeline now raises a GPUValidationError. Allowing it was an implementation bug which is now fixed with proper tests. See issue dawn:2402.

Dawn updates

In the Dawn API, the uncaptured error callback set with wgpuDeviceSetUncapturedErrorCallback is now not called after the GPU device is lost. This fix aligns Dawn with the JavaScript API specification and Blink's implementation. See issue dawn:2459.

This covers only some of the key highlights. Check out the exhaustive list of commits.

What's New in WebGPU

A list of everything that has been covered in the What's New in WebGPU series.

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