Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Webgpu Knowledge Patch?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/nevaberry-webgpu-knowledge-patch-nevaberry-plugins)
---
name: webgpu-knowledge-patch
description: WebGPU / WGSL
version: "Chrome 150"
license: MIT
metadata:
author: Nevaberry
---
# WebGPU / WGSL knowledge patch
Load this skill when updating WebGPU browser code, WGSL shaders, Dawn native
applications, or Emscripten builds. It covers API migrations, validation,
feature checks, shader behavior, and platform availability.
## Reference index
| Reference | Topics |
| --- | --- |
| [Browser API, pipeline, and pass behavior](references/browser-api-and-passes.md) | Device requests, limits, buffers, bind groups, vertex input, viewports, immediates, canvas integration |
| [Compatibility mode and platform availability](references/compatibility-and-platforms.md) | Compatibility requests and restrictions, adapter information, Android, Linux, WebXR, Kotlin bindings |
| [Dawn native APIs, builds, and Emscripten](references/dawn-native-and-emscripten.md) | Native migrations, callbacks, surfaces, resource features, headers, builds, diagnostics, browser bindings |
| [Textures, formats, and external images](references/textures-and-external-images.md) | Storage and blending, format tiers, views, video, image copies, compression, transient attachments |
| [WGSL language and shader behavior](references/wgsl-and-shaders.md) | Memory layout, buffer views, subgroups, indexing, fragment inputs and outputs, sampling, shader conversion |
## Breaking changes and deprecations
After `GPUAdapter.requestDevice()` succeeds, later calls on that adapter reject
their promises. Call `navigator.gpu.requestAdapter()` again before requesting
another device.
`GPUAdapter.isFallbackAdapter` has been removed. Read
`adapter.info.isFallbackAdapter`, or `device.adapterInfo.isFallbackAdapter`
when only a device is available. The release-specific fallback value is
documented in the compatibility reference.
| Affected code | Migration or validation behavior |
| --- | --- |
| `maxInterStageShaderComponents` | Removed; use `maxInterStageShaderVariables` and count inter-stage variables. |
| Blending into 32-bit float targets | Enable `"float32-blendable"`; `"float32-filterable"` no longer makes these targets blendable. |
| Read-only `"bgra8unorm"` storage bindings | Fail validation; use write-only storage access with this format. |
| `GPUDevice.createBuffer()` with `mappedAtCreation: true` | A size not divisible by four throws a synchronous `RangeError`; handle it at the call site if relying on a GPU validation error scope. |
| Explicit WGSL `@align(n)` | Rejected when smaller than the member's required alignment; `@align(16)` satisfies the requirement for `vec4f`. |
| `"chromium-experimental-subgroups"` and `"chromium-experimental-subgroup-uniform-control-flow"` | Removed; request `"subgroups"`. |
| `"subgroups-f16"` | Deprecated; request both `"subgroups"` and `"shader-f16"` for subgroup operations on `f16` values. |
| Emscripten `-sUSE_WEBGPU` | Replace with `--use-port=emdawnwebgpu`; Emscripten 4.0.10 or later includes a snapshot of the port. |
The experimental `GPUAdapter.featureLevel` and `GPUAdapter.isCompatibilityMode`
properties were removed. Request core capabilities when the adapter supports
them and check the resulting device to determine which validation rules apply.
## Native migration essentials
| Previous API or feature | Supported migration |
| --- | --- |
| `WGPUProgrammableStageDescriptor` for compute state | Use `WGPUComputeState`. |
| `wgpu::VertexStepMode::VertexBufferNotUsed` | Use `wgpu::VertexStepMode::Undefined` with `attributeCount` zero. |
| `WGPURequiredLimits`, `WGPUSupportedLimits` | Use `WGPULimits`, with limit fields directly on it. |
| `WGPUImageCopyBuffer` | Use `WGPUTexelCopyBufferInfo`. |
| `WGPUImageCopyTexture` | Use `WGPUTexelCopyTextureInfo`. |
| `WGPUTextureDataLayout` | Use `WGPUTexelCopyBufferLayout`. |
| `InstanceDropped` callback status | Use `CallbackCancelled`; associated work can continue after cancellation. |
| `wgpu::PopErrorScopeStatus::EmptyStack` | Use `wgpu::PopErrorScopeStatus::Error`; the callback includes an error message. |
| `wgpu::FeatureName::R8UnormStorage`, `wgpu::FeatureName::Snorm16TextureFormats` | Use `wgpu::FeatureName::TextureFormatsTier1`; tier 1 omits resolve support for 16-bit signed normalized formats. |
Use the implementation's shipped `webgpu.h` so implementation-specific
declarations match the library. `webgpu_upstream_cpp_headers` allows use of
`webgpu_cpp.h` with any implementation of the upstream `webgpu.h` API.
## Compatibility requests and validation
For experimental compatibility mode in Chrome 133, enable Unsafe WebGPU Support
at `chrome://flags/#enable-unsafe-webgpu` and request
`featureLevel: "compatibility"` in `requestAdapter()`. The supported levels are
`"core"` (the default) and `"compatibility"`. The compatibility reference
records subsequent flag and origin-trial conditions.
In Chrome 136, with Unsafe WebGPU Support enabled,
`"core-features-and-limits"` on the device lifts compatibility feature and
limit restrictions. A compatibility request can return a core-defaulting
adapter, which enables the feature on every device. A compatibility-defaulting
adapter can enable it on request if it advertises support.
Core adapters and devices expose this feature in the default browser configuration.
Applications within the compatibility subset run unchanged in browsers that
implement only core WebGPU. Tests expecting compatibility-specific validation
errors need a device with compatibility restrictions active.
Check `device.limits.maxStorageBuffersInVertexStage` before selecting a shader
variant with vertex storage-buffer bindings: this limit can be zero on
compatibility devices. OpenGL ES 3.1 supports Android compatibility mode in the
default browser configuration.
## Buffer, bind group, and pass conveniences
Unknown `requiredLimits` keys with value `undefined` are ignored by
`requestDevice()`, allowing an adapter limit that may be absent to pass through.
Use `null` in `bindGroupLayouts` for an unused slot while preserving later indices.
- A direct `GPUBuffer` bind group `resource` uses offset zero and the full size;
use `GPUBufferBinding` to specify an offset or size.
- For equal-sized buffers, `encoder.copyBufferToBuffer(source, destination)`
copies the entire buffer, with both offsets defaulting to zero.
- A direct `GPUTexture` uses its default view in a bind group `resource`, color
attachment `view` or `resolveTarget`, or depth/stencil attachment `view`.
- `GPURenderPassEncoder.setViewport()` accepts negative origins and viewports
extending beyond the render target.
Experimental `GPUBuffer.mapSync()` is available in workers when the browser
is launched with `--enable-features=WebGPUMapSyncOnWorkers`. It blocks until
mapping completes; use `mapAsync()` when the method is unavailable.
## Immediate data
Check `navigator.gpu.wgslLanguageFeatures` for `"immediate_address_space"`.
Declare `requires immediate_address_space;`, use `var<immediate>` in WGSL,
and supply values with `pass.setImmediates()` before drawing.
Immediate variables are module-scope, read-only, and have no initializers.
Types must be concrete, constructible, and host-shareable, with no arrays even
in nested members. Each entry point can statically use at most one immediate
variable, including references through called functions.
`layout: "auto"` infers `immediateSize`. An explicit pipeline layout must cover
the full WGSL size, including padding. `immediateSize` defaults to zero and is
capped by `device.limits.maxImmediateSize`, whose default is 64 bytes. All
shader stages share one byte range; size it for the largest declaration used.
The destination offset and copied byte count must be multiples of four.
Optional source offset and size count elements for a `TypedArray`, and bytes
for other buffer sources. Each encoder starts with every slot unset.
Before a draw or dispatch, set every four-byte slot used by any shader stage;
padding-only slots can remain unset. Pipelines with the same `immediateSize`
can reuse values already set.
Set a render bundle's own values on its bundle encoder; this can precede
`setPipeline()`. Pass and bundle encoders copy bytes at encoding time.
Each bundle starts execution with all slots unset, even within one
`executeBundles()` call. That call clears the render pass's immediate slots;
set the required values again before the next direct draw.
## Transient attachments
Combine `GPUTextureUsage.RENDER_ATTACHMENT` and
`GPUTextureUsage.TRANSIENT_ATTACHMENT` for contents needed only within one pass.
Clear at the start and discard at the end.
- The texture must be 2D with one mip level and one array layer.
- Both the texture and its views must use exactly those two usage bits.
- Use `"clear"` and `"discard"` for each depth or stencil aspect present.
- A multisample `resolveTarget` must use a texture without the transient bit.
- Omit `viewFormats` or use `viewFormats: []`; a nonempty list fails validation.
- Passing `TRANSIENT_ATTACHMENT` in `GPUCanvasContext.configure()` usage throws
a `TypeError`.
## Shader features and checks
Subgroups are stable. For adapters exposing `"subgroups"`, read size bounds
from `adapter.info.subgroupMinSize` and `adapter.info.subgroupMaxSize`.
In compute and fragment shaders, `enable subgroups;` enables collective
operations and the `subgroup_invocation_id` and `subgroup_size` built-ins.
`enable subgroup_size_control;` also enables `subgroups`.
| Language feature check in `navigator.gpu.wgslLanguageFeatures` | Guidance |
| --- | --- |
| `"subgroup_id"` | Request `"subgroups"` and declare `enable subgroups;` and `requires subgroup_id;`; compute shaders gain subgroup ID and count. |
| `"subgroup_uniformity"` | Check before using subgroup-uniform conditions to guard subgroup and quad built-ins; uniform control flow is checked at subgroup scope. |
| `"uniform_buffer_standard_layout"` | Declare `requires uniform_buffer_standard_layout;`; uniform buffers follow storage layout constraints, including natural array strides and nested-struct member offsets. |
| `"linear_indexing"` | Declare `requires linear_indexing;`; `global_invocation_index` and `workgroup_index` are `u32` compute inputs flattening the dispatch grid with X varying fastest. |
| `"buffer_view"` | Declare `requires buffer_view;` to reinterpret uniform, storage, or workgroup memory. |
| `"swizzle_assignment"` | Declare `requires swizzle_assignment;` to assign several components of a mutable vector in one statement. |
| `"texture_and_sampler_let"` | Allows function-local `let` bindings for textures and samplers. |
| `"texture_formats_tier1"` | Use this underscore spelling to detect the WGSL extension. |
| `"fragment_depth"` | Declare `requires fragment_depth;`; `@builtin(frag_depth, less)` or `@builtin(frag_depth, greater)` constrains output relative to interpolated depth and allows early depth testing. |
For fixed-width subgroup slots, use
`subgroup_id * subgroup_size + subgroup_invocation_id` and allow gaps when a
subgroup is partially filled. The shader reference includes complete examples.
## Texture features and external images
Request the adapter's `"texture-component-swizzle"` feature and pass `swizzle`
to `GPUTexture.createView()`. Four characters select output red, green, blue,
and alpha from source channels `r`, `g`, `b`, `a`, or constants `0`, `1`.
Requesting `"texture-formats-tier2"` also enables tier 1. Tier 2 adds
`"read-write"` storage access for selected formats, including `"r8unorm"`.
The texture reference gives the format-specific render, storage, and resolve
capabilities.
For BC or ASTC 3D textures, check the sliced-3D feature and request it together
with the matching base compression feature. For dimensions not divisible by
the format's block dimensions, request `"texture-compression-unaligned"`
alongside the chosen compression family's feature.
A compatible 2D `GPUTextureView` of a single subresource can fill an
`externalTexture` binding, keeping the same `texture_external` declaration
for imported video and intermediate textures. Imported `VideoFrame` textures
use `displayWidth` and `displayHeight` as their apparent size; use those
dimensions for `textureLoad()` coordinates.
## Canvas integration
Set `content="drawable"` on a canvas and mark child elements with `drawable`.
After drawing an element in WebGPU, optionally pass a `DOMMatrix` matching
its rendered placement to `canvas.updateElementGeometry()` to synchronize
DOM geometry with the pixels.
Use `"srgb-linear"` or `"display-p3-linear"` as the `colorSpace` in
`GPUCanvasContext.configure()` to render into an extended-range linear color
space. Right-click a WebGPU canvas and choose **Save Image As…** or
**Copy Image** to export its image.