Skip to content

feat(wgpu): select backends via InstanceExtras, add SwapChainPanel surface - #33

Open
YindSoft wants to merge 1 commit into
go-webgpu:mainfrom
YindSoft:feat/instance-backends-swapchainpanel
Open

YindSoft wants to merge 1 commit into
go-webgpu:mainfrom
YindSoft:feat/instance-backends-swapchainpanel

Conversation

@YindSoft

Copy link
Copy Markdown

Summary

Two small additions against the wgpu-native v29 header:

  • InstanceDescriptor.NativeBackends — when non-zero, CreateInstance chains WGPUInstanceExtras (full v29 layout, 112 bytes) with backends set. Until now the descriptor was ignored, so there was no way to choose a backend (wgpu-native does not read WGPU_BACKEND). Zero keeps today's behavior.
  • Instance.CreateSurfaceFromSwapChainPanel (Windows) — wraps WGPUSurfaceSourceSwapChainPanel. wgpu-native creates the swap chain with CreateSwapChainForComposition and hands it to ISwapChainPanelNative::SetSwapChain. Besides a WinUI SwapChainPanel, 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 Go ISwapChainPanelNative whose SetSwapChain calls IDCompositionVisual::SetContent keeps the game and the UI composed together in fullscreen.

Notes

🤖 Generated with Claude Code

…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>
@YindSoft
YindSoft requested a review from kolkov as a code owner September 23, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant