Skip to content

Commit

Permalink
hal,dx12: Add preliminary dynamic descriptor buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
msiglreith committed Jun 5, 2018
1 parent 447a0da commit abc7966
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 44 deletions.
37 changes: 23 additions & 14 deletions src/backend/dx12/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,18 @@ impl PipelineCache {
}
}

fn bind_descriptor_sets<'a, T>(
fn bind_descriptor_sets<'a, I, J>(
&mut self,
layout: &n::PipelineLayout,
first_set: usize,
sets: T,
sets: I,
offsets: J,
) -> [*mut d3d12::ID3D12DescriptorHeap; 2]
where
T: IntoIterator,
T::Item: Borrow<n::DescriptorSet>,
I: IntoIterator,
I::Item: Borrow<n::DescriptorSet>,
J: IntoIterator,
J::Item: Borrow<com::DescriptorSetOffset>,
{
let mut sets = sets.into_iter().peekable();
let (
Expand Down Expand Up @@ -1739,16 +1742,19 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
}
}

fn bind_graphics_descriptor_sets<'a, T>(
fn bind_graphics_descriptor_sets<'a, I, J>(
&mut self,
layout: &n::PipelineLayout,
first_set: usize,
sets: T,
sets: I,
offsets: J,
) where
T: IntoIterator,
T::Item: Borrow<n::DescriptorSet>,
I: IntoIterator,
I::Item: Borrow<n::DescriptorSet>,
J: IntoIterator,
J::Item: Borrow<com::DescriptorSetOffset>,
{
self.active_descriptor_heaps = self.gr_pipeline.bind_descriptor_sets(layout, first_set, sets);
self.active_descriptor_heaps = self.gr_pipeline.bind_descriptor_sets(layout, first_set, sets, offsets);
self.bind_descriptor_heaps();
}

Expand All @@ -1773,16 +1779,19 @@ impl com::RawCommandBuffer<Backend> for CommandBuffer {
self.comp_pipeline.pipeline = Some((pipeline.raw, pipeline.signature));
}

fn bind_compute_descriptor_sets<T>(
fn bind_compute_descriptor_sets<I, J>(
&mut self,
layout: &n::PipelineLayout,
first_set: usize,
sets: T,
sets: I,
offsets: J,
) where
T: IntoIterator,
T::Item: Borrow<n::DescriptorSet>,
I: IntoIterator,
I::Item: Borrow<n::DescriptorSet>,
J: IntoIterator,
J::Item: Borrow<com::DescriptorSetOffset>,
{
self.active_descriptor_heaps = self.comp_pipeline.bind_descriptor_sets(layout, first_set, sets);
self.active_descriptor_heaps = self.comp_pipeline.bind_descriptor_sets(layout, first_set, sets, offsets);
self.bind_descriptor_heaps();
}

Expand Down
7 changes: 4 additions & 3 deletions src/backend/dx12/src/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,16 @@ pub fn map_descriptor_range(bind: &DescriptorSetLayoutBinding, register_space: u
pso::DescriptorType::InputAttachment |
pso::DescriptorType::UniformTexelBuffer => D3D12_DESCRIPTOR_RANGE_TYPE_SRV,
pso::DescriptorType::StorageBuffer |
pso::DescriptorType::StorageBufferDynamic |
pso::DescriptorType::StorageTexelBuffer |
pso::DescriptorType::StorageImage => D3D12_DESCRIPTOR_RANGE_TYPE_UAV,
pso::DescriptorType::UniformBuffer => D3D12_DESCRIPTOR_RANGE_TYPE_CBV,
pso::DescriptorType::UniformBuffer |
pso::DescriptorType::UniformBufferDynamic => D3D12_DESCRIPTOR_RANGE_TYPE_CBV,
pso::DescriptorType::CombinedImageSampler => if sampler {
D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER
} else {
D3D12_DESCRIPTOR_RANGE_TYPE_SRV
},
_ => panic!("unsupported binding type {:?}", bind.ty)
}
},
NumDescriptors: bind.count as _,
BaseShaderRegister: bind.binding as _,
Expand Down
4 changes: 2 additions & 2 deletions src/backend/dx12/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,12 @@ impl HeapProperties {
pso::DescriptorType::InputAttachment |
pso::DescriptorType::SampledImage |
pso::DescriptorType::UniformTexelBuffer |
pso::DescriptorType::UniformBufferDynamic |
pso::DescriptorType::UniformBuffer => HeapProperties::new(true, false, false),
pso::DescriptorType::StorageImage |
pso::DescriptorType::StorageTexelBuffer |
pso::DescriptorType::StorageBufferDynamic |
pso::DescriptorType::StorageBuffer => HeapProperties::new(true, false, true),
pso::DescriptorType::UniformBufferDynamic |
pso::DescriptorType::UniformImageDynamic => unimplemented!(),
}

}
Expand Down
14 changes: 9 additions & 5 deletions src/hal/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::borrow::Borrow;

use {Backend, WorkGroupCount};
use buffer::Offset;
use command::raw::DescriptorSetOffset;
use queue::capability::{Compute, Supports};
use super::{CommandBuffer, RawCommandBuffer, Shot, Level};

Expand All @@ -14,16 +15,19 @@ impl<'a, B: Backend, C: Supports<Compute>, S: Shot, L: Level> CommandBuffer<'a,
}

/// Identical to the `RawCommandBuffer` method of the same name.
pub fn bind_compute_descriptor_sets<T>(
pub fn bind_compute_descriptor_sets<I, J>(
&mut self,
layout: &B::PipelineLayout,
first_set: usize,
sets: T,
sets: I,
offsets: J,
) where
T: IntoIterator,
T::Item: Borrow<B::DescriptorSet>,
I: IntoIterator,
I::Item: Borrow<B::DescriptorSet>,
J: IntoIterator,
J::Item: Borrow<DescriptorSetOffset>,
{
self.raw.bind_compute_descriptor_sets(layout, first_set, sets)
self.raw.bind_compute_descriptor_sets(layout, first_set, sets, offsets)
}

/// Identical to the `RawCommandBuffer` method of the same name.
Expand Down
14 changes: 9 additions & 5 deletions src/hal/src/command/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::ops::Range;
use Backend;
use {image, pso};
use buffer::IndexBufferView;
use command::raw::DescriptorSetOffset;
use query::{Query, QueryControl, QueryId};
use queue::capability::{Graphics, GraphicsOrCompute, Supports};
use super::{
Expand Down Expand Up @@ -192,16 +193,19 @@ impl<'a, B: Backend, C: Supports<Graphics>, S: Shot, L: Level> CommandBuffer<'a,
}

/// Identical to the `RawCommandBuffer` method of the same name.
pub fn bind_graphics_descriptor_sets<T>(
pub fn bind_graphics_descriptor_sets<I, J>(
&mut self,
layout: &B::PipelineLayout,
first_set: usize,
sets: T,
sets: I,
offsets: J,
) where
T: IntoIterator,
T::Item: Borrow<B::DescriptorSet>,
I: IntoIterator,
I::Item: Borrow<B::DescriptorSet>,
J: IntoIterator,
J::Item: Borrow<DescriptorSetOffset>,
{
self.raw.bind_graphics_descriptor_sets(layout, first_set, sets)
self.raw.bind_graphics_descriptor_sets(layout, first_set, sets, offsets)
}

/// Identical to the `RawCommandBuffer` method of the same name.
Expand Down
5 changes: 4 additions & 1 deletion src/hal/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ mod render_pass;
mod transfer;

pub use self::graphics::*;
pub use self::raw::{ClearValueRaw, ClearColorRaw, ClearDepthStencilRaw, RawCommandBuffer, CommandBufferFlags, Level as RawLevel, CommandBufferInheritanceInfo};
pub use self::raw::{
ClearValueRaw, ClearColorRaw, ClearDepthStencilRaw, DescriptorSetOffset,
RawCommandBuffer, CommandBufferFlags, Level as RawLevel, CommandBufferInheritanceInfo,
};
pub use self::render_pass::*;
pub use self::transfer::*;

Expand Down
24 changes: 16 additions & 8 deletions src/hal/src/command/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ pub union ClearValueRaw {
_align: [u32; 4],
}

/// Offset for dynamic descriptors.
pub type DescriptorSetOffset = u32;

bitflags! {
/// Option flags for various command buffer settings.
Expand Down Expand Up @@ -304,14 +306,17 @@ pub trait RawCommandBuffer<B: Backend>: Clone + Any + Send + Sync {

/// Takes an iterator of graphics `DescriptorSet`'s, and binds them to the command buffer.
/// `first_set` is the index that the first descriptor is mapped to in the command buffer.
fn bind_graphics_descriptor_sets<T>(
fn bind_graphics_descriptor_sets<I, J>(
&mut self,
layout: &B::PipelineLayout,
first_set: usize,
sets: T,
sets: I,
offsets: J,
) where
T: IntoIterator,
T::Item: Borrow<B::DescriptorSet>;
I: IntoIterator,
I::Item: Borrow<B::DescriptorSet>,
J: IntoIterator,
J::Item: Borrow<DescriptorSetOffset>;

/// Bind a compute pipeline.
///
Expand All @@ -326,14 +331,17 @@ pub trait RawCommandBuffer<B: Backend>: Clone + Any + Send + Sync {

/// Takes an iterator of compute `DescriptorSet`'s, and binds them to the command buffer,
/// `first_set` is the index that the first descriptor is mapped to in the command buffer.
fn bind_compute_descriptor_sets<T>(
fn bind_compute_descriptor_sets<I, J>(
&mut self,
layout: &B::PipelineLayout,
first_set: usize,
sets: T,
sets: I,
offsets: J,
) where
T: IntoIterator,
T::Item: Borrow<B::DescriptorSet>;
I: IntoIterator,
I::Item: Borrow<B::DescriptorSet>,
J: IntoIterator,
J::Item: Borrow<DescriptorSetOffset>;

/// Execute a workgroup in the compute pipeline. `x`, `y` and `z` are the
/// number of local workgroups to dispatch along each "axis"; a total of `x`*`y`*`z`
Expand Down
14 changes: 9 additions & 5 deletions src/hal/src/command/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::marker::PhantomData;

use {buffer, pso};
use {Backend, DrawCount, IndexCount, InstanceCount, VertexCount, VertexOffset};
use command::raw::DescriptorSetOffset;
use queue::{Supports, Graphics};
use super::{
AttachmentClear, ClearValue, ClearValueRaw, CommandBuffer, RawCommandBuffer,
Expand Down Expand Up @@ -75,16 +76,19 @@ impl<'a, B: Backend> RenderSubpassCommon<'a, B> {
}

///
pub fn bind_graphics_descriptor_sets<T>(
pub fn bind_graphics_descriptor_sets<I, J>(
&mut self,
layout: &B::PipelineLayout,
first_set: usize,
sets: T,
sets: I,
offsets: J,
) where
T: IntoIterator,
T::Item: Borrow<B::DescriptorSet>,
I: IntoIterator,
I::Item: Borrow<B::DescriptorSet>,
J: IntoIterator,
J::Item: Borrow<DescriptorSetOffset>,
{
self.0.bind_graphics_descriptor_sets(layout, first_set, sets)
self.0.bind_graphics_descriptor_sets(layout, first_set, sets, offsets)
}

///
Expand Down
2 changes: 1 addition & 1 deletion src/hal/src/pso/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub enum DescriptorType {
///
UniformBufferDynamic = 8,
///
UniformImageDynamic = 9,
StorageBufferDynamic = 9,
/// Allows unfiltered loads of pixel local data in the fragment shader.
InputAttachment = 10,
}
Expand Down

0 comments on commit abc7966

Please sign in to comment.