161: Update wgpu and winit r=kvark a=kvark



Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
This commit is contained in:
bors[bot]
2020-01-13 18:20:47 +00:00
committed by GitHub
4 changed files with 65 additions and 57 deletions

View File

@@ -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"

View File

@@ -63,17 +63,16 @@ pub fn run<E: Example>(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<E: Example>(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<E: Example>(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<E: Example>(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 {

View File

@@ -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(_) => {

View File

@@ -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::<SmallVec<[_; 4]>>();
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(),
)
};
}
}