Conversation
…rface - InstanceDescriptor.NativeBackends chains WGPUInstanceExtras (v29 layout) to wgpuCreateInstance so callers can restrict the backends wgpu-native enumerates, e.g. InstanceBackendDX12. The descriptor was previously ignored and there was no way to pick a backend. - Windows: Instance.CreateSurfaceFromSwapChainPanel wraps WGPUSurfaceSourceSwapChainPanel. wgpu-native creates a composition swap chain and hands it to ISwapChainPanelNative::SetSwapChain, which lets the caller host it in its own DirectComposition tree. - Chained structs are heap-allocated through package sinks, since the descriptors only refer to them as uintptr. - ABI size/offset tests for both structs, SType value test, and functional tests (instance with NativeBackends, nil panel rejected). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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
Two small additions against the wgpu-native v29 header:
InstanceDescriptor.NativeBackends— when non-zero,CreateInstancechainsWGPUInstanceExtras(full v29 layout, 112 bytes) withbackendsset. Until now the descriptor was ignored, so there was no way to choose a backend (wgpu-native does not readWGPU_BACKEND). Zero keeps today's behavior.Instance.CreateSurfaceFromSwapChainPanel(Windows) — wrapsWGPUSurfaceSourceSwapChainPanel. wgpu-native creates the swap chain withCreateSwapChainForCompositionand hands it toISwapChainPanelNative::SetSwapChain. Besides a WinUISwapChainPanel, any object implementing that interface works, so the caller can put the swap chain in its own DirectComposition tree.Motivation
We render a game with this binding under a WebView2 composition controller (DirectComposition, topmost target on the same HWND). With an HWND swap chain, going fullscreen let DWM / the driver promote the swap chain to independent flip and the WebView2 layer stopped being composed, so the UI disappeared. On NVIDIA the default adapter was Vulkan, which does the same. Forcing DX12 (
NativeBackends: InstanceBackendDX12) and presenting a composition swap chain through a small GoISwapChainPanelNativewhoseSetSwapChaincallsIDCompositionVisual::SetContentkeeps the game and the UI composed together in fullscreen.Notes
uintptrand a stack copy could move before the native call reads it.instanceExtrasWire,nativeDisplayHandleWireandsurfaceSourceSwapChainPanel, theSurfaceSourceSwapChainPanelSType value,TestCreateInstanceWithNativeBackends, and a nil-panel rejection test.main,go test ./wgpuwith the v29 DLL aborts atTestCreateBindGroupLayout, before and after this change. That is the bind group layout ABI bug fixed in fix(wgpu): v29 wire layouts, surface texture on error, pinned pointers in Proc.Call #32. With this commit cherry-picked on top of fix(wgpu): v29 wire layouts, surface texture on error, pinned pointers in Proc.Call #32, the full suite passes on Windows (ok github.com/go-webgpu/webgpu/wgpu 27.5s).go vetpasses for windows, linux and darwin.Unreleasedsection, so it will need a trivial rebase against fix(wgpu): v29 wire layouts, surface texture on error, pinned pointers in Proc.Call #32.🤖 Generated with Claude Code