Simplify TrackedDescriptorSetsCollection trait

This commit is contained in:
Pierre Krieger 2016-09-15 14:49:42 +02:00
parent 8dc2b3f09d
commit bc4e173078
3 changed files with 42 additions and 62 deletions

View File

@ -24,8 +24,6 @@ use command_buffer::sys::UnsafeCommandBufferBuilder;
use descriptor::PipelineLayout;
use descriptor::descriptor::ShaderStages;
use descriptor::descriptor_set::collection::TrackedDescriptorSetsCollection;
use descriptor::descriptor_set::collection::TrackedDescriptorSetsCollectionState;
use descriptor::descriptor_set::collection::TrackedDescriptorSetsCollectionFinished;
use device::Queue;
use image::traits::TrackedImage;
use instance::QueueFamily;
@ -123,7 +121,7 @@ unsafe impl<'a, L, Pl, S, Pc> StdCommandsList for DispatchCommand<'a, L, Pl, S,
let my_command_num = self.num_commands();
// Computing the finished state of the sets.
let (finished_state, fb) = self.sets_state.finish();
let (finished_state, fb) = self.sets.finish(self.sets_state);
final_barrier.merge(fb);
// We split the barriers in two: those to apply after our command, and those to
@ -184,7 +182,7 @@ unsafe impl<'a, L, Pl, S, Pc> ResourcesStates for DispatchCommand<'a, L, Pl, S,
-> Option<Ob::CommandListState>
where Ob: TrackedBuffer
{
if let Some(s) = self.sets_state.extract_buffer_state(buffer) {
if let Some(s) = self.sets.extract_buffer_state(&mut self.sets_state, buffer) {
return Some(s);
}
@ -194,7 +192,7 @@ unsafe impl<'a, L, Pl, S, Pc> ResourcesStates for DispatchCommand<'a, L, Pl, S,
unsafe fn extract_image_state<I>(&mut self, image: &I) -> Option<I::CommandListState>
where I: TrackedImage
{
if let Some(s) = self.sets_state.extract_image_state(image) {
if let Some(s) = self.sets.extract_image_state(&mut self.sets_state, image) {
return Some(s);
}
@ -226,11 +224,9 @@ unsafe impl<L, Pl, S> CommandBuffer for DispatchCommandCb<L, Pl, S>
{
type Pool = L::Pool;
type SemaphoresWaitIterator = Chain<L::SemaphoresWaitIterator,
<S::Finished as TrackedDescriptorSetsCollectionFinished>::
SemaphoresWaitIterator>;
S::SemaphoresWaitIterator>;
type SemaphoresSignalIterator = Chain<L::SemaphoresSignalIterator,
<S::Finished as TrackedDescriptorSetsCollectionFinished>::
SemaphoresSignalIterator>;
S::SemaphoresSignalIterator>;
#[inline]
fn inner(&self) -> &UnsafeCommandBuffer<Self::Pool> {
@ -246,7 +242,7 @@ unsafe impl<L, Pl, S> CommandBuffer for DispatchCommandCb<L, Pl, S>
let parent = self.previous.on_submit(queue, &mut fence);
// We query our sets.
let my_infos = self.sets_state.on_submit(queue, fence);
let my_infos = self.sets.on_submit(&self.sets_state, queue, fence);
// We merge the two.
SubmitInfo {

View File

@ -26,8 +26,6 @@ use command_buffer::sys::UnsafeCommandBufferBuilder;
use descriptor::PipelineLayout;
use descriptor::descriptor::ShaderStages;
use descriptor::descriptor_set::collection::TrackedDescriptorSetsCollection;
use descriptor::descriptor_set::collection::TrackedDescriptorSetsCollectionState;
use descriptor::descriptor_set::collection::TrackedDescriptorSetsCollectionFinished;
use device::Queue;
use image::traits::TrackedImage;
use instance::QueueFamily;
@ -161,7 +159,7 @@ unsafe impl<'a, L, Pv, Pl, Prp, S, Pc> StdCommandsList for DrawCommand<'a, L, Pv
let my_command_num = self.num_commands();
// Computing the finished state of the sets.
let (finished_state, fb) = self.sets_state.finish();
let (finished_state, fb) = self.sets.finish(self.sets_state);
final_barrier.merge(fb);
// We split the barriers in two: those to apply after our command, and those to
@ -241,7 +239,7 @@ unsafe impl<'a, L, Pv, Pl, Prp, S, Pc> ResourcesStates for DrawCommand<'a, L, Pv
-> Option<Ob::CommandListState>
where Ob: TrackedBuffer
{
if let Some(s) = self.sets_state.extract_buffer_state(buffer) {
if let Some(s) = self.sets.extract_buffer_state(&mut self.sets_state, buffer) {
return Some(s);
}
@ -251,7 +249,7 @@ unsafe impl<'a, L, Pv, Pl, Prp, S, Pc> ResourcesStates for DrawCommand<'a, L, Pv
unsafe fn extract_image_state<I>(&mut self, image: &I) -> Option<I::CommandListState>
where I: TrackedImage
{
if let Some(s) = self.sets_state.extract_image_state(image) {
if let Some(s) = self.sets.extract_image_state(&mut self.sets_state, image) {
return Some(s);
}
@ -308,11 +306,9 @@ unsafe impl<L, Pv, Pl, Prp, S> CommandBuffer for DrawCommandCb<L, Pv, Pl, Prp, S
{
type Pool = L::Pool;
type SemaphoresWaitIterator = Chain<L::SemaphoresWaitIterator,
<S::Finished as TrackedDescriptorSetsCollectionFinished>::
SemaphoresWaitIterator>;
S::SemaphoresWaitIterator>;
type SemaphoresSignalIterator = Chain<L::SemaphoresSignalIterator,
<S::Finished as TrackedDescriptorSetsCollectionFinished>::
SemaphoresSignalIterator>;
S::SemaphoresSignalIterator>;
#[inline]
fn inner(&self) -> &UnsafeCommandBuffer<Self::Pool> {
@ -328,7 +324,7 @@ unsafe impl<L, Pv, Pl, Prp, S> CommandBuffer for DrawCommandCb<L, Pv, Pl, Prp, S
let parent = self.previous.on_submit(queue, &mut fence);
// We query our sets.
let my_infos = self.sets_state.on_submit(queue, fence);
let my_infos = self.sets.on_submit(&self.sets_state, queue, fence);
// We merge the two.
SubmitInfo {

View File

@ -48,9 +48,15 @@ pub unsafe trait DescriptorSetsCollection {
/// commands list interface.
pub unsafe trait TrackedDescriptorSetsCollection: DescriptorSetsCollection {
/// State of the resources inside the collection.
type State: TrackedDescriptorSetsCollectionState<Finished = Self::Finished>;
type State;
/// Finished state of the resources inside the collection.
type Finished: TrackedDescriptorSetsCollectionFinished;
type Finished;
/// Iterator that returns the list of semaphores to wait upon before the command buffer is
/// submitted.
type SemaphoresWaitIterator: Iterator<Item = (Arc<Semaphore>, PipelineStages)>;
/// Iterator that returns the list of semaphores to signal after the command buffer has
/// finished execution.
type SemaphoresSignalIterator: Iterator<Item = Arc<Semaphore>>;
/// Extracts the states relevant to the buffers and images contained in the descriptor sets.
/// Then transitions them to the right state and returns a pipeline barrier to insert as part
@ -58,32 +64,25 @@ pub unsafe trait TrackedDescriptorSetsCollection: DescriptorSetsCollection {
unsafe fn extract_states_and_transition<S>(&self, list: &mut S)
-> (Self::State, usize, PipelineBarrierBuilder)
where S: ResourcesStates;
}
/// State of the resources inside the collection.
pub unsafe trait TrackedDescriptorSetsCollectionState: ResourcesStates {
/// Finished state of the resources inside the collection.
type Finished: TrackedDescriptorSetsCollectionFinished;
#[inline]
unsafe fn extract_buffer_state<B>(&self, state: &mut Self::State, buffer: &B)
-> Option<B::CommandListState>
where B: TrackedBuffer;
#[inline]
unsafe fn extract_image_state<I>(&self, state: &mut Self::State, image: &I)
-> Option<I::CommandListState>
where I: TrackedImage;
/// Turns the object into a `TrackedDescriptorSetsCollectionFinished`. All the buffers and
/// images whose state hasn't been extracted must be have `finished()` called on them as well.
///
/// The function returns a pipeline barrier to append at the end of the command buffer.
unsafe fn finish(self) -> (Self::Finished, PipelineBarrierBuilder);
}
/// Finished state of the resources inside the collection.
pub unsafe trait TrackedDescriptorSetsCollectionFinished {
/// Iterator that returns the list of semaphores to wait upon before the command buffer is
/// submitted.
type SemaphoresWaitIterator: Iterator<Item = (Arc<Semaphore>, PipelineStages)>;
/// Iterator that returns the list of semaphores to signal after the command buffer has
/// finished execution.
type SemaphoresSignalIterator: Iterator<Item = Arc<Semaphore>>;
unsafe fn finish(&self, state: Self::State) -> (Self::Finished, PipelineBarrierBuilder);
// TODO: write docs
unsafe fn on_submit<F>(&self, queue: &Arc<Queue>, fence: F)
unsafe fn on_submit<F>(&self, state: &Self::Finished, queue: &Arc<Queue>, fence: F)
-> SubmitInfo<Self::SemaphoresWaitIterator,
Self::SemaphoresSignalIterator>
where F: FnMut() -> Arc<Fence>;
@ -106,51 +105,40 @@ unsafe impl DescriptorSetsCollection for () {
}
unsafe impl TrackedDescriptorSetsCollection for () {
type State = EmptyState;
type Finished = EmptyState;
type State = ();
type Finished = ();
type SemaphoresWaitIterator = EmptyIter<(Arc<Semaphore>, PipelineStages)>;
type SemaphoresSignalIterator = EmptyIter<Arc<Semaphore>>;
#[inline]
unsafe fn extract_states_and_transition<S>(&self, list: &mut S)
-> (Self::State, usize, PipelineBarrierBuilder)
where S: ResourcesStates
{
(EmptyState, 0, PipelineBarrierBuilder::new())
((), 0, PipelineBarrierBuilder::new())
}
}
#[derive(Debug, Copy, Clone)]
pub struct EmptyState;
unsafe impl TrackedDescriptorSetsCollectionState for EmptyState {
type Finished = EmptyState;
#[inline]
unsafe fn finish(self) -> (Self::Finished, PipelineBarrierBuilder) {
(EmptyState, PipelineBarrierBuilder::new())
unsafe fn finish(&self, _: ()) -> (Self::Finished, PipelineBarrierBuilder) {
((), PipelineBarrierBuilder::new())
}
}
unsafe impl ResourcesStates for EmptyState {
#[inline]
unsafe fn extract_buffer_state<B>(&mut self, buffer: &B) -> Option<B::CommandListState>
unsafe fn extract_buffer_state<B>(&self, _: &mut (), buffer: &B) -> Option<B::CommandListState>
where B: TrackedBuffer
{
None
}
#[inline]
unsafe fn extract_image_state<I>(&mut self, image: &I) -> Option<I::CommandListState>
unsafe fn extract_image_state<I>(&self, _: &mut (), image: &I) -> Option<I::CommandListState>
where I: TrackedImage
{
None
}
}
unsafe impl TrackedDescriptorSetsCollectionFinished for EmptyState {
type SemaphoresWaitIterator = EmptyIter<(Arc<Semaphore>, PipelineStages)>;
type SemaphoresSignalIterator = EmptyIter<Arc<Semaphore>>;
unsafe fn on_submit<F>(&self, queue: &Arc<Queue>, fence: F)
#[inline]
unsafe fn on_submit<F>(&self, _: &(), queue: &Arc<Queue>, fence: F)
-> SubmitInfo<Self::SemaphoresWaitIterator,
Self::SemaphoresSignalIterator>
where F: FnMut() -> Arc<Fence>