diff --git a/CHANGELOG.md b/CHANGELOG.md index 313ce0a..49ed4be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,9 @@ Per Keep a Changelog there are 6 main categories of changes: ## Unreleased +#### Updated +- updated `wgpu` to 0.10 + #### Fixed - Internal: fix all warnings from static analysis (clippy). diff --git a/Cargo.toml b/Cargo.toml index 2d6a03d..4fb2791 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ readme = "README.md" categories = ["gui", "graphics", "rendering", "rendering::graphics-api"] keywords = ["gui", "graphics", "wgpu", "imgui"] license = "MIT OR Apache-2.0" +resolver = "2" exclude = [ ".gitignore", @@ -59,7 +60,7 @@ bytemuck = "1" imgui = "0.7" log = "0.4" smallvec = "1" -wgpu = "0.9" +wgpu = { version = "0.10", features = ["spirv"] } # deps for simple_api_unstable imgui-winit-support = { version = "0.7", optional = true } diff --git a/examples/cube.rs b/examples/cube.rs index dc95b39..8697b81 100644 --- a/examples/cube.rs +++ b/examples/cube.rs @@ -126,7 +126,7 @@ impl Example { impl Example { fn init( - sc_desc: &wgpu::SwapChainDescriptor, + surface_desc: &wgpu::SurfaceConfiguration, device: &wgpu::Device, queue: &wgpu::Queue, ) -> Self { @@ -139,13 +139,13 @@ impl Example { let vertex_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Vertex Buffer"), contents: bytemuck::cast_slice(&vertex_data), - usage: wgpu::BufferUsage::VERTEX, + usage: wgpu::BufferUsages::VERTEX, }); let index_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Index Buffer"), contents: bytemuck::cast_slice(&index_data), - usage: wgpu::BufferUsage::INDEX, + usage: wgpu::BufferUsages::INDEX, }); // Create pipeline layout @@ -154,7 +154,7 @@ impl Example { entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, @@ -164,7 +164,7 @@ impl Example { }, wgpu::BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { multisampled: false, sample_type: wgpu::TextureSampleType::Float { filterable: true }, @@ -174,7 +174,7 @@ impl Example { }, wgpu::BindGroupLayoutEntry { binding: 2, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Sampler { filtering: true, comparison: false, @@ -204,7 +204,7 @@ impl Example { sample_count: 1, dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST, + usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, }); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); queue.write_texture( @@ -212,6 +212,7 @@ impl Example { texture: &texture, mip_level: 0, origin: wgpu::Origin3d::ZERO, + aspect: wgpu::TextureAspect::All, }, &texels, wgpu::ImageDataLayout { @@ -232,12 +233,12 @@ impl Example { mipmap_filter: wgpu::FilterMode::Nearest, ..Default::default() }); - let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32, 0.0); + let mx_total = Self::generate_matrix(surface_desc.width as f32 / surface_desc.height as f32, 0.0); let mx_ref: &[f32; 16] = mx_total.as_ref(); let uniform_buf = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { label: Some("Uniform Buffer"), contents: bytemuck::cast_slice(mx_ref), - usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST, + usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); // Create bind group @@ -274,7 +275,7 @@ impl Example { entry_point: "main", buffers: &[wgpu::VertexBufferLayout { array_stride: vertex_size as wgpu::BufferAddress, - step_mode: wgpu::InputStepMode::Vertex, + step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x4, @@ -300,12 +301,12 @@ impl Example { module: &fs_module, entry_point: "main", targets: &[wgpu::ColorTargetState { - format: sc_desc.format, + format: surface_desc.format, blend: Some(BlendState { color: wgpu::BlendComponent::REPLACE, alpha: wgpu::BlendComponent::REPLACE, }), - write_mask: wgpu::ColorWrite::ALL, + write_mask: wgpu::ColorWrites::ALL, }], }), }); @@ -373,7 +374,7 @@ fn main() { // Set up window and GPU let event_loop = EventLoop::new(); - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY); let (window, size, surface) = { let version = env!("CARGO_PKG_VERSION"); @@ -399,26 +400,19 @@ fn main() { })) .unwrap(); - let (device, queue) = block_on(adapter.request_device( - &wgpu::DeviceDescriptor { - label: None, - features: wgpu::Features::empty(), - limits: wgpu::Limits::default(), - }, - None, - )) - .unwrap(); + let (device, queue) = + block_on(adapter.request_device(&wgpu::DeviceDescriptor::default(), None)).unwrap(); // Set up swap chain - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + let surface_desc = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width as u32, height: size.height as u32, present_mode: wgpu::PresentMode::Mailbox, }; - let mut swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &surface_desc); // Set up dear imgui let mut imgui = imgui::Context::create(); @@ -453,7 +447,7 @@ fn main() { // }; let renderer_config = RendererConfig { - texture_format: sc_desc.format, + texture_format: surface_desc.format, ..Default::default() }; @@ -464,7 +458,7 @@ fn main() { let mut last_cursor = None; let mut example_size: [f32; 2] = [640.0, 480.0]; - let mut example = Example::init(&sc_desc, &device, &queue); + let mut example = Example::init(&surface_desc, &device, &queue); // Stores a texture for displaying with imgui::Image(), // also as a texture view for rendering into it @@ -475,7 +469,7 @@ fn main() { height: example_size[1] as u32, ..Default::default() }, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, ..Default::default() }; @@ -496,15 +490,15 @@ fn main() { } => { let size = window.inner_size(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + let surface_desc = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width as u32, height: size.height as u32, present_mode: wgpu::PresentMode::Mailbox, }; - swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &surface_desc); } Event::WindowEvent { event: @@ -531,7 +525,7 @@ fn main() { imgui.io_mut().update_delta_time(now - last_frame); last_frame = now; - let frame = match swap_chain.get_current_frame() { + let frame = match surface.get_current_frame() { Ok(frame) => frame, Err(e) => { eprintln!("dropped frame: {:?}", e); @@ -543,10 +537,12 @@ fn main() { .expect("Failed to prepare frame"); let ui = imgui.frame(); + let view = frame.output.texture.create_view(&wgpu::TextureViewDescriptor::default()); + // Render example normally at background example.update(ui.io().delta_time); example.setup_camera(&queue, ui.io().display_size); - example.render(&frame.output.view, &device, &queue); + example.render(&view, &device, &queue); // Store the new size of Image() or None to indicate that the window is collapsed. let mut new_example_size: Option<[f32; 2]> = None; @@ -569,8 +565,8 @@ fn main() { height: (example_size[1] * scale[1]) as u32, ..Default::default() }, - usage: wgpu::TextureUsage::RENDER_ATTACHMENT - | wgpu::TextureUsage::SAMPLED, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT + | wgpu::TextureUsages::TEXTURE_BINDING, ..Default::default() }; renderer.textures.replace( @@ -599,7 +595,7 @@ fn main() { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.output.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Load, // Do not clear diff --git a/examples/custom_textures.rs b/examples/custom_textures.rs index dc44443..5667992 100644 --- a/examples/custom_textures.rs +++ b/examples/custom_textures.rs @@ -17,7 +17,7 @@ fn main() { // Set up window and GPU let event_loop = EventLoop::new(); - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY); let (window, size, surface) = { let version = env!("CARGO_PKG_VERSION"); @@ -54,15 +54,15 @@ fn main() { .unwrap(); // Set up swap chain - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + let surface_desc = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width as u32, height: size.height as u32, present_mode: wgpu::PresentMode::Mailbox, }; - let mut swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &surface_desc); // Set up dear imgui let mut imgui = imgui::Context::create(); @@ -96,7 +96,7 @@ fn main() { a: 1.0, }; let renderer_config = RendererConfig { - texture_format: sc_desc.format, + texture_format: surface_desc.format, ..Default::default() }; @@ -143,15 +143,15 @@ fn main() { } => { let size = window.inner_size(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + let surface_desc = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width as u32, height: size.height as u32, present_mode: wgpu::PresentMode::Mailbox, }; - swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &surface_desc); } Event::WindowEvent { event: @@ -180,7 +180,7 @@ fn main() { imgui.io_mut().update_delta_time(now - last_frame); last_frame = now; - let frame = match swap_chain.get_current_frame() { + let frame = match surface.get_current_frame() { Ok(frame) => frame, Err(e) => { eprintln!("dropped frame: {:?}", e); @@ -212,10 +212,11 @@ fn main() { platform.prepare_render(&ui, &window); } + let view = frame.output.texture.create_view(&wgpu::TextureViewDescriptor::default()); let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.output.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(clear_color), diff --git a/examples/hello_world.rs b/examples/hello_world.rs index e81b36d..d468340 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -18,7 +18,7 @@ fn main() { // Set up window and GPU let event_loop = EventLoop::new(); - let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY); + let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY); let (window, size, surface) = { let version = env!("CARGO_PKG_VERSION"); @@ -48,15 +48,15 @@ fn main() { block_on(adapter.request_device(&wgpu::DeviceDescriptor::default(), None)).unwrap(); // Set up swap chain - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + let surface_desc = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width as u32, height: size.height as u32, present_mode: wgpu::PresentMode::Mailbox, }; - let mut swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &surface_desc); // Set up dear imgui let mut imgui = imgui::Context::create(); @@ -91,7 +91,7 @@ fn main() { }; let renderer_config = RendererConfig { - texture_format: sc_desc.format, + texture_format: surface_desc.format, ..Default::default() }; @@ -116,15 +116,15 @@ fn main() { } => { let size = window.inner_size(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + let surface_desc = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width as u32, height: size.height as u32, present_mode: wgpu::PresentMode::Mailbox, }; - swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &surface_desc); } Event::WindowEvent { event: @@ -152,7 +152,7 @@ fn main() { imgui.io_mut().update_delta_time(now - last_frame); last_frame = now; - let frame = match swap_chain.get_current_frame() { + let frame = match surface.get_current_frame() { Ok(frame) => frame, Err(e) => { eprintln!("dropped frame: {:?}", e); @@ -199,10 +199,11 @@ fn main() { platform.prepare_render(&ui, &window); } + let view = frame.output.texture.create_view(&wgpu::TextureViewDescriptor::default()); let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: None, color_attachments: &[wgpu::RenderPassColorAttachment { - view: &frame.output.view, + view: &view, resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(clear_color), diff --git a/src/lib.rs b/src/lib.rs index 34eada2..d59372f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,7 +57,7 @@ pub struct TextureConfig<'a> { /// The format of the texture, if not set uses the format from the renderer. pub format: Option, /// The usage of the texture. - pub usage: TextureUsage, + pub usage: TextureUsages, /// The mip level of the texture. pub mip_level_count: u32, /// The sample count of the texture. @@ -77,7 +77,7 @@ impl<'a> Default for TextureConfig<'a> { }, label: None, format: None, - usage: TextureUsage::SAMPLED | TextureUsage::COPY_DST, + usage: TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST, mip_level_count: 1, sample_count: 1, dimension: TextureDimension::D2, @@ -177,6 +177,7 @@ impl Texture { texture: &self.texture, mip_level: 0, origin: Origin3d { x: 0, y: 0, z: 0 }, + aspect: TextureAspect::All, }, // source bitmap data data, @@ -319,7 +320,7 @@ impl Renderer { let uniform_buffer = device.create_buffer(&BufferDescriptor { label: Some("imgui-wgpu uniform buffer"), size, - usage: BufferUsage::UNIFORM | BufferUsage::COPY_DST, + usage: BufferUsages::UNIFORM | BufferUsages::COPY_DST, mapped_at_creation: false, }); @@ -328,7 +329,7 @@ impl Renderer { label: None, entries: &[BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::VERTEX, + visibility: wgpu::ShaderStages::VERTEX, ty: BindingType::Buffer { ty: BufferBindingType::Uniform, has_dynamic_offset: false, @@ -354,7 +355,7 @@ impl Renderer { entries: &[ BindGroupLayoutEntry { binding: 0, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: BindingType::Texture { multisampled: false, sample_type: TextureSampleType::Float { filterable: true }, @@ -364,7 +365,7 @@ impl Renderer { }, BindGroupLayoutEntry { binding: 1, - visibility: wgpu::ShaderStage::FRAGMENT, + visibility: wgpu::ShaderStages::FRAGMENT, ty: BindingType::Sampler { comparison: false, filtering: true, @@ -391,7 +392,7 @@ impl Renderer { entry_point: "main", buffers: &[VertexBufferLayout { array_stride: size_of::() as BufferAddress, - step_mode: InputStepMode::Vertex, + step_mode: VertexStepMode::Vertex, attributes: &vertex_attr_array![0 => Float32x2, 1 => Float32x2, 2 => Unorm8x4], }], }, @@ -432,7 +433,7 @@ impl Renderer { operation: BlendOperation::Add, }, }), - write_mask: ColorWrite::ALL, + write_mask: ColorWrites::ALL, }], }), }); @@ -596,7 +597,7 @@ impl Renderer { device.create_buffer_init(&BufferInitDescriptor { label: Some("imgui-wgpu vertex buffer"), contents: data, - usage: BufferUsage::VERTEX, + usage: BufferUsages::VERTEX, }) } @@ -607,7 +608,7 @@ impl Renderer { device.create_buffer_init(&BufferInitDescriptor { label: Some("imgui-wgpu index buffer"), contents: data, - usage: BufferUsage::INDEX, + usage: BufferUsages::INDEX, }) } diff --git a/src/simple_api.rs b/src/simple_api.rs index c4c3d3a..2ed33e7 100644 --- a/src/simple_api.rs +++ b/src/simple_api.rs @@ -84,7 +84,7 @@ pub fn run { let size = window.inner_size(); - let sc_desc = wgpu::SwapChainDescriptor { - usage: wgpu::TextureUsage::RENDER_ATTACHMENT, + let surface_desc = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width as u32, height: size.height as u32, - present_mode: wgpu::PresentMode::Mailbox, + present_mode: wgpu::PresentMode::Fifo, }; - swap_chain = device.create_swap_chain(&surface, &sc_desc); + surface.configure(&device, &surface_desc); (config.on_resize)(&size, &mut state, hidpi_factor); } @@ -208,7 +207,7 @@ pub fn run frame, Err(e) => { eprintln!("dropped frame: {:?}", e); @@ -230,10 +229,11 @@ pub fn run