WebGPU module

webgpu_read_texture

procedureextensionexperimentalsince 0.31.0Source

Copies the base level of a 2D texture back to the CPU and returns its bytes, rows packed one after another. The texture needs the .CopySrc usage and can't be multisampled. Free the result with array_free. It submits its own command buffer and waits, so use it for screenshots and tests rather than every frame. Returns an empty array, and logs why, on failure.

Example↗
instance := wgpuCreateInstance(null);
device: WGPUDevice;
queue: WGPUQueue;
texture: WGPUTexture;
pixels := webgpu_read_texture(instance, device, queue, texture, 256, 256);
defer array_free(pixels);

This one is only checked to compile, not run.

webgpu_read_texture :: (
    instance: WGPUInstance,
    device: WGPUDevice,
    queue: WGPUQueue,
    texture: WGPUTexture,
    width: s32,
    height: s32,
    bytes_per_pixel := 4
) -> [] u8

Parameters

instance: WGPUInstance
device: WGPUDevice
queue: WGPUQueue
texture: WGPUTexture
width: s32
height: s32
bytes_per_pixel := 4

Returns

[] u8

See also