Is your feature request related to a problem? Please describe.
Currently, windows are hardcoded to be opaque:
config.composite_alpha_mode = hal::window::CompositeAlphaMode::OPAQUE;
so the a in wgpu::RenderPassColorAttachmentDescriptor clear_color doesn't do anything.
Describe the solution you'd like
There should be support for the transparent modes. In particular, premultiplied mode should be handled, as it's the only one supported at least on my machine (using Mesa RADV driver for Radeon).
Additional context
Hardcoding ::PREMULTIPLIED makes transparency work, but I actually have to multiply the colors by the alpha:

I would be fine with exposing the composite alpha mode
As in the whole CompositeAlphaMode choice? ah good old "let the user handle it" :)
Swapchain creation is public API so this affects webgpu-headers…
Is there an alternative to telling users what modes are available, and letting them select one?
I'd be happy to consider one!
As for webgpu-headers - you are right, we'll need to expose it there as well, just like we expose the present modes. cc @Kangz
I was thinking "pick the most common mode and handle conversions" but yeah, exposing everything to the user would be much easier.
Can we have a brief investigation of what the compositing modes are and how they translate to the various APIs? I worry for example that on macOS the compositing mode might be a part of the CALayer so we'd be mutating that.
Also are there any guarantees that we can support all compositing modes on all platforms, or does for example Vulkan give little guarantees so we need to have queries in webgpu.h for it?
Can we have a brief investigation of what the compositing modes are and how they translate to the various APIs?
Agreed, would be great to have it!
I worry for example that on macOS the compositing mode might be a part of the CALayer so we'd be mutating that.
Pretty sure we are already mutating CALayer properties when you are re-configuring the swapchain, since we set the size and the vsync, etc
Also are there any guarantees that we can support all compositing modes on all platforms
No
Any updates on this?
@atsuzaki I don't think anyone has been looking into this yet (unless @myfreeweb has a branch somewhere?), but please feel free to start looking into it if you'd like.
An investigation into how to handle this on each backend and/or prototyping the changes with one or more backends would be great.
I just have a hardcoded premultiplied mode, nothing smarter, no API or anything
I've made a similar change with the PREMULTIPLIED mode but it doesn't seem to work in macOS. Not entirely sure what's missing. Presumably everything needed would be in place (such as color states and having a clear color with an alpha (plus the change in `swap_chain.rs`)
let window = WindowBuilder::new()
.with_title("Rust by Example: WGPU!")
.with_decorations(false)
.with_transparent(true)
.build(&event_loop)
.unwrap();
color_states: &[
wgpu::ColorStateDescriptor {
format: sc_desc.format,
color_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::SrcAlpha,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add
},
alpha_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::One,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add
},
//color_blend: wgpu::BlendDescriptor::REPLACE,
//alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL
}
]
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.005,
g: 0.005,
b: 0.01,
a: 0.5
}),
store: true
}
}
],
depth_stencil_attachment: None
});
config.composite_alpha_mode = hal::window::CompositeAlphaMode::PREMULTIPLIED;
gfx-rs Metal backend needs to handle this better, I guess.
@nyxtom Metal transparency support is coming in https://github.com/gfx-rs/gfx/pull/3561
Transparent windows don't work for me either. Using Linux and Xorg. I ran the Vulkan validation layers and see the error below. My GPU is an RTX 2080 Ti, and transparent windows work with OpenGL things. Seems a little weird that the only supported mode on my GPU is VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR.
vulkaninfo says it only supports opaque, so perhaps it's a driver issue of some kind. Maybe it'd work with XCB instead of Xlib?
supportedCompositeAlpha: count = 1
COMPOSITE_ALPHA_OPAQUE_BIT_KHR
VUID-VkSwapchainCreateInfoKHR-compositeAlpha-01280(ERROR / SPEC): msgNum: -1341842926 - Validation Error: [ VUID-VkSwapchainCreateInfoKHR-compositeAlpha-01280 ] Object 0: handle = 0x55f648593ab8, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xb0051a12 | vkCreateSwapchainKHR() called with a non-supported pCreateInfo->compositeAlpha (i.e. VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR). Supported values are:
VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR
. The Vulkan spec states: compositeAlpha must be one of the bits present in the supportedCompositeAlpha member of the VkSurfaceCapabilitiesKHR structure returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface (https://vulkan.lunarg.com/doc/view/1.2.162.0/linux/1.2-extensions/vkspec.html#VUID-VkSwapchainCreateInfoKHR-compositeAlpha-01280)
Objects: 1
[0] 0x55f648593ab8, type: 3, name: NULL
Still interested in a solution to this
Most helpful comment
Still interested in a solution to this