Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions getrelease.goal
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

[mkdir release]
cd release
[/bin/rm -rf wgpu-native]
[/bin/rm -rf zips]
[/usr/bin/env rm -rf wgpu-native]
[/usr/bin/env rm -rf zips]
[mkdir zips]
git clone https://github.com/gfx-rs/wgpu-native
cd wgpu-native
Expand All @@ -21,7 +21,7 @@ cd ../zips
zips := goalib.SplitLines($ls -1 "*.zip"$)
cd ../..
mv wgpu/lib wgpu/lib_old
[/bin/rm -rf wgpu/lib]
[/usr/bin/env rm -rf wgpu/lib]
mkdir wgpu/lib
cd wgpu/lib
for _, f := range zips {
Expand All @@ -37,7 +37,7 @@ for _, f := range zips {
cd ../
}

/bin/cp ../lib_old/vendor.go .
/usr/bin/env cp ../lib_old/vendor.go .

type files struct {
zip, trg, arch string
Expand All @@ -51,13 +51,12 @@ for _, f := range fls {
cd {f.trg}
[mkdir {f.arch}]
cd {f.arch}
[/bin/cp -av {"../../" + f.zip + "/lib/libwgpu_native.a"} .]
[/usr/bin/env cp -av {"../../" + f.zip + "/lib/libwgpu_native.a"} .]
if f.zip == "windows-aarch64" {
/bin/cp -av {"../../" + f.zip + "/lib/wgpu_native.lib"} libwgpu_native.a
/usr/bin/env cp -av {"../../" + f.zip + "/lib/wgpu_native.lib"} libwgpu_native.a
}
/bin/cp -av {"../../" + f.zip + "/include/webgpu/*.h"} .
/usr/bin/env cp -av {"../../" + f.zip + "/include/webgpu/*.h"} .
goalib.WriteFile("vendor.go", "package vendor")
cd ../../
/bin/rm -rf {f.zip}
/usr/bin/env rm -rf {f.zip}
}

34 changes: 31 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/cogentcore/webgpu

go 1.22
go 1.24

require (
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a
Expand All @@ -10,12 +10,40 @@ require (
)

require (
cogentcore.org/core v0.3.12 // indirect
cogentcore.org/lab v0.1.2 // indirect
github.com/Bios-Marcel/wastebasket/v2 v2.0.3 // indirect
github.com/Masterminds/vcs v1.13.3 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/bramvdbogaerde/go-scp v1.4.0 // indirect
github.com/chewxy/math32 v1.10.1 // indirect
github.com/cogentcore/readline v0.1.3 // indirect
github.com/cogentcore/yaegi v0.0.0-20250622201820-b7838bdd95eb // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/h2non/filetype v1.1.3 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-shellwords v1.0.12 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.2-0.20240227203013-2b69615b5d55 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/tools v0.23.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
golang.org/x/crypto v0.39.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/image v0.25.0 // indirect
golang.org/x/mod v0.25.0 // indirect
golang.org/x/sync v0.15.0 // indirect
golang.org/x/sys v0.33.0 // indirect
golang.org/x/text v0.26.0 // indirect
golang.org/x/tools v0.33.0 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.1.0 // indirect
)

tool cogentcore.org/lab/goal/cmd/goal
70 changes: 70 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,25 +1,95 @@
cogentcore.org/core v0.3.12 h1:wniqGY3wB+xDcJ3KfobR7VutWeiZafSQkjnbOW4nAXQ=
cogentcore.org/core v0.3.12/go.mod h1:Bwg3msVxqnfwvmQjpyJbyHMeox3UAcBcBitkGEdSYSE=
cogentcore.org/lab v0.1.2 h1:km5VUi3HVmP28maFnCvNgGXV4bGMjlPAXFIHchaRZ4k=
cogentcore.org/lab v0.1.2/go.mod h1:ilGaPEvvAVCHiUxpO83w01g1+Ix0tJxK+fnAmnLNOMk=
github.com/Bios-Marcel/wastebasket/v2 v2.0.3 h1:TkoDPcSqluhLGE+EssHu7UGmLgUEkWg7kNyHyyJ3Q9g=
github.com/Bios-Marcel/wastebasket/v2 v2.0.3/go.mod h1:769oPCv6eH7ugl90DYIsWwjZh4hgNmMS3Zuhe1bH6KU=
github.com/Masterminds/vcs v1.13.3 h1:IIA2aBdXvfbIM+yl/eTnL4hb1XwdpvuQLglAix1gweE=
github.com/Masterminds/vcs v1.13.3/go.mod h1:TiE7xuEjl1N4j016moRd6vezp6e6Lz23gypeXfzXeW8=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/bramvdbogaerde/go-scp v1.4.0 h1:jKMwpwCbcX1KyvDbm/PDJuXcMuNVlLGi0Q0reuzjyKY=
github.com/bramvdbogaerde/go-scp v1.4.0/go.mod h1:on2aH5AxaFb2G0N5Vsdy6B0Ml7k9HuHSwfo1y0QzAbQ=
github.com/chewxy/math32 v1.10.1 h1:LFpeY0SLJXeaiej/eIp2L40VYfscTvKh/FSEZ68uMkU=
github.com/chewxy/math32 v1.10.1/go.mod h1:dOB2rcuFrCn6UHrze36WSLVPKtzPMRAQvBvUwkSsLqs=
github.com/cogentcore/readline v0.1.3 h1:tYmjP3XHvsGwhsDLkAp+vBhkERmLFENZfftyPOR/PBE=
github.com/cogentcore/readline v0.1.3/go.mod h1:IHVtJHSKXspK7CMg3OC/bbPEXxO++dFlug/vsPktvas=
github.com/cogentcore/yaegi v0.0.0-20250622201820-b7838bdd95eb h1:vXYqPLO36pRyyk1cVILVlk+slDI+Q7N4bgeWlh1sjA0=
github.com/cogentcore/yaegi v0.0.0-20250622201820-b7838bdd95eb/go.mod h1:+MGpZ0srBmeJ7aaOLTdVss8WLolt0/y/plVHLpxgd3A=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a h1:vxnBhFDDT+xzxf1jTJKMKZw3H0swfWk9RpWbBbDK5+0=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20240506104042-037f3cc74f2a/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg=
github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk=
github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/pelletier/go-toml/v2 v2.1.2-0.20240227203013-2b69615b5d55 h1:CJwoX/v1ZWNj0Ofn62jvQDRuH3/hIHMqCQxbkzq2m5Y=
github.com/pelletier/go-toml/v2 v2.1.2-0.20240227203013-2b69615b5d55/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa h1:FRnLl4eNAQl8hwxVVC17teOw8kdjVDVAiFMtgUdTSRQ=
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE=
golang.org/x/image v0.25.0 h1:Y6uW6rH1y5y/LK1J8BPWZtr6yZ7hrsy6hFrXjgsc2fQ=
golang.org/x/image v0.25.0/go.mod h1:tCAmOEGthTtkalusGp1g3xa2gke8J6c2N565dTyl9Rs=
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
gonum.org/v1/gonum v0.15.0 h1:2lYxjRbTYyxkJxlhC+LvJIx3SsANPdRybu1tGj9/OrQ=
gonum.org/v1/gonum v0.15.0/go.mod h1:xzZVBJBtS+Mz4q0Yl2LJTk+OxOg4jiXZ7qBoM0uISGo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
lukechampine.com/uint128 v1.2.0 h1:mBi/5l91vocEN8otkC5bDLhi2KdCticRiwbdB0O+rjI=
lukechampine.com/uint128 v1.2.0/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk=
modernc.org/cc/v3 v3.41.0 h1:QoR1Sn3YWlmA1T4vLaKZfawdVtSiGx8H+cEojbC7v1Q=
Expand Down
13 changes: 0 additions & 13 deletions jsx/jsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,9 @@
package jsx

import (
"log/slog"
"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]))
// We directly pass the offset and length to the constructor to avoid calling subarray or slice,
// thereby improving performance and safety (this fixes a detached array buffer crash).
return js.Global().Get("Uint8ClampedArray").New(js.Global().Get("wasm").Get("instance").Get("exports").Get("mem").Get("buffer"), ptr, len(b))
}

// Await is a helper function equivalent to await in JS.
// It is copied from https://go-review.googlesource.com/c/go/+/150917/
func Await(promise js.Value) (result js.Value, ok bool) {
Expand All @@ -40,7 +28,6 @@ func Await(promise js.Value) (result js.Value, ok bool) {
onReject := js.FuncOf(func(this js.Value, args []js.Value) any {
result = args[0]
ok = false
slog.Error("wgpu.AwaitJS: promise rejected", "reason", result)
close(done)
return nil
})
Expand Down
13 changes: 6 additions & 7 deletions wgpu/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extern void gowebgpu_device_lost_callback_c(WGPUDeviceLostReason reason, char co
import "C"
import (
"errors"
"runtime/cgo"
"unsafe"
)

Expand Down Expand Up @@ -109,7 +108,7 @@ type requestDeviceCb func(status RequestDeviceStatus, device *Device, message st

//export gowebgpu_request_device_callback_go
func gowebgpu_request_device_callback_go(status C.WGPURequestDeviceStatus, device C.WGPUDevice, message C.WGPUStringView, userdata unsafe.Pointer) {
handle := *(*cgo.Handle)(userdata)
handle := lookupHandle(userdata)
defer handle.Delete()

cb, ok := handle.Value().(requestDeviceCb)
Expand All @@ -120,7 +119,7 @@ func gowebgpu_request_device_callback_go(status C.WGPURequestDeviceStatus, devic

//export gowebgpu_device_lost_callback_go
func gowebgpu_device_lost_callback_go(reason C.WGPUDeviceLostReason, message *C.char, userdata unsafe.Pointer) {
handle := *(*cgo.Handle)(userdata)
handle := lookupHandle(userdata)
defer handle.Delete()

cb, ok := handle.Value().(DeviceLostCallback)
Expand Down Expand Up @@ -206,11 +205,11 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
}

if descriptor.DeviceLostCallback != nil {
handle := cgo.NewHandle(descriptor.DeviceLostCallback)
handle := newHandle(descriptor.DeviceLostCallback)

desc.deviceLostCallbackInfo = C.WGPUDeviceLostCallbackInfo{
callback: C.WGPUDeviceLostCallback(C.gowebgpu_device_lost_callback_c),
userdata1: unsafe.Pointer(&handle),
userdata1: handle.ToPointer(),
}
}

Expand Down Expand Up @@ -238,10 +237,10 @@ func (p *Adapter) RequestDevice(descriptor *DeviceDescriptor) (*Device, error) {
status = s
device = d
}
handle := cgo.NewHandle(cb)
handle := newHandle(cb)
C.wgpuAdapterRequestDevice(p.ref, desc, C.WGPURequestDeviceCallbackInfo{
callback: C.WGPURequestDeviceCallback(C.gowebgpu_request_device_callback_c),
userdata1: unsafe.Pointer(&handle),
userdata1: handle.ToPointer(),
})

if status != RequestDeviceStatusSuccess {
Expand Down
4 changes: 2 additions & 2 deletions wgpu/adapter_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (g Adapter) GetInfo() AdapterInfo {
return AdapterInfo{} // TODO(kai): implement?
}

func (g Adapter) GetLimits() SupportedLimits {
return SupportedLimits{limitsFromJS(g.jsValue.Get("limits"))}
func (g Adapter) GetLimits() Limits {
return limitsFromJS(g.jsValue.Get("limits"))
}

func (g Adapter) Release() {} // no-op
15 changes: 7 additions & 8 deletions wgpu/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ static inline void gowebgpu_buffer_release(WGPUBuffer buffer, WGPUDevice device)
import "C"
import (
"errors"
"runtime/cgo"
"unsafe"
)

Expand Down Expand Up @@ -72,7 +71,7 @@ func (p *Buffer) GetUsage() BufferUsage {

//export gowebgpu_buffer_map_callback_go
func gowebgpu_buffer_map_callback_go(status C.WGPUMapAsyncStatus, userdata unsafe.Pointer) {
handle := *(*cgo.Handle)(userdata)
handle := lookupHandle(userdata)
defer handle.Delete()

cb, ok := handle.Value().(BufferMapCallback)
Expand All @@ -82,12 +81,12 @@ func gowebgpu_buffer_map_callback_go(status C.WGPUMapAsyncStatus, userdata unsaf
}

func (p *Buffer) MapAsync(mode MapMode, offset uint64, size uint64, callback BufferMapCallback) (err error) {
callbackHandle := cgo.NewHandle(callback)
callbackHandle := newHandle(callback)

var cb errorCallback = func(_ ErrorType, message string) {
err = errors.New("wgpu.(*Buffer).MapAsync(): " + message)
}
errorCallbackHandle := cgo.NewHandle(cb)
errorCallbackHandle := newHandle(cb)
defer errorCallbackHandle.Delete()

C.gowebgpu_buffer_map_async(
Expand All @@ -97,10 +96,10 @@ func (p *Buffer) MapAsync(mode MapMode, offset uint64, size uint64, callback Buf
C.size_t(size),
C.WGPUBufferMapCallbackInfo{
callback: C.WGPUBufferMapCallback(C.gowebgpu_buffer_map_callback_c),
userdata1: unsafe.Pointer(&callbackHandle),
userdata1: callbackHandle.ToPointer(),
},
p.deviceRef,
unsafe.Pointer(&errorCallbackHandle),
errorCallbackHandle.ToPointer(),
)
return
}
Expand All @@ -109,13 +108,13 @@ func (p *Buffer) Unmap() (err error) {
var cb errorCallback = func(_ ErrorType, message string) {
err = errors.New("wgpu.(*Buffer).Unmap(): " + message)
}
errorCallbackHandle := cgo.NewHandle(cb)
errorCallbackHandle := newHandle(cb)
defer errorCallbackHandle.Delete()

C.gowebgpu_buffer_unmap(
p.ref,
p.deviceRef,
unsafe.Pointer(&errorCallbackHandle),
errorCallbackHandle.ToPointer(),
)
return
}
Expand Down
9 changes: 7 additions & 2 deletions wgpu/buffer_js.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ func (g Buffer) GetMappedRange(offset, size uint) []byte {
}

func (g Buffer) MapAsync(mode MapMode, offset uint64, size uint64, callback BufferMapCallback) (err error) {
jsx.Await(g.jsValue.Call("mapAsync", uint32(mode), offset, size))
callback(BufferMapAsyncStatusSuccess) // TODO(kai): is this the right thing to do?
_, ok := jsx.Await(g.jsValue.Call("mapAsync", uint32(mode), offset, size))
if !ok {
callback(MapAsyncStatusError)
return
}

callback(MapAsyncStatusSuccess)
return
}

Expand Down
Loading