diff --git a/wgpu/adapt_js.go b/wgpu/adapt_js.go deleted file mode 100644 index ab85045..0000000 --- a/wgpu/adapt_js.go +++ /dev/null @@ -1,18 +0,0 @@ -//go:build js - -package wgpu - -import ( - "syscall/js" - "unsafe" -) - -// BytesToJS converts the given bytes to a js Uint8ClampedArray -// by using the global wasm memory bytes. This avoids the -// copying present in [js.CopyBytesToJS]. -func BytesToJS(b []byte) js.Value { - ptr := uintptr(unsafe.Pointer(&b[0])) - memoryBytes := js.Global().Get("Uint8ClampedArray").New(js.Global().Get("wasm").Get("instance").Get("exports").Get("mem").Get("buffer")) - // using subarray instead of slice gives a 5x performance improvement due to no copying - return memoryBytes.Call("subarray", ptr, ptr+uintptr(len(b))) -} diff --git a/wgpu/util_js.go b/wgpu/util_js.go index b7d7743..6e8d8fe 100644 --- a/wgpu/util_js.go +++ b/wgpu/util_js.go @@ -2,7 +2,20 @@ package wgpu -import "syscall/js" +import ( + "syscall/js" + "unsafe" +) + +// BytesToJS converts the given bytes to a js Uint8ClampedArray +// by using the global wasm memory bytes. This avoids the +// copying present in [js.CopyBytesToJS]. +func BytesToJS(b []byte) js.Value { + ptr := uintptr(unsafe.Pointer(&b[0])) + memoryBytes := js.Global().Get("Uint8ClampedArray").New(js.Global().Get("wasm").Get("instance").Get("exports").Get("mem").Get("buffer")) + // using subarray instead of slice gives a 5x performance improvement due to no copying + return memoryBytes.Call("subarray", ptr, ptr+uintptr(len(b))) +} // mapSlice can be used to transform one slice into another by providing a // function to do the mapping.