Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/headless/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ fn main() -> Result<()> {
async fn render(mut scenes: SceneSet, index: usize, args: &Args) -> Result<()> {
let mut context = RenderContext::new();
let device_id = context
.device(None)
.find_or_create_device(None)
.await
.ok_or_else(|| anyhow!("No compatible device found"))?;
let device_handle = &mut context.devices[device_id];
let device_handle = &mut context.device_pool[device_id];
let device = &device_handle.device;
let queue = &device_handle.queue;
let mut renderer = vello::Renderer::new(
Expand Down
9 changes: 4 additions & 5 deletions examples/simple/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl ApplicationHandler for SimpleVelloApp<'_> {

// Create a vello Renderer for the surface (using its device id)
self.renderers
.resize_with(self.context.devices.len(), || None);
.resize_with(self.context.device_pool.len(), || None);
self.renderers[surface.dev_id]
.get_or_insert_with(|| create_vello_renderer(&self.context, &surface));

Expand Down Expand Up @@ -105,8 +105,7 @@ impl ApplicationHandler for SimpleVelloApp<'_> {

// Resize the surface when the window is resized
WindowEvent::Resized(size) => {
self.context
.resize_surface(surface, size.width, size.height);
surface.resize(size.width, size.height);
}

// This is where all the rendering happens
Expand All @@ -123,7 +122,7 @@ impl ApplicationHandler for SimpleVelloApp<'_> {
let height = surface.config.height;

// Get a handle to the device
let device_handle = &self.context.devices[surface.dev_id];
let device_handle = &self.context.device_pool[surface.dev_id];

// Render to a texture, which we will later copy into the surface
self.renderers[surface.dev_id]
Expand Down Expand Up @@ -204,7 +203,7 @@ fn create_winit_window(event_loop: &ActiveEventLoop) -> Arc<Window> {
/// Helper function that creates a vello `Renderer` for a given `RenderContext` and `RenderSurface`
fn create_vello_renderer(render_cx: &RenderContext, surface: &RenderSurface<'_>) -> Renderer {
Renderer::new(
&render_cx.devices[surface.dev_id].device,
&render_cx.device_pool[surface.dev_id].device,
RendererOptions::default(),
)
.expect("Couldn't create renderer")
Expand Down
28 changes: 12 additions & 16 deletions examples/with_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ impl ApplicationHandler<UserEvent> for VelloApp<'_> {
self.state = {
let render_state = RenderState { window, surface };
self.renderers
.resize_with(self.context.devices.len(), || None);
.resize_with(self.context.device_pool.len(), || None);
let id = render_state.surface.dev_id;
self.renderers[id].get_or_insert_with(|| {
let device_handle = &self.context.devices[id];
let device_handle = &self.context.device_pool[id];
let cache = if let Some((dir, tx)) = self.cache_data.as_ref() {
// Safety: Hoping for the best. Given that we're using as private a cache directory as possible, it's
// probably fine?
Expand Down Expand Up @@ -349,14 +349,11 @@ impl ApplicationHandler<UserEvent> for VelloApp<'_> {
}
"v" => {
self.vsync_on = !self.vsync_on;
self.context.set_present_mode(
&mut render_state.surface,
if self.vsync_on {
wgpu::PresentMode::AutoVsync
} else {
wgpu::PresentMode::AutoNoVsync
},
);
render_state.surface.set_present_mode(if self.vsync_on {
wgpu::PresentMode::AutoVsync
} else {
wgpu::PresentMode::AutoNoVsync
});
}
debug_layer @ ("1" | "2" | "3" | "4") => {
match debug_layer {
Expand Down Expand Up @@ -426,8 +423,7 @@ impl ApplicationHandler<UserEvent> for VelloApp<'_> {
}
WindowEvent::Resized(size) => {
if let Some(RenderState { surface, window }) = &mut self.state {
self.context
.resize_surface(surface, size.width, size.height);
surface.resize(size.width, size.height);
window.request_redraw();
}
}
Expand Down Expand Up @@ -481,7 +477,7 @@ impl ApplicationHandler<UserEvent> for VelloApp<'_> {
};
let width = surface.config.width;
let height = surface.config.height;
let device_handle = &self.context.devices[surface.dev_id];
let device_handle = &self.context.device_pool[surface.dev_id];
let snapshot = self.stats.snapshot();

// Allow looping forever
Expand Down Expand Up @@ -671,7 +667,7 @@ impl ApplicationHandler<UserEvent> for VelloApp<'_> {
let Some(render_state) = &mut self.state else {
return;
};
let device_handle = &self.context.devices[render_state.surface.dev_id];
let device_handle = &self.context.device_pool[render_state.surface.dev_id];
log::info!("==============\nReloading shaders");
let start = Instant::now();
let result = self.renderers[render_state.surface.dev_id]
Expand Down Expand Up @@ -717,9 +713,9 @@ fn run(
#[cfg(target_arch = "wasm32")]
let (render_state, renderers) = {
let mut renderers = vec![];
renderers.resize_with(render_cx.devices.len(), || None);
renderers.resize_with(render_cx.device_pool.len(), || None);
let id = render_state.surface.dev_id;
let device_handle = &render_cx.devices[id];
let device_handle = &render_cx.device_pool[id];
let cache: Option<(PipelineCache, PathBuf)> = if let Some(dir) = cache_directory.as_ref() {
// Safety: Hoping for the best. Given that we're using as private a cache directory as possible, it's
// probably fine?
Expand Down
Loading
Loading