|
|
@ -262,9 +262,16 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
options.add_macro_definition("SETTING_BUCKETS_START", Some("2"));
|
|
|
|
options.add_macro_definition("SETTING_BUCKETS_START", Some("2"));
|
|
|
|
options.add_macro_definition("SETTING_BUCKETS_LEN", Some("2"));
|
|
|
|
options.add_macro_definition("SETTING_BUCKETS_LEN", Some("2"));
|
|
|
|
|
|
|
|
|
|
|
|
let shader =
|
|
|
|
let shader = sr::load(vertex_shader_path, fragment_shader_path).expect("");
|
|
|
|
sr::load(vertex_shader_path, fragment_shader_path)
|
|
|
|
// let shader = match sr::load(vertex_shader_path, fragment_shader_path) {
|
|
|
|
.expect("Failed to compile");
|
|
|
|
// Ok(t) => t,
|
|
|
|
|
|
|
|
// Err(e) => {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// panic!(e);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let vulkano_entry =
|
|
|
|
let vulkano_entry =
|
|
|
|
sr::parse(&shader)
|
|
|
|
sr::parse(&shader)
|
|
|
@ -327,42 +334,6 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
|
|
self.render_pass = Some(render_pass);
|
|
|
|
self.render_pass = Some(render_pass);
|
|
|
|
|
|
|
|
|
|
|
|
let (texture, tex_future) = {
|
|
|
|
|
|
|
|
let image = image::load_from_memory_with_format(include_bytes!("../resources/images/funky-bird.jpg"),
|
|
|
|
|
|
|
|
ImageFormat::JPEG).unwrap().to_rgba();
|
|
|
|
|
|
|
|
let dimensions = image.dimensions();
|
|
|
|
|
|
|
|
let image_data = image.into_raw().clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableImage::from_iter(
|
|
|
|
|
|
|
|
image_data.iter().cloned(),
|
|
|
|
|
|
|
|
Dimensions::Dim2d { width: dimensions.0, height: dimensions.1 },
|
|
|
|
|
|
|
|
Format::R8G8B8A8Srgb,
|
|
|
|
|
|
|
|
self.queue.clone()
|
|
|
|
|
|
|
|
).unwrap()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let attachment_image = {
|
|
|
|
|
|
|
|
let image = image::load_from_memory_with_format(include_bytes!("../resources/images/funky-bird.jpg"),
|
|
|
|
|
|
|
|
ImageFormat::JPEG).unwrap().to_rgba();
|
|
|
|
|
|
|
|
let dimensions = image.dimensions();
|
|
|
|
|
|
|
|
let image_data = image.into_raw().clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut usage = ImageUsage::none();
|
|
|
|
|
|
|
|
usage.transfer_destination = true;
|
|
|
|
|
|
|
|
usage.storage = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AttachmentImage::with_usage(
|
|
|
|
|
|
|
|
self.device.clone(),
|
|
|
|
|
|
|
|
[dimensions.0, dimensions.1],
|
|
|
|
|
|
|
|
Format::R8G8B8A8Uint,
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Before we draw we have to create what is called a pipeline. This is similar to an OpenGL
|
|
|
|
// Before we draw we have to create what is called a pipeline. This is similar to an OpenGL
|
|
|
|
// program, but much more specific.
|
|
|
|
// program, but much more specific.
|
|
|
|
let pipeline = GraphicsPipeline::start()
|
|
|
|
let pipeline = GraphicsPipeline::start()
|
|
|
@ -396,16 +367,8 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
.build(self.device.clone())
|
|
|
|
.build(self.device.clone())
|
|
|
|
.unwrap();
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.graphics_pipeline = Some(Arc::new(pipeline));
|
|
|
|
self.graphics_pipeline = Some(Arc::new(pipeline));
|
|
|
|
|
|
|
|
|
|
|
|
self.img_set = Some(Arc::new(PersistentDescriptorSet::start(self.graphics_pipeline.clone().unwrap().clone(), 0)
|
|
|
|
|
|
|
|
.add_sampled_image(texture.clone(), sampler.clone()).unwrap()
|
|
|
|
|
|
|
|
.add_image(attachment_image.clone().unwrap().clone()).unwrap()
|
|
|
|
|
|
|
|
.build().unwrap()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.graphics_image_buffer = Some(texture.clone());
|
|
|
|
|
|
|
|
self.graphics_iamge_swap_buffer = Some(attachment_image.clone().unwrap());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -430,6 +393,150 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
self.images = Some(new_images);
|
|
|
|
self.images = Some(new_images);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn load_buffers(&mut self, image_filename: String)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let project_root =
|
|
|
|
|
|
|
|
std::env::current_dir()
|
|
|
|
|
|
|
|
.expect("failed to get root directory");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut compute_path = project_root.clone();
|
|
|
|
|
|
|
|
compute_path.push(PathBuf::from("resources/images/"));
|
|
|
|
|
|
|
|
compute_path.push(PathBuf::from(image_filename));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let img = image::open(compute_path).expect("Couldn't find image");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.xy = img.dimensions();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data_length = self.xy.0 * self.xy.1 * 4;
|
|
|
|
|
|
|
|
let pixel_count = img.raw_pixels().len();
|
|
|
|
|
|
|
|
println!("Pixel count {}", pixel_count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pixel_count != data_length as usize {
|
|
|
|
|
|
|
|
println!("Creating apha channel...");
|
|
|
|
|
|
|
|
for i in img.raw_pixels().iter() {
|
|
|
|
|
|
|
|
if (self.image_buffer.len() + 1) % 4 == 0 {
|
|
|
|
|
|
|
|
self.image_buffer.push(255);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.image_buffer.push(*i);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.image_buffer.push(255);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
self.image_buffer = img.raw_pixels();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("Buffer length {}", self.image_buffer.len());
|
|
|
|
|
|
|
|
println!("Size {:?}", self.xy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("Allocating Buffers...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pull out the image data and place it in a buffer for the kernel to write to and for us to read from
|
|
|
|
|
|
|
|
let write_buffer = {
|
|
|
|
|
|
|
|
let mut buff = self.image_buffer.iter();
|
|
|
|
|
|
|
|
let data_iter = (0..data_length).map(|n| *(buff.next().unwrap()));
|
|
|
|
|
|
|
|
CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::all(), data_iter).unwrap()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pull out the image data and place it in a buffer for the kernel to read from
|
|
|
|
|
|
|
|
let read_buffer = {
|
|
|
|
|
|
|
|
let mut buff = self.image_buffer.iter();
|
|
|
|
|
|
|
|
let data_iter = (0..data_length).map(|n| *(buff.next().unwrap()));
|
|
|
|
|
|
|
|
CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::all(), data_iter).unwrap()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// A buffer to hold many i32 values to use as settings
|
|
|
|
|
|
|
|
let settings_buffer = {
|
|
|
|
|
|
|
|
let vec = vec![self.xy.0, self.xy.1];
|
|
|
|
|
|
|
|
let mut buff = vec.iter();
|
|
|
|
|
|
|
|
let data_iter =
|
|
|
|
|
|
|
|
(0..2).map(|n| *(buff.next().unwrap()));
|
|
|
|
|
|
|
|
CpuAccessibleBuffer::from_iter(self.device.clone(),
|
|
|
|
|
|
|
|
BufferUsage::all(),
|
|
|
|
|
|
|
|
data_iter).unwrap()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("Done");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the data descriptor set for our previously created shader pipeline
|
|
|
|
|
|
|
|
let mut set =
|
|
|
|
|
|
|
|
PersistentDescriptorSet::start(self.compute_pipeline.clone().unwrap().clone(), 0)
|
|
|
|
|
|
|
|
.add_buffer(write_buffer.clone()).unwrap()
|
|
|
|
|
|
|
|
.add_buffer(read_buffer.clone()).unwrap()
|
|
|
|
|
|
|
|
.add_buffer(settings_buffer.clone()).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.compute_set = Some(Arc::new(set.build().unwrap()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.img_buffers.push(write_buffer);
|
|
|
|
|
|
|
|
self.img_buffers.push(read_buffer);
|
|
|
|
|
|
|
|
self.settings_buffer = Some(settings_buffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We now create a buffer that will store the shape of our triangle.
|
|
|
|
|
|
|
|
let vertex_buffer = {
|
|
|
|
|
|
|
|
vulkano::impl_vertex!(tVertex, position);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::all(), [
|
|
|
|
|
|
|
|
tVertex { position: [-1.0, -1.0 ] },
|
|
|
|
|
|
|
|
tVertex { position: [-1.0, 1.0 ] },
|
|
|
|
|
|
|
|
tVertex { position: [ 1.0, 1.0 ] },
|
|
|
|
|
|
|
|
tVertex { position: [ 1.0, -1.0 ] },
|
|
|
|
|
|
|
|
].iter().cloned()).unwrap()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.vertex_buffer = Some(vertex_buffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let (texture, tex_future) = {
|
|
|
|
|
|
|
|
let image = image::load_from_memory_with_format(include_bytes!("../resources/images/funky-bird.jpg"),
|
|
|
|
|
|
|
|
ImageFormat::JPEG).unwrap().to_rgba();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("{}", image.len());
|
|
|
|
|
|
|
|
println!("{}", self.image_buffer.len());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let dimensions = image.dimensions();
|
|
|
|
|
|
|
|
let image_data = image.into_raw().clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImmutableImage::from_iter(
|
|
|
|
|
|
|
|
image_data.iter().cloned(),
|
|
|
|
|
|
|
|
Dimensions::Dim2d { width: dimensions.0, height: dimensions.1 },
|
|
|
|
|
|
|
|
Format::R8G8B8A8Srgb,
|
|
|
|
|
|
|
|
self.queue.clone()
|
|
|
|
|
|
|
|
// self.image_buffer.iter().cloned(),
|
|
|
|
|
|
|
|
// Format::R8G8B8A8Uint,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
).unwrap()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let attachment_image = {
|
|
|
|
|
|
|
|
let image = image::load_from_memory_with_format(include_bytes!("../resources/images/funky-bird.jpg"),
|
|
|
|
|
|
|
|
ImageFormat::JPEG).unwrap().to_rgba();
|
|
|
|
|
|
|
|
let dimensions = image.dimensions();
|
|
|
|
|
|
|
|
let image_data = image.into_raw().clone();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut usage = ImageUsage::none();
|
|
|
|
|
|
|
|
usage.transfer_destination = true;
|
|
|
|
|
|
|
|
usage.storage = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AttachmentImage::with_usage(
|
|
|
|
|
|
|
|
self.device.clone(),
|
|
|
|
|
|
|
|
[dimensions.0, dimensions.1],
|
|
|
|
|
|
|
|
Format::R8G8B8A8Uint,
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.img_set = Some(Arc::new(PersistentDescriptorSet::start(self.graphics_pipeline.clone().unwrap().clone(), 0)
|
|
|
|
|
|
|
|
.add_sampled_image(texture.clone(), sampler.clone()).unwrap()
|
|
|
|
|
|
|
|
.add_image(attachment_image.clone().unwrap().clone()).unwrap()
|
|
|
|
|
|
|
|
.build().unwrap()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.graphics_image_buffer = Some(texture.clone());
|
|
|
|
|
|
|
|
self.graphics_iamge_swap_buffer = Some(attachment_image.clone().unwrap());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn run(&mut self, surface: &'a Arc<Surface<Window>>, mut frame_future: Box<dyn GpuFuture>) -> Box<dyn GpuFuture> {
|
|
|
|
pub fn run(&mut self, surface: &'a Arc<Surface<Window>>, mut frame_future: Box<dyn GpuFuture>) -> Box<dyn GpuFuture> {
|
|
|
|
|
|
|
|
|
|
|
@ -490,7 +597,8 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
self.compute_pipeline.clone().unwrap().clone(),
|
|
|
|
self.compute_pipeline.clone().unwrap().clone(),
|
|
|
|
self.compute_set.clone().unwrap().clone(), ()).unwrap()
|
|
|
|
self.compute_set.clone().unwrap().clone(), ()).unwrap()
|
|
|
|
|
|
|
|
|
|
|
|
//.copy_buffer_to_image(self.img_buffers.get(0).unwrap().clone(), self.graphics_image_buffer.clone().unwrap()).unwrap()
|
|
|
|
.copy_buffer_to_image(self.img_buffers.get(0).unwrap().clone(),
|
|
|
|
|
|
|
|
self.graphics_iamge_swap_buffer.clone().unwrap()).unwrap()
|
|
|
|
.begin_render_pass(framebuffers[image_num].clone(), false, clear_values)
|
|
|
|
.begin_render_pass(framebuffers[image_num].clone(), false, clear_values)
|
|
|
|
.unwrap()
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
|
|
|
@ -504,6 +612,16 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
|
|
.build().unwrap();
|
|
|
|
.build().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut data_buffer_content = self.img_buffers.get(0).unwrap().read().unwrap();
|
|
|
|
|
|
|
|
let img = ImageBuffer::from_fn(self.xy.0, self.xy.1, |x, y| {
|
|
|
|
|
|
|
|
let r = data_buffer_content[((self.xy.0 * y + x) * 4 + 0) as usize] as u8;
|
|
|
|
|
|
|
|
let g = data_buffer_content[((self.xy.0 * y + x) * 4 + 1) as usize] as u8;
|
|
|
|
|
|
|
|
let b = data_buffer_content[((self.xy.0 * y + x) * 4 + 2) as usize] as u8;
|
|
|
|
|
|
|
|
let a = data_buffer_content[((self.xy.0 * y + x) * 4 + 3) as usize] as u8;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
image::Rgba([r, g, b, a])
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Wait on the previous frame, then execute the command buffer and present the image
|
|
|
|
// Wait on the previous frame, then execute the command buffer and present the image
|
|
|
|
let future = frame_future.join(acquire_future)
|
|
|
|
let future = frame_future.join(acquire_future)
|
|
|
|
.then_execute(self.queue.clone(), command_buffer).unwrap()
|
|
|
|
.then_execute(self.queue.clone(), command_buffer).unwrap()
|
|
|
@ -526,100 +644,6 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn load_buffers(&mut self, image_filename: String)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let project_root =
|
|
|
|
|
|
|
|
std::env::current_dir()
|
|
|
|
|
|
|
|
.expect("failed to get root directory");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut compute_path = project_root.clone();
|
|
|
|
|
|
|
|
compute_path.push(PathBuf::from("resources/images/"));
|
|
|
|
|
|
|
|
compute_path.push(PathBuf::from(image_filename));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let img = image::open(compute_path).expect("Couldn't find image");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.xy = img.dimensions();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let data_length = self.xy.0 * self.xy.1 * 4;
|
|
|
|
|
|
|
|
let pixel_count = img.raw_pixels().len();
|
|
|
|
|
|
|
|
println!("Pixel count {}", pixel_count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pixel_count != data_length as usize {
|
|
|
|
|
|
|
|
println!("Creating apha channel...");
|
|
|
|
|
|
|
|
for i in img.raw_pixels().iter() {
|
|
|
|
|
|
|
|
if (self.image_buffer.len() + 1) % 4 == 0 {
|
|
|
|
|
|
|
|
self.image_buffer.push(255);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.image_buffer.push(*i);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
self.image_buffer.push(255);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
self.image_buffer = img.raw_pixels();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("Buffer length {}", self.image_buffer.len());
|
|
|
|
|
|
|
|
println!("Size {:?}", self.xy);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("Allocating Buffers...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pull out the image data and place it in a buffer for the kernel to write to and for us to read from
|
|
|
|
|
|
|
|
let write_buffer = {
|
|
|
|
|
|
|
|
let mut buff = self.image_buffer.iter();
|
|
|
|
|
|
|
|
let data_iter = (0..data_length).map(|n| *(buff.next().unwrap()));
|
|
|
|
|
|
|
|
CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::all(), data_iter).unwrap()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Pull out the image data and place it in a buffer for the kernel to read from
|
|
|
|
|
|
|
|
let read_buffer = {
|
|
|
|
|
|
|
|
let mut buff = self.image_buffer.iter();
|
|
|
|
|
|
|
|
let data_iter = (0..data_length).map(|n| *(buff.next().unwrap()));
|
|
|
|
|
|
|
|
CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::all(), data_iter).unwrap()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// A buffer to hold many i32 values to use as settings
|
|
|
|
|
|
|
|
let settings_buffer = {
|
|
|
|
|
|
|
|
let vec = vec![self.xy.0, self.xy.1];
|
|
|
|
|
|
|
|
let mut buff = vec.iter();
|
|
|
|
|
|
|
|
let data_iter =
|
|
|
|
|
|
|
|
(0..2).map(|n| *(buff.next().unwrap()));
|
|
|
|
|
|
|
|
CpuAccessibleBuffer::from_iter(self.device.clone(),
|
|
|
|
|
|
|
|
BufferUsage::all(),
|
|
|
|
|
|
|
|
data_iter).unwrap()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("Done");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the data descriptor set for our previously created shader pipeline
|
|
|
|
|
|
|
|
let mut set =
|
|
|
|
|
|
|
|
PersistentDescriptorSet::start(self.compute_pipeline.clone().unwrap().clone(), 0)
|
|
|
|
|
|
|
|
.add_buffer(write_buffer.clone()).unwrap()
|
|
|
|
|
|
|
|
.add_buffer(read_buffer.clone()).unwrap()
|
|
|
|
|
|
|
|
.add_buffer(settings_buffer.clone()).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.compute_set = Some(Arc::new(set.build().unwrap()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.img_buffers.push(write_buffer);
|
|
|
|
|
|
|
|
self.img_buffers.push(read_buffer);
|
|
|
|
|
|
|
|
self.settings_buffer = Some(settings_buffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We now create a buffer that will store the shape of our triangle.
|
|
|
|
|
|
|
|
let vertex_buffer = {
|
|
|
|
|
|
|
|
vulkano::impl_vertex!(tVertex, position);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CpuAccessibleBuffer::from_iter(self.device.clone(), BufferUsage::all(), [
|
|
|
|
|
|
|
|
tVertex { position: [-1.0, -1.0 ] },
|
|
|
|
|
|
|
|
tVertex { position: [-1.0, 1.0 ] },
|
|
|
|
|
|
|
|
tVertex { position: [ 1.0, 1.0 ] },
|
|
|
|
|
|
|
|
tVertex { position: [ 1.0, -1.0 ] },
|
|
|
|
|
|
|
|
].iter().cloned()).unwrap()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.vertex_buffer = Some(vertex_buffer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// pub fn read_image(&self) -> Vec<u8> {
|
|
|
|
// pub fn read_image(&self) -> Vec<u8> {
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// // The buffer is sync'd so we can just read straight from the handle
|
|
|
|
// // The buffer is sync'd so we can just read straight from the handle
|
|
|
@ -683,3 +707,4 @@ impl<'a> VkProcessor<'a> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|