driver.viewFromHandle¶
Summary¶
driver.viewFromHandle reconstructs a typed-array alias from a slice's serialized handle. Supply the current buffer for the same WasmGPU memory. Use the originating slice or arena epoch to establish that the allocation is still live.
Syntax¶
viewFromHandle(buffer: ArrayBufferLike, handle: WasmSliceHandle): ArrayBufferView
const view = driver.viewFromHandle(driver.buffer(), slice.handle());
Parameters¶
| Name | Type | Required | Description |
|---|---|---|---|
buffer |
ArrayBufferLike |
Yes | Current buffer of the WebAssembly memory from which the handle was taken. |
handle |
WasmSliceHandle |
Yes | A handle from a live slice. Its pointer is in bytes and length is in typed elements. |
Returns¶
ArrayBufferView - A typed-array alias chosen by the handle's dtype. The driver trusts the pointer, length and dtype in the handle. A handle can still describe an in-bounds range after its allocation expires, so validate the lifetime before reconstructing a view.
Example¶
const slice = wgpu.driver.frame.allocF32(2);
slice.assertAlive();
const view = wgpu.driver.viewFromHandle(wgpu.driver.buffer(), slice.handle());
view[0] = 12;