Copy the base mip of a 2D texture (width x height, bytes_per_pixel per texel, such as 4 for
rgba8 or bgra8) back to the CPU and return its bytes, rows packed one after another with no
padding. The texture needs the .CopySrc usage and must not be multisampled. The caller frees the
result with array_free. It submits its own command buffer and waits for it, so it stalls the
frame: use it for screenshots and tests, not for per-frame work. Empty (and the reason logged)
when the copy or the mapping failed.
A copy out of a texture needs every row of the buffer to start at a multiple of 256 bytes, so the helper copies into a padded buffer and removes the padding as it copies out.
webgpu_read_texture :: (
instance: WGPUInstance,
device: WGPUDevice,
queue: WGPUQueue,
texture: WGPUTexture,
width: s32,
height: s32,
bytes_per_pixel := 4
) -> [] u8
Copy the base mip of a 2D texture (width x height, bytes_per_pixel per texel, such as 4 for
rgba8 or bgra8) back to the CPU and return its bytes, rows packed one after another with no
padding. The texture needs the .CopySrc usage and must not be multisampled. The caller frees the
result with array_free. It submits its own command buffer and waits for it, so it stalls the
frame: use it for screenshots and tests, not for per-frame work. Empty (and the reason logged)
when the copy or the mapping failed.
A copy out of a texture needs every row of the buffer to start at a multiple of 256 bytes, so the helper copies into a padded buffer and removes the padding as it copies out.
Parameters
- instance: WGPUInstance
- device: WGPUDevice
- queue: WGPUQueue
- texture: WGPUTexture
- width: s32
- height: s32
- bytes_per_pixel := 4
Returns
- [] u8