Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various fixes for wgpu #3

Merged
merged 4 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 6 additions & 8 deletions gfx-descriptor/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ pub struct DescriptorSet<B: Backend> {
counts: DescriptorCounts,
}

impl<B: Backend> std::ops::Deref for DescriptorSet<B> {
type Target = B::DescriptorSet;

fn deref(&self) -> &B::DescriptorSet {
impl<B: Backend> DescriptorSet<B> {
pub fn raw(&self) -> &B::DescriptorSet {
&self.raw
}
}
Expand Down Expand Up @@ -246,9 +244,9 @@ impl<B: Backend> DescriptorAllocator<B> {
}
}

/// 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);
}
Expand All @@ -264,7 +262,7 @@ impl<B: Backend> DescriptorAllocator<B> {
&mut self,
device: &B::Device,
layout: &B::DescriptorSetLayout,
layout_counts: DescriptorCounts,
layout_counts: &DescriptorCounts,
count: u32,
extend: &mut impl Extend<DescriptorSet<B>>,
) -> Result<(), OutOfMemory> {
Expand All @@ -283,7 +281,7 @@ impl<B: Backend> DescriptorAllocator<B> {
.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
Expand Down
4 changes: 2 additions & 2 deletions gfx-descriptor/src/counts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = DescriptorRangeDesc> {
self.counts
.iter()
.enumerate()
.filter(|&(_, count)| *count != 0)
.map(|(index, count)| DescriptorRangeDesc {
count: *count as usize,
ty: DESCRIPTOR_TYPES[index],
Expand Down
2 changes: 0 additions & 2 deletions gfx-memory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ categories = ["rendering"]
description = "fx-hal memory allocator"

[features]
serde = ["serde_", "hal/serde"]

[dependencies]
colorful = { version = "0.2", optional = true }
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]
Expand Down
2 changes: 0 additions & 2 deletions gfx-memory/src/allocator/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ impl<B: Backend> Block<B> for GeneralBlock<B> {

/// 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,
Expand Down Expand Up @@ -481,7 +480,6 @@ impl<B: Backend> Allocator<B> for GeneralAllocator<B> {
size: Size,
align: Size,
) -> Result<(GeneralBlock<B>, 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 {
Expand Down
6 changes: 3 additions & 3 deletions gfx-memory/src/allocator/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ impl<B: Backend> Block<B> for LinearBlock<B> {

/// 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.
Expand Down Expand Up @@ -167,7 +166,7 @@ impl<B: Backend> LinearAllocator<B> {
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.");
}
}
}
Expand Down Expand Up @@ -213,8 +212,8 @@ impl<B: Backend> Allocator<B> for LinearAllocator<B> {
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,
Expand Down Expand Up @@ -260,6 +259,7 @@ impl<B: Backend> Allocator<B> for LinearAllocator<B> {
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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion gfx-memory/src/heaps/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ impl<B: hal::Backend> Heaps<B> {
/// 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
Expand Down
15 changes: 15 additions & 0 deletions gfx-memory/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ pub struct Writer<'a, 'b, T, B: Backend> {
flush: Option<Flush<'b, B>>,
}

impl<T, B: Backend> 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<hal::memory::Segment>) {
(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() {
Expand Down Expand Up @@ -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.
///
Expand Down