Skip to content

Commit 0b22871

Browse files
committed
Remove render_to_surface
Replace with blitting/surface utilities in the `utils` module.
1 parent 05b7d69 commit 0b22871

File tree

11 files changed

+213
-579
lines changed

11 files changed

+213
-579
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/headless/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> {
9797
let mut renderer = vello::Renderer::new(
9898
device,
9999
RendererOptions {
100-
surface_format: None,
101100
use_cpu: args.use_cpu,
102101
num_init_threads: NonZeroUsize::new(1),
103102
antialiasing_support: vello::AaSupport::area_only(),

examples/simple/src/main.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,15 @@ impl ApplicationHandler for SimpleVelloApp<'_> {
131131
// Get a handle to the device
132132
let device_handle = &self.context.devices[surface.dev_id];
133133

134-
// Get the surface's texture
135-
let surface_texture = surface
136-
.surface
137-
.get_current_texture()
138-
.expect("failed to get surface texture");
139-
140-
// Render to the surface's texture
134+
// Render to a texture, which we will later copy into the surface
141135
self.renderers[surface.dev_id]
142136
.as_mut()
143137
.unwrap()
144-
.render_to_surface(
138+
.render_to_texture(
145139
&device_handle.device,
146140
&device_handle.queue,
147141
&self.scene,
148-
&surface_texture,
142+
&surface.target_view,
149143
&vello::RenderParams {
150144
base_color: palette::css::BLACK, // Background color
151145
width,
@@ -155,6 +149,28 @@ impl ApplicationHandler for SimpleVelloApp<'_> {
155149
)
156150
.expect("failed to render to surface");
157151

152+
// Get the surface's texture
153+
let surface_texture = surface
154+
.surface
155+
.get_current_texture()
156+
.expect("failed to get surface texture");
157+
158+
// Perform the copy
159+
let mut encoder =
160+
device_handle
161+
.device
162+
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
163+
label: Some("Surface Blit"),
164+
});
165+
surface.blitter.copy(
166+
&device_handle.device,
167+
&mut encoder,
168+
&surface.target_view,
169+
&surface_texture
170+
.texture
171+
.create_view(&wgpu::TextureViewDescriptor::default()),
172+
);
173+
device_handle.queue.submit([encoder.finish()]);
158174
// Queue the texture to be presented on the surface
159175
surface_texture.present();
160176

@@ -196,7 +212,6 @@ fn create_vello_renderer(render_cx: &RenderContext, surface: &RenderSurface<'_>)
196212
Renderer::new(
197213
&render_cx.devices[surface.dev_id].device,
198214
RendererOptions {
199-
surface_format: Some(surface.format),
200215
use_cpu: false,
201216
antialiasing_support: vello::AaSupport::all(),
202217
num_init_threads: NonZeroUsize::new(1),

examples/simple_sdl2/src/main.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,14 @@ fn main() {
6767

6868
let device_handle = &context.devices[surface.dev_id];
6969

70-
let surface_texture = surface
71-
.surface
72-
.get_current_texture()
73-
.expect("failed to get surface texture");
74-
7570
renderers[surface.dev_id]
7671
.as_mut()
7772
.unwrap()
78-
.render_to_surface(
73+
.render_to_texture(
7974
&device_handle.device,
8075
&device_handle.queue,
8176
&scene,
82-
&surface_texture,
77+
&surface.target_view,
8378
&vello::RenderParams {
8479
base_color: palette::css::BLACK, // Background color
8580
width,
@@ -89,6 +84,26 @@ fn main() {
8984
)
9085
.expect("failed to render to surface");
9186

87+
let surface_texture = surface
88+
.surface
89+
.get_current_texture()
90+
.expect("failed to get surface texture");
91+
92+
let mut encoder =
93+
device_handle
94+
.device
95+
.create_command_encoder(&wgpu::CommandEncoderDescriptor {
96+
label: Some("Surface Blit"),
97+
});
98+
surface.blitter.copy(
99+
&device_handle.device,
100+
&mut encoder,
101+
&surface.target_view,
102+
&surface_texture
103+
.texture
104+
.create_view(&wgpu::TextureViewDescriptor::default()),
105+
);
106+
device_handle.queue.submit([encoder.finish()]);
92107
for event in event_pump.poll_iter() {
93108
match event {
94109
Event::Quit { .. }
@@ -108,7 +123,6 @@ fn create_vello_renderer(render_cx: &RenderContext, surface: &RenderSurface<'_>)
108123
Renderer::new(
109124
&render_cx.devices[surface.dev_id].device,
110125
RendererOptions {
111-
surface_format: Some(surface.format),
112126
use_cpu: false,
113127
antialiasing_support: vello::AaSupport::all(),
114128
num_init_threads: NonZeroUsize::new(1),

examples/with_winit/src/lib.rs

Lines changed: 35 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use winit::dpi::LogicalSize;
4545
use winit::event_loop::EventLoop;
4646
use winit::window::{Window, WindowAttributes};
4747

48-
use vello::wgpu;
48+
use vello::wgpu::{self, CommandEncoderDescriptor};
4949

5050
#[cfg(not(any(target_arch = "wasm32", target_os = "android")))]
5151
mod hot_reload;
@@ -213,7 +213,6 @@ impl ApplicationHandler<UserEvent> for VelloApp<'_> {
213213
let mut renderer = Renderer::new(
214214
&self.context.devices[id].device,
215215
RendererOptions {
216-
surface_format: Some(render_state.surface.format),
217216
use_cpu: self.use_cpu,
218217
antialiasing_support: AA_CONFIGS.iter().copied().collect(),
219218
num_init_threads: NonZeroUsize::new(self.num_init_threads),
@@ -547,53 +546,47 @@ impl ApplicationHandler<UserEvent> for VelloApp<'_> {
547546
}
548547
}
549548
drop(encoding_span);
550-
let texture_span = tracing::trace_span!("Getting texture").entered();
551-
let surface_texture = surface
552-
.surface
553-
.get_current_texture()
554-
.expect("failed to get surface texture");
555-
556-
drop(texture_span);
557549
let render_span = tracing::trace_span!("Dispatching render").entered();
558-
// Note: we don't run the async/"robust" pipeline, as
559-
// it requires more async wiring for the readback. See
560-
// [#gpu > async on wasm](https://xi.zulipchat.com/#narrow/stream/197075-gpu/topic/async.20on.20wasm)
561-
#[allow(deprecated)]
562-
// #[expect(deprecated, reason = "This deprecation is not targeted at us.")] // Our MSRV is too low to use `expect`
563-
if self.async_pipeline && cfg!(not(target_arch = "wasm32")) {
564-
self.scene_complexity = vello::util::block_on_wgpu(
550+
self.renderers[surface.dev_id]
551+
.as_mut()
552+
.unwrap()
553+
.render_to_texture(
565554
&device_handle.device,
566-
self.renderers[surface.dev_id]
567-
.as_mut()
568-
.unwrap()
569-
.render_to_surface_async(
570-
&device_handle.device,
571-
&device_handle.queue,
572-
&self.scene,
573-
&surface_texture,
574-
&render_params,
575-
self.debug,
576-
),
555+
&device_handle.queue,
556+
&self.scene,
557+
&surface.target_view,
558+
&render_params,
577559
)
578560
.expect("failed to render to surface");
579-
} else {
580-
self.renderers[surface.dev_id]
581-
.as_mut()
582-
.unwrap()
583-
.render_to_surface(
584-
&device_handle.device,
585-
&device_handle.queue,
586-
&self.scene,
587-
&surface_texture,
588-
&render_params,
589-
)
590-
.expect("failed to render to surface");
591-
}
592-
surface_texture.present();
593561
drop(render_span);
594562

563+
let texture_span = tracing::trace_span!("Blitting to surface").entered();
564+
let surface_texture = surface
565+
.surface
566+
.get_current_texture()
567+
.expect("failed to get surface texture");
568+
// Perform the copy
569+
// (TODO: Does it improve throughput to acquire the surface after the previous texture render has happened?)
570+
let mut encoder =
571+
device_handle
572+
.device
573+
.create_command_encoder(&CommandEncoderDescriptor {
574+
label: Some("Surface Blit"),
575+
});
576+
surface.blitter.copy(
577+
&device_handle.device,
578+
&mut encoder,
579+
&surface.target_view,
580+
&surface_texture
581+
.texture
582+
.create_view(&wgpu::TextureViewDescriptor::default()),
583+
);
584+
device_handle.queue.submit([encoder.finish()]);
585+
surface_texture.present();
586+
drop(texture_span);
587+
595588
{
596-
let _poll_aspan = tracing::trace_span!("Polling wgpu device").entered();
589+
let _poll_span = tracing::trace_span!("Polling wgpu device").entered();
597590
device_handle.device.poll(wgpu::Maintain::Poll);
598591
}
599592
let new_time = Instant::now();

vello/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ default = ["wgpu"]
2222
# bump-allocated GPU memory.
2323
# TODO: Turn this into a runtime option used at resolve time and remove the feature.
2424
bump_estimate = ["vello_encoding/bump_estimate"]
25-
wgpu = ["dep:wgpu", "dep:vello_shaders", "dep:futures-intrusive"]
25+
wgpu = ["dep:wgpu", "dep:vello_shaders"]
2626

2727
# Development only features
2828

@@ -50,7 +50,6 @@ peniko = { workspace = true }
5050
wgpu = { workspace = true, optional = true }
5151
log = { workspace = true }
5252
static_assertions = { workspace = true }
53-
futures-intrusive = { workspace = true, optional = true }
5453
wgpu-profiler = { workspace = true, optional = true }
5554
thiserror = { workspace = true }
5655
# TODO: Add feature for built-in bitmap emoji support?

vello/src/debug.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Copyright 2023 the Vello Authors
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4-
#[cfg(all(feature = "debug_layers", feature = "wgpu"))]
5-
mod renderer;
6-
#[cfg(all(feature = "debug_layers", feature = "wgpu"))]
7-
mod validate;
4+
// #[cfg(all(feature = "debug_layers", feature = "wgpu"))]
5+
// mod renderer;
6+
// #[cfg(all(feature = "debug_layers", feature = "wgpu"))]
7+
// mod validate;
88

99
use std::fmt::Debug;
1010

11-
#[cfg(all(feature = "debug_layers", feature = "wgpu"))]
12-
pub(crate) use renderer::*;
11+
// #[cfg(all(feature = "debug_layers", feature = "wgpu"))]
12+
// pub(crate) use renderer::*;
1313

1414
/// Bitflags for enabled debug operations.
1515
///

0 commit comments

Comments
 (0)