Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into acceleration-stru…
Browse files Browse the repository at this point in the history
…cture-api
  • Loading branch information
tangmi committed Jan 5, 2021
2 parents 79ffbe6 + 187197d commit 3f8074e
Show file tree
Hide file tree
Showing 34 changed files with 1,359 additions and 1,255 deletions.
70 changes: 34 additions & 36 deletions examples/colour-uniform/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ impl<B: Backend> BufferState<B> {
where
T: Copy,
{
let memory: B::Memory;
let mut memory: B::Memory;
let mut buffer: B::Buffer;
let size: u64;

Expand Down Expand Up @@ -726,9 +726,9 @@ impl<B: Backend> BufferState<B> {
size = mem_req.size;

// TODO: check transitions: read/write mapping and vertex buffer read
let mapping = device.map_memory(&memory, m::Segment::ALL).unwrap();
let mapping = device.map_memory(&mut memory, m::Segment::ALL).unwrap();
ptr::copy_nonoverlapping(data_source.as_ptr() as *const u8, mapping, upload_size);
device.unmap_memory(&memory);
device.unmap_memory(&mut memory);
}

BufferState {
Expand All @@ -749,7 +749,7 @@ impl<B: Backend> BufferState<B> {
let upload_size = data_source.len() * stride;

assert!(offset + upload_size as u64 <= self.size);
let memory = self.memory.as_ref().unwrap();
let memory = self.memory.as_mut().unwrap();

unsafe {
let mapping = device
Expand All @@ -775,7 +775,7 @@ impl<B: Backend> BufferState<B> {
let row_pitch = (width * stride as u32 + row_alignment_mask) & !row_alignment_mask;
let upload_size = (height * row_pitch) as u64;

let memory: B::Memory;
let mut memory: B::Memory;
let mut buffer: B::Buffer;
let size: u64;

Expand All @@ -801,7 +801,7 @@ impl<B: Backend> BufferState<B> {
size = mem_reqs.size;

// copy image data into staging buffer
let mapping = device.map_memory(&memory, m::Segment::ALL).unwrap();
let mapping = device.map_memory(&mut memory, m::Segment::ALL).unwrap();
for y in 0..height as usize {
let data_source_slice =
&(**img)[y * (width as usize) * stride..(y + 1) * (width as usize) * stride];
Expand All @@ -811,7 +811,7 @@ impl<B: Backend> BufferState<B> {
data_source_slice.len(),
);
}
device.unmap_memory(&memory);
device.unmap_memory(&mut memory);
}

(
Expand Down Expand Up @@ -863,14 +863,14 @@ impl<B: Backend> Uniform<B> {
let buffer = Some(buffer);

desc.write_to_state(
vec![DescSetWrite {
DescSetWrite {
binding,
array_offset: 0,
descriptors: Some(pso::Descriptor::Buffer(
buffer.as_ref().unwrap().get_buffer(),
buffer::SubRange::WHOLE,
)),
}],
},
&mut device.borrow_mut().device,
);

Expand Down Expand Up @@ -950,23 +950,20 @@ struct DescSetWrite<W> {
impl<B: Backend> DescSet<B> {
unsafe fn write_to_state<'a, 'b: 'a, W>(
&'b mut self,
write: Vec<DescSetWrite<W>>,
d: DescSetWrite<W>,
device: &mut B::Device,
) where
W: IntoIterator,
W::IntoIter: ExactSizeIterator,
W::Item: std::borrow::Borrow<pso::Descriptor<'a, B>>,
{
let set = self.set.as_ref().unwrap();
let write: Vec<_> = write
.into_iter()
.map(|d| pso::DescriptorSetWrite {
binding: d.binding,
array_offset: d.array_offset,
descriptors: d.descriptors,
set,
})
.collect();
device.write_descriptor_sets(write);
let set = self.set.as_mut().unwrap();
device.write_descriptor_set(pso::DescriptorSetWrite {
binding: d.binding,
array_offset: d.array_offset,
descriptors: d.descriptors,
set,
});
}

fn get_layout(&self) -> &B::DescriptorSetLayout {
Expand Down Expand Up @@ -1049,21 +1046,22 @@ impl<B: Backend> ImageState<B> {
.expect("Can't create sampler");

desc.write_to_state(
vec![
DescSetWrite {
binding: 0,
array_offset: 0,
descriptors: Some(pso::Descriptor::Image(
&image_view,
i::Layout::ShaderReadOnlyOptimal,
)),
},
DescSetWrite {
binding: 1,
array_offset: 0,
descriptors: Some(pso::Descriptor::Sampler(&sampler)),
},
],
DescSetWrite {
binding: 0,
array_offset: 0,
descriptors: Some(pso::Descriptor::Image(
&image_view,
i::Layout::ShaderReadOnlyOptimal,
)),
},
device,
);
desc.write_to_state(
DescSetWrite {
binding: 1,
array_offset: 0,
descriptors: Some(pso::Descriptor::Sampler(&sampler)),
},
device,
);

Expand Down
27 changes: 13 additions & 14 deletions examples/compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn main() {
(pipeline_layout, pipeline, set_layout, desc_pool)
};

let (staging_memory, staging_buffer, _staging_size) = unsafe {
let (mut staging_memory, staging_buffer, _staging_size) = unsafe {
create_buffer::<back::Backend>(
&device,
&memory_properties.memory_types,
Expand All @@ -144,14 +144,14 @@ fn main() {

unsafe {
let mapping = device
.map_memory(&staging_memory, memory::Segment::ALL)
.map_memory(&mut staging_memory, memory::Segment::ALL)
.unwrap();
ptr::copy_nonoverlapping(
numbers.as_ptr() as *const u8,
mapping,
numbers.len() * stride as usize,
);
device.unmap_memory(&staging_memory);
device.unmap_memory(&mut staging_memory);
}

let (device_memory, device_buffer, _device_buffer_size) = unsafe {
Expand All @@ -165,25 +165,24 @@ fn main() {
)
};

let desc_set;

unsafe {
desc_set = desc_pool.allocate_set(&set_layout).unwrap();
device.write_descriptor_sets(Some(pso::DescriptorSetWrite {
set: &desc_set,
let desc_set = unsafe {
let mut desc_set = desc_pool.allocate_set(&set_layout).unwrap();
device.write_descriptor_set(pso::DescriptorSetWrite {
set: &mut desc_set,
binding: 0,
array_offset: 0,
descriptors: Some(pso::Descriptor::Buffer(
&device_buffer,
buffer::SubRange::WHOLE,
)),
}));
});
desc_set
};

let mut command_pool =
unsafe { device.create_command_pool(family.id(), pool::CommandPoolCreateFlags::empty()) }
.expect("Can't create command pool");
let fence = device.create_fence(false).unwrap();
let mut fence = device.create_fence(false).unwrap();
unsafe {
let mut command_buffer = command_pool.allocate_one(command::Level::Primary);
command_buffer.begin_primary(command::CommandBufferFlags::ONE_TIME_SUBMIT);
Expand Down Expand Up @@ -232,21 +231,21 @@ fn main() {
);
command_buffer.finish();

queue_group.queues[0].submit_without_semaphores(Some(&command_buffer), Some(&fence));
queue_group.queues[0].submit_without_semaphores(Some(&command_buffer), Some(&mut fence));

device.wait_for_fence(&fence, !0).unwrap();
command_pool.free(Some(command_buffer));
}

unsafe {
let mapping = device
.map_memory(&staging_memory, memory::Segment::ALL)
.map_memory(&mut staging_memory, memory::Segment::ALL)
.unwrap();
println!(
"Times: {:?}",
slice::from_raw_parts::<u32>(mapping as *const u8 as *const u32, numbers.len()),
);
device.unmap_memory(&staging_memory);
device.unmap_memory(&mut staging_memory);
}

unsafe {
Expand Down
20 changes: 10 additions & 10 deletions examples/mesh-shading/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ where
}
.expect("Can't create descriptor pool"),
);
let desc_set = unsafe { desc_pool.allocate_set(&set_layout) }.unwrap();
let mut desc_set = unsafe { desc_pool.allocate_set(&set_layout) }.unwrap();

// Buffer allocations
println!("Memory types: {:?}", memory_types);
Expand Down Expand Up @@ -307,13 +307,13 @@ where

// TODO: check transitions: read/write mapping and vertex buffer read
let buffer_memory = unsafe {
let memory = device
let mut memory = device
.allocate_memory(upload_type, buffer_req.size)
.unwrap();
device
.bind_buffer_memory(&memory, 0, &mut positions_buffer)
.unwrap();
let mapping = device.map_memory(&memory, m::Segment::ALL).unwrap();
let mapping = device.map_memory(&mut memory, m::Segment::ALL).unwrap();
ptr::copy_nonoverlapping(
positions.as_ptr() as *const u8,
mapping,
Expand All @@ -322,20 +322,20 @@ where
device
.flush_mapped_memory_ranges(iter::once((&memory, m::Segment::ALL)))
.unwrap();
device.unmap_memory(&memory);
device.unmap_memory(&mut memory);
ManuallyDrop::new(memory)
};

unsafe {
device.write_descriptor_sets(vec![pso::DescriptorSetWrite {
set: &desc_set,
device.write_descriptor_set(pso::DescriptorSetWrite {
set: &mut desc_set,
binding: 0,
array_offset: 0,
descriptors: Some(pso::Descriptor::Buffer(
&*positions_buffer,
buffer::SubRange::WHOLE,
)),
}]);
});
}

let caps = surface.capabilities(&adapter.physical_device);
Expand Down Expand Up @@ -583,7 +583,7 @@ where
// updated with a CPU->GPU data copy are not in use by the GPU, so we can perform those updates.
// In this case there are none to be done, however.
unsafe {
let fence = &self.submission_complete_fences[frame_idx];
let fence = &mut self.submission_complete_fences[frame_idx];
self.device
.wait_for_fence(fence, !0)
.expect("Failed to wait for fence");
Expand Down Expand Up @@ -630,14 +630,14 @@ where
};
self.queue_group.queues[0].submit(
submission,
Some(&self.submission_complete_fences[frame_idx]),
Some(&mut self.submission_complete_fences[frame_idx]),
);

// present frame
let result = self.queue_group.queues[0].present(
&mut self.surface,
surface_image,
Some(&self.submission_complete_semaphores[frame_idx]),
Some(&mut self.submission_complete_semaphores[frame_idx]),
);

self.device.destroy_framebuffer(framebuffer);
Expand Down
Loading

0 comments on commit 3f8074e

Please sign in to comment.