Skip to content

Commit

Permalink
Remove associated Desc from Node
Browse files Browse the repository at this point in the history
  • Loading branch information
Frizi committed Sep 21, 2019
1 parent 480732e commit 4095fe0
Show file tree
Hide file tree
Showing 28 changed files with 182 additions and 196 deletions.
7 changes: 1 addition & 6 deletions command/src/buffer/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,7 @@ where
dependencies: gfx_hal::memory::Dependencies,
barriers: impl IntoIterator<Item = gfx_hal::memory::Barrier<'b, B>>,
) {
gfx_hal::command::CommandBuffer::pipeline_barrier(
self.raw,
stages,
dependencies,
barriers,
)
gfx_hal::command::CommandBuffer::pipeline_barrier(self.raw, stages, dependencies, barriers)
}

/// Push graphics constants.
Expand Down
16 changes: 15 additions & 1 deletion command/src/family/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ where
let pos = queue_groups.iter().position(|qg| qg.family.0 == id.index);
let group = queue_groups.swap_remove(pos.unwrap());
assert_eq!(group.queues.len(), count);
group.queues
group
.queues
.into_iter()
.enumerate()
.map(|(index, queue)| Queue::new(queue, QueueId { family: id, index }))
Expand Down Expand Up @@ -222,6 +223,19 @@ where
pub fn indices(&self) -> &[usize] {
&self.families_indices
}

/// Find family id matching predicate
pub fn find<F>(&self, predicate: F) -> Option<FamilyId>
where
F: FnMut(&&Family<B>) -> bool,
{
self.families.iter().find(predicate).map(Family::id)
}

/// Get first matching family id with specified capability
pub fn with_capability<C: Capability>(&self) -> Option<FamilyId> {
self.find(|family| Supports::<C>::supports(&family.capability()).is_some())
}
}

/// Query queue families from device.
Expand Down
2 changes: 1 addition & 1 deletion command/src/fence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use {
family::QueueId,
util::{device_owned, Device, DeviceId},
},
gfx_hal::{Backend, device::Device as _},
gfx_hal::{device::Device as _, Backend},
};

/// Queue epoch is the point in particluar queue timeline when fence is submitted.
Expand Down
2 changes: 1 addition & 1 deletion command/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use {
crate::{buffer::*, capability::*, family::FamilyId, util::Device},
gfx_hal::{Backend, device::Device as _},
gfx_hal::{device::Device as _, Backend},
};

/// Simple pool wrapper.
Expand Down
3 changes: 1 addition & 2 deletions factory/src/blitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,7 @@ pub unsafe fn blit_image<B, C, L>(
dst_image: &Handle<Image<B>>,
filter: gfx_hal::image::Filter,
regions: impl IntoIterator<Item = BlitRegion>,
)
where
) where
B: gfx_hal::Backend,
C: Supports<Graphics>,
L: Level,
Expand Down
24 changes: 18 additions & 6 deletions factory/src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use {
resource::*,
upload::{BufferState, ImageState, ImageStateOrLayout, Uploader},
util::{rendy_backend_match, rendy_with_slow_safety_checks, Device, DeviceId, Instance},
wsi::{SwapchainError, Surface, Target},
wsi::{Surface, SwapchainError, Target},
},
gfx_hal::{
buffer, format, image,
adapter::{Adapter, Gpu, PhysicalDevice},
buffer,
device::{AllocationError, Device as _, MapError, OomOrDeviceLost, OutOfMemory, WaitFor},
format, image,
pso::DescriptorSetLayoutBinding,
window::{Extent2D, Surface as GfxSurface},
Backend, Features, Limits,
Expand Down Expand Up @@ -804,8 +805,11 @@ where
}

let timeout = !unsafe {
self.device
.wait_for_fences(fences.iter().map(|f| f.raw()), wait_for.clone(), timeout_ns)
self.device.wait_for_fences(
fences.iter().map(|f| f.raw()),
wait_for.clone(),
timeout_ns,
)
}?;

if timeout {
Expand Down Expand Up @@ -1122,14 +1126,22 @@ where

log::debug!("Queues: {:#?}", get_queues);

let Gpu { device, mut queue_groups } = unsafe {
let Gpu {
device,
mut queue_groups,
} = unsafe {
adapter
.physical_device
.open(&create_queues, adapter.physical_device.features())
}?;

let families = unsafe {
families_from_device(device_id, &mut queue_groups, get_queues, &adapter.queue_families)
families_from_device(
device_id,
&mut queue_groups,
get_queues,
&adapter.queue_families,
)
};
(device, families)
};
Expand Down
11 changes: 8 additions & 3 deletions graph/src/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ use {
factory::Factory,
frame::{Fences, Frame, Frames},
memory::Data,
node::{BufferBarrier, DynNode, ImageBarrier, NodeBuffer, NodeBuilder, NodeBuildError, NodeImage},
resource::{Buffer, BufferCreationError, BufferInfo, Handle, Image, ImageCreationError, ImageInfo},
node::{
BufferBarrier, DynNode, ImageBarrier, NodeBuffer, NodeBuildError, NodeBuilder,
NodeImage,
},
resource::{
Buffer, BufferCreationError, BufferInfo, Handle, Image, ImageCreationError, ImageInfo,
},
util::{device_owned, DeviceId},
BufferId, ImageId, NodeId,
},
Expand Down Expand Up @@ -572,7 +577,7 @@ where
let images = builder.images();
chain::Node {
id,
family: QueueFamilyId(builder.family(factory, families.as_slice()).unwrap().index),
family: QueueFamilyId(builder.family(factory, families).unwrap().index),
dependencies: builder.dependencies().into_iter().map(|id| id.0).collect(),
buffers: buffers
.into_iter()
Expand Down
34 changes: 4 additions & 30 deletions graph/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod render;

use {
crate::{
command::{Capability, Family, FamilyId, Fence, Queue, Submission, Submittable, Supports},
command::{Capability, Families, Family, FamilyId, Fence, Queue, Submission, Submittable},
factory::{Factory, UploadError},
frame::Frames,
graph::GraphContext,
Expand Down Expand Up @@ -155,26 +155,6 @@ pub trait Node<B: Backend, T: ?Sized>:
/// Graph will execute this node on command queue that supports this capability level.
type Capability: Capability;

/// Description type to instantiate the node.
type Desc: NodeDesc<B, T, Node = Self>;

/// Desc creation.
/// Convenient method if `Self::Desc` implements `Default`.
fn desc() -> Self::Desc
where
Self::Desc: Default,
{
Default::default()
}

/// Builder creation.
fn builder() -> DescBuilder<B, T, Self::Desc>
where
Self::Desc: Default,
{
Self::desc().builder()
}

/// Record commands required by node.
/// Returned submits are guaranteed to be submitted within specified frame.
fn run<'a>(
Expand Down Expand Up @@ -315,7 +295,7 @@ pub enum NodeBuildError {
/// Dynamic node builder that emits `DynNode`.
pub trait NodeBuilder<B: Backend, T: ?Sized>: std::fmt::Debug {
/// Pick family for this node to be executed onto.
fn family(&self, factory: &mut Factory<B>, families: &[Family<B>]) -> Option<FamilyId>;
fn family(&self, factory: &mut Factory<B>, families: &Families<B>) -> Option<FamilyId>;

/// Get buffer accessed by the node.
fn buffers(&self) -> Vec<(BufferId, BufferAccess)>;
Expand Down Expand Up @@ -414,14 +394,8 @@ where
T: ?Sized,
N: NodeDesc<B, T>,
{
fn family(&self, _factory: &mut Factory<B>, families: &[Family<B>]) -> Option<FamilyId> {
families
.iter()
.find(|family| {
Supports::<<N::Node as Node<B, T>>::Capability>::supports(&family.capability())
.is_some()
})
.map(|family| family.id())
fn family(&self, _factory: &mut Factory<B>, families: &Families<B>) -> Option<FamilyId> {
families.with_capability::<<N::Node as Node<B, T>>::Capability>()
}

fn buffers(&self) -> Vec<(BufferId, BufferAccess)> {
Expand Down
9 changes: 3 additions & 6 deletions graph/src/node/present.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
command::{
CommandBuffer, CommandPool, ExecutableState, Family, FamilyId, Fence, MultiShot,
CommandBuffer, CommandPool, ExecutableState, Families, Family, FamilyId, Fence, MultiShot,
PendingState, Queue, SimultaneousUse, Submission, Submit,
},
factory::Factory,
Expand Down Expand Up @@ -359,12 +359,9 @@ where
B: gfx_hal::Backend,
T: ?Sized,
{
fn family(&self, factory: &mut Factory<B>, families: &[Family<B>]) -> Option<FamilyId> {
fn family(&self, factory: &mut Factory<B>, families: &Families<B>) -> Option<FamilyId> {
// Find correct queue family.
families
.iter()
.find(|family| factory.surface_support(family.id(), &self.surface))
.map(Family::id)
families.find(|family| factory.surface_support(family.id(), &self.surface))
}

fn buffers(&self) -> Vec<(BufferId, BufferAccess)> {
Expand Down
2 changes: 1 addition & 1 deletion graph/src/node/render/group/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
},
resource::{DescriptorSetLayout, Handle},
},
gfx_hal::{Backend, device::Device as _},
gfx_hal::{device::Device as _, Backend},
};

pub use crate::util::types::{Layout, SetLayout};
Expand Down
29 changes: 14 additions & 15 deletions graph/src/node/render/pass.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use {
crate::{
command::{
CommandBuffer, CommandPool, ExecutableState, Family, FamilyId, Fence, Graphics,
IndividualReset, MultiShot, NoSimultaneousUse, PendingState, Queue, QueueId,
SecondaryLevel, SimultaneousUse, Submission, Submit, Supports,
CommandBuffer, CommandPool, ExecutableState, Families, Family, FamilyId, Fence,
Graphics, IndividualReset, MultiShot, NoSimultaneousUse, PendingState, Queue, QueueId,
SecondaryLevel, SimultaneousUse, Submission, Submit,
},
factory::Factory,
frame::{
Expand All @@ -14,13 +14,13 @@ use {
node::{
gfx_acquire_barriers, gfx_release_barriers, is_metal,
render::group::{RenderGroup, RenderGroupBuilder},
BufferAccess, DynNode, ImageAccess, NodeBuffer, NodeBuilder, NodeBuildError, NodeImage,
BufferAccess, DynNode, ImageAccess, NodeBuffer, NodeBuildError, NodeBuilder, NodeImage,
},
wsi::{Surface, Target},
BufferId, ImageId, NodeId,
},
either::Either,
gfx_hal::{image::Layout, Backend, device::Device as _},
gfx_hal::{device::Device as _, image::Layout, Backend},
std::{cmp::min, collections::HashMap},
};

Expand Down Expand Up @@ -220,11 +220,8 @@ where
B: Backend,
T: ?Sized + 'static,
{
fn family(&self, _factory: &mut Factory<B>, families: &[Family<B>]) -> Option<FamilyId> {
families
.iter()
.find(|family| Supports::<Graphics>::supports(&family.capability()).is_some())
.map(|family| family.id())
fn family(&self, _factory: &mut Factory<B>, families: &Families<B>) -> Option<FamilyId> {
families.with_capability::<Graphics>()
}

fn buffers(&self) -> Vec<(BufferId, BufferAccess)> {
Expand Down Expand Up @@ -448,7 +445,7 @@ where
}

let (caps, _f, present_modes_caps) = factory.get_surface_compatibility(&surface);

let present_mode = *present_modes_caps
.iter()
.max_by_key(|mode| match mode {
Expand All @@ -458,10 +455,10 @@ where
gfx_hal::window::PresentMode::Immediate => 0,
})
.unwrap();

let img_count_caps = caps.image_count;
let image_count = 3.min(*img_count_caps.end()).max(*img_count_caps.start());

let target = factory
.create_target(
surface,
Expand Down Expand Up @@ -766,7 +763,8 @@ where
.buffers()
.into_iter()
.map(|(id, _)| {
buffers.iter()
buffers
.iter()
.find(|b| b.id == id)
.expect("Transient buffer wasn't provided")
.clone()
Expand All @@ -776,7 +774,8 @@ where
.images()
.into_iter()
.map(|(id, _)| {
images.iter()
images
.iter()
.find(|i| i.id == id)
.expect("Transient image wasn't provided")
.clone()
Expand Down
2 changes: 1 addition & 1 deletion memory/src/allocator/dedicated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
mapping::{mapped_fitting_range, MappedRange},
memory::*,
},
gfx_hal::{Backend, device::Device as _},
gfx_hal::{device::Device as _, Backend},
};

/// Memory block allocated from `DedicatedAllocator`
Expand Down
2 changes: 1 addition & 1 deletion memory/src/allocator/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
memory::*,
util::*,
},
gfx_hal::{Backend, device::Device as _},
gfx_hal::{device::Device as _, Backend},
hibitset::{BitSet, BitSetLike as _},
};

Expand Down
2 changes: 1 addition & 1 deletion memory/src/allocator/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
memory::*,
util::*,
},
gfx_hal::{Backend, device::Device as _},
gfx_hal::{device::Device as _, Backend},
};

/// Memory block allocated from `LinearAllocator`
Expand Down
2 changes: 1 addition & 1 deletion memory/src/mapping/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub(crate) mod write;

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

Expand Down
10 changes: 6 additions & 4 deletions mesh/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,11 @@ impl<'a> MeshBuilder<'a> {
)
.map_err(UploadError::Create)?;

let mut mapped = staging.map(factory, 0..aligned_size)
.map_err(UploadError::Map)?;
let mut writer = unsafe { mapped.write(factory, 0..aligned_size) }
let mut mapped = staging
.map(factory, 0..aligned_size)
.map_err(UploadError::Map)?;
let mut writer =
unsafe { mapped.write(factory, 0..aligned_size) }.map_err(UploadError::Map)?;
let staging_slice = unsafe { writer.slice() };

let mut offset = 0usize;
Expand Down Expand Up @@ -293,7 +294,8 @@ impl<'a> MeshBuilder<'a> {
.create_buffer(
BufferInfo {
size: indices.len() as _,
usage: gfx_hal::buffer::Usage::INDEX | gfx_hal::buffer::Usage::TRANSFER_DST,
usage: gfx_hal::buffer::Usage::INDEX
| gfx_hal::buffer::Usage::TRANSFER_DST,
},
Data,
)
Expand Down
Loading

0 comments on commit 4095fe0

Please sign in to comment.