From 064a387a52cf6b119933dcd5e13812c4d21b7d59 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 7 Jan 2020 00:32:46 -0500 Subject: [PATCH 1/2] Update wgpu dependency --- src/lib.rs | 82 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2dbeffdbf5..a1c35333a4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -547,12 +547,14 @@ impl Adapter { } let mut id = wgc::id::AdapterId::ERROR; - wgn::wgpu_request_adapter_async( - Some(options), - backends, - adapter_callback, - &mut id as *mut _ as *mut std::ffi::c_void, - ); + unsafe { + wgn::wgpu_request_adapter_async( + Some(options), + backends, + adapter_callback, + &mut id as *mut _ as *mut std::ffi::c_void, + ) + }; Some(Adapter { id }) } @@ -820,9 +822,11 @@ impl Device { }; let mut ptr: *mut u8 = std::ptr::null_mut(); - let id = wgn::wgpu_device_create_buffer_mapped(self.id, &desc, &mut ptr as *mut *mut u8); - - let data = unsafe { std::slice::from_raw_parts_mut(ptr as *mut u8, size) }; + let (id, data) = unsafe { + let id = wgn::wgpu_device_create_buffer_mapped(self.id, &desc, &mut ptr as *mut *mut u8); + let data = std::slice::from_raw_parts_mut(ptr as *mut u8, size); + (id, data) + }; CreateBufferMapped { device_id: self.id, id, data } } @@ -1206,13 +1210,15 @@ impl<'a> RenderPass<'a> { bind_group: &BindGroup, offsets: &[BufferAddress], ) { - wgn::wgpu_render_pass_set_bind_group( - self.id, - index, - bind_group.id, - offsets.as_ptr(), - offsets.len(), - ); + unsafe { + wgn::wgpu_render_pass_set_bind_group( + self.id, + index, + bind_group.id, + offsets.as_ptr(), + offsets.len(), + ); + } } /// Sets the active render pipeline. @@ -1249,13 +1255,15 @@ impl<'a> RenderPass<'a> { buffers.push(buffer.id); offsets.push(offset); } - wgn::wgpu_render_pass_set_vertex_buffers( - self.id, - start_slot, - buffers.as_ptr(), - offsets.as_ptr(), - buffer_pairs.len(), - ); + unsafe { + wgn::wgpu_render_pass_set_vertex_buffers( + self.id, + start_slot, + buffers.as_ptr(), + offsets.as_ptr(), + buffer_pairs.len(), + ) + }; } /// Sets the scissor region. @@ -1344,13 +1352,15 @@ impl<'a> ComputePass<'a> { bind_group: &BindGroup, offsets: &[BufferAddress], ) { - wgn::wgpu_compute_pass_set_bind_group( - self.id, - index, - bind_group.id, - offsets.as_ptr(), - offsets.len(), - ); + unsafe { + wgn::wgpu_compute_pass_set_bind_group( + self.id, + index, + bind_group.id, + offsets.as_ptr(), + offsets.len(), + ); + } } /// Sets the active compute pipeline. @@ -1386,11 +1396,13 @@ impl Queue { .map(|cb| cb.id) .collect::>(); - wgn::wgpu_queue_submit( - self.id, - temp_command_buffers.as_ptr(), - command_buffers.len(), - ); + unsafe { + wgn::wgpu_queue_submit( + self.id, + temp_command_buffers.as_ptr(), + command_buffers.len(), + ) + }; } } From 37094051b5cddf9c01f28e2a4262db3f212876a5 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 13 Jan 2020 12:45:27 -0500 Subject: [PATCH 2/2] Update wgpu and winit --- Cargo.toml | 6 +++--- examples/framework.rs | 22 ++++++++++------------ examples/hello-triangle/main.rs | 12 +++++------- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 91365cbebb..8f651e8cd8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,14 +27,14 @@ vulkan = ["wgn/vulkan-portability"] package = "wgpu-native" version = "0.4" git = "https://github.com/gfx-rs/wgpu" -rev = "c293d6dcea0170bfa3835cfbd919f300560e0da6" +rev = "c0fa61a064c3572ee60d6c4c6a59ca0571394200" #path = "../wgpu/wgpu-native" [dependencies.wgc] package = "wgpu-core" version = "0.1" git = "https://github.com/gfx-rs/wgpu" -rev = "c293d6dcea0170bfa3835cfbd919f300560e0da6" +rev = "c0fa61a064c3572ee60d6c4c6a59ca0571394200" #path = "../wgpu/wgpu-core" [dependencies] @@ -48,7 +48,7 @@ env_logger = "0.7" glsl-to-spirv = "0.1" log = "0.4" png = "0.15" -winit = "=0.20.0-alpha6" +winit = "0.20" rand = "0.7.2" zerocopy = "0.2" futures = "0.3" diff --git a/examples/framework.rs b/examples/framework.rs index 2502eb6499..5f9b67607f 100644 --- a/examples/framework.rs +++ b/examples/framework.rs @@ -63,17 +63,16 @@ pub fn run(title: &str) { log::info!("Initializing the window..."); #[cfg(not(feature = "gl"))] - let (window, hidpi_factor, size, surface) = { + let (window, size, surface) = { let window = winit::window::Window::new(&event_loop).unwrap(); window.set_title(title); - let hidpi_factor = window.hidpi_factor(); - let size = window.inner_size().to_physical(hidpi_factor); + let size = window.inner_size(); let surface = wgpu::Surface::create(&window); - (window, hidpi_factor, size, surface) + (window, size, surface) }; #[cfg(feature = "gl")] - let (window, instance, hidpi_factor, size, surface) = { + let (window, instance, size, surface) = { let wb = winit::WindowBuilder::new(); let cb = wgpu::glutin::ContextBuilder::new().with_vsync(true); let context = cb.build_windowed(wb, &event_loop).unwrap(); @@ -91,7 +90,7 @@ pub fn run(title: &str) { let instance = wgpu::Instance::new(context); let surface = instance.get_surface(); - (window, instance, hidpi_factor, size, surface) + (window, instance, size, surface) }; let adapter = wgpu::Adapter::request( @@ -112,8 +111,8 @@ pub fn run(title: &str) { let mut sc_desc = wgpu::SwapChainDescriptor { usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, format: wgpu::TextureFormat::Bgra8UnormSrgb, - width: size.width.round() as u32, - height: size.height.round() as u32, + width: size.width, + height: size.height, present_mode: wgpu::PresentMode::Vsync, }; let mut swap_chain = device.create_swap_chain(&surface, &sc_desc); @@ -137,10 +136,9 @@ pub fn run(title: &str) { event: WindowEvent::Resized(size), .. } => { - let physical = size.to_physical(hidpi_factor); - log::info!("Resizing to {:?}", physical); - sc_desc.width = physical.width.round() as u32; - sc_desc.height = physical.height.round() as u32; + log::info!("Resizing to {:?}", size); + sc_desc.width = size.width; + sc_desc.height = size.height; swap_chain = device.create_swap_chain(&surface, &sc_desc); let command_buf = example.resize(&sc_desc, &device); if let Some(command_buf) = command_buf { diff --git a/examples/hello-triangle/main.rs b/examples/hello-triangle/main.rs index b380ae9fc0..6907902a11 100644 --- a/examples/hello-triangle/main.rs +++ b/examples/hello-triangle/main.rs @@ -10,8 +10,7 @@ fn main() { #[cfg(not(feature = "gl"))] let (window, size, surface) = { let window = winit::window::Window::new(&event_loop).unwrap(); - let size = window.inner_size().to_physical(window.hidpi_factor()); - + let size = window.inner_size(); let surface = wgpu::Surface::create(&window); (window, size, surface) }; @@ -104,8 +103,8 @@ fn main() { let mut sc_desc = wgpu::SwapChainDescriptor { usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT, format: wgpu::TextureFormat::Bgra8UnormSrgb, - width: size.width.round() as u32, - height: size.height.round() as u32, + width: size.width, + height: size.height, present_mode: wgpu::PresentMode::Vsync, }; @@ -116,9 +115,8 @@ fn main() { match event { event::Event::MainEventsCleared => window.request_redraw(), event::Event::WindowEvent { event: event::WindowEvent::Resized(size), .. } => { - let physical = size.to_physical(window.hidpi_factor()); - sc_desc.width = physical.width.round() as u32; - sc_desc.height = physical.height.round() as u32; + sc_desc.width = size.width; + sc_desc.height = size.height; swap_chain = device.create_swap_chain(&surface, &sc_desc); } event::Event::RedrawRequested(_) => {