for some reason I broke it. I think it has to do with the glsl layout

This commit is contained in:
2019-07-01 23:09:42 -07:00
parent 4b85f6dd1f
commit 20f3075fa8
3 changed files with 45 additions and 42 deletions

View File

@@ -143,10 +143,10 @@ fn main() {
println!("Device initialized");
let project_root = std::env::current_dir().expect("failed to get root directory");
let mut vert_path = project_root.clone();
vert_path.push(PathBuf::from("resources/shaders/add.compute"));
let mut compute_path = project_root.clone();
compute_path.push(PathBuf::from("resources/shaders/add.compute"));
let shader = sr::load_compute(vert_path).expect("Failed to compile");
let shader = sr::load_compute(compute_path).expect("Failed to compile");
let vulkano_entry = sr::parse_compute(&shader).expect("failed to parse");
let x = unsafe {
@@ -165,7 +165,7 @@ fn main() {
});
// Load up the input image, determine some details
let mut img = image::open("resources/images/test.png").unwrap();
let mut img = image::open("resources/images/test2.png").unwrap();
let xy = img.dimensions();
let data_length = xy.0*xy.1*4;
@@ -191,17 +191,22 @@ fn main() {
println!("Allocating Buffers...");
{
// Pull out the image data and place it in a buffer for the kernel to read from
let read_buffer = {
let q = ImmutableBuffer::from_data(image_buffer.clone(), BufferUsage::all(), queue.clone()).unwrap();
q.1.flush();
q.0
};
// 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()
};
// Pull out the image data and place it in a buffer for the kernel to read from
let read_buffer = {
// 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()
};
@@ -216,8 +221,8 @@ 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)
.add_buffer(read_buffer).unwrap()
.add_buffer(write_buffer.clone()).unwrap()
.add_buffer(read_buffer.clone()).unwrap()
.add_buffer(settings_buffer.clone()).unwrap()
.build().unwrap()
);
@@ -237,12 +242,10 @@ fn main() {
future.wait(None).unwrap();
println!("Done running kernel");
println!("Reading output");
// The buffer is sync'd so we can just read straight from the handle
let data_buffer_content = write_buffer.read().unwrap();
let p = image::load_from_memory(data_buffer_content.as_slice()).unwrap();
println!("done2");
for y in 0 .. xy.1 {
for x in 0 .. xy.0 {
@@ -261,10 +264,9 @@ fn main() {
}
}
println!("done3");
println!("Saving output");
img.save(format!("output/{}.png", SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs()));
println!("Stdddwafasddfqwefaarting");
let mut window = RenderWindow::new(
(900, 900),