GPUQueue

class wgpu.GPUQueue

Bases: GPUObjectBase

Object to submit command buffers to.

You can obtain a queue object via the GPUDevice.queue property.

on_submitted_work_done(*args, **kwargs)

Backwards compatible method for on_submitted_work_done_sync()

async on_submitted_work_done_async()

TODO

on_submitted_work_done_sync()

Sync version of on_submitted_work_done_async().

Provided by wgpu-py, but not compatible with WebGPU.

read_buffer(buffer, buffer_offset=0, size=None)

Takes the data contents of the buffer and return them as a memoryview.

Parameters:
  • buffer – The GPUBuffer object to read from.

  • buffer_offset (int) – The offset in the buffer to start reading from.

  • size – The number of bytes to read. Default all minus offset.

This copies the data in the given buffer to a temporary buffer and then maps that buffer to read the data. The given buffer’s usage must include COPY_SRC.

Also see GPUBuffer._sync() and GPUBuffer._async().

read_texture(source, data_layout, size)

Reads the contents of the texture and return them as a memoryview.

Parameters:
  • source – A dict with fields: “texture” (a texture object), “origin” (a 3-tuple), “mip_level” (an int, default 0).

  • data_layout – A dict with fields: “offset” (an int, default 0), “bytes_per_row” (an int), “rows_per_image” (an int, default 0).

  • size – A 3-tuple of ints specifying the size to write.

Unlike GPUCommandEncoder.copyBufferToTexture(), there is no alignment requirement on bytes_per_row, although in the current implementation there will be a performance penalty if bytes_per_row is not a multiple of 256 (because we’ll be copying data row-by-row in Python).

submit(command_buffers: List[GPUCommandBuffer])

Submit a GPUCommandBuffer to the queue.

Parameters:

command_buffers (list) – The GPUCommandBuffer objects to add.

write_buffer(buffer: GPUBuffer, buffer_offset: int, data: memoryview, data_offset: int = 0, size: int | None = None)

Takes the data contents and schedules a write operation to the buffer.

Changes to the data after this function is called don’t affect the buffer contents.

Parameters:
  • buffer – The GPUBuffer object to write to.

  • buffer_offset (int) – The offset in the buffer to start writing at.

  • data – The data to write to the buffer. Must be an object that supports the buffer protocol, e.g. bytes, memoryview, numpy array, etc. Must be contiguous.

  • data_offset – The offset in the data, in elements. Default 0.

  • size – The number of bytes to write. Default all minus offset.

This maps the data to a temporary buffer and then copies that buffer to the given buffer. The given buffer’s usage must include COPY_DST.

Alignment: the buffer offset must be a multiple of 4, the total size to write must be a multiple of 4 bytes.

Also see GPUBuffer.map_sync() and GPUBuffer.map_async().

write_texture(destination:, data: memoryview, data_layout:, size: ~typing.List[int] |)

Takes the data contents and schedules a write operation of these contents to the destination texture in the queue. A snapshot of the data is taken; any changes to the data after this function is called do not affect the texture contents.

Parameters:
  • destination – A dict with fields: “texture” (a texture object), “origin” (a 3-tuple), “mip_level” (an int, default 0).

  • data – The data to write to the texture. Must be an object that supports the buffer protocol, e.g. bytes, memoryview, numpy array, etc. Must be contiguous.

  • data_layout – A dict with fields: “offset” (an int, default 0), “bytes_per_row” (an int), “rows_per_image” (an int, default 0).

  • size – A 3-tuple of ints specifying the size to write.

Unlike GPUCommandEncoder.copyBufferToTexture(), there is no alignment requirement on bytes_per_row.