Skip to content

Commit

Permalink
Merge #2111
Browse files Browse the repository at this point in the history
2111: Dynamic buffers r=kvark a=msiglreith

Start defining the basic API for dynamic buffer descriptors. Atm based upon vulkan, not optimal but provides the best performance. Other possbiel API design could use `(set, Option<Offset>)` for descriptor set binding, but involves more work on the portability layer and might be more typing for users.

Feedback appreciated.
More backends to follow ..

Addresses #1949
PR checklist:
- [x] `make` succeeds (on *nix)
- [x] `make reftests` succeeds
- [ ] tested examples with the following backends:


Co-authored-by: msiglreith <[email protected]>
Co-authored-by: Dzmitry Malyshau <[email protected]>
  • Loading branch information
3 people committed Jun 5, 2018
2 parents 3058b6e + b61f215 commit 92c09cf
Show file tree
Hide file tree
Showing 20 changed files with 204 additions and 112 deletions.
2 changes: 1 addition & 1 deletion examples/hal/compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn main() {
}),
);
command_buffer.bind_compute_pipeline(&pipeline);
command_buffer.bind_compute_descriptor_sets(&pipeline_layout, 0, &[desc_set]);
command_buffer.bind_compute_descriptor_sets(&pipeline_layout, 0, &[desc_set], &[]);
command_buffer.dispatch([numbers.len() as u32, 1, 1]);
command_buffer.pipeline_barrier(
pso::PipelineStage::COMPUTE_SHADER .. pso::PipelineStage::TRANSFER,
Expand Down
2 changes: 1 addition & 1 deletion examples/hal/quad/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ fn main() {
cmd_buffer.set_scissors(0, &[viewport.rect]);
cmd_buffer.bind_graphics_pipeline(&pipeline.as_ref().unwrap());
cmd_buffer.bind_vertex_buffers(0, pso::VertexBufferSet(vec![(&vertex_buffer, 0)]));
cmd_buffer.bind_graphics_descriptor_sets(&pipeline_layout, 0, Some(&desc_set)); //TODO
cmd_buffer.bind_graphics_descriptor_sets(&pipeline_layout, 0, Some(&desc_set), &[]); //TODO

{
let mut encoder = cmd_buffer.begin_render_pass_inline(
Expand Down
30 changes: 17 additions & 13 deletions src/backend/dx11/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl hal::PhysicalDevice<Backend> for PhysicalDevice {
};

let device = device::Device::new(device, cxt, self.memory_properties.clone());

// TODO: deferred context => 1 cxt/queue?
let queues = Queues::new(
families
Expand Down Expand Up @@ -490,7 +490,7 @@ pub struct CommandBuffer {
}

unsafe impl Send for CommandBuffer {}
unsafe impl Sync for CommandBuffer {}
unsafe impl Sync for CommandBuffer {}

impl CommandBuffer {
fn create_deferred(device: ComPtr<d3d11::ID3D11Device>, internal: internal::BufferImageCopy) -> Self {
Expand Down Expand Up @@ -544,7 +544,7 @@ impl hal::command::RawCommandBuffer<Backend> for CommandBuffer {

let depth_view = framebuffer.attachments.iter().find(|a| a.dsv_handle.is_some());


unsafe {
for (clear, view) in clear_values.into_iter().zip(framebuffer.attachments.iter()) {
let clear = clear.borrow();
Expand Down Expand Up @@ -729,10 +729,12 @@ impl hal::command::RawCommandBuffer<Backend> for CommandBuffer {
}
}

fn bind_graphics_descriptor_sets<'a, T>(&mut self, layout: &PipelineLayout, first_set: usize, sets: T)
fn bind_graphics_descriptor_sets<'a, I, J>(&mut self, layout: &PipelineLayout, first_set: usize, sets: I, _offsets: J)
where
T: IntoIterator,
T::Item: Borrow<DescriptorSet>,
I: IntoIterator,
I::Item: Borrow<DescriptorSet>,
J: IntoIterator,
J::Item: Borrow<command::DescriptorSetOffset>,
{
for set in sets.into_iter() {
let set = set.borrow();
Expand All @@ -759,10 +761,12 @@ impl hal::command::RawCommandBuffer<Backend> for CommandBuffer {
}


fn bind_compute_descriptor_sets<T>(&mut self, layout: &PipelineLayout, first_set: usize, sets: T)
fn bind_compute_descriptor_sets<I, J>(&mut self, layout: &PipelineLayout, first_set: usize, sets: I, offsets: J)
where
T: IntoIterator,
T::Item: Borrow<DescriptorSet>,
I: IntoIterator,
I::Item: Borrow<DescriptorSet>,
J: IntoIterator,
J::Item: Borrow<command::DescriptorSetOffset>,
{
unimplemented!()
}
Expand Down Expand Up @@ -900,15 +904,15 @@ pub struct Memory {
}

unsafe impl Send for Memory {}
unsafe impl Sync for Memory {}
unsafe impl Sync for Memory {}

pub struct CommandPool {
device: ComPtr<d3d11::ID3D11Device>,
internal: internal::BufferImageCopy,
}

unsafe impl Send for CommandPool {}
unsafe impl Sync for CommandPool {}
unsafe impl Sync for CommandPool {}

impl hal::pool::RawCommandPool<Backend> for CommandPool {
fn reset(&mut self) {
Expand Down Expand Up @@ -996,7 +1000,7 @@ impl Buffer {
}

unsafe impl Send for Buffer {}
unsafe impl Sync for Buffer {}
unsafe impl Sync for Buffer {}

#[derive(Debug)]
pub struct BufferView;
Expand Down Expand Up @@ -1129,7 +1133,7 @@ pub struct DescriptorSet {
}

unsafe impl Send for DescriptorSet {}
unsafe impl Sync for DescriptorSet {}
unsafe impl Sync for DescriptorSet {}

impl DescriptorSet {
pub fn new() -> Self {
Expand Down
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 @@ -1732,16 +1735,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 @@ -1766,16 +1772,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 @@ -541,12 +541,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
8 changes: 6 additions & 2 deletions src/backend/empty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,12 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer {
unimplemented!()
}

fn bind_graphics_descriptor_sets<I>(&mut self, _: &(), _: usize, _: I)
fn bind_graphics_descriptor_sets<I, J>(&mut self, _: &(), _: usize, _: I, _: J)
where
I: IntoIterator,
I::Item: Borrow<()>,
J: IntoIterator,
J::Item: Borrow<command::DescriptorSetOffset>,
{
unimplemented!()
}
Expand All @@ -575,10 +577,12 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer {
unimplemented!()
}

fn bind_compute_descriptor_sets<I>(&mut self, _: &(), _: usize, _: I)
fn bind_compute_descriptor_sets<I, J>(&mut self, _: &(), _: usize, _: I, _: J)
where
I: IntoIterator,
I::Item: Borrow<()>,
J: IntoIterator,
J::Item: Borrow<command::DescriptorSetOffset>,
{
unimplemented!()
}
Expand Down
22 changes: 14 additions & 8 deletions src/backend/gl/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,14 +834,17 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer {
self.update_blend_targets(blend_targets);
}

fn bind_graphics_descriptor_sets<T>(
fn bind_graphics_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<command::DescriptorSetOffset>,
{
// TODO
}
Expand All @@ -857,14 +860,17 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer {
}
}

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<command::DescriptorSetOffset>,
{
// TODO
}
Expand Down
Loading

0 comments on commit 92c09cf

Please sign in to comment.