Skip to content

Commit

Permalink
Revert "Revert "Updated to work with latest gfx""
Browse files Browse the repository at this point in the history
This reverts commit 782d3ea.
  • Loading branch information
chemicstry committed Mar 30, 2020
1 parent 782d3ea commit 45f8c7c
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 25 deletions.
5 changes: 3 additions & 2 deletions command/src/buffer/encoder.rs
Expand Up @@ -102,11 +102,12 @@ where
C: Supports<Graphics>,
{
self.capability.assert();
let range = rendy_core::hal::buffer::SubRange { offset, size: None };
rendy_core::hal::command::CommandBuffer::bind_index_buffer(
self.raw,
rendy_core::hal::buffer::IndexBufferView {
buffer: buffer,
offset,
range,
index_type,
},
)
Expand All @@ -129,7 +130,7 @@ where
pub unsafe fn bind_vertex_buffers<'b>(
&mut self,
first_binding: u32,
buffers: impl IntoIterator<Item = (&'b B::Buffer, u64)>,
buffers: impl IntoIterator<Item = (&'b B::Buffer, rendy_core::hal::buffer::SubRange)>,
) where
C: Supports<Graphics>,
{
Expand Down
3 changes: 2 additions & 1 deletion command/src/pool.rs
Expand Up @@ -77,7 +77,8 @@ where
{
let level = L::default();

let buffers = unsafe { self.raw.allocate_vec(count, level.raw_level()) };
let mut buffers = Vec::with_capacity(count);
unsafe { self.raw.allocate(count, level.raw_level(), &mut buffers) };

buffers
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion descriptor/src/allocator.rs
Expand Up @@ -75,7 +75,7 @@ unsafe fn allocate_from_pool<B: Backend>(
allocation: &mut SmallVec<[B::DescriptorSet; 1]>,
) -> Result<(), OutOfMemory> {
let sets_were = allocation.len();
raw.allocate_sets(std::iter::repeat(layout).take(count as usize), allocation)
raw.allocate(std::iter::repeat(layout).take(count as usize), allocation)
.map_err(|err| match err {
AllocationError::Host => OutOfMemory::Host,
AllocationError::Device => OutOfMemory::Device,
Expand Down
12 changes: 9 additions & 3 deletions graph/src/node/mod.rs
Expand Up @@ -282,7 +282,7 @@ pub enum NodeBuildError {
/// Mismatched or unsupported queue family.
QueueFamily(FamilyId),
/// Failed to create an imate view.
View(rendy_core::hal::image::ViewError),
View(rendy_core::hal::image::ViewCreationError),
/// Failed to create a pipeline.
Pipeline(rendy_core::hal::pso::CreationError),
/// Failed to create a swap chain.
Expand Down Expand Up @@ -523,7 +523,10 @@ pub fn gfx_acquire_barriers<'a, 'b, B: Backend>(
.get_buffer(buffer.id)
.expect("Buffer does not exist")
.raw(),
range: Some(buffer.range.start)..Some(buffer.range.end),
range: rendy_core::hal::buffer::SubRange {
offset: buffer.range.start,
size: Some(buffer.range.end - buffer.range.start),
},
}
})
})
Expand Down Expand Up @@ -574,7 +577,10 @@ pub fn gfx_release_barriers<'a, B: Backend>(
.get_buffer(buffer.id)
.expect("Buffer does not exist")
.raw(),
range: Some(buffer.range.start)..Some(buffer.range.end),
range: rendy_core::hal::buffer::SubRange {
offset: buffer.range.start,
size: Some(buffer.range.end - buffer.range.start),
},
}
})
})
Expand Down
15 changes: 10 additions & 5 deletions graph/src/node/render/pass.rs
Expand Up @@ -858,7 +858,8 @@ where
framebuffer_width,
framebuffer_height,
rendy_core::hal::pass::Subpass {
index,
index: std::convert::TryInto::try_into(index)
.expect("More than 256 subpasses is unsupported."),
main_pass: &render_pass,
},
buffers,
Expand Down Expand Up @@ -1168,7 +1169,8 @@ where
queue.id(),
index,
rendy_core::hal::pass::Subpass {
index: subpass_index,
index: std::convert::TryInto::try_into(subpass_index)
.expect("More than 256 subpasses is unsupported."),
main_pass: &render_pass,
},
aux,
Expand Down Expand Up @@ -1219,7 +1221,8 @@ where
pass_encoder.reborrow(),
index,
rendy_core::hal::pass::Subpass {
index: subpass_index,
index: std::convert::TryInto::try_into(subpass_index)
.expect("More than 256 subpasses is unsupported."),
main_pass: &render_pass,
},
aux,
Expand Down Expand Up @@ -1350,7 +1353,8 @@ where
queue.id(),
index,
rendy_core::hal::pass::Subpass {
index: subpass_index,
index: std::convert::TryInto::try_into(subpass_index)
.expect("More than 256 subpasses is unsupported."),
main_pass: &render_pass,
},
aux,
Expand Down Expand Up @@ -1392,7 +1396,8 @@ where
pass_encoder.reborrow(),
index,
rendy_core::hal::pass::Subpass {
index: subpass_index,
index: std::convert::TryInto::try_into(subpass_index)
.expect("More than 256 subpasses is unsupported."),
main_pass: &render_pass,
},
aux,
Expand Down
10 changes: 8 additions & 2 deletions memory/src/allocator/dedicated.rs
Expand Up @@ -7,7 +7,7 @@ use {
mapping::{mapped_fitting_range, MappedRange},
memory::*,
},
gfx_hal::{device::Device as _, Backend},
gfx_hal::{device::Device as _, memory::Segment, Backend},
};

/// Memory block allocated from `DedicatedAllocator`
Expand Down Expand Up @@ -83,7 +83,13 @@ where
Ok(MappedRange::from_raw(&self.memory, ptr, range))
} else {
self.unmap(device);
let ptr = device.map_memory(self.memory.raw(), range.clone())?;
let ptr = device.map_memory(
self.memory.raw(),
Segment {
offset: range.start,
size: Some(range.end - range.start),
},
)?;
let ptr = NonNull::new(ptr).expect("Memory mapping shouldn't return nullptr");
let mapping = MappedRange::from_raw(&self.memory, ptr, range);
self.mapping = Some((mapping.ptr(), mapping.range()));
Expand Down
10 changes: 8 additions & 2 deletions memory/src/allocator/dynamic.rs
Expand Up @@ -13,7 +13,7 @@ use {
memory::*,
util::*,
},
gfx_hal::{device::Device as _, Backend},
gfx_hal::{device::Device as _, memory::Segment, Backend},
hibitset::{BitSet, BitSetLike as _},
};

Expand Down Expand Up @@ -258,7 +258,13 @@ where
.contains(gfx_hal::memory::Properties::CPU_VISIBLE)
{
log::trace!("Map new memory object");
match device.map_memory(&raw, 0..chunk_size) {
match device.map_memory(
&raw,
Segment {
offset: 0,
size: Some(chunk_size),
},
) {
Ok(mapping) => Some(NonNull::new_unchecked(mapping)),
Err(gfx_hal::device::MapError::OutOfMemory(error)) => {
device.free_memory(raw);
Expand Down
10 changes: 8 additions & 2 deletions memory/src/allocator/linear.rs
Expand Up @@ -8,7 +8,7 @@ use {
memory::*,
util::*,
},
gfx_hal::{device::Device as _, Backend},
gfx_hal::{device::Device as _, memory::Segment, Backend},
std::sync::Arc,
};

Expand Down Expand Up @@ -267,7 +267,13 @@ where
let (memory, ptr) = unsafe {
let raw = device.allocate_memory(self.memory_type, self.linear_size)?;

let ptr = match device.map_memory(&raw, 0..self.linear_size) {
let ptr = match device.map_memory(
&raw,
Segment {
offset: 0,
size: Some(self.linear_size),
},
) {
Ok(ptr) => NonNull::new_unchecked(ptr),
Err(gfx_hal::device::MapError::OutOfMemory(error)) => {
device.free_memory(raw);
Expand Down
19 changes: 15 additions & 4 deletions memory/src/mapping/mod.rs
Expand Up @@ -3,7 +3,7 @@ pub(crate) mod write;

use {
crate::{memory::Memory, util::fits_usize},
gfx_hal::{device::Device as _, Backend},
gfx_hal::{device::Device as _, memory::Segment, Backend},
std::{ops::Range, ptr::NonNull},
};

Expand Down Expand Up @@ -143,8 +143,13 @@ where
let size = (range.end - range.start) as usize;

if !self.coherent.0 {
device
.invalidate_mapped_memory_ranges(Some((self.memory.raw(), self.range.clone())))?;
device.invalidate_mapped_memory_ranges(Some((
self.memory.raw(),
Segment {
offset: self.range.start,
size: Some(self.range.end - self.range.start),
},
)))?;
}

let slice = mapped_slice::<T>(ptr, size);
Expand Down Expand Up @@ -188,7 +193,13 @@ where
flush: if !self.coherent.0 {
Some(move || {
device
.flush_mapped_memory_ranges(Some((memory.raw(), range)))
.flush_mapped_memory_ranges(Some((
memory.raw(),
Segment {
offset: range.start,
size: Some(range.end - range.start),
},
)))
.expect("Should flush successfully");
})
} else {
Expand Down
12 changes: 10 additions & 2 deletions mesh/src/mesh.rs
Expand Up @@ -383,7 +383,10 @@ where
fn get_vertex_iter<'a>(
&'a self,
formats: &[VertexFormat],
) -> Result<impl IntoIterator<Item = (&'a B::Buffer, u64)>, Incompatible> {
) -> Result<
impl IntoIterator<Item = (&'a B::Buffer, rendy_core::hal::buffer::SubRange)>,
Incompatible,
> {
debug_assert!(is_slice_sorted(formats), "Formats: {:#?}", formats);
debug_assert!(is_slice_sorted_by_key(&self.vertex_layouts, |l| &l.format));

Expand All @@ -408,7 +411,12 @@ where
}

let buffer = self.vertex_buffer.raw();
Ok(vertex.into_iter().map(move |offset| (buffer, offset)))
Ok(vertex.into_iter().map(move |offset| {
(
buffer,
rendy_core::hal::buffer::SubRange { offset, size: None },
)
}))
}

/// Bind buffers to specified attribute locations.
Expand Down
2 changes: 1 addition & 1 deletion resource/src/image.rs
Expand Up @@ -216,7 +216,7 @@ pub struct ImageView<B: Backend> {

device_owned!(ImageView<B> @ |view: &Self| view.image.device_id());
/// Alias for the error to create an image view.
pub type ImageViewCreationError = CreationError<ViewError>;
pub type ImageViewCreationError = CreationError<ViewCreationError>;

impl<B> ImageView<B>
where
Expand Down

0 comments on commit 45f8c7c

Please sign in to comment.