From f1f50ab7b1d35291c3504f4b0a50c7f12e0099db Mon Sep 17 00:00:00 2001 From: dtzxporter Date: Wed, 30 Oct 2024 11:59:19 -0400 Subject: [PATCH 1/7] Upgrade to wgpu v23. --- Cargo.toml | 8 ++++---- src/cache.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ea27abb..ef92d74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/grovesNL/glyphon" license = "MIT OR Apache-2.0 OR Zlib" [dependencies] -wgpu = { version = "22", default-features = false, features = ["wgsl"] } +wgpu = { version = "23", default-features = false, features = ["wgsl"] } etagere = "0.2.10" cosmic-text = "0.12" lru = { version = "0.12.1", default-features = false } @@ -16,6 +16,6 @@ rustc-hash = "2.0" [dev-dependencies] winit = "0.30.3" -wgpu = "22" -resvg = { version = "0.42", default-features = false } -pollster = "0.3.0" +wgpu = "23" +resvg = { version = "0.44", default-features = false } +pollster = "0.4.0" diff --git a/src/cache.rs b/src/cache.rs index a4a3449..e3a6167 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -221,13 +221,13 @@ impl Cache { layout: Some(pipeline_layout), vertex: VertexState { module: shader, - entry_point: "vs_main", + entry_point: Some("vs_main"), buffers: vertex_buffers, compilation_options: PipelineCompilationOptions::default(), }, fragment: Some(FragmentState { module: shader, - entry_point: "fs_main", + entry_point: Some("fs_main"), targets: &[Some(ColorTargetState { format, blend: Some(BlendState::ALPHA_BLENDING), From 87f959dfdb41c4c07bbf3f64f939d63e771e715a Mon Sep 17 00:00:00 2001 From: grovesNL Date: Tue, 5 Nov 2024 16:13:59 -0330 Subject: [PATCH 2/7] Release 0.7.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ef92d74..fa70fca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "glyphon" description = "Fast, simple 2D text rendering for wgpu" -version = "0.6.0" +version = "0.7.0" edition = "2021" homepage = "https://github.com/grovesNL/glyphon.git" repository = "https://github.com/grovesNL/glyphon" From 1055c2e5343661956519c244221c49f135f005ec Mon Sep 17 00:00:00 2001 From: Taj Pereira Date: Thu, 28 Nov 2024 22:36:23 +0900 Subject: [PATCH 3/7] Prepare benchmarks + ~1.7x prepare perf improvement (#121) * Add prepare benchmarks * Skip unnecessary peaks * Cite sample sources --- Cargo.toml | 5 + benches/prepare.rs | 121 +++++++++ benches/state.rs | 35 +++ samples/README.md | 8 + samples/arabic.txt | 637 +++++++++++++++++++++++++++++++++++++++++++++ samples/latin.txt | 137 ++++++++++ src/text_atlas.rs | 17 -- src/text_render.rs | 35 ++- 8 files changed, 960 insertions(+), 35 deletions(-) create mode 100644 benches/prepare.rs create mode 100644 benches/state.rs create mode 100644 samples/README.md create mode 100644 samples/arabic.txt create mode 100644 samples/latin.txt diff --git a/Cargo.toml b/Cargo.toml index fa70fca..a48b84b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,3 +19,8 @@ winit = "0.30.3" wgpu = "23" resvg = { version = "0.44", default-features = false } pollster = "0.4.0" +criterion = { version = "0.5", features = ["html_reports"] } + +[[bench]] +name = "prepare" +harness = false diff --git a/benches/prepare.rs b/benches/prepare.rs new file mode 100644 index 0000000..8907e20 --- /dev/null +++ b/benches/prepare.rs @@ -0,0 +1,121 @@ +use cosmic_text::{Attrs, Buffer, Color, Family, FontSystem, Metrics, Shaping, SwashCache}; +use criterion::{criterion_group, criterion_main, Criterion}; +use glyphon::{ + Cache, ColorMode, Resolution, TextArea, TextAtlas, TextBounds, TextRenderer, Viewport, Weight, +}; +use wgpu::{MultisampleState, TextureFormat}; + +mod state; + +fn run_bench(ctx: &mut Criterion) { + let mut group = ctx.benchmark_group("Prepare"); + group.noise_threshold(0.02); + + let state = state::State::new(); + + // Set up text renderer + let mut font_system = FontSystem::new(); + let mut swash_cache = SwashCache::new(); + let cache = Cache::new(&state.device); + let mut viewport = Viewport::new(&state.device, &cache); + let mut atlas = TextAtlas::with_color_mode( + &state.device, + &state.queue, + &cache, + TextureFormat::Bgra8Unorm, + ColorMode::Web, + ); + let mut text_renderer = + TextRenderer::new(&mut atlas, &state.device, MultisampleState::default(), None); + + let attrs = Attrs::new() + .family(Family::SansSerif) + .weight(Weight::NORMAL); + let shaping = Shaping::Advanced; + viewport.update( + &state.queue, + Resolution { + width: 1000, + height: 1000, + }, + ); + + for (test_name, text_areas) in &[ + ( + "Latin - Single Text Area", + vec![include_str!("../samples/latin.txt")], + ), + ( + "Arabic - Single Text Area", + vec![include_str!("../samples/arabic.txt")], + ), + ( + "Latin - Many Text Areas", + include_str!("../samples/latin.txt") + .repeat(100) + .split('\n') + .collect(), + ), + ( + "Arabic - Many Text Areas", + include_str!("../samples/arabic.txt") + .repeat(20) + .split('\n') + .collect(), + ), + ] { + let buffers: Vec = text_areas + .iter() + .copied() + .map(|s| { + let mut text_buffer = Buffer::new(&mut font_system, Metrics::relative(1.0, 10.0)); + text_buffer.set_size(&mut font_system, Some(20.0), None); + text_buffer.set_text(&mut font_system, s, attrs, shaping); + text_buffer.shape_until_scroll(&mut font_system, false); + text_buffer + }) + .collect(); + + group.bench_function(*test_name, |b| { + b.iter(|| { + let text_areas: Vec