GPUCommandEncoder

class wgpu.GPUCommandEncoder

Bases: GPUCommandsMixin, GPUDebugCommandsMixin, GPUObjectBase

Object to record a series of commands.

When done, call finish() to obtain a GPUCommandBuffer object.

Create a command encoder using GPUDevice.create_command_encoder().

begin_compute_pass(**parameters)

Record the beginning of a compute pass. Returns a GPUComputePassEncoder object.

Parameters:
  • label (str) – A human readable label. Optional.

  • timestamp_writes – unused

begin_render_pass(**parameters)

Record the beginning of a render pass. Returns a GPURenderPassEncoder object.

Parameters:
clear_buffer(buffer, offset=0, size=None)

Set (part of) the given buffer to zeros.

Parameters:
  • buffer (GPUBuffer) – The buffer to clear.

  • offset (int) – The byte offset.

  • size (int, optional) – The size to clear in bytes. If None, the effective size is the full size minus the offset.

Alignment: both offset and size must be a multiple of 4.

copy_buffer_to_buffer(source, source_offset, destination, destination_offset, size)

Copy the contents of a buffer to another buffer.

Parameters:
  • source (GPUBuffer) – The source buffer.

  • source_offset (int) – The byte offset.

  • destination (GPUBuffer) – The target buffer.

  • destination_offset (int) – The byte offset in the destination buffer.

  • size (int) – The number of bytes to copy.

Alignment: the size, source offset, and destination offset must all be a multiple of 4.

copy_buffer_to_texture(source, destination, copy_size)

Copy the contents of a buffer to a texture (view).

Parameters:
  • source (GPUBuffer) – A dict with fields: buffer, offset, bytes_per_row, rows_per_image.

  • destination (GPUTexture) – A dict with fields: texture, mip_level, origin.

  • copy_size (int) – The number of bytes to copy.

Alignment: the bytes_per_row must be a multiple of 256.

copy_texture_to_buffer(source, destination, copy_size)

Copy the contents of a texture (view) to a buffer.

Parameters:
  • source (GPUTexture) – A dict with fields: texture, mip_level, origin.

  • destination (GPUBuffer) – A dict with fields: buffer, offset, bytes_per_row, rows_per_image.

  • copy_size (int) – The number of bytes to copy.

Alignment: the bytes_per_row must be a multiple of 256.

copy_texture_to_texture(source, destination, copy_size)

Copy the contents of a texture (view) to another texture (view).

Parameters:
  • source (GPUTexture) – A dict with fields: texture, mip_level, origin.

  • destination (GPUTexture) – A dict with fields: texture, mip_level, origin.

  • copy_size (int) – The number of bytes to copy.

finish(**parameters)

Finish recording. Returns a GPUCommandBuffer to submit to a GPUQueue.

Parameters:

label (str) – A human readable label. Optional.

resolve_query_set(query_set, first_query, query_count, destination, destination_offset)

Resolves query results from a GPUQuerySet out into a range of a GPUBuffer.

Parameters:
  • query_set (GPUQuerySet) – The source query set.

  • first_query (int) – The first query to resolve.

  • query_count (int) – The amount of queries to resolve.

  • destination (GPUBuffer) – The buffer to write the results to.

  • destination_offset (int) – The byte offset in the buffer.

Alignment: the destination offset must be a multiple of 256.