Add reset command pool

This commit is contained in:
Maik Klein 2017-04-22 15:07:07 +02:00
parent 7215777288
commit f5b04a888d
2 changed files with 153 additions and 109 deletions

View file

@ -3,3 +3,6 @@ members = [
"examples", "examples",
"ash" "ash"
] ]
[package.metadata.release]
no-dev-version = true

View file

@ -10,46 +10,53 @@ pub trait DeviceV1_0 {
fn handle(&self) -> vk::Device; fn handle(&self) -> vk::Device;
fn fp_v1_0(&self) -> &vk::DeviceFnV1_0; fn fp_v1_0(&self) -> &vk::DeviceFnV1_0;
unsafe fn destroy_device(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) { unsafe fn destroy_device(&self, allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0().destroy_device(self.handle(), allocation_callbacks.as_raw_ptr()); self.fp_v1_0()
.destroy_device(self.handle(), allocation_callbacks.as_raw_ptr());
} }
unsafe fn destroy_sampler(&self, unsafe fn destroy_sampler(&self,
sampler: vk::Sampler, sampler: vk::Sampler,
allocation_callbacks: Option<&vk::AllocationCallbacks>) { allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0().destroy_sampler(self.handle(), sampler, allocation_callbacks.as_raw_ptr()); self.fp_v1_0()
.destroy_sampler(self.handle(), sampler, allocation_callbacks.as_raw_ptr());
} }
unsafe fn free_memory(&self, unsafe fn free_memory(&self,
memory: vk::DeviceMemory, memory: vk::DeviceMemory,
allocation_callbacks: Option<&vk::AllocationCallbacks>) { allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0().free_memory(self.handle(), memory, allocation_callbacks.as_raw_ptr()); self.fp_v1_0()
.free_memory(self.handle(), memory, allocation_callbacks.as_raw_ptr());
} }
unsafe fn free_command_buffers(&self, unsafe fn free_command_buffers(&self,
command_pool: vk::CommandPool, command_pool: vk::CommandPool,
command_buffers: &[vk::CommandBuffer]) { command_buffers: &[vk::CommandBuffer]) {
self.fp_v1_0().free_command_buffers(self.handle(), self.fp_v1_0()
command_pool, .free_command_buffers(self.handle(),
command_buffers.len() as vk::uint32_t, command_pool,
command_buffers.as_ptr()); command_buffers.len() as vk::uint32_t,
command_buffers.as_ptr());
} }
unsafe fn destroy_fence(&self, unsafe fn destroy_fence(&self,
fence: vk::Fence, fence: vk::Fence,
allocation_callbacks: Option<&vk::AllocationCallbacks>) { allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0().destroy_fence(self.handle(), fence, allocation_callbacks.as_raw_ptr()); self.fp_v1_0()
.destroy_fence(self.handle(), fence, allocation_callbacks.as_raw_ptr());
} }
unsafe fn destroy_image(&self, unsafe fn destroy_image(&self,
image: vk::Image, image: vk::Image,
allocation_callbacks: Option<&vk::AllocationCallbacks>) { allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0().destroy_image(self.handle(), image, allocation_callbacks.as_raw_ptr()); self.fp_v1_0()
.destroy_image(self.handle(), image, allocation_callbacks.as_raw_ptr());
} }
unsafe fn destroy_command_pool(&self, unsafe fn destroy_command_pool(&self,
pool: vk::CommandPool, pool: vk::CommandPool,
allocation_callbacks: Option<&vk::AllocationCallbacks>) { allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0().destroy_command_pool(self.handle(), pool, allocation_callbacks.as_raw_ptr()); self.fp_v1_0()
.destroy_command_pool(self.handle(), pool, allocation_callbacks.as_raw_ptr());
} }
unsafe fn destroy_image_view(&self, unsafe fn destroy_image_view(&self,
@ -78,15 +85,17 @@ pub trait DeviceV1_0 {
unsafe fn destroy_pipeline_layout(&self, unsafe fn destroy_pipeline_layout(&self,
pipeline_layout: vk::PipelineLayout, pipeline_layout: vk::PipelineLayout,
allocation_callbacks: Option<&vk::AllocationCallbacks>) { allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0().destroy_pipeline_layout(self.handle(), self.fp_v1_0()
pipeline_layout, .destroy_pipeline_layout(self.handle(),
allocation_callbacks.as_raw_ptr()); pipeline_layout,
allocation_callbacks.as_raw_ptr());
} }
unsafe fn destroy_buffer(&self, unsafe fn destroy_buffer(&self,
buffer: vk::Buffer, buffer: vk::Buffer,
allocation_callbacks: Option<&vk::AllocationCallbacks>) { allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0().destroy_buffer(self.handle(), buffer, allocation_callbacks.as_raw_ptr()); self.fp_v1_0()
.destroy_buffer(self.handle(), buffer, allocation_callbacks.as_raw_ptr());
} }
unsafe fn destroy_shader_module(&self, unsafe fn destroy_shader_module(&self,
@ -99,7 +108,8 @@ pub trait DeviceV1_0 {
unsafe fn destroy_pipeline(&self, unsafe fn destroy_pipeline(&self,
pipeline: vk::Pipeline, pipeline: vk::Pipeline,
allocation_callbacks: Option<&vk::AllocationCallbacks>) { allocation_callbacks: Option<&vk::AllocationCallbacks>) {
self.fp_v1_0().destroy_pipeline(self.handle(), pipeline, allocation_callbacks.as_raw_ptr()); self.fp_v1_0()
.destroy_pipeline(self.handle(), pipeline, allocation_callbacks.as_raw_ptr());
} }
unsafe fn destroy_semaphore(&self, unsafe fn destroy_semaphore(&self,
@ -116,7 +126,9 @@ pub trait DeviceV1_0 {
.destroy_descriptor_pool(self.handle(), pool, allocation_callbacks.as_raw_ptr()); .destroy_descriptor_pool(self.handle(), pool, allocation_callbacks.as_raw_ptr());
} }
unsafe fn destroy_descriptor_set_layout(&self, layout: vk::DescriptorSetLayout, allocation_callbacks: Option<&vk::AllocationCallbacks>) { unsafe fn destroy_descriptor_set_layout(&self, layout: vk::DescriptorSetLayout,
allocation_callbacks: Option<&vk::AllocationCallbacks>)
{
self.fp_v1_0() self.fp_v1_0()
.destroy_descriptor_set_layout(self.handle(), .destroy_descriptor_set_layout(self.handle(),
layout, layout,
@ -126,20 +138,22 @@ pub trait DeviceV1_0 {
unsafe fn free_descriptor_sets(&self, unsafe fn free_descriptor_sets(&self,
pool: vk::DescriptorPool, pool: vk::DescriptorPool,
descriptor_sets: &[vk::DescriptorSet]) { descriptor_sets: &[vk::DescriptorSet]) {
self.fp_v1_0().free_descriptor_sets(self.handle(), self.fp_v1_0()
pool, .free_descriptor_sets(self.handle(),
descriptor_sets.len() as u32, pool,
descriptor_sets.as_ptr()); descriptor_sets.len() as u32,
descriptor_sets.as_ptr());
} }
unsafe fn update_descriptor_sets(&self, unsafe fn update_descriptor_sets(&self,
descriptor_writes: &[vk::WriteDescriptorSet], descriptor_writes: &[vk::WriteDescriptorSet],
descriptor_copies: &[vk::CopyDescriptorSet]) { descriptor_copies: &[vk::CopyDescriptorSet]) {
self.fp_v1_0().update_descriptor_sets(self.handle(), self.fp_v1_0()
descriptor_writes.len() as u32, .update_descriptor_sets(self.handle(),
descriptor_writes.as_ptr(), descriptor_writes.len() as u32,
descriptor_copies.len() as u32, descriptor_writes.as_ptr(),
descriptor_copies.as_ptr()); descriptor_copies.len() as u32,
descriptor_copies.as_ptr());
} }
unsafe fn create_sampler(&self, unsafe fn create_sampler(&self,
@ -164,11 +178,12 @@ pub trait DeviceV1_0 {
dst_buffer: vk::Buffer, dst_buffer: vk::Buffer,
regions: &[vk::BufferCopy]) { regions: &[vk::BufferCopy]) {
self.fp_v1_0().cmd_copy_buffer(command_buffer, self.fp_v1_0()
src_buffer, .cmd_copy_buffer(command_buffer,
dst_buffer, src_buffer,
regions.len() as u32, dst_buffer,
regions.as_ptr()); regions.len() as u32,
regions.as_ptr());
} }
unsafe fn cmd_copy_buffer_to_image(&self, unsafe fn cmd_copy_buffer_to_image(&self,
@ -177,12 +192,13 @@ pub trait DeviceV1_0 {
dst_image: vk::Image, dst_image: vk::Image,
dst_image_layout: vk::ImageLayout, dst_image_layout: vk::ImageLayout,
regions: &[vk::BufferImageCopy]) { regions: &[vk::BufferImageCopy]) {
self.fp_v1_0().cmd_copy_buffer_to_image(command_buffer, self.fp_v1_0()
src_buffer, .cmd_copy_buffer_to_image(command_buffer,
dst_image, src_buffer,
dst_image_layout, dst_image,
regions.len() as u32, dst_image_layout,
regions.as_ptr()); regions.len() as u32,
regions.as_ptr());
} }
unsafe fn cmd_copy_image(&self, unsafe fn cmd_copy_image(&self,
@ -192,21 +208,23 @@ pub trait DeviceV1_0 {
dst_image: vk::Image, dst_image: vk::Image,
dst_image_layout: vk::ImageLayout, dst_image_layout: vk::ImageLayout,
regions: &[vk::ImageCopy]) { regions: &[vk::ImageCopy]) {
self.fp_v1_0().cmd_copy_image(command_buffer, self.fp_v1_0()
src_image, .cmd_copy_image(command_buffer,
src_image_layout, src_image,
dst_image, src_image_layout,
dst_image_layout, dst_image,
regions.len() as u32, dst_image_layout,
regions.as_ptr()); regions.len() as u32,
regions.as_ptr());
} }
unsafe fn allocate_descriptor_sets(&self, unsafe fn allocate_descriptor_sets(&self,
create_info: &vk::DescriptorSetAllocateInfo) create_info: &vk::DescriptorSetAllocateInfo)
-> VkResult<Vec<vk::DescriptorSet>> { -> VkResult<Vec<vk::DescriptorSet>> {
let mut desc_set = Vec::with_capacity(create_info.descriptor_set_count as usize); let mut desc_set = Vec::with_capacity(create_info.descriptor_set_count as usize);
let err_code = self.fp_v1_0() let err_code =
.allocate_descriptor_sets(self.handle(), create_info, desc_set.as_mut_ptr()); self.fp_v1_0()
.allocate_descriptor_sets(self.handle(), create_info, desc_set.as_mut_ptr());
desc_set.set_len(create_info.descriptor_set_count as usize); desc_set.set_len(create_info.descriptor_set_count as usize);
match err_code { match err_code {
@ -257,6 +275,19 @@ pub trait DeviceV1_0 {
} }
} }
unsafe fn reset_command_pool(&self,
command_pool: vk::CommandPool,
flags: vk::CommandPoolResetFlags)
-> VkResult<()> {
let err_code = self.fp_v1_0()
.reset_command_pool(self.handle(), command_pool, flags);
match err_code {
vk::Result::Success => Ok(()),
_ => Err(err_code),
}
}
unsafe fn reset_command_buffer(&self, unsafe fn reset_command_buffer(&self,
command_buffer: vk::CommandBuffer, command_buffer: vk::CommandBuffer,
flags: vk::CommandBufferResetFlags) flags: vk::CommandBufferResetFlags)
@ -270,8 +301,9 @@ pub trait DeviceV1_0 {
} }
unsafe fn reset_fences(&self, fences: &[vk::Fence]) -> VkResult<()> { unsafe fn reset_fences(&self, fences: &[vk::Fence]) -> VkResult<()> {
let err_code = self.fp_v1_0() let err_code =
.reset_fences(self.handle(), fences.len() as vk::uint32_t, fences.as_ptr()); self.fp_v1_0()
.reset_fences(self.handle(), fences.len() as vk::uint32_t, fences.as_ptr());
match err_code { match err_code {
vk::Result::Success => Ok(()), vk::Result::Success => Ok(()),
_ => Err(err_code), _ => Err(err_code),
@ -283,7 +315,8 @@ pub trait DeviceV1_0 {
buffer: vk::Buffer, buffer: vk::Buffer,
offset: vk::DeviceSize, offset: vk::DeviceSize,
index_type: vk::IndexType) { index_type: vk::IndexType) {
self.fp_v1_0().cmd_bind_index_buffer(command_buffer, buffer, offset, index_type); self.fp_v1_0()
.cmd_bind_index_buffer(command_buffer, buffer, offset, index_type);
} }
unsafe fn cmd_clear_color_image(&self, unsafe fn cmd_clear_color_image(&self,
@ -292,12 +325,13 @@ pub trait DeviceV1_0 {
image_layout: vk::ImageLayout, image_layout: vk::ImageLayout,
clear_color_value: &vk::ClearColorValue, clear_color_value: &vk::ClearColorValue,
ranges: &[vk::ImageSubresourceRange]) { ranges: &[vk::ImageSubresourceRange]) {
self.fp_v1_0().cmd_clear_color_image(command_buffer, self.fp_v1_0()
image, .cmd_clear_color_image(command_buffer,
image_layout, image,
clear_color_value, image_layout,
ranges.len() as vk::uint32_t, clear_color_value,
ranges.as_ptr()); ranges.len() as vk::uint32_t,
ranges.as_ptr());
} }
unsafe fn cmd_draw_indexed(&self, unsafe fn cmd_draw_indexed(&self,
@ -308,12 +342,13 @@ pub trait DeviceV1_0 {
vertex_offset: vk::int32_t, vertex_offset: vk::int32_t,
first_instance: vk::uint32_t) { first_instance: vk::uint32_t) {
self.fp_v1_0().cmd_draw_indexed(command_buffer, self.fp_v1_0()
index_count, .cmd_draw_indexed(command_buffer,
instance_count, index_count,
first_index, instance_count,
vertex_offset, first_index,
first_instance); vertex_offset,
first_instance);
} }
unsafe fn cmd_bind_descriptor_sets(&self, unsafe fn cmd_bind_descriptor_sets(&self,
@ -323,28 +358,31 @@ pub trait DeviceV1_0 {
first_set: vk::uint32_t, first_set: vk::uint32_t,
descriptor_sets: &[vk::DescriptorSet], descriptor_sets: &[vk::DescriptorSet],
dynamic_offsets: &[vk::uint32_t]) { dynamic_offsets: &[vk::uint32_t]) {
self.fp_v1_0().cmd_bind_descriptor_sets(command_buffer, self.fp_v1_0()
pipeline_bind_point, .cmd_bind_descriptor_sets(command_buffer,
layout, pipeline_bind_point,
first_set, layout,
descriptor_sets.len() as vk::uint32_t, first_set,
descriptor_sets.as_ptr(), descriptor_sets.len() as vk::uint32_t,
dynamic_offsets.len() as vk::uint32_t, descriptor_sets.as_ptr(),
dynamic_offsets.as_ptr()) dynamic_offsets.len() as vk::uint32_t,
dynamic_offsets.as_ptr())
} }
unsafe fn cmd_begin_render_pass(&self, unsafe fn cmd_begin_render_pass(&self,
command_buffer: vk::CommandBuffer, command_buffer: vk::CommandBuffer,
create_info: &vk::RenderPassBeginInfo, create_info: &vk::RenderPassBeginInfo,
contents: vk::SubpassContents) { contents: vk::SubpassContents) {
self.fp_v1_0().cmd_begin_render_pass(command_buffer, create_info, contents); self.fp_v1_0()
.cmd_begin_render_pass(command_buffer, create_info, contents);
} }
unsafe fn cmd_bind_pipeline(&self, unsafe fn cmd_bind_pipeline(&self,
command_buffer: vk::CommandBuffer, command_buffer: vk::CommandBuffer,
pipeline_bind_point: vk::PipelineBindPoint, pipeline_bind_point: vk::PipelineBindPoint,
pipeline: vk::Pipeline) { pipeline: vk::Pipeline) {
self.fp_v1_0().cmd_bind_pipeline(command_buffer, pipeline_bind_point, pipeline); self.fp_v1_0()
.cmd_bind_pipeline(command_buffer, pipeline_bind_point, pipeline);
} }
unsafe fn cmd_set_scissor(&self, command_buffer: vk::CommandBuffer, scissors: &[vk::Rect2D]) { unsafe fn cmd_set_scissor(&self, command_buffer: vk::CommandBuffer, scissors: &[vk::Rect2D]) {
@ -361,11 +399,12 @@ pub trait DeviceV1_0 {
buffers: &[vk::Buffer], buffers: &[vk::Buffer],
offsets: &[vk::DeviceSize]) { offsets: &[vk::DeviceSize]) {
debug_assert_eq!(buffers.len(), offsets.len()); debug_assert_eq!(buffers.len(), offsets.len());
self.fp_v1_0().cmd_bind_vertex_buffers(command_buffer, self.fp_v1_0()
first_binding, .cmd_bind_vertex_buffers(command_buffer,
buffers.len() as vk::uint32_t, first_binding,
buffers.as_ptr(), buffers.len() as vk::uint32_t,
offsets.as_ptr()); buffers.as_ptr(),
offsets.as_ptr());
} }
unsafe fn cmd_end_render_pass(&self, command_buffer: vk::CommandBuffer) { unsafe fn cmd_end_render_pass(&self, command_buffer: vk::CommandBuffer) {
@ -378,11 +417,12 @@ pub trait DeviceV1_0 {
instance_count: vk::uint32_t, instance_count: vk::uint32_t,
first_vertex: vk::uint32_t, first_vertex: vk::uint32_t,
first_instance: vk::uint32_t) { first_instance: vk::uint32_t) {
self.fp_v1_0().cmd_draw(command_buffer, self.fp_v1_0()
vertex_count, .cmd_draw(command_buffer,
instance_count, vertex_count,
first_vertex, instance_count,
first_instance); first_vertex,
first_instance);
} }
unsafe fn cmd_dispatch(&self, unsafe fn cmd_dispatch(&self,
@ -390,19 +430,18 @@ pub trait DeviceV1_0 {
group_count_x: vk::uint32_t, group_count_x: vk::uint32_t,
group_count_y: vk::uint32_t, group_count_y: vk::uint32_t,
group_count_z: vk::uint32_t) { group_count_z: vk::uint32_t) {
self.fp_v1_0().cmd_dispatch(command_buffer, self.fp_v1_0()
group_count_x, .cmd_dispatch(command_buffer, group_count_x, group_count_y, group_count_z);
group_count_y,
group_count_z);
} }
unsafe fn cmd_set_viewport(&self, unsafe fn cmd_set_viewport(&self,
command_buffer: vk::CommandBuffer, command_buffer: vk::CommandBuffer,
viewports: &[vk::Viewport]) { viewports: &[vk::Viewport]) {
self.fp_v1_0().cmd_set_viewport(command_buffer, self.fp_v1_0()
0, .cmd_set_viewport(command_buffer,
viewports.len() as vk::uint32_t, 0,
viewports.as_ptr()); viewports.len() as vk::uint32_t,
viewports.as_ptr());
} }
unsafe fn create_semaphore(&self, unsafe fn create_semaphore(&self,
@ -421,11 +460,12 @@ pub trait DeviceV1_0 {
} }
} }
unsafe fn create_graphics_pipelines(&self, unsafe fn create_graphics_pipelines
pipeline_cache: vk::PipelineCache, (&self,
create_infos: &[vk::GraphicsPipelineCreateInfo], pipeline_cache: vk::PipelineCache,
allocation_callbacks: Option<&vk::AllocationCallbacks>) create_infos: &[vk::GraphicsPipelineCreateInfo],
-> Result<Vec<vk::Pipeline>, (Vec<vk::Pipeline>, vk::Result)>{ allocation_callbacks: Option<&vk::AllocationCallbacks>)
-> Result<Vec<vk::Pipeline>, (Vec<vk::Pipeline>, vk::Result)> {
let mut pipelines = Vec::with_capacity(create_infos.len()); let mut pipelines = Vec::with_capacity(create_infos.len());
let err_code = self.fp_v1_0() let err_code = self.fp_v1_0()
.create_graphics_pipelines(self.handle(), .create_graphics_pipelines(self.handle(),
@ -437,7 +477,7 @@ pub trait DeviceV1_0 {
pipelines.set_len(create_infos.len()); pipelines.set_len(create_infos.len());
match err_code { match err_code {
vk::Result::Success => Ok(pipelines), vk::Result::Success => Ok(pipelines),
_ => Err((pipelines,err_code)), _ => Err((pipelines, err_code)),
} }
} }
@ -530,16 +570,17 @@ pub trait DeviceV1_0 {
memory_barriers: &[vk::MemoryBarrier], memory_barriers: &[vk::MemoryBarrier],
buffer_memory_barriers: &[vk::BufferMemoryBarrier], buffer_memory_barriers: &[vk::BufferMemoryBarrier],
image_memory_barriers: &[vk::ImageMemoryBarrier]) { image_memory_barriers: &[vk::ImageMemoryBarrier]) {
self.fp_v1_0().cmd_pipeline_barrier(command_buffer, self.fp_v1_0()
src_stage_mask, .cmd_pipeline_barrier(command_buffer,
dst_stage_mask, src_stage_mask,
dependency_flags, dst_stage_mask,
memory_barriers.len() as vk::uint32_t, dependency_flags,
memory_barriers.as_ptr(), memory_barriers.len() as vk::uint32_t,
buffer_memory_barriers.len() as vk::uint32_t, memory_barriers.as_ptr(),
buffer_memory_barriers.as_ptr(), buffer_memory_barriers.len() as vk::uint32_t,
image_memory_barriers.len() as vk::uint32_t, buffer_memory_barriers.as_ptr(),
image_memory_barriers.as_ptr()); image_memory_barriers.len() as vk::uint32_t,
image_memory_barriers.as_ptr());
} }
unsafe fn create_render_pass(&self, unsafe fn create_render_pass(&self,
@ -571,8 +612,7 @@ pub trait DeviceV1_0 {
} }
unsafe fn end_command_buffer(&self, command_buffer: vk::CommandBuffer) -> VkResult<()> { unsafe fn end_command_buffer(&self, command_buffer: vk::CommandBuffer) -> VkResult<()> {
let err_code = self.fp_v1_0() let err_code = self.fp_v1_0().end_command_buffer(command_buffer);
.end_command_buffer(command_buffer);
match err_code { match err_code {
vk::Result::Success => Ok(()), vk::Result::Success => Ok(()),
_ => Err(err_code), _ => Err(err_code),
@ -641,8 +681,9 @@ pub trait DeviceV1_0 {
create_info: &vk::CommandBufferAllocateInfo) create_info: &vk::CommandBufferAllocateInfo)
-> VkResult<Vec<vk::CommandBuffer>> { -> VkResult<Vec<vk::CommandBuffer>> {
let mut buffers = Vec::with_capacity(create_info.command_buffer_count as vk::size_t); let mut buffers = Vec::with_capacity(create_info.command_buffer_count as vk::size_t);
let err_code = self.fp_v1_0() let err_code =
.allocate_command_buffers(self.handle(), create_info, buffers.as_mut_ptr()); self.fp_v1_0()
.allocate_command_buffers(self.handle(), create_info, buffers.as_mut_ptr());
buffers.set_len(create_info.command_buffer_count as vk::size_t); buffers.set_len(create_info.command_buffer_count as vk::size_t);
match err_code { match err_code {
vk::Result::Success => Ok(buffers), vk::Result::Success => Ok(buffers),