Skip to content

Commit e00de19

Browse files
committed
Upgrade to WGPU v29 (+ latest vello main)
Signed-off-by: Nico Burns <nico@nicoburns.com>
1 parent 6165c96 commit e00de19

9 files changed

Lines changed: 145 additions & 388 deletions

File tree

Cargo.lock

Lines changed: 65 additions & 319 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ homepage = "https://github.com/dioxuslabs/anyrender"
2222
repository = "https://github.com/dioxuslabs/anyrender"
2323
categories = ["gui"]
2424
edition = "2024"
25-
rust-version = "1.92.0"
25+
rust-version = "1.88.0"
2626

2727
[workspace.dependencies]
2828
# AnyRender dependencies (in-repo)
@@ -52,13 +52,14 @@ color = "0.3"
5252
linebender_resource_handle = "0.1"
5353
peniko = "0.6"
5454
kurbo = "0.13"
55+
glifo = "0.0.0"
5556
vello = { version = "0.8", features = [ "wgpu" ] }
5657
vello_cpu = { version = "0.0.7", default-features = false, features = ["std", "text", "u8_pipeline"] }
5758
vello_hybrid = { version = "0.0.7" }
5859
vello_common = { version = "0.0.7" }
5960

6061
# Rendering
61-
wgpu = "28"
62+
wgpu = "29"
6263
raw-window-handle = "0.6.0"
6364
softbuffer = "0.4"
6465
pixels = "0.17"
@@ -84,3 +85,4 @@ vello = { path = "../vello/vello" }
8485
vello_cpu = { path = "../vello/sparse_strips/vello_cpu" }
8586
vello_hybrid = { path = "../vello/sparse_strips/vello_hybrid" }
8687
vello_common = { path = "../vello/sparse_strips/vello_common" }
88+
glifo = { path = "../vello/glifo" }

crates/anyrender_vello/src/window_renderer.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use vello::{
1111
AaConfig, AaSupport, RenderParams, Renderer as VelloRenderer, RendererOptions,
1212
Scene as VelloScene,
1313
};
14-
use wgpu::{Features, Limits, PresentMode, SurfaceError, Texture, TextureFormat, TextureUsages};
14+
use wgpu::{Features, Limits, PresentMode, Texture, TextureFormat, TextureUsages};
1515
use wgpu_context::{
1616
DeviceHandle, SurfaceRenderer, SurfaceRendererConfiguration, TextureConfiguration, WGPUContext,
1717
};
@@ -305,19 +305,11 @@ impl WindowRenderer for VelloWindowRenderer {
305305
});
306306
timer.record_time("cmd");
307307

308-
match render_surface.ensure_current_surface_texture() {
309-
Ok(_) => {}
310-
Err(SurfaceError::Timeout | SurfaceError::Lost | SurfaceError::Outdated) => {
311-
render_surface.clear_surface_texture();
312-
return;
313-
}
314-
Err(SurfaceError::OutOfMemory) => panic!("Out of memory"),
315-
Err(SurfaceError::Other) => panic!("Unknown error getting surface"),
308+
let Ok(texture_view) = render_surface.target_texture_view() else {
309+
// Skip frame in case of error trying to get current surface texture
310+
return;
316311
};
317312

318-
let texture_view = render_surface
319-
.target_texture_view()
320-
.expect("handled errors from ensure_current_surface_texture above");
321313
state
322314
.renderer
323315
.render_to_texture(

crates/anyrender_vello_cpu/src/scene.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ pub struct VelloCpuScenePainter {
4444
impl VelloCpuScenePainter {
4545
pub fn finish(mut self) -> Pixmap {
4646
let mut pixmap = Pixmap::new(self.render_ctx.width(), self.render_ctx.height());
47-
self.render_ctx.render_to_pixmap(&mut self.resources, &mut pixmap);
47+
self.render_ctx
48+
.render_to_pixmap(&mut self.resources, &mut pixmap);
4849
pixmap
4950
}
5051
}

crates/anyrender_vello_hybrid/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ kurbo = { workspace = true }
1919
peniko = { workspace = true }
2020
vello_hybrid = { workspace = true }
2121
vello_common = { workspace = true }
22+
glifo = { workspace = true }
2223
wgpu = { workspace = true }
2324
rustc-hash = { workspace = true }
2425
wgpu_context = { workspace = true }

crates/anyrender_vello_hybrid/src/scene.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use kurbo::{Affine, Rect, Shape, Stroke};
33
use peniko::{BlendMode, Color, Fill, FontData, ImageBrush, ImageData, StyleRef};
44
use rustc_hash::FxHashMap;
55
use vello_common::paint::{ImageId, ImageSource, PaintType};
6-
use vello_hybrid::Renderer;
6+
use vello_hybrid::{Renderer, Resources};
77
use wgpu::{CommandEncoder, Device, Queue};
88

99
const DEFAULT_TOLERANCE: f64 = 0.1;
@@ -22,7 +22,7 @@ fn anyrender_paint_to_vello_hybrid_paint<'a>(
2222
image: ImageSource::OpaqueId {
2323
id: image_id,
2424
// TODO: optimize opaque case
25-
may_have_opacities: true,
25+
may_have_transparency: true,
2626
},
2727
sampler: image_brush.sampler,
2828
})
@@ -36,6 +36,7 @@ fn anyrender_paint_to_vello_hybrid_paint<'a>(
3636

3737
pub struct ImageManager<'a> {
3838
pub(crate) renderer: &'a mut Renderer,
39+
pub(crate) resources: &'a mut Resources,
3940
pub(crate) device: &'a Device,
4041
pub(crate) queue: &'a Queue,
4142
pub(crate) encoder: &'a mut CommandEncoder,
@@ -45,13 +46,15 @@ pub struct ImageManager<'a> {
4546
impl<'a> ImageManager<'a> {
4647
pub fn new(
4748
renderer: &'a mut Renderer,
49+
resources: &'a mut Resources,
4850
device: &'a Device,
4951
queue: &'a Queue,
5052
encoder: &'a mut CommandEncoder,
5153
cache: &'a mut FxHashMap<u64, ImageId>,
5254
) -> Self {
5355
Self {
5456
renderer,
57+
resources,
5558
device,
5659
queue,
5760
encoder,
@@ -73,9 +76,13 @@ impl<'a> ImageManager<'a> {
7376
};
7477

7578
// Upload Pixamp
76-
let atlas_id = self
77-
.renderer
78-
.upload_image(self.device, self.queue, self.encoder, &pixmap);
79+
let atlas_id = self.renderer.upload_image(
80+
self.resources,
81+
self.device,
82+
self.queue,
83+
self.encoder,
84+
&pixmap,
85+
);
7986

8087
// Store ImageId in cache
8188
self.cache.insert(peniko_id, atlas_id);
@@ -194,14 +201,14 @@ impl PaintScene for VelloHybridScenePainter<'_> {
194201
_brush_alpha: f32,
195202
transform: Affine,
196203
glyph_transform: Option<Affine>,
197-
glyphs: impl Iterator<Item = anyrender::Glyph>,
204+
glyphs: impl Iterator<Item = anyrender::Glyph> + Clone,
198205
) {
199206
let paint = anyrender_paint_to_vello_hybrid_paint(paint.into(), &mut self.image_manager);
200207
self.scene.set_paint(paint);
201208
self.scene.set_transform(transform);
202209

203-
fn into_vello_hybrid_glyph(g: anyrender::Glyph) -> vello_common::glyph::Glyph {
204-
vello_common::glyph::Glyph {
210+
fn into_vello_hybrid_glyph(g: anyrender::Glyph) -> glifo::Glyph {
211+
glifo::Glyph {
205212
id: g.id,
206213
x: g.x,
207214
y: g.y,
@@ -213,7 +220,7 @@ impl PaintScene for VelloHybridScenePainter<'_> {
213220
StyleRef::Fill(fill) => {
214221
self.scene.set_fill_rule(fill);
215222
self.scene
216-
.glyph_run(font)
223+
.glyph_run(self.image_manager.resources, font)
217224
.font_size(font_size)
218225
.hint(hint)
219226
.normalized_coords(normalized_coords)
@@ -223,7 +230,7 @@ impl PaintScene for VelloHybridScenePainter<'_> {
223230
StyleRef::Stroke(stroke) => {
224231
self.scene.set_stroke(stroke.clone());
225232
self.scene
226-
.glyph_run(font)
233+
.glyph_run(self.image_manager.resources, font)
227234
.font_size(font_size)
228235
.hint(hint)
229236
.normalized_coords(normalized_coords)

crates/anyrender_vello_hybrid/src/window_renderer.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use std::future::Future;
66
use std::sync::Arc;
77
use vello_common::paint::ImageId;
88
use vello_hybrid::{
9-
RenderSettings, RenderSize, RenderTargetConfig, Renderer as VelloHybridRenderer,
10-
Scene as VelloHybridScene,
9+
RenderSettings, RenderSize, RenderTargetConfig, Renderer as VelloHybridRenderer, Resources,
10+
Scene as VelloHybridScene, TextureBindings,
1111
};
12-
use wgpu::{CommandEncoderDescriptor, Features, Limits, PresentMode, SurfaceError, TextureFormat};
12+
use wgpu::{CommandEncoderDescriptor, Features, Limits, PresentMode, TextureFormat};
1313
use wgpu_context::{DeviceHandle, SurfaceRenderer, SurfaceRendererConfiguration, WGPUContext};
1414

1515
use crate::{VelloHybridScenePainter, scene::ImageManager};
@@ -30,6 +30,7 @@ fn spawn_init<F: Future<Output = ()>>(f: F) {
3030

3131
struct ActiveRenderState {
3232
renderer: VelloHybridRenderer,
33+
resources: Resources,
3334
render_surface: SurfaceRenderer<'static>,
3435
}
3536

@@ -223,6 +224,7 @@ impl WindowRenderer for VelloHybridWindowRenderer {
223224
)
224225
.expect("Error creating SurfaceRenderer");
225226

227+
let resources = Resources::new();
226228
let renderer = VelloHybridRenderer::new(
227229
render_surface.device(),
228230
&RenderTargetConfig {
@@ -235,6 +237,7 @@ impl WindowRenderer for VelloHybridWindowRenderer {
235237
let _ = sender.send(InitOutput {
236238
active: ActiveRenderState {
237239
renderer,
240+
resources,
238241
render_surface,
239242
},
240243
});
@@ -293,6 +296,7 @@ impl WindowRenderer for VelloHybridWindowRenderer {
293296

294297
let image_manager = ImageManager {
295298
renderer: &mut state.renderer,
299+
resources: &mut state.resources,
296300
device: render_surface.device(),
297301
queue: render_surface.queue(),
298302
encoder: &mut encoder,
@@ -307,24 +311,16 @@ impl WindowRenderer for VelloHybridWindowRenderer {
307311
});
308312
timer.record_time("cmd");
309313

310-
match render_surface.ensure_current_surface_texture() {
311-
Ok(_) => {}
312-
Err(SurfaceError::Timeout | SurfaceError::Lost | SurfaceError::Outdated) => {
313-
render_surface.clear_surface_texture();
314-
return;
315-
}
316-
Err(SurfaceError::OutOfMemory) => panic!("Out of memory"),
317-
Err(SurfaceError::Other) => panic!("Unknown error getting surface"),
314+
let Ok(texture_view) = render_surface.target_texture_view() else {
315+
// Skip frame in case of error getting surface texture
316+
return;
318317
};
319318

320-
let texture_view = render_surface
321-
.target_texture_view()
322-
.expect("handled errors from ensure_current_surface_texture above");
323-
324319
state
325320
.renderer
326321
.render(
327322
&self.scene,
323+
&mut state.resources,
328324
render_surface.device(),
329325
render_surface.queue(),
330326
&mut encoder,
@@ -333,6 +329,8 @@ impl WindowRenderer for VelloHybridWindowRenderer {
333329
height: render_surface.config.height,
334330
},
335331
&texture_view,
332+
// TODO: handle texture registration
333+
&TextureBindings::new(),
336334
)
337335
.expect("failed to render to texture");
338336
render_surface.queue().submit([encoder.finish()]);

crates/wgpu_context/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,15 @@ impl WGPUContext {
115115
override_limits: Option<Limits>,
116116
) -> Self {
117117
Self {
118-
instance: Instance::new(&wgpu::InstanceDescriptor {
118+
instance: Instance::new(wgpu::InstanceDescriptor {
119119
backends: wgpu::Backends::from_env().unwrap_or_default(),
120120
flags: wgpu::InstanceFlags::from_build_config().with_env(),
121121
backend_options: wgpu::BackendOptions::from_env_or_default(),
122122
memory_budget_thresholds: wgpu::MemoryBudgetThresholds::default(),
123+
124+
// TODO: support passing display handle
125+
// Needed for opengl/webgl
126+
display: None,
123127
}),
124128
device_pool: Vec::new(),
125129
extra_features,

crates/wgpu_context/src/surface_renderer.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use crate::{DeviceHandle, WgpuContextError, util::create_texture};
22
use wgpu::{
3-
CommandEncoderDescriptor, CompositeAlphaMode, Device, PresentMode, Queue, Surface,
4-
SurfaceConfiguration, SurfaceError, SurfaceTexture, TextureFormat, TextureUsages, TextureView,
5-
TextureViewDescriptor, util::TextureBlitter,
3+
CommandEncoderDescriptor, CompositeAlphaMode, CurrentSurfaceTexture, Device, PresentMode,
4+
Queue, Surface, SurfaceConfiguration, SurfaceTexture, TextureFormat, TextureUsages,
5+
TextureView, TextureViewDescriptor, util::TextureBlitter,
66
};
77

8+
/// Error getting the current surface texture
9+
#[derive(Clone, Debug)]
10+
pub struct GetCurrentSurfaceTextureErr;
11+
812
#[derive(Clone)]
913
pub struct TextureConfiguration {
1014
pub usage: TextureUsages,
@@ -85,7 +89,7 @@ pub struct SurfaceRenderer<'s> {
8589
pub surface: Surface<'s>,
8690
pub config: SurfaceConfiguration,
8791

88-
current_surface_texture: Option<Result<SurfaceTexture, SurfaceError>>,
92+
current_surface_texture: Option<CurrentSurfaceTexture>,
8993
intermediate_texture: Option<Box<IntermediateTextureStuff>>,
9094
}
9195

@@ -189,43 +193,41 @@ impl<'s> SurfaceRenderer<'s> {
189193
self.current_surface_texture = None;
190194
}
191195

192-
pub fn ensure_current_surface_texture(&mut self) -> Result<(), SurfaceError> {
196+
pub fn ensure_current_surface_texture(
197+
&mut self,
198+
) -> Result<&SurfaceTexture, GetCurrentSurfaceTextureErr> {
193199
if self.current_surface_texture.is_none() {
194200
let tex = self.surface.get_current_texture();
195-
if let Err(SurfaceError::Lost | SurfaceError::Outdated) = &tex {
196-
self.surface
197-
.configure(&self.device_handle.device, &self.config);
201+
match &tex {
202+
CurrentSurfaceTexture::Lost
203+
| CurrentSurfaceTexture::Outdated
204+
| CurrentSurfaceTexture::Suboptimal(_) => {
205+
self.surface
206+
.configure(&self.device_handle.device, &self.config);
207+
}
208+
_ => {}
198209
}
199210

200211
self.current_surface_texture = Some(tex);
201212
}
202213

203-
self.current_surface_texture
204-
.as_ref()
205-
.unwrap()
206-
.as_ref()
207-
.map(|_| ())
208-
.map_err(|err| err.clone())
214+
match self.current_surface_texture.as_ref().unwrap() {
215+
CurrentSurfaceTexture::Success(surface_texture) => Ok(surface_texture),
216+
_ => Err(GetCurrentSurfaceTextureErr),
217+
}
209218
}
210219

211220
/// Get a target texture view to render to.
212221
///
213222
/// If there is an intermediate texture, this is a view of that intermediate texture, otherwise
214223
/// it is a view of the surface texture.
215-
pub fn target_texture_view(&mut self) -> Result<TextureView, SurfaceError> {
224+
pub fn target_texture_view(&mut self) -> Result<TextureView, GetCurrentSurfaceTextureErr> {
216225
match &self.intermediate_texture {
217226
Some(intermediate_texture) => Ok(intermediate_texture.texture_view.clone()),
218-
None => {
219-
self.ensure_current_surface_texture()?;
220-
Ok(self
221-
.current_surface_texture
222-
.as_ref()
223-
.unwrap()
224-
.as_ref()
225-
.unwrap()
226-
.texture
227-
.create_view(&TextureViewDescriptor::default()))
228-
}
227+
None => Ok(self
228+
.ensure_current_surface_texture()?
229+
.texture
230+
.create_view(&TextureViewDescriptor::default())),
229231
}
230232
}
231233

@@ -234,9 +236,13 @@ impl<'s> SurfaceRenderer<'s> {
234236
///
235237
/// Prior to calling this, [`Self::target_texture_view`] must have been called and some
236238
/// rendering work must have been scheduled to the resulting view.
237-
pub fn maybe_blit_and_present(&mut self) -> Result<(), SurfaceError> {
239+
pub fn maybe_blit_and_present(&mut self) -> Result<(), GetCurrentSurfaceTextureErr> {
238240
self.ensure_current_surface_texture()?;
239-
let surface_texture = self.current_surface_texture.take().unwrap().unwrap();
241+
let CurrentSurfaceTexture::Success(surface_texture) =
242+
self.current_surface_texture.take().unwrap()
243+
else {
244+
unreachable!("Surface texture was set in ensure_current_surface_texture above");
245+
};
240246

241247
if let Some(its) = &self.intermediate_texture {
242248
self.blit_from_intermediate_texture_to_surface(&surface_texture, its);

0 commit comments

Comments
 (0)