gpui: Pass premultiplied alpha to wgpu shaders as a uniform (#66902)

We tried implementing this switch as a WGSL override constant to avoid
the uniform read. Only `blend_color` reads it, so most of our vertex
shaders don't use the constant. WebGPU specifies that unused constants
should be ignored. Safari 26 silently fails to build the pipeline
instead. So, put the flag back in the uniform.

Release Notes:

- N/A
- [GPUI] N/A

(cherry picked from commit 8e474e1598)
This commit is contained in:
John Tur
2026-11-12 21:45:07 +00:00
parent 8a5cf7e23a
commit 0b0ab12e76
2 changed files with 11 additions and 12 deletions
+3 -4
View File
@@ -83,11 +83,10 @@ struct GlobalParams {
path_curve_base: u32,
depth_scale: f32,
quad_count: u32,
pad: vec2<u32>,
premultiplied_alpha: u32,
pad: u32,
}
override PREMULTIPLIED_ALPHA: bool = false;
struct GammaParams {
gamma_ratios: vec4<f32>,
grayscale_enhanced_contrast: f32,
@@ -388,7 +387,7 @@ fn quad_sdf_impl(corner_center_to_point: vec2<f32>, corner_radius: f32) -> f32 {
// target alpha compositing mode.
fn blend_color(color: vec4<f32>, alpha_factor: f32) -> vec4<f32> {
let alpha = color.a * alpha_factor;
let multiplier = select(1.0, alpha, PREMULTIPLIED_ALPHA);
let multiplier = select(1.0, alpha, globals.premultiplied_alpha != 0u);
return vec4<f32>(color.rgb * multiplier, alpha);
}
+8 -8
View File
@@ -63,7 +63,8 @@ struct GlobalParams {
path_curve_base: u32,
depth_scale: f32,
quad_count: u32,
pad: [u32; 2],
premultiplied_alpha: u32,
pad: u32,
}
const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
@@ -129,6 +130,7 @@ struct WgpuPipelines {
poly_sprites: wgpu::RenderPipeline,
#[allow(dead_code)]
surfaces: wgpu::RenderPipeline,
premultiplied_alpha: bool,
}
/// One frame allocation of instance data, ready to bind.
@@ -774,10 +776,6 @@ impl WgpuRendererCore {
} else {
wgpu::BlendState::ALPHA_BLENDING
};
let compilation_options = wgpu::PipelineCompilationOptions {
constants: &[("PREMULTIPLIED_ALPHA", f64::from(premultiplied_alpha as u8))],
..Default::default()
};
let color_target = wgpu::ColorTargetState {
format: surface_format,
@@ -810,13 +808,13 @@ impl WgpuRendererCore {
module,
entry_point: Some(vs_entry),
buffers: &[],
compilation_options: compilation_options.clone(),
compilation_options: wgpu::PipelineCompilationOptions::default(),
},
fragment: Some(wgpu::FragmentState {
module,
entry_point: Some(fs_entry),
targets: color_targets,
compilation_options: compilation_options.clone(),
compilation_options: wgpu::PipelineCompilationOptions::default(),
}),
primitive: wgpu::PrimitiveState {
topology,
@@ -992,6 +990,7 @@ impl WgpuRendererCore {
subpixel_sprites,
poly_sprites,
surfaces,
premultiplied_alpha,
}
}
}
@@ -1394,7 +1393,8 @@ impl WgpuRendererCore {
path_curve_base: instance_bindings.path_tiles.curve_base,
depth_scale,
quad_count: scene.quads.len() as u32,
pad: [0; 2],
premultiplied_alpha: self.resources().pipelines.premultiplied_alpha as u32,
pad: 0,
};
self.resources().queue.write_buffer(
&self.resources().globals_buffer,