Skip to content

Commit

Permalink
fixes clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Russo committed Feb 10, 2019
1 parent d2a6383 commit 84c1838
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
29 changes: 17 additions & 12 deletions src/bin/24_image_sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ use vulkano::buffer::{
};
use vulkano::descriptor::descriptor_set::{
FixedSizeDescriptorSetsPool,
FixedSizeDescriptorSet
FixedSizeDescriptorSet,
PersistentDescriptorSetBuf
};

use image::GenericImageView;
Expand All @@ -78,7 +79,7 @@ const VALIDATION_LAYERS: &[&str] = &[
"VK_LAYER_LUNARG_standard_validation"
];

const TEXTURE_PATH: &'static str = "src/bin/23_statue.jpg";
const TEXTURE_PATH: &str = "src/bin/23_statue.jpg";

/// Required device extensions
fn device_extensions() -> DeviceExtensions {
Expand Down Expand Up @@ -119,6 +120,7 @@ impl Vertex {
}
impl_vertex!(Vertex, pos, color);

#[allow(dead_code)]
#[derive(Copy, Clone)]
struct UniformBufferObject {
model: glm::Mat4,
Expand All @@ -139,6 +141,8 @@ fn indices() -> [u16; 6] {
[0, 1, 2, 2, 3, 0]
}

type DescriptorSetResources = ((), PersistentDescriptorSetBuf<Arc<CpuAccessibleBuffer<UniformBufferObject>>>);

struct HelloTriangleApplication {
instance: Arc<Instance>,
#[allow(unused)]
Expand All @@ -161,14 +165,16 @@ struct HelloTriangleApplication {

swap_chain_framebuffers: Vec<Arc<FramebufferAbstract + Send + Sync>>,

#[allow(dead_code)]
texture_image: Arc<ImmutableImage<Format>>,
#[allow(dead_code)]
image_sampler: Arc<Sampler>,

vertex_buffer: Arc<BufferAccess + Send + Sync>,
index_buffer: Arc<TypedBufferAccess<Content=[u16]> + Send + Sync>,
uniform_buffers: Vec<Arc<CpuAccessibleBuffer<UniformBufferObject>>>,

descriptor_sets: Vec<Arc<FixedSizeDescriptorSet<Arc<GraphicsPipelineAbstract + Send + Sync>, ((), vulkano::descriptor::descriptor_set::PersistentDescriptorSetBuf<std::sync::Arc<vulkano::buffer::CpuAccessibleBuffer<UniformBufferObject>>>)>>>,
descriptor_sets: Vec<Arc<FixedSizeDescriptorSet<Arc<GraphicsPipelineAbstract + Send + Sync>, DescriptorSetResources>>>,

command_buffers: Vec<Arc<AutoCommandBuffer>>,

Expand Down Expand Up @@ -272,7 +278,7 @@ impl HelloTriangleApplication {
let required_extensions = Self::get_required_extensions();

if ENABLE_VALIDATION_LAYERS && Self::check_validation_layer_support() {
Instance::new(Some(&app_info), &required_extensions, VALIDATION_LAYERS.iter().map(|s| *s))
Instance::new(Some(&app_info), &required_extensions, VALIDATION_LAYERS.iter().cloned())
.expect("failed to create Vulkan instance")
} else {
Instance::new(Some(&app_info), &required_extensions, None)
Expand Down Expand Up @@ -498,7 +504,7 @@ impl HelloTriangleApplication {
}

fn create_framebuffers(
swap_chain_images: &Vec<Arc<SwapchainImage<Window>>>,
swap_chain_images: &[Arc<SwapchainImage<Window>>],
render_pass: &Arc<RenderPassAbstract + Send + Sync>
) -> Vec<Arc<FramebufferAbstract + Send + Sync>> {
swap_chain_images.iter()
Expand Down Expand Up @@ -528,7 +534,7 @@ impl HelloTriangleApplication {

future.flush().unwrap();

return image_view;
image_view
}

fn create_image_sampler(device: &Arc<Device>) -> Arc<Sampler> {
Expand Down Expand Up @@ -590,8 +596,8 @@ impl HelloTriangleApplication {

fn create_descriptor_sets(
pool: &Arc<Mutex<FixedSizeDescriptorSetsPool<Arc<GraphicsPipelineAbstract + Send + Sync>>>>,
uniform_buffers: &Vec<Arc<CpuAccessibleBuffer<UniformBufferObject>>>,
) -> Vec<Arc<FixedSizeDescriptorSet<Arc<GraphicsPipelineAbstract + Send + Sync>, ((), vulkano::descriptor::descriptor_set::PersistentDescriptorSetBuf<std::sync::Arc<vulkano::buffer::CpuAccessibleBuffer<UniformBufferObject>>>)>>>
uniform_buffers: &[Arc<CpuAccessibleBuffer<UniformBufferObject>>],
) -> Vec<Arc<FixedSizeDescriptorSet<Arc<GraphicsPipelineAbstract + Send + Sync>, DescriptorSetResources>>>
{
uniform_buffers
.iter()
Expand Down Expand Up @@ -713,9 +719,8 @@ impl HelloTriangleApplication {

let mut done = false;
self.events_loop.poll_events(|ev| {
match ev {
Event::WindowEvent { event: WindowEvent::CloseRequested, .. } => done = true,
_ => ()
if let Event::WindowEvent { event: WindowEvent::CloseRequested, .. } = ev {
done = true
}
});
if done {
Expand Down Expand Up @@ -769,7 +774,7 @@ impl HelloTriangleApplication {

fn update_uniform_buffer(start_time: Instant, dimensions: [f32; 2]) -> UniformBufferObject {
let duration = Instant::now().duration_since(start_time);
let elapsed = (duration.as_secs() * 1000) + duration.subsec_millis() as u64;
let elapsed = (duration.as_secs() * 1000) + u64::from(duration.subsec_millis());

let identity_matrix = glm::mat4(
1.0, 0.0, 0.0, 0.0,
Expand Down
23 changes: 16 additions & 7 deletions src/bin/24_image_sampler.rs.diff
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
--- a/23_images.rs
+++ b/24_image_sampler.rs
@@ -69,6 +69,7 @@ use vulkano::descriptor::descriptor_set::{
@@ -70,6 +70,7 @@ use vulkano::descriptor::descriptor_set::{
};

use image::GenericImageView;
+use vulkano::sampler::Sampler;

const WIDTH: u32 = 800;
const HEIGHT: u32 = 600;
@@ -161,6 +162,7 @@ struct HelloTriangleApplication {
swap_chain_framebuffers: Vec<Arc<FramebufferAbstract + Send + Sync>>,
@@ -166,6 +167,8 @@ struct HelloTriangleApplication {

#[allow(dead_code)]
texture_image: Arc<ImmutableImage<Format>>,
+ #[allow(dead_code)]
+ image_sampler: Arc<Sampler>,

vertex_buffer: Arc<BufferAccess + Send + Sync>,
index_buffer: Arc<TypedBufferAccess<Content=[u16]> + Send + Sync>,
@@ -198,6 +200,7 @@ impl HelloTriangleApplication {
@@ -203,6 +206,7 @@ impl HelloTriangleApplication {
let start_time = Instant::now();

let texture_image = Self::create_texture_image(&graphics_queue);
+ let image_sampler = Self::create_image_sampler(&device);

let vertex_buffer = Self::create_vertex_buffer(&graphics_queue);
let index_buffer = Self::create_index_buffer(&graphics_queue);
@@ -230,6 +233,7 @@ impl HelloTriangleApplication {
@@ -235,6 +239,7 @@ impl HelloTriangleApplication {
swap_chain_framebuffers,

texture_image,
+ image_sampler,

vertex_buffer,
index_buffer,
@@ -527,6 +531,10 @@ impl HelloTriangleApplication {
return image_view;
@@ -532,6 +537,10 @@ impl HelloTriangleApplication {
image_view
}

+ fn create_image_sampler(device: &Arc<Device>) -> Arc<Sampler> {
Expand All @@ -43,3 +44,11 @@
fn create_vertex_buffer(graphics_queue: &Arc<Queue>) -> Arc<BufferAccess + Send + Sync> {
let (buffer, future) = ImmutableBuffer::from_iter(
vertices().iter().cloned(), BufferUsage::vertex_buffer(),
@@ -585,7 +594,6 @@ impl HelloTriangleApplication {
)
}

-
fn create_descriptor_sets(
pool: &Arc<Mutex<FixedSizeDescriptorSetsPool<Arc<GraphicsPipelineAbstract + Send + Sync>>>>,
uniform_buffers: &[Arc<CpuAccessibleBuffer<UniformBufferObject>>],

0 comments on commit 84c1838

Please sign in to comment.