pub struct WasmMemoryManager { /* private fields */ }Expand description
Browser-side buffer manager that uses async map_async staging.
This mirrors WebGpuMemoryManager but
is designed to work within the single-threaded browser event loop where
blocking calls are not allowed.
Implementations§
Source§impl WasmMemoryManager
impl WasmMemoryManager
Sourcepub fn new(device: Arc<WasmGpuDevice>) -> Self
pub fn new(device: Arc<WasmGpuDevice>) -> Self
Create a new WASM memory manager backed by device.
Sourcepub fn alloc(&self, bytes: usize) -> WebGpuResult<u64>
pub fn alloc(&self, bytes: usize) -> WebGpuResult<u64>
Allocate a device buffer of bytes bytes.
Sourcepub fn free(&self, handle: u64) -> WebGpuResult<()>
pub fn free(&self, handle: u64) -> WebGpuResult<()>
Free the buffer identified by handle.
Sourcepub fn copy_htod(&self, handle: u64, src: &[u8]) -> WebGpuResult<()>
pub fn copy_htod(&self, handle: u64, src: &[u8]) -> WebGpuResult<()>
Upload host bytes to the device buffer (host-to-device copy).
Uses Queue::write_buffer which is available in both native and WASM.
Sourcepub fn copy_dtoh(&self, dst: &mut [u8], handle: u64) -> WebGpuResult<()>
pub fn copy_dtoh(&self, dst: &mut [u8], handle: u64) -> WebGpuResult<()>
Download a device buffer to host bytes (device-to-host copy).
This is a blocking readback: it maps a staging buffer and waits on the
map callback. On a native target (including the wasm feature used for
testing) Device::poll drives completion, so this works. On the real
wasm32 browser main thread, however, blocking would starve the event
loop that delivers the map callback and freeze the tab — so there this
method returns WebGpuError::Unsupported and callers must use
copy_dtoh_async instead.
Sourcepub async fn copy_dtoh_async(
&self,
dst: &mut [u8],
handle: u64,
) -> WebGpuResult<()>
pub async fn copy_dtoh_async( &self, dst: &mut [u8], handle: u64, ) -> WebGpuResult<()>
Asynchronously download a device buffer to host bytes.
Unlike copy_dtoh this never blocks the calling
thread: it awaits the buffer-map completion via a future resolved from
the map_async callback, making it the correct readback path on the
single-threaded browser event loop. Like copy_dtoh, an oversized
destination is rejected with WebGpuError::InvalidArgument.