Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,10 @@ impl crate::Adapter for super::Adapter {
} else {
vec![wgt::PresentMode::Fifo] //TODO
},
composite_alpha_modes: vec![wgt::CompositeAlphaMode::Opaque], //TODO
composite_alpha_modes: vec![
wgt::CompositeAlphaMode::Opaque,
wgt::CompositeAlphaMode::PreMultiplied,
], //TODO
Comment on lines +1235 to +1238
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right - without telling this to the runtime at all we can't know if these modes are actually supported. I'm not sure how this works with the various platforms, but I don't think we can just change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It look like premultipliedAlpha is set to true by default https://registry.khronos.org/webgl/specs/latest/1.0/#5.2 and we do not seem to change it

Copy link
Collaborator

@grovesNL grovesNL Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like supporting multiple modes could be tricky if we want it to be handled at the WebGL context level, because we'd need to create the context (wgpu's Surface) with opaque vs. premultiplied. There seems like a couple options:

  • If we exposed a way to specify whether alpha and premultiplied should be used when creating the initial surface/context, then we could change composite_alpha_modes to return Opaque/PreMultiplied depending on whatever the surface is currently using.
  • If we always use premultiplied on the context, I guess we could at least handle both opaque and premultiplied for srgb presentation by handling it in srgb_present.frag. This wouldn't work for non-srgb though where we blit the framebuffer (unless we went through a shader there for the opaque case).

maximum_frame_latency: 2..=2, //TODO, unused currently
current_extent: None,
usage: wgt::TextureUses::COLOR_TARGET,
Expand Down
5 changes: 4 additions & 1 deletion wgpu/src/backend/webgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3735,7 +3735,10 @@ impl dispatch::SurfaceInterface for WebSurface {
formats,
// Doesn't really have meaning on the web.
present_modes: vec![wgt::PresentMode::Fifo],
alpha_modes: vec![wgt::CompositeAlphaMode::Opaque],
alpha_modes: vec![
wgt::CompositeAlphaMode::Opaque,
wgt::CompositeAlphaMode::PreMultiplied,
],
// Statically set to RENDER_ATTACHMENT for now. See https://gpuweb.github.io/gpuweb/#dom-gpucanvasconfiguration-usage
usages: wgt::TextureUsages::RENDER_ATTACHMENT,
}
Expand Down