diff --git a/Cargo.lock b/Cargo.lock index 2da1f7999..bb6e2b824 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=477f17957a54d024f0077584b68e308376cb05c6#477f17957a54d024f0077584b68e308376cb05c6" +source = "git+https://github.com/gfx-rs/gfx?rev=59730cdeefdb00c61ba747dbcaa2087e7a5b53f6#59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" 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=477f17957a54d024f0077584b68e308376cb05c6#477f17957a54d024f0077584b68e308376cb05c6" +source = "git+https://github.com/gfx-rs/gfx?rev=59730cdeefdb00c61ba747dbcaa2087e7a5b53f6#59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" 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=477f17957a54d024f0077584b68e308376cb05c6#477f17957a54d024f0077584b68e308376cb05c6" +source = "git+https://github.com/gfx-rs/gfx?rev=59730cdeefdb00c61ba747dbcaa2087e7a5b53f6#59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" 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=477f17957a54d024f0077584b68e308376cb05c6#477f17957a54d024f0077584b68e308376cb05c6" +source = "git+https://github.com/gfx-rs/gfx?rev=59730cdeefdb00c61ba747dbcaa2087e7a5b53f6#59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" 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=477f17957a54d024f0077584b68e308376cb05c6#477f17957a54d024f0077584b68e308376cb05c6" +source = "git+https://github.com/gfx-rs/gfx?rev=59730cdeefdb00c61ba747dbcaa2087e7a5b53f6#59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" 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=477f17957a54d024f0077584b68e308376cb05c6#477f17957a54d024f0077584b68e308376cb05c6" +source = "git+https://github.com/gfx-rs/gfx?rev=59730cdeefdb00c61ba747dbcaa2087e7a5b53f6#59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" 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=477f17957a54d024f0077584b68e308376cb05c6#477f17957a54d024f0077584b68e308376cb05c6" +source = "git+https://github.com/gfx-rs/gfx?rev=59730cdeefdb00c61ba747dbcaa2087e7a5b53f6#59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" 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=477f17957a54d024f0077584b68e308376cb05c6#477f17957a54d024f0077584b68e308376cb05c6" +source = "git+https://github.com/gfx-rs/gfx?rev=59730cdeefdb00c61ba747dbcaa2087e7a5b53f6#59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" dependencies = [ "bitflags", "naga", @@ -626,7 +626,7 @@ dependencies = [ [[package]] name = "gpu-alloc" version = "0.2.1" -source = "git+https://github.com/zakarumych/gpu-alloc?rev=15f4fe2cebbd0bf9ab446757a8e370e0adf4c502#15f4fe2cebbd0bf9ab446757a8e370e0adf4c502" +source = "git+https://github.com/zakarumych/gpu-alloc?rev=915d0dad0db340a4d37d5abd597b8b796e7f35f6#915d0dad0db340a4d37d5abd597b8b796e7f35f6" dependencies = [ "bitflags", "gpu-alloc-types", @@ -636,7 +636,7 @@ dependencies = [ [[package]] name = "gpu-alloc-types" version = "0.1.0" -source = "git+https://github.com/zakarumych/gpu-alloc?rev=15f4fe2cebbd0bf9ab446757a8e370e0adf4c502#15f4fe2cebbd0bf9ab446757a8e370e0adf4c502" +source = "git+https://github.com/zakarumych/gpu-alloc?rev=915d0dad0db340a4d37d5abd597b8b796e7f35f6#915d0dad0db340a4d37d5abd597b8b796e7f35f6" dependencies = [ "bitflags", ] @@ -1196,7 +1196,7 @@ dependencies = [ [[package]] name = "range-alloc" version = "0.1.1" -source = "git+https://github.com/gfx-rs/gfx?rev=477f17957a54d024f0077584b68e308376cb05c6#477f17957a54d024f0077584b68e308376cb05c6" +source = "git+https://github.com/gfx-rs/gfx?rev=59730cdeefdb00c61ba747dbcaa2087e7a5b53f6#59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" [[package]] name = "raw-window-handle" diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 80bc87983..1e82eaaad 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -33,27 +33,27 @@ smallvec = "1" tracing = { version = "0.1", default-features = false, features = ["std"] } thiserror = "1" -gpu-alloc = { git = "https://github.com/zakarumych/gpu-alloc", rev = "15f4fe2cebbd0bf9ab446757a8e370e0adf4c502", features = ["tracing"] } +gpu-alloc = { git = "https://github.com/zakarumych/gpu-alloc", rev = "915d0dad0db340a4d37d5abd597b8b796e7f35f6", features = ["tracing"] } gpu-descriptor = { git = "https://github.com/zakarumych/gpu-descriptor", rev = "aa092613889f03f8254d6f7278d08c655324c7c7", features = ["tracing"] } -hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "477f17957a54d024f0077584b68e308376cb05c6" } -gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "477f17957a54d024f0077584b68e308376cb05c6" } +hal = { package = "gfx-hal", git = "https://github.com/gfx-rs/gfx", rev = "59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" } +gfx-backend-empty = { git = "https://github.com/gfx-rs/gfx", rev = "59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" } [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 = "477f17957a54d024f0077584b68e308376cb05c6", features = ["naga"] } -gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "477f17957a54d024f0077584b68e308376cb05c6", features = ["naga"] } +gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "59730cdeefdb00c61ba747dbcaa2087e7a5b53f6", features = ["naga"] } +gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "59730cdeefdb00c61ba747dbcaa2087e7a5b53f6", 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 = "477f17957a54d024f0077584b68e308376cb05c6", features = ["naga"] } -gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "477f17957a54d024f0077584b68e308376cb05c6", optional = true } +gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx", rev = "59730cdeefdb00c61ba747dbcaa2087e7a5b53f6", features = ["naga"] } +gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "59730cdeefdb00c61ba747dbcaa2087e7a5b53f6", optional = true } [target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies] -gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "477f17957a54d024f0077584b68e308376cb05c6" } -gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "477f17957a54d024f0077584b68e308376cb05c6" } -gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "477f17957a54d024f0077584b68e308376cb05c6", features = ["naga"] } +gfx-backend-dx12 = { git = "https://github.com/gfx-rs/gfx", rev = "59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" } +gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx", rev = "59730cdeefdb00c61ba747dbcaa2087e7a5b53f6" } +gfx-backend-vulkan = { git = "https://github.com/gfx-rs/gfx", rev = "59730cdeefdb00c61ba747dbcaa2087e7a5b53f6", features = ["naga"] } [target.'cfg(target_arch = "wasm32")'.dependencies] -gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "477f17957a54d024f0077584b68e308376cb05c6", features = ["naga"] } +gfx-backend-gl = { git = "https://github.com/gfx-rs/gfx", rev = "59730cdeefdb00c61ba747dbcaa2087e7a5b53f6", features = ["naga"] } [dependencies.naga] git = "https://github.com/gfx-rs/naga" diff --git a/wgpu-core/src/device/alloc.rs b/wgpu-core/src/device/alloc.rs index de5434ab4..826c2a23a 100644 --- a/wgpu-core/src/device/alloc.rs +++ b/wgpu-core/src/device/alloc.rs @@ -3,22 +3,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use super::DeviceError; -use hal::device::Device; -use parking_lot::Mutex; -use std::{borrow::Cow, fmt, iter, ptr::NonNull, sync::Arc}; +use hal::device::Device as _; +use std::{borrow::Cow, iter, ptr::NonNull}; -pub struct MemoryAllocator(gpu_alloc::GpuAllocator>>); #[derive(Debug)] -pub struct MemoryBlock(gpu_alloc::MemoryBlock>>); +pub struct MemoryAllocator(gpu_alloc::GpuAllocator); +#[derive(Debug)] +pub struct MemoryBlock(gpu_alloc::MemoryBlock); struct MemoryDevice<'a, B: hal::Backend>(&'a B::Device); -//TODO: https://github.com/zakarumych/gpu-alloc/issues/9 -impl fmt::Debug for MemoryAllocator { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "MemoryAllocator") - } -} - impl MemoryAllocator { pub fn new(mem_props: hal::adapter::MemoryProperties, limits: hal::Limits) -> Self { let mem_config = gpu_alloc::Config { @@ -100,19 +93,19 @@ impl MemoryBlock { device: &B::Device, buffer: &mut B::Buffer, ) -> Result<(), DeviceError> { + let mem = self.0.memory(); unsafe { - let mem = self.0.memory().lock(); device - .bind_buffer_memory(&*mem, self.0.offset(), buffer) + .bind_buffer_memory(mem, self.0.offset(), buffer) .map_err(DeviceError::from_bind) } } pub fn bind_image(&self, device: &B::Device, image: &mut B::Image) -> Result<(), DeviceError> { + let mem = self.0.memory(); unsafe { - let mem = self.0.memory().lock(); device - .bind_image_memory(&*mem, self.0.offset(), image) + .bind_image_memory(mem, self.0.offset(), image) .map_err(DeviceError::from_bind) } } @@ -187,10 +180,10 @@ impl MemoryBlock { size: Option, ) -> Result<(), DeviceError> { let segment = self.segment(inner_offset, size); + let mem = self.0.memory(); unsafe { - let mem = self.0.memory().lock(); device - .flush_mapped_memory_ranges(iter::once((&*mem, segment))) + .flush_mapped_memory_ranges(iter::once((mem, segment))) .or(Err(DeviceError::OutOfMemory)) } } @@ -202,47 +195,44 @@ impl MemoryBlock { size: Option, ) -> Result<(), DeviceError> { let segment = self.segment(inner_offset, size); + let mem = self.0.memory(); unsafe { - let mem = self.0.memory().lock(); device - .invalidate_mapped_memory_ranges(iter::once((&*mem, segment))) + .invalidate_mapped_memory_ranges(iter::once((mem, segment))) .or(Err(DeviceError::OutOfMemory)) } } } -impl gpu_alloc::MemoryDevice>> for MemoryDevice<'_, B> { +impl gpu_alloc::MemoryDevice for MemoryDevice<'_, B> { #[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))] unsafe fn allocate_memory( &self, size: u64, memory_type: u32, flags: gpu_alloc::AllocationFlags, - ) -> Result>, gpu_alloc::OutOfMemory> { + ) -> Result { assert!(flags.is_empty()); self.0 .allocate_memory(hal::MemoryTypeId(memory_type as _), size) - .map(|m| Arc::new(Mutex::new(m))) .map_err(|_| gpu_alloc::OutOfMemory::OutOfDeviceMemory) } #[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))] - unsafe fn deallocate_memory(&self, memory: Arc>) { - let memory = Arc::try_unwrap(memory).expect("Memory must not be used anywhere"); - self.0.free_memory(memory.into_inner()); + unsafe fn deallocate_memory(&self, memory: B::Memory) { + self.0.free_memory(memory); } #[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))] unsafe fn map_memory( &self, - memory: &Arc>, + memory: &mut B::Memory, offset: u64, size: u64, ) -> Result, gpu_alloc::DeviceMapError> { - let mut mem = memory.lock(); match self.0.map_memory( - &mut *mem, + memory, hal::memory::Segment { offset, size: Some(size), @@ -258,24 +248,22 @@ impl gpu_alloc::MemoryDevice>> for MemoryD } #[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))] - unsafe fn unmap_memory(&self, memory: &Arc>) { - let mut mem = memory.lock(); - self.0.unmap_memory(&mut *mem); + unsafe fn unmap_memory(&self, memory: &mut B::Memory) { + self.0.unmap_memory(memory); } #[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))] unsafe fn invalidate_memory_ranges( &self, - ranges: &[gpu_alloc::MappedMemoryRange<'_, Arc>>], + ranges: &[gpu_alloc::MappedMemoryRange<'_, B::Memory>], ) -> Result<(), gpu_alloc::OutOfMemory> { - let rs: Vec<_> = ranges.iter().map(|r| (r.memory.lock(), r)).collect(); self.0 - .invalidate_mapped_memory_ranges(rs.iter().map(|range| { + .invalidate_mapped_memory_ranges(ranges.iter().map(|r| { ( - &*range.0, + r.memory, hal::memory::Segment { - offset: range.1.offset, - size: Some(range.1.size), + offset: r.offset, + size: Some(r.size), }, ) })) @@ -285,16 +273,15 @@ impl gpu_alloc::MemoryDevice>> for MemoryD #[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))] unsafe fn flush_memory_ranges( &self, - ranges: &[gpu_alloc::MappedMemoryRange<'_, Arc>>], + ranges: &[gpu_alloc::MappedMemoryRange<'_, B::Memory>], ) -> Result<(), gpu_alloc::OutOfMemory> { - let rs: Vec<_> = ranges.iter().map(|r| (r.memory.lock(), r)).collect(); self.0 - .flush_mapped_memory_ranges(rs.iter().map(|range| { + .flush_mapped_memory_ranges(ranges.iter().map(|r| { ( - &*range.0, + r.memory, hal::memory::Segment { - offset: range.1.offset, - size: Some(range.1.size), + offset: r.offset, + size: Some(r.size), }, ) }))