diff --git a/.travis.yml b/.travis.yml index 0b87d35..d851b11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,31 @@ language: rust -rust: - - nightly - - stable -os: - - windows - - linux - - osx + +matrix: + include: + # Linux 64bit + - os: linux + rust: stable + env: + - BUILD_COMMAND=clippy + - os: linux + rust: nightly + env: + - BUILD_COMMAND=check + # Windows 64bit + - os: windows + rust: stable + env: + - BUILD_COMMAND=clippy + # macOS 64bit + - os: osx + rust: stable + env: + - BUILD_COMMAND=clippy + +before_script: + - if [[ $BUILD_COMMAND == "clippy" ]]; then rustup component add clippy; fi script: - - cargo check - - cargo check --all-features + - cargo $BUILD_COMMAND + - if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then cargo check --all-features; fi - cargo test diff --git a/gfx-descriptor/src/allocator.rs b/gfx-descriptor/src/allocator.rs index a8d35f2..8f9dc65 100644 --- a/gfx-descriptor/src/allocator.rs +++ b/gfx-descriptor/src/allocator.rs @@ -24,10 +24,8 @@ pub struct DescriptorSet { counts: DescriptorCounts, } -impl std::ops::Deref for DescriptorSet { - type Target = B::DescriptorSet; - - fn deref(&self) -> &B::DescriptorSet { +impl DescriptorSet { + pub fn raw(&self) -> &B::DescriptorSet { &self.raw } } @@ -246,9 +244,9 @@ impl DescriptorAllocator { } } - /// Destroy allocator instance. + /// Clear the allocator instance. /// All sets allocated from this allocator become invalid. - pub unsafe fn dispose(mut self, device: &B::Device) { + pub unsafe fn clear(&mut self, device: &B::Device) { for (_, bucket) in self.buckets.drain() { bucket.dispose(device); } @@ -264,7 +262,7 @@ impl DescriptorAllocator { &mut self, device: &B::Device, layout: &B::DescriptorSetLayout, - layout_counts: DescriptorCounts, + layout_counts: &DescriptorCounts, count: u32, extend: &mut impl Extend>, ) -> Result<(), OutOfMemory> { @@ -283,7 +281,7 @@ impl DescriptorAllocator { .buckets .entry(layout_counts.clone()) .or_insert_with(DescriptorBucket::new); - match bucket.allocate(device, layout, &layout_counts, count, &mut self.allocation) { + match bucket.allocate(device, layout, layout_counts, count, &mut self.allocation) { Ok(()) => { extend.extend( self.allocation.pools diff --git a/gfx-descriptor/src/counts.rs b/gfx-descriptor/src/counts.rs index 6e16a85..4d2a609 100644 --- a/gfx-descriptor/src/counts.rs +++ b/gfx-descriptor/src/counts.rs @@ -172,12 +172,12 @@ impl DescriptorCounts { self.counts[descriptor_type_index(&binding.ty)] += binding.count as u32; } - /// Iterate through ranges yelding - /// descriptor types and their amount. + /// Iterate through counts yelding descriptor types and their amount. pub fn iter(&self) -> impl '_ + Iterator { self.counts .iter() .enumerate() + .filter(|&(_, count)| *count != 0) .map(|(index, count)| DescriptorRangeDesc { count: *count as usize, ty: DESCRIPTOR_TYPES[index], diff --git a/gfx-memory/Cargo.toml b/gfx-memory/Cargo.toml index 1e3c1c9..70eb8ff 100644 --- a/gfx-memory/Cargo.toml +++ b/gfx-memory/Cargo.toml @@ -14,7 +14,6 @@ categories = ["rendering"] description = "fx-hal memory allocator" [features] -serde = ["serde_", "hal/serde"] [dependencies] colorful = { version = "0.2", optional = true } @@ -22,7 +21,6 @@ fxhash = "0.2" hal = { package = "gfx-hal", version = "0.5" } hibitset = {version = "0.6", default-features = false} log = "0.4" -serde_ = { package = "serde", version = "1", features = ["derive"], optional = true } slab = "0.4" [dev-dependencies] diff --git a/gfx-memory/src/allocator/general.rs b/gfx-memory/src/allocator/general.rs index 0add3b6..66329da 100644 --- a/gfx-memory/src/allocator/general.rs +++ b/gfx-memory/src/allocator/general.rs @@ -86,7 +86,6 @@ impl Block for GeneralBlock { /// Config for `GeneralAllocator`. #[derive(Clone, Copy, Debug)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct GeneralConfig { /// All requests are rounded up to multiple of this value. pub block_size_granularity: Size, @@ -481,7 +480,6 @@ impl Allocator for GeneralAllocator { size: Size, align: Size, ) -> Result<(GeneralBlock, Size), hal::device::AllocationError> { - debug_assert!(size <= self.max_allocation()); debug_assert!(align.is_power_of_two()); let aligned_size = ((size - 1) | (align - 1) | (self.block_size_granularity - 1)) + 1; let map_aligned_size = match self.non_coherent_atom_size { diff --git a/gfx-memory/src/allocator/linear.rs b/gfx-memory/src/allocator/linear.rs index c65d9d8..39f7ea7 100644 --- a/gfx-memory/src/allocator/linear.rs +++ b/gfx-memory/src/allocator/linear.rs @@ -72,7 +72,6 @@ impl Block for LinearBlock { /// Config for `LinearAllocator`. #[derive(Clone, Copy, Debug)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct LinearConfig { /// Size of the linear chunk. /// Keep it big. @@ -167,7 +166,7 @@ impl LinearAllocator { device.free_memory(mem.into_raw()); }, Err(_) => { - log::error!("Allocated `Line` was freed, but memory is still shared and never will be destroyed"); + log::error!("Allocated `Line` was freed, but memory is still shared and never will be destroyed."); } } } @@ -213,8 +212,8 @@ impl Allocator for LinearAllocator { let aligned_offset = crate::align_offset(line.used, unsafe { AtomSize::new_unchecked(align) }); if aligned_offset + size <= self.linear_size { - line.used = aligned_offset + size; line.free += aligned_offset - line.used; + line.used = aligned_offset + size; let block = LinearBlock { linear_index: self.offset + count - 1, @@ -260,6 +259,7 @@ impl Allocator for LinearAllocator { fn free(&mut self, device: &B::Device, block: Self::Block) -> Size { let index = (block.linear_index - self.offset) as usize; self.lines[index].free += block.size(); + drop(block); self.cleanup(device, 1) } } diff --git a/gfx-memory/src/heaps/mod.rs b/gfx-memory/src/heaps/mod.rs index 90cee81..6f36ba1 100644 --- a/gfx-memory/src/heaps/mod.rs +++ b/gfx-memory/src/heaps/mod.rs @@ -63,9 +63,9 @@ impl Heaps { /// Initialize the new `Heaps` object. pub unsafe fn new( hal_memory_properties: &hal::adapter::MemoryProperties, - non_coherent_atom_size: Size, config_general: GeneralConfig, config_linear: LinearConfig, + non_coherent_atom_size: Size, ) -> Self { Heaps { types: hal_memory_properties.memory_types diff --git a/gfx-memory/src/mapping.rs b/gfx-memory/src/mapping.rs index 7c4f8f0..3648fdf 100644 --- a/gfx-memory/src/mapping.rs +++ b/gfx-memory/src/mapping.rs @@ -20,6 +20,16 @@ pub struct Writer<'a, 'b, T, B: Backend> { flush: Option>, } +impl Writer<'_, '_, T, B> { + /// Dispose of the wrapper and return a bare mapping pointer. + /// + /// The segment to flush is returned. The user is responsible + /// to flush this segment manually. + pub fn forget(mut self) -> (*mut T, Option) { + (self.slice.as_mut_ptr(), self.flush.take().map(|f| f.segment)) + } +} + impl<'a, 'b, T, B: Backend> Drop for Writer<'a, 'b, T, B> { fn drop(&mut self) { if let Some(f) = self.flush.take() { @@ -111,6 +121,11 @@ impl<'a, B: Backend> MappedRange<'a, B> { self.requested_range.clone() } + /// Return true if the mapped memory is coherent. + pub fn is_coherent(&self) -> bool { + self.memory.non_coherent_atom_size.is_none() + } + /// Fetch readable slice of sub-range to be read. /// Invalidating range if memory is not coherent. ///