|
|
|
@ -29,7 +29,7 @@ use vulkano::pipeline::ComputePipeline;
|
|
|
|
|
use vulkano::sync::GpuFuture;
|
|
|
|
|
use vulkano::sync;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
use std::fs;
|
|
|
|
|
use std::{fs, mem, iter, ptr};
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use std::result;
|
|
|
|
|
|
|
|
|
@ -40,6 +40,7 @@ use na::DimAdd;
|
|
|
|
|
use std::time::{SystemTime, Duration};
|
|
|
|
|
use shade_runner as sr;
|
|
|
|
|
use std::ffi::CStr;
|
|
|
|
|
use std::ptr::write;
|
|
|
|
|
|
|
|
|
|
mod slider;
|
|
|
|
|
mod timer;
|
|
|
|
@ -165,7 +166,7 @@ fn main() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Load up the input image, determine some details
|
|
|
|
|
let mut img = image::open("resources/images/test2.png").unwrap();
|
|
|
|
|
let mut img = image::open("resources/images/test.png").unwrap();
|
|
|
|
|
let xy = img.dimensions();
|
|
|
|
|
let data_length = xy.0*xy.1*4;
|
|
|
|
|
|
|
|
|
@ -192,22 +193,38 @@ fn main() {
|
|
|
|
|
println!("Allocating Buffers...");
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), image_buffer.clone()).unwrap()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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 = image_buffer.iter();
|
|
|
|
|
let data_iter = (0 .. data_length).map(|n| *(buff.next().unwrap()));
|
|
|
|
|
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), data_iter).unwrap()
|
|
|
|
|
//CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), image_buffer.clone()).unwrap()
|
|
|
|
|
let data_iter = (0..data_length).map(|n| *(buff.next().unwrap()));
|
|
|
|
|
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), data_iter).unwrap();
|
|
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
let uninitialized =
|
|
|
|
|
CpuAccessibleBuffer::raw(device, data_length as usize, BufferUsage::all(), iter::empty()).unwrap();
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
let mut mapping = uninitialized.write().unwrap();
|
|
|
|
|
ptr::write(&mut *mapping, image_buffer.as_slice())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uninitialized
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Pull out the image data and place it in a buffer for the kernel to read from
|
|
|
|
|
let read_buffer = {
|
|
|
|
|
let mut buff = image_buffer.iter();
|
|
|
|
|
let data_iter = (0 .. data_length).map(|n| *(buff.next().unwrap()));
|
|
|
|
|
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), data_iter).unwrap()
|
|
|
|
|
// let q = ImmutableBuffer::from_data(image_buffer.clone(), BufferUsage::all(), queue.clone()).unwrap();
|
|
|
|
|
// q.1.flush();
|
|
|
|
|
// q.0
|
|
|
|
|
// let mut buff = image_buffer.iter();
|
|
|
|
|
// let data_iter = (0 .. data_length).map(|n| *(buff.next().unwrap()));
|
|
|
|
|
CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), image_buffer.clone()).unwrap()
|
|
|
|
|
|
|
|
|
|
//CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), image_buffer.clone()).unwrap()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// A buffer to hold many i32 values to use as settings
|
|
|
|
@ -220,12 +237,12 @@ fn main() {
|
|
|
|
|
|
|
|
|
|
println!("Done");
|
|
|
|
|
// Create the data descriptor set for our previously created shader pipeline
|
|
|
|
|
let mut set = Arc::new(PersistentDescriptorSet::start(pipeline.clone(), 0)
|
|
|
|
|
let mut set = PersistentDescriptorSet::start(pipeline.clone(), 0)
|
|
|
|
|
.add_buffer(write_buffer.clone()).unwrap()
|
|
|
|
|
.add_buffer(read_buffer.clone()).unwrap()
|
|
|
|
|
.add_buffer(settings_buffer.clone()).unwrap()
|
|
|
|
|
.build().unwrap()
|
|
|
|
|
);
|
|
|
|
|
.add_buffer(settings_buffer.clone()).unwrap();
|
|
|
|
|
|
|
|
|
|
let mut set = Arc::new(set.build().unwrap());
|
|
|
|
|
|
|
|
|
|
println!("Running Kernel...");
|
|
|
|
|
// The command buffer I think pretty much serves to define what runs where for how many times
|
|
|
|
|