Update winit example to use new multi-adapter API

This commit is contained in:
Rose Hudson 2022-12-13 23:38:50 +00:00
parent f0faadc356
commit c5401e777e
2 changed files with 15 additions and 11 deletions

View file

@ -23,10 +23,13 @@ use winit::{event_loop::EventLoop, window::Window};
async fn run(event_loop: EventLoop<()>, window: Window) {
use winit::{event::*, event_loop::ControlFlow};
let render_cx = RenderContext::new().await.unwrap();
let mut render_cx = RenderContext::new().unwrap();
let size = window.inner_size();
let mut surface = render_cx.create_surface(&window, size.width, size.height);
let mut renderer = Renderer::new(&render_cx.device).unwrap();
let mut surface = render_cx
.create_surface(&window, size.width, size.height)
.await;
let device_handle = &render_cx.devices[surface.dev_id];
let mut renderer = Renderer::new(&device_handle.device).unwrap();
let mut simple_text = simple_text::SimpleText::new();
let mut current_frame = 0usize;
let mut scene_ix = 0usize;
@ -59,6 +62,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
current_frame += 1;
let width = surface.config.width;
let height = surface.config.height;
let device_handle = &render_cx.devices[surface.dev_id];
let mut builder = SceneBuilder::for_scene(&mut scene);
const N_SCENES: usize = 6;
match scene_ix % N_SCENES {
@ -76,8 +80,8 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
.expect("failed to get surface texture");
renderer
.render_to_surface(
&render_cx.device,
&render_cx.queue,
&device_handle.device,
&device_handle.queue,
&scene,
&surface_texture,
width,
@ -85,7 +89,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
)
.expect("failed to render to surface");
surface_texture.present();
render_cx.device.poll(wgpu::Maintain::Wait);
device_handle.device.poll(wgpu::Maintain::Wait);
}
_ => {}
});

View file

@ -26,13 +26,13 @@ use wgpu::{
/// Simple render context that maintains wgpu state for rendering the pipeline.
pub struct RenderContext {
pub instance: Instance,
devices: Vec<DeviceHandle>,
pub devices: Vec<DeviceHandle>,
}
struct DeviceHandle {
pub struct DeviceHandle {
adapter: Adapter,
device: Device,
queue: Queue,
pub device: Device,
pub queue: Queue,
}
impl RenderContext {
@ -131,5 +131,5 @@ impl RenderContext {
pub struct RenderSurface {
pub surface: Surface,
pub config: SurfaceConfiguration,
dev_id: usize,
pub dev_id: usize,
}