GPUDevice: createTexture() 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 createTexture() method of the GPUDevice interface creates a GPUTexture in which to store 1D, 2D, or 3D arrays of data, such as images, to use in GPU rendering operations.

Syntax

js
createTexture(descriptor)

Parameters

descriptor

An object containing the following properties:

dimension Optional

An enumerated value indicating the dimension level of the texture. Possible values are:

  • "1d": The texture is one-dimensional.
  • "2d": The texture is two-dimensional or an array of two-dimensional layers.
  • "3d": The texture is three-dimensional.

dimension defaults to "2d" if the value is omitted.

format

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

Note:

  • The depth32float-stencil8 feature needs to be enabled to create depth32float-stencil8-format GPUTextures.
  • The texture-compression-bc feature needs to be enabled to create two-dimensional (dimension: "2d") BC compressed GPUTextures: bc1-rgba-unorm, bc1-rgba-unorm-srgb, bc2-rgba-unorm, bc2-rgba-unorm-srgb, bc3-rgba-unorm, bc3-rgba-unorm-srgb, bc4-r-unorm, bc4-r-snorm, bc5-rg-unorm, bc5-rg-snorm, bc6h-rgb-ufloat, bc6h-rgb-float, bc7-rgba-unorm, and bc7-rgba-unorm-srgb formats.
  • The texture-compression-bc and texture-compression-bc-sliced-3d features need to be enabled to create three-dimensional BC compressed GPUTextures (the same format values specified in the previous bullet, but with dimension set to 3d).
  • The texture-compression-astc feature needs to be enabled to create two-dimensional (dimension: "2d") ASTC compressed GPUTextures: astc-4x4-unorm, astc-4x4-unorm-srgb, astc-5x4-unorm, astc-5x4-unorm-srgb, astc-5x5-unorm, astc-5x5-unorm-srgb, astc-6x5-unorm, astc-6x5-unorm-srgb, astc-6x6-unorm, astc-6x6-unorm-srgb, astc-8x5-unorm, astc-8x5-unorm-srgb, astc-8x6-unorm, astc-8x6-unorm-srgb, astc-8x8-unorm, astc-8x8-unorm-srgb, astc-10x5-unorm, astc-10x5-unorm-srgb, astc-10x6-unorm, astc-10x6-unorm-srgb, astc-10x8-unorm, astc-10x8-unorm-srgb, astc-10x10-unorm, astc-10x10-unorm-srgb, astc-12x10-unorm, astc-12x10-unorm-srgb, astc-12x12-unorm, and astc-12x12-unorm-srgb formats.
  • The texture-compression-astc and texture-compression-astc-sliced-3d features need to be enabled to create three-dimensional BC compressed GPUTextures (the same format values specified in the previous bullet, but with dimension set to 3d).
  • The texture-compression-etc2 feature needs to be enabled to create two-dimensional ETC2 compressed GPUTextures: etc2-rgb8unorm, etc2-rgb8unorm-srgb, etc2-rgb8a1unorm, etc2-rgb8a1unorm-srgb, etc2-rgba8unorm, etc2-rgba8unorm-srgb, eac-r11unorm, eac-r11snorm, eac-rg11unorm, and eac-rg11snorm formats.
  • See the Tier 1 and Tier 2 texture formats section for more information about those texture format sets and the requirements to create them.
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 specifying the number of mip levels the texture will contain. If omitted, this defaults to 1.

sampleCount Optional

A number specifying the texture's sample count. To be valid, the value must be 1 or 4. If omitted, this defaults to 1. A value higher than 1 indicates a multi-sampled texture.

size

An object or array specifying the width, height, and depth/array layer count of the texture. The width value must always be specified, while the height and depth/array layer count values are optional and will default to 1 if omitted.

For example, you can pass an array like [16, 16, 2], or its equivalent object { width: 16, height: 16, depthOrArrayLayers: 2 }.

usage

The bitwise flags representing the allowed usages for the GPUTexture. The possible values are in the GPUTexture.usage value table.

Note that multiple possible usages can be specified by separating values with bitwise OR, for example: GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT.

Note:

  • The bgra8unorm-storage feature needs to be enabled to specify STORAGE_BINDING usage for a bgra8unorm-format GPUTexture.
  • The rg11b10ufloat-renderable feature needs to be enabled to specify RENDER_ATTACHMENT usage for a rg11b10ufloat-format GPUTexture, as well as its blending and multisampling.
viewFormats Optional

An array of enumerated values specifying other texture formats permitted when calling GPUTexture.createView() on this texture, in addition to the texture format specified in its format value.

Return value

A GPUTexture object instance.

Validation

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

  • A valid usage is specified.
  • The values specified in size (width, height, or depth/array layer count) are greater than 0.
  • mipLevelCount is greater than 0.
  • sampleCount is equal to 1 or 4.
  • If dimension is set to "1d":
  • If dimension is set to "2d":
    • The size width and height values are less than or equal to the GPUDevice's maxTextureDimension2D limit.
    • The size depth/array layer count value is less than or equal to the GPUDevice's maxTextureArrayLayers limit.
  • If dimension is set to "3d":
  • The size width value is a multiple of the texel block width.
  • The size height value is a multiple of the texel block height.
  • If sampleCount is greater than 1:
    • mipLevelCount is equal to 1.
    • The size depth/array layer count value is equal to 1.
    • usage includes the GPUTextureUsage.RENDER_ATTACHMENT flag.
    • usage does not include the GPUTextureUsage.STORAGE_BINDING flag.
    • The specified format supports multi-sampling.
  • The mipLevelCount value is less than or equal to the maximum miplevel count.
  • The formats specified in format and viewFormats are compatible with one another.
  • If usage includes the GPUTextureUsage.RENDER_ATTACHMENT flag:
    • format is a renderable format (meaning a color renderable format, or a depth-or-stencil format).
    • dimension is set to "2d".
  • If usage includes the GPUTextureUsage.STORAGE_BINDING flag:
    • The specified format includes the STORAGE_BINDING capability (see the Plain color formats table for reference).

Tier 1 and Tier 2 texture formats

This section describes the WebGPU Tier1 and Tier2 texture formats.

Tier 1

The Tier 1 set of texture formats is designed to allow developers to port existing content to the web without needing to rewrite it to use WebGPU's lower-level capabilities. To use this set, enable the texture-formats-tier1 feature (see GPUSupportedFeatures).

Enabling this feature allows:

  • Using the following formats with usages of RENDER_ATTACHMENT (including blendable and multisampling capabilities) and STORAGE_BINDING (with read-only and write-only access):
    • r16unorm
    • r16snorm
    • rg16unorm
    • rg16snorm
    • rgba16unorm
    • rgba16snorm
  • Using the following formats with the RENDER_ATTACHMENT usage (including blendable and multisampling capabilities):
    • r8snorm
    • rg8snorm
    • rgba8snorm
  • Using the following formats with the STORAGE_BINDING usage (with read-only and write-only access):
    • r8unorm
    • r8snorm
    • r8uint
    • r8sint
    • rg8unorm
    • rg8snorm
    • rg8uint
    • rg8sint
    • r16uint
    • r16sint
    • r16float
    • rg16uint
    • rg16sint
    • rg16float
    • rgb10a2uint
    • rgb10a2unorm
    • rg11b10ufloat
  • Using the following GPUTexture formats in the destination texture of GPUQueue.copyExternalImageToTexture() calls:
    • r16unorm
    • rg16unorm
    • rgba16unorm

Note: Enabling the texture-formats-tier1 feature automatically enables the rg11b10ufloat-renderable feature, which allows the rg11b10ufloat texture to be used with the RENDER_ATTACHMENT usage, including blending and multisampling.

Tier2

The Tier 2 set of texture formats supports storage texture formats that don't have support in "core" WebGPU, and are required for advanced usage. To use this set, enable the texture-formats-tier2 feature (see GPUSupportedFeatures).

Enabling this feature allows using the following formats with the STORAGE_BINDING usage (with read-write access):

  • r8unorm
  • r8uint
  • r8sint
  • rgba8unorm
  • rgba8uint
  • rgba8sint
  • r16uint
  • r16sint
  • r16float
  • rgba16uint
  • rgba16sint
  • rgba16float
  • rgba32uint
  • rgba32sint
  • rgba32float

Note: Enabling the texture-formats-tier2 feature automatically enables the rg11b10ufloat-renderable and texture-formats-tier1 features.

Examples

In the WebGPU samples Textured Cube sample, a texture to use on the faces of a cube is created by:

js
// …

let cubeTexture;

{
  const img = document.createElement("img");
  img.src = new URL(
    "../../../assets/img/Di-3d.png",
    import.meta.url,
  ).toString();
  await img.decode();
  const imageBitmap = await createImageBitmap(img);

  cubeTexture = device.createTexture({
    size: [imageBitmap.width, imageBitmap.height, 1],
    format: "rgba8unorm",
    usage:
      GPUTextureUsage.TEXTURE_BINDING |
      GPUTextureUsage.COPY_DST |
      GPUTextureUsage.RENDER_ATTACHMENT,
  });
  device.queue.copyExternalImageToTexture(
    { source: imageBitmap },
    { texture: cubeTexture },
    [imageBitmap.width, imageBitmap.height],
  );
}

// …

Specifications

Specification
WebGPU
# dom-gpudevice-createtexture

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
createTexture
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.
rgb10a2uint texture format
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

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