From a8679459ead77b68dc9e540091144496c9bdeaa8 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Wed, 31 Jul 2019 22:39:45 -0700 Subject: [PATCH] I have kinda given up trying to wrangle this descriptorsetbuilder. Going to read more on how sprites are best handled in regards to their textures --- notes | 48 ++++++++++++++++++++++++++++ src/vkprocessor.rs | 79 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 108 insertions(+), 19 deletions(-) diff --git a/notes b/notes index eb345f39..a23a0f15 100644 --- a/notes +++ b/notes @@ -7,3 +7,51 @@ StorageImage AttachmentImage ImageAccess whose purpose is to be used as a framebuffer attachment + + + +Hello! + +Any of you guys use the Vulkano library? There is this PersistentDescriptorSetBuilder struct +which uses this fun chaining dynamic + +``` +PersistentDescriptorSet::start(layout, 0) + .add_sampled_image(sampled_image1).unwrap() + .add_sampled_image(sampled_image2).unwrap() + .add_sampled_image(sampled_image3).unwrap() + .build().unwrap(); +``` + +But it modifies the return values template values so I can't store it between loops + +``` +let mut set_builder = PersistentDescriptorSet::start(layout, 0); +for image in images { + set_builder = set_builder.add_sampled_image(image); +} +let descriptor_set = set_builder.build().unwrap(); +``` + +The gist of the error that I get is something like: + +``` +expected: +PersistentDescriptorSetBuilder, ()> +got: +PersistentDescriptorSetBuilder, ((), PersistentDescriptorSetImg>>)> +``` + +So it's adding tuples of tuples of tuples of tuples of tuples each time I chain a +.add_sampled_image() call. I really really want to be able to do this dynamically in +a loop; I've tried this neat iter().fold() thinking that if I didn't explicitly +overwrite the previous returned value, rust would figure it out. It didn't + +``` +let descriptor_set = images.iter().fold( + PersistentDescriptorSet::start(layout, 0) + ,|a, &b| a.add_image(b)) + .unwrap()).build().unwrap(); +``` + +How do I do this dynamically? \ No newline at end of file diff --git a/src/vkprocessor.rs b/src/vkprocessor.rs index 827c99a3..f3928192 100644 --- a/src/vkprocessor.rs +++ b/src/vkprocessor.rs @@ -1,6 +1,7 @@ use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer, DeviceLocalBuffer, ImmutableBuffer, BufferAccess}; use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState}; -use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, StdDescriptorPoolAlloc, PersistentDescriptorSetBuilder}; +use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, StdDescriptorPoolAlloc, PersistentDescriptorSetBuilder, FixedSizeDescriptorSetsPool, StdDescriptorPool}; +use vulkano::descriptor::descriptor_set::collection::DescriptorSetsCollection; use vulkano::device::{Device, DeviceExtensions, QueuesIter, Queue}; use vulkano::instance::{Instance, InstanceExtensions, PhysicalDevice, QueueFamily}; use vulkano::pipeline::{ComputePipeline, GraphicsPipeline, GraphicsPipelineAbstract}; @@ -42,6 +43,53 @@ use crate::vkprocessor::compute_kernel::ComputeKernel; mod shader_kernels; use crate::vkprocessor::shader_kernels::ShaderKernels; +use vulkano::descriptor::descriptor::DescriptorDesc; + +// +//#[derive(Clone)] +//struct ImageBuffers { +// pub image_buffers : Vec>, +//} +// +//impl ImageBuffers { +// +// pub fn new() -> ImageBuffers { +// ImageBuffers { +// image_buffers: vec![] +// } +// } +// pub fn add_image(self) -> Self { +// +// self +// } +//} +// +//unsafe impl DescriptorSetsCollection for ImageBuffers { +// fn into_vec(self) -> Vec> { +// unimplemented!() +// } +// +// fn num_bindings_in_set(&self, set: usize) -> Option { +// unimplemented!() +// } +// +// fn descriptor(&self, set: usize, binding: usize) -> Option { +// unimplemented!() +// } +//} + + + + + + + + + + + + + #[derive(Default, Debug, Clone)] @@ -103,7 +151,6 @@ unsafe impl SpecializationConstants for SimpleSpecializationConstants { } } - pub struct VkProcessor<'a> { pub shader_kernels: Option, pub compute_kernel: Option, @@ -133,7 +180,7 @@ pub struct VkProcessor<'a> { pub image_buffer_store : Vec>, - + // pub image_buffers_obj : ImageBuffers, } @@ -181,7 +228,8 @@ impl<'a> VkProcessor<'a> { dynamic_state: DynamicState { line_width: None, viewports: None, scissors: None }, graphics_image_swap_buffer: None, - image_buffer_store: vec![] + image_buffer_store: vec![], + //image_buffers_obj: ImageBuffers::new(), } } @@ -320,18 +368,7 @@ impl<'a> VkProcessor<'a> { usage) }; - let sampler = Sampler::new(self.device.clone(), Filter::Linear, Filter::Linear, - MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat, - SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap(); - - // img_set is only used in the run()'s command buffer construction - // So, adding a get image set function, I can just build lazily - - self.img_set = Some(Arc::new(PersistentDescriptorSet::start( - self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(), 0) - .add_sampled_image(texture.clone(), sampler.clone()).unwrap() - .add_image(compute_transfer_image.clone().unwrap().clone()).unwrap() - .build().unwrap())); + self.image_buffer_store.push(Box::new(texture.clone())); self.graphics_image_buffer = Some(texture.clone()); self.graphics_image_swap_buffer = Some(compute_transfer_image.clone().unwrap()); @@ -348,6 +385,12 @@ impl<'a> VkProcessor<'a> { MipmapMode::Nearest, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat, SamplerAddressMode::Repeat, 0.0, 1.0, 0.0, 0.0).unwrap(); + let mut descriptor_sets = PersistentDescriptorSet::start( + self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(), 0 + ); + + let descriptor_sets = descriptor_sets.add_sampled_image(self.graphics_image_buffer.clone().unwrap().clone(), sampler.clone()).unwrap(); + let o : Box = Box::new( PersistentDescriptorSet::start( self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(), 0 @@ -355,7 +398,6 @@ impl<'a> VkProcessor<'a> { .add_sampled_image(self.graphics_image_buffer.clone().unwrap().clone(), sampler.clone()).unwrap() .add_image(self.graphics_image_swap_buffer.clone().unwrap().clone()).unwrap() .build().unwrap()); - o } @@ -425,8 +467,7 @@ impl<'a> VkProcessor<'a> { .draw(self.shader_kernels.clone().unwrap().graphics_pipeline.clone().unwrap().clone(), &self.dynamic_state.clone(), v, - //self.img_set.clone().unwrap().clone(), ()) - self.get_image_set(), ()) + vec![self.get_image_set()], ()) .unwrap() .end_render_pass()