GPUQueue: copyExternalImageToTexture() 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 copyExternalImageToTexture() method of the GPUQueue interface copies a snapshot taken from a source image, video, or canvas into a given GPUTexture.

Using this function allows the user agent to determine the most efficient way to copy the data over for each source type.

Syntax

js
copyExternalImageToTexture(source, destination, copySize)

Parameters

source

An object representing the source to write to the destination, and its origin. This can take the following properties:

source

An object providing the source of the snapshot to copy. This can be an HTMLCanvasElement, HTMLImageElement, HTMLVideoElement, ImageBitmap, ImageData, OffscreenCanvas, or VideoFrame object. The image source data is captured at the exact moment copyExternalImageToTexture() is invoked.

origin Optional

An object or array specifying the origin of the copy — the top-left corner of the source sub-region to copy from. Together with copySize, this defines the full extent of the source sub-region. The x and y values default to 0 if any of all of origin is omitted.

For example, you can pass an array like [0, 0], or its equivalent object { x: 0, y: 0 }.

flipY Optional

A boolean. If set to true, the image capture is flipped vertically. If omitted, flipY defaults to false.

destination

An object defining the texture subresource and origin to write the captured image to, plus encoding metadata. This can take the following properties:

aspect Optional

An enumerated value defining which aspects of the texture to write the image to. Possible values are:

"all"

All available aspects of the texture format will be written to, 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 written to.

"stencil-only"

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

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

colorSpace Optional

An enumerated value describing the color space and encoding used to encode data into the destination texture. Possible values are "srgb" and "display-p3". If omitted, colorSpace defaults to "srgb".

Note: The encoding may result in values outside of the range [0, 1] being written to the target texture, if its format can represent them. Otherwise, the results are clamped to the target texture format's range. Conversion may not be necessary if colorSpace matches the source image color space.

mipLevel Optional

A number representing the mip-map level of the texture to write the image to. If omitted, mipLevel defaults to 0.

origin Optional

An object or array specifying the origin of the copy — the minimum corner of the texture region to write the image data to. Together with copySize, this defines the full extent of the region to copy to. The x, y, and z values default to 0 if any of all of origin is omitted.

For example, you can pass an array like [0, 0, 0], or its equivalent object { x: 0, y: 0, z: 0 }.

premultipliedAlpha Optional

A boolean. If set to true, the image data written into the texture will have its RGB channels premultiplied by the alpha channel. If omitted, premultipliedAlpha defaults to false.

Note: If this option is set to true and the source is also premultiplied, the source RGB values must be preserved even if they exceed their corresponding alpha values.

texture

A GPUTexture object representing the texture to write the data to.

copySize

An object or array specifying width, height, and depthOrArrayLayers — of the region to copy from/to.

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

The width value has to be included. If the height or depthOrArrayLayers values are omitted, they default to 1.

Return value

None (Undefined).

Exceptions

OperationError DOMException

The method throws an OperationError if the following criteria are not met:

  • source.origin.x + the width of the region to copy to is less than or equal to the width of the source image.
  • source.origin.y + the height of the region to copy to is less than or equal to the height of the source image.
  • source.origin.z + the depthOrArrayLayers of the region to copy to is less than or equal to 1.
  • dataOffset is equal to or smaller than the size of data.
  • The size of data (when converted to bytes, in the case of TypedArrays) is a multiple of 4.
SecurityError DOMException

Thrown if the image source data is cross-origin.

Validation

The following criteria must be met when calling writeTexture(), otherwise a GPUValidationError is generated and the GPUQueue becomes invalid:

Examples

In the WebGPU Samples Textured Cube example, the following snippet is used to fetch an image and upload it into a GPUTexture:

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-gpuqueue-copyexternalimagetotexture

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
copyExternalImageToTexture
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.
HTMLImageElement and ImageData objects as source
Experimental
Chrome – Partial support
Chrome 118 (Release date: 2023-10-10)
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 118 (Release date: 2023-10-13)
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 104 (Release date: 2023-10-23)
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
VideoFrame object as source
Chrome – Partial support
Chrome 116 (Release date: 2023-08-15)
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 116 (Release date: 2023-08-21)
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 102 (Release date: 2023-08-23)
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.

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