Windows: transparent window renders black with the Skia wgpu (DX12) renderer
Bug Description
A window with background: transparent renders a black background instead of the desktop when using the Skia wgpu renderer (Direct3D 12) on Windows.
Steps: run the code below with SLINT_BACKEND=winit-skia-wgpu (optionally WGPU_DX12_PRESENTATION_SYSTEM=Visual).
Expected: desktop visible around the red square. Actual: black background.
Root causes
Found by hooking IDXGIFactory2::CreateSwapChainFor* in a test app:
WGPU_*environment variables are ignored.wgpu-30is a workspace dependency withdefault-features = false, and nothing enables itsstdfeature, sowgpu-typesis built withoutstdandwgpu_types::env::var()always returnsNone.WGPU_BACKEND,WGPU_POWER_PREFandWGPU_DX12_PRESENTATION_SYSTEMhave no effect. With the defaultDxgiFromHwnd, wgpu callsCreateSwapChainForHwndwithDXGI_ALPHA_MODE_IGNORE.The premultiplied alpha mode never reaches DXGI. With
DxgiFromVisual,WGPUSurface::init_with_partsfirst configures the surface with the alpha mode fromget_default_config(Auto→DXGI_ALPHA_MODE_UNSPECIFIED).set_transparent()then reconfigures withPreMultiplied, but on DX12 wgpu-hal only callsResizeBufferson an existing swapchain, which cannot change the alpha mode, so it staysUNSPECIFIED.
Workaround that works for us
-wgpu-30 = { package = "wgpu", version = "30", default-features = false }
+wgpu-30 = { package = "wgpu", version = "30", default-features = false, features = ["std"] }and in internal/renderers/skia/wgpu_30_surface.rs, init_with_parts(), before the first configure:
if swapchain_capabilities.alpha_modes.contains(&wgpu::CompositeAlphaMode::PreMultiplied) {
surface_config.alpha_mode = wgpu::CompositeAlphaMode::PreMultiplied;
}With both changes and WGPU_DX12_PRESENTATION_SYSTEM=Visual, the swapchain is created by CreateSwapChainForComposition with DXGI_ALPHA_MODE_PREMULTIPLIED, and the window is transparent on both monitors (checked by reading back screen pixels). A proper fix probably passes the window's transparency to the surface before its first configure, or recreates the swapchain when the alpha mode changes.
Why not OpenGL
With winit-skia-opengl, the AMD driver presents OpenGL through its own DXGI swapchain on a FreeSync monitor (it loads amdxc64.dll, D3D12Core.dll, dcomp.dll from atio6axx.dll), and window alpha is lost there too. That makes DX12 with DirectComposition the only reliable option for transparency on such setups.
Side note
With the wgpu surface, Window::set_rendering_notifier callbacks never fire, because WGPUSurface::with_graphics_api is gated behind unstable-wgpu-30.
This was investigated with the help of an AI assistant (Claude): test programs and DXGI hooks. I verified the results on my own hardware.
Reproducible Code (if applicable)
export component TestCase inherits Window {
no-frame: true;
background: transparent;
Rectangle { width: 50px; height: 50px; background: red; }
}Environment Details
- Slint Version: 1.18.1
- Platform/OS: Windows 11 23H2 (22631); AMD Radeon 660M iGPU (driver 26.8.1) + NVIDIA RTX 3050 Ti Laptop
- Programming Language: C++ (CMake FetchContent)
- Backend/Renderer: winit + Skia (wgpu / Direct3D 12); OpenGL for comparison
Product Impact
A screenshot tool with a semi-transparent full-screen overlay across multiple monitors. Transparency is essential; we currently ship a local patch of Slint as a workaround.
Source: slint-ui/slint