From d1b83a5192af1930e0b873efbf5e252e89e8ef84 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 23 Jun 2017 10:32:49 +0200 Subject: [PATCH] Fix some warnings and examples --- examples/src/bin/basic-compute-shader.rs | 1 - vulkano/src/command_buffer/auto.rs | 21 +++++++ vulkano/src/command_buffer/synced.rs | 62 +++++++++---------- vulkano/src/command_buffer/sys.rs | 25 +++----- .../command_buffer/validity/dynamic_state.rs | 4 -- .../descriptor/descriptor_set/collection.rs | 1 - 6 files changed, 58 insertions(+), 56 deletions(-) diff --git a/examples/src/bin/basic-compute-shader.rs b/examples/src/bin/basic-compute-shader.rs index 704b7ed62..fcd5ad141 100644 --- a/examples/src/bin/basic-compute-shader.rs +++ b/examples/src/bin/basic-compute-shader.rs @@ -22,7 +22,6 @@ extern crate vulkano_shader_derive; use vulkano::buffer::BufferUsage; use vulkano::buffer::CpuAccessibleBuffer; use vulkano::command_buffer::AutoCommandBufferBuilder; -use vulkano::command_buffer::CommandBufferBuilder; use vulkano::device::Device; use vulkano::device::DeviceExtensions; use vulkano::instance::Instance; diff --git a/vulkano/src/command_buffer/auto.rs b/vulkano/src/command_buffer/auto.rs index fde68977f..5a53229e9 100644 --- a/vulkano/src/command_buffer/auto.rs +++ b/vulkano/src/command_buffer/auto.rs @@ -197,6 +197,27 @@ impl

AutoCommandBufferBuilder

{ } } + #[inline] + pub fn dispatch(mut self, dimensions: [u32; 3], pipeline: Cp, sets: S, constants: Pc) + -> Result + where Cp: ComputePipelineAbstract + Send + Sync + 'static + Clone, // TODO: meh for Clone + S: DescriptorSetsCollection, + { + unsafe { + // TODO: missing checks + + if let StateCacherOutcome::NeedChange = self.state_cacher.bind_compute_pipeline(&pipeline) { + self.inner.bind_pipeline_compute(pipeline.clone()); + } + + push_constants(&mut self.inner, pipeline.clone(), constants); + descriptor_sets(&mut self.inner, false, pipeline.clone(), sets); + + self.inner.dispatch(dimensions); + Ok(self) + } + } + #[inline] pub fn draw(mut self, pipeline: Gp, dynamic: DynamicState, vertices: V, sets: S, constants: Pc) -> Result diff --git a/vulkano/src/command_buffer/synced.rs b/vulkano/src/command_buffer/synced.rs index ef9da566e..d7b4492ac 100644 --- a/vulkano/src/command_buffer/synced.rs +++ b/vulkano/src/command_buffer/synced.rs @@ -9,8 +9,6 @@ use std::collections::hash_map::Entry; use std::hash::{Hash, Hasher}; -use std::mem; -use std::ops::DerefMut; use std::sync::Arc; use std::sync::Mutex; use fnv::FnvHashMap; @@ -30,13 +28,10 @@ use command_buffer::sys::UnsafeCommandBufferBuilderBindVertexBuffer; use command_buffer::sys::UnsafeCommandBufferBuilderBufferImageCopy; use command_buffer::sys::UnsafeCommandBufferBuilderPipelineBarrier; use descriptor::descriptor_set::DescriptorSet; -use descriptor::descriptor_set::UnsafeDescriptorSet; use descriptor::descriptor::ShaderStages; use descriptor::pipeline_layout::PipelineLayoutAbstract; use format::ClearValue; -use framebuffer::Framebuffer; use framebuffer::FramebufferAbstract; -use framebuffer::RenderPass; use framebuffer::RenderPassAbstract; use image::ImageLayout; use image::ImageAccess; @@ -47,7 +42,6 @@ use device::Queue; use pipeline::ComputePipelineAbstract; use pipeline::GraphicsPipelineAbstract; use pipeline::input_assembly::IndexType; -use pipeline::vertex::VertexSource; use pipeline::viewport::Scissor; use pipeline::viewport::Viewport; use sync::AccessCheckError; @@ -135,16 +129,16 @@ impl

BuilderKey

{ #[inline] fn conflicts_buffer_all(&self, buf: &BufferAccess) -> bool { - let mut commands_lock = self.commands.lock().unwrap(); + let commands_lock = self.commands.lock().unwrap(); // TODO: put the conflicts_* methods directly on the Command trait to avoid an indirect call? match self.resource_ty { KeyTy::Buffer => { - let mut c = &commands_lock.commands[self.command_id]; + let c = &commands_lock.commands[self.command_id]; c.buffer(self.resource_index).conflicts_buffer_all(buf) }, KeyTy::Image => { - let mut c = &commands_lock.commands[self.command_id]; + let c = &commands_lock.commands[self.command_id]; c.image(self.resource_index).conflicts_buffer_all(buf) }, } @@ -152,16 +146,16 @@ impl

BuilderKey

{ #[inline] fn conflicts_image_all(&self, img: &ImageAccess) -> bool { - let mut commands_lock = self.commands.lock().unwrap(); + let commands_lock = self.commands.lock().unwrap(); // TODO: put the conflicts_* methods directly on the Command trait to avoid an indirect call? match self.resource_ty { KeyTy::Buffer => { - let mut c = &commands_lock.commands[self.command_id]; + let c = &commands_lock.commands[self.command_id]; c.buffer(self.resource_index).conflicts_image_all(img) }, KeyTy::Image => { - let mut c = &commands_lock.commands[self.command_id]; + let c = &commands_lock.commands[self.command_id]; c.image(self.resource_index).conflicts_image_all(img) }, } @@ -172,15 +166,15 @@ impl

PartialEq for BuilderKey

{ #[inline] fn eq(&self, other: &BuilderKey

) -> bool { debug_assert!(Arc::ptr_eq(&self.commands, &other.commands)); - let mut commands_lock = self.commands.lock().unwrap(); + let commands_lock = self.commands.lock().unwrap(); match other.resource_ty { KeyTy::Buffer => { - let mut c = &commands_lock.commands[other.command_id]; + let c = &commands_lock.commands[other.command_id]; self.conflicts_buffer_all(c.buffer(other.resource_index)) }, KeyTy::Image => { - let mut c = &commands_lock.commands[other.command_id]; + let c = &commands_lock.commands[other.command_id]; self.conflicts_image_all(c.image(other.resource_index)) }, } @@ -193,15 +187,15 @@ impl

Eq for BuilderKey

{ impl

Hash for BuilderKey

{ #[inline] fn hash(&self, state: &mut H) { - let mut commands_lock = self.commands.lock().unwrap(); + let commands_lock = self.commands.lock().unwrap(); match self.resource_ty { KeyTy::Buffer => { - let mut c = &commands_lock.commands[self.command_id]; + let c = &commands_lock.commands[self.command_id]; c.buffer(self.resource_index).conflict_key_all() }, KeyTy::Image => { - let mut c = &commands_lock.commands[self.command_id]; + let c = &commands_lock.commands[self.command_id]; c.image(self.resource_index).conflict_key_all() }, }.hash(state) @@ -282,7 +276,7 @@ impl

SyncCommandBufferBuilder

{ debug_assert!(exclusive || start_layout == end_layout); let (first_unflushed, latest_command_id) = { - let mut commands_lock = self.commands.lock().unwrap(); + let commands_lock = self.commands.lock().unwrap(); debug_assert!(commands_lock.commands.len() >= 1); (commands_lock.first_unflushed, commands_lock.commands.len() - 1) }; @@ -1465,16 +1459,16 @@ impl<'a> CbKey<'a> { fn conflicts_buffer_all(&self, buf: &BufferAccess) -> bool { match *self { CbKey::Command { ref commands, command_id, resource_ty, resource_index } => { - let mut commands_lock = commands.lock().unwrap(); + let commands_lock = commands.lock().unwrap(); // TODO: put the conflicts_* methods directly on the FinalCommand trait to avoid an indirect call? match resource_ty { KeyTy::Buffer => { - let mut c = &commands_lock[command_id]; + let c = &commands_lock[command_id]; c.buffer(resource_index).conflicts_buffer_all(buf) }, KeyTy::Image => { - let mut c = &commands_lock[command_id]; + let c = &commands_lock[command_id]; c.image(resource_index).conflicts_buffer_all(buf) }, } @@ -1489,16 +1483,16 @@ impl<'a> CbKey<'a> { fn conflicts_image_all(&self, img: &ImageAccess) -> bool { match *self { CbKey::Command { ref commands, command_id, resource_ty, resource_index } => { - let mut commands_lock = commands.lock().unwrap(); + let commands_lock = commands.lock().unwrap(); // TODO: put the conflicts_* methods directly on the Command trait to avoid an indirect call? match resource_ty { KeyTy::Buffer => { - let mut c = &commands_lock[command_id]; + let c = &commands_lock[command_id]; c.buffer(resource_index).conflicts_image_all(img) }, KeyTy::Image => { - let mut c = &commands_lock[command_id]; + let c = &commands_lock[command_id]; c.image(resource_index).conflicts_image_all(img) }, } @@ -1521,15 +1515,15 @@ impl<'a> PartialEq for CbKey<'a> { other.conflicts_image_all(a) }, CbKey::Command { ref commands, command_id, resource_ty, resource_index } => { - let mut commands_lock = commands.lock().unwrap(); + let commands_lock = commands.lock().unwrap(); match resource_ty { KeyTy::Buffer => { - let mut c = &commands_lock[command_id]; + let c = &commands_lock[command_id]; other.conflicts_buffer_all(c.buffer(resource_index)) }, KeyTy::Image => { - let mut c = &commands_lock[command_id]; + let c = &commands_lock[command_id]; other.conflicts_image_all(c.image(resource_index)) }, } @@ -1564,15 +1558,15 @@ impl<'a> Hash for CbKey<'a> { fn hash(&self, state: &mut H) { match *self { CbKey::Command { ref commands, command_id, resource_ty, resource_index } => { - let mut commands_lock = commands.lock().unwrap(); + let commands_lock = commands.lock().unwrap(); match resource_ty { KeyTy::Buffer => { - let mut c = &commands_lock[command_id]; + let c = &commands_lock[command_id]; c.buffer(resource_index).conflict_key_all().hash(state) }, KeyTy::Image => { - let mut c = &commands_lock[command_id]; + let c = &commands_lock[command_id]; c.image(resource_index).conflict_key_all().hash(state) }, } @@ -1603,11 +1597,11 @@ unsafe impl

CommandBuffer for SyncCommandBuffer

{ _ => unreachable!() }; - let mut commands_lock = commands.lock().unwrap(); + let commands_lock = commands.lock().unwrap(); match resource_ty { KeyTy::Buffer => { - let mut cmd = &commands_lock[command_id]; + let cmd = &commands_lock[command_id]; let buf = cmd.buffer(resource_index); let prev_err = match future.check_buffer_access(&buf, entry.exclusive, queue) { @@ -1625,7 +1619,7 @@ unsafe impl

CommandBuffer for SyncCommandBuffer

{ } }, KeyTy::Image => { - let mut cmd = &commands_lock[command_id]; + let cmd = &commands_lock[command_id]; let img = cmd.image(resource_index); let prev_err = match future.check_image_access(img, entry.initial_layout, diff --git a/vulkano/src/command_buffer/sys.rs b/vulkano/src/command_buffer/sys.rs index 99547678c..d103f4e37 100644 --- a/vulkano/src/command_buffer/sys.rs +++ b/vulkano/src/command_buffer/sys.rs @@ -17,17 +17,14 @@ use smallvec::SmallVec; use buffer::BufferAccess; use buffer::BufferInner; use command_buffer::CommandBuffer; -use command_buffer::CommandBufferExecError; use command_buffer::pool::CommandPool; use command_buffer::pool::CommandPoolBuilderAlloc; use command_buffer::pool::CommandPoolAlloc; use descriptor::descriptor::ShaderStages; use descriptor::pipeline_layout::PipelineLayoutAbstract; -use descriptor::descriptor_set::DescriptorSet; use descriptor::descriptor_set::UnsafeDescriptorSet; use device::Device; use device::DeviceOwned; -use device::Queue; use format::ClearValue; use framebuffer::EmptySinglePassRenderPassDesc; use framebuffer::Framebuffer; @@ -43,10 +40,8 @@ use pipeline::GraphicsPipelineAbstract; use pipeline::input_assembly::IndexType; use pipeline::viewport::Scissor; use pipeline::viewport::Viewport; -use sync::AccessCheckError; use sync::AccessFlagBits; use sync::PipelineStages; -use sync::GpuFuture; use sync::Event; use OomError; use VulkanObject; @@ -715,18 +710,16 @@ impl

UnsafeCommandBufferBuilder

{ return; } - unsafe { - let vk = self.device().pointers(); - let cmd = self.internal_object(); + let vk = self.device().pointers(); + let cmd = self.internal_object(); - vk.CmdPipelineBarrier(cmd, command.src_stage_mask, command.dst_stage_mask, - command.dependency_flags, command.memory_barriers.len() as u32, - command.memory_barriers.as_ptr(), - command.buffer_barriers.len() as u32, - command.buffer_barriers.as_ptr(), - command.image_barriers.len() as u32, - command.image_barriers.as_ptr()); - } + vk.CmdPipelineBarrier(cmd, command.src_stage_mask, command.dst_stage_mask, + command.dependency_flags, command.memory_barriers.len() as u32, + command.memory_barriers.as_ptr(), + command.buffer_barriers.len() as u32, + command.buffer_barriers.as_ptr(), + command.image_barriers.len() as u32, + command.image_barriers.as_ptr()); } /// Calls `vkCmdPushConstants` on the builder. diff --git a/vulkano/src/command_buffer/validity/dynamic_state.rs b/vulkano/src/command_buffer/validity/dynamic_state.rs index 2688763d5..f4ed10694 100644 --- a/vulkano/src/command_buffer/validity/dynamic_state.rs +++ b/vulkano/src/command_buffer/validity/dynamic_state.rs @@ -10,12 +10,8 @@ use std::error; use std::fmt; -use buffer::BufferAccess; use command_buffer::DynamicState; -use device::Device; -use device::DeviceOwned; use pipeline::GraphicsPipelineAbstract; -use VulkanObject; /// Checks whether states that are about to be set are correct. pub fn check_dynamic_state_validity(pipeline: &Pl, state: &DynamicState) diff --git a/vulkano/src/descriptor/descriptor_set/collection.rs b/vulkano/src/descriptor/descriptor_set/collection.rs index 5b0628031..97f87f67b 100644 --- a/vulkano/src/descriptor/descriptor_set/collection.rs +++ b/vulkano/src/descriptor/descriptor_set/collection.rs @@ -12,7 +12,6 @@ use buffer::BufferAccess; use descriptor::descriptor::DescriptorDesc; use descriptor::descriptor_set::DescriptorSet; use descriptor::descriptor_set::DescriptorSetDesc; -use descriptor::descriptor_set::UnsafeDescriptorSet; use image::ImageAccess; /// A collection of descriptor set objects.