|
|
@ -8,6 +8,7 @@ extern crate nalgebra as na;
|
|
|
|
extern crate quick_xml;
|
|
|
|
extern crate quick_xml;
|
|
|
|
extern crate rand;
|
|
|
|
extern crate rand;
|
|
|
|
extern crate sfml;
|
|
|
|
extern crate sfml;
|
|
|
|
|
|
|
|
extern crate time;
|
|
|
|
|
|
|
|
|
|
|
|
use image::{DynamicImage, GenericImage, GenericImageView, Pixel, SubImage};
|
|
|
|
use image::{DynamicImage, GenericImage, GenericImageView, Pixel, SubImage};
|
|
|
|
use sfml::graphics::*;
|
|
|
|
use sfml::graphics::*;
|
|
|
@ -29,11 +30,15 @@ use vulkano::sync::GpuFuture;
|
|
|
|
use vulkano::sync;
|
|
|
|
use vulkano::sync;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use std::fs;
|
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::input::Input;
|
|
|
|
use crate::input::Input;
|
|
|
|
use crate::slider::Slider;
|
|
|
|
use crate::slider::Slider;
|
|
|
|
use crate::timer::Timer;
|
|
|
|
use crate::timer::Timer;
|
|
|
|
use na::DimAdd;
|
|
|
|
use na::DimAdd;
|
|
|
|
|
|
|
|
use std::time::{SystemTime, Duration};
|
|
|
|
|
|
|
|
use shade_runner as sr;
|
|
|
|
|
|
|
|
use std::ffi::CStr;
|
|
|
|
|
|
|
|
|
|
|
|
mod slider;
|
|
|
|
mod slider;
|
|
|
|
mod timer;
|
|
|
|
mod timer;
|
|
|
@ -159,20 +164,30 @@ fn main() {
|
|
|
|
let queue = queues.next().unwrap();
|
|
|
|
let queue = queues.next().unwrap();
|
|
|
|
println!("Device initialized");
|
|
|
|
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 shader = sr::load_compute(vert_path).expect("Failed to compile");
|
|
|
|
|
|
|
|
let vulkano_entry = sr::parse_compute(&shader).expect("failed to parse");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let x = unsafe {
|
|
|
|
|
|
|
|
vulkano::pipeline::shader::ShaderModule::from_words(device.clone(), &shader.compute)
|
|
|
|
|
|
|
|
}.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Compile the shader and add it to a pipeline
|
|
|
|
// Compile the shader and add it to a pipeline
|
|
|
|
let pipeline = Arc::new({
|
|
|
|
let pipeline = Arc::new({
|
|
|
|
mod cs {
|
|
|
|
unsafe {
|
|
|
|
vulkano_shaders::shader!{
|
|
|
|
ComputePipeline::new(device.clone(), &x.compute_entry_point(
|
|
|
|
ty: "compute",
|
|
|
|
CStr::from_bytes_with_nul_unchecked(b"main\0"),
|
|
|
|
path: "resources/shaders/add.compute"
|
|
|
|
vulkano_entry.compute_layout), &()
|
|
|
|
}
|
|
|
|
).unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let shader = cs::Shader::load(device.clone()).unwrap();
|
|
|
|
|
|
|
|
ComputePipeline::new(device.clone(), &shader.main_entry_point(), &()).unwrap()
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Load up the input image, determine some details
|
|
|
|
// Load up the input image, determine some details
|
|
|
|
let mut img = image::open("resources/images/background.jpg").unwrap();
|
|
|
|
let mut img = image::open("resources/images/funky-bird.jpg").unwrap();
|
|
|
|
let xy = img.dimensions();
|
|
|
|
let xy = img.dimensions();
|
|
|
|
let data_length = xy.0*xy.1*4;
|
|
|
|
let data_length = xy.0*xy.1*4;
|
|
|
|
|
|
|
|
|
|
|
@ -192,21 +207,30 @@ fn main() {
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Pull out the image data and place it in a sync'd CPU<->GPU buffer
|
|
|
|
// Pull out the image data and place it in a sync'd CPU<->GPU buffer
|
|
|
|
// Raw pixels is a u8 rgb buffer (x*y*3)
|
|
|
|
|
|
|
|
let data_buffer = {
|
|
|
|
let data_buffer = {
|
|
|
|
//let mut buff = img.raw_pixels();
|
|
|
|
|
|
|
|
|
|
|
|
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 out_buffer = {
|
|
|
|
let mut buff = image_buffer.iter();
|
|
|
|
let mut buff = image_buffer.iter();
|
|
|
|
let data_iter = (0 .. data_length).map(|n| *(buff.next().unwrap()));
|
|
|
|
let data_iter = (0 .. data_length).map(|n| *(buff.next().unwrap()));
|
|
|
|
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), data_iter).unwrap()
|
|
|
|
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), data_iter).unwrap()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let settings_buffer = {
|
|
|
|
let settings_buffer = {
|
|
|
|
CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), vec![xy.0, xy.1]).unwrap()
|
|
|
|
let vec = vec![xy.0, xy.1];
|
|
|
|
|
|
|
|
let mut buff = vec.iter();
|
|
|
|
|
|
|
|
let data_iter = (0 .. 2).map(|n| *(buff.next().unwrap()));
|
|
|
|
|
|
|
|
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), data_iter).unwrap()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Create the data descriptor set for our previously created shader pipeline
|
|
|
|
// Create the data descriptor set for our previously created shader pipeline
|
|
|
|
let set = Arc::new(PersistentDescriptorSet::start(pipeline.clone(), 0)
|
|
|
|
let mut set = Arc::new(PersistentDescriptorSet::start(pipeline.clone(), 0)
|
|
|
|
.add_buffer(data_buffer.clone()).unwrap()
|
|
|
|
.add_buffer(data_buffer.clone()).unwrap()
|
|
|
|
|
|
|
|
.add_buffer(out_buffer.clone()).unwrap()
|
|
|
|
.add_buffer(settings_buffer.clone()).unwrap()
|
|
|
|
.add_buffer(settings_buffer.clone()).unwrap()
|
|
|
|
.build().unwrap()
|
|
|
|
.build().unwrap()
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -222,19 +246,19 @@ fn main() {
|
|
|
|
.then_signal_fence_and_flush().unwrap();
|
|
|
|
.then_signal_fence_and_flush().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
// I think this is redundant and returns immediately
|
|
|
|
// I think this is redundant and returns immediately
|
|
|
|
// future.wait(None).unwrap();
|
|
|
|
future.wait(None).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
let data_buffer_content = data_buffer.read().unwrap();
|
|
|
|
let data_buffer_content = data_buffer.read().unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
for y in 0 .. xy.1 {
|
|
|
|
for y in 0 .. xy.1 {
|
|
|
|
for x in 0 .. xy.0 {
|
|
|
|
for x in 0 .. xy.0 {
|
|
|
|
|
|
|
|
|
|
|
|
let r = data_buffer_content[((xy.0 * y + x) * 4 + 0) as usize] as u8;
|
|
|
|
let r = data_buffer_content[((xy.0 * y + x) * 4 + 0) as usize] as u8;
|
|
|
|
let g = data_buffer_content[((xy.0 * y + x) * 4 + 1) as usize] as u8;
|
|
|
|
let g = data_buffer_content[((xy.0 * y + x) * 4 + 1) as usize] as u8;
|
|
|
|
let b = data_buffer_content[((xy.0 * y + x) * 4 + 2) as usize] as u8;
|
|
|
|
let b = data_buffer_content[((xy.0 * y + x) * 4 + 2) as usize] as u8;
|
|
|
|
let a = data_buffer_content[((xy.0 * y + x) * 4 + 3) as usize] as u8;
|
|
|
|
let a = data_buffer_content[((xy.0 * y + x) * 4 + 3) as usize] as u8;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 0) as usize).unwrap() = r;
|
|
|
|
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 0) as usize).unwrap() = r;
|
|
|
|
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 1) as usize).unwrap() = g;
|
|
|
|
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 1) as usize).unwrap() = g;
|
|
|
|
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 2) as usize).unwrap() = b;
|
|
|
|
*image_buffer.get_mut(((xy.0 * y + x) * 4 + 2) as usize).unwrap() = b;
|
|
|
@ -245,9 +269,9 @@ fn main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
img.save("output9.png");
|
|
|
|
img.save(format!("output/{}.png", SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs()));
|
|
|
|
|
|
|
|
|
|
|
|
println!("Starting");
|
|
|
|
println!("Stdddwafasddfqwefaarting");
|
|
|
|
|
|
|
|
|
|
|
|
let mut window = RenderWindow::new(
|
|
|
|
let mut window = RenderWindow::new(
|
|
|
|
(900, 900),
|
|
|
|
(900, 900),
|
|
|
|