GPUTexture: createView() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

The createView() method of the GPUTexture interface creates a GPUTextureView representing a specific view of the GPUTexture.

Syntax

js
createView()
createView(descriptor)

Parameters

descriptor Optional

An object containing the following properties:

arrayLayerCount Optional

A number defining how many array layers are accessible to the view, starting with the baseArrayLayer value.

If arrayLayerCount is omitted, it is given a value as follows:

  • If dimension is "1d", "2d", or "3d", arrayLayerCount is 1.
  • If dimension is "cube", arrayLayerCount is 6.
  • If dimension is "2d-array", or "cube-array", arrayLayerCount is GPUTexture.depthOrArrayLayers - baseArrayLayer.
aspect Optional

An enumerated value specifying which aspect(s) of the texture are accessible to the texture view. Possible values are:

"all"

All available aspects of the texture format will be accessible to the view, which can mean all or any of color, depth, and stencil, depending on what kind of format you are dealing with.

"depth-only"

Only the depth aspect of a depth-or-stencil format will be accessible to the view.

"stencil-only"

Only the stencil aspect of a depth-or-stencil format will be accessible to the view.

If omitted, aspect takes a value of "all".

baseArrayLayer Optional

A number defining the index of the first array layer accessible to the view. If omitted, baseArrayLayer takes a value of 0.

baseMipLevel Optional

A number representing the first (most detailed) mipmap level accessible to the view. If omitted, baseMipLevel takes a value of 0.

dimension Optional

An enumerated value specifying the format to view the texture as. Possible values are:

  • "1d": The texture is viewed as a one-dimensional image.
  • "2d": The texture is viewed as a single two-dimensional image.
  • "2d-array": The texture is viewed as an array of two-dimensional images.
  • "cube": The texture is viewed as a cubemap. The view has 6 array layers, corresponding to the [+X, -X, +Y, -Y, +Z, -Z] faces of the cube. Sampling is done seamlessly across the faces of the cubemap.
  • "cube-array": The texture is viewed as a packed array of N cubemaps, each with 6 array layers corresponding to the [+X, -X, +Y, -Y, +Z, -Z] faces of the cube. Sampling is done seamlessly across the faces of the cubemaps.
  • "3d": The texture is viewed as a three-dimensional image.

If dimension is omitted, it is given a value as follows:

format Optional

An enumerated value specifying the format of the texture view. See the Texture formats section of the specification for all the possible values.

If format is omitted, it will be given a value as follows:

label Optional

A string providing a label that can be used to identify the object, for example in GPUError messages or console warnings.

mipLevelCount Optional

A number defining how many mipmap levels are accessible to the view, starting with the baseMipLevel value.

If mipLevelCount is omitted, it will be given a value of GPUTexture.mipLevelCount - baseMipLevel.

swizzle Optional

A string containing four characters. The position of each character maps to the texture view's red, green, blue, and alpha channel values, respectively. The value of each character specifies the value each of those channels will take when the view is accessed by a shader. Possible values are:

r

The texture's red channel value.

g

The texture's green channel value.

b

The texture's blue channel value.

a

The texture's alpha channel value.

0

Enforces a value of 0.

1

Enforces a value of 1.

For example, swizzle: "grba" would result in the texture's red and green channel values being swapped when a shader accesses the view. Texture component swizzle allows developers to optimize performance, correct component ordering mismatches, and reuse shader code across various texture formats when sampling textures.

Note: To use the swizzle property, you must enable the texture-component-swizzle feature in your GPUDevice by specifying it in the requiredFeatures array of the GPUAdapter.requestDevice() descriptor. If this feature is not enabled, the swizzle property will have no effect.

usage Optional

A set of bitwise flags representing a subset of the source texture's usage flags (available in the GPUTexture.usage property) that are compatible with the chosen view format. This can be used to restrict the allowed view usage in cases where the view format is incompatible with certain usages. The available usage flags are listed in the GPUTexture.usage value table.

The default value is 0, which represents the source texture's full set of usage flags. If the view's format doesn't support all of the texture's usages, the default will fail, and the view's usage must be specified explicitly.

Return value

A GPUTextureView object instance.

Validation

The following criteria must be met when calling createView(), otherwise a GPUValidationError is generated and an invalid GPUTextureView object is returned:

Examples

Typical createView() usage

In the WebGPU Samples Cubemap demo, you will see multiple examples of how createView() is used, both as to create a view resource for a GPUDevice.createBindGroup() call, and to provide a view in the depthStencilAttachment object of a GPUCommandEncoder.beginRenderPass() descriptor.

js
const uniformBindGroup = device.createBindGroup({
  layout: pipeline.getBindGroupLayout(0),
  entries: [
    {
      binding: 0,
      resource: {
        buffer: uniformBuffer,
        offset: 0,
        size: uniformBufferSize,
      },
    },
    {
      binding: 1,
      resource: sampler,
    },
    {
      binding: 2,
      resource: cubemapTexture.createView({
        dimension: "cube",
      }),
    },
  ],
});

const renderPassDescriptor: GPURenderPassDescriptor = {
  colorAttachments: [
    {
      view: undefined, // Assigned later
      loadOp: "clear",
      storeOp: "store",
    },
  ],
  depthStencilAttachment: {
    view: depthTexture.createView(),

    depthClearValue: 1.0,
    depthLoadOp: "clear",
    depthStoreOp: "store",
  },
};

// …

const commandEncoder = device.createCommandEncoder();
const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);

// …

createView() with usage restriction

In this snippet, we create a texture and then create a view that has its usage restricted via the usage property.

js
const texture = myDevice.createTexture({
  size: [4, 4],
  format: "rgba8unorm",
  usage:
    GPUTextureUsage.RENDER_ATTACHMENT |
    GPUTextureUsage.TEXTURE_BINDING |
    GPUTextureUsage.STORAGE_BINDING,
  viewFormats: ["rgba8unorm-srgb"],
});

const view = texture.createView({
  format: "rgba8unorm-srgb",
  usage: GPUTextureUsage.RENDER_ATTACHMENT, // Restrict allowed usage
});

Specifications

Specification
WebGPU
# dom-gputexture-createview

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
createView
Chrome – Partial support
Chrome 113 (Release date: 2023-05-02)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Chrome 144.
Edge – Partial support
Edge 113 (Release date: 2023-05-05)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Edge 144.
Firefox – Partial support
Firefox 141 (Release date: 2025-07-22)
footnote Partial support
footnote Supports all contexts except service workers. See bug 1942431.
footnote Supports Windows since Firefox 141. See bug 1972486.
footnote Supports macOS Tahoe on Apple silicon since Firefox 145. See bug 1992212.
footnote Supports older macOS versions on Apple silicon since Firefox 147. See bug 1993341.
footnote Does not support macOS on Intel CPUs. See bug 2004105.
footnote Does not support Linux. See bug 2006676.
Opera – Partial support
Opera 99 (Release date: 2023-05-16)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Opera 128.
Safari – Full support
Safari 26 (Release date: 2025-09-15)
footnote Full support
Chrome Android – Full support
Chrome Android 121 (Release date: 2024-01-23)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 81 (Release date: 2024-03-14)
footnote Full support
Safari on iOS – Full support
Safari on iOS 26 (Release date: 2025-09-15)
footnote Full support
Samsung Internet – Full support
Samsung Internet 25 (Release date: 2024-04-24)
footnote Full support
WebView Android – Full support
WebView Android 121 (Release date: 2024-01-23)
footnote Full support
WebView on iOS – Full support
WebView on iOS 26 (Release date: 2025-09-15)
footnote Full support
Deno – No support
Deno 1.8 – 1.31 (Release date: 2021-03-02)
footnote Removed in 1.32 and later
Deno – No support
Deno 1.39 (Release date: 2023-12-14)
disabled
disabled From version 1.39 users must explicitly set the --unstable-webgpu runtime flag.
descriptor.format parameter accepts "rgb10a2uint"
Experimental
Chrome – Partial support
Chrome 119 (Release date: 2023-10-31)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Chrome 144.
Edge – Partial support
Edge 119 (Release date: 2023-11-02)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Edge 144.
Firefox – No support
Firefox
footnote No support
Opera – Partial support
Opera 105 (Release date: 2023-11-14)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Opera 128.
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 121 (Release date: 2024-01-23)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 81 (Release date: 2024-03-14)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 25 (Release date: 2024-04-24)
footnote Full support
WebView Android – Full support
WebView Android 121 (Release date: 2024-01-23)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
Deno – No support
Deno
footnote No support
descriptor.swizzle parameter
Experimental
Chrome – Partial support
Chrome 143 (Release date: 2025-12-02)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Chrome 144.
Edge – Partial support
Edge 143 (Release date: 2025-12-05)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Edge 144.
Firefox – No support
Firefox
footnote No support
Opera – Partial support
Opera 127 (Release date: 2026-02-02)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Opera 128.
Safari – No support
Safari
footnote No support
Chrome Android – Partial support
Chrome Android 143 (Release date: 2025-12-02)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Chrome Android 144.
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Partial support
Opera Android 94 (Release date: 2026-01-13)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Opera Android 95.
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Partial support
WebView Android 143 (Release date: 2025-12-02)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since WebView Android 144.
WebView on iOS – No support
WebView on iOS
footnote No support
Deno – No support
Deno
footnote No support
descriptor.usage parameter
Experimental
Chrome – Partial support
Chrome 132 (Release date: 2025-01-14)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Chrome 144.
Edge – Partial support
Edge 132 (Release date: 2025-01-17)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Edge 144.
Firefox – No support
Firefox
footnote No support
Opera – Partial support
Opera 117 (Release date: 2025-02-13)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Opera 128.
Safari – No support
Safari
footnote No support
Chrome Android – Partial support
Chrome Android 132 (Release date: 2025-01-14)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Chrome Android 144.
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Partial support
Opera Android 87 (Release date: 2025-01-22)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since Opera Android 95.
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Partial support
Samsung Internet 29 (Release date: 2025-10-25)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
WebView Android – Partial support
WebView Android 132 (Release date: 2025-01-14)
footnote Partial support
footnote Supported on ChromeOS, macOS, and Windows.
footnote Supported on Linux (Intel Gen12+ GPUs only) since WebView Android 144.
WebView on iOS – No support
WebView on iOS
footnote No support
Deno – No support
Deno
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
User must explicitly enable this feature.
Has more compatibility info.

See also