Skip to content

Commit 948b437

Browse files
SomeoneToIgnorelocalccreflectronicapricotbucket28
authored
Stop using linear color space on Linux Blade renderer (zed-industries#38967)
Part of zed-industries#7992 Closes zed-industries#22711 Left is main, right is patched. * default font <img width="3862" height="2152" alt="image" src="https://github.com/user-attachments/assets/c4e3d18a-a0dd-48b8-a1f0-182407655efb" /> <img width="3862" height="2152" alt="image" src="https://github.com/user-attachments/assets/6eea07e7-1676-422c-961f-05bc72677fad" /> <img width="3862" height="2152" alt="image" src="https://github.com/user-attachments/assets/4d9e30dc-6905-48ad-849d-48eac6ebed03" /> <img width="3862" height="2152" alt="image" src="https://github.com/user-attachments/assets/ef20986e-c29c-4fe0-9f20-56da4fb0ac29" /> * font size 7 <img width="3862" height="2152" alt="image" src="https://github.com/user-attachments/assets/8b277e92-9ae4-4415-8903-68566b580f5a" /> <img width="3862" height="2152" alt="image" src="https://github.com/user-attachments/assets/b9140e73-81af-430b-b07f-af118c7e3dae" /> <img width="3862" height="2152" alt="image" src="https://github.com/user-attachments/assets/185f526a-241e-4573-af1d-f27aedeac48e" /> <img width="3862" height="2152" alt="image" src="https://github.com/user-attachments/assets/7a239121-ae13-4db9-99d9-785ec26cd98e" /> Release Notes: - Improved color rendering on Linux Co-authored-by: Kate <[email protected]> Co-authored-by: John <[email protected]> Co-authored-by: apricotbucket28 <[email protected]>
1 parent 8db24dd commit 948b437

File tree

3 files changed

+6
-21
lines changed

3 files changed

+6
-21
lines changed

crates/gpui/src/platform/blade/blade_atlas.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl BladeAtlasState {
163163
usage = gpu::TextureUsage::COPY | gpu::TextureUsage::RESOURCE;
164164
}
165165
AtlasTextureKind::Polychrome => {
166-
format = gpu::TextureFormat::Bgra8UnormSrgb;
166+
format = gpu::TextureFormat::Bgra8Unorm;
167167
usage = gpu::TextureUsage::COPY | gpu::TextureUsage::RESOURCE;
168168
}
169169
}

crates/gpui/src/platform/blade/blade_renderer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl BladeRenderer {
353353
size: config.size,
354354
usage: gpu::TextureUsage::TARGET,
355355
display_sync: gpu::DisplaySync::Recent,
356-
color_space: gpu::ColorSpace::Linear,
356+
color_space: gpu::ColorSpace::Srgb,
357357
allow_exclusive_full_screen: false,
358358
transparent: config.transparent,
359359
};

crates/gpui/src/platform/blade/shaders.wgsl

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,6 @@ fn linear_to_srgb(linear: vec3<f32>) -> vec3<f32> {
194194
return select(higher, lower, cutoff);
195195
}
196196

197-
fn linear_to_srgb_component(linear: f32) -> f32 {
198-
let cutoff = linear < 0.0031308;
199-
let higher = 1.055 * pow(linear, 1.0 / 2.4) - 0.055;
200-
let lower = linear * 12.92;
201-
return select(higher, lower, cutoff);
202-
}
203-
204197
/// Convert a linear color to sRGBA space.
205198
fn linear_to_srgba(color: vec4<f32>) -> vec4<f32> {
206199
return vec4<f32>(linear_to_srgb(color.rgb), color.a);
@@ -243,12 +236,7 @@ fn hsla_to_rgba(hsla: Hsla) -> vec4<f32> {
243236
color.b += x;
244237
}
245238

246-
// Input colors are assumed to be in sRGB space,
247-
// but blending and rendering needs to happen in linear space.
248-
// The output will be converted to sRGB by either the target
249-
// texture format or the swapchain color space.
250-
let linear = srgb_to_linear(color);
251-
return vec4<f32>(linear, a);
239+
return vec4<f32>(color, a);
252240
}
253241

254242
/// Convert a linear sRGB to Oklab space.
@@ -1169,18 +1157,15 @@ fn vs_mono_sprite(@builtin(vertex_index) vertex_id: u32, @builtin(instance_index
11691157
@fragment
11701158
fn fs_mono_sprite(input: MonoSpriteVarying) -> @location(0) vec4<f32> {
11711159
let sample = textureSample(t_sprite, s_sprite, input.tile_position).r;
1172-
// converting to linear space to do color operations as cosmic_text outputs texture data in srgb format
1173-
// cannot make the gpu automatically do the conversion as there's no R8UnormSrgb format
1174-
let sample_linear = srgb_to_linear_component(sample);
1175-
let alpha_corrected = apply_contrast_and_gamma_correction(sample_linear, input.color.rgb, grayscale_enhanced_contrast, gamma_ratios);
1160+
let alpha_corrected = apply_contrast_and_gamma_correction(sample, input.color.rgb, grayscale_enhanced_contrast, gamma_ratios);
11761161

11771162
// Alpha clip after using the derivatives.
11781163
if (any(input.clip_distances < vec4<f32>(0.0))) {
11791164
return vec4<f32>(0.0);
11801165
}
11811166

11821167
// convert to srgb space as the rest of the code (output swapchain) expects that
1183-
return blend_color(input.color, linear_to_srgb_component(alpha_corrected));
1168+
return blend_color(input.color, alpha_corrected);
11841169
}
11851170

11861171
// --- polychrome sprites --- //
@@ -1233,7 +1218,7 @@ fn fs_poly_sprite(input: PolySpriteVarying) -> @location(0) vec4<f32> {
12331218
let grayscale = dot(color.rgb, GRAYSCALE_FACTORS);
12341219
color = vec4<f32>(vec3<f32>(grayscale), sample.a);
12351220
}
1236-
return blend_color(color, linear_to_srgb_component(sprite.opacity * saturate(0.5 - distance)));
1221+
return blend_color(color, sprite.opacity * saturate(0.5 - distance));
12371222
}
12381223

12391224
// --- surfaces --- //

0 commit comments

Comments
 (0)