HTMLImageElement and ImageData support in copyExternalImageToTexture()
The copyExternalImageToTexture()
method on GPUQueue
allows you to copy a snapshot taken from a source image, video, or canvas into a given GPUTexture
. You can now pass HTMLImageElement
and ImageData
objects as the source. See the following example and 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);
Experimental support for read-write and read-only storage texture
The storage texture binding type allows you to perform texture reads without sampling and store to arbitrary positions in shaders. When the "chromium-experimental-read-write-storage-texture"
feature is available in a GPUAdapter
, you can now request a GPUDevice
with this feature and set GPUStorageTexture
access to either "read-write"
or "read-only"
when creating a bind group layout. Previously this was restricted to "write-only"
.
To take advantage of this, you must explicitly enable this extension in your WGSL code with enable chromium_experimental_read_write_storage_texture
. When enabled, you 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. See the following example and issue dawn:1972.
This feature is still experimental and may change. While it’s getting standardized, run chrome with the --enable-dawn-features=allow_unsafe_apis
flag to make it available.
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 updates
The webgpu.h C API has renamed the following fields for consistency: requiredFeaturesCount
to requiredFeatureCount
, pipelineStatisticsCount
to pipelineStatisticCount
, and colorFormatsCount
to colorFormatCount
. See issue dawn:146040.
A new DawnInfo
program (similar to vulkaninfo) allows you to list toggles, adapters, adapter features and adapter limits. It is available when building dawn samples
. Here’s the output below heavily trimmed for brevity. See 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
[…]
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 129
Chrome 128
- Experimenting with subgroups
- Deprecate setting depth bias for lines and points
- Hide uncaptured error DevTools warning if preventDefault
- WGSL interpolate sampling first and either
- Dawn updates
Chrome 127
- Experimental support for OpenGL ES on Android
- GPUAdapter info attribute
- WebAssembly interop improvements
- Improved command encoder errors
- Dawn updates
Chrome 126
- Increase maxTextureArrayLayers limit
- Buffer upload optimization for Vulkan backend
- Shader compilation time improvements
- Submitted command buffers must be unique
- Dawn updates
Chrome 125
Chrome 124
- Read-only and read-write storage textures
- Service workers and shared workers support
- New adapter information attributes
- Bug fixes
- Dawn updates
Chrome 123
- DP4a built-in functions support in WGSL
- Unrestricted pointer parameters in WGSL
- Syntax sugar for dereferencing composites in WGSL
- Separate read-only state for stencil and depth aspects
- Dawn updates
Chrome 122
- Expand reach with compatibility mode (feature in development)
- Increase maxVertexAttributes limit
- Dawn updates
Chrome 121
- Support WebGPU on Android
- Use DXC instead of FXC for shader compilation on Windows
- Timestamp queries in compute and render passes
- Default entry points to shader modules
- Support display-p3 as GPUExternalTexture color space
- Memory heaps info
- Dawn updates
Chrome 120
- Support for 16-bit floating-point values in WGSL
- Push the limits
- Changes to depth-stencil state
- Adapter information updates
- Timestamp queries quantization
- Spring-cleaning features
Chrome 119
- Filterable 32-bit float textures
- unorm10-10-10-2 vertex format
- rgb10a2uint texture format
- Dawn updates
Chrome 118
- HTMLImageElement and ImageData support in
copyExternalImageToTexture()
- Experimental support for read-write and read-only storage texture
- Dawn updates
Chrome 117
- Unset vertex buffer
- Unset bind group
- Silence errors from async pipeline creation when device is lost
- SPIR-V shader module creation updates
- Improving developer experience
- Caching pipelines with automatically generated layout
- Dawn updates
Chrome 116
- WebCodecs integration
- Lost device returned by GPUAdapter
requestDevice()
- Keep video playback smooth if
importExternalTexture()
is called - Spec conformance
- Improving developer experience
- Dawn updates
Chrome 115
- Supported WGSL language extensions
- Experimental support for Direct3D 11
- Get discrete GPU by default on AC power
- Improving developer experience
- Dawn updates
Chrome 114
- Optimize JavaScript
- getCurrentTexture() on unconfigured canvas throws InvalidStateError
- WGSL updates
- Dawn updates