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 device buffer to host bytes (device-to-host copy).
Uses a staging buffer with map_async and blocks via pollster::block_on.
On native WASM, callers should prefer the async variant or schedule this
on a web worker to avoid blocking the main thread.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for WasmMemoryManager
impl !RefUnwindSafe for WasmMemoryManager
impl Send for WasmMemoryManager
impl Sync for WasmMemoryManager
impl Unpin for WasmMemoryManager
impl UnsafeUnpin for WasmMemoryManager
impl !UnwindSafe for WasmMemoryManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more