demo · v132

View Usage Validator

Chrome 132 adds a usage field to GPUTextureViewDescriptor. This lets you create a view that only exposes a subset of the parent texture's usage flags — useful for passing a texture view to an untrusted module without exposing write access. Configure the texture and view below to validate the usage rules.

Checking WebGPU texture view usage support…
Texture and view configuration
Validation result

GPUTextureUsage flags

TEXTURE_BINDING
0x04
View can be bound as a sampled texture in a shader.
STORAGE_BINDING
0x08
View can be bound as a storage texture — random-access read/write in shaders.
RENDER_ATTACHMENT
0x10
View can be used as a color or depth attachment in a render pass.
COPY_SRC
0x01
Texture can be the source of a copyTextureToBuffer or copyTextureToTexture.
COPY_DST
0x02
Texture can be the destination of a copy or writeTexture.
// Chrome 132: GPUTextureViewDescriptor.usage
const texture = device.createTexture({
  format: 'rgba8unorm',
  usage: GPUTextureUsage.TEXTURE_BINDING |
         GPUTextureUsage.RENDER_ATTACHMENT |
         GPUTextureUsage.STORAGE_BINDING,
  size: [512, 512],
});

// Create a view that only allows sampling (not write)
const readOnlyView = texture.createView({
  usage: GPUTextureUsage.TEXTURE_BINDING  // subset of texture usage
  // RENDER_ATTACHMENT and STORAGE_BINDING NOT exposed
});

// Now pass readOnlyView to untrusted shader module — it can't write
bindGroup = device.createBindGroup({
  entries: [{ binding: 0, resource: readOnlyView }],
});

// View usage must be a subset of the texture's usage — this would error:
// texture.createView({ usage: GPUTextureUsage.COPY_SRC }) // ← not in texture

see also