From ab7831cea27c2c1ad8cba76d27a2465ac724ceb7 Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Sun, 10 May 2026 15:00:47 +0200 Subject: [PATCH 1/6] obwgpu: use oliverbestmann/webgpu instead of cogentcore/webgpu --- base/iox/imagex/wrapjs_js.go | 2 +- base/websocket/websocket_js.go | 2 +- docs/content/gpu.md | 2 +- go.mod | 9 +++++++-- go.sum | 18 ++++++++++++++---- gpu/buffer.go | 14 +++++++------- gpu/cmd/webgpuinfo/main.go | 2 +- gpu/compute.go | 6 +++--- gpu/cpipeline.go | 4 ++-- gpu/device.go | 18 ++++++++---------- gpu/doc.go | 2 +- gpu/examples/drawidx/drawidx.go | 2 +- gpu/examples/drawtri/drawtri.go | 3 +++ gpu/examples/offscreen/offscreen.go | 2 +- gpu/examples/phong/phong.go | 2 +- gpu/format.go | 2 +- gpu/glfw.go | 4 ++-- gpu/glfw_js.go | 2 +- gpu/gpipeline.go | 6 +++--- gpu/gpu.go | 26 +++++++++++--------------- gpu/gpu_test.go | 2 +- gpu/gpudraw/system.go | 2 +- gpu/gsystem.go | 6 +++--- gpu/phong/phong.go | 2 +- gpu/phong/system.go | 2 +- gpu/pipeline.go | 4 ++-- gpu/render.go | 2 +- gpu/renderer.go | 2 +- gpu/rendertexture.go | 2 +- gpu/roles.go | 2 +- gpu/sampler.go | 4 ++-- gpu/shader.go | 8 ++++---- gpu/surface.go | 11 ++++------- gpu/texture.go | 18 +++++++++--------- gpu/types.go | 4 ++-- gpu/value.go | 16 ++++++++-------- gpu/values.go | 2 +- gpu/var.go | 2 +- gpu/vargroup.go | 6 +++--- gpu/vars.go | 6 +++--- system/driver/android/app.go | 2 +- system/driver/desktop/app.go | 2 +- system/driver/ios/app.go | 2 +- system/examples/drawidx/drawidx.go | 2 +- system/examples/drawtri/drawtri.go | 2 +- xyz/node.go | 2 +- xyz/solid.go | 2 +- xyz/xyzcore/render_js.go | 2 +- 48 files changed, 128 insertions(+), 119 deletions(-) diff --git a/base/iox/imagex/wrapjs_js.go b/base/iox/imagex/wrapjs_js.go index 97a5107f9d..704b82ad78 100644 --- a/base/iox/imagex/wrapjs_js.go +++ b/base/iox/imagex/wrapjs_js.go @@ -12,7 +12,7 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/colors/gradient" - "github.com/cogentcore/webgpu/jsx" + "github.com/oliverbestmann/webgpu/jsx" ) // WrapJS returns a JavaScript optimized wrapper around the given diff --git a/base/websocket/websocket_js.go b/base/websocket/websocket_js.go index 6c57b4306f..17507c2d62 100644 --- a/base/websocket/websocket_js.go +++ b/base/websocket/websocket_js.go @@ -9,7 +9,7 @@ package websocket import ( "syscall/js" - "github.com/cogentcore/webgpu/jsx" + "github.com/oliverbestmann/webgpu/jsx" ) // Client represents a WebSocket client connection. diff --git a/docs/content/gpu.md b/docs/content/gpu.md index 6b28bceda7..083805f128 100644 --- a/docs/content/gpu.md +++ b/docs/content/gpu.md @@ -19,7 +19,7 @@ The main gpu code is in the top-level `gpu` package, with the following sub-pack * [[doc:gpu/gpudraw]] implements GPU-accelerated texture-based versions of the Go [image/draw](https://pkg.go.dev/image/draw) api. This is used by the `Composer` framework for compositing images in the `core` GUI to construct the final rendered scene, and for drawing that scene on the actual hardware window (see [[render]] for details). -We maintain a separate [webgpu](https://github.com/cogentcore/webgpu) package that provides a Go and JS wrapper around the rust-based [wgpu](https://github.com/gfx-rs/wgpu) and [wgpu-native](https://github.com/gfx-rs/wgpu-native) packages that actually implement WebGPU itself on the desktop and mobile. This "native" version is just as performant as the much more difficult-to-use [Vulkan](https://www.vulkan.org/) framework, which we used to use. +We maintain a separate [webgpu](https://github.com/oliverbestmann/webgpu) package that provides a Go and JS wrapper around the rust-based [wgpu](https://github.com/gfx-rs/wgpu) and [wgpu-native](https://github.com/gfx-rs/wgpu-native) packages that actually implement WebGPU itself on the desktop and mobile. This "native" version is just as performant as the much more difficult-to-use [Vulkan](https://www.vulkan.org/) framework, which we used to use. ## Selecting a GPU Device diff --git a/go.mod b/go.mod index 734c002ca6..7ac5ad2e23 100644 --- a/go.mod +++ b/go.mod @@ -13,14 +13,13 @@ require ( github.com/bramvdbogaerde/go-scp v1.6.0 github.com/chewxy/math32 v1.11.1 github.com/cogentcore/reisen v0.0.0-20240814194831-4d884b6e7666 - github.com/cogentcore/webgpu v0.23.1-0.20260410073005-a2ae7d757168 github.com/cogentcore/yaegi v0.0.0-20260116172027-700fbf8949f3 github.com/coreos/go-oidc/v3 v3.17.0 github.com/ericchiang/css v1.4.0 github.com/faiface/beep v1.1.0 github.com/fsnotify/fsnotify v1.9.0 github.com/go-fonts/latin-modern v0.3.3 - github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1 + github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1.0.20260406072232-3ac4aa2bb164 github.com/go-text/typesetting v0.3.5-0.20260418130854-c41d02a44bec github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df github.com/gorilla/websocket v1.5.3 @@ -33,6 +32,7 @@ require ( github.com/mattn/go-shellwords v1.0.12 github.com/mitchellh/go-homedir v1.1.0 github.com/muesli/termenv v0.16.0 + github.com/oliverbestmann/webgpu v1.32.0 github.com/pelletier/go-toml/v2 v2.2.4 github.com/stretchr/testify v1.11.1 github.com/tdewolff/parse/v2 v2.8.5 @@ -63,6 +63,11 @@ require ( github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect + github.com/oliverbestmann/webgpu/libs-android v0.0.0-20260509160813-48db59792a15 // indirect + github.com/oliverbestmann/webgpu/libs-darwin v0.0.0-20260509160802-b09403b07cd3 // indirect + github.com/oliverbestmann/webgpu/libs-ios v0.0.0-20260509160803-765e39d2a48b // indirect + github.com/oliverbestmann/webgpu/libs-linux v0.0.0-20260509160809-2fefaf7c9ead // indirect + github.com/oliverbestmann/webgpu/libs-windows v0.0.0-20260509160807-0bc32b12c7bc // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/rivo/uniseg v0.4.7 // indirect diff --git a/go.sum b/go.sum index eabe5f2227..2a49a46c03 100644 --- a/go.sum +++ b/go.sum @@ -29,8 +29,6 @@ github.com/chewxy/math32 v1.11.1 h1:b7PGHlp8KjylDoU8RrcEsRuGZhJuz8haxnKfuMMRqy8= github.com/chewxy/math32 v1.11.1/go.mod h1:dOB2rcuFrCn6UHrze36WSLVPKtzPMRAQvBvUwkSsLqs= github.com/cogentcore/reisen v0.0.0-20240814194831-4d884b6e7666 h1:gmXMw/Xcva/2V5qRO920q4am1odNE0xFEGBzG7y7cus= github.com/cogentcore/reisen v0.0.0-20240814194831-4d884b6e7666/go.mod h1:HoDh/nWYrLffGjfVxUmbJHb0yZvcV3TwrN73WurddNs= -github.com/cogentcore/webgpu v0.23.1-0.20260410073005-a2ae7d757168 h1:K5en4IrBrolIAWvjrLuXRb9CvU1w+WMMi0Eu0KmcMfQ= -github.com/cogentcore/webgpu v0.23.1-0.20260410073005-a2ae7d757168/go.mod h1:DQLhF8pM/WkdaGpX6pKmZJPYsoR9x+hohhA1nnNuCa8= github.com/cogentcore/yaegi v0.0.0-20260116172027-700fbf8949f3 h1:y3Djpt/g3QTjFdj8cpvy/r8FsZsEa7PqHGjgsKXbta0= github.com/cogentcore/yaegi v0.0.0-20260116172027-700fbf8949f3/go.mod h1:XkOm++pRmWlk85p+hw71ZItfTeRdzqG23+2xjP9eb+M= github.com/coreos/go-oidc/v3 v3.17.0 h1:hWBGaQfbi0iVviX4ibC7bk8OKT5qNr4klBaCHVNvehc= @@ -56,8 +54,8 @@ github.com/go-audio/riff v1.0.0/go.mod h1:l3cQwc85y79NQFCRB7TiPoNiaijp6q8Z0Uv38r github.com/go-audio/wav v1.0.0/go.mod h1:3yoReyQOsiARkvPl3ERCi8JFjihzG6WhjYpZCf5zAWE= github.com/go-fonts/latin-modern v0.3.3 h1:g2xNgI8yzdNzIVm+qvbMryB6yGPe0pSMss8QT3QwlJ0= github.com/go-fonts/latin-modern v0.3.3/go.mod h1:tHaiWDGze4EPB0Go4cLT5M3QzRY3peya09Z/8KSCrpY= -github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1 h1:nIVzcwqIaO1mK8LFr0fGkKpgQD4wJDDHRyv4t5k40Ps= -github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1/go.mod h1:T5Dn0JwIJOX1euPZ/iT4tq6nFYtmukjcYa7937HuYK8= +github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1.0.20260406072232-3ac4aa2bb164 h1:c87Nyz3ox3QbCl0yozQPeVPW4mmgFOSKY4yyc1TrS0w= +github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1.0.20260406072232-3ac4aa2bb164/go.mod h1:T5Dn0JwIJOX1euPZ/iT4tq6nFYtmukjcYa7937HuYK8= github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA= github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08= github.com/go-text/typesetting v0.3.5-0.20260418130854-c41d02a44bec h1:qkk9+cZlaY8920dQrhY8GoI91N72f58XmJgGDkkDiaA= @@ -124,6 +122,18 @@ github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= +github.com/oliverbestmann/webgpu v1.32.0 h1:JyGhxkBD/HHi/VB7WDy4VU2Q2enoUyWSXjhVpqbfokQ= +github.com/oliverbestmann/webgpu v1.32.0/go.mod h1:0UEcoJ8VnwnAqo3JfzdFptplxtjhaQasc3n/nYZOrPA= +github.com/oliverbestmann/webgpu/libs-android v0.0.0-20260509160813-48db59792a15 h1:HPxVSV8C8JaxGfa9hjDhzNmryoqPF3EwESBTFWpxNBo= +github.com/oliverbestmann/webgpu/libs-android v0.0.0-20260509160813-48db59792a15/go.mod h1:tczQXCdsoFy+FTJVsZSve/vF8cmWEkxhvjcyY2Rujp8= +github.com/oliverbestmann/webgpu/libs-darwin v0.0.0-20260509160802-b09403b07cd3 h1:NbBG2+pwqKcNfKUKtjWOj+02RkXSUWVkxY3hqzgyjSA= +github.com/oliverbestmann/webgpu/libs-darwin v0.0.0-20260509160802-b09403b07cd3/go.mod h1:XoHM/ZcjQqJQyEfQjU0ScDkxvQRWfZLxKP8IrEz4xyo= +github.com/oliverbestmann/webgpu/libs-ios v0.0.0-20260509160803-765e39d2a48b h1:j+uRWcmAl3Y4RPJ4rmxnc1DRHgZ6VNywZPsRHUEuD0M= +github.com/oliverbestmann/webgpu/libs-ios v0.0.0-20260509160803-765e39d2a48b/go.mod h1:IV+TkwmPA0yMzZZoz0Aj4X+22WLEQq2TOyN4/0k8lgs= +github.com/oliverbestmann/webgpu/libs-linux v0.0.0-20260509160809-2fefaf7c9ead h1:kkY04PFBq6I58BwK5cwJ3LRp+xy7Y5/jrkLHBdcBL68= +github.com/oliverbestmann/webgpu/libs-linux v0.0.0-20260509160809-2fefaf7c9ead/go.mod h1:SOeo2YWe2UxWxOeAHyZtwaSXkBbP78cGnm7I+6lIWV0= +github.com/oliverbestmann/webgpu/libs-windows v0.0.0-20260509160807-0bc32b12c7bc h1:YVCfgeByW1ibKniigozHCwF2wC26TDmAIJwQG40bCBM= +github.com/oliverbestmann/webgpu/libs-windows v0.0.0-20260509160807-0bc32b12c7bc/go.mod h1:58qRJHG2+mjEu/AKJFh026bz3xE1zEHYt41i4TBM8NE= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= diff --git a/gpu/buffer.go b/gpu/buffer.go index b7fbdc0d2f..66a234a1f7 100644 --- a/gpu/buffer.go +++ b/gpu/buffer.go @@ -8,14 +8,14 @@ import ( "fmt" "cogentcore.org/core/base/errors" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // note: WriteBuffer is the preferred method for writing, so we only need to manage Read // BufferMapAsyncError returns an error message if the status is not success. -func BufferMapAsyncError(status wgpu.BufferMapAsyncStatus) error { - if status != wgpu.BufferMapAsyncStatusSuccess { +func BufferMapAsyncError(status wgpu.MapAsyncStatus) error { + if status != wgpu.MapAsyncStatusSuccess { return errors.New("gpu BufferMapAsync was not successful") } return nil @@ -24,8 +24,8 @@ func BufferMapAsyncError(status wgpu.BufferMapAsyncStatus) error { // BufferReadSync does a MapAsync on given buffer, waiting on the device // until the sync is complete, and returning error if any issues. func BufferReadSync(device *Device, size int, buffer *wgpu.Buffer) error { - var status wgpu.BufferMapAsyncStatus - err := buffer.MapAsync(wgpu.MapModeRead, 0, uint64(size), func(s wgpu.BufferMapAsyncStatus) { + var status wgpu.MapAsyncStatus + err := buffer.TryMapAsync(wgpu.MapModeRead, 0, uint64(size), func(s wgpu.MapAsyncStatus) { status = s }) if errors.Log(err) != nil { @@ -44,9 +44,9 @@ func ValueReadSync(device *Device, values ...*Value) error { return nil } var errs []error - status := make([]wgpu.BufferMapAsyncStatus, nv) + status := make([]wgpu.MapAsyncStatus, nv) for i, vl := range values { - err := vl.readBuffer.MapAsync(wgpu.MapModeRead, 0, uint64(vl.AllocSize), func(s wgpu.BufferMapAsyncStatus) { + err := vl.readBuffer.TryMapAsync(wgpu.MapModeRead, 0, uint64(vl.AllocSize), func(s wgpu.MapAsyncStatus) { status[i] = s }) if err != nil { diff --git a/gpu/cmd/webgpuinfo/main.go b/gpu/cmd/webgpuinfo/main.go index 7f326e882e..0a0aa6665b 100644 --- a/gpu/cmd/webgpuinfo/main.go +++ b/gpu/cmd/webgpuinfo/main.go @@ -10,7 +10,7 @@ import ( "cogentcore.org/core/base/reflectx" "cogentcore.org/core/gpu" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) func main() { diff --git a/gpu/compute.go b/gpu/compute.go index cf6ad8be15..e0b34592a1 100644 --- a/gpu/compute.go +++ b/gpu/compute.go @@ -11,7 +11,7 @@ import ( "sync" "cogentcore.org/core/base/errors" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // ComputeSystem manages a system of ComputePipelines that all share @@ -111,7 +111,7 @@ func (sy *ComputeSystem) Config() { // compute commands. This is automatically called by // BeginRenderPass and the result maintained in [CommandEncoder]. func (sy *ComputeSystem) NewCommandEncoder() (*wgpu.CommandEncoder, error) { - cmd, err := sy.device.Device.CreateCommandEncoder(nil) + cmd, err := sy.device.Device.TryCreateCommandEncoder(nil) if errors.Log(err) != nil { return nil, err } @@ -150,7 +150,7 @@ func (sy *ComputeSystem) EndComputePass() error { sy.ComputeEncoder = nil sy.CommandEncoder = nil ce.Release() // must happen before Finish - cmdBuffer, err := cmd.Finish(nil) + cmdBuffer, err := cmd.TryFinish(nil) if errors.Log(err) != nil { return err } diff --git a/gpu/cpipeline.go b/gpu/cpipeline.go index b1ece9513e..c867f66a89 100644 --- a/gpu/cpipeline.go +++ b/gpu/cpipeline.go @@ -11,7 +11,7 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/base/fsx" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // ComputePipeline is a compute pipeline, which runs shader code on vars data. @@ -192,7 +192,7 @@ func (pl *ComputePipeline) Config(rebuild bool) error { defer play.Release() sh := pl.EntryByType(ComputeShader) - cp, err := pl.System.Device().Device.CreateComputePipeline(&wgpu.ComputePipelineDescriptor{ + cp, err := pl.System.Device().Device.TryCreateComputePipeline(&wgpu.ComputePipelineDescriptor{ Layout: play, Compute: wgpu.ProgrammableStageDescriptor{ Module: sh.Shader.module, diff --git a/gpu/device.go b/gpu/device.go index 15cc30e004..fc80ff7d2f 100644 --- a/gpu/device.go +++ b/gpu/device.go @@ -8,7 +8,7 @@ import ( "fmt" "cogentcore.org/core/base/errors" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Device holds Device and associated Queue info. @@ -44,30 +44,28 @@ func NewComputeDevice(gpu *GPU) (*Device, error) { // hardware, so we may need to detect that. OTOH it probably won't be useful for compute anyway, // but we can just sort that out later // note: on web / chromium / dawn, limited to 10: https://issues.chromium.org/issues/366151398?pli=1 - limits.MaxStorageBuffersPerShaderStage = gpu.Limits.Limits.MaxStorageBuffersPerShaderStage - // fmt.Println("MaxStorageBuffersPerShaderStage:", gpu.Limits.Limits.MaxStorageBuffersPerShaderStage) + limits.MaxStorageBuffersPerShaderStage = gpu.Limits.MaxStorageBuffersPerShaderStage + // fmt.Println("MaxStorageBuffersPerShaderStage:", gpu.Limits.MaxStorageBuffersPerShaderStage) // note: these limits are being processed and allow the MaxBufferSize to be the // controlling factor -- if we don't set these, then the slrand example doesn't // work above a smaller limit. // TODO: converting these limits to int may cause issues on 32-bit systems - limits.MaxUniformBufferBindingSize = uint64(MemSizeAlignDown(int(gpu.Limits.Limits.MaxUniformBufferBindingSize), int(gpu.Limits.Limits.MinUniformBufferOffsetAlignment))) + limits.MaxUniformBufferBindingSize = uint64(MemSizeAlignDown(int(gpu.Limits.MaxUniformBufferBindingSize), int(gpu.Limits.MinUniformBufferOffsetAlignment))) - limits.MaxStorageBufferBindingSize = uint64(MemSizeAlignDown(int(gpu.Limits.Limits.MaxStorageBufferBindingSize), int(gpu.Limits.Limits.MinStorageBufferOffsetAlignment))) + limits.MaxStorageBufferBindingSize = uint64(MemSizeAlignDown(int(gpu.Limits.MaxStorageBufferBindingSize), int(gpu.Limits.MinStorageBufferOffsetAlignment))) // note: this limit is not working properly: g4 := uint64(0xFFFFFF00) - limits.MaxBufferSize = uint64(MemSizeAlignDown(int(min(gpu.Limits.Limits.MaxBufferSize, g4)), int(gpu.Limits.Limits.MinStorageBufferOffsetAlignment))) + limits.MaxBufferSize = uint64(MemSizeAlignDown(int(min(gpu.Limits.MaxBufferSize, g4)), int(gpu.Limits.MinStorageBufferOffsetAlignment))) if limits.MaxBufferSize == 0 { limits.MaxBufferSize = g4 } - // limits.MaxBindGroups = gpu.Limits.Limits.MaxBindGroups // note: no point in changing -- web constraint + // limits.MaxBindGroups = gpu.Limits.MaxBindGroups // note: no point in changing -- web constraint if Debug { fmt.Printf("Requesting sizes: MaxStorageBufferBindingSize: %X MaxBufferSize: %X\n", limits.MaxStorageBufferBindingSize, limits.MaxBufferSize) } desc := wgpu.DeviceDescriptor{ - RequiredLimits: &wgpu.RequiredLimits{ - Limits: limits, - }, + RequiredLimits: &limits, } wdev, err := gpu.GPU.RequestDevice(&desc) if errors.Log(err) != nil { diff --git a/gpu/doc.go b/gpu/doc.go index fcb240abcc..b5e4101c50 100644 --- a/gpu/doc.go +++ b/gpu/doc.go @@ -5,7 +5,7 @@ /* Package gpu implements a convenient interface to the WebGPU graphics and compute framework, in Go, using the -[github.com/cogentcore/webgpu] bindings. +[github.com/oliverbestmann/webgpu] bindings. The Cogent Core GUI framework runs on top of this. */ diff --git a/gpu/examples/drawidx/drawidx.go b/gpu/examples/drawidx/drawidx.go index 46b6c4ae66..8ee65a4fdb 100644 --- a/gpu/examples/drawidx/drawidx.go +++ b/gpu/examples/drawidx/drawidx.go @@ -15,7 +15,7 @@ import ( "cogentcore.org/core/gpu" "cogentcore.org/core/math32" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) //go:embed indexed.wgsl diff --git a/gpu/examples/drawtri/drawtri.go b/gpu/examples/drawtri/drawtri.go index 64cac16f2f..0f58dc4141 100644 --- a/gpu/examples/drawtri/drawtri.go +++ b/gpu/examples/drawtri/drawtri.go @@ -8,6 +8,7 @@ import ( _ "embed" "fmt" "image" + "os" "runtime" "time" @@ -20,6 +21,8 @@ var trianglelit string func init() { // must lock main thread for gpu! runtime.LockOSThread() + gpu.Debug = true + os.Setenv("RUST_BACKTRACE", "full") } func main() { diff --git a/gpu/examples/offscreen/offscreen.go b/gpu/examples/offscreen/offscreen.go index c3b69853a2..5e77475d2a 100644 --- a/gpu/examples/offscreen/offscreen.go +++ b/gpu/examples/offscreen/offscreen.go @@ -19,7 +19,7 @@ import ( "cogentcore.org/core/gpu" "cogentcore.org/core/gpu/gpudraw" "cogentcore.org/core/math32" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) //go:embed indexed.wgsl diff --git a/gpu/examples/phong/phong.go b/gpu/examples/phong/phong.go index e9ab022796..a2df859ddc 100644 --- a/gpu/examples/phong/phong.go +++ b/gpu/examples/phong/phong.go @@ -19,7 +19,7 @@ import ( "cogentcore.org/core/gpu/phong" "cogentcore.org/core/gpu/shape" "cogentcore.org/core/math32" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) func init() { diff --git a/gpu/format.go b/gpu/format.go index ee9cf3decc..d08b29b663 100644 --- a/gpu/format.go +++ b/gpu/format.go @@ -9,7 +9,7 @@ import ( "image" "log" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // TextureFormat describes the size and WebGPU format of a Texture. diff --git a/gpu/glfw.go b/gpu/glfw.go index 0973b4c908..cab85d59c7 100644 --- a/gpu/glfw.go +++ b/gpu/glfw.go @@ -11,9 +11,9 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/system" - "github.com/cogentcore/webgpu/wgpu" - "github.com/cogentcore/webgpu/wgpuglfw" "github.com/go-gl/glfw/v3.4/glfw" + "github.com/oliverbestmann/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpuglfw" ) // note: this file contains the glfw dependencies, for desktop platform builds diff --git a/gpu/glfw_js.go b/gpu/glfw_js.go index dfbccbba09..809df5e6ef 100644 --- a/gpu/glfw_js.go +++ b/gpu/glfw_js.go @@ -12,7 +12,7 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/system/driver/web/jsfs" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // GLFWCreateWindow is a helper function intended only for use in simple examples that makes a diff --git a/gpu/gpipeline.go b/gpu/gpipeline.go index a0fefe9ccf..c3367e7c87 100644 --- a/gpu/gpipeline.go +++ b/gpu/gpipeline.go @@ -6,7 +6,7 @@ package gpu import ( "cogentcore.org/core/base/errors" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // GraphicsPipeline is a Pipeline specifically for the Graphics stack. @@ -185,7 +185,7 @@ func (pl *GraphicsPipeline) Config(rebuild bool) error { if pl.System.Render().Depth.texture != nil { pd.DepthStencil = &wgpu.DepthStencilState{ Format: pl.System.Render().Depth.Format.Format, - DepthWriteEnabled: true, + DepthWriteEnabled: wgpu.OptionalBoolTrue, DepthCompare: wgpu.CompareFunctionLess, StencilFront: wgpu.StencilFaceState{ Compare: wgpu.CompareFunctionAlways, @@ -195,7 +195,7 @@ func (pl *GraphicsPipeline) Config(rebuild bool) error { }, } } - rp, err := pl.System.Device().Device.CreateRenderPipeline(pd) + rp, err := pl.System.Device().Device.TryCreateRenderPipeline(pd) if errors.Log(err) != nil { return err } diff --git a/gpu/gpu.go b/gpu/gpu.go index 27bef9df28..bab0663dbe 100644 --- a/gpu/gpu.go +++ b/gpu/gpu.go @@ -16,7 +16,7 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/base/reflectx" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) func init() { @@ -88,7 +88,7 @@ type GPU struct { Properties wgpu.AdapterInfo // Limits are the limits of the current GPU adapter. - Limits wgpu.SupportedLimits + Limits wgpu.Limits // ComputeOnly indicates if this GPU is only used for compute, // which determines if it listens to GPU_COMPUTE_DEVICE @@ -181,7 +181,7 @@ func (gp *GPU) init(sf *wgpu.Surface) error { fmt.Println(gp.PropertiesString()) } - gp.MaxComputeWorkGroupCount1D = int(gp.Limits.Limits.MaxComputeWorkgroupsPerDimension) + gp.MaxComputeWorkGroupCount1D = int(gp.Limits.MaxComputeWorkgroupsPerDimension) dv := actualVendorName(&gp.Properties) if Debug || DebugAdapter { fmt.Println("GPU device vendor:", dv) @@ -201,7 +201,7 @@ func (gp *GPU) init(sf *wgpu.Surface) error { // string that the adapter VendorName contains, // or, failing that, from the description. func actualVendorName(ai *wgpu.AdapterInfo) string { - nm := strings.ToLower(ai.VendorName) + nm := strings.ToLower(ai.Vendor) // source: https://www.reddit.com/r/vulkan/comments/4ta9nj/is_there_a_comprehensive_list_of_the_names_and/ switch nm { case "0x10de": @@ -217,7 +217,7 @@ func actualVendorName(ai *wgpu.AdapterInfo) string { case "0x8086": return "intel" } - vd := strings.ToLower(ai.DriverDescription) + vd := strings.ToLower(ai.Description) if strings.Contains(vd, "apple") { return "apple" } @@ -225,13 +225,10 @@ func actualVendorName(ai *wgpu.AdapterInfo) string { } func adapterName(ai *wgpu.AdapterInfo) string { - if ai.Name != "" && !strings.HasPrefix(ai.Name, "0x") { - return ai.Name + if ai.Description != "" && !strings.HasPrefix(ai.Description, "0x") { + return ai.Description } - if ai.DriverDescription != "" && !strings.HasPrefix(ai.DriverDescription, "0x") { - return ai.DriverDescription - } - return ai.VendorName + return ai.Vendor } func (gp *GPU) SelectGraphicsGPU(gpus []*wgpu.Adapter) int { @@ -259,7 +256,7 @@ func (gp *GPU) SelectGraphicsGPU(gpus []*wgpu.Adapter) int { } pnm := adapterName(&props) if strings.Contains(pnm, trgDevNm) { - devNm := props.Name + devNm := pnm if Debug { log.Printf("gpu: selected device named: %s, specified in GPU_DEVICE or GPU_COMPUTE_DEVICE environment variable, index: %d\n", devNm, gi) } @@ -349,9 +346,8 @@ func (gp *GPU) SelectComputeGPU(gpus []*wgpu.Adapter) int { } pnm := adapterName(&props) if strings.Contains(pnm, trgDevNm) { - devNm := props.Name if Debug { - log.Printf("gpu: selected device named: %s, specified in GPU_DEVICE or GPU_COMPUTE_DEVICE environment variable, index: %d\n", devNm, gi) + log.Printf("gpu: selected device named: %s, specified in GPU_DEVICE or GPU_COMPUTE_DEVICE environment variable, index: %d\n", pnm, gi) } return gi } @@ -408,7 +404,7 @@ func (gp *GPU) NewDevice() (*Device, error) { // PropertiesString returns a human-readable summary of the GPU properties. func (gp *GPU) PropertiesString() string { - return "\n######## GPU Properties\n" + reflectx.StringJSON(&gp.Properties) + reflectx.StringJSON(gp.Limits.Limits) + return "\n######## GPU Properties\n" + reflectx.StringJSON(&gp.Properties) + reflectx.StringJSON(gp.Limits) } // NoDisplayGPU Initializes WebGPU and returns that and a new diff --git a/gpu/gpu_test.go b/gpu/gpu_test.go index 3d41978bbd..9727c53600 100644 --- a/gpu/gpu_test.go +++ b/gpu/gpu_test.go @@ -12,7 +12,7 @@ import ( _ "cogentcore.org/core/base/iox/imagex" "cogentcore.org/core/math32" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" "github.com/stretchr/testify/assert" ) diff --git a/gpu/gpudraw/system.go b/gpu/gpudraw/system.go index e0a69ec625..efc9dd1acb 100644 --- a/gpu/gpudraw/system.go +++ b/gpu/gpudraw/system.go @@ -14,7 +14,7 @@ import ( "cogentcore.org/core/base/slicesx" "cogentcore.org/core/gpu" "cogentcore.org/core/gpu/drawmatrix" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) //go:embed shaders/*.wgsl diff --git a/gpu/gsystem.go b/gpu/gsystem.go index e6aec7ff68..ab7e85f1ab 100644 --- a/gpu/gsystem.go +++ b/gpu/gsystem.go @@ -12,7 +12,7 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/base/iox/imagex" "cogentcore.org/core/colors" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // GraphicsSystem manages a system of Pipelines that all share @@ -203,7 +203,7 @@ func (sy *GraphicsSystem) SetClearDepthStencil(depth float32, stencil uint32) *G // rendering commands. This is automatically called by // BeginRenderPass and the result maintained in CurrentCommandEncoder. func (sy *GraphicsSystem) NewCommandEncoder() (*wgpu.CommandEncoder, error) { - cmd, err := sy.device.Device.CreateCommandEncoder(nil) + cmd, err := sy.device.Device.TryCreateCommandEncoder(nil) if errors.Log(err) != nil { return nil, err } @@ -262,7 +262,7 @@ func (sy *GraphicsSystem) SubmitRender(rp *wgpu.RenderPassEncoder) error { cmd := sy.CommandEncoder sy.CommandEncoder = nil rp.Release() // must happen before Finish - cmdBuffer, err := cmd.Finish(nil) + cmdBuffer, err := cmd.TryFinish(nil) if errors.Log(err) != nil { return err } diff --git a/gpu/phong/phong.go b/gpu/phong/phong.go index d4e3c77140..7ec68db1c8 100644 --- a/gpu/phong/phong.go +++ b/gpu/phong/phong.go @@ -14,7 +14,7 @@ import ( "cogentcore.org/core/base/ordmap" "cogentcore.org/core/gpu" "cogentcore.org/core/gpu/shape" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // MaxLights is upper limit on number of any given type of light diff --git a/gpu/phong/system.go b/gpu/phong/system.go index 0b7e5366a6..c8180724e2 100644 --- a/gpu/phong/system.go +++ b/gpu/phong/system.go @@ -9,7 +9,7 @@ import ( "unsafe" "cogentcore.org/core/gpu" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) //go:embed shaders/*.wgsl diff --git a/gpu/pipeline.go b/gpu/pipeline.go index a474317034..0b0a263b76 100644 --- a/gpu/pipeline.go +++ b/gpu/pipeline.go @@ -9,7 +9,7 @@ import ( "log/slog" "cogentcore.org/core/base/errors" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Pipeline is the shared Base for Graphics and Compute Pipelines. @@ -134,7 +134,7 @@ func (pl *Pipeline) bindLayout(used ...*Var) (*wgpu.PipelineLayout, error) { } }() } - rpl, err := pl.System.Device().Device.CreatePipelineLayout(&wgpu.PipelineLayoutDescriptor{ + rpl, err := pl.System.Device().Device.TryCreatePipelineLayout(&wgpu.PipelineLayoutDescriptor{ Label: pl.Name, BindGroupLayouts: lays, }) diff --git a/gpu/render.go b/gpu/render.go index 611412010f..10c903f034 100644 --- a/gpu/render.go +++ b/gpu/render.go @@ -11,7 +11,7 @@ import ( "log" "cogentcore.org/core/colors" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Render manages various elements needed for rendering, diff --git a/gpu/renderer.go b/gpu/renderer.go index ef295bff18..331e33df09 100644 --- a/gpu/renderer.go +++ b/gpu/renderer.go @@ -7,7 +7,7 @@ package gpu import ( "image" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Renderer is an interface for something that can actually be rendered to. diff --git a/gpu/rendertexture.go b/gpu/rendertexture.go index 5b6ecc2cd2..fff52274fd 100644 --- a/gpu/rendertexture.go +++ b/gpu/rendertexture.go @@ -7,7 +7,7 @@ package gpu import ( "image" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // RenderTexture is an offscreen, non-window-backed rendering target, diff --git a/gpu/roles.go b/gpu/roles.go index 8b67dfd233..a364a37c89 100644 --- a/gpu/roles.go +++ b/gpu/roles.go @@ -4,7 +4,7 @@ package gpu -import "github.com/cogentcore/webgpu/wgpu" +import "github.com/oliverbestmann/webgpu/wgpu" // VarRoles are the functional roles of variables, type VarRoles int32 //enums:enum diff --git a/gpu/sampler.go b/gpu/sampler.go index fa6542d04d..d86896ae00 100644 --- a/gpu/sampler.go +++ b/gpu/sampler.go @@ -6,7 +6,7 @@ package gpu import ( "cogentcore.org/core/base/errors" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Sampler represents a WebGPU image sampler @@ -43,7 +43,7 @@ func (sm *Sampler) Config(dev *Device) error { if sm.sampler != nil { return nil } - samp, err := dev.Device.CreateSampler(&wgpu.SamplerDescriptor{ + samp, err := dev.Device.TryCreateSampler(&wgpu.SamplerDescriptor{ AddressModeU: sm.UMode.Mode(), AddressModeV: sm.VMode.Mode(), AddressModeW: sm.WMode.Mode(), diff --git a/gpu/shader.go b/gpu/shader.go index 4d9f56bd0d..c20d9a88ec 100644 --- a/gpu/shader.go +++ b/gpu/shader.go @@ -10,7 +10,7 @@ import ( "path/filepath" "cogentcore.org/core/base/errors" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Shader manages a single Shader program, which can have multiple @@ -56,9 +56,9 @@ func (sh *Shader) OpenFileFS(fsys fs.FS, fname string) error { // OpenCode loads given WGSL ".wgl" code for the Shader. func (sh *Shader) OpenCode(code string) error { - module, err := sh.device.Device.CreateShaderModule(&wgpu.ShaderModuleDescriptor{ - Label: sh.Name, - WGSLDescriptor: &wgpu.ShaderModuleWGSLDescriptor{Code: code}, + module, err := sh.device.Device.TryCreateShaderModule(&wgpu.ShaderModuleDescriptor{ + Label: sh.Name, + WGSLSource: &wgpu.ShaderSourceWGSL{Code: code}, }) if errors.Log(err) != nil { return err diff --git a/gpu/surface.go b/gpu/surface.go index 7c5b469d45..fc3c102899 100644 --- a/gpu/surface.go +++ b/gpu/surface.go @@ -9,7 +9,7 @@ import ( "sync" "cogentcore.org/core/base/errors" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Surface manages the physical device for the visible image @@ -110,21 +110,18 @@ func (sf *Surface) Size() image.Point { // target for rendering. func (sf *Surface) GetCurrentTexture() (*wgpu.TextureView, error) { sf.Lock() // we remain locked until submit! - texture, err := sf.surface.GetCurrentTexture() + texture, err := sf.surface.TryGetCurrentTexture() if errors.Log(err) != nil { return nil, err } // Note: we need to specify a descriptor here so that we use the correct // format, which may be different from the default format, such as when // it is srgb. - view, err := texture.CreateView(&wgpu.TextureViewDescriptor{ + view, err := texture.TryCreateView(&wgpu.TextureViewDescriptor{ MipLevelCount: texture.GetMipLevelCount(), ArrayLayerCount: texture.GetDepthOrArrayLayers(), Format: sf.Format.Format, }) - if errors.Log(err) != nil { - return nil, err - } sf.curTexture = view return view, nil } @@ -175,7 +172,7 @@ func (sf *Surface) InitConfig() error { // Config configures the surface based on the surface configuration. func (sf *Surface) Config() { - sf.surface.Configure(sf.GPU.GPU, sf.device.Device, sf.config) + sf.surface.Configure(sf.device.Device, sf.config) } // Reconfig reconfigures the surface. diff --git a/gpu/texture.go b/gpu/texture.go index b2ce015cea..74ab7b37a8 100644 --- a/gpu/texture.go +++ b/gpu/texture.go @@ -10,7 +10,7 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/base/iox/imagex" "cogentcore.org/core/base/slicesx" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Texture represents a WebGPU Texture with an associated TextureView. @@ -93,14 +93,14 @@ func (tx *Texture) SetFromGoImage(img image.Image, layer int) error { // https://www.w3.org/TR/webgpu/#gpuimagecopytexture tx.device.Queue.WriteTexture( - &wgpu.ImageCopyTexture{ + &wgpu.TexelCopyTextureInfo{ Aspect: wgpu.TextureAspectAll, Texture: tx.texture, MipLevel: 0, Origin: wgpu.Origin3D{X: 0, Y: 0, Z: 0}, }, rimg.Pix, - &wgpu.TextureDataLayout{ + &wgpu.TexelCopyBufferLayout{ Offset: 0, BytesPerRow: 4 * uint32(sz.X), RowsPerImage: uint32(sz.Y), @@ -116,7 +116,7 @@ func (tx *Texture) CreateTexture(usage wgpu.TextureUsage) error { tx.ReleaseTexture() size := tx.Format.Extent3D() - t, err := tx.device.Device.CreateTexture(&wgpu.TextureDescriptor{ + t, err := tx.device.Device.TryCreateTexture(&wgpu.TextureDescriptor{ Label: tx.Name, Size: size, MipLevelCount: 1, @@ -129,7 +129,7 @@ func (tx *Texture) CreateTexture(usage wgpu.TextureUsage) error { return err } tx.texture = t - vw, err := t.CreateView(nil) + vw, err := t.TryCreateView(nil) if errors.Log(err) != nil { return err } @@ -236,7 +236,7 @@ func (tx *Texture) ConfigReadBuffer() error { if tx.readBuffer != nil && tx.ReadBufferDims == *dims { return nil } - b, err := tx.device.Device.CreateBuffer(&wgpu.BufferDescriptor{ + b, err := tx.device.Device.TryCreateBuffer(&wgpu.BufferDescriptor{ Size: buffSize, Usage: wgpu.BufferUsageMapRead | wgpu.BufferUsageCopyDst, }) @@ -259,9 +259,9 @@ func (tx *Texture) CopyToReadBuffer(cmd *wgpu.CommandEncoder) error { size := tx.Format.Extent3D() cmd.CopyTextureToBuffer( tx.texture.AsImageCopy(), - &wgpu.ImageCopyBuffer{ + &wgpu.TexelCopyBufferInfo{ Buffer: tx.readBuffer, - Layout: wgpu.TextureDataLayout{ + Layout: wgpu.TexelCopyBufferLayout{ Offset: 0, BytesPerRow: uint32(tx.ReadBufferDims.PaddedRowSize), RowsPerImage: wgpu.CopyStrideUndefined, @@ -330,7 +330,7 @@ func (tx *Texture) ReadDataMapped() ([]byte, error) { buffSize := dims.PaddedSize() if tx.readBuffer == nil || tx.ReadBufferDims != *dims { - b, err := tx.device.Device.CreateBuffer(&wgpu.BufferDescriptor{ + b, err := tx.device.Device.TryCreateBuffer(&wgpu.BufferDescriptor{ Size: buffSize, Usage: wgpu.BufferUsageMapRead | wgpu.BufferUsageCopyDst, }) diff --git a/gpu/types.go b/gpu/types.go index fd45d72e4e..ab1fe9b605 100644 --- a/gpu/types.go +++ b/gpu/types.go @@ -5,7 +5,7 @@ package gpu import ( - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // See: https://www.khronos.org/opengl/wiki/Data_Type_(GLSL) @@ -139,7 +139,7 @@ var TypeSizes = map[Types]int{ // TypeToVertexFormat maps gpu.Types to WebGPU VertexFormat var TypeToVertexFormat = map[Types]wgpu.VertexFormat{ - UndefinedType: wgpu.VertexFormatUndefined, + UndefinedType: wgpu.VertexFormat(0), // Bool32: wgpu.VertexFormatUint32, // Int16: wgpu.VertexFormatR16Sint, // Uint16: wgpu.VertexFormatR16Uint, diff --git a/gpu/value.go b/gpu/value.go index c0fecb9aec..5ec6bc433b 100644 --- a/gpu/value.go +++ b/gpu/value.go @@ -11,7 +11,7 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/base/slicesx" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Value represents a specific value of a Var variable, with @@ -171,7 +171,7 @@ func (vl *Value) CreateBuffer() error { } vl.Release() - buf, err := vl.device.Device.CreateBuffer(&wgpu.BufferDescriptor{ + buf, err := vl.device.Device.TryCreateBuffer(&wgpu.BufferDescriptor{ Size: uint64(sz), Label: vl.Name, Usage: vl.vvar.bufferUsages(), @@ -281,7 +281,7 @@ func (vl *Value) SetFromBytes(from []byte) error { if vl.buffer == nil || vl.AllocSize != tb { vl.varGroupDirty() // only if tb is different; buffer created in bindGroupEntry so not nil here vl.Release() - buf, err := vl.device.Device.CreateBufferInit(&wgpu.BufferInitDescriptor{ + buf, err := vl.device.Device.TryCreateBufferInit(&wgpu.BufferInitDescriptor{ Label: vl.Name, Contents: from, Usage: vl.vvar.bufferUsages(), @@ -295,7 +295,7 @@ func (vl *Value) SetFromBytes(from []byte) error { vl.CreateReadBuffer() } } else { - err := vl.device.Queue.WriteBuffer(vl.buffer, 0, from) + err := vl.device.Queue.TryWriteBuffer(vl.buffer, 0, from) if errors.Log(err) != nil { return err } @@ -357,7 +357,7 @@ func (vl *Value) WriteDynamicBuffer() error { if vl.buffer == nil || nb != vl.AllocSize { vl.varGroupDirty() // only if nb is different; buffer created in bindGroupEntry so not nil here vl.Release() - buf, err := vl.device.Device.CreateBufferInit(&wgpu.BufferInitDescriptor{ + buf, err := vl.device.Device.TryCreateBufferInit(&wgpu.BufferInitDescriptor{ Label: vl.Name, Contents: vl.dynamicBuffer, Usage: vl.vvar.bufferUsages(), @@ -368,7 +368,7 @@ func (vl *Value) WriteDynamicBuffer() error { vl.buffer = buf vl.AllocSize = nb } else { - err := vl.device.Queue.WriteBuffer(vl.buffer, 0, vl.dynamicBuffer) + err := vl.device.Queue.TryWriteBuffer(vl.buffer, 0, vl.dynamicBuffer) if errors.Log(err) != nil { return err } @@ -462,7 +462,7 @@ func (vl *Value) CreateReadBuffer() error { } vl.ReleaseRead() - buf, err := vl.device.Device.CreateBuffer(&wgpu.BufferDescriptor{ + buf, err := vl.device.Device.TryCreateBuffer(&wgpu.BufferDescriptor{ Size: uint64(sz), Label: vl.Name, Usage: wgpu.BufferUsageMapRead | wgpu.BufferUsageCopyDst, @@ -495,7 +495,7 @@ func (vl *Value) GPUToRead(cmd *wgpu.CommandEncoder) error { if err := vl.readNilCheck(); err != nil { return errors.Log(err) } - return cmd.CopyBufferToBuffer(vl.buffer, 0, vl.readBuffer, 0, uint64(vl.AllocSize)) + return cmd.TryCopyBufferToBuffer(vl.buffer, 0, vl.readBuffer, 0, uint64(vl.AllocSize)) } // ReadSync reads data from GPU to CPU side of the read buffer. diff --git a/gpu/values.go b/gpu/values.go index b2a764fa00..06ae0314ea 100644 --- a/gpu/values.go +++ b/gpu/values.go @@ -10,7 +10,7 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/base/slicesx" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Values is a list container of Value values, accessed by index or name. diff --git a/gpu/var.go b/gpu/var.go index 501131859a..db96880a6d 100644 --- a/gpu/var.go +++ b/gpu/var.go @@ -7,7 +7,7 @@ package gpu import ( "fmt" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Var specifies a variable used in a pipeline, accessed in shader programs diff --git a/gpu/vargroup.go b/gpu/vargroup.go index c0153277bb..c904d7d86c 100644 --- a/gpu/vargroup.go +++ b/gpu/vargroup.go @@ -11,7 +11,7 @@ import ( "sync" "cogentcore.org/core/base/errors" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) const ( @@ -307,7 +307,7 @@ func (vg *VarGroup) bindLayout(vs *Vars, used ...*Var) (*wgpu.BindGroupLayout, e Entries: binds, } - bgl, err := vg.device.Device.CreateBindGroupLayout(&bgld) + bgl, err := vg.device.Device.TryCreateBindGroupLayout(&bgld) if errors.Log(err) != nil { return nil, err } @@ -351,7 +351,7 @@ func (vg *VarGroup) bindGroup(vs *Vars, used ...*Var) (*wgpu.BindGroup, error) { } bgs = append(bgs, vr.bindGroupEntry()...) } - bg, err := vg.device.Device.CreateBindGroup(&wgpu.BindGroupDescriptor{ + bg, err := vg.device.Device.TryCreateBindGroup(&wgpu.BindGroupDescriptor{ Layout: bgl, Entries: bgs, Label: vg.Name, diff --git a/gpu/vars.go b/gpu/vars.go index 152308d77b..5465f8b942 100644 --- a/gpu/vars.go +++ b/gpu/vars.go @@ -12,7 +12,7 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/base/indent" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Vars are all the variables that are used by a pipeline, @@ -101,12 +101,12 @@ func (vs *Vars) AddGroup(role VarRoles, name ...string) *VarGroup { } vg.alignBytes = 1 if role == Uniform { - vg.alignBytes = int(vs.sys.GPU().Limits.Limits.MinUniformBufferOffsetAlignment) + vg.alignBytes = int(vs.sys.GPU().Limits.MinUniformBufferOffsetAlignment) // note: wgpu-native reports alignment sizes of 64 // but then barfs when that is used. 256 seems to keep it happy vg.alignBytes = max(vg.alignBytes, 256) } else if role == Storage { - vg.alignBytes = int(vs.sys.GPU().Limits.Limits.MinStorageBufferOffsetAlignment) + vg.alignBytes = int(vs.sys.GPU().Limits.MinStorageBufferOffsetAlignment) vg.alignBytes = max(vg.alignBytes, 256) } vs.Groups[idx] = vg diff --git a/system/driver/android/app.go b/system/driver/android/app.go index d4b4fc9371..a1d9d104b9 100644 --- a/system/driver/android/app.go +++ b/system/driver/android/app.go @@ -16,7 +16,7 @@ import ( "cogentcore.org/core/system" "cogentcore.org/core/system/composer" "cogentcore.org/core/system/driver/base" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) func Init() { diff --git a/system/driver/desktop/app.go b/system/driver/desktop/app.go index 3a179ac048..562236dc50 100644 --- a/system/driver/desktop/app.go +++ b/system/driver/desktop/app.go @@ -19,8 +19,8 @@ import ( "cogentcore.org/core/system" "cogentcore.org/core/system/composer" "cogentcore.org/core/system/driver/base" - "github.com/cogentcore/webgpu/wgpuglfw" "github.com/go-gl/glfw/v3.4/glfw" + "github.com/oliverbestmann/webgpu/wgpuglfw" ) func Init() { diff --git a/system/driver/ios/app.go b/system/driver/ios/app.go index a1cce97d73..eaf9079587 100644 --- a/system/driver/ios/app.go +++ b/system/driver/ios/app.go @@ -20,7 +20,7 @@ import ( "cogentcore.org/core/system" "cogentcore.org/core/system/composer" "cogentcore.org/core/system/driver/base" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) func Init() { diff --git a/system/examples/drawidx/drawidx.go b/system/examples/drawidx/drawidx.go index aa782c59c1..961a7eb8da 100644 --- a/system/examples/drawidx/drawidx.go +++ b/system/examples/drawidx/drawidx.go @@ -19,7 +19,7 @@ import ( "cogentcore.org/core/system" "cogentcore.org/core/system/composer" _ "cogentcore.org/core/system/driver" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) //go:embed indexed.wgsl diff --git a/system/examples/drawtri/drawtri.go b/system/examples/drawtri/drawtri.go index 21bac3b735..d2c8f30c2c 100644 --- a/system/examples/drawtri/drawtri.go +++ b/system/examples/drawtri/drawtri.go @@ -17,7 +17,7 @@ import ( "cogentcore.org/core/system" "cogentcore.org/core/system/composer" _ "cogentcore.org/core/system/driver" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) //go:embed trianglelit.wgsl diff --git a/xyz/node.go b/xyz/node.go index d91ad6fd7f..c71629ccbd 100644 --- a/xyz/node.go +++ b/xyz/node.go @@ -12,7 +12,7 @@ import ( "cogentcore.org/core/math32" "cogentcore.org/core/tree" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // Node is the common interface for all xyz 3D tree nodes. diff --git a/xyz/solid.go b/xyz/solid.go index c2c227f5fa..907d5926a7 100644 --- a/xyz/solid.go +++ b/xyz/solid.go @@ -10,7 +10,7 @@ import ( "cogentcore.org/core/base/errors" "cogentcore.org/core/gpu/phong" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // https://www.khronos.org/opengl/wiki/Vertex_Specification_Best_Practices diff --git a/xyz/xyzcore/render_js.go b/xyz/xyzcore/render_js.go index 2bce187250..8ac701a3d4 100644 --- a/xyz/xyzcore/render_js.go +++ b/xyz/xyzcore/render_js.go @@ -14,7 +14,7 @@ import ( "cogentcore.org/core/gpu" "cogentcore.org/core/gpu/phong" "cogentcore.org/core/system/composer" - "github.com/cogentcore/webgpu/wgpu" + "github.com/oliverbestmann/webgpu/wgpu" ) // xyzSource implements [composer.Source] for core direct rendering. From 7a87368671eb450454b777300492550fe86667d1 Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Mon, 11 May 2026 01:10:10 +0200 Subject: [PATCH 2/6] update for new 1.33 of webgpu and especially for when the PR 1 there hits, which takes care of the Occluded case directly. --- go.mod | 2 +- go.sum | 4 ++-- gpu/examples/drawtri/drawtri.go | 6 +++++- gpu/gsystem.go | 10 +++++++--- gpu/surface.go | 11 +++++++++-- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 7ac5ad2e23..4245417755 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/mattn/go-shellwords v1.0.12 github.com/mitchellh/go-homedir v1.1.0 github.com/muesli/termenv v0.16.0 - github.com/oliverbestmann/webgpu v1.32.0 + github.com/oliverbestmann/webgpu v1.33.0 github.com/pelletier/go-toml/v2 v2.2.4 github.com/stretchr/testify v1.11.1 github.com/tdewolff/parse/v2 v2.8.5 diff --git a/go.sum b/go.sum index 2a49a46c03..2303905bc3 100644 --- a/go.sum +++ b/go.sum @@ -122,8 +122,8 @@ github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= -github.com/oliverbestmann/webgpu v1.32.0 h1:JyGhxkBD/HHi/VB7WDy4VU2Q2enoUyWSXjhVpqbfokQ= -github.com/oliverbestmann/webgpu v1.32.0/go.mod h1:0UEcoJ8VnwnAqo3JfzdFptplxtjhaQasc3n/nYZOrPA= +github.com/oliverbestmann/webgpu v1.33.0 h1:Nr0IYIApoELWwDrF42nlEmgnuI0F517J4kbWPK9ZNIM= +github.com/oliverbestmann/webgpu v1.33.0/go.mod h1:0UEcoJ8VnwnAqo3JfzdFptplxtjhaQasc3n/nYZOrPA= github.com/oliverbestmann/webgpu/libs-android v0.0.0-20260509160813-48db59792a15 h1:HPxVSV8C8JaxGfa9hjDhzNmryoqPF3EwESBTFWpxNBo= github.com/oliverbestmann/webgpu/libs-android v0.0.0-20260509160813-48db59792a15/go.mod h1:tczQXCdsoFy+FTJVsZSve/vF8cmWEkxhvjcyY2Rujp8= github.com/oliverbestmann/webgpu/libs-darwin v0.0.0-20260509160802-b09403b07cd3 h1:NbBG2+pwqKcNfKUKtjWOj+02RkXSUWVkxY3hqzgyjSA= diff --git a/gpu/examples/drawtri/drawtri.go b/gpu/examples/drawtri/drawtri.go index 0f58dc4141..cd27c55706 100644 --- a/gpu/examples/drawtri/drawtri.go +++ b/gpu/examples/drawtri/drawtri.go @@ -66,7 +66,11 @@ func main() { // rt := time.Now() rp, err := sy.BeginRenderPass() - if err != nil { + if err != nil { // error here is fatal + panic(err) + } + if rp == nil { // nil indicates need to reconfig + sf.Reconfig() return } pl.BindPipeline(rp) diff --git a/gpu/gsystem.go b/gpu/gsystem.go index ab7e85f1ab..c4ae40cd73 100644 --- a/gpu/gsystem.go +++ b/gpu/gsystem.go @@ -213,7 +213,7 @@ func (sy *GraphicsSystem) NewCommandEncoder() (*wgpu.CommandEncoder, error) { func (sy *GraphicsSystem) beginRenderPass() (*Render, *wgpu.TextureView, error) { rd := sy.Renderer view, err := rd.GetCurrentTexture() - if errors.Log(err) != nil { + if view == nil || errors.Log(err) != nil { return nil, nil, err } cmd, err := sy.NewCommandEncoder() @@ -230,9 +230,11 @@ func (sy *GraphicsSystem) beginRenderPass() (*Render, *wgpu.TextureView, error) // rendering commands should be added. // Call [GraphicsSystem.EndRenderPass] when done. // This version Clears the target texture first, using ClearValues. +// The RenderPassEncoder can be nil AND the err also nil, which +// indicates the need to reconfigure the surface and try again. func (sy *GraphicsSystem) BeginRenderPass() (*wgpu.RenderPassEncoder, error) { rd, view, err := sy.beginRenderPass() - if errors.Log(err) != nil { + if view == nil || errors.Log(err) != nil { return nil, err } return rd.BeginRenderPass(sy.CommandEncoder, view), nil @@ -245,9 +247,11 @@ func (sy *GraphicsSystem) BeginRenderPass() (*wgpu.RenderPassEncoder, error) { // Call [GraphicsSystem.EndRenderPass] when done. // This version does NOT clear the target texture first, // so the prior render output is carried over. +// The RenderPassEncoder can be nil AND the err also nil, which +// indicates the need to reconfigure the surface and try again. func (sy *GraphicsSystem) BeginRenderPassNoClear() (*wgpu.RenderPassEncoder, error) { rd, view, err := sy.beginRenderPass() - if errors.Log(err) != nil { + if view == nil || errors.Log(err) != nil { return nil, err } return rd.BeginRenderPassNoClear(sy.CommandEncoder, view), nil diff --git a/gpu/surface.go b/gpu/surface.go index fc3c102899..779c2da046 100644 --- a/gpu/surface.go +++ b/gpu/surface.go @@ -107,13 +107,20 @@ func (sf *Surface) Size() image.Point { } // GetCurrentTexture returns a TextureView that is the current -// target for rendering. +// target for rendering. The TextureView can be nil AND the err +// also nil, in which case the surface needs to be reconfigured. func (sf *Surface) GetCurrentTexture() (*wgpu.TextureView, error) { sf.Lock() // we remain locked until submit! - texture, err := sf.surface.TryGetCurrentTexture() + stexture, err := sf.surface.TryGetCurrentTexture() if errors.Log(err) != nil { + sf.Unlock() return nil, err } + texture, ok := stexture.Get() + if !ok { + sf.Unlock() + return nil, nil + } // Note: we need to specify a descriptor here so that we use the correct // format, which may be different from the default format, such as when // it is srgb. From 90a9ff2cbc03f74a581b9b33da223179543def86 Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Mon, 11 May 2026 23:19:14 +0200 Subject: [PATCH 3/6] obwgpu: working solution for threads and simple demos -- can't have it all handled within wgpu itself, due to need to run glfw.PollEvents on main thread. --- gpu/surface.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/gpu/surface.go b/gpu/surface.go index 779c2da046..cb2cc7c31a 100644 --- a/gpu/surface.go +++ b/gpu/surface.go @@ -7,8 +7,11 @@ package gpu import ( "image" "sync" + "time" "cogentcore.org/core/base/errors" + "cogentcore.org/core/system" + "github.com/go-gl/glfw/v3.4/glfw" "github.com/oliverbestmann/webgpu/wgpu" ) @@ -108,13 +111,29 @@ func (sf *Surface) Size() image.Point { // GetCurrentTexture returns a TextureView that is the current // target for rendering. The TextureView can be nil AND the err -// also nil, in which case the surface needs to be reconfigured. +// also nil, in which case the surface needs to be reconfigured, func (sf *Surface) GetCurrentTexture() (*wgpu.TextureView, error) { sf.Lock() // we remain locked until submit! - stexture, err := sf.surface.TryGetCurrentTexture() - if errors.Log(err) != nil { - sf.Unlock() - return nil, err + var stexture wgpu.SurfaceTexture + for { + var err error + stexture, err = sf.surface.TryGetCurrentTexture() + if errors.Log(err) != nil { + sf.Unlock() + return nil, err + } + if stexture.Status == wgpu.SurfaceGetCurrentTextureStatusOccluded { + time.Sleep(16 * time.Millisecond) + if system.TheApp != nil { + system.TheApp.RunOnMain(func() { + glfw.PollEvents() + }) + } else { + glfw.PollEvents() + } + continue + } + break } texture, ok := stexture.Get() if !ok { @@ -129,6 +148,10 @@ func (sf *Surface) GetCurrentTexture() (*wgpu.TextureView, error) { ArrayLayerCount: texture.GetDepthOrArrayLayers(), Format: sf.Format.Format, }) + if errors.Log(err) != nil { + sf.Unlock() + return nil, err + } sf.curTexture = view return view, nil } From fd1c9d83d33de07ef8c528ba3c9ed03f9a6a259e Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Mon, 11 May 2026 23:31:55 +0200 Subject: [PATCH 4/6] obwgpu add replace here too --- go.mod | 2 ++ go.sum | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 4245417755..8496233223 100644 --- a/go.mod +++ b/go.mod @@ -80,3 +80,5 @@ require ( modernc.org/knuth v0.5.4 // indirect modernc.org/token v1.1.0 // indirect ) + +replace github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1.0.20260406072232-3ac4aa2bb164 => github.com/oliverbestmann/go-gl-glfw/v3.4/glfw v0.0.0-20260510101646-c1f83c493fe1 diff --git a/go.sum b/go.sum index 2303905bc3..90d04a0a4b 100644 --- a/go.sum +++ b/go.sum @@ -54,8 +54,6 @@ github.com/go-audio/riff v1.0.0/go.mod h1:l3cQwc85y79NQFCRB7TiPoNiaijp6q8Z0Uv38r github.com/go-audio/wav v1.0.0/go.mod h1:3yoReyQOsiARkvPl3ERCi8JFjihzG6WhjYpZCf5zAWE= github.com/go-fonts/latin-modern v0.3.3 h1:g2xNgI8yzdNzIVm+qvbMryB6yGPe0pSMss8QT3QwlJ0= github.com/go-fonts/latin-modern v0.3.3/go.mod h1:tHaiWDGze4EPB0Go4cLT5M3QzRY3peya09Z/8KSCrpY= -github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1.0.20260406072232-3ac4aa2bb164 h1:c87Nyz3ox3QbCl0yozQPeVPW4mmgFOSKY4yyc1TrS0w= -github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1.0.20260406072232-3ac4aa2bb164/go.mod h1:T5Dn0JwIJOX1euPZ/iT4tq6nFYtmukjcYa7937HuYK8= github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA= github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08= github.com/go-text/typesetting v0.3.5-0.20260418130854-c41d02a44bec h1:qkk9+cZlaY8920dQrhY8GoI91N72f58XmJgGDkkDiaA= @@ -122,6 +120,8 @@ github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= +github.com/oliverbestmann/go-gl-glfw/v3.4/glfw v0.0.0-20260510101646-c1f83c493fe1 h1:NE2h8adQKd5RgELMJRDh6jk+w2AZGJnqiceettnqjAs= +github.com/oliverbestmann/go-gl-glfw/v3.4/glfw v0.0.0-20260510101646-c1f83c493fe1/go.mod h1:T5Dn0JwIJOX1euPZ/iT4tq6nFYtmukjcYa7937HuYK8= github.com/oliverbestmann/webgpu v1.33.0 h1:Nr0IYIApoELWwDrF42nlEmgnuI0F517J4kbWPK9ZNIM= github.com/oliverbestmann/webgpu v1.33.0/go.mod h1:0UEcoJ8VnwnAqo3JfzdFptplxtjhaQasc3n/nYZOrPA= github.com/oliverbestmann/webgpu/libs-android v0.0.0-20260509160813-48db59792a15 h1:HPxVSV8C8JaxGfa9hjDhzNmryoqPF3EwESBTFWpxNBo= From 044dd6e0c376bc86416f62ee14d7931f0b37465f Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Tue, 12 May 2026 00:09:18 +0200 Subject: [PATCH 5/6] obwgpu: add BytesToJS to base/jscp -- is not used in webgpu --- base/iox/imagex/wrapjs_js.go | 3 ++- base/jscp/jscp.go | 19 +++++++++++++++++++ base/websocket/websocket_js.go | 4 ++-- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 base/jscp/jscp.go diff --git a/base/iox/imagex/wrapjs_js.go b/base/iox/imagex/wrapjs_js.go index 704b82ad78..59ee70fbd9 100644 --- a/base/iox/imagex/wrapjs_js.go +++ b/base/iox/imagex/wrapjs_js.go @@ -11,6 +11,7 @@ import ( "syscall/js" "cogentcore.org/core/base/errors" + "cogentcore.org/core/base/jscp" "cogentcore.org/core/colors/gradient" "github.com/oliverbestmann/webgpu/jsx" ) @@ -155,7 +156,7 @@ type JSImageData struct { // setImageData sets the JavaScript pointers from given bytes. func (im *JSImageData) SetImageData(src []byte, sbb image.Rectangle, options map[string]any) { - jsBuf := jsx.BytesToJS(src) + jsBuf := jscp.BytesToJS(src) imageData := js.Global().Get("ImageData").New(jsBuf, sbb.Dx(), sbb.Dy()) im.Bounds = image.Rectangle{Max: sbb.Size()} im.Data = imageData diff --git a/base/jscp/jscp.go b/base/jscp/jscp.go new file mode 100644 index 0000000000..4f787a1498 --- /dev/null +++ b/base/jscp/jscp.go @@ -0,0 +1,19 @@ +//go:build js + +// Package jscp provides functions for copying data to JavaScript +package jscp + +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])) + // 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)) +} diff --git a/base/websocket/websocket_js.go b/base/websocket/websocket_js.go index 17507c2d62..009dbfa7ff 100644 --- a/base/websocket/websocket_js.go +++ b/base/websocket/websocket_js.go @@ -9,7 +9,7 @@ package websocket import ( "syscall/js" - "github.com/oliverbestmann/webgpu/jsx" + "cogentcore.org/core/base/jscp" ) // Client represents a WebSocket client connection. @@ -51,7 +51,7 @@ func (c *Client) Send(typ MessageTypes, msg []byte) error { c.ws.Call("send", string(msg)) return nil } - array := jsx.BytesToJS(msg) + array := jscp.BytesToJS(msg) c.ws.Call("send", array) return nil } From df1c148e248a8026a44903c724c1ed39e4255806 Mon Sep 17 00:00:00 2001 From: "Randall C. O'Reilly" Date: Tue, 12 May 2026 00:18:32 +0200 Subject: [PATCH 6/6] obwgpu: use 1.33.2 release tag --- docs/content/gpu.md | 2 +- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/content/gpu.md b/docs/content/gpu.md index 083805f128..bbce5e359d 100644 --- a/docs/content/gpu.md +++ b/docs/content/gpu.md @@ -19,7 +19,7 @@ The main gpu code is in the top-level `gpu` package, with the following sub-pack * [[doc:gpu/gpudraw]] implements GPU-accelerated texture-based versions of the Go [image/draw](https://pkg.go.dev/image/draw) api. This is used by the `Composer` framework for compositing images in the `core` GUI to construct the final rendered scene, and for drawing that scene on the actual hardware window (see [[render]] for details). -We maintain a separate [webgpu](https://github.com/oliverbestmann/webgpu) package that provides a Go and JS wrapper around the rust-based [wgpu](https://github.com/gfx-rs/wgpu) and [wgpu-native](https://github.com/gfx-rs/wgpu-native) packages that actually implement WebGPU itself on the desktop and mobile. This "native" version is just as performant as the much more difficult-to-use [Vulkan](https://www.vulkan.org/) framework, which we used to use. +There is a separate [webgpu](https://github.com/oliverbestmann/webgpu) package that provides a Go and JS wrapper around the rust-based [wgpu](https://github.com/gfx-rs/wgpu) and [wgpu-native](https://github.com/gfx-rs/wgpu-native) packages that actually implement WebGPU itself on the desktop and mobile. This "native" version is just as performant as the much more difficult-to-use [Vulkan](https://www.vulkan.org/) framework, which we used to use. ## Selecting a GPU Device diff --git a/go.mod b/go.mod index 8496233223..a17ad5b300 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/mattn/go-shellwords v1.0.12 github.com/mitchellh/go-homedir v1.1.0 github.com/muesli/termenv v0.16.0 - github.com/oliverbestmann/webgpu v1.33.0 + github.com/oliverbestmann/webgpu v1.33.2 github.com/pelletier/go-toml/v2 v2.2.4 github.com/stretchr/testify v1.11.1 github.com/tdewolff/parse/v2 v2.8.5 diff --git a/go.sum b/go.sum index 90d04a0a4b..35282aa404 100644 --- a/go.sum +++ b/go.sum @@ -122,8 +122,8 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/oliverbestmann/go-gl-glfw/v3.4/glfw v0.0.0-20260510101646-c1f83c493fe1 h1:NE2h8adQKd5RgELMJRDh6jk+w2AZGJnqiceettnqjAs= github.com/oliverbestmann/go-gl-glfw/v3.4/glfw v0.0.0-20260510101646-c1f83c493fe1/go.mod h1:T5Dn0JwIJOX1euPZ/iT4tq6nFYtmukjcYa7937HuYK8= -github.com/oliverbestmann/webgpu v1.33.0 h1:Nr0IYIApoELWwDrF42nlEmgnuI0F517J4kbWPK9ZNIM= -github.com/oliverbestmann/webgpu v1.33.0/go.mod h1:0UEcoJ8VnwnAqo3JfzdFptplxtjhaQasc3n/nYZOrPA= +github.com/oliverbestmann/webgpu v1.33.2 h1:uDs3Fx4uAiUs8E4QytblofDpLtqBRGX3pfnLZzlhWGY= +github.com/oliverbestmann/webgpu v1.33.2/go.mod h1:0UEcoJ8VnwnAqo3JfzdFptplxtjhaQasc3n/nYZOrPA= github.com/oliverbestmann/webgpu/libs-android v0.0.0-20260509160813-48db59792a15 h1:HPxVSV8C8JaxGfa9hjDhzNmryoqPF3EwESBTFWpxNBo= github.com/oliverbestmann/webgpu/libs-android v0.0.0-20260509160813-48db59792a15/go.mod h1:tczQXCdsoFy+FTJVsZSve/vF8cmWEkxhvjcyY2Rujp8= github.com/oliverbestmann/webgpu/libs-darwin v0.0.0-20260509160802-b09403b07cd3 h1:NbBG2+pwqKcNfKUKtjWOj+02RkXSUWVkxY3hqzgyjSA=