Skip to content

WGL: fixes for adopted contexts, and a fallback without WGL_NV_DX_interop - #2

Open
fran6co wants to merge 4 commits into
upstream-mainfrom
upstream/wgl-fixes
Open

fran6co wants to merge 4 commits into
upstream-mainfrom
upstream/wgl-fixes

Conversation

@fran6co

@fran6co fran6co commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Draft for review before upstreaming to servo/surfman. Written with Claude Code: servo's AI policy means it has to be rewritten by a person before it goes upstream.

Four fixes to the WGL backend, found embedding Servo in an application that shares its own WGL context with it. Upstream CI cannot run WGL, which is likely why they went unnoticed. One commit each:

  1. Take an adopted context's pixel format from the DC it is current on. create_context_from_native_context set no pixel format on the hidden window it renders the context on, so wglMakeCurrent failed there and an assert fired. The only place to find an HGLRC's format is the DC it is current on, so adopting now requires the context to be current on the calling thread and returns NoCurrentContext otherwise; a failing wglMakeCurrent returns MakeCurrentFailed instead of panicking.
  2. Report the compatibility profile in context descriptor attributes. context_descriptor_attributes never set COMPATIBILITY_PROFILE, so a descriptor read back from a compatibility context described a core one.
  3. Leave new contexts current, as the other backends do. create_context restored the previously current context, unlike EGL and CGL, so code written against those backends then issued GL calls with no context current. make_no_context_current also returns early when nothing is current, as releasing nothing fails on some implementations.
  4. Fall back to shared GL textures without WGL_NV_DX_interop. Without the extension, device creation failed. Generic surfaces are now plain GL textures: each connection makes a share group, rooted at the first context made or adopted on it, and contexts that share a surface's texture order their access with GL fences (left on unbind and surface texture destruction, waited on at bind and surface texture creation). With the extension nothing changes.

Rebased onto main. Main removed Device::connection (servo#401), so the device now keeps its own handle to its connection's share root rather than the connection.

Tested: surfman's suite cross-compiled with cargo-xwin and run under 64-bit Wine, whose WGL has no WGL_NV_DX_interop, so it exercises the fallback: 13 passed, 1 ignored (test_cross_device_surface_texture_blit_framebuffer, ignored on main). Not yet run on a Windows host with the extension.

🤖 Generated with Claude Code

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