fix(gles): Instance-owned GL context on hidden window (Rust wgpu parity)#191
Merged
Conversation
Move GL context from Surface to Instance using a hidden 1×1 HWND. Previously Surface owned the GL context — closing the window killed it, leaving Adapter/Device/Queue with dangling references. Architecture (follows Rust wgpu-hal/src/gles/wgl.rs): - Instance creates hidden 1×1 window with CS_OWNDC + pixel format at init - GL context lazily created on first Lock() via sync.Once on render thread (avoids cross-thread WGL issues — Go goroutines migrate between OS threads) - AdapterContext: sync.Mutex + runtime.LockOSThread pins goroutine during GL - Lock() → wglMakeCurrent(hiddenDC, hglrc) for resource creation and submit - LockForDC(userDC) → wglMakeCurrent(userDC, hglrc) for presentation - Unlock() → wglMakeCurrent(0,0) with wglGetCurrentContext guard (Rust pattern) - Surface.Configure: two lock scopes (swap interval on user DC, FBO on hidden DC) - Surface lightweight: only HWND + shared *AdapterContext reference New files: - wgl/hidden_window.go: hidden HWND, window class, lifecycle management - adapter_context.go: mutex-protected GL context with lazy init - surface_linux_compat.go: compat wrappers for Linux (Phase 2 pending) Verified: triangle rendering on Intel Iris Xe, OpenGL 4.6. Build: Windows/Linux/macOS/WASM. Tests: 15/15. Lint: 0 all platforms.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AdapterContextwithsync.Mutex+runtime.LockOSThread()+ lazy GL init viasync.OnceAdapterContext::lock()/lock_with_dc()patternArchitecture
New files (3)
wgl/hidden_window.go— hidden HWND, CS_OWNDC window class, lifecycleadapter_context.go— mutex-protected GL context with lazy initsurface_linux_compat.go— compat wrappers for Linux (Phase 2)Test plan
GOGPU_GRAPHICS_API=glestriangle renders on Intel Iris Xe, OpenGL 4.6