Skip to main content
torch.js has not been released yet.
torch.js logotorch.js logotorch.js
PlaygroundContact
Login
Documentation
IntroductionType SafetyTensor ExpressionsTensor IndexingEinsumEinopsAutogradTraining a ModelProfiling & MemoryPyTorch MigrationBest PracticesRuntimesPerformancePyTorch CompatibilityBenchmarksDType Coverage
Introduction
createdestroyBufferUsageMapModeShaderStageBufferHandleDeviceHandleAdapterHandleShaderModuleHandleComputePipelineHandleBindGroupHandleBindGroupLayoutHandleCommandEncoderHandleCommandBufferHandleComputePassEncoderHandleQuerySetHandleQueueHandleWGPUBufferWGPUShaderModuleWGPUBindGroupLayoutWGPUBindGroupWGPUComputePipelineWGPUQuerySetWGPUComputePassEncoderWGPUCommandBufferWGPUCommandEncoderWGPUQueueWGPULimitsBufferDescriptorShaderModuleDescriptorComputePipelineDescriptorBufferBindingBindGroupEntryBindGroupDescriptorQuerySetDescriptorWGPUDeviceWGPUSupportedFeaturesWGPUAdapterWGPU
torch.js· 2026
LegalTerms of UsePrivacy Policy
/
/
  1. docs
  2. dawn
  3. dawn
  4. WGPUBuffer

dawn.WGPUBuffer

export interface WGPUBuffer {
  /**
   * Size of the buffer in bytes.
   */
  readonly size: number;

  /**
   * Combined {@link BufferUsage} flags specifying allowed operations.
   */
  readonly usage: number;

  /**
   * Current mapping state: 'unmapped', 'pending', or 'mapped'.
   *
   * - 'unmapped': Buffer is not mapped
   * - 'pending': mapAsync() called, waiting for GPU
   * - 'mapped': Buffer is mapped and accessible
   */
  readonly mapState: 'unmapped' | 'pending' | 'mapped';

  /**
   * Opaque native handle to this buffer.
   */
  readonly handle: BufferHandle;

  /**
   * Map buffer for CPU access.
   *
   * @param mode - Map mode (READ or WRITE from {@link MapMode})
   * @param offset - Byte offset into buffer (default: 0)
   * @param size - Number of bytes to map (default: entire buffer)
   * @returns Promise that resolves when buffer is ready for access
   */
  mapAsync(mode: number, offset?: number, size?: number): Promise<void>;

  /**
   * Get a mapped range of the buffer as an ArrayBuffer.
   *
   * Only valid when buffer is in 'mapped' state.
   *
   * @param offset - Byte offset into buffer (default: 0)
   * @param size - Number of bytes (default: entire buffer)
   * @returns ArrayBuffer view of the mapped region
   */
  getMappedRange(offset?: number, size?: number): ArrayBuffer;

  /**
   * Unmap the buffer, making it inaccessible from CPU but usable by GPU again.
   */
  unmap(): void;

  /**
   * Destroy the buffer and free its GPU memory.
   */
  destroy(): void;
}
readonlysize(number)
– Size of the buffer in bytes.
readonlyusage(number)
– Combined BufferUsage flags specifying allowed operations.
readonlymapState('unmapped' | 'pending' | 'mapped')
– Current mapping state: 'unmapped', 'pending', or 'mapped'. - 'unmapped': Buffer is not mapped - 'pending': mapAsync() called, waiting for GPU - 'mapped': Buffer is mapped and accessible
readonlyhandle(BufferHandle)
– Opaque native handle to this buffer.
mapAsync((mode: number, offset?: number, size?: number) => Promise<void>)
– Map buffer for CPU access.
getMappedRange((offset?: number, size?: number) => ArrayBuffer)
– Get a mapped range of the buffer as an ArrayBuffer. Only valid when buffer is in 'mapped' state.
unmap(() => void)
– Unmap the buffer, making it inaccessible from CPU but usable by GPU again.
destroy(() => void)
– Destroy the buffer and free its GPU memory.

GPU buffer resource.

Represents a block of GPU memory that can hold data for tensors, indices, uniforms, etc. Buffers must be created with specific usage flags that determine what operations they can be used for.

Previous
WGPUBindGroupLayout
Next
WGPUCommandBuffer