wgpu.GPUBuffer¶
- class wgpu.GPUBuffer¶
Bases:
GPUObjectBaseRepresents a block of memory that can be used in GPU operations.
Data is stored in linear layout, meaning that each byte of the allocation can be addressed by its offset from the start of the buffer, subject to alignment restrictions depending on the operation.
Create a buffer using GPUDevice.create_buffer(), GPUDevice.create_buffer_mapped() or GPUDevice.create_buffer_mapped_async().
One can sync data in a buffer by mapping it (or by creating a mapped buffer) and then setting/getting the values in the mapped memoryview. Alternatively, one can tell the GPU (via the command encoder) to copy data between buffers and textures.
- destroy()¶
An application that no longer requires a buffer can choose to destroy it. Note that this is automatically called when the Python object is cleaned up by the garbadge collector.
- map_read()¶
Map the buffer and read the data from it, then unmap. Return a memoryview object. Requires the buffer usage to include MAP_READ.
See GPUQueue.read_buffer() for a simpler alternative.
- property map_state¶
The mapping state of the buffer, see BufferMapState.
- map_write(data)¶
Map the buffer and write the data to it, then unmap. Return a memoryview object. Requires the buffer usage to include MAP_WRITE.
See WGPUQueue.write_buffer() for a simpler alternative.
- property size¶
The length of the GPUBuffer allocation in bytes.
- property usage¶
The allowed usages (int bitmap) for this GPUBuffer, specifying e.g. whether the buffer may be used as a vertex buffer, uniform buffer, target or source for copying data, etc.