diff --git a/Cargo.lock b/Cargo.lock index 60e311426f..90c4ab1840 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -476,7 +476,7 @@ dependencies = [ [[package]] name = "gfx-auxil" version = "0.5.0" -source = "git+https://github.com/gfx-rs/gfx?rev=00285817af676e091ac886b927e9e5e292f22a03#00285817af676e091ac886b927e9e5e292f22a03" +source = "git+https://github.com/gfx-rs/gfx?rev=2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8#2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" dependencies = [ "fxhash", "gfx-hal", @@ -486,7 +486,7 @@ dependencies = [ [[package]] name = "gfx-backend-dx11" version = "0.6.0" -source = "git+https://github.com/gfx-rs/gfx?rev=00285817af676e091ac886b927e9e5e292f22a03#00285817af676e091ac886b927e9e5e292f22a03" +source = "git+https://github.com/gfx-rs/gfx?rev=2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8#2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" dependencies = [ "arrayvec", "bitflags", @@ -507,7 +507,7 @@ dependencies = [ [[package]] name = "gfx-backend-dx12" version = "0.6.2" -source = "git+https://github.com/gfx-rs/gfx?rev=00285817af676e091ac886b927e9e5e292f22a03#00285817af676e091ac886b927e9e5e292f22a03" +source = "git+https://github.com/gfx-rs/gfx?rev=2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8#2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" dependencies = [ "arrayvec", "bit-set", @@ -527,7 +527,7 @@ dependencies = [ [[package]] name = "gfx-backend-empty" version = "0.6.0" -source = "git+https://github.com/gfx-rs/gfx?rev=00285817af676e091ac886b927e9e5e292f22a03#00285817af676e091ac886b927e9e5e292f22a03" +source = "git+https://github.com/gfx-rs/gfx?rev=2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8#2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" dependencies = [ "gfx-hal", "log", @@ -537,7 +537,7 @@ dependencies = [ [[package]] name = "gfx-backend-gl" version = "0.6.0" -source = "git+https://github.com/gfx-rs/gfx?rev=00285817af676e091ac886b927e9e5e292f22a03#00285817af676e091ac886b927e9e5e292f22a03" +source = "git+https://github.com/gfx-rs/gfx?rev=2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8#2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" dependencies = [ "arrayvec", "bitflags", @@ -559,7 +559,7 @@ dependencies = [ [[package]] name = "gfx-backend-metal" version = "0.6.0" -source = "git+https://github.com/gfx-rs/gfx?rev=00285817af676e091ac886b927e9e5e292f22a03#00285817af676e091ac886b927e9e5e292f22a03" +source = "git+https://github.com/gfx-rs/gfx?rev=2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8#2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" dependencies = [ "arrayvec", "bitflags", @@ -583,7 +583,7 @@ dependencies = [ [[package]] name = "gfx-backend-vulkan" version = "0.6.5" -source = "git+https://github.com/gfx-rs/gfx?rev=00285817af676e091ac886b927e9e5e292f22a03#00285817af676e091ac886b927e9e5e292f22a03" +source = "git+https://github.com/gfx-rs/gfx?rev=2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8#2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" dependencies = [ "arrayvec", "ash", @@ -603,7 +603,7 @@ dependencies = [ [[package]] name = "gfx-hal" version = "0.6.0" -source = "git+https://github.com/gfx-rs/gfx?rev=00285817af676e091ac886b927e9e5e292f22a03#00285817af676e091ac886b927e9e5e292f22a03" +source = "git+https://github.com/gfx-rs/gfx?rev=2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8#2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" dependencies = [ "bitflags", "naga", @@ -706,9 +706,9 @@ dependencies = [ [[package]] name = "inplace_it" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd01a2a73f2f399df96b22dc88ea687ef4d76226284e7531ae3c7ee1dc5cb534" +checksum = "90953f308a79fe6d62a4643e51f848fbfddcd05975a38e69fdf4ab86a7baf7ca" [[package]] name = "instant" @@ -935,7 +935,7 @@ dependencies = [ [[package]] name = "naga" version = "0.2.0" -source = "git+https://github.com/gfx-rs/naga?tag=gfx-7#0ea8a0a3c2ce1211511d763915fcc511408240c0" +source = "git+https://github.com/gfx-rs/naga?tag=gfx-8#4a13ce022b666a4896ba1dbcbd82121e8b06ad3e" dependencies = [ "bit-set", "bitflags", @@ -1201,7 +1201,7 @@ dependencies = [ [[package]] name = "range-alloc" version = "0.1.1" -source = "git+https://github.com/gfx-rs/gfx?rev=00285817af676e091ac886b927e9e5e292f22a03#00285817af676e091ac886b927e9e5e292f22a03" +source = "git+https://github.com/gfx-rs/gfx?rev=2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8#2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" [[package]] name = "raw-window-handle" diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index cfa1ffea49..453d779c68 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -36,28 +36,28 @@ thiserror = "1" gpu-alloc = { version = "0.3", features = ["tracing"] } gpu-descriptor = { version = "0.1", features = ["tracing"] } -hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "00285817af676e091ac886b927e9e5e292f22a03" } -gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "00285817af676e091ac886b927e9e5e292f22a03" } +hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" } +gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" } [target.'cfg(all(not(target_arch = "wasm32"), all(unix, not(target_os = "ios"), not(target_os = "macos"))))'.dependencies] -gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "00285817af676e091ac886b927e9e5e292f22a03", features = ["naga"] } -gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "00285817af676e091ac886b927e9e5e292f22a03", features = ["naga"] } +gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8", features = ["naga"] } +gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8", features = ["naga"] } [target.'cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))'.dependencies] -gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "00285817af676e091ac886b927e9e5e292f22a03", features = ["naga"] } -gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "00285817af676e091ac886b927e9e5e292f22a03", optional = true } +gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8", features = ["naga"] } +gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8", optional = true } [target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies] -gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "00285817af676e091ac886b927e9e5e292f22a03" } -gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "00285817af676e091ac886b927e9e5e292f22a03" } -gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "00285817af676e091ac886b927e9e5e292f22a03", features = ["naga"] } +gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" } +gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8" } +gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8", features = ["naga"] } [target.'cfg(target_arch = "wasm32")'.dependencies] -gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "00285817af676e091ac886b927e9e5e292f22a03", features = ["naga"] } +gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "2fd74dbe1562a3eef05b11dcd300c1c9c9bc12a8", features = ["naga"] } [dependencies.naga] git = "https://github.com/gfx-rs/naga" -tag = "gfx-7" +tag = "gfx-8" features = ["spv-in", "spv-out", "wgsl-in"] [dependencies.wgt] diff --git a/wgpu-core/src/command/allocator.rs b/wgpu-core/src/command/allocator.rs index df30faa6a8..f00c5d9eda 100644 --- a/wgpu-core/src/command/allocator.rs +++ b/wgpu-core/src/command/allocator.rs @@ -62,6 +62,13 @@ impl CommandPool { } self.available.pop().unwrap() } + + fn destroy(mut self, device: &B::Device) { + unsafe { + self.raw.free(self.available.into_iter()); + device.destroy_command_pool(self.raw); + } + } } #[derive(Debug)] @@ -237,11 +244,8 @@ impl CommandAllocator { } for thread_id in remove_threads { tracing::info!("Removing from thread {:?}", thread_id); - let mut pool = inner.pools.remove(&thread_id).unwrap(); - unsafe { - pool.raw.free(pool.available); - device.destroy_command_pool(pool.raw); - } + let pool = inner.pools.remove(&thread_id).unwrap(); + pool.destroy(device); } } @@ -258,10 +262,7 @@ impl CommandAllocator { pool.total ); } - unsafe { - pool.raw.free(pool.available); - device.destroy_command_pool(pool.raw); - } + pool.destroy(device); } } } diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index f137bb86ba..a1399f8e75 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -15,10 +15,9 @@ use crate::{ span, track::{TrackerSet, UsageConflict}, validation::{check_buffer_usage, MissingBufferUsageError}, - Label, MAX_BIND_GROUPS, + Label, }; -use arrayvec::ArrayVec; use hal::command::CommandBuffer as _; use thiserror::Error; use wgt::{BufferAddress, BufferUsage, ShaderStage}; @@ -330,13 +329,11 @@ impl Global { bind_group, &temp_offsets, ) { - let bind_groups = iter::once(bind_group.raw.raw()) - .chain( - follow_ups - .clone() - .map(|(bg_id, _)| bind_group_guard[bg_id].raw.raw()), - ) - .collect::>(); + let bind_groups = iter::once(bind_group.raw.raw()).chain( + follow_ups + .clone() + .map(|(bg_id, _)| bind_group_guard[bg_id].raw.raw()), + ); temp_offsets.extend(follow_ups.flat_map(|(_, offsets)| offsets)); unsafe { raw.bind_compute_descriptor_sets( diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index c9ff83af15..bf3ff2e3b9 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -24,7 +24,7 @@ use crate::{ validation::{ check_buffer_usage, check_texture_usage, MissingBufferUsageError, MissingTextureUsageError, }, - Label, Stored, MAX_BIND_GROUPS, + Label, Stored, }; use arrayvec::ArrayVec; @@ -802,11 +802,7 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> { inputs: &[], preserves: &[], }; - let all = entry - .key() - .all() - .map(|(at, _)| at.clone()) - .collect::>(); + let all = entry.key().all().map(|(at, _)| at.clone()); let pass = unsafe { device @@ -1127,13 +1123,11 @@ impl Global { bind_group, &temp_offsets, ) { - let bind_groups = iter::once(bind_group.raw.raw()) - .chain( - follow_ups - .clone() - .map(|(bg_id, _)| bind_group_guard[bg_id].raw.raw()), - ) - .collect::>(); + let bind_groups = iter::once(bind_group.raw.raw()).chain( + follow_ups + .clone() + .map(|(bg_id, _)| bind_group_guard[bg_id].raw.raw()), + ); temp_offsets.extend(follow_ups.flat_map(|(_, offsets)| offsets)); unsafe { raw.bind_graphics_descriptor_sets( diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index a226c9ef15..e19fcd3a87 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -319,9 +319,6 @@ impl Global { let (mut cmd_buf_guard, mut token) = hub.command_buffers.write(&mut token); let cmd_buf = CommandBuffer::get_encoder_mut(&mut *cmd_buf_guard, command_encoder_id)?; let (buffer_guard, _) = hub.buffers.read(&mut token); - // we can't hold both src_pending and dst_pending in scope because they - // borrow the buffer tracker mutably... - let mut barriers = Vec::new(); #[cfg(feature = "trace")] if let Some(ref mut list) = cmd_buf.commands { @@ -346,7 +343,10 @@ impl Global { if !src_buffer.usage.contains(BufferUsage::COPY_SRC) { Err(TransferError::MissingCopySrcUsageFlag)? } - barriers.extend(src_pending.map(|pending| pending.into_hal(src_buffer))); + // expecting only a single barrier + let src_barrier = src_pending + .map(|pending| pending.into_hal(src_buffer)) + .next(); let (dst_buffer, dst_pending) = cmd_buf .trackers @@ -363,7 +363,9 @@ impl Global { None, ))? } - barriers.extend(dst_pending.map(|pending| pending.into_hal(dst_buffer))); + let dst_barrier = dst_pending + .map(|pending| pending.into_hal(dst_buffer)) + .next(); if size % wgt::COPY_BUFFER_ALIGNMENT != 0 { Err(TransferError::UnalignedCopySize(size))? @@ -409,7 +411,7 @@ impl Global { cmd_buf_raw.pipeline_barrier( all_buffer_stages()..hal::pso::PipelineStage::TRANSFER, hal::memory::Dependencies::empty(), - barriers, + src_barrier.into_iter().chain(dst_barrier), ); cmd_buf_raw.copy_buffer(src_raw, dst_raw, iter::once(region)); } @@ -713,9 +715,6 @@ impl Global { let cmd_buf = CommandBuffer::get_encoder_mut(&mut *cmd_buf_guard, command_encoder_id)?; let (_, mut token) = hub.buffers.read(&mut token); // skip token let (texture_guard, _) = hub.textures.read(&mut token); - // we can't hold both src_pending and dst_pending in scope because they - // borrow the buffer tracker mutably... - let mut barriers = Vec::new(); let (src_layers, src_selector, src_offset) = texture_copy_view_to_hal(source, copy_size, &*texture_guard)?; let (dst_layers, dst_selector, dst_offset) = @@ -755,7 +754,11 @@ impl Global { if !src_texture.usage.contains(TextureUsage::COPY_SRC) { Err(TransferError::MissingCopySrcUsageFlag)? } - barriers.extend(src_pending.map(|pending| pending.into_hal(src_texture))); + //TODO: try to avoid this the collection. It's needed because both + // `src_pending` and `dst_pending` try to hold `trackers.textures` mutably. + let mut barriers = src_pending + .map(|pending| pending.into_hal(src_texture)) + .collect::>(); let (dst_texture, dst_pending) = cmd_buf .trackers @@ -822,7 +825,7 @@ impl Global { cmd_buf_raw.pipeline_barrier( all_image_stages()..hal::pso::PipelineStage::TRANSFER, hal::memory::Dependencies::empty(), - barriers, + barriers.into_iter(), ); cmd_buf_raw.copy_image( src_raw, diff --git a/wgpu-core/src/device/descriptor.rs b/wgpu-core/src/device/descriptor.rs index 3b350233eb..3f21a44d8b 100644 --- a/wgpu-core/src/device/descriptor.rs +++ b/wgpu-core/src/device/descriptor.rs @@ -121,7 +121,7 @@ impl match hal::device::Device::create_descriptor_pool( self.0, max_sets as usize, - ranges, + ranges.into_iter(), hal::pso::DescriptorPoolCreateFlags::from_bits_truncate(flags.bits()), ) { Ok(pool) => Ok(pool), diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 0103a76b01..1a2fcc733c 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1066,10 +1066,7 @@ impl Device { resolves: &[], preserves: &[], }; - let all = key - .all() - .map(|(at, _)| at.clone()) - .collect::>(); + let all = key.all().map(|(at, _)| at.clone()); unsafe { self.raw @@ -1169,7 +1166,7 @@ impl Device { let raw = unsafe { let mut raw_layout = self .raw - .create_descriptor_set_layout(raw_bindings, &[]) + .create_descriptor_set_layout(raw_bindings, iter::empty()) .or(Err(DeviceError::OutOfMemory))?; if let Some(label) = label { self.raw @@ -1526,10 +1523,7 @@ impl Device { } if let Some(start_binding) = write_map.keys().next().cloned() { - let descriptors = write_map - .into_iter() - .flat_map(|(_, list)| list) - .collect::>(); + let descriptors = write_map.into_iter().flat_map(|(_, list)| list); unsafe { let write = hal::pso::DescriptorSetWrite { set: desc_set.raw_mut(), diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index d51ed3f555..dbc53f28a4 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -619,14 +619,11 @@ impl Global { .raw .create_fence(false) .or(Err(DeviceError::OutOfMemory))?; - let mut command_buffers = pending_write_command_buffer - .as_ref() - .into_iter() - .collect::>(); - for &cmd_buf_id in command_buffer_ids { - let cmd_buf = command_buffer_guard.get(cmd_buf_id).unwrap(); - command_buffers.extend(cmd_buf.raw.iter()); - } + let command_buffers = pending_write_command_buffer.as_ref().into_iter().chain( + command_buffer_ids.iter().flat_map(|&cmd_buf_id| { + command_buffer_guard.get(cmd_buf_id).unwrap().raw.iter() + }), + ); let signal_semaphores = signal_swapchain_semaphores .into_iter() .map(|sc_id| &swap_chain_guard[sc_id].semaphore);