Fix antialiased outline compositing on Windows (#66972)

## Summary

Antialiased rounded outlines can show dark spots on Windows when the
quad background is transparent black. The shader interpolates
straight-alpha colors at the inner edge, which mixes the transparent
background's RGB into partially covered border pixels.

Apply inner-edge coverage to the border alpha before compositing. Handle
zero combined alpha without dividing by zero.

## Testing

Windows 11 at 100% display scaling. I compared screenshots from the
original and patched Direct3D shaders using agent-desktop.

**Zed**  
The built-in onboarding page was pixel-identical before and after the
fix with the normal renderer configuration. To reproduce the affected
path in Zed, I applied the same temporary probe to both shaders to set
the RGB of transparent bordered backgrounds to black. I then measured
the default state of the two outlined buttons under **Import Settings**.

| Button | Corner pixels darker than both the straight border and the
page background |
| --- | ---: |
| VS Code | 8 → 0 |
| Cursor | 16 → 0 |

The top and bottom borders remained one physical pixel wide. This check
used an existing Zed debug build, which compiles the HLSL at startup.

**Material Gallery**  
On the **Loading indicator** page, I compared the **Start loading**
outlined button at rest and while held down. For the held state, a
temporary Gallery build dispatched a mouse-down event and captured the
rendered frame before mouse-up.

| State | Corner pixels darker than the straight border |
| --- | ---: |
| Default | 68 → 0 |
| Held | 24 → 0 |

All four straight edges remained one physical pixel wide in both states.
The held state retained its smaller corner radius and darker fill. The
Windows quad shaders also compiled successfully with Direct3D.

Release Notes:

- [GPUI] Fixed dark spots on antialiased rounded outlines.

---------

Co-authored-by: John Tur <john-tur@outlook.com>
This commit is contained in:
肆意妄为
2026-11-15 05:20:14 +00:00
committed by GitHub
parent 703b5ac3f4
commit e2f00a41ac
3 changed files with 13 additions and 26 deletions
+5 -10
View File
@@ -386,11 +386,8 @@ fragment float4 quad_fragment(QuadFragmentInput input [[stage_in]],
}
}
// Blend the border on top of the background and then linearly interpolate
// between the two as we slide inside the background.
float4 blended_border = over(background, border_color);
color = mix(background, blended_border,
saturate(antialias_threshold - inner_sdf));
border_color.a *= saturate(antialias_threshold - inner_sdf);
color = over(background, border_color);
}
return color * float4(1.0, 1.0, 1.0, saturate(antialias_threshold - outer_sdf));
@@ -1200,12 +1197,10 @@ float4 distance_from_clip_rect_transformed(float2 unit_vertex, Bounds_ScaledPixe
}
float4 over(float4 below, float4 above) {
float4 result;
float alpha = above.a + below.a * (1.0 - above.a);
result.rgb =
(above.rgb * above.a + below.rgb * below.a * (1.0 - above.a)) / alpha;
result.a = alpha;
return result;
float3 premultiplied =
above.rgb * above.a + below.rgb * below.a * (1.0 - above.a);
return float4(premultiplied / (alpha == 0.0 ? 1.0 : alpha), alpha);
}
PreparedBackground prepare_background(Background background) {
+4 -7
View File
@@ -330,8 +330,8 @@ fn oklab_to_linear_srgb(color: vec4<f32>) -> vec4<f32> {
fn over(below: vec4<f32>, above: vec4<f32>) -> vec4<f32> {
let alpha = above.a + below.a * (1.0 - above.a);
let color = (above.rgb * above.a + below.rgb * below.a * (1.0 - above.a)) / alpha;
return vec4<f32>(color, alpha);
let premultiplied = above.rgb * above.a + below.rgb * below.a * (1.0 - above.a);
return vec4<f32>(premultiplied / select(alpha, 1.0, alpha == 0.0), alpha);
}
// Selects corner radius based on quadrant.
@@ -901,11 +901,8 @@ fn fs_quad(input: QuadVarying) -> @location(0) vec4<f32> {
}
}
// Blend the border on top of the background and then linearly interpolate
// between the two as we slide inside the background.
let blended_border = over(background, border_color);
color = mix(background, blended_border,
saturate(antialias_threshold - inner_sdf));
border_color.a *= saturate(antialias_threshold - inner_sdf);
color = over(background, border_color);
}
return blend_color(color, saturate(antialias_threshold - outer_sdf));
+4 -9
View File
@@ -248,11 +248,9 @@ float4 oklab_to_srgb(float4 color) {
}
float4 over(float4 below, float4 above) {
float4 result;
float alpha = above.a + below.a * (1.0 - above.a);
result.rgb = (above.rgb * above.a + below.rgb * below.a * (1.0 - above.a)) / alpha;
result.a = alpha;
return result;
float3 premultiplied = above.rgb * above.a + below.rgb * below.a * (1.0 - above.a);
return float4(premultiplied / (alpha == 0.0 ? 1.0 : alpha), alpha);
}
float2 to_tile_position(float2 unit_vertex, AtlasTile tile) {
@@ -830,11 +828,8 @@ float4 quad_fragment(QuadFragmentInput input): SV_Target {
}
}
// Blend the border on top of the background and then linearly interpolate
// between the two as we slide inside the background.
float4 blended_border = over(background, border_color);
color = lerp(background, blended_border,
saturate(antialias_threshold - inner_sdf));
border_color.a *= saturate(antialias_threshold - inner_sdf);
color = over(background, border_color);
}
return color * float4(1.0, 1.0, 1.0, saturate(antialias_threshold - outer_sdf));