From 0b0ab12e764812ea1634a5713fea2258df015a68 Mon Sep 17 00:00:00 2001 From: John Tur Date: Thu, 12 Nov 2026 21:45:07 +0000 Subject: [PATCH] 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 8e474e1598875be89a2225fb7ba0f6ebcdb7190a) --- crates/gpui_wgpu/src/shaders.wgsl | 7 +++---- crates/gpui_wgpu/src/wgpu_renderer.rs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/crates/gpui_wgpu/src/shaders.wgsl b/crates/gpui_wgpu/src/shaders.wgsl index 69a5338d3c5..3bfa53fdbf6 100644 --- a/crates/gpui_wgpu/src/shaders.wgsl +++ b/crates/gpui_wgpu/src/shaders.wgsl @@ -83,11 +83,10 @@ struct GlobalParams { path_curve_base: u32, depth_scale: f32, quad_count: u32, - pad: vec2, + premultiplied_alpha: u32, + pad: u32, } -override PREMULTIPLIED_ALPHA: bool = false; - struct GammaParams { gamma_ratios: vec4, grayscale_enhanced_contrast: f32, @@ -388,7 +387,7 @@ fn quad_sdf_impl(corner_center_to_point: vec2, corner_radius: f32) -> f32 { // target alpha compositing mode. fn blend_color(color: vec4, alpha_factor: f32) -> vec4 { 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(color.rgb * multiplier, alpha); } diff --git a/crates/gpui_wgpu/src/wgpu_renderer.rs b/crates/gpui_wgpu/src/wgpu_renderer.rs index 9cb06b0d2f5..53af304a9f6 100644 --- a/crates/gpui_wgpu/src/wgpu_renderer.rs +++ b/crates/gpui_wgpu/src/wgpu_renderer.rs @@ -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,